Caffe2 - C++ API
A deep learning, cross platform ML framework
create_scope_op.cc
1 
17 #include "caffe2/operators/create_scope_op.h"
18 
19 CAFFE2_DEFINE_bool(
20  caffe2_workspace_stack_debug,
21  false,
22  "Enable debug checks for CreateScope's workspace stack");
23 
24 namespace caffe2 {
25 CAFFE_KNOWN_TYPE(detail::WorkspaceStack);
26 
27 template <>
28 bool CreateScopeOp<CPUContext>::RunOnDevice() {
29  auto* ws_stack = OperatorBase::Output<detail::WorkspaceStack>(0);
30  ws_stack->clear();
31  return true;
32 }
33 
34 REGISTER_CPU_OPERATOR(CreateScope, CreateScopeOp<CPUContext>);
35 
36 SHOULD_NOT_DO_GRADIENT(CreateScope);
37 
38 OPERATOR_SCHEMA(CreateScope).NumInputs(0).NumOutputs(1).SetDoc(R"DOC(
39 'CreateScope' operator initializes and outputs empty scope that is used
40 by Do operator to store local blobs
41  )DOC");
42 
43 template <>
44 bool HasScopeOp<CPUContext>::RunOnDevice() {
45  const auto& ws_stack = OperatorBase::Input<detail::WorkspaceStack>(0);
46  auto* output = Output(0);
47  output->Resize(1);
48  bool* output_value = output->template mutable_data<bool>();
49  *output_value = !ws_stack.empty();
50  return true;
51 }
52 
53 REGISTER_CPU_OPERATOR(HasScope, HasScopeOp<CPUContext>);
54 
55 SHOULD_NOT_DO_GRADIENT(HasScope);
56 
57 OPERATOR_SCHEMA(HasScope).NumInputs(1).NumOutputs(1).SetDoc(R"DOC(
58 Checks whether scope blob has any saved scopes left
59  )DOC");
60 
61 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.