Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ list(REMOVE_ITEM TEST_SRC_FILES ${UNMATCH_FILES})
file(GLOB_RECURSE TEST_BASE_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
set(PADDLE_TARGET_FOLDER ${CMAKE_BINARY_DIR}/paddle)

# ---------------------------------------------------------------------------
# CUDA Toolkit (needed for CUDA-specific test headers in the Torch build)
# ---------------------------------------------------------------------------
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
message(STATUS "Found CUDA Toolkit: ${CUDAToolkit_INCLUDE_DIRS}")
set(CUDA_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRS}")
elseif(EXISTS "/usr/local/cuda/include")
set(CUDA_INCLUDE_DIRS "/usr/local/cuda/include")
message(STATUS "Using default CUDA include dir: ${CUDA_INCLUDE_DIRS}")
else()
message(WARNING "CUDA headers not found; CUDA tests may not compile.")
set(CUDA_INCLUDE_DIRS "")
Comment on lines +90 to +91
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package(CUDAToolkit QUIET) falls back to a warning and continues even when CUDA headers aren’t present, but test/ops/CUDABlasTest.cpp includes CUDA-specific headers and is always part of TEST_SRC_FILES, so the build can still hard-fail at compile time. Consider either making CUDA headers a hard requirement for building this test (use REQUIRED or a dedicated option) or conditionally excluding CUDABlasTest.cpp from TEST_SRC_FILES when CUDA isn’t found.

Suggested change
message(WARNING "CUDA headers not found; CUDA tests may not compile.")
set(CUDA_INCLUDE_DIRS "")
message(STATUS
"CUDA headers not found; CUDA-specific tests (e.g. CUDABlasTest) will be skipped.")
set(CUDA_INCLUDE_DIRS "")
# Avoid compiling CUDA-dependent tests when CUDA is not available.
list(REMOVE_ITEM TEST_SRC_FILES
"${PROJECT_SOURCE_DIR}/test/ops/CUDABlasTest.cpp")

Copilot uses AI. Check for mistakes.
endif()

# ---------------------------------------------------------------------------
# Build Torch test case
# ---------------------------------------------------------------------------
Expand All @@ -87,8 +102,9 @@ set(TORCH_LIBRARIES "")
file(GLOB_RECURSE TORCH_LIBRARIES "${TORCH_DIR}/lib/*.so"
"${TORCH_DIR}/lib/*.a")

set(TORCH_INCLUDE_DIR "${TORCH_DIR}/include"
"${TORCH_DIR}/include/torch/csrc/api/include/")
set(TORCH_INCLUDE_DIR
"${TORCH_DIR}/include" "${TORCH_DIR}/include/torch/csrc/api/include/"
"${CUDA_INCLUDE_DIRS}")

set(TORCH_TARGET_FOLDER ${CMAKE_BINARY_DIR}/torch)
set(BIN_PREFIX "torch_")
Expand Down Expand Up @@ -119,7 +135,8 @@ set(PADDLE_INCLUDE_DIR
"${PADDLE_DIR}/include/third_party"
"${PADDLE_DIR}/include/paddle/phi/api/include/compat/"
"${PADDLE_DIR}/include/paddle/phi/api/include/compat/torch/csrc/api/include/"
)
"${CUDA_INCLUDE_DIRS}"
"${CUDA_INCLUDE_DIRS}/cccl")

Comment on lines +138 to 140
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CUDA_INCLUDE_DIRS is set to an empty string when CUDA headers aren’t found, but ${CUDA_INCLUDE_DIRS}/cccl will then expand to /cccl and be added as an include directory. Also, if CUDA_INCLUDE_DIRS is a CMake list (multiple include dirs), appending /cccl this way will only apply to the last element. Please guard this append (only add the cccl path when CUDA include dir is non-empty and exists) and derive the cccl subdir from a single concrete CUDA include path (e.g., the first element).

Suggested change
"${CUDA_INCLUDE_DIRS}"
"${CUDA_INCLUDE_DIRS}/cccl")
"${CUDA_INCLUDE_DIRS}")
# Append CUDA cccl include directory if available.
if(CUDA_INCLUDE_DIRS)
# CUDA_INCLUDE_DIRS may be a list; use the first element as the base path.
list(GET CUDA_INCLUDE_DIRS 0 CUDA_INCLUDE_DIRS_FIRST)
if(CUDA_INCLUDE_DIRS_FIRST AND EXISTS "${CUDA_INCLUDE_DIRS_FIRST}")
list(APPEND PADDLE_INCLUDE_DIR "${CUDA_INCLUDE_DIRS_FIRST}/cccl")
endif()
endif()

Copilot uses AI. Check for mistakes.
set(PADDLE_LIBRARIES
"${PADDLE_DIR}/base/libpaddle.so" "${PADDLE_DIR}/libs/libcommon.so"
Expand Down
14 changes: 14 additions & 0 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ function(
message(STATUS "include dir: ${INCLUDE_DIR}")
target_compile_definitions(${_test_name}
PRIVATE USE_PADDLE_API=${USE_PADDLE_API})
if(${USE_PADDLE_API})
# Paddle's CUDA compat headers (CUDAContextLight.h, CUDAFunctions.h)
# require PADDLE_WITH_CUDA to be defined so that GPU type aliases
# (gpuStream_t, cudaDeviceProp) are resolved via cuda_runtime.h.
target_compile_definitions(${_test_name} PRIVATE PADDLE_WITH_CUDA)
# Link libcudart for CUDA runtime symbols used by the Paddle CUDA compat
# layer.
if(TARGET CUDA::cudart)
target_link_libraries(${_test_name} CUDA::cudart)
elseif(EXISTS "/usr/local/cuda/lib64/libcudart.so")
target_link_libraries(${_test_name}
"/usr/local/cuda/lib64/libcudart.so")
endif()
Comment on lines +27 to +38
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unconditionally defines PADDLE_WITH_CUDA for all Paddle builds (USE_PADDLE_API=1), even if the detected Paddle installation is CPU-only or ROCm/HIP-based. That can force inclusion of CUDA-only types/headers and break compilation. Please gate PADDLE_WITH_CUDA (and the cudart linking) on actually having CUDA headers/libraries available (e.g., CUDAToolkit_FOUND / TARGET CUDA::cudart), or make the CUDA-dependent tests opt-in/out explicitly.

Suggested change
# Paddle's CUDA compat headers (CUDAContextLight.h, CUDAFunctions.h)
# require PADDLE_WITH_CUDA to be defined so that GPU type aliases
# (gpuStream_t, cudaDeviceProp) are resolved via cuda_runtime.h.
target_compile_definitions(${_test_name} PRIVATE PADDLE_WITH_CUDA)
# Link libcudart for CUDA runtime symbols used by the Paddle CUDA compat
# layer.
if(TARGET CUDA::cudart)
target_link_libraries(${_test_name} CUDA::cudart)
elseif(EXISTS "/usr/local/cuda/lib64/libcudart.so")
target_link_libraries(${_test_name}
"/usr/local/cuda/lib64/libcudart.so")
endif()
# Only enable Paddle's CUDA pathways when CUDA is actually available.
# This prevents defining PADDLE_WITH_CUDA for CPU-only or ROCm builds,
# which would otherwise pull in CUDA-only headers/types and break
# compilation.
set(_paddle_cuda_available OFF)
if(CUDAToolkit_FOUND)
set(_paddle_cuda_available ON)
elseif(TARGET CUDA::cudart)
set(_paddle_cuda_available ON)
elseif(EXISTS "/usr/local/cuda/include/cuda.h"
AND EXISTS "/usr/local/cuda/lib64/libcudart.so")
set(_paddle_cuda_available ON)
endif()
if(_paddle_cuda_available)
# Paddle's CUDA compat headers (CUDAContextLight.h, CUDAFunctions.h)
# require PADDLE_WITH_CUDA to be defined so that GPU type aliases
# (gpuStream_t, cudaDeviceProp) are resolved via cuda_runtime.h.
target_compile_definitions(${_test_name} PRIVATE PADDLE_WITH_CUDA)
# Link libcudart for CUDA runtime symbols used by the Paddle CUDA
# compat layer.
if(TARGET CUDA::cudart)
target_link_libraries(${_test_name} CUDA::cudart)
elseif(EXISTS "/usr/local/cuda/lib64/libcudart.so")
target_link_libraries(${_test_name}
"/usr/local/cuda/lib64/libcudart.so")
endif()
else()
message(WARNING
"USE_PADDLE_API is enabled, but CUDA toolkit was not detected; "
"skipping PADDLE_WITH_CUDA definition and cudart linkage for "
"test target ${_test_name}.")
endif()

Copilot uses AI. Check for mistakes.
endif()
message(STATUS "USE_PADDLE_API: ${USE_PADDLE_API}")
add_test(NAME ${_test_name} COMMAND ${_test_name})
set_tests_properties(${_test_name} PROPERTIES TIMEOUT 5)
Expand Down
Loading
Loading