Skip to content

Commit

Permalink
Adding a toolchain file (#15581)
Browse files Browse the repository at this point in the history
  • Loading branch information
blozano-tt authored Jan 22, 2025
1 parent 6e2fd36 commit de53975
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 60 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/all-static-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ jobs:
# TODO: Use a lukka/run-cmake with a preset after upgrading to a more modern CMake
run: |
echo "Checking compatibility with $(cmake --version)"
cmake -B build .
# FIXME: Why is HAVE_STD_REGEX needed? Clean up when we solve it.
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake -DHAVE_STD_REGEX=ON -B build .
clang-tidy:
runs-on: ubuntu-latest
container: ghcr.io/tenstorrent/tt-metal/tt-metalium/ubuntu-22.04-amd64:latest
Expand Down Expand Up @@ -157,7 +158,7 @@ jobs:
sudo ln -s $(which clang-tidy-17) /usr/local/bin/clang-tidy
- name: Prepare compile_commands.json
run: |
ARCH_NAME=grayskull cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON -DTT_METAL_BUILD_TESTS=ON -DTTNN_BUILD_TESTS=ON -DTT_UMD_BUILD_TESTS=ON -DTT_UNITY_BUILDS=OFF
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON -DTT_METAL_BUILD_TESTS=ON -DTTNN_BUILD_TESTS=ON -DTT_UNITY_BUILDS=OFF -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake
- name: 'Install jq'
uses: dcarbone/install-jq-action@v2
- name: Create results directory
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ jobs:
fail-fast: false
matrix:
build: [
{type: Debug, cxx_compiler: clang++-17, c_compiler: clang-17, runs-on: ["build", "in-service"], os: ubuntu-20.04},
{type: RelWithDebInfo, cxx_compiler: clang++-17, c_compiler: clang-17, runs-on: ["build", "in-service"], os: ubuntu-20.04},
#{type: Debug, cxx_compiler: clang++-17, c_compiler: clang-17, runs-on: ["build", "in-service"], os: ubuntu-22.04},
#{type: RelWithDebInfo, cxx_compiler: clang++-17, c_compiler: clang-17, runs-on: ["build", "in-service"], os: ubuntu-22.04},
{type: Release, cxx_compiler: clang++-17, c_compiler: clang-17, runs-on: ["build", "in-service"], os: ubuntu-22.04},
#{type: Debug, cxx_compiler: g++-12, c_compiler: gcc-12, runs-on: ["build", "in-service"], os: ubuntu-22.04},
#{type: RelWithDebInfo, cxx_compiler: g++-12, c_compiler: gcc-12, runs-on: ["build", "in-service"], os: ubuntu-22.04},
{type: Release, cxx_compiler: g++-12, c_compiler: gcc-12, runs-on: ["build", "in-service"], os: ubuntu-22.04},
{type: Debug, toolchain: cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake, runs-on: ["build", "in-service"], os: ubuntu-20.04},
{type: RelWithDebInfo, toolchain: cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake, runs-on: ["build", "in-service"], os: ubuntu-20.04},
{type: Release, toolchain: cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake, runs-on: ["build", "in-service"], os: ubuntu-22.04},
{type: Release, toolchain: cmake/x86_64-linux-clang-17-libstdcpp-toolchain.cmake, runs-on: ["build", "in-service"], os: ubuntu-22.04},
{type: Release, toolchain: cmake/x86_64-linux-gcc-12-toolchain.cmake, runs-on: ["build", "in-service"], os: ubuntu-22.04},
]
env:
# So we can get all the makefile output we want
VERBOSE: 1
runs-on: ${{ matrix.build.runs-on }}
name: ${{ matrix.build.type }} ${{ matrix.build.cxx_compiler }} any ${{ matrix.build.os }}
name: ${{ matrix.build.type }} ${{ matrix.build.toolchain }} any ${{ matrix.build.os }}
steps:
- name: Verify ccache availability
shell: bash
Expand Down Expand Up @@ -70,7 +67,7 @@ jobs:
# NOTE: may be inaccurate if we have >1 build runner on the same machine, using the same local cache
ccache -z
build_command="./build_metal.sh --build-type ${{ matrix.build.type }} --cxx-compiler-path ${{ matrix.build.cxx_compiler }} --c-compiler-path ${{ matrix.build.c_compiler }} --build-tests --build-programming-examples --disable-unity-builds --enable-ccache"
build_command="./build_metal.sh --build-type ${{ matrix.build.type }} --toolchain-path ${{ matrix.build.toolchain }} --build-tests --build-programming-examples --disable-unity-builds --enable-ccache"
nice -n 19 $build_command
ccache --show-stats
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cpp-ttnn-project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ jobs:
run: |
set -eu # basic shell hygiene
mkdir -p build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake ..
ninja
2 changes: 1 addition & 1 deletion .github/workflows/tg-unit-tests-impl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
- name: Build UMD device and tests
run: |
cmake -B build -G Ninja -DTT_UMD_BUILD_TESTS=ON
cmake -B build -G Ninja -DTT_UMD_BUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake
cmake --build build --target umd_tests
- name: Run UMD unit regression tests
timeout-minutes: 10
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/umd-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
- name: Build UMD device and tests
run: |
cmake -B build -G Ninja -DTT_UMD_BUILD_TESTS=ON
cmake -B build -G Ninja -DTT_UMD_BUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake
cmake --build build --target umd_tests
- name: Run UMD unit tests
timeout-minutes: ${{ inputs.timeout }}
Expand Down
37 changes: 9 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ endif()
############################################
include(cmake/compilers.cmake)

if(DEFINED ENV{CMAKE_C_COMPILER} AND DEFINED ENV{CMAKE_CXX_COMPILER})
message(STATUS "Setting C and C++ compiler from environment variables")
set(CMAKE_C_COMPILER $ENV{CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER $ENV{CMAKE_CXX_COMPILER})
endif()

if(CMAKE_CXX_COMPILER AND CMAKE_C_COMPILER)
message(STATUS "Using specifed C++ compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "Using specifed C compiler: ${CMAKE_C_COMPILER}")
else()
message(STATUS "No C or C++ compiler specified, defaulting to Clang-17")
FIND_AND_SET_CLANG17()
endif()

list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(version)
ParseGitDescribe()
Expand All @@ -45,6 +31,12 @@ if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
)
endif()

if(DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE)
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
else()
message(STATUS "CMAKE_TOOLCHAIN_FILE is not set.")
endif()

include(project_options)
include(unity)
include(clang-tidy)
Expand All @@ -53,21 +45,9 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(ENABLE_LIBCXX)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>)
#add_link_options(
# $<$<LINK_LANG_AND_ID:CXX,Clang>:-lc++>
# $<$<LINK_LANG_AND_ID:CXX,Clang>:-lc++abi>
#)
else()
if(NOT ENABLE_LIBCXX)
# required when linking with libstdc++ with clang and gcc
add_compile_options(-fsized-deallocation)
endif()

# Using below until we can move to CMake >= 3.18 for LINK_LANG_AND_ID
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ENABLE_LIBCXX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++ -lc++abi")
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:-fsized-deallocation>)
endif()

include(CTest)
Expand Down Expand Up @@ -115,6 +95,7 @@ set(CMAKE_CXX_FLAGS_CI "-O3 -DDEBUG")
# Project Options
# The following options and their defaults impact what artifacts get built
############################################################################################################################
message(STATUS "ENABLE_LIBCXX: ${ENABLE_LIBCXX}")
message(STATUS "Build shared libs: ${BUILD_SHARED_LIBS}")
message(STATUS "Build with ASAN: ${ENABLE_ASAN}")
message(STATUS "Build with MSAN: ${ENABLE_MSAN}")
Expand Down
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"CMAKE_DISABLE_PRECOMPILE_HEADERS": {"value": "TRUE"},
"ENABLE_CCACHE": {"value": "TRUE"},
"TT_UNITY_BUILDS": {"value": "FALSE"}
}
},
"toolchainFile": "cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake"
},
{
"name": "clang-tidy",
Expand Down
45 changes: 44 additions & 1 deletion build_metal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ show_help() {
echo " --cxx-compiler-path Set path to C++ compiler."
echo " --c-compiler-path Set path to C++ compiler."
echo " --ttnn-shared-sub-libs Use shared libraries for ttnn."
echo " --toolchain-path Set path to CMake toolchain file."
}

clean() {
Expand Down Expand Up @@ -61,11 +62,44 @@ build_all="OFF"
cxx_compiler_path=""
c_compiler_path=""
ttnn_shared_sub_libs="OFF"
toolchain_path="cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake"

declare -a cmake_args

OPTIONS=h,e,c,t,a,m,s,u,b:,p
LONGOPTIONS=help,build-all,export-compile-commands,enable-ccache,enable-time-trace,enable-asan,enable-msan,enable-tsan,enable-ubsan,build-type:,enable-profiler,install-prefix:,build-tests,build-ttnn-tests,build-metal-tests,build-umd-tests,build-programming-examples,build-tt-train,build-static-libs,disable-unity-builds,release,development,debug,clean,cxx-compiler-path:,c-compiler-path:,ttnn-shared-sub-libs
LONGOPTIONS="
help
build-all
export-compile-commands
enable-ccache
enable-time-trace
enable-asan
enable-msan
enable-tsan
enable-ubsan
build-type:
enable-profiler
install-prefix:
build-tests
build-ttnn-tests
build-metal-tests
build-umd-tests
build-programming-examples
build-tt-train
build-static-libs
disable-unity-builds
release
development
debug
clean
cxx-compiler-path:
c-compiler-path:
ttnn-shared-sub-libs
toolchain-path:
"

# Flatten LONGOPTIONS into a comma-separated string for getopt
LONGOPTIONS=$(echo "$LONGOPTIONS" | tr '\n' ',' | sed 's/,$//')

# Parse the options
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
Expand Down Expand Up @@ -125,6 +159,8 @@ while true; do
cxx_compiler_path="$2";shift;;
--c-compiler-path)
c_compiler_path="$2";shift;;
--toolchain-path)
toolchain_path="$2";shift;;
--release)
build_type="Release";;
--development)
Expand Down Expand Up @@ -279,6 +315,13 @@ if [ "$build_all" = "ON" ]; then
cmake_args+=("-DBUILD_TT_TRAIN=ON")
fi

# toolchain and cxx_compiler settings would conflict with eachother
# only use toolchain if not setting cxx compiler directly
if [ "$cxx_compiler_path" == "" ]; then
echo "INFO: CMAKE_TOOLCHAIN_FILE: $toolchain_path"
cmake_args+=("-DCMAKE_TOOLCHAIN_FILE=${toolchain_path}")
fi

# Create and link the build directory
mkdir -p $build_dir
ln -nsf $build_dir build
Expand Down
14 changes: 1 addition & 13 deletions cmake/compilers.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
function(FIND_AND_SET_CLANG17)
find_program(CLANGPP_17 clang++-17)
find_program(CLANG_17 clang-17)

if(NOT CLANGPP_17 OR NOT CLANG_17)
message(FATAL_ERROR "Clang-17 not found. Make sure you have clang-17 and clang++-17 installed and in your PATH")
endif()

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

function(CHECK_COMPILERS)
message(STATUS "Checking compilers")

Expand All @@ -34,6 +22,6 @@ function(CHECK_COMPILERS)
message(WARNING "Only GCC-12 is tested right now")
endif()
else()
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID} ! Only Clang and GCC are supported")
message(WARNING "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID} ! Only Clang and GCC are supported")
endif()
endfunction()
2 changes: 1 addition & 1 deletion cmake/project_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
option(WITH_PYTHON_BINDINGS "Enables build of python bindings" ON)
option(ENABLE_CODE_TIMERS "Enable code timers" OFF)
option(ENABLE_TRACY "Enable Tracy Profiling" OFF)
option(ENABLE_LIBCXX "Enable using libc++" ON)
option(ENABLE_LIBCXX "Enable using libc++" OFF)
option(ENABLE_BUILD_TIME_TRACE "Enable build time trace (Clang only -ftime-trace)" OFF)
option(BUILD_SHARED_LIBS "Create shared libraries" ON)
option(ENABLE_ASAN "Enable build with AddressSanitizer" OFF)
Expand Down
12 changes: 12 additions & 0 deletions cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER clang-17 CACHE INTERNAL "C compiler")

set(CMAKE_CXX_COMPILER clang++-17 CACHE INTERNAL "C++ compiler")

set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-lc++ -lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-lc++ -lc++abi")

# Use for configure time
set(ENABLE_LIBCXX TRUE CACHE INTERNAL "Using clang's libc++")
8 changes: 8 additions & 0 deletions cmake/x86_64-linux-clang-17-libstdcpp-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER clang-17 CACHE INTERNAL "C compiler")

set(CMAKE_CXX_COMPILER clang++-17 CACHE INTERNAL "C++ compiler")

# Use for configure time
set(ENABLE_LIBCXX FALSE CACHE INTERNAL "Using clang's libc++")
8 changes: 8 additions & 0 deletions cmake/x86_64-linux-gcc-12-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER gcc-12 CACHE INTERNAL "C compiler")

set(CMAKE_CXX_COMPILER g++-12 CACHE INTERNAL "C++ compiler")

# Use for configure time
set(ENABLE_LIBCXX FALSE CACHE INTERNAL "Using clang's libc++")
9 changes: 8 additions & 1 deletion dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ CPMAddPackage(
# benchmark : https://github.com/google/benchmark
############################################################################################################################

CPMAddPackage(NAME benchmark GITHUB_REPOSITORY google/benchmark GIT_TAG v1.9.1)
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
GIT_TAG v1.9.1
OPTIONS
"BENCHMARK_USE_LIBCXX ${ENABLE_LIBCXX}"
"BENCHMARK_ENABLE_TESTING OFF"
)

if(benchmark_ADDED)
set_target_properties(
Expand Down

0 comments on commit de53975

Please sign in to comment.