1 #pragma once
2 
3 #include <string>
4 #include <utility>
5 
6 #include "chainerx/context.h"
7 #include "chainerx/graph.h"
8 
9 namespace chainerx {
10 
11 class BackpropScope {
12 public:
13     explicit BackpropScope(std::string backprop_name, Context& context = GetDefaultContext())
14         : backprop_id_{context.MakeBackpropId(std::move(backprop_name))} {}
15 
16     BackpropScope(const BackpropScope&) = delete;
17     BackpropScope& operator=(const BackpropScope&) = delete;
18     BackpropScope& operator=(BackpropScope&&) = delete;
19     BackpropScope(BackpropScope&& other) = delete;
20 
~BackpropScope()21     ~BackpropScope() { backprop_id_.context().ReleaseBackpropIdNoExcept(backprop_id_); }
22 
backprop_id()23     BackpropId backprop_id() const { return backprop_id_; }
24 
25 private:
26     BackpropId backprop_id_;
27 };
28 
29 }  // namespace chainerx
30