Skip to content

Commit

Permalink
#14001: remove header target in CMake (#14748)
Browse files Browse the repository at this point in the history
### Ticket
#14001 

### Problem description
Globals have a few problems:
* Enables circular dependencies
* Confounds humans and tools from reasoning through the project
structure
* Hinders packaging efforts <-- what prompted this PR

### What's changed
Remove `metal_header_directories` in favour of targets linking against
the actual targets that they depend on, and allowing CMake to flow usage
requirements according to the dependency graph.

### Checklist
- [x] Post commit CI passes
https://github.com/tenstorrent/tt-metal/actions/runs/11689366899
- [ ] Blackhole Post commit (if applicable)
- [ ] Model regression CI testing passes (if applicable)
- [ ] Device performance regression CI testing passes (if applicable)
- [ ] New/Existing tests provide coverage for changes
- [x] TTNN C++ Project passes
https://github.com/tenstorrent/tt-metal/actions/runs/11689407001
  • Loading branch information
afuller-TT authored Nov 8, 2024
1 parent ee55081 commit 23c3b81
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 62 deletions.
25 changes: 1 addition & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
GLOBAL
PROPERTY
GLOBAL_DEPENDS_NO_CYCLES
ON
FALSE #FIXME(14541): We've got work to do :(
)

if(ENABLE_CCACHE)
Expand Down Expand Up @@ -258,29 +258,6 @@ if(ENABLE_TRACY)
add_link_options(-rdynamic)
endif()

add_library(metal_header_directories INTERFACE)
target_include_directories(metal_header_directories INTERFACE ${PROJECT_SOURCE_DIR}/tt_metal/hw/inc)
foreach(lib ${BoostPackages})
target_include_directories(metal_header_directories INTERFACE ${Boost${lib}_SOURCE_DIR}/include)
endforeach()

if("$ENV{ARCH_NAME}" STREQUAL "wormhole_b0")
target_include_directories(
metal_header_directories
INTERFACE
tt_metal/hw/inc/wormhole
${PROJECT_SOURCE_DIR}/tt_metal/hw/inc/wormhole/wormhole_b0_defines
${UMD_HOME}/device/wormhole
)
else()
target_include_directories(
metal_header_directories
INTERFACE
${PROJECT_SOURCE_DIR}/tt_metal/hw/inc/$ENV{ARCH_NAME}
${UMD_HOME}/device/$ENV{ARCH_NAME}
)
endif()

if(WITH_PYTHON_BINDINGS)
# Can't use the `REUSE_FROM` option bc tt_lib and ttnn have different build flags :(
add_library(pch_pybinds INTERFACE)
Expand Down
1 change: 0 additions & 1 deletion tests/tt_metal/tt_metal/unit_tests_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ TT_ENABLE_UNITY_BUILD(unit_tests_common_o)
target_link_libraries(
unit_tests_common_o
PUBLIC
metal_header_directories
gtest
gtest_main
magic_enum
Expand Down
1 change: 0 additions & 1 deletion tt_metal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ target_sources(
target_link_libraries(
tt_metal
PUBLIC
metal_header_directories
Metalium::Metal::Impl
Metalium::Metal::STL
umd::device
Expand Down
7 changes: 5 additions & 2 deletions tt_metal/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ set(COMMON_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/work_split.cpp
)

add_library(common OBJECT ${COMMON_SRCS})
add_library(common STATIC ${COMMON_SRCS}) # FIXME(14541): Should be OBJECT, but can't handle circular deps between Object libs
add_library(Metalium::Metal::Common ALIAS common)

target_link_libraries(common PRIVATE yaml-cpp::yaml-cpp)
target_link_libraries(
common
PUBLIC
metal_header_directories
magic_enum
fmt::fmt-header-only
span
Metalium::Metal::STL
Metalium::Metal::LLRT
umd::Firmware
)

target_include_directories(
Expand Down
48 changes: 18 additions & 30 deletions tt_metal/hw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,9 @@ foreach(ARCH IN LISTS ARCHS)

# add output file to the custom target
list(APPEND PREPROCESSED_LD_FILES ${HW_OUTPUT_FILE})
endforeach(
TYPE
IN
LISTS
TYPES
)
endforeach(
PROC
IN
LISTS
PORCS
)
endforeach(
ARCH
IN
LISTS
ARCHS
)
endforeach()
endforeach()
endforeach()

# Function appends b0 if its wormhole
function(get_alias INPUT_STRING OUTPUT_VAR)
Expand Down Expand Up @@ -193,18 +178,8 @@ foreach(ARCH IN LISTS ARCHS)
VERBATIM
)
list(APPEND PREPROCESSED_O_FILES ${HW_OUTPUT_FILE})
endforeach(
HWLIB
IN
LISTS
HWLIBS
)
endforeach(
ARCH
IN
LISTS
ARCHS
)
endforeach()
endforeach()

# custom target that depends on all the output files
add_custom_target(
Expand All @@ -214,3 +189,16 @@ add_custom_target(
${PREPROCESSED_LD_FILES}
${PREPROCESSED_O_FILES}
)

add_library(hw INTERFACE)
add_library(Metalium::Metal::Hardware ALIAS hw)

set(currentArch "$ENV{ARCH_NAME}")
string(REPLACE "wormhole_b0" "wormhole" currentArch "${currentArch}")
target_include_directories(
hw
INTERFACE
inc
inc/${currentArch}
$<$<STREQUAL:${currentArch},wormhole>:${CMAKE_CURRENT_SOURCE_DIR}/inc/wormhole/wormhole_b0_defines>
)
4 changes: 3 additions & 1 deletion tt_metal/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ add_library(Metalium::Metal::Impl ALIAS impl)

target_link_libraries(
impl
PUBLIC
common
Metalium::Metal::LLRT
PRIVATE
Boost::smart_ptr
range-v3::range-v3
)
target_link_libraries(impl PUBLIC common)

target_include_directories(
impl
Expand Down
7 changes: 5 additions & 2 deletions tt_metal/llrt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ set(LLRT_SRC
${CMAKE_CURRENT_SOURCE_DIR}/blackhole/bh_hal_idle_eth.cpp
)

add_library(llrt OBJECT ${LLRT_SRC})
add_library(llrt STATIC ${LLRT_SRC}) # FIXME(14541): Should be OBJECT, but can't handle circular deps between Object libs
add_library(Metalium::Metal::LLRT ALIAS llrt)

target_link_libraries(
llrt
PUBLIC
common
Metalium::Metal::Common
umd::device
Metalium::Metal::Hardware
)
target_compile_options(llrt PRIVATE -Wno-int-to-pointer-cast)
1 change: 0 additions & 1 deletion ttnn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ set(TTNN_PUBLIC_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/cpp
)
set(TTNN_PUBLIC_LINK_LIBRARIES
metal_header_directories
metal_common_libs
Metalium::Metal
Boost::container
Expand Down

0 comments on commit 23c3b81

Please sign in to comment.