Skip to content

Commit 659d807

Browse files
jeffdailyfacebook-github-bot
authored andcommitted
add tbb as library dep explicitly in cmake (#4859)
Summary: X-link: facebookresearch/FBGEMM#1904 The existing setup.py solution is not robust and is failing to properly link when building fbgemm in torch dynamo benchmarks. Pull Request resolved: #4859 Reviewed By: ionuthristodorescu Differential Revision: D82186848 Pulled By: q10 fbshipit-source-id: 04a1315cc3215201d52fc7bd45bfa9770dd956e8
1 parent 5e8c476 commit 659d807

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

.github/scripts/utils_build.bash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,14 @@ install_build_tools () {
379379
echo "[INSTALL] Adding symlink librhash.so.0, which is needed by CMake ..."
380380
# shellcheck disable=SC2155,SC2086
381381
local conda_prefix=$(conda run ${env_prefix} printenv CONDA_PREFIX)
382-
(print_exec ln -s "${conda_prefix}/lib/librhash.so" "${conda_prefix}/lib/librhash.so.0") || return 1
382+
if [ ! -e "${conda_prefix}/lib/librhash.so.0" ]; then
383+
(print_exec ln -s "${conda_prefix}/lib/librhash.so" "${conda_prefix}/lib/librhash.so.0") || return 1
384+
fi
383385

384386
echo "[INSTALL] Adding symlink libtbb.so, which is needed by HIPCC ..."
385-
(print_exec ln -s "${conda_prefix}/lib/libtbb.so.12" "${conda_prefix}/lib/libtbb.so") || return 1
387+
if [ ! -e "${conda_prefix}/lib/libtbb.so" ]; then
388+
(print_exec ln -s "${conda_prefix}/lib/libtbb.so.12" "${conda_prefix}/lib/libtbb.so") || return 1
389+
fi
386390

387391
# For some reason, the build package for Python 3.12+ is missing from conda,
388392
# so we have to install through pip instead.

fbgemm_gpu/FbgemmGpu.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,30 @@ gpu_cpp_library(
162162
DESTINATION
163163
fbgemm_gpu)
164164

165+
# For the ROCm case on non-Nova, an explicit link to
166+
# libtbb is required, or the following error is
167+
# encountered on library load:
168+
# undefined symbol: _ZN3tbb6detail2r117deallocate_memoryEPv
169+
if (DEFINED ENV{BUILD_FROM_NOVA})
170+
message(STATUS "BUILD_FROM_NOVA is $ENV{BUILD_FROM_NOVA}.")
171+
if($ENV{BUILD_FROM_NOVA} STREQUAL "0")
172+
set(IS_NOVA FALSE)
173+
else()
174+
set(IS_NOVA TRUE)
175+
endif()
176+
else()
177+
message(STATUS "BUILD_FROM_NOVA is not defined.")
178+
set(IS_NOVA FALSE)
179+
endif()
180+
if(FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_ROCM AND NOT IS_NOVA)
181+
message(STATUS "Adding tbb as dep.")
182+
find_library(DEP_MAYBE_TBB NAMES tbb HINTS $ENV{CONDA_ENV}/lib)
183+
if(DEP_MAYBE_TBB)
184+
message(STATUS "Found tbb: ${DEP_MAYBE_TBB}")
185+
else()
186+
message(FATAL_ERROR "tbb not found")
187+
endif()
188+
endif()
165189

166190
gpu_cpp_library(
167191
PREFIX
@@ -184,5 +208,6 @@ gpu_cpp_library(
184208
fbgemm_gpu_tbe_cache
185209
fbgemm_gpu_tbe_optimizers
186210
fbgemm_gpu_tbe_utils
211+
${DEP_MAYBE_TBB}
187212
DESTINATION
188213
fbgemm_gpu)

fbgemm_gpu/setup.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,6 @@ def _get_cxx11_abi():
379379
]
380380
)
381381

382-
if self.nova_flag() is None:
383-
cxx_flags.extend(
384-
[
385-
# For the ROCm case on non-Nova, an explicit link to
386-
# libtbb is required, or the following error is
387-
# encountered on library load:
388-
#
389-
# undefined symbol: _ZN3tbb6detail2r117deallocate_memoryEPv
390-
"-ltbb",
391-
]
392-
)
393-
394382
cmake_args.extend(
395383
[
396384
f"-DCMAKE_C_FLAGS='{' '.join(cxx_flags)}'",

0 commit comments

Comments
 (0)