Skip to content

Commit

Permalink
more code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kpedro88 committed Mar 11, 2020
1 parent f03f117 commit c67d250
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 71 deletions.
2 changes: 0 additions & 2 deletions HeterogeneousCore/SonicCore/interface/SonicClientAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
template <typename InputT, typename OutputT = InputT>
class SonicClientAsync : public SonicClientBase, public SonicClientTypes<InputT, OutputT> {
public:
virtual ~SonicClientAsync() {}

//main operation
void dispatch(edm::WaitingTaskWithArenaHolder holder) override final {
holder_ = std::move(holder);
Expand Down
5 changes: 2 additions & 3 deletions HeterogeneousCore/SonicCore/interface/SonicClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SonicClientBase {
virtual ~SonicClientBase() = default;

void setDebugName(const std::string& debugName) { debugName_ = debugName; }
const std::string& debugName() const { return debugName_; }

//main operation
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder) = 0;
Expand All @@ -25,11 +26,10 @@ class SonicClientBase {
if (debugName_.empty())
return;
t0_ = std::chrono::high_resolution_clock::now();
setTime_ = true;
}

void finish(std::exception_ptr eptr = std::exception_ptr{}) {
if (setTime_) {
if (!debugName_.empty()) {
auto t1 = std::chrono::high_resolution_clock::now();
edm::LogInfo(debugName_) << "Client time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0_).count();
Expand All @@ -43,7 +43,6 @@ class SonicClientBase {
//for logging/debugging
std::string debugName_;
std::chrono::time_point<std::chrono::high_resolution_clock> t0_;
bool setTime_ = false;
};

#endif
16 changes: 8 additions & 8 deletions HeterogeneousCore/SonicCore/interface/SonicClientPseudoAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class SonicClientPseudoAsync : public SonicClientBase, public SonicClientTypes<I
thread_ = std::make_unique<std::thread>([this]() { waitForNext(); });
}
//destructor
virtual ~SonicClientPseudoAsync() {
{
std::lock_guard<std::mutex> guard(mutex_);
stop_ = true;
}
~SonicClientPseudoAsync() override {
stop_ = true;
cond_.notify_one();
if (thread_) {
thread_->join();
thread_.reset();
try {
thread_->join();
thread_.reset();
} catch (...) {
}
}
}
//accessor
Expand All @@ -46,7 +46,7 @@ class SonicClientPseudoAsync : public SonicClientBase, public SonicClientTypes<I
cond_.notify_one();
}

protected:
private:
void waitForNext() {
while (true) {
//wait for condition
Expand Down
2 changes: 0 additions & 2 deletions HeterogeneousCore/SonicCore/interface/SonicClientSync.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
template <typename InputT, typename OutputT = InputT>
class SonicClientSync : public SonicClientBase, public SonicClientTypes<InputT, OutputT> {
public:
virtual ~SonicClientSync() {}

//main operation
void dispatch(edm::WaitingTaskWithArenaHolder holder) override final {
holder_ = std::move(holder);
Expand Down
2 changes: 0 additions & 2 deletions HeterogeneousCore/SonicCore/interface/SonicClientTypes.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef HeterogeneousCore_SonicCore_SonicClientTypes
#define HeterogeneousCore_SonicCore_SonicClientTypes

#include "FWCore/ParameterSet/interface/ParameterSet.h"

//this base class exists to limit the impact of dependent scope in derived classes
template <typename InputT, typename OutputT = InputT>
class SonicClientTypes {
Expand Down
12 changes: 4 additions & 8 deletions HeterogeneousCore/SonicCore/interface/SonicEDProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi
auto t0 = std::chrono::high_resolution_clock::now();
acquire(iEvent, iSetup, client_.input());
auto t1 = std::chrono::high_resolution_clock::now();
if (!debugName_.empty())
edm::LogInfo(debugName_) << "Load time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
if (!client_.debugName().empty())
edm::LogInfo(client_.debugName()) << "Load time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
client_.dispatch(holder);
}
virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
Expand All @@ -47,13 +47,9 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi

protected:
//for debugging
void setDebugName(const std::string& debugName) {
debugName_ = debugName;
client_.setDebugName(debugName);
}
void setDebugName(const std::string& debugName) { client_.setDebugName(debugName); }
//members
Client client_;
std::string debugName_;
};

#endif
5 changes: 1 addition & 4 deletions HeterogeneousCore/SonicCore/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<environment>
<bin file="TestIntegration.cpp" name="TestIntegrationSonic">
<flags TEST_RUNNER_ARGS=" /bin/bash HeterogeneousCore/SonicCore/test run_sonic_test.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<test name="TestHeterogeneousCoreSonicCore" command="cmsRun ${LOCALTOP}/src/HeterogeneousCore/SonicCore/test/sonicTest_cfg.py"/>
<library file="SonicDummyProducer.cc">
<flags EDM_PLUGIN="1"/>
<use name="HeterogeneousCore/SonicCore"/>
Expand Down
35 changes: 12 additions & 23 deletions HeterogeneousCore/SonicCore/test/SonicDummyProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <memory>

namespace edmtest {
namespace sonictest {
template <typename Client>
class SonicDummyProducer : public SonicEDProducer<Client> {
public:
Expand All @@ -15,50 +15,39 @@ namespace edmtest {
using typename SonicEDProducer<Client>::Output;
explicit SonicDummyProducer(edm::ParameterSet const& cfg)
: SonicEDProducer<Client>(cfg), input_(cfg.getParameter<int>("input")) {
this->template produces<IntProduct>();
//for debugging
this->setDebugName("SonicDummyProducer");
putToken_ = this->template produces<edmtest::IntProduct>();
}

void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) override { iInput = input_; }

void produce(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) override {
iEvent.put(std::make_unique<IntProduct>(iOutput));
iEvent.emplace(putToken_, iOutput);
}

//to ensure distinct cfi names - specialized below
static std::string getCfiName();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
Client::fillPSetDescription(desc);
desc.add<int>("input");
descriptions.add(getCfiName(), desc);
//to ensure distinct cfi names
descriptions.addWithDefaultLabel(desc);
}

private:
//members
int input_;
edm::EDPutTokenT<edmtest::IntProduct> putToken_;
};

typedef SonicDummyProducer<DummyClientSync> SonicDummyProducerSync;
typedef SonicDummyProducer<DummyClientPseudoAsync> SonicDummyProducerPseudoAsync;
typedef SonicDummyProducer<DummyClientAsync> SonicDummyProducerAsync;
} // namespace sonictest

template <>
std::string SonicDummyProducerSync::getCfiName() {
return "SonicDummyProducerSync";
}
template <>
std::string SonicDummyProducerPseudoAsync::getCfiName() {
return "SonicDummyProducerPseudoAsync";
}
template <>
std::string SonicDummyProducerAsync::getCfiName() {
return "SonicDummyProducerAsync";
}
} // namespace edmtest

using edmtest::SonicDummyProducerSync;
using sonictest::SonicDummyProducerSync;
DEFINE_FWK_MODULE(SonicDummyProducerSync);
using edmtest::SonicDummyProducerPseudoAsync;
using sonictest::SonicDummyProducerPseudoAsync;
DEFINE_FWK_MODULE(SonicDummyProducerPseudoAsync);
using edmtest::SonicDummyProducerAsync;
using sonictest::SonicDummyProducerAsync;
DEFINE_FWK_MODULE(SonicDummyProducerAsync);
3 changes: 0 additions & 3 deletions HeterogeneousCore/SonicCore/test/TestIntegration.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions HeterogeneousCore/SonicCore/test/run_sonic_test.sh

This file was deleted.

8 changes: 3 additions & 5 deletions HeterogeneousCore/SonicCore/test/sonicTest_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

process.source = cms.Source("EmptySource")

process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))
process.maxEvents.input = 1

process.options = cms.untracked.PSet(
numberOfThreads = cms.untracked.uint32(2),
numberOfStreams = cms.untracked.uint32(0)
)
process.options.numberOfThreads = 2
process.options.numberOfStreams = 0

process.dummySync = cms.EDProducer("SonicDummyProducerSync",
input = cms.int32(1),
Expand Down

0 comments on commit c67d250

Please sign in to comment.