3 #include "caffe2/core/operator.h" 4 #include "caffe2/utils/eigen_utils.h" 5 #include "caffe2/utils/math.h" 9 template <
class Context>
12 USE_OPERATOR_CONTEXT_FUNCTIONS;
15 bool RunOnDevice()
override {
17 this, this->
template Input<Tensor>(INDICES, CPU));
20 template <
typename Index>
21 bool DoRunWithType() {
22 const auto& data =
Input(DATA);
23 const auto& indices =
Input(INDICES);
25 CAFFE_ENFORCE_EQ(data.dim(), 2,
"DATA must be a matrix");
26 CAFFE_ENFORCE_EQ(indices.dim(), 1,
"INDICES must be a vector");
27 CAFFE_ENFORCE_GT(data.size(1), 8,
"DATA must have more than 8 columns");
30 const std::vector<int64_t> shape = {indices.size(0), data.size(1) - 8};
31 auto* output = Output(0, shape, at::dtype<float>());
33 int block_size = shape[1];
34 auto block_bytesize = data.size_from_dim(1) * data.dtype().itemsize();
35 int N = indices.numel();
37 const uint8_t* src_base = data.template data<uint8_t>();
38 const Index* idxs = indices.template data<Index>();
39 auto out = output->template mutable_data<float>();
41 for (
int i = 0; i < N; ++i) {
44 0 <= idx && idx < data.size(0),
45 "INDICES element is out of DATA bounds, id=",
49 const uint8_t* src = src_base + idx * block_bytesize;
50 ConstEigenVectorArrayMap<uint8_t> input_row_values(src, shape[1]);
51 ConstEigenVectorArrayMap<float> input_row_scale_bias(
52 reinterpret_cast<const float*>(src + shape[1]), 2);
54 EigenVectorArrayMap<float> output_row(out + i * shape[1], shape[1]);
56 output_row = input_row_values.cast<
float>() * input_row_scale_bias(0) +
57 input_row_scale_bias(1);
62 INPUT_TAGS(DATA, INDICES);
const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...