ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExCUDA
src
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).
6
#include "
LinearTransformAsyncExampleAlg.h
"
7
8
// Gaudi include(s).
9
#include <Gaudi/CUDA/CUDAStream.h>
10
11
namespace
AthCUDAExamples
{
12
13
StatusCode
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
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
LinearTransformAsyncExampleAlg.h
AthCUDAExamples::LinearTransformAsyncExampleAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition
LinearTransformAsyncExampleAlg.cxx:13
AthCUDAExamples
Definition
cudaMultiply.h:11
AthCUDAExamples::linearTransform
void linearTransform(cudaStream_t stream, std::vector< float > &arr, float multiplier)
GPU kernel launcher.
Generated on
for ATLAS Offline Software by
1.17.0