ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigAccel
TrigGpuTest
src
trigGpuTest.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include <dlfcn.h>
7
8
#include <experimental/filesystem>
9
#include "tbb/tick_count.h"
10
11
#include "
TrigAccelEvent/WorkFactory.h
"
12
#include "
TrigAccelEvent/DataExportBuffer.h
"
13
#include "
TrigAccelEvent/TrigInDetAccelEDM.h
"
14
#include "
TrigAccelEvent/TrigInDetAccelCodes.h
"
15
16
#include <vector>
17
#include <memory>
18
#include <iostream>
19
#include <fstream>
20
#include <cstring>
21
22
int
main
(
int
argc,
char
* argv[]) {
23
if
(argc < 4) {
24
std::cout<<
"trigGpuTest usage: ./trigGpuTest <geo_file.bin> <data_dir> nevents"
<<std::endl;
25
return
0;
26
}
27
28
29
//open the factory library
30
31
void
* handle = dlopen(
"libTrigInDetCUDA.so"
, RTLD_LAZY);
32
33
if
(!handle) {
34
fprintf(stderr,
"cannot load the factory library : %s\n"
, dlerror());
35
return
EXIT_FAILURE;
36
}
37
38
dlerror();
39
40
//declare library interface methods
41
42
TrigAccel::WorkFactory
* (*getFactory)();
43
int (*getFactoryId)();
44
void (*deleteFactory)(
TrigAccel::WorkFactory
*);
45
46
getFactory = (
TrigAccel::WorkFactory
* (*)()) dlsym(handle,
"getFactory"
);
47
getFactoryId = (int (*)()) dlsym(handle,
"getFactoryId"
);
48
deleteFactory = (void (*)(
TrigAccel::WorkFactory
*)) dlsym(handle,
"deleteFactory"
);
49
50
std::cout<<
"factory library id = "
<<std::hex<<getFactoryId()<<std::dec<<std::endl;
51
52
TrigAccel::WorkFactory
* pW = getFactory();
53
54
bool
cfgResult = pW->
configure
();
55
56
if
(!cfgResult) {
57
std::cout<<
"Factory config failed"
<<std::endl;
58
dlclose(handle);
59
return
-2;
60
}
61
62
63
const
size_t
bufferOffset = 256;
64
65
TrigAccel::DATA_EXPORT_BUFFER
* pBG =
new
TrigAccel::DATA_EXPORT_BUFFER
();
66
67
std::string geoName(argv[1]);
68
69
std::cout<<
"reading geometry from file "
<<geoName<<std::endl;
70
71
size_t
bSize = pBG->
load
(geoName);
72
73
std::cout<<
"loaded "
<<bSize<<
" bytes"
<<std::endl;
74
75
std::shared_ptr<TrigAccel::OffloadBuffer> pDMBuff = std::make_shared<TrigAccel::OffloadBuffer>(pBG);
76
77
delete
pBG;
78
79
std::cout<<
"Creating Work item for task "
<<
TrigAccel::InDetJobControlCode::SIL_LAYERS_EXPORT
<<std::endl;
80
//coverity[tainted_data]
81
pW->
createWork
(
TrigAccel::InDetJobControlCode::SIL_LAYERS_EXPORT
, std::move(pDMBuff));
82
83
84
std::string data_path(argv[2]);
85
std::vector<std::string> event_files;
86
87
for
(
const
auto
& entry : std::experimental::filesystem::directory_iterator(data_path)) {
88
event_files.push_back(entry.path());
89
}
90
91
int
nEvents
= atoi(argv[3]);
92
93
std::cout<<
"running the GPU test with "
<<
nEvents
<<
" events"
<<std::endl;
94
95
TrigAccel::DATA_EXPORT_BUFFER
* pB =
new
TrigAccel::DATA_EXPORT_BUFFER
();
96
97
int
fileIdx = 0;
98
99
std::ofstream timeFile(
"results.csv"
);
100
101
timeFile<<
"nsp,nseeds,time"
<<std::endl;
102
//coverity[TAINTED_SCALAR]
103
for
(
int
iEvent=0;iEvent<
nEvents
;iEvent++) {
104
105
const
std::string& fileName = event_files[fileIdx];
106
107
fileIdx++;
108
if
(fileIdx >= (
int
)event_files.size()) {
109
fileIdx = 0;
110
}
111
112
std::cout<<
"reading event from file "
<<fileName<<std::endl;
113
114
bSize = pB->
load
(fileName);
115
116
TrigAccel::SEED_MAKING_JOB
* pJ =
reinterpret_cast<
TrigAccel::SEED_MAKING_JOB
*
>
(pB->
m_buffer
+ bufferOffset);
117
118
TrigAccel::SPACEPOINT_STORAGE
& sps = pJ->
m_data
;
119
120
tbb::tick_count tzero = tbb::tick_count::now();
121
122
std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(pB);
123
124
TrigAccel::Work
* pJob = pW->
createWork
(
TrigAccel::InDetJobControlCode::MAKE_SEEDS
, std::move(pBuff));
125
126
if
(!pJob) {
127
std::cout<<
"ERROR: cannot create work item"
<<std::endl;
128
return
-3;
129
}
130
131
pJob->
run
();
132
133
tbb::tick_count tnow=tbb::tick_count::now();
134
tbb::tick_count::interval_t duration = tnow - tzero;
135
std::cout<<
"triplet making took "
<<duration.seconds()*1000.0<<
" ms"
<<std::endl;
136
137
std::shared_ptr<TrigAccel::OffloadBuffer> pOB = pJob->
getOutput
();
138
139
TrigAccel::OUTPUT_SEED_STORAGE
* pOutput =
reinterpret_cast<
TrigAccel::OUTPUT_SEED_STORAGE
*
>
(pOB->m_rawBuffer);
140
141
std::cout<<
"Found "
<<pOutput->
m_nSeeds
<<
" triplets"
<<std::endl;
142
timeFile<<sps.
m_nSpacepoints
<<
","
<<pOutput->
m_nSeeds
<<
","
<<duration.seconds()*1000.0<<std::endl;
143
144
delete
pJob;
145
}
146
147
timeFile.close();
148
149
delete
pB;
150
151
deleteFactory(pW);
152
153
dlclose(handle);
154
155
156
157
}
DataExportBuffer.h
TrigInDetAccelCodes.h
TrigInDetAccelEDM.h
WorkFactory.h
TrigAccel::WorkFactory
Definition
WorkFactory.h:16
TrigAccel::WorkFactory::createWork
virtual Work * createWork(int, std::shared_ptr< OffloadBuffer > data)=0
TrigAccel::WorkFactory::configure
virtual bool configure()=0
TrigAccel::Work
Definition
Work.h:14
TrigAccel::Work::run
virtual bool run()=0
TrigAccel::Work::getOutput
virtual std::shared_ptr< OffloadBuffer > getOutput()=0
nEvents
const int nEvents
Definition
fbtTestBasics.cxx:78
main
int main()
Definition
hello.cxx:18
TrigAccel::DATA_EXPORT_BUFFER
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
TrigAccel::SEED_MAKING_JOB
struct TrigAccel::SeedMakingJob SEED_MAKING_JOB
TrigAccel::MAKE_SEEDS
@ MAKE_SEEDS
Definition
TrigInDetAccelCodes.h:29
TrigAccel::SIL_LAYERS_EXPORT
@ SIL_LAYERS_EXPORT
Definition
TrigInDetAccelCodes.h:24
TrigAccel::OUTPUT_SEED_STORAGE
struct TrigAccel::OutputSeedStorage OUTPUT_SEED_STORAGE
TrigAccel::SPACEPOINT_STORAGE
struct TrigAccel::SpacePointStorage SPACEPOINT_STORAGE
TrigAccel::DataExportBuffer::m_buffer
char * m_buffer
Definition
DataExportBuffer.h:57
TrigAccel::DataExportBuffer::load
size_t load(const std::string &name)
Definition
DataExportBuffer.h:42
TrigAccel::OutputSeedStorage::m_nSeeds
int m_nSeeds
Definition
TrigInDetAccelEDM.h:91
TrigAccel::SeedMakingJob::m_data
SPACEPOINT_STORAGE m_data
Definition
TrigInDetAccelEDM.h:86
TrigAccel::SpacePointStorage::m_nSpacepoints
int m_nSpacepoints
Definition
TrigInDetAccelEDM.h:51
Generated on
for ATLAS Offline Software by
1.17.0