Skip to content

Commit

Permalink
Fix uploading the EventSetup conditions to multiple CUDA devices
Browse files Browse the repository at this point in the history
Associate to the correct CUDA device the events used to track if the
conditions have been transferred to each device.
  • Loading branch information
fwyzard committed Aug 19, 2021
1 parent 1d940d4 commit 097fe4a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions HeterogeneousCore/CUDACore/interface/ESProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "FWCore/Utilities/interface/thread_safety_macros.h"
#include "HeterogeneousCore/CUDAServices/interface/numberOfDevices.h"
#include "HeterogeneousCore/CUDAUtilities/interface/EventCache.h"
#include "HeterogeneousCore/CUDAUtilities/interface/ScopedSetDevice.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "HeterogeneousCore/CUDAUtilities/interface/currentDevice.h"
#include "HeterogeneousCore/CUDAUtilities/interface/eventWorkHasCompleted.h"
Expand All @@ -19,23 +20,24 @@ namespace cms {
class ESProduct {
public:
ESProduct() : gpuDataPerDevice_(numberOfDevices()) {
cms::cuda::ScopedSetDevice scopedDevice;
for (size_t i = 0; i < gpuDataPerDevice_.size(); ++i) {
scopedDevice.set(i);
gpuDataPerDevice_[i].m_event = getEventCache().get();
}
}

~ESProduct() = default;

// transferAsync should be a function of (T&, cudaStream_t)
// which enqueues asynchronous transfers (possibly kernels as well)
// to the CUDA stream
template <typename F>
const T& dataForCurrentDeviceAsync(cudaStream_t cudaStream, F transferAsync) const {
auto device = currentDevice();

int device = currentDevice();
auto& data = gpuDataPerDevice_[device];

// If GPU data has already been filled, we can return it
// immediately
// If the GPU data has already been filled, we can return it immediately
if (not data.m_filled.load()) {
// It wasn't, so need to fill it
std::scoped_lock<std::mutex> lk{data.m_mutex};
Expand Down Expand Up @@ -103,4 +105,4 @@ namespace cms {
} // namespace cuda
} // namespace cms

#endif
#endif // HeterogeneousCore_CUDACore_ESProduct_h

0 comments on commit 097fe4a

Please sign in to comment.