Skip to content

Commit

Permalink
CUDA: remove the need of adiosCUDAReduceImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Feb 3, 2022
1 parent a382cc0 commit d84d5d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 483 deletions.
26 changes: 22 additions & 4 deletions source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ add_library(adios2_core
helper/adiosXML.cpp
helper/adiosXMLUtil.cpp
helper/adiosYAML.cpp
helper/adiosCUDA.cu
helper/adiosLog.cpp

#engine derived classes
Expand Down Expand Up @@ -105,10 +104,24 @@ add_library(adios2_core
set_property(TARGET adios2_core PROPERTY EXPORT_NAME core)
set_property(TARGET adios2_core PROPERTY OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUFFIX}_core)

set(maybe_adios2_core_cuda)
if(ADIOS2_HAVE_CUDA)
enable_language(CUDA)
target_link_libraries(adios2_core PRIVATE CUDA::cudart)
set_target_properties(adios2_core PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

add_library(adios2_core_cuda helper/adiosCUDA.cu)
set_target_properties(adios2_core_cuda PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_STANDARD 14
CUDA_STANDARD_REQUIRED ON
CUDA_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${ADIOS2_SOURCE_DIR}/source>;$<BUILD_INTERFACE:${ADIOS2_BINARY_DIR}/source>"
EXPORT_NAME core_cuda
OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUFFIX}_core_cuda
)

target_link_libraries(adios2_core PRIVATE adios2_core_cuda CUDA::cudart CUDA::cuda_driver)
set(maybe_adios2_core_cuda adios2_core_cuda)
endif()

target_include_directories(adios2_core
Expand Down Expand Up @@ -358,6 +371,11 @@ install(DIRECTORY core/
FILES_MATCHING PATTERN "*.h"
)

install(DIRECTORY core/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/adios2/core/ COMPONENT adios2_core-development
FILES_MATCHING PATTERN "*.cu"
)

install(DIRECTORY engine/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/adios2/engine COMPONENT adios2_core-development
FILES_MATCHING PATTERN "*/*.h"
Expand All @@ -377,7 +395,7 @@ install(DIRECTORY toolkit/
)

# Library installation
install(TARGETS adios2_core ${maybe_adios2_core_mpi} EXPORT adios2Exports
install(TARGETS adios2_core ${maybe_adios2_core_mpi} ${maybe_adios2_core_cuda} EXPORT adios2Exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT adios2_core-runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT adios2_core-libraries NAMELINK_COMPONENT adios2_core-development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT adios2_core-development
Expand Down
12 changes: 8 additions & 4 deletions source/adios2/helper/adiosCUDA.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
#define ADIOS2_HELPER_ADIOSCUDA_CU_

#include "adios2/common/ADIOSMacros.h"
#include <thrust/device_ptr.h>
#include <thrust/extrema.h>

#include "adiosCUDA.h"
#include "adiosCUDAReduceImpl.h"

namespace
{

template <class T>
void CUDAMinMaxImpl(const T *values, const size_t size, T &min, T &max)
{
min = reduce<T, MinOp>(size, 1024, 64, 1, values);
max = reduce<T, MaxOp>(size, 1024, 64, 1, values);
thrust::device_ptr<const T> dev_ptr(values);
auto res = thrust::minmax_element(dev_ptr, dev_ptr + size);
cudaMemcpy(&min, thrust::raw_pointer_cast(res.first), sizeof(T),
cudaMemcpyDeviceToHost);
cudaMemcpy(&max, thrust::raw_pointer_cast(res.second), sizeof(T),
cudaMemcpyDeviceToHost);
}
// types non supported on the device
void CUDAMinMaxImpl(const long double * /*values*/, const size_t /*size*/,
Expand Down
9 changes: 8 additions & 1 deletion source/adios2/helper/adiosCUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ namespace adios2
namespace helper
{

#ifdef _WIN32
#define ADIOS2_EXPORT __declspec(dllexport)
#else
#define ADIOS2_EXPORT __attribute__((visibility("default")))
#endif

/*
* CUDA kernel for computing the min and max from a
* GPU buffer
*/
template <class T>
void CUDAMinMax(const T *values, const size_t size, T &min, T &max);
ADIOS2_EXPORT void CUDAMinMax(const T *values, const size_t size, T &min,
T &max);

} // helper
} // adios2
Expand Down
Loading

0 comments on commit d84d5d2

Please sign in to comment.