Skip to content

Commit

Permalink
Merge pull request #46876 from fwyzard/no_default_constructed_Portabl…
Browse files Browse the repository at this point in the history
…eCollections

Do not use default-constructed PortableCollections
  • Loading branch information
cmsbuild authored Dec 5, 2024
2 parents 530e534 + 6d13038 commit 567a8bc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
5 changes: 2 additions & 3 deletions DataFormats/VertexSoA/test/alpaka/ZVertexSoA_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ int main() {

// If the device is actually the host, use the collection as-is.
// Otherwise, copy the data from the device to the host.
ZVertexHost zvertex_h;
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
zvertex_h = std::move(zvertex_d);
ZVertexHost zvertex_h = std::move(zvertex_d);
#else
zvertex_h = cms::alpakatools::CopyToHost<ZVertexSoACollection>::copyAsync(queue, zvertex_d);
ZVertexHost zvertex_h = cms::alpakatools::CopyToHost<ZVertexSoACollection>::copyAsync(queue, zvertex_d);
#endif
alpaka::wait(queue);
std::cout << zvertex_h.view().metadata().size() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
event.emplace(digisF5HBToken_, std::move(df5_));

if (qie11Digis.empty()) {
event.emplace(digisF01HEToken_);
event.emplace(digisF3HBToken_);
event.emplace(digisF01HEToken_, 0, event.queue());
event.emplace(digisF3HBToken_, 0, event.queue());

} else {
auto size_f1 = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
hostProductMulti2_ = portabletest::TestHostMultiCollection2{deviceProductMulti2.sizes(), iEvent.queue()};
hostProductMulti3_ = portabletest::TestHostMultiCollection3{deviceProductMulti3.sizes(), iEvent.queue()};

alpaka::memcpy(iEvent.queue(), hostProduct_.buffer(), deviceProduct.const_buffer());
alpaka::memcpy(iEvent.queue(), hostProductMulti2_.buffer(), deviceProductMulti2.const_buffer());
alpaka::memcpy(iEvent.queue(), hostProductMulti3_.buffer(), deviceProductMulti3.const_buffer());
alpaka::memcpy(iEvent.queue(), hostProduct_->buffer(), deviceProduct.const_buffer());
alpaka::memcpy(iEvent.queue(), hostProductMulti2_->buffer(), deviceProductMulti2.const_buffer());
alpaka::memcpy(iEvent.queue(), hostProductMulti3_->buffer(), deviceProductMulti3.const_buffer());
}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
28 changes: 22 additions & 6 deletions HeterogeneousCore/AlpakaTest/plugins/alpaka/TestHelperClass.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef HeterogeneousCore_AlpakaTest_plugins_alpaka_TestHelperClass_h
#define HeterogeneousCore_AlpakaTest_plugins_alpaka_TestHelperClass_h

#include <optional>

#include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"
#include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceCollection.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
Expand All @@ -23,9 +25,23 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

void makeAsync(device::Event const& iEvent, device::EventSetup const& iSetup);

portabletest::TestHostCollection moveFrom() { return std::move(hostProduct_); }
portabletest::TestHostMultiCollection2 moveFromMulti2() { return std::move(hostProductMulti2_); }
portabletest::TestHostMultiCollection3 moveFromMulti3() { return std::move(hostProductMulti3_); }
portabletest::TestHostCollection moveFrom() {
auto product = std::move(*hostProduct_);
hostProduct_.reset();
return product;
}

portabletest::TestHostMultiCollection2 moveFromMulti2() {
auto product = std::move(*hostProductMulti2_);
hostProductMulti2_.reset();
return product;
}

portabletest::TestHostMultiCollection3 moveFromMulti3() {
auto product = std::move(*hostProductMulti3_);
hostProductMulti3_.reset();
return product;
}

private:
const device::EDGetToken<portabletest::TestDeviceCollection> getToken_;
Expand All @@ -35,9 +51,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const device::ESGetToken<AlpakaESTestDataCDevice, AlpakaESTestRecordC> esTokenDevice_;

// hold the output product between acquire() and produce()
portabletest::TestHostCollection hostProduct_;
portabletest::TestHostMultiCollection2 hostProductMulti2_;
portabletest::TestHostMultiCollection3 hostProductMulti3_;
std::optional<portabletest::TestHostCollection> hostProduct_;
std::optional<portabletest::TestHostMultiCollection2> hostProductMulti2_;
std::optional<portabletest::TestHostMultiCollection3> hostProductMulti3_;
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// C++ includes
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
Expand Down Expand Up @@ -43,16 +44,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> pixelDigiToken_;

device::EDPutToken<SiPixelDigisSoACollection> digiPutToken_;
device::EDPutToken<SiPixelClustersSoACollection> clusterPutToken_;

Algo Algo_;

const device::EDPutToken<SiPixelDigisSoACollection> digiPutToken_;
const device::EDPutToken<SiPixelClustersSoACollection> clusterPutToken_;
const SiPixelClusterThresholds clusterThresholds_;
uint32_t nDigis_ = 0;

SiPixelDigisSoACollection digis_d;
Algo algo_;
uint32_t nDigis_ = 0;
std::optional<SiPixelDigisSoACollection> digis_d_;
};

SiPixelPhase2DigiToCluster::SiPixelPhase2DigiToCluster(const edm::ParameterSet& iConfig)
Expand Down Expand Up @@ -87,59 +85,50 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

const TrackerGeometry* geom_ = &iSetup.getData(geomToken_);

uint32_t nDigis = 0;

nDigis_ = 0;
for (const auto& det : input) {
nDigis += det.size();
nDigis_ += det.size();
}
digis_d_ = SiPixelDigisSoACollection(nDigis_, iEvent.queue());

if (nDigis == 0)
if (nDigis_ == 0)
return;

nDigis_ = nDigis;
SiPixelDigisHost digis_h(nDigis_, iEvent.queue());

nDigis = 0;
uint32_t nDigis = 0;
for (const auto& det : input) {
unsigned int detid = det.detId();
DetId detIdObject(detid);
const GeomDetUnit* genericDet = geom_->idToDetUnit(detIdObject);
auto const gind = genericDet->index();
for (auto const& px : det) {
digis_h.view()[nDigis].moduleId() = uint16_t(gind);

digis_h.view()[nDigis].xx() = uint16_t(px.row());
digis_h.view()[nDigis].yy() = uint16_t(px.column());
digis_h.view()[nDigis].adc() = uint16_t(px.adc());

digis_h.view()[nDigis].clus() = 0;

digis_h.view()[nDigis].pdigi() = uint32_t(px.packedData());

digis_h.view()[nDigis].rawIdArr() = uint32_t(detid);

nDigis++;
++nDigis;
}
}
assert(nDigis == nDigis_);

digis_d = SiPixelDigisSoACollection(nDigis, iEvent.queue());
alpaka::memcpy(iEvent.queue(), digis_d.buffer(), digis_h.buffer());

Algo_.makePhase2ClustersAsync(iEvent.queue(), clusterThresholds_, digis_d.view(), nDigis_);
alpaka::memcpy(iEvent.queue(), digis_d_->buffer(), digis_h.buffer());
algo_.makePhase2ClustersAsync(iEvent.queue(), clusterThresholds_, digis_d_->view(), nDigis_);
}

void SiPixelPhase2DigiToCluster::produce(device::Event& iEvent, device::EventSetup const& iSetup) {
if (nDigis_ == 0) {
SiPixelClustersSoACollection clusters_d{pixelTopology::Phase2::numberOfModules, iEvent.queue()};
SiPixelDigisSoACollection digis_d_zero{nDigis_, iEvent.queue()};
iEvent.emplace(digiPutToken_, std::move(digis_d_zero));
iEvent.emplace(clusterPutToken_, std::move(clusters_d));
return;
iEvent.emplace(digiPutToken_, std::move(*digis_d_));
iEvent.emplace(clusterPutToken_, pixelTopology::Phase2::numberOfModules, iEvent.queue());
} else {
digis_d_->setNModules(algo_.nModules());
iEvent.emplace(digiPutToken_, std::move(*digis_d_));
iEvent.emplace(clusterPutToken_, algo_.getClusters());
}

digis_d.setNModules(Algo_.nModules());
iEvent.emplace(digiPutToken_, std::move(digis_d));
iEvent.emplace(clusterPutToken_, Algo_.getClusters());
digis_d_.reset();
}

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
Expand Down Expand Up @@ -262,10 +263,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// are no valid pointers to clusters' Collection columns, instantiation
// of TrackingRecHits fail. Example: workflow 11604.0

iEvent.emplace(digiPutToken_, nDigis_, iEvent.queue());
iEvent.emplace(digiPutToken_, 0, iEvent.queue());
iEvent.emplace(clusterPutToken_, pixelTopology::Phase1::numberOfModules, iEvent.queue());
if (includeErrors_) {
iEvent.emplace(digiErrorPutToken_);
iEvent.emplace(digiErrorPutToken_, 0, iEvent.queue());
iEvent.emplace(fmtErrorToken_);
}
return;
Expand Down

0 comments on commit 567a8bc

Please sign in to comment.