From e2ee3fc2c9af0a1b45e767b79b28e15ef472361e Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:45:00 +0100 Subject: [PATCH 1/2] GPU Metal: provide numeric_limits and the layout traits in GPUCommonTypeTraits MSL has metal::numeric_limits but no std:: one, and no is_standard_layout_v or is_trivially_copyable_v. Shared headers that use them in static_asserts or type selections then compile for Metal unchanged. --- GPU/Common/GPUCommonTypeTraits.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GPU/Common/GPUCommonTypeTraits.h b/GPU/Common/GPUCommonTypeTraits.h index 6d72f164771bc..96688ab7daa2b 100644 --- a/GPU/Common/GPUCommonTypeTraits.h +++ b/GPU/Common/GPUCommonTypeTraits.h @@ -33,6 +33,13 @@ #endif namespace std { +#ifdef __METAL__ +using metal::numeric_limits; +template +constant constexpr bool is_standard_layout_v = __is_standard_layout(T); +template +constant constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T); +#endif template struct conditional { typedef T type; From a6c290e6288bfc7462871352cfbb873b454e1562 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:45:00 +0100 Subject: [PATCH 2/2] ITS: let the tracklet-finding device headers compile as Metal code ITS shared, needs agreement with the ITS GPU developers. MSL, like OpenCL, has no standard library headers and needs program-scope constants in the constant address space. Guard the std includes the device code does not need, use GPUCommonArray/GPUCommonTypeTraits for std::array and the traits, GPUglobalconstexpr for the namespace and static constants, keep the MC label out of device code, give the device only the views of the ROF tables (the tables themselves are built on the host), and rename two variables named after MSL keywords (half, vertex). No change for CPU, CUDA and HIP. --- .../ITS/include/DataFormatsITS/TimeEstBC.h | 7 ++- .../ITS/include/DataFormatsITS/Vertex.h | 4 ++ .../tracking/include/ITStracking/Cluster.h | 2 +- .../include/ITStracking/IndexTableUtils.h | 2 +- .../tracking/include/ITStracking/LayerMask.h | 4 +- .../include/ITStracking/TrackingTopology.h | 9 ++-- .../include/ITSMFTTracking/Constants.h | 51 ++++++++++--------- .../include/ITSMFTTracking/ROFLookupTables.h | 26 ++++++++++ .../include/ITSMFTTracking/ROFViews.h | 8 +-- 9 files changed, 79 insertions(+), 34 deletions(-) diff --git a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TimeEstBC.h b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TimeEstBC.h index a37ffa63988b7..8ac1326a771ca 100644 --- a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TimeEstBC.h +++ b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TimeEstBC.h @@ -12,9 +12,12 @@ #ifndef O2_TRACKINGITS_TIMEESTBC_H_ #define O2_TRACKINGITS_TIMEESTBC_H_ +#ifndef __METAL__ #include #include +#endif #include "CommonDataFormat/TimeStamp.h" +#include "GPUCommonTypeTraits.h" #include "GPUCommonRtypes.h" #include "GPUCommonDef.h" #include "GPUCommonMath.h" @@ -40,8 +43,8 @@ class TimeEstBC : public o2::dataformats::TimeStampWithError(this->getTimeStamp()); - const float half = (float)this->getTimeStampError() / 2.f; - return {start + half, half}; + const float halfError = (float)this->getTimeStampError() / 2.f; + return {start + halfError, halfError}; } // check if timestamps overlap within their interval diff --git a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/Vertex.h b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/Vertex.h index 1e4ed03b753eb..5871469ae769b 100644 --- a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/Vertex.h +++ b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/Vertex.h @@ -17,14 +17,18 @@ #include #endif #include "ReconstructionDataFormats/Vertex.h" +#ifndef __METAL__ #include "SimulationDataFormat/MCCompLabel.h" +#endif #include "DataFormatsITS/TimeEstBC.h" namespace o2::its { // NOTE: this uses the internal asymmetrical time reprenstation! using Vertex = o2::dataformats::Vertex; +#ifndef __METAL__ using VertexLabel = std::pair; +#endif } // namespace o2::its #ifndef GPUCA_GPUCODE_DEVICE diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/Cluster.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/Cluster.h index 7187c5f50cb4e..cc08af8f7f76a 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/Cluster.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/Cluster.h @@ -16,7 +16,7 @@ #ifndef TRACKINGITSU_INCLUDE_CACLUSTER_H_ #define TRACKINGITSU_INCLUDE_CACLUSTER_H_ -#include +#include "GPUCommonArray.h" #include "ITSMFTTracking/Constants.h" #include "ITSMFTTracking/MathUtils.h" #include "GPUCommonRtypes.h" diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IndexTableUtils.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IndexTableUtils.h index 427abd9b876a5..9eda12bccc0c8 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IndexTableUtils.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IndexTableUtils.h @@ -16,7 +16,7 @@ #ifndef TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_ #define TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_ -#include +#include "GPUCommonArray.h" #include "ITStracking/Cluster.h" #include "ITSMFTTracking/MathUtils.h" diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/LayerMask.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/LayerMask.h index 1a3854f4a6d2b..c0ef41c8068c1 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/LayerMask.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/LayerMask.h @@ -12,8 +12,10 @@ #ifndef TRACKINGITSU_INCLUDE_LAYERMASK_H_ #define TRACKINGITSU_INCLUDE_LAYERMASK_H_ +#ifndef __METAL__ #include -#include +#endif +#include "GPUCommonTypeTraits.h" #ifndef GPUCA_GPUCODE #include diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingTopology.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingTopology.h index 80432ebc4151c..a4d20e05c17a3 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingTopology.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingTopology.h @@ -12,10 +12,13 @@ #ifndef TRACKINGITSU_INCLUDE_TRACKINGTOPOLOGY_H_ #define TRACKINGITSU_INCLUDE_TRACKINGTOPOLOGY_H_ -#include +#ifndef __METAL__ #include #include #include +#endif +#include "GPUCommonArray.h" +#include "GPUCommonTypeTraits.h" #ifndef GPUCA_GPUCODE #include @@ -35,8 +38,8 @@ template class TrackingTopology { public: - static constexpr int MaxLinks = (NLayers * (NLayers - 1)) / 2; - static constexpr int MaxCells = (NLayers * (NLayers - 1) * (NLayers - 2)) / 6; + static GPUglobalconstexpr() int MaxLinks = (NLayers * (NLayers - 1)) / 2; + static GPUglobalconstexpr() int MaxCells = (NLayers * (NLayers - 1) * (NLayers - 2)) / 6; using Id = std::conditional_t::max(), uint8_t, uint16_t>; using Mask = LayerMask; using Range = o2::dataformats::RangeReference; diff --git a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/Constants.h b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/Constants.h index e3ff1d8cf87b2..7ce261b195a3f 100644 --- a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/Constants.h +++ b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/Constants.h @@ -16,36 +16,40 @@ #ifndef TRACKINGITSU_INCLUDE_CONSTANTS_H_ #define TRACKINGITSU_INCLUDE_CONSTANTS_H_ +#include "GPUCommonDef.h" +#ifndef __METAL__ #include #include +#endif namespace o2::its::constants { -constexpr float KB = 1024.f; -constexpr float MB = KB * KB; -constexpr float GB = MB * KB; -constexpr bool DoTimeBenchmarks = true; -constexpr bool SaveTimeBenchmarks = false; -constexpr float Tolerance = 1e-12; // numerical tolerance -constexpr int ClustersPerCell = 3; // number of clusters for a cell -constexpr int UnusedIndex = -1; // global unused flag -constexpr float UnsetValue = -999.f; // global unset value -constexpr float Radl = 9.36f; // Radiation length of Si [cm] -constexpr float Rho = 2.33f; // Density of Si [g/cm^3] -constexpr int MaxIter = 4; // Max. supported iterations -constexpr int MaxSeedingPasses = 2; // seeding + UPC passes optionally appended after the tracking iterations -constexpr int MaxSelectedTrackletsPerCluster = 100; // vertexer: max lines per cluster -constexpr int NumberOfConcurrentSeeds = 16; // default split per worker for the final track fit/extraploation step -constexpr int MinNumberOfConcurrentSeeds = (1 << 8); // minimum chunk size for a worker for the final track fit/extraploation step -constexpr int MaxNumberOfConcurrentSeeds = (1 << 12); // maximum chunk size for a worker for the final track fit/extraploation step -constexpr float MaxTrackSeedQ2Pt = 1.e3f; // maximum q/pt for track seeds - -constexpr int MaxBootstrapPasses = 5; // beam bootstrap: cap on the re-trackleting passes -constexpr float BeamConvergence2 = 5.e-3f * 5.e-3f; // beam bootstrap: stop below a (50 um)^2 beam shift -constexpr float VtxMinGoodThreshold = 2.f; // seeding emit: floor of the k*sqrt(ROF load) debris threshold (bounds included) -constexpr float VtxOverpopulatedRofTrimFraction = 0.02f; // overpopulated-ROF pruning: busiest fraction of ROFs left out of the per-ROF mean +GPUglobalconstexpr() float KB = 1024.f; +GPUglobalconstexpr() float MB = KB * KB; +GPUglobalconstexpr() float GB = MB * KB; +GPUglobalconstexpr() bool DoTimeBenchmarks = true; +GPUglobalconstexpr() bool SaveTimeBenchmarks = false; +GPUglobalconstexpr() float Tolerance = 1e-12; // numerical tolerance +GPUglobalconstexpr() int ClustersPerCell = 3; // number of clusters for a cell +GPUglobalconstexpr() int UnusedIndex = -1; // global unused flag +GPUglobalconstexpr() float UnsetValue = -999.f; // global unset value +GPUglobalconstexpr() float Radl = 9.36f; // Radiation length of Si [cm] +GPUglobalconstexpr() float Rho = 2.33f; // Density of Si [g/cm^3] +GPUglobalconstexpr() int MaxIter = 4; // Max. supported iterations +GPUglobalconstexpr() int MaxSeedingPasses = 2; // seeding + UPC passes optionally appended after the tracking iterations +GPUglobalconstexpr() int MaxSelectedTrackletsPerCluster = 100; // vertexer: max lines per cluster +GPUglobalconstexpr() int NumberOfConcurrentSeeds = 16; // default split per worker for the final track fit/extraploation step +GPUglobalconstexpr() int MinNumberOfConcurrentSeeds = (1 << 8); // minimum chunk size for a worker for the final track fit/extraploation step +GPUglobalconstexpr() int MaxNumberOfConcurrentSeeds = (1 << 12); // maximum chunk size for a worker for the final track fit/extraploation step +GPUglobalconstexpr() float MaxTrackSeedQ2Pt = 1.e3f; // maximum q/pt for track seeds +GPUglobalconstexpr() int MaxBootstrapPasses = 5; // beam bootstrap: cap on the re-trackleting passes +GPUglobalconstexpr() float BeamConvergence2 = 5.e-3f * 5.e-3f; // beam bootstrap: stop below a (50 um)^2 beam shift +GPUglobalconstexpr() float VtxMinGoodThreshold = 2.f; // seeding emit: floor of the k*sqrt(ROF load) debris threshold (bounds included) +GPUglobalconstexpr() float VtxOverpopulatedRofTrimFraction = 0.02f; // overpopulated-ROF pruning: busiest fraction of ROFs left out of the per-ROF mean + +#ifndef __METAL__ namespace helpers { @@ -57,6 +61,7 @@ constexpr std::array initArray() } } // namespace helpers +#endif } // namespace o2::its::constants #endif /* TRACKINGITSU_INCLUDE_CONSTANTS_H_ */ diff --git a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFLookupTables.h b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFLookupTables.h index 0e0ad3cf6698f..dad9604913b78 100644 --- a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFLookupTables.h +++ b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFLookupTables.h @@ -12,6 +12,7 @@ #ifndef TRACKINGITSU_INCLUDE_ROFOVERLAPTABLE_H_ #define TRACKINGITSU_INCLUDE_ROFOVERLAPTABLE_H_ +#ifndef __METAL__ #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#endif #ifndef GPUCA_GPUCODE #include @@ -40,6 +42,28 @@ namespace o2::itsmft::tracking using LayerTiming = ROFTimingLayer; +#ifdef __METAL__ +// Device code only needs the views of the tables, which are built on the host +using ROFTableRange = dataformats::RangeReference; +} // namespace o2::itsmft::tracking + +namespace o2::its +{ +template +struct ROFOverlapTable { + using View = o2::itsmft::tracking::ROFOverlapView; +}; +template +struct ROFVertexLookupTable { + using View = o2::itsmft::tracking::ROFVertexLookupView; +}; +template +struct ROFMaskTable { + using View = o2::itsmft::tracking::ROFMaskView; +}; +} // namespace o2::its +#else + // Base class for lookup to define layers class LayerTimingBase { @@ -542,4 +566,6 @@ class ROFMaskTable : public o2::itsmft::tracking::ROFMaskTable }; } // namespace o2::its +#endif // __METAL__ + #endif diff --git a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFViews.h b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFViews.h index 6074b211b9641..1e070063e4a72 100644 --- a/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFViews.h +++ b/Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/ROFViews.h @@ -12,10 +12,12 @@ #ifndef ALICEO2_ITSMFT_TRACKING_ROFVIEWS_H_ #define ALICEO2_ITSMFT_TRACKING_ROFVIEWS_H_ +#ifndef __METAL__ #include #include #include #include +#endif #ifndef GPUCA_GPUCODE #include @@ -288,14 +290,14 @@ struct ROFVertexLookupView { return maxCount; } - GPUhdi() bool isVertexCompatible(int32_t layer, size_t rofIdx, const o2::its::Vertex& vertex) const noexcept + GPUhdi() bool isVertexCompatible(int32_t layer, size_t rofIdx, const o2::its::Vertex& vtx) const noexcept { assert(layer >= 0 && layer < mLayerCount); const auto& layerDef = mLayers[layer]; int64_t rofLower = o2::gpu::CAMath::Max(static_cast(layerDef.getROFStartInBC(rofIdx)) - static_cast(layerDef.mROFAddTimeErr), int64_t(0)); int64_t rofUpper = static_cast(layerDef.getROFEndInBC(rofIdx)) + layerDef.mROFAddTimeErr; - auto vLower = static_cast(vertex.getTimeStamp().lower()); - auto vUpper = static_cast(vertex.getTimeStamp().upper()); + auto vLower = static_cast(vtx.getTimeStamp().lower()); + auto vUpper = static_cast(vtx.getTimeStamp().upper()); return vUpper >= rofLower && vLower < rofUpper; }