Skip to content

Commit

Permalink
Merge pull request #65 from SegmentLinking/use_common_library
Browse files Browse the repository at this point in the history
Move some things out into a common library
  • Loading branch information
slava77 authored Jul 18, 2024
2 parents 1d9b396 + fb12af0 commit 1250a8c
Show file tree
Hide file tree
Showing 43 changed files with 1,098 additions and 1,080 deletions.
6 changes: 3 additions & 3 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 All @@ -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
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<SDL::Acc> lst_;
SDL::LST<Acc3D> 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>);
5 changes: 1 addition & 4 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(SDL::LSTESData<SDL::DevHost>);
TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESData);
1 change: 1 addition & 0 deletions RecoTracker/LSTCore/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="root"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<flags CXXFLAGS="-DCACHE_ALLOC -DT4FromT3 -DUSE_RZCHI2 -DUSE_T5_DNN -DPT_CUT=0.8 -DDUP_pLS -DDUP_T5 -DDUP_pT5 -DDUP_pT3 -DCrossclean_T5 -DCrossclean_pT3"/>
<use name="1" for="alpaka"/>
<flags ALPAKA_BACKENDS="1"/>
<export>
<lib name="1"/>
Expand Down
80 changes: 80 additions & 0 deletions RecoTracker/LSTCore/interface/Constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#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;
#endif

constexpr unsigned int MAX_BLOCKS = 80;
constexpr unsigned int MAX_CONNECTED_MODULES = 40;

constexpr unsigned int N_MAX_PIXEL_SEGMENTS_PER_MODULE = 50000;

constexpr unsigned int N_MAX_PIXEL_MD_PER_MODULES = 2 * N_MAX_PIXEL_SEGMENTS_PER_MODULE;

constexpr unsigned int N_MAX_PIXEL_TRIPLETS = 5000;
constexpr unsigned int N_MAX_PIXEL_QUINTUPLETS = 15000;

constexpr unsigned int N_MAX_PIXEL_TRACK_CANDIDATES = 30000;
constexpr unsigned int N_MAX_NONPIXEL_TRACK_CANDIDATES = 1000;

constexpr unsigned int size_superbins = 45000;

//defining the constant host device variables right up here
// Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4) and 4 hits. To be potentially handled better in the future.
struct Params_pLS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_LS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_T3 {
static constexpr int kLayers = 3, kHits = 6;
};
struct Params_pT3 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_T5 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_pT5 {
static constexpr int kLayers = 7, kHits = 14;
};

} //namespace SDL

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef EndcapGeometry_h
#define EndcapGeometry_h
#ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h
#define RecoTracker_LSTCore_interface_EndcapGeometry_h

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

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

namespace SDL {
template <typename>
class EndcapGeometry;
template <>
class EndcapGeometry<SDL::Dev> {
class EndcapGeometry {
private:
std::map<unsigned int, float> dxdy_slope_; // dx/dy slope
std::map<unsigned int, float> centroid_phis_; // centroid phi
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,9 +9,7 @@
#include <vector>
#include <stdexcept>

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

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

namespace SDL {

Expand Down Expand Up @@ -49,7 +47,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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#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>
Expand All @@ -16,14 +16,15 @@ namespace SDL {
template <typename>
class LST;

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

void run(QueueAcc& queue,
template <typename TQueue>
void run(TQueue& queue,
bool verbose,
const LSTESData<Dev>* deviceESData,
const LSTESData<alpaka::Dev<TAcc>>* 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 SDL {
const std::vector<float> ph2_y,
const std::vector<float> ph2_z);

void getOutput(SDL::Event<Acc>& event);
void getOutput(SDL::Event<TAcc>& 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,9 +1,10 @@
#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"

Expand All @@ -12,8 +13,6 @@

namespace SDL {

struct pixelMap;

template <typename TDev>
struct LSTESData {
uint16_t nModules;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#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/alpaka/Constants.h"
#include "RecoTracker/LSTCore/interface/Constants.h"

namespace SDL {
enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ModuleConnectionMap_h
#define ModuleConnectionMap_h
#ifndef RecoTracker_LSTCore_interface_ModuleConnectionMap_h
#define RecoTracker_LSTCore_interface_ModuleConnectionMap_h

#include <iostream>
#include <fstream>
Expand All @@ -8,14 +8,8 @@
#include <sstream>
#include <algorithm>

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

namespace SDL {
//FIXME: move to non-alpaka single arch build
template <typename>
class ModuleConnectionMap;
template <>
class ModuleConnectionMap<SDL::Dev> {
class ModuleConnectionMap {
private:
std::map<unsigned int, std::vector<unsigned int>> moduleConnections_;

Expand All @@ -32,7 +26,7 @@ namespace SDL {
int size() const;
};

using MapPLStoLayer = std::array<std::array<ModuleConnectionMap<SDL::Dev>, 4>, 3>;
using MapPLStoLayer = std::array<std::array<ModuleConnectionMap, 4>, 3>;
} // namespace SDL

#endif
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#ifndef PixelMap_h
#define PixelMap_h
#ifndef RecoTracker_LSTCore_interface_PixelMap_h
#define RecoTracker_LSTCore_interface_PixelMap_h

#include <vector>
#include <cstdint>

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

namespace SDL {
// PixelMap is never allocated on the device.
// This is also not passed to any of the kernels, so we can combine the structs.
struct pixelMap {
uint16_t pixelModuleIndex;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TiltedGeometry_h
#define TiltedGeometry_h
#ifndef RecoTracker_LSTCore_interface_TiltedGeometry_h
#define RecoTracker_LSTCore_interface_TiltedGeometry_h

#include <vector>
#include <map>
Expand All @@ -9,13 +9,8 @@
#include <string>
#include <stdexcept>

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

namespace SDL {
template <typename>
class TiltedGeometry;
template <>
class TiltedGeometry<SDL::Dev> {
class TiltedGeometry {
private:
std::map<unsigned int, float> drdzs_; // dr/dz slope
std::map<unsigned int, float> dxdys_; // dx/dy slope
Expand Down
Loading

0 comments on commit 1250a8c

Please sign in to comment.