Skip to content

Commit

Permalink
#4252: bring in boost with CPM, caching enabled during config step
Browse files Browse the repository at this point in the history
  • Loading branch information
vtangTT committed Jun 4, 2024
1 parent 0f883f0 commit f9b618f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ compile_commands.json
# rpath_check
tt_eager/tt_lib/.rpath_checked*
ttnn/ttnn/.rpath_checked

# exclude boost from CPM
tt_metal/third_party/boost
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ CHECK_COMPILERS()
############################################################################################################################
# Find all required libraries to build
############################################################################################################################
include(${CMAKE_SOURCE_DIR}/cmake/CPM_boost.cmake)
find_package(GTest REQUIRED)
find_package (Python3 COMPONENTS Interpreter Development)
find_package(Python3 COMPONENTS Interpreter Development)

############################################################################################################################
# Setting build type flags
Expand Down Expand Up @@ -84,8 +85,7 @@ set(CMAKE_INSTALL_DATAROOTDIR "${CMAKE_BINARY_DIR}/tmp/share")
############################################################################################################################
add_library(metal_common_libs INTERFACE)
target_link_libraries(metal_common_libs INTERFACE
dl z pthread atomic stdc++ hwloc numa # system libraries, hwloc has no cmake support, find_package won't find it
# boost_interprocess boost_format boost_core boost_container_hash boost_align
dl z pthread atomic stdc++ hwloc # system libraries, hwloc has no cmake support, find_package won't find it
)

# Note on flags:
Expand Down Expand Up @@ -122,6 +122,10 @@ add_library(metal_header_directories INTERFACE)
target_include_directories(metal_header_directories INTERFACE ${CMAKE_SOURCE_DIR}/tt_metal/hw/inc
${CMAKE_SOURCE_DIR}/tt_metal/third_party
)
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
tt_metal/hw/inc/wormhole/wormhole_b0_defines
Expand All @@ -147,8 +151,6 @@ target_precompile_headers(pch_pybinds INTERFACE
############################################################################################################################
# Build subdirectories
############################################################################################################################
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tt_metal/third_party/boost)

if($ENV{ENABLE_TRACY})
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/tracy.cmake)
endif()
Expand All @@ -163,7 +165,6 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ttnn)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests EXCLUDE_FROM_ALL)


############################################################################################################################
# Install targets for build artifacts and pybinds
# If built with Tracy, cannot install 'all' since it will pick up install targets from Tracy
Expand Down
25 changes: 25 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.39.0)
set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
35 changes: 35 additions & 0 deletions cmake/CPM_boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

set(ENV{CPM_SOURCE_CACHE} "${CMAKE_SOURCE_DIR}/tt_metal/third_party/boost")

include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake)
set(BoostPackages
Align
Config
Container_Hash
Core
Detail
Format
Interprocess
Smart_Ptr
Assert
Integer
Type_Traits
Optional
Static_Assert
Throw_Exception
Move
Utility
Preprocessor
Date_Time
Numeric_Conversion
Mpl
)

foreach(package ${BoostPackages})
CPMAddPackage(
NAME Boost${package}
GITHUB_REPOSITORY boostorg/${package}
GIT_TAG boost-1.76.0
DOWNLOAD_ONLY YES
)
endforeach()
14 changes: 12 additions & 2 deletions cmake/umd_device.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ if($ENV{ENABLE_TRACY})
endif()

# MUST have the RPATH set, or else can't find the tracy lib
# set(LDFLAGS_ "-L${CMAKE_BINARY_DIR}/lib -L/usr/local/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/lib -Wl,-rpath,/usr/local/lib ${CONFIG_LDFLAGS} -ldl -lz -lboost_thread -lboost_filesystem -lboost_system -lboost_regex -lpthread -latomic -lhwloc -lstdc++")
set(LDFLAGS_ "-L${CMAKE_BINARY_DIR}/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/lib ${CONFIG_LDFLAGS} -ldl -lz -lpthread -latomic -lhwloc -lstdc++")
set(SHARED_LIB_FLAGS_ "-shared -fPIC")
set(STATIC_LIB_FLAGS_ "-fPIC")

set (CMAKE_CXX_FLAGS_ "--std=c++17 -fvisibility-inlines-hidden -I${CMAKE_SOURCE_DIR}/tt_metal/third_party")
set (CMAKE_CXX_FLAGS_ "--std=c++17 -fvisibility-inlines-hidden")
foreach(lib ${BoostPackages})
set(CMAKE_CXX_FLAGS_ "${CMAKE_CXX_FLAGS_} -I${Boost${lib}_SOURCE_DIR}/include")
endforeach()

set(UMD_OUTPUT > /dev/null 2>&1)
if(DEFINED ENV{VERBOSE})
if($ENV{VERBOSE} STREQUAL 1)
set(UMD_OUTPUT "")
endif()
endif()

# This will build the shared library libdevice.so in build/lib where tt_metal can then find and link it
include(ExternalProject)
Expand Down Expand Up @@ -56,6 +65,7 @@ ExternalProject_Add(
STATIC_LIB_FLAGS=${STATIC_LIB_FLAGS_}
LDFLAGS=${LDFLAGS_}
CXXFLAGS=${CMAKE_CXX_FLAGS_}
${UMD_OUTPUT}
)
# add_dependencies(umd_device umd_boost)
if($ENV{ENABLE_TRACY})
Expand Down

0 comments on commit f9b618f

Please sign in to comment.