File indexing completed on 2024-04-06 12:26:27
0001 #include <cassert>
0002
0003 #include <cuda_runtime.h>
0004 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0006
0007 #include "ChannelLocsGPU.h"
0008
0009 ChannelLocs::ChannelLocs(size_t size, cudaStream_t stream) : ChannelLocsBase(size) {
0010 if (size > 0) {
0011 input_ = cms::cuda::make_host_unique<const uint8_t*[]>(size, stream);
0012 inoff_ = cms::cuda::make_host_unique<size_t[]>(size, stream);
0013 offset_ = cms::cuda::make_host_unique<size_t[]>(size, stream);
0014 length_ = cms::cuda::make_host_unique<uint16_t[]>(size, stream);
0015 fedID_ = cms::cuda::make_host_unique<stripgpu::fedId_t[]>(size, stream);
0016 fedCh_ = cms::cuda::make_host_unique<stripgpu::fedCh_t[]>(size, stream);
0017 detID_ = cms::cuda::make_host_unique<stripgpu::detId_t[]>(size, stream);
0018 }
0019 }
0020
0021 void ChannelLocsView::fill(const ChannelLocsGPU& c) {
0022 input_ = c.input();
0023 inoff_ = c.inoff();
0024 offset_ = c.offset();
0025 length_ = c.length();
0026 fedID_ = c.fedID();
0027 fedCh_ = c.fedCh();
0028 detID_ = c.detID();
0029 size_ = c.size();
0030 }
0031
0032 ChannelLocsGPU::ChannelLocsGPU(size_t size, cudaStream_t stream) : ChannelLocsBase(size) {
0033 if (size > 0) {
0034 input_ = cms::cuda::make_device_unique<const uint8_t*[]>(size, stream);
0035 inoff_ = cms::cuda::make_device_unique<size_t[]>(size, stream);
0036 offset_ = cms::cuda::make_device_unique<size_t[]>(size, stream);
0037 length_ = cms::cuda::make_device_unique<uint16_t[]>(size, stream);
0038 fedID_ = cms::cuda::make_device_unique<stripgpu::fedId_t[]>(size, stream);
0039 fedCh_ = cms::cuda::make_device_unique<stripgpu::fedCh_t[]>(size, stream);
0040 detID_ = cms::cuda::make_device_unique<stripgpu::detId_t[]>(size, stream);
0041
0042 auto channelLocsView = cms::cuda::make_host_unique<ChannelLocsView>(stream);
0043 channelLocsView->fill(*this);
0044 channelLocsViewGPU_ = cms::cuda::make_device_unique<ChannelLocsView>(stream);
0045 cms::cuda::copyAsync(channelLocsViewGPU_, channelLocsView, stream);
0046 }
0047 }
0048
0049 void ChannelLocsGPU::setVals(const ChannelLocs* c,
0050 cms::cuda::host::unique_ptr<const uint8_t*[]> inputGPU,
0051 cudaStream_t stream) {
0052 assert(c->size() == size_);
0053 cms::cuda::copyAsync(input_, inputGPU, size_, stream);
0054 cms::cuda::copyAsync(inoff_, c->inoff_, size_, stream);
0055 cms::cuda::copyAsync(offset_, c->offset_, size_, stream);
0056 cms::cuda::copyAsync(length_, c->length_, size_, stream);
0057 cms::cuda::copyAsync(fedID_, c->fedID_, size_, stream);
0058 cms::cuda::copyAsync(fedCh_, c->fedCh_, size_, stream);
0059 cms::cuda::copyAsync(detID_, c->detID_, size_, stream);
0060 }