| 83 | |
| 84 | private: |
| 85 | void Compute(user_op::KernelComputeContext* ctx) const override { |
| 86 | const user_op::Tensor* in = ctx->Tensor4ArgNameAndIndex("in", 0); |
| 87 | if (in->shape_view().elem_cnt() == 0) { return; } |
| 88 | user_op::Tensor* out = ctx->Tensor4ArgNameAndIndex("out", 0); |
| 89 | user_op::Tensor* tmp_buffer = ctx->Tensor4ArgNameAndIndex("tmp_buffer", 0); |
| 90 | |
| 91 | const int64_t instance_size = in->shape_view().At(in->shape_view().NumAxes() - 1); |
| 92 | const int64_t instance_num = in->shape_view().elem_cnt() / instance_size; |
| 93 | const int64_t k = std::min(static_cast<int64_t>(ctx->Attr<int32_t>("k")), instance_size); |
| 94 | int64_t* indices_ptr = tmp_buffer ? tmp_buffer->mut_dptr<int64_t>() : nullptr; |
| 95 | CpuTopK(ctx->stream(), in->dptr<T>(), indices_ptr, instance_num, instance_size, k, |
| 96 | ctx->Attr<bool>("sorted"), out->mut_dptr<int64_t>()); |
| 97 | } |
| 98 | bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } |
| 99 | }; |
| 100 |
nothing calls this directly
no test coverage detected