diff --git a/RecoTracker/LST/interface/LSTOutput.h b/RecoTracker/LST/interface/LSTOutput.h index 765be209201d9..7a581cc3299f9 100644 --- a/RecoTracker/LST/interface/LSTOutput.h +++ b/RecoTracker/LST/interface/LSTOutput.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LST_LSTOutput_h -#define RecoTracker_LST_LSTOutput_h +#ifndef RecoTracker_LST_interface_LSTOutput_h +#define RecoTracker_LST_interface_LSTOutput_h #include #include diff --git a/RecoTracker/LST/interface/LSTPhase2OTHitsInput.h b/RecoTracker/LST/interface/LSTPhase2OTHitsInput.h index 524a06be1250a..6a65d09dd30d7 100644 --- a/RecoTracker/LST/interface/LSTPhase2OTHitsInput.h +++ b/RecoTracker/LST/interface/LSTPhase2OTHitsInput.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LST_LSTPhase2OTHitsInput_h -#define RecoTracker_LST_LSTPhase2OTHitsInput_h +#ifndef RecoTracker_LST_interface_LSTPhase2OTHitsInput_h +#define RecoTracker_LST_interface_LSTPhase2OTHitsInput_h #include #include diff --git a/RecoTracker/LST/interface/LSTPixelSeedInput.h b/RecoTracker/LST/interface/LSTPixelSeedInput.h index 14681f266de2f..69fa1ed0d4ece 100644 --- a/RecoTracker/LST/interface/LSTPixelSeedInput.h +++ b/RecoTracker/LST/interface/LSTPixelSeedInput.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LST_LSTPixelSeedInput_h -#define RecoTracker_LST_LSTPixelSeedInput_h +#ifndef RecoTracker_LST_interface_LSTPixelSeedInput_h +#define RecoTracker_LST_interface_LSTPixelSeedInput_h #include #include diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index e6b3c42b7ed10..6e7b14d4f0c88 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -15,41 +15,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { class LSTModulesDevESProducer : public ESProducer { public: - LSTModulesDevESProducer(const edm::ParameterSet& iConfig); + LSTModulesDevESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig) { setWhatProduced(this); } - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + descriptions.addWithDefaultLabel(desc); + } - std::unique_ptr> produceHost(TrackerRecoGeometryRecord const& iRecord); - std::unique_ptr> produceDevice( - device::Record const& iRecord); - - private: - edm::ESGetToken, TrackerRecoGeometryRecord> lstESHostToken_; + std::unique_ptr> produce(TrackerRecoGeometryRecord const& iRecord) { + return SDL::loadAndFillESHost(); + } }; - LSTModulesDevESProducer::LSTModulesDevESProducer(const edm::ParameterSet& iConfig) : ESProducer(iConfig) { - setWhatProduced(this, &LSTModulesDevESProducer::produceHost); - auto cc = setWhatProduced(this, &LSTModulesDevESProducer::produceDevice); - lstESHostToken_ = cc.consumes(); - } - - void LSTModulesDevESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - descriptions.addWithDefaultLabel(desc); - } - - std::unique_ptr> LSTModulesDevESProducer::produceHost( - TrackerRecoGeometryRecord const& iRecord) { - return SDL::loadAndFillESHost(); - } - - std::unique_ptr> LSTModulesDevESProducer::produceDevice( - device::Record const& iRecord) { - auto const& lstESHostData = iRecord.get(lstESHostToken_); - SDL::QueueAcc& queue = iRecord.queue(); - return SDL::loadAndFillESDevice(queue, &lstESHostData); - } - } // namespace ALPAKA_ACCELERATOR_NAMESPACE DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(LSTModulesDevESProducer); diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index e51501f85b361..375ab86e0b094 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -87,7 +87,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { private: edm::EDGetTokenT lstPixelSeedInputToken_; edm::EDGetTokenT lstPhase2OTHitsInputToken_; - device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; + device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; const bool verbose_, nopLSDupClean_, tcpLSTriplets_; edm::EDPutTokenT lstOutputToken_; diff --git a/RecoTracker/LST/src/alpaka/ES_ModulesDev.cc b/RecoTracker/LST/src/alpaka/ES_ModulesDev.cc index 9c66dda420db0..3964d050f924b 100644 --- a/RecoTracker/LST/src/alpaka/ES_ModulesDev.cc +++ b/RecoTracker/LST/src/alpaka/ES_ModulesDev.cc @@ -3,8 +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::LSTESHostData); -TYPELOOKUP_DATA_REG(SDL::LSTESDeviceData); -TYPELOOKUP_DATA_REG(ALPAKA_ACCELERATOR_NAMESPACE::ESDeviceProduct>>); -TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESHostData); -TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESDeviceData); +TYPELOOKUP_DATA_REG(SDL::LSTESData); +TYPELOOKUP_ALPAKA_TEMPLATED_DATA_REG(SDL::LSTESData); diff --git a/RecoTracker/LSTCore/BuildFile.xml b/RecoTracker/LSTCore/BuildFile.xml index 2aa254e0c0f6c..45a3932180439 100644 --- a/RecoTracker/LSTCore/BuildFile.xml +++ b/RecoTracker/LSTCore/BuildFile.xml @@ -2,7 +2,7 @@ - + diff --git a/RecoTracker/LSTCore/interface/alpaka/Constants.h b/RecoTracker/LSTCore/interface/alpaka/Constants.h index 2050c5e0727b0..8ad42ce48ea7d 100644 --- a/RecoTracker/LSTCore/interface/alpaka/Constants.h +++ b/RecoTracker/LSTCore/interface/alpaka/Constants.h @@ -1,5 +1,5 @@ -#ifndef Constants_cuh -#define Constants_cuh +#ifndef RecoTracker_LSTCore_interface_alpaka_Constants_h +#define RecoTracker_LSTCore_interface_alpaka_Constants_h #include diff --git a/RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h b/RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h new file mode 100644 index 0000000000000..3def25c3ccb7b --- /dev/null +++ b/RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h @@ -0,0 +1,57 @@ +#ifndef RecoTracker_LSTCore_interface_alpaka_EndcapGeometryBuffers_h +#define RecoTracker_LSTCore_interface_alpaka_EndcapGeometryBuffers_h + +#include +#include +#include +#include +#include +#include +#include + +#include "HeterogeneousCore/AlpakaInterface/interface/host.h" + +#include "RecoTracker/LSTCore/interface/alpaka/Constants.h" + +namespace SDL { + + struct EndcapGeometryDev { + const unsigned int* geoMapDetId; + const float* geoMapPhi; + + template + void setData(const TBuff& endcapgeombuf) { + geoMapDetId = alpaka::getPtrNative(endcapgeombuf.geoMapDetId_buf); + geoMapPhi = alpaka::getPtrNative(endcapgeombuf.geoMapPhi_buf); + } + }; + + template + struct EndcapGeometryBuffer : EndcapGeometryDev { + Buf geoMapDetId_buf; + Buf geoMapPhi_buf; + + EndcapGeometryBuffer(TDev const& dev, unsigned int nEndCapMap) + : geoMapDetId_buf(allocBufWrapper(dev, nEndCapMap)), + geoMapPhi_buf(allocBufWrapper(dev, nEndCapMap)) { + setData(*this); + } + + template + inline void copyFromSrc(TQueue queue, const EndcapGeometryBuffer& src) { + alpaka::memcpy(queue, geoMapDetId_buf, src.geoMapDetId_buf); + alpaka::memcpy(queue, geoMapPhi_buf, src.geoMapPhi_buf); + } + + template + EndcapGeometryBuffer(TQueue queue, const EndcapGeometryBuffer& src, unsigned int nEndCapMap) + : EndcapGeometryBuffer(alpaka::getDev(queue), nEndCapMap) { + copyFromSrc(queue, src); + } + + inline SDL::EndcapGeometryDev const* data() const { return this; } + }; + +} // namespace SDL + +#endif diff --git a/RecoTracker/LSTCore/interface/alpaka/LST.h b/RecoTracker/LSTCore/interface/alpaka/LST.h index 16f3e87361489..6b8ee7e23ddd3 100644 --- a/RecoTracker/LSTCore/interface/alpaka/LST.h +++ b/RecoTracker/LSTCore/interface/alpaka/LST.h @@ -1,5 +1,5 @@ -#ifndef LST_H -#define LST_H +#ifndef RecoTracker_LSTCore_interface_alpaka_LST_h +#define RecoTracker_LSTCore_interface_alpaka_LST_h #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" #include "RecoTracker/LSTCore/interface/alpaka/LSTESData.h" @@ -23,7 +23,7 @@ namespace SDL { void run(QueueAcc& queue, bool verbose, - const LSTESDeviceData* deviceESData, + const LSTESData* deviceESData, const std::vector see_px, const std::vector see_py, const std::vector see_pz, diff --git a/RecoTracker/LSTCore/interface/alpaka/LSTESData.h b/RecoTracker/LSTCore/interface/alpaka/LSTESData.h index 12b39135766ba..5bec4018daba5 100644 --- a/RecoTracker/LSTCore/interface/alpaka/LSTESData.h +++ b/RecoTracker/LSTCore/interface/alpaka/LSTESData.h @@ -1,7 +1,9 @@ -#ifndef LSTESData_H -#define LSTESData_H +#ifndef RecoTracker_LSTCore_interface_alpaka_LSTESData_h +#define RecoTracker_LSTCore_interface_alpaka_LSTESData_h #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" +#include "RecoTracker/LSTCore/interface/alpaka/EndcapGeometryBuffer.h" +#include "RecoTracker/LSTCore/interface/alpaka/Module.h" #include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" @@ -12,77 +14,56 @@ namespace SDL { struct pixelMap; - template - class TiltedGeometry; - - template - class ModuleConnectionMap; - using MapPLStoLayer = std::array, 4>, 3>; - - template - struct modulesBuffer; - - template - class EndcapGeometryHost; - - template - class EndcapGeometry; - - template - struct LSTESHostData; - - // FIXME: This shouldn't be a templated struct - template <> - struct LSTESHostData { - std::shared_ptr mapPLStoLayer; - std::shared_ptr> endcapGeometry; - std::shared_ptr> tiltedGeometry; - std::shared_ptr> moduleConnectionMap; - - LSTESHostData(std::shared_ptr mapPLStoLayerIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr> tiltedGeometryIn, - std::shared_ptr> moduleConnectionMapIn) - : mapPLStoLayer(mapPLStoLayerIn), - endcapGeometry(endcapGeometryIn), - tiltedGeometry(tiltedGeometryIn), - moduleConnectionMap(moduleConnectionMapIn) {} - }; - template - struct LSTESDeviceData { + struct LSTESData { uint16_t nModules; uint16_t nLowerModules; unsigned int nPixels; + unsigned int nEndCapMap; std::shared_ptr> modulesBuffers; - std::shared_ptr> endcapGeometry; + std::shared_ptr> endcapGeometryBuffers; std::shared_ptr pixelMapping; - LSTESDeviceData(uint16_t nModulesIn, - uint16_t nLowerModulesIn, - unsigned int nPixelsIn, - std::shared_ptr> modulesBuffersIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr pixelMappingIn) + LSTESData(uint16_t const& nModulesIn, + uint16_t const& nLowerModulesIn, + unsigned int const& nPixelsIn, + unsigned int const& nEndCapMapIn, + std::shared_ptr> const& modulesBuffersIn, + std::shared_ptr> const& endcapGeometryBuffersIn, + std::shared_ptr const& pixelMappingIn) : nModules(nModulesIn), nLowerModules(nLowerModulesIn), nPixels(nPixelsIn), + nEndCapMap(nEndCapMapIn), modulesBuffers(modulesBuffersIn), - endcapGeometry(endcapGeometryIn), + endcapGeometryBuffers(endcapGeometryBuffersIn), pixelMapping(pixelMappingIn) {} }; - std::unique_ptr> loadAndFillESHost(); - std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, const LSTESHostData* hostData); + std::unique_ptr> loadAndFillESHost(); } // namespace SDL namespace cms::alpakatools { template <> - struct CopyToDevice> { + struct CopyToDevice> { template - static auto copyAsync(TQueue& queue, SDL::LSTESHostData const& hostData) { - return std::make_unique>(hostData); + static SDL::LSTESData> copyAsync(TQueue& queue, + SDL::LSTESData const& srcData) { + auto deviceModulesBuffers = std::make_shared>>( + alpaka::getDev(queue), srcData.nModules, srcData.nPixels); + deviceModulesBuffers->copyFromSrc(queue, *srcData.modulesBuffers); + auto deviceEndcapGeometryBuffers = + std::make_shared>>(alpaka::getDev(queue), srcData.nEndCapMap); + deviceEndcapGeometryBuffers->copyFromSrc(queue, *srcData.endcapGeometryBuffers); + + return SDL::LSTESData>(srcData.nModules, + srcData.nLowerModules, + srcData.nPixels, + srcData.nEndCapMap, + deviceModulesBuffers, + deviceEndcapGeometryBuffers, + srcData.pixelMapping); } }; } // namespace cms::alpakatools diff --git a/RecoTracker/LSTCore/interface/alpaka/Module.h b/RecoTracker/LSTCore/interface/alpaka/Module.h index 145aca7604bd7..323b74fa146dd 100644 --- a/RecoTracker/LSTCore/interface/alpaka/Module.h +++ b/RecoTracker/LSTCore/interface/alpaka/Module.h @@ -1,5 +1,5 @@ -#ifndef Module_cuh -#define Module_cuh +#ifndef RecoTracker_LSTCore_interface_alpaka_Module_h +#define RecoTracker_LSTCore_interface_alpaka_Module_h #include @@ -355,8 +355,8 @@ namespace SDL { alpaka::wait(queue); } - template - modulesBuffer(TQueue queue, const modulesBuffer& src, unsigned int nMod, unsigned int nPixs) + template + modulesBuffer(TQueue queue, const modulesBuffer& src, unsigned int nMod, unsigned int nPixs) : modulesBuffer(alpaka::getDev(queue), nMod, nPixs) { copyFromSrc(queue, src); } diff --git a/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.dev.cc b/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.dev.cc index 2b5be62ec94bc..6e185abda5973 100644 --- a/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.dev.cc +++ b/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.dev.cc @@ -1,16 +1,8 @@ #include "EndcapGeometry.h" -SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, - SDL::QueueAcc& queue, - SDL::EndcapGeometryHost const& endcapGeometryIn) - : geoMapDetId_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())), - geoMapPhi_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())) { - dxdy_slope_ = endcapGeometryIn.dxdy_slope_; - centroid_phis_ = endcapGeometryIn.centroid_phis_; - fillGeoMapArraysExplicit(queue); -} +SDL::EndcapGeometry::EndcapGeometry(std::string filename) { load(filename); } -void SDL::EndcapGeometryHost::load(std::string filename) { +void SDL::EndcapGeometry::load(std::string filename) { dxdy_slope_.clear(); centroid_phis_.clear(); @@ -38,35 +30,22 @@ void SDL::EndcapGeometryHost::load(std::string filename) { } } } -} -void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) { - unsigned int phi_size = centroid_phis_.size(); + fillGeoMapArraysExplicit(); +} - // Allocate buffers on host - SDL::DevHost const& devHost = cms::alpakatools::host(); - auto mapPhi_host_buf = allocBufWrapper(devHost, phi_size); - auto mapDetId_host_buf = allocBufWrapper(devHost, phi_size); +void SDL::EndcapGeometry::fillGeoMapArraysExplicit() { + nEndCapMap = centroid_phis_.size(); - // Access the raw pointers of the buffers - float* mapPhi = alpaka::getPtrNative(mapPhi_host_buf); - unsigned int* mapDetId = alpaka::getPtrNative(mapDetId_host_buf); + geoMapDetId_buf.reserve(nEndCapMap); + geoMapPhi_buf.reserve(nEndCapMap); - unsigned int counter = 0; for (auto it = centroid_phis_.begin(); it != centroid_phis_.end(); ++it) { unsigned int detId = it->first; float Phi = it->second; - mapPhi[counter] = Phi; - mapDetId[counter] = detId; - counter++; + geoMapPhi_buf.push_back(Phi); + geoMapDetId_buf.push_back(detId); } - - nEndCapMap = counter; - - // Copy data from host to device buffers - alpaka::memcpy(queue, geoMapPhi_buf, mapPhi_host_buf); - alpaka::memcpy(queue, geoMapDetId_buf, mapDetId_host_buf); - alpaka::wait(queue); } float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { @@ -76,10 +55,3 @@ float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { return 0; } } -float SDL::EndcapGeometryHost::getdxdy_slope(unsigned int detid) const { - if (dxdy_slope_.find(detid) != dxdy_slope_.end()) { - return dxdy_slope_.at(detid); - } else { - return 0; - } -} diff --git a/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.h b/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.h index 8b343a70a9be8..56b51aa8cb194 100644 --- a/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.h +++ b/RecoTracker/LSTCore/src/alpaka/EndcapGeometry.h @@ -11,47 +11,27 @@ #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" -#include "HeterogeneousCore/AlpakaInterface/interface/host.h" - namespace SDL { - - // FIXME: Need to separate this better into host and device classes - // This is only needed for host, but we template it to avoid symbol conflicts - template - class EndcapGeometryHost; - - template <> - class EndcapGeometryHost { - public: - std::map dxdy_slope_; // dx/dy slope - std::map centroid_phis_; // centroid phi - - EndcapGeometryHost() = default; - ~EndcapGeometryHost() = default; - - void load(std::string); - float getdxdy_slope(unsigned int detid) const; - }; - - template + template class EndcapGeometry; - template <> - class EndcapGeometry { + class EndcapGeometry { private: std::map dxdy_slope_; // dx/dy slope std::map centroid_phis_; // centroid phi public: - Buf geoMapDetId_buf; - Buf geoMapPhi_buf; + std::vector geoMapDetId_buf; + std::vector geoMapPhi_buf; unsigned int nEndCapMap; - EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometryHost const& endcapGeometryIn); + EndcapGeometry() = default; + EndcapGeometry(std::string filename); ~EndcapGeometry() = default; - void fillGeoMapArraysExplicit(QueueAcc& queue); + void load(std::string); + void fillGeoMapArraysExplicit(); float getdxdy_slope(unsigned int detid) const; }; } // namespace SDL diff --git a/RecoTracker/LSTCore/src/alpaka/Event.dev.cc b/RecoTracker/LSTCore/src/alpaka/Event.dev.cc index 18f86217f9e72..70d2ae8d69ed1 100644 --- a/RecoTracker/LSTCore/src/alpaka/Event.dev.cc +++ b/RecoTracker/LSTCore/src/alpaka/Event.dev.cc @@ -191,9 +191,9 @@ void SDL::Event::addHitToEvent(std::vector x, Endcap, TwoS, nModules_, - endcapGeometry_->nEndCapMap, - alpaka::getPtrNative(endcapGeometry_->geoMapDetId_buf), - alpaka::getPtrNative(endcapGeometry_->geoMapPhi_buf), + nEndCapMap_, + alpaka::getPtrNative(endcapGeometryBuffers_->geoMapDetId_buf), + alpaka::getPtrNative(endcapGeometryBuffers_->geoMapPhi_buf), *modulesBuffers_->data(), *hitsInGPU, nHits)); diff --git a/RecoTracker/LSTCore/src/alpaka/Event.h b/RecoTracker/LSTCore/src/alpaka/Event.h index 11f1fe6c68898..53cb824fb729a 100644 --- a/RecoTracker/LSTCore/src/alpaka/Event.h +++ b/RecoTracker/LSTCore/src/alpaka/Event.h @@ -84,23 +84,25 @@ namespace SDL { const uint16_t nModules_; const uint16_t nLowerModules_; const unsigned int nPixels_; + const unsigned int nEndCapMap_; const std::shared_ptr> modulesBuffers_; const std::shared_ptr pixelMapping_; - const std::shared_ptr> endcapGeometry_; + const std::shared_ptr> endcapGeometryBuffers_; public: // Constructor used for CMSSW integration. Uses an external queue. template - Event(bool verbose, TQueue const& q, const LSTESDeviceData* deviceESData) + Event(bool verbose, TQueue const& q, const LSTESData* deviceESData) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), nModules_(deviceESData->nModules), nLowerModules_(deviceESData->nLowerModules), nPixels_(deviceESData->nPixels), + nEndCapMap_(deviceESData->nEndCapMap), modulesBuffers_(deviceESData->modulesBuffers), pixelMapping_(deviceESData->pixelMapping), - endcapGeometry_(deviceESData->endcapGeometry) { + endcapGeometryBuffers_(deviceESData->endcapGeometryBuffers) { init(verbose); } void resetEvent(); diff --git a/RecoTracker/LSTCore/src/alpaka/LST.dev.cc b/RecoTracker/LSTCore/src/alpaka/LST.dev.cc index 0c6cf5cc0e961..f216352637051 100644 --- a/RecoTracker/LSTCore/src/alpaka/LST.dev.cc +++ b/RecoTracker/LSTCore/src/alpaka/LST.dev.cc @@ -7,7 +7,7 @@ using XYZVector = ROOT::Math::XYZVector; void SDL::LST::run(SDL::QueueAcc& queue, bool verbose, - const LSTESDeviceData* deviceESData, + const LSTESData* deviceESData, const std::vector see_px, const std::vector see_py, const std::vector see_pz, diff --git a/RecoTracker/LSTCore/src/alpaka/LSTESData.dev.cc b/RecoTracker/LSTCore/src/alpaka/LSTESData.dev.cc index 4bbcf27de877e..6b635673837ae 100644 --- a/RecoTracker/LSTCore/src/alpaka/LSTESData.dev.cc +++ b/RecoTracker/LSTCore/src/alpaka/LSTESData.dev.cc @@ -40,7 +40,7 @@ namespace { } void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, - std::shared_ptr> endcapGeometry, + std::shared_ptr> endcapGeometry, std::shared_ptr> tiltedGeometry, std::shared_ptr> moduleConnectionMap) { // Module orientation information (DrDz or phi angles) @@ -77,30 +77,29 @@ namespace { } } // namespace -std::unique_ptr> SDL::loadAndFillESHost() { +std::unique_ptr> SDL::loadAndFillESHost() { + uint16_t nModules; + uint16_t nLowerModules; + unsigned int nPixels; + std::shared_ptr> modulesBuffers = nullptr; auto pLStoLayer = std::make_shared(); - auto endcapGeometry = std::make_shared>(); + auto endcapGeometry = std::make_shared>(); auto tiltedGeometry = std::make_shared>(); + auto pixelMapping = std::make_shared(); auto moduleConnectionMap = std::make_shared>(); ::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); - return std::make_unique>(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); -} -std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, - const LSTESHostData* hostData) { - SDL::Dev const& devAccIn = alpaka::getDev(queue); - uint16_t nModules; - uint16_t nLowerModules; - unsigned int nPixels; - std::shared_ptr> modulesBuffers = nullptr; - auto endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); - auto pixelMapping = std::make_shared(); - auto moduleConnectionMap = hostData->moduleConnectionMap; + auto endcapGeometryBuffers = + std::make_shared>(cms::alpakatools::host(), endcapGeometry->nEndCapMap); + alpaka::QueueCpuBlocking queue(cms::alpakatools::host()); + alpaka::memcpy( + queue, endcapGeometryBuffers->geoMapDetId_buf, endcapGeometry->geoMapDetId_buf, endcapGeometry->nEndCapMap); + alpaka::memcpy( + queue, endcapGeometryBuffers->geoMapPhi_buf, endcapGeometry->geoMapPhi_buf, endcapGeometry->nEndCapMap); auto path = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); - SDL::loadModulesFromFile(queue, - hostData->mapPLStoLayer.get(), + SDL::loadModulesFromFile(pLStoLayer.get(), path.c_str(), nModules, nLowerModules, @@ -108,8 +107,8 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu modulesBuffers, pixelMapping.get(), endcapGeometry.get(), - hostData->tiltedGeometry.get(), + tiltedGeometry.get(), moduleConnectionMap.get()); - return std::make_unique>( - nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping); + return std::make_unique>( + nModules, nLowerModules, nPixels, endcapGeometry->nEndCapMap, modulesBuffers, endcapGeometryBuffers, pixelMapping); } diff --git a/RecoTracker/LSTCore/src/alpaka/ModuleMethods.h b/RecoTracker/LSTCore/src/alpaka/ModuleMethods.h index d3d2fb1ae7fd7..5d8b40bf3dda2 100644 --- a/RecoTracker/LSTCore/src/alpaka/ModuleMethods.h +++ b/RecoTracker/LSTCore/src/alpaka/ModuleMethods.h @@ -25,7 +25,7 @@ namespace SDL { }; template - inline void fillPixelMap(std::shared_ptr>& modulesBuf, + inline void fillPixelMap(std::shared_ptr>& modulesBuf, uint16_t nModules, unsigned int& nPixels, pixelMap& pixelMapping, @@ -83,12 +83,11 @@ namespace SDL { nPixels = connectedPix_size; // Now we can initialize modulesBuf + DevHost const& devHost = cms::alpakatools::host(); if (modulesBuf == nullptr) { - SDL::Dev const& devAcc = alpaka::getDev(queue); - modulesBuf = std::make_shared>(devAcc, nModules, nPixels); + modulesBuf = std::make_shared>(devHost, nModules, nPixels); } - DevHost const& devHost = cms::alpakatools::host(); auto connectedPixels_buf = allocBufWrapper(devHost, connectedPix_size); unsigned int* connectedPixels = alpaka::getPtrNative(connectedPixels_buf); @@ -220,18 +219,16 @@ namespace SDL { nModules = counter; }; - template - void loadModulesFromFile(TQueue& queue, - const MapPLStoLayer* pLStoLayer, - const char* moduleMetaDataFilePath, - uint16_t& nModules, - uint16_t& nLowerModules, - unsigned int& nPixels, - std::shared_ptr>& modulesBuf, - pixelMap* pixelMapping, - const EndcapGeometry* endcapGeometry, - const TiltedGeometry* tiltedGeometry, - const ModuleConnectionMap* moduleConnectionMap) { + inline void loadModulesFromFile(const MapPLStoLayer* pLStoLayer, + const char* moduleMetaDataFilePath, + uint16_t& nModules, + uint16_t& nLowerModules, + unsigned int& nPixels, + std::shared_ptr>& modulesBuf, + pixelMap* pixelMapping, + const EndcapGeometry* endcapGeometry, + const TiltedGeometry* tiltedGeometry, + const ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); @@ -376,6 +373,9 @@ namespace SDL { } } + // TODO: We don't need a queue, but this code needs to be refactored + alpaka::QueueCpuBlocking queue(cms::alpakatools::host()); + // modulesBuf is initialized in fillPixelMap since both nModules and nPix will be known fillPixelMap(modulesBuf, nModules, nPixels, *pixelMapping, queue, *pLStoLayer, mmd); diff --git a/RecoTracker/LSTCore/standalone/bin/sdl.cc b/RecoTracker/LSTCore/standalone/bin/sdl.cc index ce1b0f12461ed..b6bba324801dd 100644 --- a/RecoTracker/LSTCore/standalone/bin/sdl.cc +++ b/RecoTracker/LSTCore/standalone/bin/sdl.cc @@ -306,7 +306,8 @@ void run_sdl() { TStopwatch full_timer; full_timer.Start(); auto hostESData = SDL::loadAndFillESHost(); - auto deviceESData = SDL::loadAndFillESDevice(queues[0], hostESData.get()); + auto deviceESData = + cms::alpakatools::CopyToDevice>::copyAsync(queues[0], *hostESData.get()); float timeForMapLoading = full_timer.RealTime() * 1000; if (ana.do_write_ntuple) { @@ -384,7 +385,7 @@ void run_sdl() { full_timer.Start(); std::vector *> events; for (int s = 0; s < ana.streams; s++) { - SDL::Event *event = new SDL::Event(ana.verbose >= 2, queues[s], deviceESData.get()); + SDL::Event *event = new SDL::Event(ana.verbose >= 2, queues[s], &deviceESData); events.push_back(event); } float timeForEventCreation = full_timer.RealTime() * 1000;