Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ALPAKA_STATIC_ACC_MEM_GLOBAL with HOST_DEVICE_CONSTANT #47108

Merged
merged 2 commits into from
Jan 16, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <alpaka/alpaka.hpp>

#include "DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h"
#include "FWCore/Utilities/interface/HostDeviceConstant.h"
#include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
#include "HeterogeneousCore/AlpakaInterface/interface/HistoContainer.h"
#include "HeterogeneousCore/AlpakaInterface/interface/SimpleVector.h"
Expand All @@ -20,7 +21,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering {

#ifdef GPU_DEBUG
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_STATIC_ACC_MEM_GLOBAL uint32_t gMaxHit = 0;
HOST_DEVICE_CONSTANT uint32_t gMaxHit = 0;
#endif

namespace pixelStatus {
Expand Down
56 changes: 28 additions & 28 deletions RecoTracker/LSTCore/interface/alpaka/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <numbers>

#include "FWCore/Utilities/interface/HostDeviceConstant.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "RecoTracker/LSTCore/interface/Common.h"

Expand Down Expand Up @@ -40,50 +41,49 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {

// The constants below are usually used in functions like alpaka::math::min(),
// expecting a reference (T const&) in the arguments. Hence,
// ALPAKA_STATIC_ACC_MEM_GLOBAL needs to be used in addition to constexpr.
// HOST_DEVICE_CONSTANT needs to be used instead of constexpr.

ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kPi = std::numbers::pi_v<float>;
HOST_DEVICE_CONSTANT float kPi = std::numbers::pi_v<float>;
// 15 MeV constant from the approximate Bethe-Bloch formula
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMulsInGeV = 0.015;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniMulsPtScaleBarrel[6] = {
0.0052, 0.0038, 0.0034, 0.0034, 0.0032, 0.0034};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniMulsPtScaleEndcap[5] = {0.006, 0.006, 0.006, 0.006, 0.006};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniRminMeanBarrel[6] = {
HOST_DEVICE_CONSTANT float kMulsInGeV = 0.015;
HOST_DEVICE_CONSTANT float kMiniMulsPtScaleBarrel[6] = {0.0052, 0.0038, 0.0034, 0.0034, 0.0032, 0.0034};
HOST_DEVICE_CONSTANT float kMiniMulsPtScaleEndcap[5] = {0.006, 0.006, 0.006, 0.006, 0.006};
HOST_DEVICE_CONSTANT float kMiniRminMeanBarrel[6] = {
25.007152356, 37.2186993757, 52.3104270826, 68.6658656666, 85.9770373007, 108.301772384};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniRminMeanEndcap[5] = {
HOST_DEVICE_CONSTANT float kMiniRminMeanEndcap[5] = {
130.992832231, 154.813883559, 185.352604327, 221.635123002, 265.022076742};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf = (2.99792458e-3 * 3.8) / 2;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kR1GeVf = 1. / (2.99792458e-3 * 3.8);
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kSinAlphaMax = 0.95;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kDeltaZLum = 15.0;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kPixelPSZpitch = 0.15;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kStripPSZpitch = 2.4;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kStrip2SZpitch = 5.0;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kWidth2S = 0.009;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kWidthPS = 0.01;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kPt_betaMax = 7.0;
HOST_DEVICE_CONSTANT float k2Rinv1GeVf = (2.99792458e-3 * 3.8) / 2;
HOST_DEVICE_CONSTANT float kR1GeVf = 1. / (2.99792458e-3 * 3.8);
HOST_DEVICE_CONSTANT float kSinAlphaMax = 0.95;
HOST_DEVICE_CONSTANT float kDeltaZLum = 15.0;
HOST_DEVICE_CONSTANT float kPixelPSZpitch = 0.15;
HOST_DEVICE_CONSTANT float kStripPSZpitch = 2.4;
HOST_DEVICE_CONSTANT float kStrip2SZpitch = 5.0;
HOST_DEVICE_CONSTANT float kWidth2S = 0.009;
HOST_DEVICE_CONSTANT float kWidthPS = 0.01;
HOST_DEVICE_CONSTANT float kPt_betaMax = 7.0;
// To be updated with std::numeric_limits<float>::infinity() in the code and data files
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kVerticalModuleSlope = 123456789.0;
HOST_DEVICE_CONSTANT float kVerticalModuleSlope = 123456789.0;

ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaTilted[3] = {0.26f, 0.26f, 0.26f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaLooseTilted[3] = {0.4f, 0.4f, 0.4f};
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMiniDeltaEndcap[5][15] = {
HOST_DEVICE_CONSTANT float kMiniDeltaTilted[3] = {0.26f, 0.26f, 0.26f};
HOST_DEVICE_CONSTANT float kMiniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f};
HOST_DEVICE_CONSTANT float kMiniDeltaLooseTilted[3] = {0.4f, 0.4f, 0.4f};
HOST_DEVICE_CONSTANT float kMiniDeltaEndcap[5][15] = {
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f},
{0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 0.18f, /*10*/ 0.18f, 0.18f, 0.18f, 0.18f, 0.18f}};

namespace t5dnn {
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kZ_max = 267.2349854f;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kR_max = 110.1099396f;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kEta_norm = 2.5f;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kPhi_norm = kPi;
HOST_DEVICE_CONSTANT float kZ_max = 267.2349854f;
HOST_DEVICE_CONSTANT float kR_max = 110.1099396f;
HOST_DEVICE_CONSTANT float kEta_norm = 2.5f;
HOST_DEVICE_CONSTANT float kPhi_norm = kPi;
// pt, eta binned
constexpr unsigned int kPtBins = 2;
constexpr unsigned int kEtaBins = 10;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kWp[kPtBins][kEtaBins] = {
HOST_DEVICE_CONSTANT float kWp[kPtBins][kEtaBins] = {
{0.4493, 0.4939, 0.5715, 0.6488, 0.5709, 0.5938, 0.7164, 0.7565, 0.8103, 0.8593},
{0.4488, 0.4448, 0.5067, 0.5929, 0.4836, 0.4112, 0.4968, 0.4403, 0.5597, 0.5067}};
} // namespace t5dnn
Expand Down
14 changes: 8 additions & 6 deletions RecoTracker/LSTCore/src/alpaka/NeuralNetworkWeights.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

#include <alpaka/alpaka.hpp>

#include "FWCore/Utilities/interface/HostDeviceConstant.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_layer1[32] = {
HOST_DEVICE_CONSTANT float bias_layer1[32] = {
-1.3837075f, -0.0653152f, -0.7900129f, 0.0714758f, -1.1574365f, -1.4634879f, -0.9317133f, -0.1455518f,
-0.0459635f, -0.2055620f, 0.0586231f, -0.8943899f, -0.1009487f, 0.0166031f, -0.5451909f, -0.1384538f,
1.2664700f, -1.8996916f, -0.0025585f, -0.1647783f, -1.9019107f, 0.0707104f, -0.2373025f, 0.0357050f,
-0.0048417f, 2.3127339f, -0.0508943f, -0.1116435f, -0.1610904f, -1.6463890f, -1.0739423f, -0.0962902f};

ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_layer1[23][32] = {
HOST_DEVICE_CONSTANT float wgtT_layer1[23][32] = {
{-0.1881404f, -0.0534256f, 1.6563641f, 0.0401664f, 2.8318353f, 1.5049738f, 1.4111555f, -0.2339872f,
0.0431970f, 0.1220361f, -0.0450153f, -1.6025578f, 0.0394025f, -0.3051167f, 1.9442217f, 0.1599094f,
0.1376955f, 2.4181051f, -0.0226484f, -0.1801709f, -0.4861264f, -0.0268545f, 0.5463807f, 0.2420150f,
Expand Down Expand Up @@ -105,13 +107,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
-0.1102583f, -0.5788267f, 0.0017006f, 2.6352038f, -1.7847317f, 1.7510574f, 2.1478791f, -0.2251654f},
};

ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_layer2[32] = {
HOST_DEVICE_CONSTANT float bias_layer2[32] = {
-0.2689391f, 1.5461178f, -0.2424639f, 0.4424149f, -0.0411816f, -4.1070848f, 1.4709516f, -0.2439820f,
-0.1750926f, 2.8802166f, -0.1573734f, -1.3724055f, 0.3671952f, 1.8267332f, 1.5655776f, -0.7323843f,
1.6318209f, 2.2198663f, -1.5951139f, -0.0870247f, 0.2806863f, -0.2407108f, 0.1310665f, -0.5246177f,
0.1914421f, -0.3386542f, -0.6310596f, 3.2995102f, 0.7519229f, -0.1565450f, -0.1496341f, 1.0073272f};

ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_layer2[32][32] = {
HOST_DEVICE_CONSTANT float wgtT_layer2[32][32] = {
{-0.1731049f, 1.7775618f, -0.2532010f, -0.2902778f, -0.1392802f, 4.2428946f, -0.1866968f, -0.1800365f,
-0.0634398f, 0.0763313f, 0.0472901f, -0.8030146f, 0.3161853f, -1.0713238f, -4.6514492f, -0.3908085f,
1.1607268f, 0.8834935f, -0.1194544f, -0.0785166f, 0.4967587f, -0.0558136f, -0.9601135f, -0.1001592f,
Expand Down Expand Up @@ -242,9 +244,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst::t5dnn {
0.0378523f, 0.1039687f, -0.0701027f, 0.0509319f, 0.1355647f, 0.0978021f, 0.0391430f, 0.0241266f},
};

ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_output_layer[1] = {-0.7420582f};
HOST_DEVICE_CONSTANT float bias_output_layer[1] = {-0.7420582f};

ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_output_layer[32][1] = {
HOST_DEVICE_CONSTANT float wgtT_output_layer[32][1] = {
{0.0381968f}, {1.0667214f}, {0.0505496f}, {-1.5677565f}, {0.0066824f}, {-0.9951485f}, {0.9438043f},
{0.0068631f}, {-0.0216870f}, {0.6560486f}, {-0.0235629f}, {0.9653404f}, {0.6641668f}, {-0.5351945f},
{-0.5303048f}, {1.9339687f}, {0.4359012f}, {-0.7492802f}, {-0.5728400f}, {0.0473893f}, {-0.5091293f},
Expand Down
16 changes: 8 additions & 8 deletions RecoTracker/LSTCore/standalone/analysis/DNN/train_T5_DNN.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_layer1[32] = {\n",
"HOST_DEVICE_CONSTANT const float bias_layer1[32] = {\n",
"-1.3837075f, -0.0653152f, -0.7900129f, 0.0714758f, -1.1574365f, -1.4634879f, -0.9317133f, -0.1455518f, -0.0459635f, -0.2055620f, 0.0586231f, -0.8943899f, -0.1009487f, 0.0166031f, -0.5451909f, -0.1384538f, 1.2664700f, -1.8996916f, -0.0025585f, -0.1647783f, -1.9019107f, 0.0707104f, -0.2373025f, 0.0357050f, -0.0048417f, 2.3127339f, -0.0508943f, -0.1116435f, -0.1610904f, -1.6463890f, -1.0739423f, -0.0962902f };\n",
"\n",
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_layer1[23][32] = {\n",
"HOST_DEVICE_CONSTANT const float wgtT_layer1[23][32] = {\n",
"{ -0.1881404f, -0.0534256f, 1.6563641f, 0.0401664f, 2.8318353f, 1.5049738f, 1.4111555f, -0.2339872f, 0.0431970f, 0.1220361f, -0.0450153f, -1.6025578f, 0.0394025f, -0.3051167f, 1.9442217f, 0.1599094f, 0.1376955f, 2.4181051f, -0.0226484f, -0.1801709f, -0.4861264f, -0.0268545f, 0.5463807f, 0.2420150f, -0.1238829f, 0.2916382f, 0.1507791f, 0.7952659f, 0.2736979f, 3.2790639f, 1.2062043f, -0.0884467f },\n",
"{ -0.0469924f, 0.2013927f, 0.0307775f, -0.1241788f, -0.0100412f, 0.0422375f, 0.0211071f, -0.0359304f, 0.0451861f, 0.0291862f, -0.2094866f, -0.0013007f, 0.1191471f, 0.0750159f, 0.0184378f, 0.0419437f, -0.0207304f, -0.0444109f, 0.0013400f, -0.0699210f, -0.0668742f, -0.0880825f, -0.0107244f, 0.0363424f, 0.1391699f, -0.0112885f, -0.0060098f, -0.0073863f, -0.0566143f, -0.0224207f, 0.0103718f, -0.0015193f },\n",
"{ 0.4520382f, 0.1227609f, -1.3887709f, -0.0542129f, -3.2003114f, -0.8354173f, -1.3173198f, 0.3292131f, -0.1657729f, -0.1982902f, 0.1599589f, -0.0417666f, -0.1461042f, -1.3237997f, -5.3609071f, -0.0981676f, 0.2922535f, -1.8692241f, -0.0345302f, 0.1810613f, 0.4473544f, -0.0159401f, -0.7293931f, -1.4816793f, -0.1431545f, -0.0955672f, -0.2370718f, -0.7204540f, 0.8451244f, -3.4310548f, -1.3518151f, 0.1551731f },\n",
Expand All @@ -761,10 +761,10 @@
"{ 0.0340557f, -0.1659652f, -0.0042457f, 0.0010229f, -2.1550148f, -0.4728722f, -1.3667214f, 0.2625635f, -0.0302200f, -0.0322885f, 0.0227866f, 0.6977839f, 0.0050141f, -1.6183628f, 0.0869662f, -0.0775411f, 0.4754244f, 0.4596581f, 2.1509945f, -0.0313832f, 0.0336208f, -0.1547154f, -0.6017126f, 0.0369996f, -0.1102583f, -0.5788267f, 0.0017006f, 2.6352038f, -1.7847317f, 1.7510574f, 2.1478791f, -0.2251654f },\n",
"};\n",
"\n",
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_layer2[32] = {\n",
"HOST_DEVICE_CONSTANT const float bias_layer2[32] = {\n",
"-0.2689391f, 1.5461178f, -0.2424639f, 0.4424149f, -0.0411816f, -4.1070848f, 1.4709516f, -0.2439820f, -0.1750926f, 2.8802166f, -0.1573734f, -1.3724055f, 0.3671952f, 1.8267332f, 1.5655776f, -0.7323843f, 1.6318209f, 2.2198663f, -1.5951139f, -0.0870247f, 0.2806863f, -0.2407108f, 0.1310665f, -0.5246177f, 0.1914421f, -0.3386542f, -0.6310596f, 3.2995102f, 0.7519229f, -0.1565450f, -0.1496341f, 1.0073272f };\n",
"\n",
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_layer2[32][32] = {\n",
"HOST_DEVICE_CONSTANT const float wgtT_layer2[32][32] = {\n",
"{ -0.1731049f, 1.7775618f, -0.2532010f, -0.2902778f, -0.1392802f, 4.2428946f, -0.1866968f, -0.1800365f, -0.0634398f, 0.0763313f, 0.0472901f, -0.8030146f, 0.3161853f, -1.0713238f, -4.6514492f, -0.3908085f, 1.1607268f, 0.8834935f, -0.1194544f, -0.0785166f, 0.4967587f, -0.0558136f, -0.9601135f, -0.1001592f, 3.4427991f, -0.2144053f, -0.3632556f, 0.0117088f, 0.1742481f, -0.2540179f, -0.1705156f, -0.2627344f },\n",
"{ -0.1478276f, -0.1659575f, 0.1602777f, -0.0758106f, 0.1067696f, -0.0247068f, -0.1123443f, -0.1724832f, -0.0013103f, -0.0685904f, 0.1537329f, 0.1042632f, -0.0360880f, -0.0679077f, 0.0672719f, 0.1597116f, -0.0150259f, 0.0367102f, -0.0545881f, -0.0693004f, -0.1008447f, -0.0672846f, -0.1395939f, -0.0324785f, -0.1051702f, -0.0530534f, -0.1019061f, -0.0921245f, 0.1195077f, 0.0453448f, 0.0257045f, -0.0622537f },\n",
"{ -0.0363173f, -0.1990481f, -0.0452148f, 0.4074381f, -0.0731660f, -0.0823270f, 0.3154473f, -0.1909118f, -0.0165690f, 0.1325824f, -0.0760181f, 0.7768906f, -0.2702211f, -0.6023573f, 1.5904741f, 0.2384946f, 0.7610655f, -2.8705251f, 0.5754877f, -0.1587478f, -0.5708794f, -0.3421216f, 0.5023443f, 1.2806857f, 0.2158970f, -0.1364033f, -0.3398291f, 0.9066412f, -1.2935438f, 0.0273695f, -0.1850613f, -0.9301611f },\n",
Expand Down Expand Up @@ -799,10 +799,10 @@
"{ -0.0246332f, 0.1165779f, 0.0255498f, -0.0601489f, 0.1545041f, -0.0977981f, 0.1242626f, -0.1533627f, -0.1294386f, -0.0231293f, -0.1460808f, 0.1763088f, 0.0953614f, -0.0716483f, -0.1003436f, 0.0804519f, 0.1373295f, -0.0686773f, 0.1198382f, 0.1519430f, 0.1640775f, -0.1675753f, 0.0790529f, -0.1521838f, 0.0378523f, 0.1039687f, -0.0701027f, 0.0509319f, 0.1355647f, 0.0978021f, 0.0391430f, 0.0241266f },\n",
"};\n",
"\n",
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_output_layer[1] = {\n",
"HOST_DEVICE_CONSTANT const float bias_output_layer[1] = {\n",
"-0.7420582f };\n",
"\n",
"ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_output_layer[32][1] = {\n",
"HOST_DEVICE_CONSTANT const float wgtT_output_layer[32][1] = {\n",
"{ 0.0381968f },\n",
"{ 1.0667214f },\n",
"{ 0.0505496f },\n",
Expand Down Expand Up @@ -843,12 +843,12 @@
"source": [
"def print_formatted_weights_biases(weights, biases, layer_name):\n",
" # Print biases\n",
" print(f\"ALPAKA_STATIC_ACC_MEM_GLOBAL const float bias_{layer_name}[{len(biases)}] = {{\")\n",
" print(f\"HOST_DEVICE_CONSTANT const float bias_{layer_name}[{len(biases)}] = {{\")\n",
" print(\", \".join(f\"{b:.7f}f\" for b in biases) + \" };\")\n",
" print()\n",
"\n",
" # Print weights\n",
" print(f\"ALPAKA_STATIC_ACC_MEM_GLOBAL const float wgtT_{layer_name}[{len(weights[0])}][{len(weights)}] = {{\")\n",
" print(f\"HOST_DEVICE_CONSTANT const float wgtT_{layer_name}[{len(weights[0])}][{len(weights)}] = {{\")\n",
" for row in weights.T:\n",
" formatted_row = \", \".join(f\"{w:.7f}f\" for w in row)\n",
" print(f\"{{ {formatted_row} }},\")\n",
Expand Down