MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compile

Method Compile

tensorflow/compiler/tf2xla/kernels/shape_op.cc:110–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108 explicit SizeOp(OpKernelConstruction* ctx) : XlaOpKernel(ctx) {}
109
110 void Compile(XlaOpKernelContext* ctx) override {
111 const TensorShape input_shape = ctx->InputShape(0);
112 OP_REQUIRES(ctx,
113 FastBoundsCheck(input_shape.num_elements(),
114 std::numeric_limits<int32>::max()),
115 errors::InvalidArgument("Size does not work for tensors > "
116 "int32 max."));
117 Tensor size_constant(DT_INT32, TensorShape({}));
118 const int rank = input_shape.dims();
119 xla::XlaBuilder* builder = ctx->builder();
120 auto size = xla::One(builder, xla::U32);
121 for (int64 i = 0; i < rank; ++i) {
122 size = xla::Mul(
123 size, xla::ConvertElementType(xla::GetDimensionSize(ctx->Input(0), i),
124 xla::U32));
125 }
126 size = xla::ConvertElementType(size, ctx->output_xla_type(0));
127 ctx->SetOutput(0, size);
128 }
129};
130
131REGISTER_XLA_OP(Name("Size").CompilationOnly().IsMetadataOp(), SizeOp);

Callers

nothing calls this directly

Calls 15

FastBoundsCheckFunction · 0.85
InvalidArgumentFunction · 0.85
GetDimensionSizeFunction · 0.85
InputShapeMethod · 0.80
output_xla_typeMethod · 0.80
maxFunction · 0.50
TensorShapeClass · 0.50
OneFunction · 0.50
MulFunction · 0.50
ConvertElementTypeFunction · 0.50
num_elementsMethod · 0.45
dimsMethod · 0.45

Tested by

no test coverage detected