Caffe2 - C++ API
A deep learning, cross platform ML framework
Activation.cpp
1 #include <ATen/native/Activation.h>
2 
3 #include <ATen/ATen.h>
4 #include <ATen/cpu/vec256/vec256.h>
5 #include <ATen/native/TensorIterator.h>
6 #include <ATen/native/cpu/Loops.h>
7 
8 namespace at { namespace native {
9 namespace {
10 
11 static void threshold_kernel(TensorIterator& iter, Scalar threshold_scalar, Scalar value_scalar) {
12  AT_DISPATCH_ALL_TYPES(iter.dtype(), "threshold_cpu", [&] {
13  using Vec = Vec256<scalar_t>;
14  scalar_t threshold = threshold_scalar.to<scalar_t>();
15  scalar_t value = value_scalar.to<scalar_t>();
16  binary_kernel_vec(
17  iter,
18  [&](scalar_t x, scalar_t other) -> scalar_t {
19  return x <= threshold ? value : other;
20  },
21  [&](Vec x, Vec other) -> Vec {
22  return Vec::blendv(other, Vec(value), x <= Vec(threshold));
23  });
24  });
25 }
26 
27 } // anonymous namespace
28 
29 REGISTER_DISPATCH(threshold_stub, &threshold_kernel);
30 
31 }} // namespace at::native
Flush-To-Zero and Denormals-Are-Zero mode.