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