ATLAS Offline Software
Loading...
Searching...
No Matches
LinearTransformAsyncExampleAlg.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
7
8namespace AthCUDAExamples {
9
10StatusCode LinearTransformAsyncExampleAlg::execute(const EventContext&) const {
11 ATH_MSG_INFO("Starting execute");
12
13 // Create a dummy array variable in pinned memory that will be multiplied by
14 // some amount.
15 static const std::size_t ARRAY_SIZE = 10000;
16 static const float ARRAY_ELEMENT = 3.141592f;
17 std::vector<float> dummyArray(ARRAY_SIZE, ARRAY_ELEMENT);
18
19 // Run calculation. See LinearTransformAsyncExampleAlg.cu.
20 static const float MULTIPLIER = 1.23f;
21 ATH_MSG_INFO("Starting linearTransform");
22 ATH_CHECK(linearTransform(dummyArray, MULTIPLIER));
23
24 // Check if the operation succeeded.
25 static const float EXPECTED_RESULT = ARRAY_ELEMENT * MULTIPLIER;
26 for (std::size_t i = 0; i < ARRAY_SIZE; ++i) {
27 if (std::abs(dummyArray[i] - EXPECTED_RESULT) > 0.001) {
28 ATH_MSG_ERROR("The CUDA transformation failed to run");
29 return StatusCode::FAILURE;
30 }
31 }
32
33 // Return gracefully.
34 return StatusCode::SUCCESS;
35}
36
37} // 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.
StatusCode linearTransform(std::vector< float > &arr, float multiplier) const
GPU kernel launcher.