File indexing completed on 2024-06-07 02:29:40
0001 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_EDMetadata_h
0002 #define HeterogeneousCore_AlpakaCore_interface_alpaka_EDMetadata_h
0003
0004 #include <atomic>
0005 #include <memory>
0006
0007 #include <alpaka/alpaka.hpp>
0008
0009 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0011
0012 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0037
0038
0039 class EDMetadata {
0040 public:
0041 EDMetadata(std::shared_ptr<Queue> queue) : queue_(std::move(queue)) {}
0042
0043 Device device() const { return alpaka::getDev(*queue_); }
0044
0045
0046
0047 Queue& queue() const { return *queue_; }
0048
0049 void recordEvent() {}
0050 void discardEvent() {}
0051
0052 private:
0053 std::shared_ptr<Queue> queue_;
0054 };
0055
0056
0057
0058 #else
0059
0060
0061 class EDMetadata {
0062 public:
0063 EDMetadata(std::shared_ptr<Queue> queue, std::shared_ptr<Event> event)
0064 : queue_(std::move(queue)), event_(std::move(event)) {}
0065 ~EDMetadata();
0066
0067 Device device() const { return alpaka::getDev(*queue_); }
0068
0069
0070
0071 Queue& queue() const { return *queue_; }
0072
0073 void enqueueCallback(edm::WaitingTaskWithArenaHolder holder);
0074
0075 void recordEvent() { alpaka::enqueue(*queue_, *event_); }
0076 void discardEvent() { event_.reset(); }
0077
0078
0079
0080
0081 void synchronize(EDMetadata& consumer, bool tryReuseQueue) const;
0082
0083 private:
0084
0085
0086
0087
0088 std::shared_ptr<Queue> tryReuseQueue_() const;
0089
0090 std::shared_ptr<Queue> queue_;
0091 std::shared_ptr<Event> event_;
0092
0093
0094
0095 mutable std::atomic<bool> mayReuseQueue_ = true;
0096
0097 mutable std::atomic<bool> eventComplete_ = false;
0098 };
0099 #endif
0100 }
0101
0102 #endif