ATLAS Offline Software
Loading...
Searching...
No Matches
LinearTransformAsyncExampleAlg.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).
7
8// Gaudi include(s).
9#include <Gaudi/CUDA/CUDAStream.h>
10
11namespace AthCUDAExamples {
12
13StatusCode LinearTransformAsyncExampleAlg::execute(const EventContext&) const {
14 ATH_MSG_INFO("Starting execute");
15
16 // Create a dummy array variable in pinned memory that will be multiplied by
17 // some amount.
18 static const std::size_t ARRAY_SIZE = 10000;
19 static const float ARRAY_ELEMENT = 3.141592f;
20 std::vector<float> dummyArray(ARRAY_SIZE, ARRAY_ELEMENT);
21
22 // Run calculation. See LinearTransformAsyncExampleAlg.cu.
23 static const float MULTIPLIER = 1.23f;
24 ATH_MSG_INFO("Starting linearTransform");
25 Gaudi::CUDA::Stream stream(this);
26 linearTransform(stream, dummyArray, MULTIPLIER);
27 ATH_CHECK(stream.await());
28
29 // Check if the operation succeeded.
30 static const float EXPECTED_RESULT = ARRAY_ELEMENT * MULTIPLIER;
31 for (std::size_t i = 0; i < ARRAY_SIZE; ++i) {
32 if (std::abs(dummyArray[i] - EXPECTED_RESULT) > 0.001) {
33 ATH_MSG_ERROR("The CUDA transformation failed to run");
34 return StatusCode::FAILURE;
35 }
36 }
37
38 // Return gracefully.
39 return StatusCode::SUCCESS;
40}
41
42} // namespace AthCUDAExamples
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
void linearTransform(cudaStream_t stream, std::vector< float > &arr, float multiplier)
GPU kernel launcher.