Skip to content
Merged
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
8 changes: 7 additions & 1 deletion symforce/caspar/source/runtime/cuda_to_hip.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

#if defined(USE_HIP) || defined(__HIP_PLATFORM_AMD__)

#include <hip/hip_cooperative_groups.h>
#include <hip/hip_runtime.h>

// Host-only translation units (e.g. code using the generated headers) get just the runtime API.
#if defined(__HIPCC__)
#include <hip/hip_cooperative_groups.h>
#include <hipcub/hipcub.hpp>
#endif

// CUDA runtime API -> HIP runtime API
#define cudaMalloc hipMalloc
Expand Down Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions symforce/caspar/source/runtime/sort_indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <sys/types.h>
#include <cstddef>

#if defined(USE_HIP) || defined(__HIP_PLATFORM_AMD__)
#include <hip/hip_runtime.h>
Expand All @@ -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
3 changes: 3 additions & 0 deletions symforce/caspar/source/templates/solver.cc.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <stdexcept>
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <string>
#include <utility>

#include "caspar_mappings.h"
#include "shared_indices.h"
Expand Down
15 changes: 12 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<TARGET_PROPERTY:hip::hipcub,INTERFACE_INCLUDE_DIRECTORIES>
)
endif()

# Each caspar_<name>_cuda_test.cc runs the code generated into symforce_caspar_<name>_test,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include <algorithm>
#include <chrono>
#include <cstdio>
#include <stdexcept>
#include <string>
#include <utility>

#include "caspar_mappings.h"
#include "kernel_Matrix21_alpha_denominator_or_beta_numerator.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include <algorithm>
#include <chrono>
#include <cstdio>
#include <stdexcept>
#include <string>
#include <utility>

#include "caspar_mappings.h"
#include "kernel_ChainA_alpha_denominator_or_beta_numerator.h"
Expand Down