Skip to content

Commit

Permalink
Synchronize event in the CUDAProductBase destructor
Browse files Browse the repository at this point in the history
Otherwise there are possibilities for weird races (e.g. combination
non-ExternalWork producers, consumed-but-not-read CUDAProducts, CUDA
streams executing work later than expected (= on the next event)).
  • Loading branch information
makortel committed Sep 20, 2019
1 parent 513c861 commit 97b6279
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 @@ -8,3 +8,15 @@ bool CUDAProductBase::isAvailable() const {
}
return event_->has_occurred();
}

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-api-wrappers"/>
<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-api-wrappers"/>
<use name="rootcore"/>
<use name="CUDADataFormats/Common"/>
<use name="DataFormats/Common"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="eigen"/>
Expand Down

0 comments on commit 97b6279

Please sign in to comment.