Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kokkos] Add functions for profiling hooks #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kokkos/Framework/PluginFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace edm {
}; // namespace impl

std::unique_ptr<Worker> create(std::string const& name, ProductRegistry& reg) {
return impl::getGlobalRegistry().get(name)->create(reg);
return impl::getGlobalRegistry().get(name)->create(reg, name);
}
} // namespace PluginFactory
} // namespace edm
6 changes: 3 additions & 3 deletions src/kokkos/Framework/PluginFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace edm {
public:
virtual ~MakerBase() = default;

virtual std::unique_ptr<Worker> create(ProductRegistry& reg) const = 0;
virtual std::unique_ptr<Worker> create(ProductRegistry& reg, const std::string& name) const = 0;
};

template <typename T>
class Maker : public MakerBase {
public:
virtual std::unique_ptr<Worker> create(ProductRegistry& reg) const override {
return std::make_unique<WorkerT<T>>(reg);
virtual std::unique_ptr<Worker> create(ProductRegistry& reg, const std::string& name) const override {
return std::make_unique<WorkerT<T>>(reg, name);
};
};

Expand Down
11 changes: 11 additions & 0 deletions src/kokkos/Framework/Profile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#include "Framework/Profile.h"
#include "Framework/Event.h"

void beginProduce(const std::string& name, const edm::Event& event) {}

void endProduce(const std::string& name, const edm::Event& event) {}

void beginAcquire(const std::string& name, const edm::Event& event) {}

void endAcquire(const std::string& name, const edm::Event& event) {}
25 changes: 25 additions & 0 deletions src/kokkos/Framework/Profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#ifndef Profile_h
#define Profile_h

#include <string>

// Functions that get called before and after the produce and acquire functions
// get called for each module.
// Intended to be a place to put profiling, instrumentation points, and/or task annotations.
//
// The 'name' parameter is the name of the module being called.

namespace edm {
class Event;
};

void beginProduce(const std::string& name, const edm::Event& event);

void endProduce(const std::string& name, const edm::Event& event);

void beginAcquire(const std::string& name, const edm::Event& event);

void endAcquire(const std::string& name, const edm::Event& event);

#endif
15 changes: 13 additions & 2 deletions src/kokkos/Framework/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Framework/WaitingTaskHolder.h"
#include "Framework/WaitingTaskList.h"
#include "Framework/WaitingTaskWithArenaHolder.h"
#include "Framework/Profile.h"

namespace edm {
class Event;
Expand All @@ -17,7 +18,7 @@ namespace edm {

class Worker {
public:
Worker() : prefetchRequested_{false} {}
Worker(const std::string& name) : name_(name), prefetchRequested_{false} {}
virtual ~Worker() = default;

// not thread safe
Expand All @@ -43,6 +44,7 @@ namespace edm {

protected:
virtual void doReset() = 0;
std::string name_;

private:
std::vector<Worker*> itemsToGet_;
Expand All @@ -52,7 +54,8 @@ namespace edm {
template <typename T>
class WorkerT : public Worker {
public:
explicit WorkerT(ProductRegistry& reg) : producer_(reg), workStarted_{false} {}
explicit WorkerT(ProductRegistry& reg, const std::string& name)
: Worker(name), producer_(reg), workStarted_{false} {}

void doWorkAsync(Event& event, EventSetup const& eventSetup, WaitingTaskHolder task) override {
waitingTasksWork_.add(task);
Expand All @@ -69,7 +72,9 @@ namespace edm {
std::exception_ptr exceptionPtr;
try {
//std::cout << "calling doProduce " << this << std::endl;
beginProduce(name_, event);
producer_.doProduce(event, eventSetup);
endProduce(name_, event);
} catch (...) {
exceptionPtr = std::current_exception();
}
Expand All @@ -87,7 +92,9 @@ namespace edm {
} else {
std::exception_ptr exceptionPtr;
try {
beginAcquire(name_, event);
producer_.doAcquire(event, eventSetup, runProduceHolder);
endAcquire(name_, event);
} catch (...) {
exceptionPtr = std::current_exception();
}
Expand All @@ -106,7 +113,9 @@ namespace edm {
tbb::task_group group;
{
WaitingTaskWithArenaHolder runProducerHolder{group, &waitTask};
beginAcquire(name_, event);
producer_.doAcquire(event, eventSetup, runProducerHolder);
endAcquire(name_, event);
}
do {
group.wait();
Expand All @@ -115,7 +124,9 @@ namespace edm {
std::rethrow_exception(*(waitTask.exceptionPtr()));
}
}
beginProduce(name_, event);
producer_.doProduce(event, eventSetup);
endProduce(name_, event);
}

void doEndJob() override { producer_.doEndJob(); }
Expand Down