ATLAS Offline Software
trigGpuTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
21 int 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  return -2;
58  }
59 
60 
61  const size_t bufferOffset = 256;
62 
64 
65  std::string geoName(argv[1]);
66 
67  std::cout<<"reading geometry from file "<<geoName<<std::endl;
68 
69  size_t bSize = pBG->load(geoName);
70 
71  std::cout<<"loaded "<<bSize<<" bytes"<<std::endl;
72 
73  std::shared_ptr<TrigAccel::OffloadBuffer> pDMBuff = std::make_shared<TrigAccel::OffloadBuffer>(pBG);
74 
75  delete pBG;
76 
77  std::cout<<"Creating Work item for task "<<TrigAccel::InDetJobControlCode::SIL_LAYERS_EXPORT<<std::endl;
78 
80 
81 
82  std::string data_path(argv[2]);
83  std::vector<std::string> event_files;
84 
85  for(const auto& entry : std::experimental::filesystem::directory_iterator(data_path)) {
86  event_files.push_back(entry.path());
87  }
88 
89  int nEvents = atoi(argv[3]);
90 
91  std::cout<<"running the GPU test with "<<nEvents<<" events"<<std::endl;
92 
94 
95  int fileIdx = 0;
96 
97  std::ofstream timeFile("results.csv");
98 
99  timeFile<<"nsp,nseeds,time"<<std::endl;
100 
101  for(int iEvent=0;iEvent<nEvents;iEvent++) {
102 
103  const std::string& fileName = event_files[fileIdx];
104 
105  fileIdx++;
106  if(fileIdx >= (int)event_files.size()) {
107  fileIdx = 0;
108  }
109 
110  std::cout<<"reading event from file "<<fileName<<std::endl;
111 
112  bSize = pB->load(fileName);
113 
114  TrigAccel::SEED_MAKING_JOB* pJ = reinterpret_cast<TrigAccel::SEED_MAKING_JOB*>(pB->m_buffer + bufferOffset);
115 
117 
118  tbb::tick_count tzero = tbb::tick_count::now();
119 
120  std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(pB);
121 
123 
124  if(!pJob) {
125  std::cout<<"ERROR: cannot create work item"<<std::endl;
126  return -3;
127  }
128 
129  pJob->run();
130 
131  tbb::tick_count tnow=tbb::tick_count::now();
132  tbb::tick_count::interval_t duration = tnow - tzero;
133  std::cout<<"triplet making took "<<duration.seconds()*1000.0<<" ms"<<std::endl;
134 
135  std::shared_ptr<TrigAccel::OffloadBuffer> pOB = pJob->getOutput();
136 
138 
139  std::cout<<"Found "<<pOutput->m_nSeeds<<" triplets"<<std::endl;
140  timeFile<<sps.m_nSpacepoints<<","<<pOutput->m_nSeeds<<","<<duration.seconds()*1000.0<<std::endl;
141 
142  delete pJob;
143  }
144 
145  timeFile.close();
146 
147  delete pB;
148 
149  deleteFactory(pW);
150 
151  dlclose(handle);
152 
153 
154 
155 }
TrigAccel::DataExportBuffer
Definition: DataExportBuffer.h:14
TrigAccel::DATA_EXPORT_BUFFER
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TrigAccel::SeedMakingJob
Definition: TrigInDetAccelEDM.h:83
TrigAccel::Work::run
virtual bool run()=0
TrigAccel::SpacePointStorage
Definition: TrigInDetAccelEDM.h:49
TrigAccel::OutputSeedStorage
Definition: TrigInDetAccelEDM.h:89
TrigAccel::WorkFactory::createWork
virtual Work * createWork(int, std::shared_ptr< OffloadBuffer > data)=0
TrigAccel::SIL_LAYERS_EXPORT
@ SIL_LAYERS_EXPORT
Definition: TrigInDetAccelCodes.h:24
TrigInDetAccelCodes.h
TrigAccel::Work::getOutput
virtual std::shared_ptr< OffloadBuffer > getOutput()=0
TrigAccel::OutputSeedStorage::m_nSeeds
int m_nSeeds
Definition: TrigInDetAccelEDM.h:91
get_generator_info.stderr
stderr
Definition: get_generator_info.py:40
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
DataExportBuffer.h
WorkFactory.h
python.handimod.now
now
Definition: handimod.py:675
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
TrigAccel::SpacePointStorage::m_nSpacepoints
int m_nSpacepoints
Definition: TrigInDetAccelEDM.h:51
TrigAccel::WorkFactory::configure
virtual bool configure()=0
nEvents
int nEvents
Definition: fbtTestBasics.cxx:77
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
PixelAthHitMonAlgCfg.duration
duration
Definition: PixelAthHitMonAlgCfg.py:152
TrigAccel::SeedMakingJob::m_data
SPACEPOINT_STORAGE m_data
Definition: TrigInDetAccelEDM.h:86
TrigAccel::DataExportBuffer::load
size_t load(const std::string &name)
Definition: DataExportBuffer.h:42
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TrigAccel::Work
Definition: Work.h:14
TrigAccel::DataExportBuffer::m_buffer
char * m_buffer
Definition: DataExportBuffer.h:57
main
int main(int argc, char *argv[])
Definition: trigGpuTest.cxx:21
TrigAccel::OffloadBuffer::m_rawBuffer
unsigned char * m_rawBuffer
Definition: OffloadBuffer.h:39
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
TrigAccel::WorkFactory
Definition: WorkFactory.h:16
TrigAccel::MAKE_SEEDS
@ MAKE_SEEDS
Definition: TrigInDetAccelCodes.h:29
TrigInDetAccelEDM.h