|
30 | 30 | #include "ITStrackingGPU/ClusterLinesGPU.h" |
31 | 31 | #include "ITStrackingGPU/VertexerTraitsGPU.h" |
32 | 32 |
|
| 33 | +#include "GPUCommonArray.h" |
| 34 | + |
33 | 35 | namespace o2 |
34 | 36 | { |
35 | 37 | namespace its |
36 | 38 | { |
37 | | - |
38 | 39 | using constants::its::VertexerHistogramVolume; |
39 | 40 | using constants::math::TwoPi; |
40 | 41 | using gpu::utils::host::checkGPUError; |
@@ -119,9 +120,9 @@ GPUd() void printVectorOnThread(const char* name, Vector<int>& vector, size_t si |
119 | 120 | // { |
120 | 121 | // if (blockIdx.x * blockDim.x + threadIdx.x == threadId) { |
121 | 122 | // printf("XmaxBin: %d at index: %d | YmaxBin: %d at index: %d | ZmaxBin: %d at index: %d\n", |
122 | | -// store.getTmpVertexPositionBins()[0].value, store.getTmpVertexPositionBins()[0].key, |
123 | | -// store.getTmpVertexPositionBins()[1].value, store.getTmpVertexPositionBins()[1].key, |
124 | | -// store.getTmpVertexPositionBins()[2].value, store.getTmpVertexPositionBins()[2].key); |
| 123 | +// tmpVertexBins[0].value, tmpVertexBins[0].key, |
| 124 | +// tmpVertexBins[1].value, tmpVertexBins[1].key, |
| 125 | +// tmpVertexBins[2].value, tmpVertexBins[2].key); |
125 | 126 | // } |
126 | 127 | // } |
127 | 128 |
|
@@ -313,35 +314,44 @@ GPUg() void computeZCentroidsKernel(const int nLines, |
313 | 314 | } |
314 | 315 | } |
315 | 316 |
|
316 | | -// GPUg() void computeVertexKernel(DeviceStoreVertexerGPU& store, const int vertIndex, const int minContributors, const int binOpeningZ) |
317 | | -// { |
318 | | -// for (size_t currentThreadIndex = blockIdx.x * blockDim.x + threadIdx.x; currentThreadIndex < binOpeningZ; currentThreadIndex += blockDim.x * gridDim.x) { |
319 | | -// if (currentThreadIndex == 0) { |
320 | | -// if (store.getTmpVertexPositionBins()[2].value > 1 && (store.getTmpVertexPositionBins()[0].value || store.getTmpVertexPositionBins()[1].value)) { |
321 | | -// float z{store.getConfig().histConf.lowHistBoundariesXYZ[2] + store.getTmpVertexPositionBins()[2].key * store.getConfig().histConf.binSizeHistZ + store.getConfig().histConf.binSizeHistZ / 2}; |
322 | | -// float ex{0.f}; |
323 | | -// float ey{0.f}; |
324 | | -// float ez{0.f}; |
325 | | -// int sumWZ{store.getTmpVertexPositionBins()[2].value}; |
326 | | -// float wZ{z * store.getTmpVertexPositionBins()[2].value}; |
327 | | -// for (int iBin{o2::gpu::GPUCommonMath::Max(0, store.getTmpVertexPositionBins()[2].key - binOpeningZ)}; iBin < o2::gpu::GPUCommonMath::Min(store.getTmpVertexPositionBins()[2].key + binOpeningZ + 1, store.getConfig().histConf.nBinsXYZ[2] - 1); ++iBin) { |
328 | | -// if (iBin != store.getTmpVertexPositionBins()[2].key) { |
329 | | -// wZ += (store.getConfig().histConf.lowHistBoundariesXYZ[2] + iBin * store.getConfig().histConf.binSizeHistZ + store.getConfig().histConf.binSizeHistZ / 2) * store.getHistogramXYZ()[2].get()[iBin]; |
330 | | -// sumWZ += store.getHistogramXYZ()[2].get()[iBin]; |
331 | | -// } |
332 | | -// store.getHistogramXYZ()[2].get()[iBin] = 0; |
333 | | -// } |
334 | | -// if (sumWZ > minContributors || vertIndex == 0) { |
335 | | -// store.getVertices().emplace(vertIndex, store.getBeamPosition()[0], store.getBeamPosition()[1], wZ / sumWZ, ex, ey, ez, sumWZ); |
336 | | -// } else { |
337 | | -// store.getVertices().emplace(vertIndex); |
338 | | -// } |
339 | | -// } else { |
340 | | -// store.getVertices().emplace(vertIndex); |
341 | | -// } |
342 | | -// } |
343 | | -// } |
344 | | -// } |
| 317 | +GPUg() void computeVertexKernel(cub::KeyValuePair<int, int>* tmpVertexBins, |
| 318 | + int* histZ, // Z |
| 319 | + const float lowHistZ, |
| 320 | + const float binSizeHistZ, |
| 321 | + const int nBinsHistZ, |
| 322 | + Vertex* vertices, |
| 323 | + float* beamPosition, |
| 324 | + const int vertIndex, |
| 325 | + const int minContributors, |
| 326 | + const int binOpeningZ) |
| 327 | +{ |
| 328 | + for (size_t currentThreadIndex = blockIdx.x * blockDim.x + threadIdx.x; currentThreadIndex < binOpeningZ; currentThreadIndex += blockDim.x * gridDim.x) { |
| 329 | + if (currentThreadIndex == 0) { |
| 330 | + if (tmpVertexBins[2].value > 1 && (tmpVertexBins[0].value || tmpVertexBins[1].value)) { |
| 331 | + float z{lowHistZ + tmpVertexBins[2].key * binSizeHistZ + binSizeHistZ / 2}; |
| 332 | + float ex{0.f}; |
| 333 | + float ey{0.f}; |
| 334 | + float ez{0.f}; |
| 335 | + int sumWZ{tmpVertexBins[2].value}; |
| 336 | + float wZ{z * tmpVertexBins[2].value}; |
| 337 | + for (int iBin{o2::gpu::GPUCommonMath::Max(0, tmpVertexBins[2].key - binOpeningZ)}; iBin < o2::gpu::GPUCommonMath::Min(tmpVertexBins[2].key + binOpeningZ + 1, nBinsHistZ - 1); ++iBin) { |
| 338 | + if (iBin != tmpVertexBins[2].key) { |
| 339 | + wZ += (lowHistZ + iBin * binSizeHistZ + binSizeHistZ / 2) * histZ[iBin]; |
| 340 | + sumWZ += histZ[iBin]; |
| 341 | + } |
| 342 | + histZ[iBin] = 0; |
| 343 | + } |
| 344 | + if (sumWZ > minContributors || vertIndex == 0) { |
| 345 | + new (vertices + vertIndex) Vertex{o2::math_utils::Point3D<float>(beamPosition[0], beamPosition[1], wZ / sumWZ), o2::gpu::gpustd::array<float, 6>{ex, 0, ey, 0, 0, ez}, sumWZ, 0}; |
| 346 | + } else { |
| 347 | + new (vertices + vertIndex) Vertex{}; |
| 348 | + } |
| 349 | + } else { |
| 350 | + new (vertices + vertIndex) Vertex{}; |
| 351 | + } |
| 352 | + } |
| 353 | + } |
| 354 | +} |
345 | 355 | } // namespace gpu |
346 | 356 |
|
347 | 357 | void VertexerTraitsGPU::computeTracklets() |
@@ -538,23 +548,34 @@ void VertexerTraitsGPU::computeVertices() |
538 | 548 | mTimeFrameGPU->getConfig().histConf.lowHistBoundariesXYZ[2], // lower_level |
539 | 549 | mTimeFrameGPU->getConfig().histConf.highHistBoundariesXYZ[2], // fupper_level |
540 | 550 | nLines)); // num_row_pixels |
541 | | - // for (int iVertex{0}; iVertex < mStoreVertexerGPU.getConfig().nMaxVertices; ++iVertex) { |
542 | | - // discardResult(cub::DeviceReduce::ArgMax(reinterpret_cast<void*>(mStoreVertexerGPU.getCUBTmpBuffer().get()), |
543 | | - // bufferSize, |
544 | | - // mStoreVertexerGPU.getHistogramXYZ()[2].get(), |
545 | | - // mStoreVertexerGPU.getTmpVertexPositionBins().get() + 2, |
546 | | - // mStoreVertexerGPU.getConfig().histConf.nBinsXYZ[2])); |
547 | | - // gpu::computeVertexKernel<<<blocksGrid, 5>>>(getDeviceContext(), iVertex, mVrtParams.clusterContributorsCut, mStoreVertexerGPU.getConfig().histConf.binSpanXYZ[2]); |
548 | | - // } |
549 | | - // std::vector<gpu::GPUVertex> vertices; |
550 | | - // vertices.resize(mStoreVertexerGPU.getConfig().nMaxVertices); |
551 | | - // mStoreVertexerGPU.getVertices().copyIntoSizedVector(vertices); |
552 | | - |
553 | | - // for (auto& vertex : vertices) { |
554 | | - // if (vertex.realVertex) { |
555 | | - // mVertices.emplace_back(vertex.xCoord, vertex.yCoord, vertex.zCoord, std::array<float, 6>{0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, vertex.contributors, 0.f, -9); |
556 | | - // } |
557 | | - // } |
| 551 | + for (int iVertex{0}; iVertex < mTimeFrameGPU->getConfig().maxVerticesCapacity; ++iVertex) { |
| 552 | + discardResult(cub::DeviceReduce::ArgMax(reinterpret_cast<void*>(mTimeFrameGPU->getDeviceCUBBuffer(rofId)), |
| 553 | + bufferSize, |
| 554 | + mTimeFrameGPU->getDeviceZHistograms(rofId), |
| 555 | + mTimeFrameGPU->getTmpVertexPositionBins(rofId) + 2, |
| 556 | + mTimeFrameGPU->getConfig().histConf.nBinsXYZ[2])); |
| 557 | + |
| 558 | + gpu::computeVertexKernel<<<blocksGrid, 5>>>(mTimeFrameGPU->getTmpVertexPositionBins(rofId), |
| 559 | + mTimeFrameGPU->getDeviceZHistograms(rofId), |
| 560 | + mTimeFrameGPU->getConfig().histConf.lowHistBoundariesXYZ[2], |
| 561 | + mTimeFrameGPU->getConfig().histConf.binSizeHistZ, |
| 562 | + mTimeFrameGPU->getConfig().histConf.nBinsXYZ[2], |
| 563 | + mTimeFrameGPU->getDeviceVertices(rofId), |
| 564 | + mTimeFrameGPU->getDeviceBeamPosition(rofId), |
| 565 | + iVertex, |
| 566 | + mVrtParams.clusterContributorsCut, |
| 567 | + mTimeFrameGPU->getConfig().histConf.binSpanXYZ[2]); |
| 568 | + } |
| 569 | + std::vector<Vertex> GPUvertices; |
| 570 | + GPUvertices.resize(mTimeFrameGPU->getConfig().maxVerticesCapacity); |
| 571 | + checkGPUError(cudaMemcpy(GPUvertices.data(), mTimeFrameGPU->getDeviceVertices(rofId), sizeof(gpu::GPUVertex) * mTimeFrameGPU->getConfig().maxVerticesCapacity, cudaMemcpyDeviceToHost), __FILE__, __LINE__); |
| 572 | + int nRealVertices{0}; |
| 573 | + for (auto& vertex : GPUvertices) { |
| 574 | + if (vertex.getX() || vertex.getY() || vertex.getZ()) { |
| 575 | + ++nRealVertices; |
| 576 | + } |
| 577 | + } |
| 578 | + mTimeFrameGPU->addPrimaryVertices(gsl::span<const Vertex>{GPUvertices.data(), static_cast<gsl::span<const Vertex>::size_type>(nRealVertices)}); |
558 | 579 | } |
559 | 580 | gpuThrowOnError(); |
560 | 581 | } |
|
0 commit comments