ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHIP
src
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).
7
#include "
LinearTransformExampleAlg.h
"
8
#include "
HIPFunctions.h
"
9
10
// System include(s).
11
#include <limits>
12
#include <sstream>
13
14
namespace
AthHIPExamples
{
15
16
StatusCode
LinearTransformExampleAlg::initialize_worker
() {
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
ATH_MSG_INFO
(
"Starting linearTransform"
);
30
// Create a dummy array variable that will be linearly transformed.
31
static
constexpr
float
ARRAY_ELEMENT = 3.141592f;
32
std::vector< float > dummyArray(
m_arraySize
.value(), ARRAY_ELEMENT );
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
LinearTransformExampleAlg.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:365
HIPFunctions.h
AthHIPExamples::LinearTransformExampleAlg::m_hipDevice
Gaudi::Property< int > m_hipDevice
The HIP device (ID) to use.
Definition
AthExHIP/src/LinearTransformExampleAlg.h:46
AthHIPExamples::LinearTransformExampleAlg::m_multiplier
Gaudi::Property< float > m_multiplier
The multiplier of the linear transformation.
Definition
AthExHIP/src/LinearTransformExampleAlg.h:54
AthHIPExamples::LinearTransformExampleAlg::initialize_worker
virtual StatusCode initialize_worker() override
Initialization per process.
Definition
LinearTransformExampleAlg.cxx:16
AthHIPExamples::LinearTransformExampleAlg::m_arraySize
Gaudi::Property< unsigned int > m_arraySize
Size of the dummy array to use.
Definition
AthExHIP/src/LinearTransformExampleAlg.h:50
AthHIPExamples::LinearTransformExampleAlg::m_shift
Gaudi::Property< float > m_shift
Shift used in the linear transformation.
Definition
AthExHIP/src/LinearTransformExampleAlg.h:57
AthHIPExamples::LinearTransformExampleAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
The function executing this algorithm.
Definition
LinearTransformExampleAlg.cxx:27
AthHIPExamples
Definition
DeviceStateHandler.h:20
AthHIPExamples::printHipDeviceInfo
void printHipDeviceInfo(int deviceId, std::ostream &out)
Return information about the selected device.
AthHIPExamples::linearTransform
void linearTransform(int deviceId, std::vector< float > &data, float a, float b)
Perform a linear transformation on an array.
Generated on
for ATLAS Offline Software by
1.17.0