summaryrefslogtreecommitdiff
path: root/caffe2/share
diff options
context:
space:
mode:
authorBram Wasti <bwasti@fb.com>2017-10-16 14:26:32 -0700
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>2017-10-16 14:32:56 -0700
commit7d16d320d532b2c61bbf33a6ac294b2aac2981f9 (patch)
treed9ac44a9816a403860ff266a853e6339b1f0b190 /caffe2/share
parent1735c5f6c7173722aad4a19b10899ced4afbee90 (diff)
downloadpytorch-7d16d320d532b2c61bbf33a6ac294b2aac2981f9.tar.gz
pytorch-7d16d320d532b2c61bbf33a6ac294b2aac2981f9.tar.bz2
pytorch-7d16d320d532b2c61bbf33a6ac294b2aac2981f9.zip
expose observers to python, add multiple observers per observable
Summary: observer framework can now be used in python + a small writeup of how to use it. this is D6035393 with a fix for ct-scan Reviewed By: salexspb Differential Revision: D6066380 fbshipit-source-id: 896c4c580d4387240b81ac2dbbc43db51d4bfeb9
Diffstat (limited to 'caffe2/share')
-rw-r--r--caffe2/share/contrib/observers/perf_observer.cc8
-rw-r--r--caffe2/share/contrib/observers/perf_observer.h5
2 files changed, 10 insertions, 3 deletions
diff --git a/caffe2/share/contrib/observers/perf_observer.cc b/caffe2/share/contrib/observers/perf_observer.cc
index 000883b3f7..ad8ce8388b 100644
--- a/caffe2/share/contrib/observers/perf_observer.cc
+++ b/caffe2/share/contrib/observers/perf_observer.cc
@@ -50,7 +50,8 @@ bool PerfNetObserver::Start() {
whenever we measure operator delay */
const auto& operators = subject_->GetOperators();
for (auto* op : operators) {
- op->SetObserver(caffe2::make_unique<PerfOperatorObserver>(op, this));
+ observerMap_[op] = op->AttachObserver(
+ caffe2::make_unique<PerfOperatorObserver>(op, this));
}
}
@@ -72,7 +73,7 @@ bool PerfNetObserver::Stop() {
for (int idx = 0; idx < operators.size(); ++idx) {
const auto* op = operators[idx];
auto name = getObserverName(op, idx);
- double delay = static_cast<const PerfOperatorObserver*>(op->GetObserver())
+ double delay = static_cast<const PerfOperatorObserver*>(observerMap_[op])
->getMilliseconds();
std::pair<std::string, double> name_delay_pair = {name, delay};
operator_delays.push_back(name_delay_pair);
@@ -82,8 +83,9 @@ bool PerfNetObserver::Stop() {
/* clear all operator delay after use so that we don't spent time
collecting the operator delay info in later runs */
for (auto* op : operators) {
- op->RemoveObserver();
+ op->DetachObserver(observerMap_[op]);
}
+ observerMap_.clear();
}
return true;
}
diff --git a/caffe2/share/contrib/observers/perf_observer.h b/caffe2/share/contrib/observers/perf_observer.h
index 7ac4ed21dd..770d5371e4 100644
--- a/caffe2/share/contrib/observers/perf_observer.h
+++ b/caffe2/share/contrib/observers/perf_observer.h
@@ -1,8 +1,11 @@
#pragma once
#include "caffe2/core/net.h"
+#include "caffe2/core/observer.h"
#include "caffe2/core/timer.h"
+#include <unordered_map>
+
namespace caffe2 {
class PerfNetObserver : public NetObserver {
@@ -28,6 +31,8 @@ class PerfNetObserver : public NetObserver {
};
LogType logType_;
unsigned int numRuns_;
+ std::unordered_map<const OperatorBase*, const ObserverBase<OperatorBase>*>
+ observerMap_;
caffe2::Timer timer_;
};