Skip to content

Commit

Permalink
Moved more things out of the alpaka directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Jul 17, 2024
1 parent 9fd3355 commit 64a7bf1
Show file tree
Hide file tree
Showing 25 changed files with 747 additions and 751 deletions.
4 changes: 2 additions & 2 deletions RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"

// LST includes
#include "RecoTracker/LSTCore/interface/alpaka/Module.h"
#include "RecoTracker/LSTCore/interface/alpaka/LST.h"
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/LST.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LST/plugins/alpaka/LSTProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"

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

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand Down Expand Up @@ -91,7 +91,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const bool verbose_, nopLSDupClean_, tcpLSTriplets_;
edm::EDPutTokenT<LSTOutput> lstOutputToken_;

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

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
5 changes: 5 additions & 0 deletions RecoTracker/LST/src/ES_ModulesDev.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "RecoTracker/LSTCore/interface/LSTESData.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "FWCore/Utilities/interface/typelookup.h"

TYPELOOKUP_DATA_REG(SDL::LSTESData<alpaka_common::DevHost>);
7 changes: 2 additions & 5 deletions RecoTracker/LST/src/alpaka/ES_ModulesDev.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include "RecoTracker/LSTCore/interface/alpaka/LST.h"
#include "RecoTracker/LSTCore/interface/LSTESData.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/typelookup.h"

// 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(ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka_common::DevHost>);
TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData);
TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESData);
27 changes: 27 additions & 0 deletions RecoTracker/LSTCore/interface/Constants.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
#ifndef RecoTracker_LSTCore_interface_Constants_h
#define RecoTracker_LSTCore_interface_Constants_h

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

#ifdef CACHE_ALLOC
#include "HeterogeneousCore/AlpakaInterface/interface/CachedBufAlloc.h"
#endif

namespace SDL {

// Buffer type for allocations where auto type can't be used.
template <typename TDev, typename TData>
using Buf = alpaka::Buf<TDev, TData, alpaka_common::Dim1D, alpaka_common::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, alpaka_common::Idx>(devAccIn, queue, alpaka_common::Vec1D(static_cast<alpaka_common::Idx>(nElements)));
#else
return alpaka::allocBuf<T, alpaka_common::Idx>(devAccIn, alpaka_common::Vec1D(static_cast<alpaka_common::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, alpaka_common::Idx>(devAccIn, alpaka_common::Vec1D(static_cast<alpaka_common::Idx>(nElements)));
}

// If a compile time flag does not define PT_CUT, default to 0.8 (GeV)
#ifndef PT_CUT
constexpr float PT_CUT = 0.8f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_EndcapGeometryBuffers_h
#define RecoTracker_LSTCore_interface_alpaka_EndcapGeometryBuffers_h
#ifndef RecoTracker_LSTCore_interface_EndcapGeometryBuffers_h
#define RecoTracker_LSTCore_interface_EndcapGeometryBuffers_h

#include <map>
#include <iostream>
Expand All @@ -9,11 +9,9 @@
#include <vector>
#include <stdexcept>

#include "HeterogeneousCore/AlpakaInterface/interface/host.h"
#include "RecoTracker/LSTCore/interface/Constants.h"

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

namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
namespace SDL {

struct EndcapGeometryDev {
const unsigned int* geoMapDetId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_LST_h
#define RecoTracker_LSTCore_interface_alpaka_LST_h
#ifndef RecoTracker_LSTCore_interface_LST_h
#define RecoTracker_LSTCore_interface_LST_h

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

#include <cstdlib>
#include <numeric>
#include <mutex>
#include <alpaka/alpaka.hpp>

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

template <typename>
class LST;

template <>
class LST<Acc3D> {
template <typename TDev>
class LST {
public:
LST() = default;

void run(Queue& queue,
template <typename TQueue>
void run(TQueue& queue,
bool verbose,
const LSTESData<Device>* deviceESData,
const LSTESData<TDev>* 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 +72,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
const std::vector<float> ph2_y,
const std::vector<float> ph2_z);

void getOutput(SDL::Event<Acc3D>& event);
void getOutput(SDL::Event<TDev>& event);
std::vector<unsigned int> getHitIdxs(const short trackCandidateType,
const unsigned int TCIdx,
const unsigned int* TCHitIndices,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_LSTESData_h
#define RecoTracker_LSTCore_interface_alpaka_LSTESData_h
#ifndef RecoTracker_LSTCore_interface_LSTESData_h
#define RecoTracker_LSTCore_interface_LSTESData_h

#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/Constants.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometryBuffer.h"
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/PixelMap.h"

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

#include <filesystem>
#include <memory>

namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
namespace SDL {

template <typename TDev>
struct LSTESData {
Expand All @@ -21,15 +21,15 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
unsigned int nEndCapMap;
std::shared_ptr<const modulesBuffer<TDev>> modulesBuffers;
std::shared_ptr<const EndcapGeometryBuffer<TDev>> endcapGeometryBuffers;
std::shared_ptr<const ::SDL::pixelMap> pixelMapping;
std::shared_ptr<const 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 ::SDL::pixelMap> const& pixelMappingIn)
std::shared_ptr<const pixelMap> const& pixelMappingIn)
: nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
nPixels(nPixelsIn),
Expand All @@ -45,18 +45,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {

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

return ALPAKA_ACCELERATOR_NAMESPACE::SDL::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
return SDL::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
srcData.nLowerModules,
srcData.nPixels,
srcData.nEndCapMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_Module_h
#define RecoTracker_LSTCore_interface_alpaka_Module_h
#ifndef RecoTracker_LSTCore_interface_Module_h
#define RecoTracker_LSTCore_interface_Module_h

#include <alpaka/alpaka.hpp>
#include "RecoTracker/LSTCore/interface/Constants.h"

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

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

enum Side { NegZ = 1, PosZ = 2, Center = 3 };
Expand Down Expand Up @@ -286,7 +284,7 @@ namespace ALPAKA_ACCELERATOR_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 * ::SDL::MAX_CONNECTED_MODULES)),
moduleMap_buf(allocBufWrapper<uint16_t>(dev, nMod * 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
51 changes: 9 additions & 42 deletions RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_Constants_h
#define RecoTracker_LSTCore_interface_alpaka_Constants_h

#include <alpaka/alpaka.hpp>

#include "RecoTracker/LSTCore/interface/Constants.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

#ifdef CACHE_ALLOC
#include "HeterogeneousCore/AlpakaInterface/interface/CachedBufAlloc.h"
#endif

#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
#include <cuda_fp16.h>
#endif

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

alpaka_common::Vec3D const elementsPerThread(alpaka_common::Vec3D::all(static_cast<Idx>(1)));
alpaka_common::Vec3D const elementsPerThread(alpaka_common::Vec3D::all(static_cast<alpaka_common::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 @@ -39,53 +32,31 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
};
#endif

// Buffer type for allocations where auto type can't be used.
template <typename TDev, typename TData>
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)));
#else
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)));
}

// Wrapper function to reduce code boilerplate for defining grid/block sizes.
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));
return alpaka_common::Vec3D(static_cast<alpaka_common::Idx>(x), static_cast<alpaka_common::Idx>(y), static_cast<alpaka_common::Idx>(z));
}

// Adjust grid and block sizes based on backend configuration
template <typename Vec>
ALPAKA_FN_HOST ALPAKA_FN_INLINE WorkDiv3D createWorkDiv(const Vec& blocksPerGrid,
ALPAKA_FN_HOST ALPAKA_FN_INLINE alpaka_common::WorkDiv3D createWorkDiv(const Vec& blocksPerGrid,
const Vec& threadsPerBlock,
const Vec& elementsPerThreadArg) {
Vec adjustedBlocks = blocksPerGrid;
Vec adjustedThreads = threadsPerBlock;

// Serial execution, so all launch parameters set to 1.
#if defined(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED)
adjustedBlocks = Vec::all(static_cast<Idx>(1));
adjustedThreads = Vec::all(static_cast<Idx>(1));
adjustedBlocks = Vec::all(static_cast<alpaka_common::Idx>(1));
adjustedThreads = Vec::all(static_cast<alpaka_common::Idx>(1));
#endif

// Threads enabled, set number of blocks to 1.
#if defined(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED)
adjustedBlocks = Vec::all(static_cast<Idx>(1));
adjustedBlocks = Vec::all(static_cast<alpaka_common::Idx>(1));
#endif

return WorkDiv3D(adjustedBlocks, adjustedThreads, elementsPerThreadArg);
return alpaka_common::WorkDiv3D(adjustedBlocks, adjustedThreads, elementsPerThreadArg);
}

// 15 MeV constant from the approximate Bethe-Bloch formula
Expand All @@ -100,11 +71,7 @@ namespace ALPAKA_ACCELERATOR_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 @@ -117,7 +84,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::SDL {
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float SDL_INF = 123456789.0;
} //namespace SDL

namespace ALPAKA_ACCELERATOR_NAMESPACE::T5DNN {
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
Loading

0 comments on commit 64a7bf1

Please sign in to comment.