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

Method Compile

tensorflow/compiler/tf2xla/kernels/reverse_op.cc:35–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 explicit ReverseOp(OpKernelConstruction* ctx) : XlaOpKernel(ctx) {}
34
35 void Compile(XlaOpKernelContext* ctx) override {
36 // r = tf.reverse(x, revdims)
37 const TensorShape x_shape = ctx->InputShape(0);
38 const TensorShape revd_shape = ctx->InputShape(1);
39 // Validate input sizes.
40 OP_REQUIRES(ctx, TensorShapeUtils::IsVector(revd_shape),
41 errors::InvalidArgument("axes must be a vector, not shape ",
42 revd_shape.DebugString()));
43 OP_REQUIRES(ctx, revd_shape.num_elements() == x_shape.dims(),
44 errors::InvalidArgument("axes ", revd_shape.DebugString(),
45 " must have same number of elements as"
46 " than input tensor has dimensions ",
47 x_shape.DebugString(), "."));
48 if (revd_shape.num_elements() == 0) {
49 ctx->SetOutput(0, ctx->Input(0));
50 return;
51 }
52 // XlaBuilder::Rev() requires concrete values for dimensions arg.
53 xla::Literal lax;
54 OP_REQUIRES_OK(ctx, ctx->ConstantInput(1, &lax));
55
56 std::vector<int64> dimensions;
57 for (int d = 0; d < x_shape.dims(); ++d) {
58 if (lax.Get<bool>({d})) {
59 dimensions.push_back(d);
60 }
61 }
62
63 ctx->SetOutput(0, xla::Rev(ctx->Input(0), dimensions));
64 }
65};
66
67REGISTER_XLA_OP(Name("Reverse").CompileTimeConstantInput("dims"), ReverseOp);

Callers

nothing calls this directly

Calls 10

InvalidArgumentFunction · 0.85
RevFunction · 0.85
InputShapeMethod · 0.80
ConstantInputMethod · 0.80
DebugStringMethod · 0.45
num_elementsMethod · 0.45
dimsMethod · 0.45
SetOutputMethod · 0.45
InputMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected