-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathCfArray2D.h
More file actions
126 lines (102 loc) · 2.76 KB
/
CfArray2D.h
File metadata and controls
126 lines (102 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file PackedCharge.h
/// \author Felix Weiglhofer
#ifndef O2_GPU_ARRAY2D_H
#define O2_GPU_ARRAY2D_H
#include "clusterFinderDefs.h"
#include "CfChargePos.h"
namespace o2::gpu
{
template <typename T, typename Layout>
class AbstractCfArray2D
{
public:
GPUdi() explicit AbstractCfArray2D(T* d) : data(d) {}
GPUdi() T& operator[](const CfChargePos& p) { return data[Layout::idx(p)]; }
GPUdi() const T& operator[](const CfChargePos& p) const { return data[Layout::idx(p)]; }
GPUdi() void safeWrite(const CfChargePos& p, const T& v)
{
if (data != nullptr) {
(*this)[p] = v;
}
}
private:
T* data;
};
template <typename Grid>
class TilingLayout
{
public:
enum {
Height = Grid::Height,
Width = Grid::Width,
WidthInTiles = (TPC_NUM_OF_PADS + Width - 1) / Width,
};
GPUdi() static tpccf::SizeT idx(const CfChargePos& p)
{
const tpccf::SizeT tilePad = p.gpad / Width;
const tpccf::SizeT tileTime = p.timePadded / Height;
const tpccf::SizeT inTilePad = p.gpad % Width;
const tpccf::SizeT inTileTime = p.timePadded % Height;
return (tileTime * WidthInTiles + tilePad) * (Width * Height) + inTileTime * Width + inTilePad;
}
GPUd() static size_t items(size_t fragmentLen)
{
return (TPC_NUM_OF_PADS + Width - 1) / Width * Width * (TPC_MAX_FRAGMENT_LEN_PADDED(fragmentLen) + Height - 1) / Height * Height;
}
};
class LinearLayout
{
public:
GPUdi() static tpccf::SizeT idx(const CfChargePos& p)
{
return TPC_NUM_OF_PADS * p.timePadded + p.gpad;
}
GPUd() static size_t items(size_t fragmentLen)
{
return TPC_NUM_OF_PADS * TPC_MAX_FRAGMENT_LEN_PADDED(fragmentLen);
}
};
template <tpccf::SizeT S>
struct GridSize;
template <>
struct GridSize<1> {
enum {
Width = 8,
Height = 8,
};
};
template <>
struct GridSize<2> {
enum {
Width = 8,
Height = 4,
};
};
template <>
struct GridSize<4> {
enum {
Width = 4,
Height = 4,
};
};
#if defined(CHARGEMAP_TILING_LAYOUT)
template <typename T>
using TPCMapMemoryLayout = TilingLayout<GridSize<sizeof(T)>>;
#else
template <typename T>
using TPCMapMemoryLayout = LinearLayout;
#endif
template <typename T>
using CfArray2D = AbstractCfArray2D<T, TPCMapMemoryLayout<T>>;
} // namespace o2::gpu
#endif