File indexing completed on 2025-01-18 09:12:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "Acts/Plugins/Cuda/Seeding2/Details/Types.hpp"
0011 #include "Acts/Plugins/Cuda/Utilities/Arrays.hpp"
0012 #include "Acts/Plugins/Cuda/Utilities/MemoryManager.hpp"
0013
0014 #include "ErrorCheck.cuh"
0015 #include "StreamHandlers.cuh"
0016
0017
0018 #include <cuda_runtime.h>
0019
0020
0021 #include <cstdlib>
0022
0023 namespace Acts {
0024 namespace Cuda {
0025 namespace Details {
0026
0027 void DeviceArrayDeleter::operator()(void*) {
0028
0029
0030 return;
0031 }
0032
0033 void HostArrayDeleter::operator()(void* ptr) {
0034
0035 if (ptr == nullptr) {
0036 return;
0037 }
0038
0039
0040 free(ptr);
0041 return;
0042 }
0043
0044 }
0045
0046 template <typename T>
0047 device_array<T> make_device_array(std::size_t size) {
0048
0049 T* ptr = nullptr;
0050 if (size != 0) {
0051 ptr = static_cast<T*>(MemoryManager::instance().allocate(size * sizeof(T)));
0052 }
0053
0054 return device_array<T>(ptr);
0055 }
0056
0057 template <typename T>
0058 host_array<T> make_host_array(std::size_t size) {
0059
0060 T* ptr = nullptr;
0061 if (size != 0) {
0062 ptr = static_cast<T*>(malloc(size * sizeof(T)));
0063 }
0064
0065 return host_array<T>(ptr);
0066 }
0067
0068 template <typename T>
0069 void copyToDevice(device_array<T>& dev, const host_array<T>& host,
0070 std::size_t arraySize) {
0071 ACTS_CUDA_ERROR_CHECK(cudaMemcpy(dev.get(), host.get(), arraySize * sizeof(T),
0072 cudaMemcpyHostToDevice));
0073 return;
0074 }
0075
0076 template <typename T>
0077 void copyToDevice(device_array<T>& dev, const host_array<T>& host,
0078 std::size_t arraySize, const StreamWrapper& stream) {
0079 ACTS_CUDA_ERROR_CHECK(
0080 cudaMemcpyAsync(dev.get(), host.get(), arraySize * sizeof(T),
0081 cudaMemcpyHostToDevice, getStreamFrom(stream)));
0082 return;
0083 }
0084
0085 template <typename T>
0086 void copyToHost(host_array<T>& host, const device_array<T>& dev,
0087 std::size_t arraySize) {
0088 ACTS_CUDA_ERROR_CHECK(cudaMemcpy(host.get(), dev.get(), arraySize * sizeof(T),
0089 cudaMemcpyDeviceToHost));
0090 return;
0091 }
0092
0093 template <typename T>
0094 void copyToHost(host_array<T>& host, const device_array<T>& dev,
0095 std::size_t arraySize, const StreamWrapper& stream) {
0096 ACTS_CUDA_ERROR_CHECK(
0097 cudaMemcpyAsync(host.get(), dev.get(), arraySize * sizeof(T),
0098 cudaMemcpyDeviceToHost, getStreamFrom(stream)));
0099 return;
0100 }
0101
0102 }
0103 }
0104
0105
0106
0107
0108
0109
0110
0111 #define INST_ARRAY_FOR_TYPE(TYPE) \
0112 template class std::unique_ptr<TYPE, \
0113 Acts::Cuda::Details::DeviceArrayDeleter>; \
0114 template std::unique_ptr<TYPE, Acts::Cuda::Details::DeviceArrayDeleter> \
0115 Acts::Cuda::make_device_array<TYPE>(std::size_t); \
0116 template class std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter>; \
0117 template std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter> \
0118 Acts::Cuda::make_host_array<TYPE>(std::size_t); \
0119 template void Acts::Cuda::copyToDevice<TYPE>( \
0120 std::unique_ptr<TYPE, Acts::Cuda::Details::DeviceArrayDeleter>&, \
0121 const std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter>&, \
0122 std::size_t); \
0123 template void Acts::Cuda::copyToDevice<TYPE>( \
0124 std::unique_ptr<TYPE, Acts::Cuda::Details::DeviceArrayDeleter>&, \
0125 const std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter>&, \
0126 std::size_t, const Acts::Cuda::StreamWrapper&); \
0127 template void Acts::Cuda::copyToHost<TYPE>( \
0128 std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter>&, \
0129 const std::unique_ptr<TYPE, Acts::Cuda::Details::DeviceArrayDeleter>&, \
0130 std::size_t); \
0131 template void Acts::Cuda::copyToHost<TYPE>( \
0132 std::unique_ptr<TYPE, Acts::Cuda::Details::HostArrayDeleter>&, \
0133 const std::unique_ptr<TYPE, Acts::Cuda::Details::DeviceArrayDeleter>&, \
0134 std::size_t, const Acts::Cuda::StreamWrapper&)
0135
0136
0137 INST_ARRAY_FOR_TYPE(char);
0138 INST_ARRAY_FOR_TYPE(unsigned char);
0139 INST_ARRAY_FOR_TYPE(short);
0140 INST_ARRAY_FOR_TYPE(unsigned short);
0141 INST_ARRAY_FOR_TYPE(int);
0142 INST_ARRAY_FOR_TYPE(unsigned int);
0143 INST_ARRAY_FOR_TYPE(long);
0144 INST_ARRAY_FOR_TYPE(unsigned long);
0145 INST_ARRAY_FOR_TYPE(long long);
0146 INST_ARRAY_FOR_TYPE(unsigned long long);
0147 INST_ARRAY_FOR_TYPE(float);
0148 INST_ARRAY_FOR_TYPE(double);
0149
0150
0151 INST_ARRAY_FOR_TYPE(Acts::Cuda::Details::SpacePoint);
0152 INST_ARRAY_FOR_TYPE(Acts::Cuda::Details::DubletCounts);
0153 INST_ARRAY_FOR_TYPE(Acts::Cuda::Details::LinCircle);
0154 INST_ARRAY_FOR_TYPE(Acts::Cuda::Details::Triplet);
0155
0156
0157 #undef INST_ARRAY_FOR_TYPE