Skip to content

Commit 784dd71

Browse files
authored
Merge pull request FloopCZ#201 from Youw/require_cuda_option
add option REQUIRE_CUDA
2 parents fe14c43 + 9310db5 commit 784dd71

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tensorflow_cc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project(
99
# If enabled, bazel has to be installed.
1010
option(TENSORFLOW_SHARED "Build shared library (required for GPU support)." OFF)
1111
option(ALLOW_CUDA "When building the shared library, try to find and use CUDA." ON)
12+
option(REQUIRE_CUDA "When building the shared library, make sure to find and use CUDA (implies ALLOW_CUDA)." OFF)
1213
option(TENSORFLOW_STATIC "Build static library." ON)
1314
set(TENSORFLOW_TAG "v1.15.0" CACHE STRING "The tensorflow release tag to be checked out (default v1.15.0).")
1415
option(SYSTEM_PROTOBUF "Use system protobuf instead of static protobuf from contrib/makefile." OFF)

tensorflow_cc/cmake/build_tensorflow.sh.in

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,25 @@ export PYTHON_BIN_PATH=${PYTHON_BIN_PATH:-"$(which python3)"}
3333
export PYTHON_LIB_PATH="$($PYTHON_BIN_PATH -c 'import site; print(site.getsitepackages()[0])')"
3434

3535
# check if cuda support requested and supported
36-
if [ "@ALLOW_CUDA@" = "ON" ] && hash nvcc 2>/dev/null; then
36+
cuda_available=false
37+
if hash nvcc 2>/dev/null; then
38+
cuda_available=true
39+
fi
40+
41+
cuda_allowed=false
42+
if [ "@ALLOW_CUDA@" = "ON" ]; then
43+
cuda_allowed=true
44+
fi
45+
46+
if [ "@REQUIRE_CUDA@" = "ON" ]; then
47+
cuda_allowed=true
48+
if [ "$cuda_available" != true ]; then
49+
echo "CUDA support is required but not available in the system (nvcc not found)"
50+
exit 1
51+
fi
52+
fi
53+
54+
if [ "$cuda_allowed" == true ] && [ "$cuda_available" == true ]; then
3755
echo "CUDA support enabled"
3856
cuda_config_opts="--config=cuda"
3957
export TF_NEED_CUDA=1

0 commit comments

Comments
 (0)