ATLAS Offline Software
Loading...
Searching...
No Matches
AsyncCopyTool.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
6#include "AsyncCopyTool.h"
7
8// VecMem include(s).
9#include <vecmem/utils/cuda/async_copy.hpp>
10
11// System include(s).
12#include <format>
13#include <stdexcept>
14
16#define CUDA_ERROR_CHECK(EXP) \
17 do { \
18 cudaError_t errorCode = EXP; \
19 if (errorCode != cudaSuccess) { \
20 throw std::runtime_error(std::format("{}:{} Failed to execute: {} ({})", \
21 __FILE__, __LINE__, #EXP, \
22 cudaGetErrorString(errorCode))); \
23 } \
24 } while (false)
25
26namespace AthCUDA {
27
31
35 cudaStreamDestroy(m_stream);
36}
37
39
40 // Create the slot specific stream.
41 m_streams = std::make_unique<const SG::SlotSpecificObj<Stream>>();
42
43 // Return gracefully.
44 return StatusCode::SUCCESS;
45}
46
47std::shared_ptr<const vecmem::copy> AsyncCopyTool::copy(
48 const EventContext& ctx) const {
49
50 // Create an asynchronous copy object, specific to this slot's CUDA stream.
51 cudaStream_t stream = m_streams->get(ctx)->m_stream;
52 assert(stream != nullptr);
53 return std::make_shared<const vecmem::cuda::async_copy>(stream);
54}
55
56} // namespace AthCUDA
#define CUDA_ERROR_CHECK(EXP)
Helper macro used for checking cudaError_t type return values.
virtual std::shared_ptr< const vecmem::copy > copy(const EventContext &ctx) const override
Get the provided vecmem::copy object.
virtual StatusCode initialize() override
Initialize the tool.
std::unique_ptr< const SG::SlotSpecificObj< Stream > > m_streams
Slot specific CUDA stream.
Definition Info.h:14
Stream()
Constructor, creating the CUDA stream.
cudaStream_t m_stream
The CUDA stream to use for asynchronous copies.
~Stream()
Destructor, destroying the CUDA stream.