Skip to content

Commit

Permalink
build type selection re-vamp + cleanup (#10627)
Browse files Browse the repository at this point in the history
* #10552: remove CONFIG env variable from build infra

* #0: add check in CMake to verify that build type is legit

* #0: ignore all folders with build_ prefix as we may have 4 build folders now

* #0: remove references to CONFIG env variable and add option to switch build type + symlink build folder

* #0: change option to -b from -t

* #0: update instructions

* #0: remove ref to CONFIG env variable
  • Loading branch information
TT-billteng authored Jul 24, 2024
1 parent 29b1868 commit 116e3c0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 33 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
os: [ubuntu-20.04]
env:
ARCH_NAME: ${{ matrix.arch }}
CONFIG: ${{ matrix.build.type }}
# So we can get all the makefile output we want
VERBOSE: 1
runs-on: ${{ matrix.build.runs-on }}
Expand All @@ -38,7 +37,7 @@ jobs:
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
- name: Build tt-metal libraries
run: |
cmake -B build -G Ninja
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build.type }} -G Ninja
cmake --build build
- name: Build tt-metal C++ tests
run: |
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/eager-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
env:
TT_METAL_ENV: ${{ vars.TT_METAL_ENV }}
ARCH_NAME: ${{ inputs.arch }}
CONFIG: Release
TT_METAL_CREATE_STATIC_LIB: 1
steps:
- uses: tenstorrent-metal/metal-workflows/.github/actions/checkout-with-submodule-lfs@v2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
env:
TT_METAL_ENV: ${{ vars.TT_METAL_ENV }}
ARCH_NAME: ${{ matrix.runner-info.arch }}
CONFIG: ci
TT_METAL_WATCHER: 60
environment: dev
runs-on: ${{ matrix.runner-info.runs-on }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
env:
TT_METAL_ENV: ${{ vars.TT_METAL_ENV }}
ARCH_NAME: ${{ matrix.runner-info.arch }}
CONFIG: ci
TT_METAL_SLOW_DISPATCH_MODE: 1
TT_METAL_WATCHER: 60
environment: dev
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_hlk_args_init_gen
tt_build
tt_debug
build
build_debug
build_*
/python_env/

/llk_out/
Expand Down
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ CHECK_COMPILERS()

############################################################################################################################
# Setting build type flags
# Will default to assert build, unless CONFIG env variable is set or manually set -DCMAKE_BUILD_TYPE
# Will default to Release build unless manually set with -DCMAKE_BUILD_TYPE
############################################################################################################################
if(DEFINED ENV{CONFIG})
message(STATUS "CONFIG is set, CMAKE_BUILD_TYPE being set to $ENV{CONFIG}")
set(CMAKE_BUILD_TYPE $ENV{CONFIG})
elseif(NOT CMAKE_BUILD_TYPE)
# Define valid build types
set(VALID_BUILD_TYPES Debug Release RelWithDebInfo CI)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Release build is the default" FORCE)
endif()

# Check if the specified build type is valid
list(FIND VALID_BUILD_TYPES ${CMAKE_BUILD_TYPE} _build_type_index)

if(_build_type_index EQUAL -1)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}. Valid options are: ${VALID_BUILD_TYPES}")
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG=DEBUG")
Expand Down
37 changes: 16 additions & 21 deletions build_metal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Notes:
agnostic of the build system (Ninja or Make)
Different configs: to change build type or use tracy, you have to change the configuration cmake step (step #2)
- changing build types: `CONFIG=<type> cmake -B build -G Ninja`
- valid build_types: `Release`, `Debug`, `RelWithDebInfo`
- Release is the default if you do not set CONFIG
- changing build types: `cmake -B build -DCMAKE_BUILD_TYPE=<type> -G Ninja`
- valid CMAKE_BUILD_TYPE values: `Release`, `Debug`, `RelWithDebInfo`, `CI`
- Release is the default if you do not set CMAKE_BUILD_TYPE
- tracy: `cmake -B build -G Ninja -DENABLE_TRACY=ON`
Now you can have multiple build folders with different configs, if you want to switch just run `ninja install -C <your_build_folder` to install different pybinds
Expand All @@ -37,7 +37,7 @@ Now you can have multiple build folders with different configs, if you want to s
Example:
./create_venv.sh
cmake -B build -G Ninja && ninja -C build # <- build in Release, inside folder called `build`
CONFIG=Debug cmake -B build_debug -G Ninja && ninja -C build # <- build in Debug, inside folder called `build_debug`
cmake -DCMAKE_BUILD_TYPE=Debug -B build_debug -G Ninja && ninja -C build # <- build in Debug, inside folder called `build_debug`
source python_env/bin/activate # <- you can not run pytests yet since pybinds have not been installed
ninja install -C build # <- install Release pybinds
<run a pytest> # <- this test ran in Release config
Expand All @@ -56,12 +56,14 @@ show_help() {
echo " -h Show this help message."
echo " -e Enable CMAKE_EXPORT_COMPILE_COMMANDS."
echo " -c Enable ccache for the build."
echo " -t Set the build type. Default is Release. Other options are Debug and RelWithDebInfo."
}

# Parse CLI options
export_compile_commands="OFF"
enable_ccache="OFF"
while getopts "hec" opt; do
build_type="Release"
while getopts "hecb:" opt; do
case ${opt} in
h )
show_help
Expand All @@ -73,6 +75,9 @@ while getopts "hec" opt; do
c )
enable_ccache="ON"
;;
b )
build_type="$OPTARG"
;;
\? )
show_help
exit 1
Expand All @@ -84,27 +89,17 @@ if [ -z "$PYTHON_ENV_DIR" ]; then
PYTHON_ENV_DIR=$(pwd)/python_env
fi

if [ -z "$CONFIG" ]; then
echo "Build type defaulted to Release"
else
VALID_CONFIGS="RelWithDebInfo Debug Release ci"
if [[ $VALID_CONFIGS =~ (^|[[:space:]])"$CONFIG"($|[[:space:]]) ]]; then
echo "CONFIG set to $CONFIG"
else
echo "Invalid config "$CONFIG" given.. Valid configs are: $VALID_CONFIGS"
exit 1
fi
fi

echo "Building tt-metal"
cmake_args="-B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=$export_compile_commands"
echo "Building tt-metal in $build_type mode"
mkdir -p build_$build_type
ln -nsf build_$build_type build
cmake_args="-B build_$build_type -G Ninja -DCMAKE_BUILD_TYPE=$build_type -DCMAKE_EXPORT_COMPILE_COMMANDS=$export_compile_commands"

if [ "$enable_ccache" = "ON" ]; then
cmake_args="$cmake_args -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi

cmake $cmake_args
cmake --build build --target install # <- this is a general cmake way, can also just run `ninja install -C build`
cmake --build build_$build_type --target install # <- this is a general cmake way, can also just run `ninja install -C build`

echo "Building cpp tests"
cmake --build build --target tests # <- can also just run `ninja tests -C build`
cmake --build build_$build_type --target tests # <- can also just run `ninja tests -C build`
1 change: 0 additions & 1 deletion scripts/docker/run_docker_func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function run_docker_common {
-e TT_METAL_HOME=${TT_METAL_HOME} \
-e LOGURU_LEVEL=${LOGURU_LEVEL} \
-e LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \
-e CONFIG=${CONFIG} \
-e ARCH_NAME=${ARCH_NAME} \
-e PYTHONPATH=${TT_METAL_HOME} \
-e XDG_CACHE_HOME=${TT_METAL_HOME}/.pipcache \
Expand Down

0 comments on commit 116e3c0

Please sign in to comment.