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

Method Compile

tensorflow/compiler/tf2xla/kernels/topk_op.cc:33–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 }
32
33 void Compile(XlaOpKernelContext* context) override {
34 int64 k;
35 OP_REQUIRES_OK(context, context->ConstantInputAsIntScalar(1, &k));
36 OP_REQUIRES(context, k >= 0,
37 errors::InvalidArgument("Need k >= 0, got ", k));
38 const TensorShape input_shape = context->InputShape(0);
39 OP_REQUIRES(context, input_shape.dims() >= 1,
40 errors::InvalidArgument("input must be >= 1-D, got shape ",
41 input_shape.DebugString()));
42 int last_dim = input_shape.dims() - 1;
43 int last_dim_size = input_shape.dim_size(last_dim);
44 OP_REQUIRES(
45 context, last_dim_size >= k,
46 errors::InvalidArgument("input must have at least k columns. Had ",
47 last_dim_size, ", needed ", k));
48 if (last_dim_size < k) {
49 k = last_dim_size;
50 }
51 xla::XlaOp output_tuple = TopK(context->Input(0), k);
52 context->SetOutput(0, xla::GetTupleElement(output_tuple, 0));
53 context->SetOutput(1, xla::GetTupleElement(output_tuple, 1));
54 }
55
56 private:
57 bool sorted_;

Callers

nothing calls this directly

Calls 10

InvalidArgumentFunction · 0.85
InputShapeMethod · 0.80
TopKFunction · 0.50
GetTupleElementFunction · 0.50
dimsMethod · 0.45
DebugStringMethod · 0.45
dim_sizeMethod · 0.45
InputMethod · 0.45
SetOutputMethod · 0.45

Tested by

no test coverage detected