ATLAS Offline Software
Loading...
Searching...
No Matches
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
15
16#include <vector>
17#include <memory>
18#include <iostream>
19#include <fstream>
20#include <cstring>
21
22int 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
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]
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
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
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
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}
virtual Work * createWork(int, std::shared_ptr< OffloadBuffer > data)=0
virtual bool configure()=0
virtual bool run()=0
virtual std::shared_ptr< OffloadBuffer > getOutput()=0
const int nEvents
int main()
Definition hello.cxx:18
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
struct TrigAccel::SeedMakingJob SEED_MAKING_JOB
struct TrigAccel::OutputSeedStorage OUTPUT_SEED_STORAGE
struct TrigAccel::SpacePointStorage SPACEPOINT_STORAGE
size_t load(const std::string &name)
SPACEPOINT_STORAGE m_data