ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
HDF5Utils
util
test-half-precision.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
HDF5Utils/Writer.h
"
6
7
#include <random>
8
9
//-------------------------------------------------------------------------
10
// output data structure
11
struct
out_t
12
{
13
double
dtype
;
14
float
ftype
;
15
bool
btype
;
16
};
17
using
consumer_t
=
H5Utils::Consumers<const out_t&>
;
18
19
#define ADD(NAME) consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0)
20
#define HADD(NAME) consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0, h)
21
22
23
consumer_t
getFullConsumers
() {
24
consumer_t
consumers;
25
ADD
(ftype);
26
ADD
(dtype);
27
ADD
(btype);
28
return
consumers;
29
}
30
consumer_t
getHalfConsumers
() {
31
consumer_t
consumers;
32
H5Utils::Compression
h
=
H5Utils::Compression::HALF_PRECISION
;
33
HADD
(ftype);
34
HADD
(dtype);
35
ADD
(btype);
36
return
consumers;
37
}
38
39
//-------------------------------------------------------------------------
40
// outputs
41
42
using
mt_t
=
decltype
(std::mt19937());
43
44
std::vector<out_t>
getOutputs
(
size_t
length
,
mt_t
& rand ) {
45
std::vector<out_t> outvec;
46
std::uniform_int_distribution<int> exponent(-10, 2);
47
std::uniform_real_distribution<float> man(-0.0001, 0.0001);
48
std::uniform_int_distribution<short> booldist(0, 1);
49
for
(
size_t
n = 0; n <
length
; n++) {
50
out_t
out;
51
double
value = std::exp2(exponent(rand)) * (1 + man(rand));
52
out.dtype = value;
53
out.ftype = value;
54
out.btype = booldist(rand);
55
outvec.push_back(out);
56
}
57
return
outvec;
58
}
59
60
61
//-------------------------------------------------------------------------
62
// main routine
63
64
void
fill
(H5::Group& out_file,
size_t
iterations) {
65
66
const
int
deflate = 7;
67
const
int
max_width = 10;
68
std::mt19937 random(42);
69
70
// compare outputs
71
using
writer_t =
H5Utils::Writer<1, consumer_t::input_type>
;
72
writer_t::configuration_type config;
73
config.name =
"full"
;
74
config.extent = {max_width};
75
config.deflate = deflate;
76
writer_t full(out_file,
getFullConsumers
(), config);
77
config.name =
"half"
;
78
writer_t half(out_file,
getHalfConsumers
(), config);
79
std::uniform_int_distribution<int>
width
(0, max_width+1);
80
for
(
size_t
n = 0; n < iterations; n++) {
81
auto
out =
getOutputs
(
width
(random), random);
82
full.fill(out);
83
half.fill(out);
84
}
85
}
86
87
int
main
(
int
nargs,
char
* argv[]) {
88
H5::H5File out_file(
"output.h5"
, H5F_ACC_TRUNC);
89
size_t
iterations = 1;
90
if
(nargs > 2) {
91
return
1;
92
}
93
if
(nargs > 1) iterations = std::atoi(argv[1]);
94
fill
(out_file, iterations);
95
return
0;
96
}
length
double length(const pvec &v)
Definition
FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
width
const double width
Definition
TTileTripReader.cxx:24
Writer.h
h
Header file for AthHistogramAlgorithm.
H5Utils::Consumers
Definition
Writer.h:130
H5Utils::Writer
Writer.
Definition
Writer.h:351
main
int main()
Definition
hello.cxx:18
H5Utils::Compression
Compression
Definition
CompressionEnums.h:11
H5Utils::Compression::HALF_PRECISION
@ HALF_PRECISION
Definition
CompressionEnums.h:11
out_t
Definition
test-half-precision.cxx:12
out_t::btype
bool btype
Definition
test-half-precision.cxx:15
out_t::ftype
float ftype
Definition
test-half-precision.cxx:14
out_t::dtype
double dtype
Definition
test-half-precision.cxx:13
getHalfConsumers
consumer_t getHalfConsumers()
Definition
test-half-precision.cxx:30
fill
void fill(H5::Group &out_file, size_t iterations)
Definition
test-half-precision.cxx:64
ADD
#define ADD(NAME)
Definition
test-half-precision.cxx:19
mt_t
decltype(std::mt19937()) mt_t
Definition
test-half-precision.cxx:42
getOutputs
std::vector< out_t > getOutputs(size_t length, mt_t &rand)
Definition
test-half-precision.cxx:44
HADD
#define HADD(NAME)
Definition
test-half-precision.cxx:20
getFullConsumers
consumer_t getFullConsumers()
Definition
test-half-precision.cxx:23
consumer_t
H5Utils::Consumers< const out_t & > consumer_t
Definition
test-half-precision.cxx:17
Generated on
for ATLAS Offline Software by
1.17.0