MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / Compute

Method Compute

oneflow/user/kernels/dim_gather_kernels.cpp:41–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40 private:
41 void Compute(KernelComputeContext* ctx) const override {
42 const Tensor* input_tensor = ctx->Tensor4ArgNameAndIndex("input", 0);
43 if (input_tensor->shape_view().elem_cnt() == 0) { return; }
44 const Tensor* index_tensor = ctx->Tensor4ArgNameAndIndex("index", 0);
45 Tensor* out_tensor = ctx->Tensor4ArgNameAndIndex("output", 0);
46 const int32_t dim = ctx->Attr<int32_t>("dim");
47
48 const IN_T* input = input_tensor->dptr<IN_T>();
49 const IDX_T* index = index_tensor->dptr<IDX_T>();
50 IN_T* output = out_tensor->mut_dptr<IN_T>();
51
52 const Shape in_shape = ExpandDimIf0D(input_tensor->shape_view());
53 const auto ndim = in_shape.NumAxes();
54 const auto dim_length = in_shape.At(dim);
55
56 DimOpIndexNdHelper<IDX_T> input_nd_helper(in_shape.data(), ndim);
57 DimOpIndexNdHelper<IDX_T> index_nd_helper(index_tensor->shape_view().data(), ndim);
58 DimGatherFunctor<device_type, IN_T, IDX_T>()(ctx->stream(), input_nd_helper, index_nd_helper,
59 ndim, index_tensor->shape_view().elem_cnt(),
60 dim_length, dim, index, input, output);
61 }
62 bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; }
63};
64

Callers

nothing calls this directly

Calls 8

ExpandDimIf0DFunction · 0.85
elem_cntMethod · 0.45
shape_viewMethod · 0.45
NumAxesMethod · 0.45
AtMethod · 0.45
dataMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected