Skip to content

Commit

Permalink
#0: Use LLVM's libc++ as the standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-zaretskiy authored and TT-billteng committed Jun 14, 2024
1 parent ad68ea3 commit a0a8e5a
Show file tree
Hide file tree
Showing 39 changed files with 210 additions and 240 deletions.
7 changes: 7 additions & 0 deletions .github/actions/install-metal-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ runs:
echo $DEPENDENCIES
sudo apt update
sudo apt install -y $DEPENDENCIES
- name: Install Clang-17
shell: bash
run: |
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 17
sudo apt install -y libc++-17-dev libc++abi-17-dev
2 changes: 0 additions & 2 deletions .github/actions/install-metal-deps/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"software-properties-common=0.99.9.12",
"build-essential=12.8ubuntu1.1",
"python3.8-venv=3.8.10-0ubuntu1~20.04.9",
"libyaml-cpp-dev=0.6.2-4ubuntu1",
"libhwloc-dev",
"graphviz",
"patchelf"
Expand All @@ -12,7 +11,6 @@
"software-properties-common",
"build-essential",
"python3.10-venv",
"libyaml-cpp-dev",
"libhwloc-dev",
"graphviz",
"patchelf"
Expand Down
6 changes: 0 additions & 6 deletions .github/actions/install-metal-dev-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,3 @@ runs:
tar -xvf doxygen-1.9.6.linux.bin.tar.gz
cd doxygen-1.9.6
sudo make install
- name: Install Clang-17
shell: bash
run: |
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 17
34 changes: 16 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ cmake_policy(VERSION 3.16)

# Use Clang-17 by default until we upgrade to Ubuntu version that supports higher GCC
# No longer support GCC-9 as it does not support C++20
find_program(CLANG_17 clang++-17)
if(CLANG_17)
message(STATUS "Found Clang-17 here: ${CLANG_17}")
set(CMAKE_CXX_COMPILER "${CLANG_17}")
else()
message(WARNING "Clang++-17 not found!!!")
find_program(CLANGPP_17 clang++-17)
find_program(CLANG_17 clang-17)

if (NOT CLANGPP_17)
message(FATAL_ERROR "clang++-17 not found")
endif()

if (NOT CLANG_17)
message(FATAL_ERROR "clang-17 not found")
endif()

set(CMAKE_CXX_COMPILER "${CLANGPP_17}")
set(CMAKE_C_COMPILER "${CLANG_17}")

if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
message(FATAL_ERROR "CMake generation is not allowed within source directory!! Please set a build folder with '-B'!!")
endif()
Expand All @@ -32,22 +38,14 @@ CHECK_COMPILERS()
############################################################################################################################
# Find all required libraries to build
############################################################################################################################
include(${PROJECT_SOURCE_DIR}/cmake/CPM_boost.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/dependencies.cmake)

find_package (Python3 COMPONENTS Interpreter Development)
find_library(NUMA_LIBRARY NAMES numa)
if (NOT NUMA_LIBRARY)
message(FATAL_ERROR "NUMA library not found")
endif()

CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.12.1
VERSION 1.12.1
OPTIONS "INSTALL_GTEST OFF"
)


############################################################################################################################
# Setting build type flags
# Will default to assert build, unless CONFIG env variable is set or manually set -DCMAKE_BUILD_TYPE
Expand Down Expand Up @@ -98,7 +96,7 @@ set(CMAKE_INSTALL_DATAROOTDIR "${PROJECT_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
dl z pthread atomic c++ c++abi hwloc numa # system libraries, hwloc has no cmake support, find_package won't find it
)

# Note on flags:
Expand All @@ -112,7 +110,7 @@ CHECK_COMPILER_WARNINGS() # <- add any extra compile warning flags for buil

add_library(compiler_flags INTERFACE)
target_link_libraries(compiler_flags INTERFACE compiler_warnings)
target_compile_options(compiler_flags INTERFACE -mavx2 -fPIC -DFMT_HEADER_ONLY -fvisibility-inlines-hidden -fno-lto)
target_compile_options(compiler_flags INTERFACE -mavx2 -fPIC -DFMT_HEADER_ONLY -fvisibility-inlines-hidden -fno-lto -stdlib=libc++)

if(TT_METAL_VERSIM_DISABLED)
target_compile_options(compiler_flags INTERFACE -DTT_METAL_VERSIM_DISABLED)
Expand Down
5 changes: 2 additions & 3 deletions INSTALLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ Note the current compatability matrix:

```sh
sudo apt update
sudo apt install software-properties-common=0.99.9.12 build-essential=12.8ubuntu1.1 python3.8-venv=3.8.10-0ubuntu1~20.04.9 libyaml-cpp-dev=0.6.2-4ubuntu1 libhwloc-dev graphviz

# Install Clang-17 for C++20 support!!
sudo apt install software-properties-common=0.99.9.12 build-essential=12.8ubuntu1.1 python3.8-venv=3.8.10-0ubuntu1~20.04.9 libhwloc-dev graphviz
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 17
sudo apt install libc++-17-dev libc++abi-17-dev
```

---
Expand Down
35 changes: 0 additions & 35 deletions cmake/CPM_boost.cmake

This file was deleted.

80 changes: 80 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

set(ENV{CPM_SOURCE_CACHE} "${PROJECT_SOURCE_DIR}/.cpmcache")

############################################################################################################################
# Boost
############################################################################################################################

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

foreach(package ${BoostPackages})
CPMAddPackage(
NAME Boost${package}
GITHUB_REPOSITORY boostorg/${package}
GIT_TAG boost-1.85.0
DOWNLOAD_ONLY YES
)
endforeach()

############################################################################################################################
# yaml-cpp
############################################################################################################################

CPMAddPackage(
NAME yaml-cpp
GITHUB_REPOSITORY jbeder/yaml-cpp
GIT_TAG 0.8.0
OPTIONS
"YAML_CPP_BUILD_TESTS OFF"
"YAML_CPP_BUILD_TOOLS OFF"
)

if (yaml-cpp_ADDED)
target_compile_options(yaml-cpp PUBLIC -stdlib=libc++)
target_link_libraries(yaml-cpp PUBLIC c++ c++abi)
set_target_properties(yaml-cpp PROPERTIES DEBUG_POSTFIX "")
endif()

############################################################################################################################
# googletest
############################################################################################################################

CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.13.0
VERSION 1.13.0
OPTIONS "INSTALL_GTEST OFF"
)

if (googletest_ADDED)
target_compile_options(gtest PRIVATE -stdlib=libc++ -Wno-implicit-int-float-conversion)
target_compile_options(gtest_main PRIVATE -stdlib=libc++)
target_link_libraries(gtest PRIVATE c++ c++abi)
target_link_libraries(gtest_main PRIVATE c++ c++abi)
endif()
2 changes: 1 addition & 1 deletion cmake/helper_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(CREATE_PGM_EXAMPLES_EXE TESTLIST SUBDIR)
get_filename_component(TEST_TARGET ${TEST} NAME)

add_executable(${TEST_TARGET} ${TEST})
target_link_libraries(${TEST_TARGET} PUBLIC tt_metal stdc++fs yaml-cpp m pthread)
target_link_libraries(${TEST_TARGET} PUBLIC tt_metal yaml-cpp::yaml-cpp m pthread)
target_include_directories(${TEST_TARGET} PRIVATE
${UMD_HOME}
${PROJECT_SOURCE_DIR}
Expand Down
121 changes: 19 additions & 102 deletions cmake/umd_device.cmake
Original file line number Diff line number Diff line change
@@ -1,107 +1,24 @@
set(UMD_SRC
${UMD_HOME}/device/architecture_implementation.cpp
${UMD_HOME}/device/blackhole_implementation.cpp
${UMD_HOME}/device/cpuset_lib.cpp
${UMD_HOME}/device/grayskull_implementation.cpp
${UMD_HOME}/device/tlb.cpp
${UMD_HOME}/device/tt_cluster_descriptor.cpp
${UMD_HOME}/device/tt_device.cpp
${UMD_HOME}/device/tt_emulation_stub.cpp
${UMD_HOME}/device/tt_silicon_driver.cpp
${UMD_HOME}/device/tt_silicon_driver_common.cpp
${UMD_HOME}/device/tt_soc_descriptor.cpp
${UMD_HOME}/device/tt_versim_stub.cpp
${UMD_HOME}/device/wormhole_implementation.cpp
)

### THIS CMAKE IS TO BUILD THE UMD_DEVICE SHARED LIBRARY ###
### All variables/compiler flags declared in this file are passed to umd/device .mk file to build device ###

set(WARNINGS "-Werror -Wdelete-non-virtual-dtor -Wreturn-type -Wswitch -Wuninitialized -Wno-unused-parameter" CACHE STRING "Warnings to enable")

if(CMAKE_BUILD_TYPE STREQUAL "ci")
set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -Wl,--verbose")
elseif(CMAKE_BUILD_TYPE STREQUAL "asan")
set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -fsanitize=address")
elseif(CMAKE_BUILD_TYPE STREQUAL "ubsan")
set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -fsanitize=undefined")
endif()

if(NOT TT_METAL_VERSIM_DISABLED)
set(UMD_VERSIM_STUB 0)
else()
set(UMD_VERSIM_STUB 1)
endif()
if($ENV{ENABLE_TRACY})
set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -ltracy -rdynamic")
endif()

# MUST have the RPATH set, or else can't find the tracy lib
set(LDFLAGS_ "-L${PROJECT_BINARY_DIR}/lib -Wl,-rpath,${PROJECT_BINARY_DIR}/lib ${CONFIG_LDFLAGS} -ldl -lz -lpthread -latomic -lhwloc -lstdc++")
set(SHARED_LIB_FLAGS_ "-shared -fPIC")
set(STATIC_LIB_FLAGS_ "-fPIC")
add_library(umd_device OBJECT ${UMD_SRC})
target_include_directories(umd_device PRIVATE ${UMD_HOME} ${UMD_HOME}/third_party/fmt/include)

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")
target_include_directories(umd_device PRIVATE ${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)
ExternalProject_Add(
umd_device
PREFIX ${UMD_HOME}
SOURCE_DIR ${UMD_HOME}
BINARY_DIR ${PROJECT_BINARY_DIR}
INSTALL_DIR ${PROJECT_BINARY_DIR}
STAMP_DIR "${PROJECT_BINARY_DIR}/tmp/umd_stamp"
TMP_DIR "${PROJECT_BINARY_DIR}/tmp/umd_tmp"
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND
make -f ${UMD_HOME}/device/module.mk umd_device
OUT=${PROJECT_BINARY_DIR}
LIBDIR=${PROJECT_BINARY_DIR}/lib
OBJDIR=${PROJECT_BINARY_DIR}/obj
UMD_HOME=${UMD_HOME}
UMD_VERSIM_STUB=${UMD_VERSIM_STUB}
UMD_VERSIM_HEADERS=${TT_METAL_VERSIM_ROOT}/versim/
UMD_USER_ROOT=$ENV{TT_METAL_HOME}
WARNINGS=${WARNINGS}
SHARED_LIB_FLAGS=${SHARED_LIB_FLAGS_}
STATIC_LIB_FLAGS=${STATIC_LIB_FLAGS_}
LDFLAGS=${LDFLAGS_}
CXXFLAGS=${CMAKE_CXX_FLAGS_}
DEVICE_CXX=${CMAKE_CXX_COMPILER}
${UMD_OUTPUT}
)
# add_dependencies(umd_device umd_boost)
if($ENV{ENABLE_TRACY})
add_dependencies(umd_device TracyClient)
endif()

# If in production build for python packaging, need to use objs built by umd_device
if(NOT BUILD_SHARED_LIBS)
set(UMD_OBJS
${UMD_OBJS}
${PROJECT_BINARY_DIR}/obj/umd/device/architecture_implementation.o
${PROJECT_BINARY_DIR}/obj/umd/device/blackhole_implementation.o
${PROJECT_BINARY_DIR}/obj/umd/device/cpuset_lib.o
${PROJECT_BINARY_DIR}/obj/umd/device/grayskull_implementation.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_cluster_descriptor.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_device.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_emulation_stub.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_silicon_driver_common.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_silicon_driver.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_soc_descriptor.o
${PROJECT_BINARY_DIR}/obj/umd/device/tt_versim_stub.o
${PROJECT_BINARY_DIR}/obj/umd/device/tlb.o
${PROJECT_BINARY_DIR}/obj/umd/device/wormhole_implementation.o
)
set(UMD_STATIC_LIB ${PROJECT_BINARY_DIR}/lib/libdevice.a)

# Build static lib with objs created after umd_device is built
add_custom_command(
OUTPUT ${UMD_STATIC_LIB}
COMMAND ar rcs ${UMD_STATIC_LIB} ${UMD_OBJS}
DEPENDS umd_device
COMMENT "Creating static device library"
)
add_custom_target(
umd_static_lib_target ALL
DEPENDS ${UMD_STATIC_LIB}
)
endif()
target_link_libraries(umd_device PUBLIC yaml-cpp::yaml-cpp rt compiler_flags)
1 change: 0 additions & 1 deletion scripts/docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apt-utils
dialog
software-properties-common=0.99.9.12
build-essential=12.8ubuntu1.1
libyaml-cpp-dev=0.6.2-4ubuntu1
git
git-lfs
pandoc
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
enable_testing()
include(GoogleTest)
add_library(test_common_libs INTERFACE)
target_link_libraries(test_common_libs INTERFACE pthread stdc++fs gtest gtest_main)
target_link_libraries(test_common_libs INTERFACE pthread gtest gtest_main)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tt_metal/tt_metal)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tt_eager)
Expand Down
Loading

0 comments on commit a0a8e5a

Please sign in to comment.