-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
HeterogeneousCore/CUDATest/plugins/TestPortableAnalyzerCUDA.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <cassert> | ||
|
||
#include "CUDADataFormats/Common/interface/Product.h" | ||
#include "CUDADataFormats/PortableTestObjects/interface/TestHostCollection.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/stream/EDAnalyzer.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
#include "HeterogeneousCore/CUDACore/interface/ScopedContext.h" | ||
|
||
#include "TestAlgo.h" | ||
|
||
namespace { | ||
|
||
template <typename T> | ||
class Column { | ||
public: | ||
Column(T const* data, size_t size) : data_(data), size_(size) {} | ||
|
||
void print(std::ostream& out) const { | ||
std::stringstream buffer; | ||
buffer << "{ "; | ||
if (size_ > 0) { | ||
buffer << data_[0]; | ||
} | ||
if (size_ > 1) { | ||
buffer << ", " << data_[1]; | ||
} | ||
if (size_ > 2) { | ||
buffer << ", " << data_[2]; | ||
} | ||
if (size_ > 3) { | ||
buffer << ", ..."; | ||
} | ||
buffer << '}'; | ||
out << buffer.str(); | ||
} | ||
|
||
private: | ||
T const* const data_; | ||
size_t const size_; | ||
}; | ||
|
||
template <typename T> | ||
std::ostream& operator<<(std::ostream& out, Column<T> const& column) { | ||
column.print(out); | ||
return out; | ||
} | ||
} // namespace | ||
|
||
class TestPortableAnalyzerCUDA : public edm::stream::EDAnalyzer<> { | ||
public: | ||
TestPortableAnalyzerCUDA(edm::ParameterSet const& config) | ||
: source_{config.getParameter<edm::InputTag>("source")}, token_{consumes(source_)} {} | ||
|
||
void analyze(edm::Event const& event, edm::EventSetup const&) override { | ||
// create a context reusing the same device and queue as the producer of the input collection | ||
auto const& input = event.get(token_); | ||
cms::cuda::ScopedContextProduce ctx{input}; | ||
cudatest::TestDeviceCollection const& product = ctx.get(input); | ||
|
||
algo_.check(product, ctx.stream()); | ||
} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("source"); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
private: | ||
const edm::InputTag source_; | ||
const edm::EDGetTokenT<cms::cuda::Product<cudatest::TestDeviceCollection>> token_; | ||
|
||
// implementation of the algorithm | ||
cudatest::TestAlgo algo_; | ||
}; | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(TestPortableAnalyzerCUDA); |