Caffe2 - C++ API
A deep learning, cross platform ML framework
sigmoid_cpu.cc
1 #include <ATen/core/dispatch/KernelRegistration.h>
2 #include "caffe2/operators/experimental/c10/schemas/sigmoid.h"
3 #include "caffe2/utils/eigen_utils.h"
4 #include "caffe2/utils/math.h"
5 #include "caffe2/core/tensor.h"
6 
7 using caffe2::Tensor;
8 
9 namespace caffe2 {
10 namespace {
11 template <class DataType>
12 void sigmoid_op_cpu_impl(
13  const at::Tensor& input_,
14  const at::Tensor& output_) {
15  Tensor input{C10Tensor(input_)};
16  Tensor output{C10Tensor(output_)};
17  output.ResizeLike(input);
18 
19  caffe2::ConstEigenVectorArrayMap<DataType> xM(
20  input.data<DataType>(), input.numel());
21  caffe2::EigenVectorArrayMap<DataType>(
22  output.mutable_data<DataType>(), input.numel()) =
23  1. / (1. + (-xM).exp());
24 }
25 } // namespace
26 } // namespace caffe2
27 
28 namespace c10 {
29 C10_REGISTER_KERNEL(caffe2::ops::Sigmoid)
30  .kernel<decltype(caffe2::sigmoid_op_cpu_impl<float>), &caffe2::sigmoid_op_cpu_impl<float>>()
31  .dispatchKey(CPUTensorId());
32 } // namespace c10
Tensor class holds a shared pointer to the implementation TensorImpl, redirects API calls to TensorIm...
Definition: tensor.h:25
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
Definition: alias_info.h:7