Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:46

0001 #include <cassert>
0002 
0003 #include "CUDADataFormats/SiPixelDigi/interface/SiPixelDigiErrorsCUDA.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
0006 #include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"
0007 #include "HeterogeneousCore/CUDAUtilities/interface/memsetAsync.h"
0008 
0009 SiPixelDigiErrorsCUDA::SiPixelDigiErrorsCUDA(size_t maxFedWords, SiPixelFormatterErrors errors, cudaStream_t stream)
0010     : data_d(cms::cuda::make_device_unique<SiPixelErrorCompact[]>(maxFedWords, stream)),
0011       error_d(cms::cuda::make_device_unique<SiPixelErrorCompactVector>(stream)),
0012       error_h(cms::cuda::make_host_unique<SiPixelErrorCompactVector>(stream)),
0013       formatterErrors_h(std::move(errors)),
0014       nErrorWords_(maxFedWords) {
0015   assert(maxFedWords != 0);
0016   cms::cuda::memsetAsync(data_d, 0x00, maxFedWords, stream);
0017 
0018   cms::cuda::make_SimpleVector(error_h.get(), maxFedWords, data_d.get());
0019   assert(error_h->empty());
0020   assert(error_h->capacity() == static_cast<int>(maxFedWords));
0021 
0022   cms::cuda::copyAsync(error_d, error_h, stream);
0023 }
0024 
0025 void SiPixelDigiErrorsCUDA::copyErrorToHostAsync(cudaStream_t stream) {
0026   cms::cuda::copyAsync(error_h, error_d, stream);
0027 }
0028 
0029 SiPixelDigiErrorsCUDA::HostDataError SiPixelDigiErrorsCUDA::dataErrorToHostAsync(cudaStream_t stream) const {
0030   // On one hand size() could be sufficient. On the other hand, if
0031   // someone copies the SimpleVector<>, (s)he might expect the data
0032   // buffer to actually have space for capacity() elements.
0033   auto data = cms::cuda::make_host_unique<SiPixelErrorCompact[]>(error_h->capacity(), stream);
0034 
0035   // but transfer only the required amount
0036   if (not error_h->empty()) {
0037     cms::cuda::copyAsync(data, data_d, error_h->size(), stream);
0038   }
0039   auto err = *error_h;
0040   err.set_data(data.get());
0041   return HostDataError(err, std::move(data));
0042 }