24#ifndef GPUCA_GPUCODE_DEVICE
42 mRows[
i].mX = GPUTPCGeometry::Row2X(
i);
43 mRows[
i].mMaxY = CAMath::Tan(p.dAlpha / 2.f) * mRows[
i].mX;
50 mClusterIdOffset = clusterIdOffset;
56 const uint32_t kVectorAlignment = 256;
103 maxZ = (mem->param.continuousMaxTimeBin > 0 ? (mem->calibObjects.fastTransformHelper->getCorrMap()->convTimeToZinTimeFrame(0, 0, mem->param.continuousMaxTimeBin)) : GPUTPCGeometry::TPCLength()) + 50;
109 return 128 *
nRows + 4 * nHits;
115 float tfFactor = 1.f;
116 if (dz > GPUTPCGeometry::TPCLength() + 20.f) {
117 tfFactor = dz / GPUTPCGeometry::TPCLength();
118 dz = GPUTPCGeometry::TPCLength();
120 const float norm = CAMath::InvSqrt(
row->mNHits / tfFactor);
124 GetMaxNBins(mem,
row, maxy, maxz);
125 int32_t ny = CAMath::Max(1, CAMath::Min<int32_t>(maxy, (
yMax - yMin) / sy + 1));
126 int32_t nz = CAMath::Max(1, CAMath::Min<int32_t>(maxz, (
zMax -
zMin) / sz + 1));
149 row.mGrid.CreateEmpty();
151 row.mHitNumberOffset = 0;
158 for (int32_t
i = 0;
i < 4;
i++) {
172 static_assert(
sizeof(*YZData) <= (
sizeof(*mLinkUpData) +
sizeof(*mLinkDownData)),
"Cannot reuse memory");
173 static_assert(
sizeof(*binMemory) <=
sizeof(*mHitWeights),
"Cannot reuse memory");
176 for (int32_t rowIndex = iBlock; rowIndex <
GPUCA_ROW_COUNT; rowIndex += nBlocks) {
182 const uint32_t NumberOfClusters = mem->ioPtrs.clustersNative->nClusters[iSector][rowIndex];
183 const uint32_t RowOffset = mem->ioPtrs.clustersNative->clusterOffset[iSector][rowIndex] - mem->ioPtrs.clustersNative->clusterOffset[iSector][0];
184 constexpr const uint32_t maxN = 1u << (
sizeof(
calink) < 3 ? (
sizeof(
calink) * 8) : 24);
189 if (NumberOfClusters >= maxN) {
191 mem->errorCodes.raiseError(GPUErrors::ERROR_SECTORDATA_HITINROW_OVERFLOW, iSector * 1000 + rowIndex, NumberOfClusters, maxN);
192 SetRowGridEmpty(
row);
205 if (NumberOfClusters == 0) {
207 SetRowGridEmpty(
row);
212 for (uint32_t
i = iThread;
i < NumberOfClusters;
i += nThreads) {
214 GPUTPCConvertImpl::convert(*mem, iSector, rowIndex, mem->ioPtrs.clustersNative->clusters[iSector][rowIndex][
i].getPad(), mem->ioPtrs.clustersNative->clusters[iSector][rowIndex][
i].getTime(),
x,
y,
z);
216 YZData[RowOffset +
i] = CAMath::MakeFloat2(
y,
z);
220 row.mNHits = NumberOfClusters;
224#ifdef GPUCA_HAVE_ATOMIC_MINMAX_FLOAT
225 CAMath::AtomicMinShared(&tmpMinMax[0], yMin);
226 CAMath::AtomicMaxShared(&tmpMinMax[1],
yMax);
227 CAMath::AtomicMinShared(&tmpMinMax[2],
zMin);
228 CAMath::AtomicMaxShared(&tmpMinMax[3],
zMax);
230 for (int32_t
i = 0;
i < nThreads;
i++) {
233 if (tmpMinMax[0] > yMin) {
236 if (tmpMinMax[1] <
yMax) {
239 if (tmpMinMax[2] >
zMin) {
242 if (tmpMinMax[3] <
zMax) {
250 CreateGrid(mem, &
row, tmpMinMax[0], tmpMinMax[1], tmpMinMax[2], tmpMinMax[3]);
254 const int32_t numberOfBins = grid.N();
255 constexpr const int32_t maxBins =
sizeof(
calink) < 4 ? (int32_t)(1ul << (
sizeof(
calink) * 8)) : 0x7FFFFFFF;
256 if (
sizeof(
calink) < 4 && numberOfBins >= maxBins) {
258 mem->errorCodes.raiseError(GPUErrors::ERROR_SECTORDATA_BIN_OVERFLOW, iSector * 1000 + rowIndex, numberOfBins, maxBins);
259 SetRowGridEmpty(
row);
263 const uint32_t nn = numberOfBins + grid.Ny() + 3;
264 const uint32_t maxnn = GetGridSize(NumberOfClusters, 1);
267 mem->errorCodes.raiseError(GPUErrors::ERROR_SECTORDATA_FIRSTHITINBIN_OVERFLOW, iSector, nn, maxnn);
268 SetRowGridEmpty(
row);
275 for (int32_t bin = iThread; bin < numberOfBins; bin += nThreads) {
279 for (int32_t hitIndex = iThread; hitIndex <
row.mNHits; hitIndex += nThreads) {
280 const int32_t globalHitIndex = RowOffset + hitIndex;
281 const calink bin =
row.mGrid.GetBin(YZData[globalHitIndex].
x, YZData[globalHitIndex].
y);
283 bins[hitIndex] = bin;
284 CAMath::AtomicAdd(&
c[bin], 1u);
290 for (int32_t bin = 0; bin < numberOfBins; ++bin) {
294 for (uint32_t bin = numberOfBins; bin < nn; bin++) {
300 constexpr float maxVal = (((int64_t)1 << (
sizeof(
cahit) < 3 ?
sizeof(
cahit) * 8 : 24)) - 1);
301 constexpr float packingConstant = 1.f / (maxVal - 2.f);
302 const float y0 =
row.mGrid.YMin();
303 const float z0 =
row.mGrid.ZMin();
304 const float stepY = (
row.mGrid.YMax() -
y0) * packingConstant;
305 const float stepZ = (
row.mGrid.ZMax() - z0) * packingConstant;
306 const float stepYi = 1.f / stepY;
307 const float stepZi = 1.f / stepZ;
314 row.mHstepYi = stepYi;
315 row.mHstepZi = stepZi;
320 for (int32_t hitIndex = iThread; hitIndex <
row.mNHits; hitIndex += nThreads) {
322 const calink ind = CAMath::AtomicAdd(&
c[bin], (
calink)-1) - 1;
323 const int32_t globalBinsortedIndex =
row.mHitNumberOffset + ind;
324 const int32_t globalHitIndex = RowOffset + hitIndex;
327 mClusterDataIndex[globalBinsortedIndex] = RowOffset + hitIndex;
329 const float xx = ((YZData[globalHitIndex].
x -
y0) * stepYi) + .5;
330 const float yy = ((YZData[globalHitIndex].
y - z0) * stepZi) + .5;
331#if !defined(GPUCA_GPUCODE) && !defined(NDEBUG)
332 if (xx < 0 || yy < 0 || xx > maxVal || yy > maxVal) {
333 std::cout <<
"!!!! hit packing error!!! " << xx <<
" " << yy <<
" (" << maxVal <<
")" << std::endl;
338 mHitData[globalBinsortedIndex].x = (
cahit)xx;
339 mHitData[globalBinsortedIndex].y = (
cahit)yy;
344 if (iThread == 0 && !mem->param.par.continuousTracking) {
345 const float maxAbsZ = CAMath::Max(CAMath::Abs(tmpMinMax[2]), CAMath::Abs(tmpMinMax[3]));
347 mem->errorCodes.raiseError(GPUErrors::ERROR_SECTORDATA_Z_OVERFLOW, iSector, (uint32_t)maxAbsZ);
348 SetRowGridEmpty(
row);
#define GPUCA_MAX_BIN_SIZE
#define GPUCA_MIN_BIN_SIZE
#define GPUCA_ROWALIGNMENT
static void computePointerWithAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
static constexpr size_t nextMultipleOf(size_t size)
void SetClusterData(int32_t nClusters, int32_t clusterIdOffset)
void InitializeRows(const GPUParam &p)
void * SetPointersScratch(void *mem, bool idsOnGPU)
void * SetPointersWeights(void *mem)
void * SetPointersClusterIds(void *mem, bool idsOnGPU)
void * SetPointersLinks(void *mem)
void * SetPointersRows(void *mem)
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
GLuint GLfloat GLfloat y0
GLdouble GLdouble GLdouble z
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
constexpr std::array< int, nLayers > nRows
typename std::vector< T, vecpod_allocator< T > > vecpod