Skip to content

Commit

Permalink
Synchronize event in the CUDAProductBase destructor (#391)
Browse files Browse the repository at this point in the history
Otherwise there are possibilities for weird races, e.g. combination of
non-ExternalWork producers, consumed-but-not-read CUDAProducts, CUDA
streams executing work later than expected (= on the next event).
  • Loading branch information
makortel authored and fwyzard committed Oct 29, 2019
1 parent 6bfe94f commit 8177676
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CUDADataFormats/Common/interface/CUDAProductBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ namespace impl {
class CUDAProductBase {
public:
CUDAProductBase() = default; // Needed only for ROOT dictionary generation
~CUDAProductBase();

CUDAProductBase(const CUDAProductBase&) = delete;
CUDAProductBase& operator=(const CUDAProductBase&) = delete;
CUDAProductBase(CUDAProductBase&& other)
: stream_{std::move(other.stream_)},
event_{std::move(other.event_)},
Expand Down
12 changes: 12 additions & 0 deletions CUDADataFormats/Common/src/CUDAProductBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ bool CUDAProductBase::isAvailable() const {
}
return cudautils::eventIsOccurred(event_->id());
}

CUDAProductBase::~CUDAProductBase() {
// Make sure that the production of the product in the GPU is
// complete before destructing the product. This is to make sure
// that the EDM stream does not move to the next event before all
// asynchronous processing of the current is complete.
if (event_) {
// TODO: a callback notifying a WaitingTaskHolder (or similar)
// would avoid blocking the CPU, but would also require more work.
event_->synchronize();
}
}
1 change: 1 addition & 0 deletions CUDADataFormats/Track/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<use name="cuda"/>
<use name="rootcore"/>
<use name="CUDADataFormats/Common"/>
<use name="DataFormats/Common"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="eigen"/>
Expand Down
1 change: 1 addition & 0 deletions CUDADataFormats/Vertex/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<use name="cuda"/>
<use name="rootcore"/>
<use name="CUDADataFormats/Common"/>
<use name="DataFormats/Common"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="eigen"/>
Expand Down

0 comments on commit 8177676

Please sign in to comment.