Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions DataFormats/Detectors/TPC/src/CompressedClusters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ namespace o2::tpc

CompressedClusters::CompressedClusters(const CompressedClustersFlat& c)
{
CompressedClustersCounters& cc = *this;
CompressedClustersPtrs& cp = *this;
const CompressedClustersOffsets& offsets = c;
cc = c;
for (unsigned int i = 0; i < sizeof(cp) / sizeof(size_t); i++) {
reinterpret_cast<void**>(&cp)[i] = reinterpret_cast<void*>(reinterpret_cast<const size_t*>(&offsets)[i] + reinterpret_cast<size_t>(&c)); // Restore pointers from offsets
if (c.ptrForward) {
*this = *c.ptrForward;
} else {
CompressedClustersCounters& cc = *this;
CompressedClustersPtrs& cp = *this;
const CompressedClustersOffsets& offsets = c;
cc = c;
for (unsigned int i = 0; i < sizeof(cp) / sizeof(size_t); i++) {
reinterpret_cast<void**>(&cp)[i] = reinterpret_cast<void*>(reinterpret_cast<const size_t*>(&offsets)[i] + reinterpret_cast<size_t>(&c)); // Restore pointers from offsets
}
}
};

Expand Down
127 changes: 4 additions & 123 deletions Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#include "GPUO2InterfaceUtils.h"
#include "GPUParam.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "TPCClusterDecompressionCore.inc"
#include "GPUTPCCompressionKernels.inc"
#include "TPCClusterDecompressionFilter.inc"
#include "TPCCalibration/VDriftHelper.h"
#include "DetectorsBase/GRPGeomHelper.h"

Expand Down Expand Up @@ -127,7 +126,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc)
auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{"TPC", "CTFDATA", 0});
std::vector<bool> rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced;
CompressedClusters clustersFiltered = clusters;
std::vector<std::pair<std::vector<unsigned int>, std::vector<unsigned short>>> tmpBuffer(std::max<int>(mNThreads, 1));
std::vector<std::pair<std::vector<unsigned int>, std::vector<unsigned short>>> tmpBuffer;

// prepare trigger info
trigComp.clear();
Expand All @@ -144,128 +143,10 @@ void EntropyEncoderSpec::run(ProcessingContext& pc)
}

if (mSelIR) {
if (clusters.nTracks && clusters.solenoidBz != -1e6f && clusters.solenoidBz != mParam->bzkG) {
throw std::runtime_error("Configured solenoid Bz does not match value used for track model encoding");
}
if (clusters.nTracks && clusters.maxTimeBin != -1e6 && clusters.maxTimeBin != mParam->continuousMaxTimeBin) {
throw std::runtime_error("Configured max time bin does not match value used for track model encoding");
}
mCTFCoder.setSelectedIRFrames(pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("selIRFrames"));
rejectHits.resize(clusters.nUnattachedClusters);
rejectTracks.resize(clusters.nTracks);
rejectTrackHits.resize(clusters.nAttachedClusters);
rejectTrackHitsReduced.resize(clusters.nAttachedClustersReduced);

auto chkFunc = [&](const o2::InteractionRecord& chkVal, float chkExt) { return mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; };
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
const auto firstIR = o2::InteractionRecord(0, tinfo.firstTForbit);
const float totalT = std::max(mFastTransform->getMaxDriftTime(0), mFastTransform->getMaxDriftTime(GPUTPCGeometry::NSECTORS / 2));

unsigned int offset = 0, lasti = 0;
const unsigned int maxTime = (mParam->continuousMaxTimeBin + 1) * o2::tpc::ClusterNative::scaleTimePacked - 1;
#ifdef WITH_OPENMP
#pragma omp parallel for firstprivate(offset, lasti) num_threads(mNThreads)
#endif
for (unsigned int i = 0; i < clusters.nTracks; i++) {
unsigned int tMinP = maxTime, tMaxP = 0;
auto checker = [&tMinP, &tMaxP](const o2::tpc::ClusterNative& cl, unsigned int offset) {
if (cl.getTimePacked() > tMaxP) {
tMaxP = cl.getTimePacked();
}
if (cl.getTimePacked() < tMinP) {
tMinP = cl.getTimePacked();
}
};
if (i < lasti) {
offset = lasti = 0; // dynamic OMP scheduling, need to reinitialize offset
}
while (lasti < i) {
offset += clusters.nTrackClusters[lasti++];
}
lasti++;
o2::gpu::TPCClusterDecompressionCore::decompressTrack(clusters, *mParam, maxTime, i, offset, checker);
const float tMin = o2::tpc::ClusterNative::unpackTime(tMinP), tMax = o2::tpc::ClusterNative::unpackTime(tMaxP);
const auto chkVal = firstIR + (tMin * constants::LHCBCPERTIMEBIN);
const auto chkExt = totalT > tMax - tMin ? ((totalT - (tMax - tMin)) * constants::LHCBCPERTIMEBIN + 1) : 0;
const bool reject = mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0;
if (reject) {
for (unsigned int k = offset - clusters.nTrackClusters[i]; k < offset; k++) {
rejectTrackHits[k] = true;
}
for (unsigned int k = offset - clusters.nTrackClusters[i] - i; k < offset - i - 1; k++) {
rejectTrackHitsReduced[k] = true;
}
rejectTracks[i] = true;
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
while (lock.test_and_set(std::memory_order_acquire)) {
}
clustersFiltered.nTracks--;
clustersFiltered.nAttachedClusters -= clusters.nTrackClusters[i];
clustersFiltered.nAttachedClustersReduced -= clusters.nTrackClusters[i] - 1;
lock.clear(std::memory_order_release);
}
}
offset = 0;
unsigned int offsets[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS];
for (unsigned int i = 0; i < GPUTPCGeometry::NSECTORS; i++) {
for (unsigned int j = 0; j < GPUTPCGeometry::NROWS; j++) {
if (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) {
break;
}
offsets[i][j] = offset;
offset += (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) ? 0 : clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j];
}
}

#ifdef WITH_OPENMP
#pragma omp parallel for num_threads(mNThreads) schedule(static, (GPUTPCGeometry::NSECTORS + mNThreads - 1) / mNThreads) // Static round-robin scheduling with one chunk per thread to ensure correct order of the final vector
#endif
for (unsigned int ii = 0; ii < clusters.nSliceRows; ii++) {
unsigned int i = ii / GPUTPCGeometry::NROWS;
unsigned int j = ii % GPUTPCGeometry::NROWS;
o2::tpc::ClusterNative preCl;
#ifdef WITH_OPENMP
int myThread = omp_get_thread_num();
#else
int myThread = 0;
#endif
unsigned int count = 0;
const float x = GPUTPCGeometry::Row2X(j);
auto checker = [i, j, firstIR, totalT, x, this, &preCl, &count, &outBuffer = tmpBuffer[myThread], &rejectHits, &clustersFiltered](const o2::tpc::ClusterNative& cl, unsigned int k) {
const float y = GPUTPCGeometry::LinearPad2Y(i, j, cl.getPad());
const float r = sqrtf(x * x + y * y);
const float maxz = r * mEtaFactor + mMaxZ;
const unsigned int deltaBC = std::max<float>(0.f, totalT - mFastTransform->convDeltaZtoDeltaTimeInTimeFrameAbs(maxz)) * constants::LHCBCPERTIMEBIN;
const auto chkVal = firstIR + (cl.getTime() * constants::LHCBCPERTIMEBIN) - deltaBC;
const auto chkExt = totalT * constants::LHCBCPERTIMEBIN - deltaBC;
const bool reject = mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0;
if (reject) {
rejectHits[k] = true;
clustersFiltered.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]--;
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
while (lock.test_and_set(std::memory_order_acquire)) {
}
clustersFiltered.nUnattachedClusters--;
lock.clear(std::memory_order_release);
} else {
outBuffer.first.emplace_back(0);
outBuffer.second.emplace_back(0);
GPUTPCCompression_EncodeUnattached(clustersFiltered.nComppressionModes, cl, outBuffer.first.back(), outBuffer.second.back(), count++ ? &preCl : nullptr);
preCl = cl;
}
};
unsigned int end = offsets[i][j] + clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j];
o2::gpu::TPCClusterDecompressionCore::decompressHits(clusters, offsets[i][j], end, checker);
}
tmpBuffer[0].first.reserve(clustersFiltered.nUnattachedClusters);
tmpBuffer[0].second.reserve(clustersFiltered.nUnattachedClusters);
for (int i = 1; i < mNThreads; i++) {
tmpBuffer[0].first.insert(tmpBuffer[0].first.end(), tmpBuffer[i].first.begin(), tmpBuffer[i].first.end());
tmpBuffer[i].first.clear();
tmpBuffer[0].second.insert(tmpBuffer[0].second.end(), tmpBuffer[i].second.begin(), tmpBuffer[i].second.end());
tmpBuffer[i].second.clear();
}
clustersFiltered.timeDiffU = tmpBuffer[0].first.data();
clustersFiltered.padDiffU = tmpBuffer[0].second.data();
o2::gpu::TPCClusterDecompressionFilter::runFilter(*mParam, *mFastTransform, clusters, clustersFiltered, rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced, tmpBuffer, mNThreads, tinfo.firstTForbit, chkFunc, mEtaFactor, mMaxZ);
}

// transform trigger info to differential form
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUTracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ set(HDRS_INSTALL
DataCompression/GPUTPCClusterRejection.h
DataCompression/GPUTPCCompressionKernels.inc
DataCompression/TPCClusterDecompressionCore.inc
DataCompression/TPCClusterDecompressionFilter.inc
DataTypes/GPUdEdxInfo.h
DataTypes/GPUHostDataTypes.h
DataTypes/GPUO2DataTypes.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess*
std::vector<o2::tpc::ClusterNative> clusterBuffer;
GPUInfo("Compression statistics, decoding: %d attached (%d tracks), %d unattached", clustersCompressed->nAttachedClusters, clustersCompressed->nTracks, clustersCompressed->nUnattachedClusters);
auto allocator = [&clusterBuffer](size_t size) {clusterBuffer.resize(size); return clusterBuffer.data(); };
mDecoder.decompress(clustersCompressed, clustersNativeDecoded, allocator, param, true);
mDecoder.decompress(*clustersCompressed, clustersNativeDecoded, allocator, param, true);
std::vector<o2::tpc::ClusterNative> tmpClusters;
if (param.rec.tpc.rejectionStrategy == GPUSettings::RejectionNone) { // verification does not make sense if we reject clusters during compression
for (uint32_t i = 0; i < NSECTORS; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file GPUTPCCompressionKernels.cxx
/// \file GPUTPCCompressionKernels.inc
/// \author David Rohr

#include "GPUO2DataTypes.h"
Expand All @@ -20,7 +20,7 @@
namespace o2::gpu
{

GPUdii() void GPUTPCCompression_EncodeUnattached(uint8_t nComppressionModes, const o2::tpc::ClusterNative& orgCl, uint32_t& outTime, uint16_t& outPad, const o2::tpc::ClusterNative* orgClPre = nullptr)
GPUdi() GPUAlwaysInline() void GPUTPCCompression_EncodeUnattached(uint8_t nComppressionModes, const o2::tpc::ClusterNative& orgCl, uint32_t& outTime, uint16_t& outPad, const o2::tpc::ClusterNative* orgClPre = nullptr)
{
if (nComppressionModes & GPUSettings::CompressionDifferences) {
uint32_t lastTime = 0, lastPad = 0;
Expand Down
42 changes: 21 additions & 21 deletions GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file TPCCLusterDecompressionCore.inc
/// \file TPCClusterDecompressionCore.inc
/// \author Gabriele Cimador

#ifndef TPCCLUSTERDECOMPRESSOR_INC
Expand All @@ -21,50 +21,50 @@
#include "GPUCommonAlgorithm.h"
#include "GPUO2DataTypes.h"
#include "GPUTPCGeometry.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/CompressedClusters.h"

#ifndef GPUCA_GPUCODE
#include <functional>
#endif

using namespace o2::tpc;

namespace o2::gpu
{

class TPCClusterDecompressionCore
{
public:
#ifndef GPUCA_GPUCODE
GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::function<void(const ClusterNative&, uint32_t)> func)
GPUhi() static auto decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::function<void(const o2::tpc::ClusterNative&, uint32_t)> func)
{
const auto cluster = ClusterNative(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]);
const auto cluster = o2::tpc::ClusterNative(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]);
func(cluster, offset);
return cluster;
}

GPUhi() static const auto& decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector<ClusterNative>& clusterVector)
GPUhi() static const auto& decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector<o2::tpc::ClusterNative>& clusterVector)
{
clusterVector.emplace_back(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]);
return clusterVector.back();
}

GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector<ClusterNative> (&clusters)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS], std::atomic_flag (&locks)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS])
GPUhi() static auto decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector<o2::tpc::ClusterNative> (&clusters)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS], std::atomic_flag (&locks)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS])
{
std::vector<ClusterNative>& clusterVector = clusters[slice][row];
std::vector<o2::tpc::ClusterNative>& clusterVector = clusters[slice][row];
auto& lock = locks[slice][row];
while (lock.test_and_set(std::memory_order_acquire)) {
}
ClusterNative retVal = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, clusterVector);
o2::tpc::ClusterNative retVal = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, clusterVector);
lock.clear(std::memory_order_release);
return retVal;
}
#endif

GPUdi() static ClusterNative decompressTrackStore(const CompressedClusters& cmprClusters, const uint32_t clusterOffset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, GPUTPCDecompression& decompressor)
GPUdi() static o2::tpc::ClusterNative decompressTrackStore(const o2::tpc::CompressedClusters& cmprClusters, const uint32_t clusterOffset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, GPUTPCDecompression& decompressor)
{
uint32_t tmpBufferIndex = slice * (GPUTPCGeometry::NROWS * decompressor.mMaxNativeClustersPerBuffer) + row * decompressor.mMaxNativeClustersPerBuffer;
uint32_t currentClusterIndex = CAMath::AtomicAdd(decompressor.mNativeClustersIndex + (slice * GPUTPCGeometry::NROWS + row), 1u);
const ClusterNative c(time, cmprClusters.flagsA[clusterOffset], pad, cmprClusters.sigmaTimeA[clusterOffset], cmprClusters.sigmaPadA[clusterOffset], cmprClusters.qMaxA[clusterOffset], cmprClusters.qTotA[clusterOffset]);
const o2::tpc::ClusterNative c(time, cmprClusters.flagsA[clusterOffset], pad, cmprClusters.sigmaTimeA[clusterOffset], cmprClusters.sigmaPadA[clusterOffset], cmprClusters.qMaxA[clusterOffset], cmprClusters.qTotA[clusterOffset]);
if (currentClusterIndex < decompressor.mMaxNativeClustersPerBuffer) {
decompressor.mTmpNativeClusters[tmpBufferIndex + currentClusterIndex] = c;
} else {
Expand All @@ -75,7 +75,7 @@ class TPCClusterDecompressionCore
}

template <typename... Args>
GPUdi() static void decompressTrack(const CompressedClusters& cmprClusters, const GPUParam& param, const uint32_t maxTime, const uint32_t& trackIndex, uint32_t& clusterOffset, Args&... args)
GPUdi() static void decompressTrack(const o2::tpc::CompressedClusters& cmprClusters, const GPUParam& param, const uint32_t maxTime, const uint32_t& trackIndex, uint32_t& clusterOffset, Args&... args)
{
float zOffset = 0;
uint32_t slice = cmprClusters.sliceA[trackIndex];
Expand Down Expand Up @@ -114,16 +114,16 @@ class TPCClusterDecompressionCore
if (timeTmp & 0x800000) {
timeTmp |= 0xFF000000;
}
time = timeTmp + ClusterNative::packTime(CAMath::Max(0.f, geo.LinearZ2Time(slice, track.Z() + zOffset)));
time = timeTmp + o2::tpc::ClusterNative::packTime(CAMath::Max(0.f, geo.LinearZ2Time(slice, track.Z() + zOffset)));
float tmpPad = CAMath::Max(0.f, CAMath::Min((float)geo.NPads(GPUTPCGeometry::NROWS - 1), track.LinearY2Pad(slice, track.Y(), geo.PadWidth(row), geo.NPads(row))));
pad = cmprClusters.padResA[clusterOffset - trackIndex - 1] + ClusterNative::packPad(tmpPad);
pad = cmprClusters.padResA[clusterOffset - trackIndex - 1] + o2::tpc::ClusterNative::packPad(tmpPad);
time = time & 0xFFFFFF;
pad = (uint16_t)pad;
if (pad >= geo.NPads(row) * ClusterNative::scalePadPacked) {
if (pad >= geo.NPads(row) * o2::tpc::ClusterNative::scalePadPacked) {
if (pad >= 0xFFFF - 11968) { // Constant 11968 = (2^15 - MAX_PADS(138) * scalePadPacked(64)) / 2
pad = 0;
} else {
pad = geo.NPads(row) * ClusterNative::scalePadPacked - 1;
pad = geo.NPads(row) * o2::tpc::ClusterNative::scalePadPacked - 1;
}
}
if (param.continuousMaxTimeBin > 0 && time >= maxTime) {
Expand Down Expand Up @@ -152,22 +152,22 @@ class TPCClusterDecompressionCore
clusterOffset += cmprClusters.nTrackClusters[trackIndex] - clusterIndex;
}

GPUdi() static const auto& decompressHitsStore(const CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, ClusterNative*& clusterBuffer)
GPUdi() static const auto& decompressHitsStore(const o2::tpc::CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, o2::tpc::ClusterNative*& clusterBuffer)
{
return ((*(clusterBuffer++) = ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k])));
return ((*(clusterBuffer++) = o2::tpc::ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k])));
}

#ifndef GPUCA_GPUCODE
GPUhi() static auto decompressHitsStore(const CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, std::function<void(const ClusterNative&, uint32_t)> func)
GPUhi() static auto decompressHitsStore(const o2::tpc::CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, std::function<void(const o2::tpc::ClusterNative&, uint32_t)> func)
{
const auto cluster = ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]);
const auto cluster = o2::tpc::ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]);
func(cluster, k);
return cluster;
}
#endif

template <typename... Args>
GPUdi() static void decompressHits(const CompressedClusters& cmprClusters, const uint32_t start, const uint32_t end, Args&... args)
GPUdi() static void decompressHits(const o2::tpc::CompressedClusters& cmprClusters, const uint32_t start, const uint32_t end, Args&... args)
{
uint32_t time = 0;
uint16_t pad = 0;
Expand Down
Loading