Skip to content

Commit 051ad3c

Browse files
committed
fix
1 parent 2655a95 commit 051ad3c

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

source/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT)
356356
endif()
357357
endif()
358358
find_package(Torch REQUIRED)
359+
# TorchConfig populates TORCH_CUDA_LIBRARIES only when PyTorch itself was
360+
# built with CUDA. The fused graph-lower operators in op/pt include ATen CUDA
361+
# headers and link libtorch_cuda, so they can be compiled only against a
362+
# CUDA-enabled PyTorch: a CPU-only wheel ships the ATen/c10 CUDA headers but
363+
# neither the generated c10/cuda/impl/cuda_cmake_macros.h nor libtorch_cuda.
364+
if(TORCH_CUDA_LIBRARIES)
365+
set(DEEPMD_TORCH_HAS_CUDA TRUE)
366+
else()
367+
set(DEEPMD_TORCH_HAS_CUDA FALSE)
368+
endif()
359369
if(NOT Torch_VERSION VERSION_LESS "2.1.0")
360370
set_if_higher(CMAKE_CXX_STANDARD 17)
361371
elseif(NOT Torch_VERSION VERSION_LESS "1.5.0")

source/op/pt/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
file(GLOB OP_SRC print_summary.cc comm.cc tabulate_multi_device.cc)
2-
# Fused graph-lower inference operators (CUDA / cuBLAS); GPU builds only. The
3-
# CUDA language is scoped per directory, so it must be enabled here: the sibling
4-
# GPU library turns it on only within its own subtree, which does not cover this
5-
# target.
6-
if(USE_CUDA_TOOLKIT)
2+
# Fused graph-lower inference operators (CUDA / cuBLAS). They include ATen CUDA
3+
# headers and link libtorch_cuda, so they build only against a CUDA-enabled
4+
# PyTorch (DEEPMD_TORCH_HAS_CUDA); against a CPU-only torch they are omitted and
5+
# the Python dispatch falls back to the reference path (see
6+
# deepmd.kernels.cuda.*.op_available). The CUDA language is scoped per
7+
# directory, so it must be enabled here: the sibling GPU library turns it on
8+
# only within its own subtree, which does not cover this target.
9+
if(USE_CUDA_TOOLKIT AND DEEPMD_TORCH_HAS_CUDA)
710
find_package(CUDAToolkit REQUIRED)
811
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
912
# CUDA 12.9 and 13.x CCCL fail to compile CUB/Thrust with -arch=all.
@@ -28,7 +31,7 @@ endif()
2831
add_library(deepmd_op_pt MODULE ${OP_SRC})
2932
# link: libdeepmd libtorch
3033
target_link_libraries(deepmd_op_pt PRIVATE ${TORCH_LIBRARIES})
31-
if(USE_CUDA_TOOLKIT)
34+
if(USE_CUDA_TOOLKIT AND DEEPMD_TORCH_HAS_CUDA)
3235
target_link_libraries(deepmd_op_pt PRIVATE CUDA::cublas)
3336
# libtorch headers require C++17; the CUDA sources must match.
3437
set_target_properties(deepmd_op_pt PROPERTIES CUDA_STANDARD 17

0 commit comments

Comments
 (0)