Ai
1 Star 0 Fork 1

周司南/pytorch-github

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
perf_observer.h 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
#pragma once
#include "caffe2/core/common.h"
#include "caffe2/core/net.h"
#include "caffe2/core/observer.h"
#include "caffe2/core/timer.h"
#include "observers/macros.h"
#include <unordered_map>
namespace caffe2 {
double getClockTimeMilliseconds();
class CAFFE2_OBSERVER_API PerfNetObserver : public NetObserver {
public:
explicit PerfNetObserver(NetBase* subject_);
virtual ~PerfNetObserver();
private:
void Start() override;
void Stop() override;
caffe2::string getObserverName(const OperatorBase* op, int idx) const;
private:
enum LogType {
NONE,
OPERATOR_DELAY,
NET_DELAY,
};
LogType logType_;
unsigned int numRuns_;
std::unordered_map<const OperatorBase*, const ObserverBase<OperatorBase>*>
observerMap_;
double wallMilliseconds_;
double cpuMilliseconds_;
};
class PerfOperatorObserver : public ObserverBase<OperatorBase> {
public:
PerfOperatorObserver(OperatorBase* op, PerfNetObserver* netObserver);
virtual ~PerfOperatorObserver();
double getWallMilliseconds() const;
double getCpuMilliseconds() const;
std::vector<TensorShape> getTensorShapes() const;
private:
void Start() override;
void Stop() override;
private:
// Observer of a net that owns corresponding op. We make sure net is never
// destructed while operator observer is still alive. First operator observer
// gets destructed, then the op, then the net and its observer.
// We do this trick in order to get access to net's name and other fields
// without storing inside the operator observer. Each field is memory
// costly here and a raw pointer is a cheapest sholution
PerfNetObserver* netObserver_;
double wallMilliseconds_;
double cpuMilliseconds_;
std::vector<TensorShape> tensor_shapes_;
};
} // namespace caffe2
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou_sinan/pytorch-github.git
git@gitee.com:zhou_sinan/pytorch-github.git
zhou_sinan
pytorch-github
pytorch-github
master

搜索帮助