25#ifdef GPUCA_TRACKLET_CONSTRUCTOR_DO_PROFILE
29#define PROFILE_MAX_SIZE (100 * 1024 * 1024)
37#ifdef GPUCA_TRACKLET_CONSTRUCTOR_DO_PROFILE
47#ifdef GPUCA_TRACKLET_CONSTRUCTOR_DO_PROFILE
51 FILE* fp = fopen(
"profile.txt",
"w+");
52 FILE* fp2 = fopen(
"profile.bmp",
"w+b");
57 memset(&bmpFH, 0,
sizeof(bmpFH));
58 memset(&bmpIH, 0,
sizeof(bmpIH));
61 bmpFH.
bfSize =
sizeof(bmpFH) +
sizeof(bmpIH) + (ConstructorBlockCount() * ConstructorThreadCount() / 32 * 33 - 1) * bmpheight;
62 bmpFH.
bfOffBits =
sizeof(bmpFH) +
sizeof(bmpIH);
64 bmpIH.
biSize =
sizeof(bmpIH);
65 bmpIH.
biWidth = ConstructorBlockCount() * ConstructorThreadCount() / 32 * 33 - 1;
70 fwrite(&bmpFH, 1,
sizeof(bmpFH), fp2);
71 fwrite(&bmpIH, 1,
sizeof(bmpIH), fp2);
73 [[maybe_unused]]
int32_t nEmptySync = 0;
74 for (
uint32_t i = 0;
i < bmpheight * ConstructorBlockCount() * ConstructorThreadCount();
i += ConstructorBlockCount() * ConstructorThreadCount()) {
76 for (
uint32_t j = 0;
j < ConstructorBlockCount() * ConstructorThreadCount();
j++) {
77 fprintf(fp,
"%d\t", stageAtSync[
i +
j]);
79 if (stageAtSync[
i +
j] == 1) {
80 color = RGB(255, 0, 0);
82 if (stageAtSync[
i +
j] == 2) {
83 color = RGB(0, 255, 0);
85 if (stageAtSync[
i +
j] == 3) {
86 color = RGB(0, 0, 255);
88 if (stageAtSync[
i +
j] == 4) {
89 color = RGB(255, 255, 0);
92 if (
j > 0 &&
j % 32 == 0) {
93 color = RGB(255, 255, 255);
94 fwrite(&
color, 1, 4, fp2);
96 if (stageAtSync[
i +
j]) {
117struct GPUChainTrackingMemUsage {
118 void add(
size_t n,
size_t bound)
120 nMax = std::max(nMax,
n);
121 maxUse = std::max(
n / std::max<double>(bound, 1.), maxUse);
128 size_t nBoundSum = 0;
133void addToMap(std::string
name, std::map<std::string, GPUChainTrackingMemUsage>& map, uint64_t
n, uint64_t bound)
135 GPUChainTrackingMemUsage& obj = map.insert({
name, {}}).
first->second;
142 std::map<std::string, GPUChainTrackingMemUsage> usageMap;
146 addToMap(
"TPC Clusterer Sector Peaks", usageMap,
processors()->tpcClusterer[
i].mPmemory->counters.nPeaks,
processors()->tpcClusterer[
i].mNMaxPeaks);
147 addToMap(
"TPC Clusterer Sector Clusters", usageMap,
processors()->tpcClusterer[
i].mPmemory->counters.nClusters,
processors()->tpcClusterer[
i].mNMaxClusters);
150 addToMap(
"TPC Sector Start Hits", usageMap, *
processors()->tpcTrackers[
i].NStartHits(),
processors()->tpcTrackers[
i].NMaxStartHits());
151 addToMap(
"TPC Sector Tracklets", usageMap, *
processors()->tpcTrackers[
i].NTracklets(),
processors()->tpcTrackers[
i].NMaxTracklets());
152 addToMap(
"TPC Sector TrackletHits", usageMap, *
processors()->tpcTrackers[
i].NRowHits(),
processors()->tpcTrackers[
i].NMaxRowHits());
153 addToMap(
"TPC Sector Tracks", usageMap, *
processors()->tpcTrackers[
i].NTracks(),
processors()->tpcTrackers[
i].NMaxTracks());
154 addToMap(
"TPC Sector TrackHits", usageMap, *
processors()->tpcTrackers[
i].NTrackHits(),
processors()->tpcTrackers[
i].NMaxTrackHits());
158 addToMap(
"TPC Tracks", usageMap,
processors()->tpcMerger.NMergedTracks(),
processors()->tpcMerger.NMaxTracks());
159 addToMap(
"TPC TrackHits", usageMap,
processors()->tpcMerger.NMergedTrackClusters(),
processors()->tpcMerger.NMaxMergedTrackClusters());
163 addToMap(
"TPC O2 Tracks", usageMap,
processors()->tpcMerger.NOutputTracksTPCO2(),
processors()->tpcMerger.NOutputTracksTPCO2());
164 addToMap(
"TPC O2 ClusRefs", usageMap,
processors()->tpcMerger.NOutputClusRefsTPCO2(),
processors()->tpcMerger.NOutputClusRefsTPCO2());
169 addToMap(
"TPC ComprCache HitsAttached", usageMap,
processors()->tpcCompressor.mOutput->nAttachedClusters,
processors()->tpcCompressor.mMaxTrackClusters);
170 addToMap(
"TPC ComprCache HitsUnattached", usageMap,
processors()->tpcCompressor.mOutput->nUnattachedClusters,
processors()->tpcCompressor.mMaxClustersInCache);
171 addToMap(
"TPC ComprCache Tracks", usageMap,
processors()->tpcCompressor.mOutput->nTracks,
processors()->tpcCompressor.mMaxTracks);
175 for (
auto& elem : usageMap) {
176 printf(
"Mem Usage %-30s : %'14zu / %'14zu (%3.0f%% / %3.0f%% / count %3u / max %'14zu)\n", elem.first.c_str(), elem.second.nSum, elem.second.nBoundSum, 100. * elem.second.nSum / std::max<size_t>(1, elem.second.nBoundSum), 100. * elem.second.maxUse, elem.second.count, elem.second.nMax);
183 GPUInfo(
"MEMREL StartHits NCl %d NTrkl %d",
processors()->tpcTrackers[
i].NHitsTotal(), *
processors()->tpcTrackers[
i].NStartHits());
184 GPUInfo(
"MEMREL Tracklets NCl %d NTrkl %d",
processors()->tpcTrackers[
i].NHitsTotal(), *
processors()->tpcTrackers[
i].NTracklets());
185 GPUInfo(
"MEMREL Tracklets NCl %d NTrkl %d",
processors()->tpcTrackers[
i].NHitsTotal(), *
processors()->tpcTrackers[
i].NRowHits());
186 GPUInfo(
"MEMREL SectorTracks NCl %d NTrk %d",
processors()->tpcTrackers[
i].NHitsTotal(), *
processors()->tpcTrackers[
i].NTracks());
187 GPUInfo(
"MEMREL SectorTrackHits NCl %d NTrkH %d",
processors()->tpcTrackers[
i].NHitsTotal(), *
processors()->tpcTrackers[
i].NTrackHits());
190 GPUInfo(
"MEMREL Tracks NCl %d NTrk %d",
processors()->tpcMerger.NMaxClusters(),
processors()->tpcMerger.NMergedTracks());
191 GPUInfo(
"MEMREL TrackHitss NCl %d NTrkH %d",
processors()->tpcMerger.NMaxClusters(),
processors()->tpcMerger.NMergedTrackClusters());
197#ifdef GPUCA_KERNEL_DEBUGGER_OUTPUT
210#ifdef GPUCA_KERNEL_DEBUGGER_OUTPUT
219 int32_t nTracks = 0, nAttachedClusters = 0, nAttachedClustersFitted = 0, nAdjacentClusters = 0;
234 for (
uint32_t k = 0; k < nCls; k++) {
242 char trdText[1024] =
"";
249 nTRDTracklets += trk.getNtracklets();
250 nTRDTracks += trk.getNtracklets() != 0;
253 nTRDTracklets += trk.getNtracklets();
254 nTRDTracks += trk.getNtracklets() != 0;
257 snprintf(trdText, 1024,
" - TRD Tracker reconstructed %d tracks (%d tracklets)", nTRDTracks, nTRDTracklets);
259 GPUInfo(
"Output Tracks: %d (%d / %d / %d / %d clusters (fitted / attached / adjacent / total) - %s format)%s", nTracks, nAttachedClustersFitted, nAttachedClusters, nAdjacentClusters, nCls,
GetProcessingSettings().createO2Output > 1 ?
"O2" :
"GPU", trdText);
262void GPUChainTracking::OutputSanityCheck()
268 const auto&
ref = trk.getClusterRef();
270 if (nErrors++ < 1000) {
276 if (nErrors++ < 1000) {
281 for (int32_t
j = 0;
j < trk.getNClusters();
j++) {
285 if (
sector >= GPUTPCGeometry::NSECTORS ||
row >= GPUTPCGeometry::NROWS) {
286 if (nErrors++ < 1000) {
287 GPUError(
"Invalid sector / row %d / %d", (int32_t)
sector, (int32_t)
row);
292 if (nErrors++ < 1000) {
300 GPUInfo(
"Sanity check passed");
302 GPUError(
"Sanity check found %lu errors", nErrors);
311 for (int32_t iPhase = 0; iPhase < 2; iPhase++) {
314 for (
uint32_t iRow = 0; iRow < GPUTPCGeometry::NROWS; iRow++) {
319 if (applyClusterCuts) {
320 keep = keep && cl.getQtot() >
param().
rec.tpc.cfQTotCutoff && cl.
qMax >
param().
rec.tpc.cfQMaxCutoff;
326 keep = keep && (!filterType || clusterFilter.filter(
iSector, iRow, cl));
327 if (iPhase && keep) {
328 outputBuffer[countTotal] = cl;
339 clusters->clustersLinear = outputBuffer;
342 outputBuffer = allocator(countTotal);
349 out <<
"\nTPC Clusters:\n";
350 for (
uint32_t iSec = 0; iSec < GPUTPCGeometry::NSECTORS; iSec++) {
351 out <<
"TPCClusters - Sector " << iSec <<
"\n";
352 for (
uint32_t i = 0;
i < GPUTPCGeometry::NROWS;
i++) {
353 out <<
" Row: " <<
i <<
": " <<
clusters->nClusters[iSec][
i] <<
" clusters:\n";
355 const auto& cl =
clusters->clusters[iSec][
i][
j];
365 std::vector<uint32_t> sorted(
c.nTracks),
offsets(
c.nTracks);
366 std::iota(sorted.begin(), sorted.end(), 0);
367 auto sorter = [&
c](
const auto a,
const auto b) {
368 return std::tie(
c.sliceA[
a],
c.rowA[
a],
c.timeA[
a],
c.padA[
a],
c.qPtA[
a]) <
369 std::tie(
c.sliceA[
b],
c.rowA[
b],
c.timeA[
b],
c.padA[
b],
c.qPtA[
b]);
371 std::sort(sorted.begin(), sorted.end(), sorter);
378 auto sortArray = [&
c, &sorted, &
offsets](
auto*
src,
size_t totalSize,
auto getOffset,
auto getSize) {
379 auto buf = std::make_unique<std::remove_reference_t<
decltype(
src[0])>[]>(totalSize);
380 memcpy(
buf.get(),
src, totalSize *
sizeof(*
src));
385 targetOffset += getSize(
j);
388 auto sortMultiple = [&sortArray](
size_t totalSize,
auto getOffset,
auto getSize,
auto&&...
arrays) {
392 auto getReducedOffset = [](
uint32_t off,
uint32_t ind) {
return off - ind; };
394 auto getN = [&
c](
uint32_t j) {
return c.nTrackClusters[
j]; };
395 auto getN1 = [&
c](
uint32_t j) {
return c.nTrackClusters[
j] - 1; };
396 auto get1 = [](
uint32_t j) {
return 1; };
398 sortMultiple(
c.nAttachedClusters, getFullOffset, getN,
c.qTotA,
c.qMaxA,
c.flagsA,
c.sigmaPadA,
c.sigmaTimeA);
399 sortMultiple(
c.nAttachedClustersReduced, getReducedOffset, getN1,
c.rowDiffA,
c.sliceLegDiffA,
c.padResA,
c.timeResA);
400 sortMultiple(
c.nTracks, getIndex, get1,
c.qPtA,
c.rowA,
c.sliceA,
c.timeA,
c.padA,
c.nTrackClusters);
418 GPUInfo(
"Doing debug raw dump");
420 DumpData((dirName +
"/event.0.dump").c_str(), &ioPtrs);
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
static void DebugSortCompressedClusters(o2::tpc::CompressedClustersFlat *cls)
void PrintKernelDebugOutput()
void PrintMemoryStatistics() override
static void DumpClusters(std::ostream &out, const o2::tpc::ClusterNativeAccess *clusters)
void PrintMemoryRelations()
void DumpData(const char *filename, const GPUTrackingInOutPointers *ioPtrs=nullptr)
void PrepareKernelDebugOutput()
GPUTrackingInOutPointers & mIOPtrs
GPUReconstruction::RecoStepField GetRecoSteps() const
void WriteToConstantMemory(RecoStep step, size_t offset, const void *src, size_t size, int32_t stream=-1, deviceEvent *ev=nullptr)
uint32_t ThreadCount() const
virtual std::unique_ptr< GPUReconstructionProcessing::threadContext > GetThreadContext()
GPUConstantMem * processors()
void SetupGPUProcessor(T *proc, bool allocate)
const GPUSettingsProcessing & GetProcessingSettings() const
GPUReconstructionCPU * mRec
GPUConstantMem * processorsShadow()
static constexpr int32_t NSECTORS
void TransferMemoryResourcesToHost(RecoStep step, GPUProcessor *proc, int32_t stream=-1, bool all=false)
uint32_t BlockCount() const
GPUReconstruction * rec()
virtual size_t GPUMemCpy(void *dst, const void *src, size_t size, int32_t stream, int32_t toGPU, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1)
std::string getDebugFolder(const std::string &prefix="")
GPUMemorySizeScalers * MemoryScalers()
const GPUSettingsProcessing & GetProcessingSettings() const
void DumpSettings(const char *dir="")
void * AllocateDirectMemory(size_t size, int32_t type)
GLuint GLsizei const GLuint const GLintptr * offsets
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLenum GLuint GLenum GLsizei const GLchar * buf
GPUTPCTracker tpcTrackers[GPUTPCGeometry::NSECTORS]
size_t NTPCClusters(size_t tpcDigits, bool perSector=false)
const o2::tpc::ClusterNativeAccess * clustersNative
const uint32_t * outputClusRefsTPCO2
const uint32_t * mergedTrackHitAttachment
const GPUTRDTrackGPU * trdTracks
const GPUTrackingInOutZS * tpcZS
const GPUTRDTrack * trdTracksO2
uint32_t nOutputTracksTPCO2
uint32_t nMergedTrackHits
uint32_t nOutputClusRefsTPCO2
const o2::tpc::TrackTPC * outputTracksTPCO2
const GPUTrackingInOutDigits * tpcPackedDigits
const GPUTPCGMMergedTrack * mergedTracks
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClustersTotal
std::vector< Cluster > clusters
auto getOffset(const map_T &resultsMap) -> typename map_T::key_type