Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Remove device initialization from library #385

Merged
merged 11 commits into from
Apr 23, 2024
2 changes: 1 addition & 1 deletion SDL/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace SDL {
auto const devHost = alpaka::getDevByIdx(platformHost, 0u);
#if defined ALPAKA_ACC_GPU_CUDA_ENABLED || defined ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED || \
defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
auto const devAcc = alpaka::getDevByIdx(platformAcc, 0u);
// auto const devAcc = alpaka::getDevByIdx(platformAcc, 0u);
using QueueAcc = alpaka::Queue<Acc, QueueProperty>;
#endif

Expand Down
25 changes: 13 additions & 12 deletions SDL/EndcapGeometry.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "EndcapGeometry.h"

Check notice on line 1 in SDL/EndcapGeometry.cc

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/EndcapGeometry.cc

File SDL/EndcapGeometry.cc does not conform to Custom style guidelines. (lines 7, 38)

SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(unsigned int sizef)
: geoMapDetId_buf(allocBufWrapper<unsigned int>(devAcc, sizef)),
geoMapPhi_buf(allocBufWrapper<float>(devAcc, sizef)) {}

SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(std::string filename, unsigned int sizef)
: geoMapDetId_buf(allocBufWrapper<unsigned int>(devAcc, sizef)),
geoMapPhi_buf(allocBufWrapper<float>(devAcc, sizef)) {
load(filename);
SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(SDL::Dev const& devAccIn, unsigned int sizef)
: geoMapDetId_buf(allocBufWrapper<unsigned int>(devAccIn, sizef)),
geoMapPhi_buf(allocBufWrapper<float>(devAccIn, sizef)) {}

SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, std::string filename, unsigned int sizef)
: geoMapDetId_buf(allocBufWrapper<unsigned int>(devAccIn, sizef)),
geoMapPhi_buf(allocBufWrapper<float>(devAccIn, sizef)) {
load(queue, filename);
}

void SDL::EndcapGeometry<SDL::Dev>::load(std::string filename) {
template <typename TQueue>
void SDL::EndcapGeometry<SDL::Dev>::load(TQueue& queue, std::string filename) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be a template? can SDL::QueueAcc be used instead?

Copy link
Member Author

@ariostas ariostas Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was also thinking about this. I think now we don't really need any templates since we could just use SDL::Dev, SDL::DevAcc and SDL::QueueAcc. So I was deciding whether to sticking with templated functions like in most of the code.

dxdy_slope_.clear();
centroid_phis_.clear();

Expand All @@ -30,11 +31,11 @@
}
}

fillGeoMapArraysExplicit();
fillGeoMapArraysExplicit(queue);
}

void SDL::EndcapGeometry<SDL::Dev>::fillGeoMapArraysExplicit() {
QueueAcc queue(devAcc);
template <typename TQueue>
void SDL::EndcapGeometry<SDL::Dev>::fillGeoMapArraysExplicit(TQueue& queue) {

int phi_size = centroid_phis_.size();

Expand Down
11 changes: 6 additions & 5 deletions SDL/EndcapGeometry.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef EndcapGeometry_h

Check notice on line 1 in SDL/EndcapGeometry.h

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/EndcapGeometry.h

File SDL/EndcapGeometry.h does not conform to Custom style guidelines. (lines 30)
#define EndcapGeometry_h

#include <map>
Expand Down Expand Up @@ -26,14 +26,15 @@

unsigned int nEndCapMap;

EndcapGeometry(unsigned int sizef = endcap_size);
EndcapGeometry(std::string filename, unsigned int sizef = endcap_size);
EndcapGeometry(SDL::Dev const& devAccIn, unsigned int sizef = endcap_size);
EndcapGeometry(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, std::string filename, unsigned int sizef = endcap_size);
~EndcapGeometry() = default;

void load(std::string);
template <typename TQueue>
void load(TQueue& queue, std::string);

void fillGeoMapArraysExplicit();
void CreateGeoMapArraysExplicit();
template <typename TQueue>
void fillGeoMapArraysExplicit(TQueue& queue);
float getdxdy_slope(unsigned int detid);
};
} // namespace SDL
Expand Down
5 changes: 2 additions & 3 deletions SDL/Event.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Event.h"

Check notice on line 1 in SDL/Event.cc

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/Event.cc

File SDL/Event.cc does not conform to Custom style guidelines. (lines 47, 155)
#include "Globals.h"

void SDL::Event<SDL::Acc>::init(bool verbose) {
Expand Down Expand Up @@ -44,7 +44,7 @@
}

// Standalone constructor that has each event object create its own queue.
SDL::Event<SDL::Acc>::Event(bool verbose) : queue(alpaka::getDevByIdx(platformAcc, 0u)) { init(verbose); }
SDL::Event<SDL::Acc>::Event(bool verbose) : devAcc(alpaka::getDevByIdx(platformAcc, 0u)), queue(alpaka::getDevByIdx(platformAcc, 0u)) { init(verbose); }

void SDL::Event<SDL::Acc>::resetEvent() {
//reset the arrays
Expand Down Expand Up @@ -152,8 +152,7 @@
}
}

void SDL::Event<SDL::Acc>::initModules(const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath) {
QueueAcc queue(devAcc);
void SDL::Event<SDL::Acc>::initModules(QueueAcc& queue, const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath) {

// nModules gets filled here
loadModulesFromFile(Globals<SDL::Dev>::modulesBuffers,
Expand Down
12 changes: 7 additions & 5 deletions SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace SDL {
template <>
class Event<SDL::Acc> {
private:
Dev devAcc;
QueueAcc queue;
bool addObjects;

Expand Down Expand Up @@ -75,11 +76,11 @@ namespace SDL {
int8_t* pixelTypeCPU;

public:
// Standalone constructor that has each event object create its own queue.
// Standalone constructor that has each event object create its own device and queue.
Event(bool verbose);
// Constructor used for CMSSW integration. Uses an external queue.
template <typename TQueue>
Event(bool verbose, const TQueue& q) : queue(q) {
// Constructor used for CMSSW integration. Uses an external device and queue.
template <typename TDevAcc, typename TQueue>
Event(bool verbose, TDevAcc const& devAccIn, TQueue const& q) : devAcc(devAccIn), queue(q) {
init(verbose);
}
void resetEvent();
Expand Down Expand Up @@ -177,7 +178,8 @@ namespace SDL {
modulesBuffer<alpaka::DevCpu>* getModules(bool isFull = false);

//read from file and init
static void initModules(const MapPLStoLayer& pLStoLayer,
static void initModules(QueueAcc& queue,
const MapPLStoLayer& pLStoLayer,
const char* moduleMetaDataFilePath = "data/OT800_IT615_pt0.8/sensor_centroids.txt");
};

Expand Down
2 changes: 1 addition & 1 deletion SDL/Globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ std::shared_ptr<SDL::pixelMap> SDL::Globals<SDL::Dev>::pixelMapping = nullptr;
uint16_t SDL::Globals<SDL::Dev>::nModules;
uint16_t SDL::Globals<SDL::Dev>::nLowerModules;

SDL::EndcapGeometry<SDL::Dev>* SDL::Globals<SDL::Dev>::endcapGeometry = new SDL::EndcapGeometry<SDL::Dev>();
SDL::EndcapGeometry<SDL::Dev>* SDL::Globals<SDL::Dev>::endcapGeometry = nullptr;

SDL::TiltedGeometry<SDL::Dev> SDL::Globals<SDL::Dev>::tiltedGeometry;
SDL::ModuleConnectionMap<SDL::Dev> SDL::Globals<SDL::Dev>::moduleConnectionMap;
Expand Down
17 changes: 10 additions & 7 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "LST.h"

Check notice on line 1 in SDL/LST.cc

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/LST.cc

File SDL/LST.cc does not conform to Custom style guidelines. (lines 27, 58)
#include "Event.h"
#include "Globals.h"

Expand All @@ -17,13 +17,15 @@
return fullpath.string();
}

void loadMaps(SDL::MapPLStoLayer& pLStoLayer) {
void loadMaps(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer) {
// Module orientation information (DrDz or phi angles)
auto endcap_geom =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.txt");
auto tilted_geom = get_absolute_path_after_check_file_exists(
trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.txt");
SDL::Globals<SDL::Dev>::endcapGeometry->load(endcap_geom); // centroid values added to the map
if (SDL::Globals<SDL::Dev>::endcapGeometry == nullptr) {
SDL::Globals<SDL::Dev>::endcapGeometry = new SDL::EndcapGeometry<SDL::Dev>(devAccIn, queue, endcap_geom); // centroid values added to the map
}
SDL::Globals<SDL::Dev>::tiltedGeometry.load(tilted_geom);

// Module connection map (for line segment building)
Expand Down Expand Up @@ -53,14 +55,14 @@

} // namespace

void SDL::LST<SDL::Acc>::loadAndFillES(alpaka::QueueCpuBlocking& queue, struct modulesBuffer<alpaka::DevCpu>* modules) {
void SDL::LST<SDL::Acc>::loadAndFillES(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, struct modulesBuffer<alpaka::DevCpu>* modules) {
SDL::MapPLStoLayer pLStoLayer;
::loadMaps(pLStoLayer);
::loadMaps(devAccIn, queue, pLStoLayer);

auto path =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.txt");
if (SDL::Globals<SDL::Dev>::modulesBuffers == nullptr) {
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(SDL::devAcc);
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(devAccIn);
}
if (SDL::Globals<SDL::Dev>::pixelMapping == nullptr) {
SDL::Globals<SDL::Dev>::pixelMapping = std::make_shared<SDL::pixelMap>();
Expand All @@ -74,7 +76,8 @@
pLStoLayer);
}

void SDL::LST<SDL::Acc>::run(SDL::QueueAcc& queue,
void SDL::LST<SDL::Acc>::run(SDL::Dev& devAccIn,
SDL::QueueAcc& queue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to have a queue and a device separately? Isn't a queue uniquely attached to a device?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I'll tidy things up.

const SDL::modulesBuffer<SDL::Dev>* modules,
bool verbose,
const std::vector<float> see_px,
Expand All @@ -97,7 +100,7 @@
const std::vector<float> ph2_y,
const std::vector<float> ph2_z) {
SDL::Globals<SDL::Dev>::modulesBuffersES = modules;
auto event = SDL::Event<Acc>(verbose, queue);
auto event = SDL::Event<Acc>(verbose, devAccIn, queue);
prepareInput(see_px,
see_py,
see_pz,
Expand Down
5 changes: 3 additions & 2 deletions SDL/LST.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef LST_H

Check notice on line 1 in SDL/LST.h

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/LST.h

File SDL/LST.h does not conform to Custom style guidelines. (lines 27)
#define LST_H

#include "Constants.h"
Expand All @@ -24,9 +24,10 @@
public:
LST() = default;

static void loadAndFillES(alpaka::QueueCpuBlocking& queue, struct modulesBuffer<alpaka::DevCpu>* modules);
static void loadAndFillES(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, struct modulesBuffer<alpaka::DevCpu>* modules);

void run(SDL::QueueAcc& queue,
void run(SDL::Dev& devAccIn,
SDL::QueueAcc& queue,
const SDL::modulesBuffer<SDL::Dev>* modules,
bool verbose,
const std::vector<float> see_px,
Expand Down
6 changes: 4 additions & 2 deletions bin/sdl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ int main(int argc, char** argv)
//___________________________________________________________________________________________________________________________________________________________________________________________
void run_sdl()
{
SDL::Dev devAcc = alpaka::getDevByIdx(SDL::platformAcc, 0u);
SDL::QueueAcc queue(devAcc);

// Load various maps used in the SDL reconstruction
TStopwatch full_timer;
full_timer.Start();
loadMaps();
loadMaps(devAcc, queue);
float timeForMapLoading = full_timer.RealTime()*1000;

if (ana.do_write_ntuple)
Expand Down Expand Up @@ -383,7 +385,7 @@ void run_sdl()
std::vector<SDL::Event<SDL::Acc>*> events;
for (int s = 0; s < ana.streams; s++)
{
SDL::Event<SDL::Acc> *event = new SDL::Event<SDL::Acc>(ana.verbose>=2);
SDL::Event<SDL::Acc> *event = new SDL::Event<SDL::Acc>(ana.verbose>=2, devAcc, queue);
events.push_back(event);
}
float timeForEventCreation = full_timer.RealTime()*1000;
Expand Down
10 changes: 6 additions & 4 deletions code/core/trkCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Globals.h"

//___________________________________________________________________________________________________________________________________________________________________________________________
void loadMaps()
void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue)
{
// From the environment variable figure out the main tracklooper absolute path
TString TrackLooperDir = gSystem->Getenv("TRACKLOOPERDIR");
Expand All @@ -21,7 +21,9 @@ void loadMaps()
std::cout << "pLS map: " << pLSMapDir << std::endl;
std::cout << "centroid: " << centroid << std::endl;

SDL::Globals<SDL::Dev>::endcapGeometry->load(endcap_geom.Data()); // centroid values added to the map
if (SDL::Globals<SDL::Dev>::endcapGeometry == nullptr) {
SDL::Globals<SDL::Dev>::endcapGeometry = new SDL::EndcapGeometry<SDL::Dev>(devAccIn, queue, endcap_geom.Data()); // centroid values added to the map
}
SDL::Globals<SDL::Dev>::tiltedGeometry.load(tilted_geom.Data());
SDL::Globals<SDL::Dev>::moduleConnectionMap.load(mappath.Data());

Expand All @@ -41,12 +43,12 @@ void loadMaps()

// WARNING: initModules must come after above load commands!! keep it at the last line here!
if (SDL::Globals<SDL::Dev>::modulesBuffers == nullptr) {
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(SDL::devAcc);
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(devAccIn);
}
if (SDL::Globals<SDL::Dev>::pixelMapping == nullptr) {
SDL::Globals<SDL::Dev>::pixelMapping = std::make_shared<SDL::pixelMap>();
}
SDL::Event<SDL::Acc>::initModules(pLStoLayer, centroid.Data());
SDL::Event<SDL::Acc>::initModules(queue, pLStoLayer, centroid.Data());
}

//___________________________________________________________________________________________________________________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion code/core/trkCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// --------------------- ======================== ---------------------

void loadMaps();
void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue);
bool goodEvent();
float runMiniDoublet(SDL::Event<SDL::Acc>* event, int evt);
float runSegment(SDL::Event<SDL::Acc>* event);
Expand Down
Loading