diff --git a/symforce/caspar/source/runtime/cuda_to_hip.h b/symforce/caspar/source/runtime/cuda_to_hip.h index a8d959f8..122b886b 100644 --- a/symforce/caspar/source/runtime/cuda_to_hip.h +++ b/symforce/caspar/source/runtime/cuda_to_hip.h @@ -13,9 +13,13 @@ #if defined(USE_HIP) || defined(__HIP_PLATFORM_AMD__) -#include #include + +// Host-only translation units (e.g. code using the generated headers) get just the runtime API. +#if defined(__HIPCC__) +#include #include +#endif // CUDA runtime API -> HIP runtime API #define cudaMalloc hipMalloc @@ -48,8 +52,10 @@ inline hipError_t cudaFuncSetAttribute(T* func, hipFuncAttribute attr, int value // so atomicAdd_block is equivalent to atomicAdd on shared memory. #define atomicAdd_block atomicAdd +#if defined(__HIPCC__) // CUB -> hipCUB namespace namespace cub = hipcub; +#endif #else // CUDA path diff --git a/symforce/caspar/source/runtime/sort_indices.h b/symforce/caspar/source/runtime/sort_indices.h index 180be9b7..700622d8 100644 --- a/symforce/caspar/source/runtime/sort_indices.h +++ b/symforce/caspar/source/runtime/sort_indices.h @@ -5,7 +5,7 @@ #pragma once -#include +#include #if defined(USE_HIP) || defined(__HIP_PLATFORM_AMD__) #include @@ -17,15 +17,16 @@ namespace caspar { size_t SortIndicesGetTmpNbytes(size_t problem_size); -void SortIndices(void* tmp_storage, size_t tmp_storage_bytes, const uint* keys_in, uint* sorted_out, - uint* target_out, uint* argsort_out, size_t problem_size); +void SortIndices(void* tmp_storage, size_t tmp_storage_bytes, const unsigned int* keys_in, + unsigned int* sorted_out, unsigned int* target_out, unsigned int* argsort_out, + size_t problem_size); size_t SortKeysGetTmpNbytes(size_t problem_size); -void SortKeys(void* tmp_storage, size_t tmp_storage_bytes, const uint* keys_in, uint* sorted_out, - size_t problem_size); +void SortKeys(void* tmp_storage, size_t tmp_storage_bytes, const unsigned int* keys_in, + unsigned int* sorted_out, size_t problem_size); -void SelectIndex(const uint* const input, const uint* const selections, uint* const output, - size_t problem_size); +void SelectIndex(const unsigned int* const input, const unsigned int* const selections, + unsigned int* const output, size_t problem_size); } // namespace caspar diff --git a/symforce/caspar/source/templates/solver.cc.jinja b/symforce/caspar/source/templates/solver.cc.jinja index 866a31ef..1119f1a5 100644 --- a/symforce/caspar/source/templates/solver.cc.jinja +++ b/symforce/caspar/source/templates/solver.cc.jinja @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "caspar_mappings.h" #include "shared_indices.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce003cdd..3d1892f4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -114,7 +114,12 @@ if(CMAKE_CUDA_COMPILER OR CMAKE_HIP_COMPILER) get_target_property(CASPAR_RUNTIME_SOURCES caspar_test_runtime SOURCES) set_source_files_properties(${CASPAR_RUNTIME_SOURCES} PROPERTIES LANGUAGE HIP) target_compile_definitions(caspar_test_runtime PUBLIC USE_HIP) - target_link_libraries(caspar_test_runtime PUBLIC hip::host hip::hipcub) + # hip::hipcub also carries hip::device, whose -x hip would reach the host-compiled .cc test + # sources below. hipCUB and rocPRIM are header-only, so take just their headers. + target_link_libraries(caspar_test_runtime PUBLIC hip::host roc::rocprim) + target_include_directories(caspar_test_runtime PUBLIC + $ + ) endif() # Each caspar__cuda_test.cc runs the code generated into symforce_caspar__test, @@ -137,8 +142,12 @@ if(CMAKE_CUDA_COMPILER OR CMAKE_HIP_COMPILER) add_executable(${TARGET_NAME} ${SOURCE_FILE} ${DATA_SOURCES}) if(CMAKE_HIP_COMPILER) - # The test and generated .cc files include the HIP runtime too. - set_source_files_properties(${SOURCE_FILE} ${DATA_SOURCES} PROPERTIES LANGUAGE HIP) + # Only the .cu files are HIP. The test and generated .cc files stay with the host C++ + # compiler, as in the CUDA build, so the generated headers are checked to be includable + # from host code. + set(HIP_SOURCES ${DATA_SOURCES}) + list(FILTER HIP_SOURCES INCLUDE REGEX "\\.cu$") + set_source_files_properties(${HIP_SOURCES} PROPERTIES LANGUAGE HIP) endif() set_target_properties(${TARGET_NAME} PROPERTIES CUDA_ARCHITECTURES 75 diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/solver.cc b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/solver.cc index e910f2c6..266df822 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/solver.cc +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/solver.cc @@ -2,7 +2,10 @@ #include #include +#include #include +#include +#include #include "caspar_mappings.h" #include "kernel_Matrix21_alpha_denominator_or_beta_numerator.h" diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/solver.cc b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/solver.cc index e82e6cd0..69b3b22b 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/solver.cc +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/solver.cc @@ -2,7 +2,10 @@ #include #include +#include #include +#include +#include #include "caspar_mappings.h" #include "kernel_ChainA_alpha_denominator_or_beta_numerator.h"