CMS 3D CMS Logo

TestAlpakaHostDeviceCompare.cc
Go to the documentation of this file.
1 #include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"
12 
13 #include <fmt/format.h>
14 
16 public:
19  deviceToken_{consumes(iConfig.getUntrackedParameter<edm::InputTag>("srcDevice"))},
20  expectedXdiff_{iConfig.getUntrackedParameter<double>("expectedXdiff")} {}
21 
22  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
24  desc.addUntracked<edm::InputTag>("srcHost");
25  desc.addUntracked<edm::InputTag>("srcDevice");
26  desc.addUntracked<double>("expectedXdiff", 0.);
27  descriptions.addWithDefaultLabel(desc);
28  }
29 
30  template <typename T>
31  static void require(T const& host, T const& device, T const& expectedDiff, std::string_view name) {
32  T const diff = host - device;
33  if (diff != expectedDiff) {
34  throw cms::Exception("Assert") << "Comparison of " << name << " failed, expected difference " << expectedDiff
35  << " but got " << diff << ", host value " << host << " device value " << device;
36  }
37  }
38 
39  void analyze(edm::StreamID iStream, edm::Event const& iEvent, edm::EventSetup const& iSetup) const override {
40  auto const& hostData = iEvent.get(hostToken_);
41  auto const& deviceData = iEvent.get(deviceToken_);
42 
43  require(hostData->metadata().size(), deviceData->metadata().size(), 0, "metadata().size()");
44  auto const hostView = hostData.view();
45  auto const deviceView = deviceData.view();
46  for (int i = 0; i < hostData->metadata().size(); ++i) {
47  require(hostView[i].x(), deviceView[i].x(), expectedXdiff_, fmt::format("view[{}].x()", i));
48  }
49  }
50 
51 private:
54  double const expectedXdiff_;
55 };
56 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
string host
Definition: query.py:115
TestAlpakaHostDeviceCompare(edm::ParameterSet const &iConfig)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< portabletest::TestHostCollection > const hostToken_
edm::EDGetTokenT< portabletest::TestHostCollection > const deviceToken_
long double T
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void analyze(edm::StreamID iStream, edm::Event const &iEvent, edm::EventSetup const &iSetup) const override
static void require(T const &host, T const &device, T const &expectedDiff, std::string_view name)