Caffe2 - C++ API
A deep learning, cross platform ML framework
create_scope_op.cc
1 #include "caffe2/operators/create_scope_op.h"
2 
3 C10_DEFINE_bool(
4  caffe2_workspace_stack_debug,
5  false,
6  "Enable debug checks for CreateScope's workspace stack");
7 
8 namespace caffe2 {
9 CAFFE_KNOWN_TYPE(detail::WorkspaceStack);
10 
11 template <>
12 bool CreateScopeOp<CPUContext>::RunOnDevice() {
13  auto* ws_stack = OperatorBase::Output<detail::WorkspaceStack>(0);
14  ws_stack->clear();
15  return true;
16 }
17 
18 REGISTER_CPU_OPERATOR(CreateScope, CreateScopeOp<CPUContext>);
19 
20 SHOULD_NOT_DO_GRADIENT(CreateScope);
21 
22 OPERATOR_SCHEMA(CreateScope).NumInputs(0).NumOutputs(1).SetDoc(R"DOC(
23 'CreateScope' operator initializes and outputs empty scope that is used
24 by Do operator to store local blobs
25  )DOC");
26 
27 template <>
28 bool HasScopeOp<CPUContext>::RunOnDevice() {
29  const auto& ws_stack = OperatorBase::Input<detail::WorkspaceStack>(0);
30 
31  auto* output = Output(0, {1}, at::dtype<bool>());
32  bool* output_value = output->template mutable_data<bool>();
33  *output_value = !ws_stack.empty();
34  return true;
35 }
36 
37 REGISTER_CPU_OPERATOR(HasScope, HasScopeOp<CPUContext>);
38 
39 SHOULD_NOT_DO_GRADIENT(HasScope);
40 
41 OPERATOR_SCHEMA(HasScope).NumInputs(1).NumOutputs(1).SetDoc(R"DOC(
42 Checks whether scope blob has any saved scopes left
43  )DOC");
44 
45 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13