Skip to content

Commit

Permalink
Use edm::async() in Alpaka modules
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed May 3, 2024
1 parent d96a64c commit b758c10
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 5 additions & 1 deletion HeterogeneousCore/AlpakaCore/interface/EventCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ namespace cms::alpakatools {

private:
std::shared_ptr<Event> makeOrGet(Device dev) {
return cache_[alpaka::getNativeHandle(dev)].makeOrGet([dev]() { return std::make_unique<Event>(dev); });
return cache_[alpaka::getNativeHandle(dev)].makeOrGet([dev]() {
// We want non-busy waits
bool constexpr busyWait = false;
return std::make_unique<Event>(dev, busyWait);
});
}

// not thread safe, intended to be called only from AlpakaService
Expand Down
1 change: 0 additions & 1 deletion HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/HostOnlyTask.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
/**
Expand Down
8 changes: 3 additions & 5 deletions HeterogeneousCore/AlpakaCore/src/alpaka/EDMetadata.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <alpaka/alpaka.hpp>

#include "FWCore/Concurrency/interface/async.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadata.h"

Expand All @@ -23,11 +24,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
}

void EDMetadata::enqueueCallback(edm::WaitingTaskWithArenaHolder holder) {
alpaka::enqueue(*queue_, alpaka::HostOnlyTask([holder = std::move(holder)](std::exception_ptr eptr) {
// The functor is required to be const, but the original waitingTaskHolder_
// needs to be notified...
const_cast<edm::WaitingTaskWithArenaHolder&>(holder).doneWaiting(eptr);
}));
recordEvent();
edm::async(std::move(holder), [event = event_]() mutable { alpaka::wait(*event); });
}

void EDMetadata::synchronize(EDMetadata& consumer, bool tryReuseQueue) const {
Expand Down

0 comments on commit b758c10

Please sign in to comment.