Skip to content

Commit 3ec271b

Browse files
committed
add CUDABlas related API tests
1 parent 4a2ec44 commit 3ec271b

File tree

3 files changed

+600
-3
lines changed

3 files changed

+600
-3
lines changed

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ list(REMOVE_ITEM TEST_SRC_FILES ${UNMATCH_FILES})
7676
file(GLOB_RECURSE TEST_BASE_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
7777
set(PADDLE_TARGET_FOLDER ${CMAKE_BINARY_DIR}/paddle)
7878

79+
# ---------------------------------------------------------------------------
80+
# CUDA Toolkit (needed for CUDA-specific test headers in the Torch build)
81+
# ---------------------------------------------------------------------------
82+
find_package(CUDAToolkit QUIET)
83+
if(CUDAToolkit_FOUND)
84+
message(STATUS "Found CUDA Toolkit: ${CUDAToolkit_INCLUDE_DIRS}")
85+
set(CUDA_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRS}")
86+
elseif(EXISTS "/usr/local/cuda/include")
87+
set(CUDA_INCLUDE_DIRS "/usr/local/cuda/include")
88+
message(STATUS "Using default CUDA include dir: ${CUDA_INCLUDE_DIRS}")
89+
else()
90+
message(WARNING "CUDA headers not found; CUDA tests may not compile.")
91+
set(CUDA_INCLUDE_DIRS "")
92+
endif()
93+
7994
# ---------------------------------------------------------------------------
8095
# Build Torch test case
8196
# ---------------------------------------------------------------------------
@@ -87,8 +102,9 @@ set(TORCH_LIBRARIES "")
87102
file(GLOB_RECURSE TORCH_LIBRARIES "${TORCH_DIR}/lib/*.so"
88103
"${TORCH_DIR}/lib/*.a")
89104

90-
set(TORCH_INCLUDE_DIR "${TORCH_DIR}/include"
91-
"${TORCH_DIR}/include/torch/csrc/api/include/")
105+
set(TORCH_INCLUDE_DIR
106+
"${TORCH_DIR}/include" "${TORCH_DIR}/include/torch/csrc/api/include/"
107+
"${CUDA_INCLUDE_DIRS}")
92108

93109
set(TORCH_TARGET_FOLDER ${CMAKE_BINARY_DIR}/torch)
94110
set(BIN_PREFIX "torch_")
@@ -119,7 +135,8 @@ set(PADDLE_INCLUDE_DIR
119135
"${PADDLE_DIR}/include/third_party"
120136
"${PADDLE_DIR}/include/paddle/phi/api/include/compat/"
121137
"${PADDLE_DIR}/include/paddle/phi/api/include/compat/torch/csrc/api/include/"
122-
)
138+
"${CUDA_INCLUDE_DIRS}"
139+
"${CUDA_INCLUDE_DIRS}/cccl")
123140

124141
set(PADDLE_LIBRARIES
125142
"${PADDLE_DIR}/base/libpaddle.so" "${PADDLE_DIR}/libs/libcommon.so"

cmake/build.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ function(
2323
message(STATUS "include dir: ${INCLUDE_DIR}")
2424
target_compile_definitions(${_test_name}
2525
PRIVATE USE_PADDLE_API=${USE_PADDLE_API})
26+
if(${USE_PADDLE_API})
27+
# Paddle's CUDA compat headers (CUDAContextLight.h, CUDAFunctions.h)
28+
# require PADDLE_WITH_CUDA to be defined so that GPU type aliases
29+
# (gpuStream_t, cudaDeviceProp) are resolved via cuda_runtime.h.
30+
target_compile_definitions(${_test_name} PRIVATE PADDLE_WITH_CUDA)
31+
# Link libcudart for CUDA runtime symbols used by the Paddle CUDA compat
32+
# layer.
33+
if(TARGET CUDA::cudart)
34+
target_link_libraries(${_test_name} CUDA::cudart)
35+
elseif(EXISTS "/usr/local/cuda/lib64/libcudart.so")
36+
target_link_libraries(${_test_name}
37+
"/usr/local/cuda/lib64/libcudart.so")
38+
endif()
39+
endif()
2640
message(STATUS "USE_PADDLE_API: ${USE_PADDLE_API}")
2741
add_test(NAME ${_test_name} COMMAND ${_test_name})
2842
set_tests_properties(${_test_name} PROPERTIES TIMEOUT 5)

0 commit comments

Comments
 (0)