ATLAS Offline Software
Loading...
Searching...
No Matches
LinearTransformExampleAlg.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2//
3// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4//
5
6// Local include(s).
8#include "HIPFunctions.h"
9
10// System include(s).
11#include <limits>
12#include <sstream>
13
14namespace AthHIPExamples {
15
17
18 // Print a bit of information about the selected device.
19 std::ostringstream deviceInfo;
20 printHipDeviceInfo( m_hipDevice.value(), deviceInfo );
21 ATH_MSG_INFO( "Will be using device:\n" << deviceInfo.str() );
22
23 // Return gracefully.
24 return StatusCode::SUCCESS;
25 }
26
27 StatusCode LinearTransformExampleAlg::execute( const EventContext& ) const {
28
29 // Create a dummy array variable that will be linearly transformed.
30 static constexpr float ARRAY_ELEMENT = 3.141592f;
31 std::vector< float > dummyArray( m_arraySize.value(), ARRAY_ELEMENT );
32
33 // Perform the transformation.
34 linearTransform( m_hipDevice.value(), dummyArray, m_multiplier.value(),
35 m_shift.value() );
36
37 // Validate the contents of the transformed array.
38 const float expectedResult =
39 m_multiplier.value() * ARRAY_ELEMENT + m_shift.value();
40 static constexpr float allowedDeviation =
41 std::numeric_limits< float >::epsilon() * 4;
42 for( float element : dummyArray ) {
43 if( std::abs( element - expectedResult ) > allowedDeviation ) {
44 REPORT_MESSAGE( MSG::FATAL )
45 << "The HIP linear transformation failed";
46 return StatusCode::FAILURE;
47 }
48 }
49
50 // Return gracefully.
51 return StatusCode::SUCCESS;
52 }
53
54} // namespace AthHIPExamples
#define ATH_MSG_INFO(x)
#define REPORT_MESSAGE(LVL)
Report a message.
Gaudi::Property< int > m_hipDevice
The HIP device (ID) to use.
Gaudi::Property< float > m_multiplier
The multiplier of the linear transformation.
Gaudi::Property< unsigned int > m_arraySize
Size of the dummy array to use.
Gaudi::Property< float > m_shift
Shift used in the linear transformation.
virtual StatusCode execute(const EventContext &ctx) const override
The function executing this algorithm.
virtual StatusCode initialize() override
The function initialising the algorithm.
void printHipDeviceInfo(int deviceId, std::ostream &out)
Return information about the selected device.
void linearTransform(int deviceId, std::vector< float > &data, float a, float b)
Perform a linear transformation on an array.