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

Method InitOpKernelCache

oneflow/user/kernels/gather_kernel.cpp:67–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 ~GatherKernel() override = default;
66
67 std::shared_ptr<user_op::OpKernelCache> InitOpKernelCache(
68 user_op::KernelCacheContext* ctx) const override {
69 if (ctx->parallel_ctx().parallel_num() > 1) {
70 const auto axis = ctx->Attr<int64_t>("axis");
71 const NdSbp& in_nd_sbp = ctx->NdSbp4ArgNameAndIndex("in", 0);
72 const Shape& hierarchy = *ctx->parallel_desc().hierarchy();
73 CheckNdSbp(hierarchy, axis, in_nd_sbp, ctx->NdSbp4ArgNameAndIndex("indices", 0),
74 ctx->NdSbp4ArgNameAndIndex("out", 0));
75 const Shape in_logical_shape =
76 ExpandDimIf0D(ctx->LogicalTensorDesc4ArgNameAndIndex("in", 0)->shape());
77 TensorSliceView view = GetTensorSliceView4ParallelId(hierarchy, in_nd_sbp, in_logical_shape,
78 ctx->parallel_ctx().parallel_id());
79 return std::make_shared<GatherOpKernelCache>(view.At(axis).begin(), view.At(axis).end());
80 } else {
81 return nullptr;
82 }
83 }
84
85 private:
86 void Compute(user_op::KernelComputeContext* ctx, user_op::OpKernelState*,

Callers

nothing calls this directly

Calls 14

ExpandDimIf0DFunction · 0.85
hierarchyMethod · 0.80
parallel_idMethod · 0.80
CheckNdSbpFunction · 0.70
parallel_numMethod · 0.45
parallel_ctxMethod · 0.45
NdSbp4ArgNameAndIndexMethod · 0.45
parallel_descMethod · 0.45
shapeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected