ATLAS Offline Software
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 
14 namespace 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 ) {
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
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthHIPExamples::LinearTransformExampleAlg::m_shift
Gaudi::Property< float > m_shift
Shift used in the linear transformation.
Definition: AthExHIP/src/LinearTransformExampleAlg.h:50
LinearTransformExampleAlg.h
AthHIPExamples
Definition: HIPFunctions.h:12
HIPFunctions.h
AthHIPExamples::LinearTransformExampleAlg::m_hipDevice
Gaudi::Property< int > m_hipDevice
The HIP device (ID) to use.
Definition: AthExHIP/src/LinearTransformExampleAlg.h:39
AthHIPExamples::LinearTransformExampleAlg::m_arraySize
Gaudi::Property< unsigned int > m_arraySize
Size of the dummy array to use.
Definition: AthExHIP/src/LinearTransformExampleAlg.h:43
AthHIPExamples::LinearTransformExampleAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
The function executing this algorithm.
Definition: LinearTransformExampleAlg.cxx:27
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthHIPExamples::linearTransform
void linearTransform(int deviceId, std::vector< float > &data, float a, float b)
Perform a linear transformation on an array.
AthHIPExamples::LinearTransformExampleAlg::initialize
virtual StatusCode initialize() override
The function initialising the algorithm.
Definition: LinearTransformExampleAlg.cxx:16
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
AthHIPExamples::LinearTransformExampleAlg::m_multiplier
Gaudi::Property< float > m_multiplier
The multiplier of the linear transformation.
Definition: AthExHIP/src/LinearTransformExampleAlg.h:47
AthHIPExamples::printHipDeviceInfo
void printHipDeviceInfo(int deviceId, std::ostream &out)
Return information about the selected device.