mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/67624 Test Plan: Visual inspection. Sandcastle. Reviewed By: malfet Differential Revision: D31986628 fbshipit-source-id: c872bded7325997a2945dbf5d4d052628dcb3659
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "caffe2/core/net.h"
|
|
#include "caffe2/core/observer.h"
|
|
#include "caffe2/core/operator.h"
|
|
#include "caffe2/observers/operator_attaching_net_observer.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
class RunCountNetObserver;
|
|
|
|
class TORCH_API RunCountOperatorObserver final
|
|
: public ObserverBase<OperatorBase> {
|
|
public:
|
|
explicit RunCountOperatorObserver(OperatorBase* op) = delete;
|
|
RunCountOperatorObserver(OperatorBase* op, RunCountNetObserver* netObserver);
|
|
~RunCountOperatorObserver() {}
|
|
std::unique_ptr<ObserverBase<OperatorBase>> rnnCopy(
|
|
OperatorBase* subject,
|
|
int rnn_order) const override;
|
|
|
|
private:
|
|
void Start() override;
|
|
void Stop() override;
|
|
|
|
private:
|
|
RunCountNetObserver* netObserver_;
|
|
};
|
|
|
|
class TORCH_API RunCountNetObserver final : public OperatorAttachingNetObserver<
|
|
RunCountOperatorObserver,
|
|
RunCountNetObserver> {
|
|
public:
|
|
explicit RunCountNetObserver(NetBase* subject_)
|
|
: OperatorAttachingNetObserver<
|
|
RunCountOperatorObserver,
|
|
RunCountNetObserver>(subject_, this),
|
|
cnt_(0) {}
|
|
~RunCountNetObserver() {}
|
|
|
|
std::string debugInfo() override;
|
|
|
|
friend class RunCountOperatorObserver;
|
|
|
|
private:
|
|
void Start() override;
|
|
void Stop() override;
|
|
|
|
protected:
|
|
std::atomic<int> cnt_;
|
|
};
|
|
|
|
} // namespace caffe2
|