26 #include <boost/type_erasure/any_cast.hpp>
27 #include <cuda_profiler_api.h>
35 std::vector<const SpacePoint*> readSP;
37 std::ifstream spFile(filename);
38 if (spFile.is_open()) {
39 while (!spFile.eof()) {
41 std::stringstream ss(line);
44 float x,
y,
z, r, varianceR, varianceZ;
45 if (linetype ==
"lxyz") {
46 ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
47 r = std::sqrt(x * x + y * y);
48 float f22 = varianceR;
49 float wid = varianceZ;
50 float cov = wid * wid * .08333;
72 int main(
int argc,
char** argv) {
73 auto start_pre = std::chrono::system_clock::now();
75 std::string
file{
"sp.txt"};
80 int nGroupToIterate = 500;
83 int nTrplPerSpBLimit = 100;
84 int nAvgTrplPerSpBLimit = 2;
87 while ((opt = getopt(argc, argv,
"haf:n:s:d:l:m:qG")) != -1) {
96 nGroupToIterate = atoi(optarg);
102 deviceID = atoi(optarg);
105 nAvgTrplPerSpBLimit = atoi(optarg);
108 nTrplPerSpBLimit = atoi(optarg);
120 std::cerr <<
"Usage: " << argv[0] <<
" [-hq] [-f FILENAME]\n";
122 std::cout <<
" -h : this help" << std::endl;
123 std::cout <<
" -a ALL : analyze all groups. Default is \""
124 << allgroup <<
"\"" << std::endl;
126 <<
" -f FILE : read spacepoints from FILE. Default is \""
127 <<
file <<
"\"" << std::endl;
128 std::cout <<
" -n NUM : Number of groups to iterate in seed "
129 "finding. Default is "
130 << nGroupToIterate << std::endl;
131 std::cout <<
" -s SKIP : Number of groups to skip in seed "
132 "finding. Default is "
133 << skip << std::endl;
134 std::cout <<
" -d DEVID : NVIDIA GPU device ID. Default is "
135 << deviceID << std::endl;
136 std::cout <<
" -l : A limit on the average number of triplets "
137 "per bottom spacepoint: this is used for determining "
138 "matrix size for triplets per middle space point"
139 << nAvgTrplPerSpBLimit << std::endl;
140 std::cout <<
" -m : A limit on the number of triplets per "
141 "bottom spacepoint: users do not have to touch this for "
142 "# spacepoints < ~200k"
143 << nTrplPerSpBLimit << std::endl;
144 std::cout <<
" -q : don't print out all found seeds"
146 std::cout <<
" -G : only run on GPU, not CPU" << std::endl;
154 ACTS_CUDA_ERROR_CHECK(cudaSetDevice(deviceID));
156 std::ifstream f(
file);
158 std::cerr <<
"input file \"" <<
file <<
"\" does not exist\n";
164 std::cout <<
"read " << spVec.size() <<
" SP from file " <<
file << std::endl;
174 config.
zMin = -2800.;
189 ACTS_CUDA_ERROR_CHECK(cudaGetDeviceProperties(&prop, deviceID));
190 printf(
"\n GPU Device %d: \"%s\" with compute capability %d.%d\n\n", deviceID,
191 prop.name, prop.major, prop.minor);
197 auto bottomBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
199 auto topBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
203 config.
seedFilter = std::make_unique<Acts::SeedFilter<SpacePoint>>(
223 std::unique_ptr<Acts::SpacePointGrid<SpacePoint>> grid =
224 Acts::SpacePointGridCreator::createGrid<SpacePoint>(gridConf);
226 bottomBinFinder, topBinFinder,
229 auto end_pre = std::chrono::system_clock::now();
230 std::chrono::duration<double> elapsec_pre = end_pre - start_pre;
231 double preprocessTime = elapsec_pre.count();
232 std::cout <<
"Preprocess Time: " << preprocessTime << std::endl;
238 auto start_cpu = std::chrono::system_clock::now();
241 auto groupIt = spGroup.begin();
245 std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector_cpu;
246 groupIt = spGroup.begin();
249 for (
int i_s = 0; i_s <
skip; i_s++)
251 for (; !(groupIt == spGroup.end()); ++groupIt) {
253 groupIt.bottom(), groupIt.middle(), groupIt.top()));
255 if (allgroup ==
false) {
256 if (group_count >= nGroupToIterate)
261 std::cout <<
"Analyzed " << group_count <<
" groups for CPU" << std::endl;
264 auto end_cpu = std::chrono::system_clock::now();
265 std::chrono::duration<double> elapsec_cpu = end_cpu - start_cpu;
266 double cpuTime = elapsec_cpu.count();
271 auto start_cuda = std::chrono::system_clock::now();
274 std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector_cuda;
275 groupIt = spGroup.begin();
277 for (
int i_s = 0; i_s <
skip; i_s++)
279 for (; !(groupIt == spGroup.end()); ++groupIt) {
281 groupIt.bottom(), groupIt.middle(), groupIt.top()));
283 if (allgroup ==
false) {
284 if (group_count >= nGroupToIterate)
288 auto end_cuda = std::chrono::system_clock::now();
289 std::chrono::duration<double> elapsec_cuda = end_cuda - start_cuda;
290 double cudaTime = elapsec_cuda.count();
293 std::cout <<
"Analyzed " << group_count <<
" groups for CUDA" << std::endl;
295 std::cout << std::endl;
296 std::cout <<
"----------------------- Time Metric -----------------------"
298 std::cout <<
" " << (do_cpu ?
"CPU" :
" ")
299 <<
" CUDA " << (do_cpu ?
"Speedup " :
"")
301 std::cout <<
"Seedfinding_Time " << std::setw(11)
302 << (do_cpu ?
std::to_string(cpuTime) :
"") <<
" " << std::setw(11)
303 << cudaTime <<
" " << std::setw(11)
304 << (do_cpu ?
std::to_string(cpuTime / cudaTime) :
"") << std::endl;
305 double wallTime_cpu = cpuTime + preprocessTime;
306 double wallTime_cuda = cudaTime + preprocessTime;
307 std::cout <<
"Wall_time " << std::setw(11)
309 << std::setw(11) << wallTime_cuda <<
" " << std::setw(11)
312 std::cout <<
"-----------------------------------------------------------"
314 std::cout << std::endl;
317 for (
auto& outVec : seedVector_cpu) {
318 nSeed_cpu += outVec.size();
322 for (
auto& outVec : seedVector_cuda) {
323 nSeed_cuda += outVec.size();
326 std::cout <<
"Number of Seeds (CPU | CUDA): " << nSeed_cpu <<
" | "
327 << nSeed_cuda << std::endl;
331 for (
size_t i = 0; i < seedVector_cpu.size(); i++) {
332 auto regionVec_cpu = seedVector_cpu[i];
333 auto regionVec_cuda = seedVector_cuda[i];
335 std::vector<std::vector<SpacePoint>> seeds_cpu;
336 std::vector<std::vector<SpacePoint>> seeds_cuda;
339 for (
auto sd : regionVec_cpu) {
340 std::vector<SpacePoint> seed_cpu;
341 seed_cpu.push_back(*(sd.sp()[0]));
342 seed_cpu.push_back(*(sd.sp()[1]));
343 seed_cpu.push_back(*(sd.sp()[2]));
345 seeds_cpu.push_back(seed_cpu);
348 for (
auto sd : regionVec_cuda) {
349 std::vector<SpacePoint> seed_cuda;
350 seed_cuda.push_back(*(sd.sp()[0]));
351 seed_cuda.push_back(*(sd.sp()[1]));
352 seed_cuda.push_back(*(sd.sp()[2]));
354 seeds_cuda.push_back(seed_cuda);
357 for (
auto seed : seeds_cpu) {
358 for (
auto other : seeds_cuda) {
359 if (seed[0] == other[0] && seed[1] == other[1] && seed[2] == other[2]) {
368 std::cout << nMatch <<
" seeds are matched" << std::endl;
369 std::cout <<
"Matching rate: " << float(nMatch) / nSeed_cpu * 100 <<
"%"
375 std::cout <<
"CPU Seed result:" << std::endl;
377 for (
auto& regionVec : seedVector_cpu) {
378 for (
size_t i = 0; i < regionVec.size(); i++) {
381 std::cout <<
" (" << sp->
x() <<
", " << sp->
y() <<
", " << sp->
z()
384 std::cout << sp->
surface <<
" (" << sp->
x() <<
", " << sp->
y() <<
", "
387 std::cout << sp->
surface <<
" (" << sp->
x() <<
", " << sp->
y() <<
", "
389 std::cout << std::endl;
393 std::cout << std::endl;
395 std::cout <<
"CUDA Seed result:" << std::endl;
397 for (
auto& regionVec : seedVector_cuda) {
398 for (
size_t i = 0; i < regionVec.size(); i++) {
401 std::cout <<
" (" << sp->
x() <<
", " << sp->
y() <<
", " << sp->
z()
404 std::cout << sp->
surface <<
" (" << sp->
x() <<
", " << sp->
y() <<
", "
407 std::cout << sp->
surface <<
" (" << sp->
x() <<
", " << sp->
y() <<
", "
409 std::cout << std::endl;
414 std::cout << std::endl;
415 std::cout << std::endl;