Caffe2 - C++ API
A deep learning, cross platform ML framework
copy_op.h
1 #ifndef CAFFE2_OPERATORS_COPY_OP_H_
2 #define CAFFE2_OPERATORS_COPY_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/operator.h"
6 
7 namespace caffe2 {
8 
9 template <class Context, class DstContext, class SrcContext>
10 class CopyOp : public Operator<Context> {
11  public:
12  USE_OPERATOR_CONTEXT_FUNCTIONS;
13  USE_SIMPLE_CTOR_DTOR(CopyOp)
14 
15  bool RunOnDevice() override {
16  auto& input = this->template Input<Tensor>(0, SrcContext::GetDeviceType());
17  auto* output =
18  this->template Output<Tensor>(0, DstContext::GetDeviceType());
19  output->ResizeLike(input);
20  this->context_.template CopyItems<SrcContext, DstContext>(
21  input.dtype(),
22  input.numel(),
23  input.raw_data(),
24  output->raw_mutable_data(input.dtype()));
25  return true;
26  }
27 };
28 
29 template <class Context, class DstContext, class SrcContext>
31  public:
32  template <class... Args>
33  explicit CopyOnDeviceLikeOp(Args&&... args)
34  : CopyOp<Context, DstContext, SrcContext>(std::forward<Args>(args)...) {}
35 };
36 
37 } // namespace caffe2
38 
39 #endif // CAFFE2_OPERATORS_COPY_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13