ATLAS Offline Software
Functions
trigGpuTest.cxx File Reference
#include <iostream>
#include <fstream>
#include <cstring>
#include <dlfcn.h>
#include <experimental/filesystem>
#include "tbb/tick_count.h"
#include "TrigAccelEvent/WorkFactory.h"
#include "TrigAccelEvent/DataExportBuffer.h"
#include "TrigAccelEvent/TrigInDetAccelEDM.h"
#include "TrigAccelEvent/TrigInDetAccelCodes.h"
#include <vector>
#include <memory>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 21 of file trigGpuTest.cxx.

21  {
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 
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 
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 }
nEvents
const int nEvents
Definition: fbtTestBasics.cxx:77
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
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
python.handimod.now
now
Definition: handimod.py:675
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
TrigAccel::SpacePointStorage::m_nSpacepoints
int m_nSpacepoints
Definition: TrigInDetAccelEDM.h:51
TrigAccel::WorkFactory::configure
virtual bool configure()=0
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
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