Skip to content

Commit 1d5c26f

Browse files
committed
TRD: place shared constants in the constant address space
Same treatment the TPC constants already had. MSL requires every variable at program scope to name an address space, and diagnoses it at the declaration, so a header full of plain constexpr breaks any device translation unit that merely includes it -- whether or not the constants are used. GPUglobalconstexpr() expands to constexpr everywhere except Metal, where it adds constant. Class-scope static members need it too: MSL counts them as program scope. constexpr functions do not, and are left alone. The six vDrift and ExB calibration defaults are double, which does not exist in MSL at all. They are host-only -- nothing under GPU/ refers to them -- so they are now compiled out of device code rather than converted, which would have changed their precision on CUDA and HIP. Preprocessed output is unchanged for host, CUDA, HIP and cling; device code sees the same constants minus those six doubles. Together this takes the TRD headers from 144 errors to 0 in a Metal translation unit.
1 parent d7aa492 commit 1d5c26f

2 files changed

Lines changed: 154 additions & 149 deletions

File tree

‎DataFormats/Detectors/TRD/include/DataFormatsTRD/Constants.h‎

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,97 @@
1616
#ifndef AliceO2_TRD_Constants_H
1717
#define AliceO2_TRD_Constants_H
1818

19+
#include "GPUCommonDef.h"
20+
1921
namespace o2
2022
{
2123
namespace trd
2224
{
2325
namespace constants
2426
{
25-
constexpr int NSECTOR = 18; ///< the number of sectors
26-
constexpr int NSTACK = 5; ///< the number of stacks per sector
27-
constexpr int NLAYER = 6; ///< the number of layers
28-
constexpr int NCHAMBERPERSEC = 30; ///< the number of chambers per sector
29-
constexpr int NHCPERSEC = 60; ///< the number of half-chambers per sector
30-
constexpr int MAXCHAMBER = 540; ///< the maximum number of installed chambers
31-
constexpr int MAXHALFCHAMBER = 1080; ///< the maximum number of installed half-chambers
32-
constexpr int NCHAMBER = 521; ///< the number of chambers actually installed
33-
constexpr int NHALFCRU = 72; ///< the number of half cru (link bundles)
34-
constexpr int NLINKSPERHALFCRU = 15; ///< the number of links per half cru or cru end point.
35-
constexpr int NLINKSPERCRU = 30; ///< the number of links per CRU (two CRUs serve one supermodule)
36-
constexpr int NCRU = 36; ///< the number of CRU we have
37-
constexpr int NFLP = 12; ///< the number of FLP we have.
38-
constexpr int NCRUPERFLP = 3; ///< the number of CRU per FLP
39-
constexpr int TRDLINKID = 15; ///< hard coded link id, specific to TRD
27+
GPUglobalconstexpr() int NSECTOR = 18; ///< the number of sectors
28+
GPUglobalconstexpr() int NSTACK = 5; ///< the number of stacks per sector
29+
GPUglobalconstexpr() int NLAYER = 6; ///< the number of layers
30+
GPUglobalconstexpr() int NCHAMBERPERSEC = 30; ///< the number of chambers per sector
31+
GPUglobalconstexpr() int NHCPERSEC = 60; ///< the number of half-chambers per sector
32+
GPUglobalconstexpr() int MAXCHAMBER = 540; ///< the maximum number of installed chambers
33+
GPUglobalconstexpr() int MAXHALFCHAMBER = 1080; ///< the maximum number of installed half-chambers
34+
GPUglobalconstexpr() int NCHAMBER = 521; ///< the number of chambers actually installed
35+
GPUglobalconstexpr() int NHALFCRU = 72; ///< the number of half cru (link bundles)
36+
GPUglobalconstexpr() int NLINKSPERHALFCRU = 15; ///< the number of links per half cru or cru end point.
37+
GPUglobalconstexpr() int NLINKSPERCRU = 30; ///< the number of links per CRU (two CRUs serve one supermodule)
38+
GPUglobalconstexpr() int NCRU = 36; ///< the number of CRU we have
39+
GPUglobalconstexpr() int NFLP = 12; ///< the number of FLP we have.
40+
GPUglobalconstexpr() int NCRUPERFLP = 3; ///< the number of CRU per FLP
41+
GPUglobalconstexpr() int TRDLINKID = 15; ///< hard coded link id, specific to TRD
4042

41-
constexpr int NCOLUMN = 144; ///< the number of pad columns for each chamber
42-
constexpr int NROWC0 = 12; ///< the number of pad rows for chambers of type C0 (installed in stack 2)
43-
constexpr int NROWC1 = 16; ///< the number of pad rows for chambers of type C1 (installed in stacks 0, 1, 3 and 4)
44-
constexpr int FIRSTROW[NSTACK] = {0, 16, 32, 44, 60}; ///< first pad row for each stack
43+
GPUglobalconstexpr() int NCOLUMN = 144; ///< the number of pad columns for each chamber
44+
GPUglobalconstexpr() int NROWC0 = 12; ///< the number of pad rows for chambers of type C0 (installed in stack 2)
45+
GPUglobalconstexpr() int NROWC1 = 16; ///< the number of pad rows for chambers of type C1 (installed in stacks 0, 1, 3 and 4)
46+
GPUglobalconstexpr() int FIRSTROW[NSTACK] = {0, 16, 32, 44, 60}; ///< first pad row for each stack
4547

46-
constexpr int NMCMROB = 16; ///< the number of MCMs per ROB
47-
constexpr int NMCMHCMAX = 64; ///< the maximum number of MCMs for one half chamber (C1 type)
48-
constexpr int NMCMROBINROW = 4; ///< the number of MCMs per ROB in row direction
49-
constexpr int NMCMROBINCOL = 4; ///< the number of MCMs per ROB in column direction
50-
constexpr int NROBC0 = 6; ///< the number of ROBs per C0 chamber
51-
constexpr int NROBC1 = 8; ///< the number of ROBs per C1 chamber
52-
constexpr int NADCMCM = 21; ///< the number of ADC channels per MCM
53-
constexpr int NCOLMCM = 18; ///< the number of pads per MCM
54-
constexpr int NCHANNELSPERROW = NMCMROBINCOL * 2 * NADCMCM; ///< the number of readout channels per pad row
55-
constexpr int NCHANNELSC0 = NROWC0 * NCHANNELSPERROW; ///< the number of readout channels per C0 chamber
56-
constexpr int NCHANNELSC1 = NROWC1 * NCHANNELSPERROW; ///< the number of readout channels per C1 chamber
57-
constexpr int NCHANNELSTOTAL = NSECTOR * NLAYER * (NSTACK - 1) * NCHANNELSC1 + NSECTOR * NLAYER * NCHANNELSC0; ///< the total number of readout channels for TRD
58-
constexpr int NCHANNELSPERSECTOR = NCHANNELSTOTAL / NSECTOR; ///< then number of readout channels per sector
59-
constexpr int NCHANNELSPERLAYER = NCHANNELSPERSECTOR / NLAYER; ///< then number of readout channels per layer
60-
constexpr int NCPU = 4; ///< the number of CPUs inside the TRAP chip
61-
constexpr int NCHARGES = 3; ///< the number of charges per tracklet (Q0/1/2)
48+
GPUglobalconstexpr() int NMCMROB = 16; ///< the number of MCMs per ROB
49+
GPUglobalconstexpr() int NMCMHCMAX = 64; ///< the maximum number of MCMs for one half chamber (C1 type)
50+
GPUglobalconstexpr() int NMCMROBINROW = 4; ///< the number of MCMs per ROB in row direction
51+
GPUglobalconstexpr() int NMCMROBINCOL = 4; ///< the number of MCMs per ROB in column direction
52+
GPUglobalconstexpr() int NROBC0 = 6; ///< the number of ROBs per C0 chamber
53+
GPUglobalconstexpr() int NROBC1 = 8; ///< the number of ROBs per C1 chamber
54+
GPUglobalconstexpr() int NADCMCM = 21; ///< the number of ADC channels per MCM
55+
GPUglobalconstexpr() int NCOLMCM = 18; ///< the number of pads per MCM
56+
GPUglobalconstexpr() int NCHANNELSPERROW = NMCMROBINCOL * 2 * NADCMCM; ///< the number of readout channels per pad row
57+
GPUglobalconstexpr() int NCHANNELSC0 = NROWC0 * NCHANNELSPERROW; ///< the number of readout channels per C0 chamber
58+
GPUglobalconstexpr() int NCHANNELSC1 = NROWC1 * NCHANNELSPERROW; ///< the number of readout channels per C1 chamber
59+
GPUglobalconstexpr() int NCHANNELSTOTAL = NSECTOR * NLAYER * (NSTACK - 1) * NCHANNELSC1 + NSECTOR * NLAYER * NCHANNELSC0; ///< the total number of readout channels for TRD
60+
GPUglobalconstexpr() int NCHANNELSPERSECTOR = NCHANNELSTOTAL / NSECTOR; ///< then number of readout channels per sector
61+
GPUglobalconstexpr() int NCHANNELSPERLAYER = NCHANNELSPERSECTOR / NLAYER; ///< then number of readout channels per layer
62+
GPUglobalconstexpr() int NCPU = 4; ///< the number of CPUs inside the TRAP chip
63+
GPUglobalconstexpr() int NCHARGES = 3; ///< the number of charges per tracklet (Q0/1/2)
6264

6365
// the values below should come out of the TRAP config in the future
64-
constexpr int NBITSTRKLPOS = 11; ///< number of bits for position in tracklet64 word
65-
constexpr int NBITSTRKLSLOPE = 8; ///< number of bits for slope in tracklet64 word
66-
constexpr int ADDBITSHIFTSLOPE = 1 << 3; ///< in the TRAP the slope is shifted by 3 additional bits compared to the position
67-
constexpr int PADGRANULARITYTRKLPOS = 40; ///< tracklet position is stored in units of 1/40 pad
68-
constexpr int PADGRANULARITYTRKLSLOPE = 128; ///< tracklet deflection is stored in units of 1/128 pad per time bin
69-
constexpr float GRANULARITYTRKLPOS = 1.f / PADGRANULARITYTRKLPOS; ///< granularity of position in tracklet64 word in pad-widths
70-
constexpr float GRANULARITYTRKLSLOPE = 1.f / PADGRANULARITYTRKLSLOPE; ///< granularity of slope in tracklet64 word in pads/timebin
71-
constexpr int ADCBASELINE = 10; ///< baseline in ADC units
66+
GPUglobalconstexpr() int NBITSTRKLPOS = 11; ///< number of bits for position in tracklet64 word
67+
GPUglobalconstexpr() int NBITSTRKLSLOPE = 8; ///< number of bits for slope in tracklet64 word
68+
GPUglobalconstexpr() int ADDBITSHIFTSLOPE = 1 << 3; ///< in the TRAP the slope is shifted by 3 additional bits compared to the position
69+
GPUglobalconstexpr() int PADGRANULARITYTRKLPOS = 40; ///< tracklet position is stored in units of 1/40 pad
70+
GPUglobalconstexpr() int PADGRANULARITYTRKLSLOPE = 128; ///< tracklet deflection is stored in units of 1/128 pad per time bin
71+
GPUglobalconstexpr() float GRANULARITYTRKLPOS = 1.f / PADGRANULARITYTRKLPOS; ///< granularity of position in tracklet64 word in pad-widths
72+
GPUglobalconstexpr() float GRANULARITYTRKLSLOPE = 1.f / PADGRANULARITYTRKLSLOPE; ///< granularity of slope in tracklet64 word in pads/timebin
73+
GPUglobalconstexpr() int ADCBASELINE = 10; ///< baseline in ADC units
7274

7375
// OS: Should this not be flexible for example in case of Kr calib?
74-
constexpr int TIMEBINS = 30; ///< the number of time bins
75-
constexpr float MAXIMPACTANGLE = 25.f; ///< the maximum impact angle for tracks relative to the TRD detector plane to be considered for vDrift and ExB calibration
76-
constexpr int NBINSANGLEDIFF = 25; ///< the number of bins for the track angle used for the vDrift and ExB calibration based on the tracking
76+
GPUglobalconstexpr() int TIMEBINS = 30; ///< the number of time bins
77+
GPUglobalconstexpr() float MAXIMPACTANGLE = 25.f; ///< the maximum impact angle for tracks relative to the TRD detector plane to be considered for vDrift and ExB calibration
78+
GPUglobalconstexpr() int NBINSANGLEDIFF = 25; ///< the number of bins for the track angle used for the vDrift and ExB calibration based on the tracking
79+
#ifndef GPUCA_GPUCODE_DEVICE
80+
// calibration defaults, host only: these are double and never used in device code
7781
constexpr double VDRIFTDEFAULT = 1.546; ///< default value for vDrift
7882
constexpr double VDRIFTMIN = 0.4; ///< min value for vDrift
7983
constexpr double VDRIFTMAX = 2.0; ///< max value for vDrift
8084
constexpr double EXBDEFAULT = 0.0; ///< default value for LorentzAngle
8185
constexpr double EXBMIN = -0.4; ///< min value for LorentzAngle
8286
constexpr double EXBMAX = 0.4; ///< max value for LorentzAngle
83-
constexpr int NBINSGAINCALIB = 320; ///< number of bins in the charge (Q0+Q1+Q2) histogram for gain calibration
84-
constexpr float MPVDEDXDEFAULT = 42.; ///< default Most Probable Value of TRD dEdx
85-
constexpr float T0DEFAULT = 1.2; ///< default value for t0
87+
#endif
88+
GPUglobalconstexpr() int NBINSGAINCALIB = 320; ///< number of bins in the charge (Q0+Q1+Q2) histogram for gain calibration
89+
GPUglobalconstexpr() float MPVDEDXDEFAULT = 42.; ///< default Most Probable Value of TRD dEdx
90+
GPUglobalconstexpr() float T0DEFAULT = 1.2; ///< default value for t0
8691

8792
// array size to store incoming half cru payload.
88-
constexpr int HBFBUFFERMAX = 1048576; ///< max buffer size for data read from a half cru, (all events)
89-
constexpr unsigned int CRUPADDING32 = 0xeeeeeeee; ///< padding word used in the cru.
90-
constexpr int CHANNELNRNOTRKLT = 23; ///< this marks channels in the ADC mask which don't contribute to a tracklet
91-
constexpr int NOTRACKLETFIT = 31; ///< this value is assigned to the fit pointer in case no tracklet is available
92-
constexpr int TRACKLETENDMARKER = 0x10001000; ///< marker for the end of tracklets in raw data, 2 of these.
93-
constexpr int PADDINGWORD = 0xeeeeeeee; ///< half-CRU links will be padded with this words to get an even number of 256bit words
94-
constexpr int DIGITENDMARKER = 0x0; ///< marker for the end of digits in raw data, 2 of these
95-
constexpr int MAXDATAPERLINK32 = 13824; ///< max number of 32 bit words per link ((21x12+2+4)*64) 64 mcm, 21 channels, 10 words per channel 2 header words(DigitMCMHeader DigitMCMADCmask) 4 words for tracklets.
96-
constexpr int MAXDATAPERLINK256 = 1728; ///< max number of linkwords per cru link. (256bit words)
97-
constexpr int MAXEVENTCOUNTERSEPERATION = 200; ///< how far apart can subsequent mcmheader event counters be before we flag for concern, used as a sanity check in rawreader.
98-
constexpr int MAXMCMCOUNT = 69120; ///< at most mcm count maxchamber x nrobc1 nmcmrob
99-
constexpr int MAXLINKERRORHISTOGRAMS = 10; ///< size of the array holding the link error plots from the raw reader
100-
constexpr int MAXPARSEERRORHISTOGRAMS = 60; ///< size of the array holding the parsing error plots from the raw reader
101-
constexpr unsigned int ETYPEPHYSICSTRIGGER = 0x2; ///< CRU Half Chamber header eventtype definition
102-
constexpr unsigned int ETYPECALIBRATIONTRIGGER = 0x3; ///< CRU Half Chamber header eventtype definition
103-
constexpr int MAXCRUERRORVALUE = 0x2; ///< Max possible value for a CRU Halfchamber link error. As of may 2022, can only be 0x0, 0x1, and 0x2, at least that is all so far(may2022).
104-
constexpr int INVALIDPRETRIGGERPHASE = 0xf; ///< Invalid value for phase, used to signify there is no hcheader.
93+
GPUglobalconstexpr() int HBFBUFFERMAX = 1048576; ///< max buffer size for data read from a half cru, (all events)
94+
GPUglobalconstexpr() unsigned int CRUPADDING32 = 0xeeeeeeee; ///< padding word used in the cru.
95+
GPUglobalconstexpr() int CHANNELNRNOTRKLT = 23; ///< this marks channels in the ADC mask which don't contribute to a tracklet
96+
GPUglobalconstexpr() int NOTRACKLETFIT = 31; ///< this value is assigned to the fit pointer in case no tracklet is available
97+
GPUglobalconstexpr() int TRACKLETENDMARKER = 0x10001000; ///< marker for the end of tracklets in raw data, 2 of these.
98+
GPUglobalconstexpr() int PADDINGWORD = 0xeeeeeeee; ///< half-CRU links will be padded with this words to get an even number of 256bit words
99+
GPUglobalconstexpr() int DIGITENDMARKER = 0x0; ///< marker for the end of digits in raw data, 2 of these
100+
GPUglobalconstexpr() int MAXDATAPERLINK32 = 13824; ///< max number of 32 bit words per link ((21x12+2+4)*64) 64 mcm, 21 channels, 10 words per channel 2 header words(DigitMCMHeader DigitMCMADCmask) 4 words for tracklets.
101+
GPUglobalconstexpr() int MAXDATAPERLINK256 = 1728; ///< max number of linkwords per cru link. (256bit words)
102+
GPUglobalconstexpr() int MAXEVENTCOUNTERSEPERATION = 200; ///< how far apart can subsequent mcmheader event counters be before we flag for concern, used as a sanity check in rawreader.
103+
GPUglobalconstexpr() int MAXMCMCOUNT = 69120; ///< at most mcm count maxchamber x nrobc1 nmcmrob
104+
GPUglobalconstexpr() int MAXLINKERRORHISTOGRAMS = 10; ///< size of the array holding the link error plots from the raw reader
105+
GPUglobalconstexpr() int MAXPARSEERRORHISTOGRAMS = 60; ///< size of the array holding the parsing error plots from the raw reader
106+
GPUglobalconstexpr() unsigned int ETYPEPHYSICSTRIGGER = 0x2; ///< CRU Half Chamber header eventtype definition
107+
GPUglobalconstexpr() unsigned int ETYPECALIBRATIONTRIGGER = 0x3; ///< CRU Half Chamber header eventtype definition
108+
GPUglobalconstexpr() int MAXCRUERRORVALUE = 0x2; ///< Max possible value for a CRU Halfchamber link error. As of may 2022, can only be 0x0, 0x1, and 0x2, at least that is all so far(may2022).
109+
GPUglobalconstexpr() int INVALIDPRETRIGGERPHASE = 0xf; ///< Invalid value for phase, used to signify there is no hcheader.
105110

106111
} // namespace constants
107112
} // namespace trd

0 commit comments

Comments
 (0)