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

Method Compile

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

Source from the content-addressed store, hash-verified

242 explicit ZerosLikeOp(OpKernelConstruction* ctx) : XlaOpKernel(ctx) {}
243
244 void Compile(XlaOpKernelContext* ctx) override {
245 if (IsTensorListInput(ctx, 0)) {
246 // Input is a TensorList.
247
248 // Check the TensorList input is initialized.
249 xla::XlaOp list = ctx->Input(0);
250 bool is_initialized;
251 OP_REQUIRES_OK(ctx, IsTensorListInitialized(list, &is_initialized));
252 OP_REQUIRES(
253 ctx, is_initialized,
254 errors::InvalidArgument(
255 "TensorList input for ZerosLike op is an uninitialized list"));
256
257 auto list_shape_or = ctx->builder()->GetShape(list);
258 OP_REQUIRES_OK(ctx, list_shape_or.status());
259 xla::XlaOp new_list;
260 OP_REQUIRES_OK(
261 ctx, CreateZerosTensorListWithShape(
262 ctx->builder(), list_shape_or.ValueOrDie(), &new_list));
263
264 xla::XlaOp push_index;
265 OP_REQUIRES_OK(ctx, GetTensorListPushIndex(list, &push_index));
266
267 xla::XlaOp result;
268 OP_REQUIRES_OK(ctx,
269 SetTensorListPushIndex(new_list, push_index, &result));
270 ctx->SetTensorListOutput(0, result);
271 } else {
272 const TensorShape input_shape = ctx->InputShape(0);
273
274 auto zero = XlaHelpers::Zero(ctx->builder(), input_type(0));
275 ctx->SetOutput(0, xla::Broadcast(zero, input_shape.dim_sizes()));
276 }
277 }
278};
279
280REGISTER_XLA_OP(Name("ZerosLike").AllowVariantTypes(), ZerosLikeOp);

Callers

nothing calls this directly

Calls 15

IsTensorListInputFunction · 0.85
IsTensorListInitializedFunction · 0.85
InvalidArgumentFunction · 0.85
GetTensorListPushIndexFunction · 0.85
SetTensorListPushIndexFunction · 0.85
BroadcastFunction · 0.85
SetTensorListOutputMethod · 0.80
InputShapeMethod · 0.80
ZeroFunction · 0.50
InputMethod · 0.45
GetShapeMethod · 0.45

Tested by

no test coverage detected