Skip to content

GPU TPC: Run extrapolation tracking only on selected tracks - #16210

Open
OliverRietmann wants to merge 10 commits into
AliceO2Group:devfrom
cern-nextgen:PR-extrapolation-tracking
Open

OliverRietmann wants to merge 10 commits into
AliceO2Group:devfrom
cern-nextgen:PR-extrapolation-tracking

Conversation

@OliverRietmann

Copy link
Copy Markdown
Contributor

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:

  1. Since extrapolation tracking is now done per edge rather than per sector, we needed write access via iSector.GetConstantMem()->tpcTrackers[iSectorNeighbor]. This is was actively prohibited before and should thus be looked at.
  2. Since the extrapolation over the left and right edge of a sector now run in different streams, copying to the host is less trivial. The PR implements a redundant copy in 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.

@davidrohr davidrohr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general comments, didn't check the kernel in detail, I assume with deterministic reconstruction, it reproduces the previous output exactly?

Comment thread GPU/GPUTracking/Base/GPUProcessor.h Outdated
#endif

GPUd() GPUconstantref() const GPUConstantMem* GetConstantMem() const; // Body in GPUConstantMem.h to avoid circular headers
GPUd() GPUconstantref() GPUConstantMem* GetConstantMem(); // ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a non-const version? In principle, this should be constant memory during kernels?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move everything that is not pure-GPU related to GPUChainTracking. GPUReconstruction should be generic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@OliverRietmann OliverRietmann Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

@davidrohr

Copy link
Copy Markdown
Collaborator

2. Since the extrapolation over the left and right edge of a sector now run in different streams, copying to the host is less trivial. The PR implements a redundant copy in 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.

I think you can just use GPUMemcpy directly to copy only part of a buffer?

@davidrohr

Copy link
Copy Markdown
Collaborator
  1. Since extrapolation tracking is now done per edge rather than per sector, we needed write access via iSector.GetConstantMem()->tpcTrackers[iSectorNeighbor]. This is was actively prohibited before and should thus be looked at.

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.
In any case, probably what you want to do instead is to change the processoor type of the processor, so that you get all of them (like

  GPUhdi() static processorType* Processor(GPUConstantMem& processors)
  {
    return &processors;
  }

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)};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@OliverRietmann OliverRietmann Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@OliverRietmann

OliverRietmann commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  1. Since extrapolation tracking is now done per edge rather than per sector, we needed write access via iSector.GetConstantMem()->tpcTrackers[iSectorNeighbor]. This is was actively prohibited before and should thus be looked at.

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. In any case, probably what you want to do instead is to change the processoor type of the processor, so that you get all of them (like

  GPUhdi() static processorType* Processor(GPUConstantMem& processors)
  {
    return &processors;
  }

like the merger and DataCompression kernels do it. Then your kernel already receives ConstantMem and not only the current sector GPUTPCTracker.

Yes, this is exactly what I wanted. I changed it to the above.

@OliverRietmann

Copy link
Copy Markdown
Contributor Author

Some general comments, didn't check the kernel in detail, I assume with deterministic reconstruction, it reproduces the previous output exactly?

Yes, we get the exact same GPU.out and CPU.out files.

@OliverRietmann

OliverRietmann commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

I think you can just use GPUMemcpy directly to copy only part of a buffer?

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 TransferMemoryResourceLinkToHost allowed me to wait for the other side to finish it's extrapolation tracking.

@davidrohr davidrohr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function ValidateSettings, where such checks should live.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the range check to GPUChainTracking::ValidateSettings(), see here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the range check and clamp to NStreams() in StreamForSector, according to our private discussion.

…UReconstruction.cxx to GPUChainTracking::ValidateSettings()
@OliverRietmann

Copy link
Copy Markdown
Contributor Author

Do you want me to clean up the git history after these fixes so that we have just 4 commits again? (requires force-push)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants