Skip to content

Commit

Permalink
Use pre-defined alpaka types
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Jul 16, 2024
1 parent 9c87a88 commit 9fd3355
Show file tree
Hide file tree
Showing 23 changed files with 635 additions and 638 deletions.
2 changes: 1 addition & 1 deletion RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
descriptions.addWithDefaultLabel(desc);
}

std::unique_ptr<SDL::LSTESData<SDL::DevHost>> produce(TrackerRecoGeometryRecord const& iRecord) {
std::unique_ptr<SDL::LSTESData<DevHost>> produce(TrackerRecoGeometryRecord const& iRecord) {
return SDL::loadAndFillESHost();
}
};
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/LST/plugins/alpaka/LSTProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const bool verbose_, nopLSDupClean_, tcpLSTriplets_;
edm::EDPutTokenT<LSTOutput> lstOutputToken_;

SDL::LST<SDL::Acc> lst_;
SDL::LST<Acc3D> lst_;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LST/src/alpaka/ES_ModulesDev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

// Temporary hack: The DevHost instantiation is needed in both CPU and GPU plugins,
// whereas the (non-host-)Device instantiation only in the GPU plugin
TYPELOOKUP_DATA_REG(SDL::LSTESData<SDL::DevHost>);
TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESData);
TYPELOOKUP_DATA_REG(ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka_common::DevHost>);
TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData);
38 changes: 15 additions & 23 deletions RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <cuda_fp16.h>
#endif

namespace SDL {
namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
// Half precision wrapper functions.
#if defined(FP16_Base)
#define __F2H __float2half
Expand All @@ -26,19 +26,7 @@ namespace SDL {
typedef float FPX;
#endif

using Idx = alpaka_common::Idx;
using Dim = alpaka_common::Dim3D;
using Dim1d = alpaka_common::Dim1D;
using Vec = alpaka_common::Vec3D;
using Vec1d = alpaka_common::Vec1D;
using WorkDiv = alpaka_common::WorkDiv3D;

using Acc = ALPAKA_ACCELERATOR_NAMESPACE::Acc3D;
using Dev = ALPAKA_ACCELERATOR_NAMESPACE::Device;
using DevHost = ALPAKA_ACCELERATOR_NAMESPACE::DevHost;
using QueueAcc = ALPAKA_ACCELERATOR_NAMESPACE::Queue;

Vec const elementsPerThread(Vec::all(static_cast<Idx>(1)));
alpaka_common::Vec3D const elementsPerThread(alpaka_common::Vec3D::all(static_cast<Idx>(1)));

// Needed for files that are compiled by g++ to not throw an error.
// uint4 is defined only for CUDA, so we will have to revisit this soon when running on other backends.
Expand All @@ -53,34 +41,34 @@ namespace SDL {

// Buffer type for allocations where auto type can't be used.
template <typename TDev, typename TData>
using Buf = alpaka::Buf<TDev, TData, Dim1d, Idx>;
using Buf = alpaka::Buf<TDev, TData, Dim1D, Idx>;

// Allocation wrapper function to make integration of the caching allocator easier and reduce code boilerplate.
template <typename T, typename TAcc, typename TSize, typename TQueue>
ALPAKA_FN_HOST ALPAKA_FN_INLINE Buf<alpaka::Dev<TAcc>, T> allocBufWrapper(TAcc const& devAccIn,
TSize nElements,
TQueue queue) {
#ifdef CACHE_ALLOC
return cms::alpakatools::allocCachedBuf<T, Idx>(devAccIn, queue, Vec1d(static_cast<Idx>(nElements)));
return cms::alpakatools::allocCachedBuf<T, Idx>(devAccIn, queue, Vec1D(static_cast<Idx>(nElements)));
#else
return alpaka::allocBuf<T, Idx>(devAccIn, Vec1d(static_cast<Idx>(nElements)));
return alpaka::allocBuf<T, Idx>(devAccIn, Vec1D(static_cast<Idx>(nElements)));
#endif
}

// Second allocation wrapper function when queue is not given. Reduces code boilerplate.
template <typename T, typename TAcc, typename TSize>
ALPAKA_FN_HOST ALPAKA_FN_INLINE Buf<alpaka::Dev<TAcc>, T> allocBufWrapper(TAcc const& devAccIn, TSize nElements) {
return alpaka::allocBuf<T, Idx>(devAccIn, Vec1d(static_cast<Idx>(nElements)));
return alpaka::allocBuf<T, Idx>(devAccIn, Vec1D(static_cast<Idx>(nElements)));
}

// Wrapper function to reduce code boilerplate for defining grid/block sizes.
ALPAKA_FN_HOST ALPAKA_FN_INLINE Vec createVec(int x, int y, int z) {
return Vec(static_cast<Idx>(x), static_cast<Idx>(y), static_cast<Idx>(z));
ALPAKA_FN_HOST ALPAKA_FN_INLINE alpaka_common::Vec3D createVec(int x, int y, int z) {
return alpaka_common::Vec3D(static_cast<Idx>(x), static_cast<Idx>(y), static_cast<Idx>(z));
}

// Adjust grid and block sizes based on backend configuration
template <typename Vec>
ALPAKA_FN_HOST ALPAKA_FN_INLINE WorkDiv createWorkDiv(const Vec& blocksPerGrid,
ALPAKA_FN_HOST ALPAKA_FN_INLINE WorkDiv3D createWorkDiv(const Vec& blocksPerGrid,
const Vec& threadsPerBlock,
const Vec& elementsPerThreadArg) {
Vec adjustedBlocks = blocksPerGrid;
Expand All @@ -97,7 +85,7 @@ namespace SDL {
adjustedBlocks = Vec::all(static_cast<Idx>(1));
#endif

return WorkDiv(adjustedBlocks, adjustedThreads, elementsPerThreadArg);
return WorkDiv3D(adjustedBlocks, adjustedThreads, elementsPerThreadArg);
}

// 15 MeV constant from the approximate Bethe-Bloch formula
Expand All @@ -112,7 +100,11 @@ namespace SDL {
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 sinAlphaMax = 0.95;
#ifdef PT_CUT
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float ptCut = PT_CUT;
#else
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float ptCut = ::SDL::PT_CUT;
#endif
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float deltaZLum = 15.0;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float pixelPSZpitch = 0.15;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float stripPSZpitch = 2.4;
Expand All @@ -125,7 +117,7 @@ namespace SDL {
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float SDL_INF = 123456789.0;
} //namespace SDL

namespace T5DNN {
namespace ALPAKA_ACCELERATOR_NAMESPACE::T5DNN {
// Working points matching LST fake rate (43.9%) or signal acceptance (82.0%)
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float LSTWP1 = 0.3418833f; // 94.0% TPR, 43.9% FPR
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float LSTWP2 = 0.6177366f; // 82.0% TPR, 20.0% FPR
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"

namespace SDL {
namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {

struct EndcapGeometryDev {
const unsigned int* geoMapDetId;
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace SDL {
copyFromSrc(queue, src);
}

inline SDL::EndcapGeometryDev const* data() const { return this; }
inline EndcapGeometryDev const* data() const { return this; }
};

} // namespace SDL
Expand Down
10 changes: 5 additions & 5 deletions RecoTracker/LSTCore/interface/alpaka/LST.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
#include <mutex>
#include <alpaka/alpaka.hpp>

namespace SDL {
namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
template <typename>
class Event;

template <typename>
class LST;

template <>
class LST<SDL::Acc> {
class LST<Acc3D> {
public:
LST() = default;

void run(QueueAcc& queue,
void run(Queue& queue,
bool verbose,
const LSTESData<Dev>* deviceESData,
const LSTESData<Device>* deviceESData,
const std::vector<float> see_px,
const std::vector<float> see_py,
const std::vector<float> see_pz,
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace SDL {
const std::vector<float> ph2_y,
const std::vector<float> ph2_z);

void getOutput(SDL::Event<Acc>& event);
void getOutput(SDL::Event<Acc3D>& event);
std::vector<unsigned int> getHitIdxs(const short trackCandidateType,
const unsigned int TCIdx,
const unsigned int* TCHitIndices,
Expand Down
21 changes: 10 additions & 11 deletions RecoTracker/LSTCore/interface/alpaka/LSTESData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"
#include "RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h"
#include "RecoTracker/LSTCore/interface/alpaka/Module.h"
#include "RecoTracker/LSTCore/interface/PixelMap.h"

#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"

#include <filesystem>
#include <memory>

namespace SDL {

struct pixelMap;
namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {

template <typename TDev>
struct LSTESData {
Expand All @@ -22,15 +21,15 @@ namespace SDL {
unsigned int nEndCapMap;
std::shared_ptr<const modulesBuffer<TDev>> modulesBuffers;
std::shared_ptr<const EndcapGeometryBuffer<TDev>> endcapGeometryBuffers;
std::shared_ptr<const pixelMap> pixelMapping;
std::shared_ptr<const ::SDL::pixelMap> pixelMapping;

LSTESData(uint16_t const& nModulesIn,
uint16_t const& nLowerModulesIn,
unsigned int const& nPixelsIn,
unsigned int const& nEndCapMapIn,
std::shared_ptr<const modulesBuffer<TDev>> const& modulesBuffersIn,
std::shared_ptr<const EndcapGeometryBuffer<TDev>> const& endcapGeometryBuffersIn,
std::shared_ptr<const pixelMap> const& pixelMappingIn)
std::shared_ptr<const ::SDL::pixelMap> const& pixelMappingIn)
: nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
nPixels(nPixelsIn),
Expand All @@ -46,18 +45,18 @@ namespace SDL {

namespace cms::alpakatools {
template <>
struct CopyToDevice<SDL::LSTESData<alpaka_common::DevHost>> {
struct CopyToDevice<ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka_common::DevHost>> {
template <typename TQueue>
static SDL::LSTESData<alpaka::Dev<TQueue>> copyAsync(TQueue& queue,
SDL::LSTESData<alpaka_common::DevHost> const& srcData) {
auto deviceModulesBuffers = std::make_shared<SDL::modulesBuffer<alpaka::Dev<TQueue>>>(
static ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka::Dev<TQueue>> copyAsync(TQueue& queue,
ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka_common::DevHost> const& srcData) {
auto deviceModulesBuffers = std::make_shared<ALPAKA_ACCELERATOR_NAMESPACE::SDL::modulesBuffer<alpaka::Dev<TQueue>>>(
alpaka::getDev(queue), srcData.nModules, srcData.nPixels);
deviceModulesBuffers->copyFromSrc(queue, *srcData.modulesBuffers);
auto deviceEndcapGeometryBuffers =
std::make_shared<SDL::EndcapGeometryBuffer<alpaka::Dev<TQueue>>>(alpaka::getDev(queue), srcData.nEndCapMap);
std::make_shared<ALPAKA_ACCELERATOR_NAMESPACE::SDL::EndcapGeometryBuffer<alpaka::Dev<TQueue>>>(alpaka::getDev(queue), srcData.nEndCapMap);
deviceEndcapGeometryBuffers->copyFromSrc(queue, *srcData.endcapGeometryBuffers);

return SDL::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
return ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
srcData.nLowerModules,
srcData.nPixels,
srcData.nEndCapMap,
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LSTCore/interface/alpaka/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"

namespace SDL {
namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 };

enum Side { NegZ = 1, PosZ = 2, Center = 3 };
Expand Down Expand Up @@ -286,7 +286,7 @@ namespace SDL {

modulesBuffer(TDev const& dev, unsigned int nMod, unsigned int nPixs)
: detIds_buf(allocBufWrapper<unsigned int>(dev, nMod)),
moduleMap_buf(allocBufWrapper<uint16_t>(dev, nMod * MAX_CONNECTED_MODULES)),
moduleMap_buf(allocBufWrapper<uint16_t>(dev, nMod * ::SDL::MAX_CONNECTED_MODULES)),
mapdetId_buf(allocBufWrapper<unsigned int>(dev, nMod)),
mapIdx_buf(allocBufWrapper<uint16_t>(dev, nMod)),
nConnectedModules_buf(allocBufWrapper<uint16_t>(dev, nMod)),
Expand Down
Loading

0 comments on commit 9fd3355

Please sign in to comment.