在文章(2)中,介绍了ConstantOp类的构造函数。构造函数中唯一的一个参数是OpKernelConstruction类型的对象。这个对象包含了操作类需要的所有输入,参数以及运行环境。它定义在tensorflow/core/framework/op_kernel.h文件中。OpKernelConstruction类的成员函数比较多,无法在一篇文章中一一列举。本文先从它的构造函数入手,分析它的成员变量。
OpKernelConstruction类的构造函数定义在tensorflow/core/framework/op_kernel.cc文件中。
OpKernelConstruction::OpKernelConstruction(
DeviceType device_type, DeviceBase* device, Allocator* allocator,
const NodeDef* node_def, const OpDef* op_def, FunctionLibraryRuntime* flib,
const DataTypeSlice& input_types, const MemoryTypeSlice& input_memory_types,
const DataTypeSlice& output_types,
const MemoryTypeSlice& output_memory_types, int graph_def_version,
Status* status)
: device_type_(std::move(device_type)),
device_(device),
allocator_(allocator),
def_(node_def),
op_def_(op_def),
flib_(flib),
input_types_(input_types