Repository navigation
GPU TPC: Run extrapolation tracking only on selected tracks - #16210
OliverRietmann wants to merge 10 commits into
Conversation
davidrohr
left a comment
There was a problem hiding this comment.
Some general comments, didn't check the kernel in detail, I assume with deterministic reconstruction, it reproduces the previous output exactly?
| #endif | ||
|
|
||
| GPUd() GPUconstantref() const GPUConstantMem* GetConstantMem() const; // Body in GPUConstantMem.h to avoid circular headers | ||
| GPUd() GPUconstantref() GPUConstantMem* GetConstantMem(); // ... |
There was a problem hiding this comment.
Why do you need a non-const version? In principle, this should be constant memory during kernels?
There was a problem hiding this comment.
I fixed it according to your comment below.
| void GPUReconstruction::RegisterGPUDeviceProcessor(GPUProcessor* proc, GPUProcessor* slaveProcessor) { proc->InitGPUProcessor(this, GPUProcessor::PROCESSOR_TYPE_DEVICE, slaveProcessor); } | ||
| void GPUReconstruction::ConstructGPUProcessor(GPUProcessor* proc) { proc->mConstantMem = proc->mGPUProcessorType == GPUProcessor::PROCESSOR_TYPE_DEVICE ? mDeviceConstantMem : mHostConstantMem.get(); } | ||
|
|
||
| uint32_t GPUReconstruction::StreamForSector(uint32_t sector) const |
There was a problem hiding this comment.
Could we move everything that is not pure-GPU related to GPUChainTracking. GPUReconstruction should be generic.
There was a problem hiding this comment.
The reusable memory in GPUTPCTracker::RegisterMemoryAllocation() relied on the specific way of assigning the sectors to the streams that we had before (round robin). I moved the function to have a "single source of truth" for both GPUTPCTracker and GPUTPCChainTrackingSectorTracker. I can move it back to GPUChainTracking and include the latter in GPUTPCTracker.
| AddOption(inKernelParallel, uint8_t, 2, "", 0, "Parallelize with multi-threading inside kernels on the host instead of over TPC sectors: 0 disable, 1 full and exclusive in-kernel parallelization, 2 for nested parallelization over TPC sectors (nTPCClustererLanes thread-groups) and inside kernels") | ||
| AddOption(autoAdjustHostThreads, bool, true, "", 0, "Auto-adjust number of OMP threads, decreasing the number for small input data") | ||
| AddOption(nStreams, int8_t, 8, "", 0, "Number of GPU streams / command queues") | ||
| AddOption(nStreams, int8_t, 6, "", 0, "Number of GPU streams / command queues") |
There was a problem hiding this comment.
I might be wrong, but I belive the TPC clusterization can parallelize over 7 streams at the moment. I thought you wanted to add a nStreamsTPCSectorTracking option, to use only a subset of streams in the sector tracking?
There was a problem hiding this comment.
I have rest --nStreams to a deafult of 8 and I added a new option --nStreamsTPCSectorTracking with a default of 6. It gets clamped between 1 and --nStreams here.
| GPUhd() GPUglobalref() GPUAtomic(uint32_t) * NExtrapolationCandidatesRight() const { return &mCommonMem->nExtrapolationCandidatesRight; } | ||
| GPUhd() GPUglobalref() int32_t* ExtrapolationCandidatesLeft() const { return mExtrapolationCandidatesLeft; } | ||
| GPUhd() GPUglobalref() int32_t* ExtrapolationCandidatesRight() const { return mExtrapolationCandidatesRight; } | ||
| GPUhd() GPUglobalref() int32_t* ExtrapolationCandidatesLeftDirection() const { return mExtrapolationCandidatesLeftDirection; } |
There was a problem hiding this comment.
int8_t should be enough. In principle, you should be able to store the direction together with the candidateID by using the highest bit. nTracks should never exceed 24 bit anyway.
There was a problem hiding this comment.
I removed the two direction arrays and we are now storing the direction in the sign bit. We need this "packing/unpacking" logic in three files: GPUTPCTrackletSelector.cxx, GPUTPCExtrapolationTracking.cxx, and GPUTPCSectorDebugSortKernels.cxx and therefor I have created a dedicated class GPUTPCExtrapolationCandidate. (But maybe this is an overkill?)
I think you can just use GPUMemcpy directly to copy only part of a buffer? |
I still don't understand what do you need the write access for? You should only write to the arrays, but not to the constant memory itself. like the merger and DataCompression kernels do it. Then your kernel already receives ConstantMem and not only the current sector GPUTPCTracker. |
| { | ||
| AllocateAndInitializeLate(); | ||
| bool reuseCondition = MemoryReuseAllowed(); | ||
| GPUMemoryReuse reLinks{reuseCondition, GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::TrackerDataLinks, (uint16_t)(mISector % mRec->GetProcessingSettings().nStreams)}; |
There was a problem hiding this comment.
Ah, you refer to this? This seems a bug indeed! I'd do the following:
- Move StreamForSector back to GPUChainTracking.
- Include GPUChainTracking.h to GPUTPCTracker.cxx #ifndef GPUCAGPUCODE
- Add an optional option to StreamForSector overriding the nstreams, and use the new parameter for tpcsectortracking when called from GPUTPCTracker.cxx
There was a problem hiding this comment.
I moved the function back and added a second argumentGPUChainTracking::StreamForSector(uint32_t sector, const GPUSettingsProcessing& proc). I was not quite sure what you want as default behavior, but StreamForSector now reads the number of streams for sector tracking from the new option --nStreamsTPCSectorTracking to ensure it is always the same in GPUMemoryReuse reLinks and the actual sector tracking.
… --nStreamsTPCSectorTracking
…st bit of their local track id
Yes, this is exactly what I wanted. I changed it to the above. |
Yes, we get the exact same GPU.out and CPU.out files. |
The problem is actually not the two consecutive lines of copies, but the fact that the left and right entering tracks are computed in different streams. Thus we cannot copy when one is done, because we don't know if the other is already done. I have now enqueued the host to device copies at the end of the sector's stream, see here. I am still not using GPUMemcpy because |
davidrohr
left a comment
There was a problem hiding this comment.
Thanks, looks good. I have one more minor request below.
| mNStreams = std::max<int32_t>(GetProcessingSettings().nStreams, 3); | ||
| } | ||
|
|
||
| if ((int32_t)GetProcessingSettings().nStreamsTPCSectorTracking > GetProcessingSettings().nStreams || GetProcessingSettings().nStreamsTPCSectorTracking < 1) { |
There was a problem hiding this comment.
There is a function ValidateSettings, where such checks should live.
There was a problem hiding this comment.
I moved the range check to GPUChainTracking::ValidateSettings(), see here.
There was a problem hiding this comment.
I removed the range check and clamp to NStreams() in StreamForSector, according to our private discussion.
…UReconstruction.cxx to GPUChainTracking::ValidateSettings()
|
Do you want me to clean up the git history after these fixes so that we have just 4 commits again? (requires force-push) |
…lamp to NStreams()
|
Performance-wise, looks very good: On my 5090, the ExtrapolationKernel gets 2x faster, and trackletSelector maintains the same speed. I asked Claude to do a code review, and it found some issues. Could you have a look: Bugs:
Suggestions:
|
Changes: For every TPC sector, during GPUTPCTrackletSelector, we write a list of left and right exiting tracks. Then GPUTPCExtrapolationTracking only runs on those tracks. Newly, we do this per pair of sectors, or per edge that they share, respectively. This changes how the sectors have to wait for their neighboring sectors to finish GPUTPCTrackletSelector. While not strictly necessary, we have changed the number of streams and how we assign them to the sectors. Finally, the GPUParameters.csv was updated to fit the new extrapolation tracking.
Remarks:
iSector.GetConstantMem()->tpcTrackers[iSectorNeighbor]. This is was actively prohibited before and should thus be looked at.GPUChainTracking::ExtrapolationTracking. The two copies are racing, but in a way taht doesn't corrupt the final data (on copy copies a subset of the other). Maybe we can find a better solution for this.