tenstorrent / tt-metal

:metal: TT-NN operator library, and TT-Metalium low level kernel programming model.
Apache License 2.0
303 stars 26 forks source link

[Feature Request] CMake integration (provide CMake module to locate metalium and provide easy linking) #7914

Open marty1885 opened 2 months ago

marty1885 commented 2 months ago

Is your feature request related to a problem? Please describe.

Most (at least a large chunk of) C++ code base uses CMake as the build system (generator). So far my projects uses my own script to hack to let programs see Metalium. It'll be nice to be able to have some MetaliumConfig.cmake that the project comes with, which also makes outside projects immune to Metalium structure and dependency changes.


if("$ENV{TT_METAL_HOME}" STREQUAL "")
    message(FATAL_ERROR "TT_METAL_HOME is not set")
endif()
if("$ENV{ARCH_NAME}" STREQUAL "")
    message(FATAL_ERROR "ARCH_NAME is not set")
endif()

message($ENV{TT_METAL_HOME}/tt_metal/third_party/src/firmware/riscv/$ENV{ARCH_NAME})
add_executable(ttvecadd ttvecadd.cpp)
target_include_directories(ttvecadd PRIVATE
    $ENV{TT_METAL_HOME}
    $ENV{TT_METAL_HOME}/tt_metal
    $ENV{TT_METAL_HOME}/tt_metal/third_party/umd
    $ENV{TT_METAL_HOME}/tt_metal/hw/inc/$ENV{ARCH_NAME}
    $ENV{TT_METAL_HOME}/tt_metal/hw/inc/
    $ENV{TT_METAL_HOME}/tt_metal/third_party/umd/src/firmware/riscv/$ENV{ARCH_NAME}
)
target_link_directories(ttvecadd PRIVATE
    $ENV{TT_METAL_HOME}/build/lib
)
target_link_libraries(ttvecadd PRIVATE
    tt_metal
    yaml-cpp
    fmt
)

Describe the solution you'd like

A MetaliumConfig.cmake that gets included in the tt-metal repository. Which I can use to link against Metalium like so:

find_package(Metalium CONFIG)
target_link_libraries(foo PRIVATE Metalium::Metalium)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

jliangTT commented 2 months ago

Setting as P2 and triaging to the infra queue to comment on the build.

TT-billteng commented 2 months ago

Hi @marty1885, I agree that we should do this and will act in the near future. FYI, we just got full Metal CMake support as of today. Give it a try :)

marty1885 commented 2 months ago

@TT-billteng Just tried. I love it. Works really well!

Minor note. It'll be great if you could enable precompiled headers during build. Should cut down the build time by a lot for Metalium. TTNN takes a while to build, I think it'll greatly benefit from it.

TT-billteng commented 2 months ago

Minor note. It'll be great if you could enable precompiled headers during build. Should cut down the build time by a lot for Metalium. TTNN takes a while to build, I think it'll greatly benefit from it.

@vtangTT

vtangTT commented 1 month ago

Hi @marty1885, thank you for your helpful feedback. I agree that precompiled headers are something we should be using more in the future. I've added some in this PR: https://github.com/tenstorrent/tt-metal/pull/8265 mainly for our third party headers such as pybinds, and that should help a little bit.

Unfortunately, right now it seems metal doesn't play well with pch due to the different build flags of our targets and rapidly changing header files. Please let me know if you see any other areas for improvement!