Caffe2 - C++ API
A deep learning, cross platform ML framework
half_float_ops.cc
1 #include "caffe2/operators/half_float_ops.h"
2 
3 namespace caffe2 {
4 OPERATOR_SCHEMA(FloatToHalf)
5  .NumInputs(1)
6  .NumOutputs(1)
7  .TensorInferenceFunction(
8  [](const OperatorDef& def, const vector<TensorShape>& in) {
9  vector<TensorShape> out;
10  const TensorShape& X = in[0];
11  out.push_back(X);
12  out[0].set_data_type(TensorProto_DataType_FLOAT16);
13 
14  return out;
15  });
16 
17 OPERATOR_SCHEMA(HalfToFloat)
18  .NumInputs(1)
19  .NumOutputs(1)
20  .TensorInferenceFunction(
21  [](const OperatorDef& def, const vector<TensorShape>& in) {
22  vector<TensorShape> out;
23  const TensorShape& X = in[0];
24  out.push_back(X);
25  out[0].set_data_type(TensorProto_DataType_FLOAT);
26 
27  return out;
28  });
29 OPERATOR_SCHEMA(Float16ConstantFill)
30  .NumInputs(0)
31  .NumOutputs(1)
32  .TensorInferenceFunction(Float16FillerTensorInference)
33  .Arg("value", "The value for the elements of the output tensor.")
34  .Arg("shape", "The shape of the output tensor.")
35  .Output(
36  0,
37  "output",
38  "Output tensor of constant values specified by 'value'");
39 
41  using GradientMakerBase::GradientMakerBase;
42  vector<OperatorDef> GetGradientDefs() override {
43  return SingleGradientDef(
44  "HalfToFloat", "", vector<string>{GO(0)}, vector<string>{GI(0)});
45  }
46 };
47 REGISTER_GRADIENT(FloatToHalf, GetFloatToHalfGradient);
48 
50  using GradientMakerBase::GradientMakerBase;
51  vector<OperatorDef> GetGradientDefs() override {
52  return SingleGradientDef(
53  "FloatToHalf", "", vector<string>{GO(0)}, vector<string>{GI(0)});
54  }
55 };
56 REGISTER_GRADIENT(HalfToFloat, GetHalfToFloatGradient);
57 NO_GRADIENT(Float16ConstantFill);
58 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...