ATLAS Offline Software
Loading...
Searching...
No Matches
LinearTransformStandaloneExampleAlg.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
7#include "cudaMultiply.h"
8
9// System include(s).
10#include <cmath>
11#include <vector>
12
13namespace AthCUDAExamples {
14
16 LinearTransformStandaloneExampleAlg::execute( const EventContext& ) const {
17
18 // Create a dummy array variable that will be multiplied by some amount.
19 static const std::size_t ARRAY_SIZE = 10000;
20 std::vector< float > dummyArray;
21 dummyArray.reserve( ARRAY_SIZE );
22 static const float ARRAY_ELEMENT = 3.141592f;
23 for( std::size_t i = 0; i < ARRAY_SIZE; ++i ) {
24 dummyArray.push_back( ARRAY_ELEMENT );
25 }
26
27 // Call on a function, which would synchronously make some modification
28 // to this vector.
29 static const float MULTIPLIER = 1.23f;
30 cudaMultiply( dummyArray, MULTIPLIER );
31
32 // Check if the operation succeeded.
33 static const float EXPECTED_RESULT = ARRAY_ELEMENT * MULTIPLIER;
34 for( std::size_t i = 0; i < ARRAY_SIZE; ++i ) {
35 if( std::abs( dummyArray[ i ] - EXPECTED_RESULT ) > 0.001 ) {
36 ATH_MSG_ERROR( "The CUDA transformation failed to run" );
37 return StatusCode::FAILURE;
38 }
39 }
40
41 // Return gracefully.
42 return StatusCode::SUCCESS;
43 }
44
45} // namespace AthCUDAExamples
#define ATH_MSG_ERROR(x)
virtual StatusCode execute(const EventContext &ctx) const override
The function executing this algorithm.
void cudaMultiply(std::vector< float > &array, float multiplier)
Function used to multiple a vector of variables by some amount.
::StatusCode StatusCode
StatusCode definition for legacy code.