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

Function InitDataSourceDistributedInfo

oneflow/user/data/distributed_util.h:28–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26namespace data {
27
28inline Maybe<void> InitDataSourceDistributedInfo(user_op::KernelInitContext* ctx,
29 size_t& world_size, int64_t& rank) {
30 auto nd_sbp_str_vec = ctx->Attr<std::vector<std::string>>("nd_sbp");
31 if (nd_sbp_str_vec.empty()) {
32 world_size = GlobalProcessCtx::WorldSize();
33 rank = GlobalProcessCtx::Rank();
34 } else {
35 const Shape& hierarchy = *ctx->parallel_desc().hierarchy();
36 CHECK_EQ_OR_RETURN(hierarchy.NumAxes(), nd_sbp_str_vec.size());
37 rank = 0;
38 world_size = 1;
39
40 using index_helper_t = NdIndexOffsetHelper<int64_t, SHAPE_MAX_AXIS_SIZE>;
41 index_helper_t index_helper(hierarchy.dim_vec().data(), hierarchy.NumAxes());
42 int64_t nd_index[SHAPE_MAX_AXIS_SIZE] = {0};
43 index_helper.OffsetToNdIndex(ctx->parallel_ctx().parallel_id(), nd_index);
44
45 for (int i = hierarchy.NumAxes() - 1; i >= 0; --i) {
46 SbpParallel sbp;
47 CHECK_OR_RETURN(ParseSbpParallelFromString(nd_sbp_str_vec[i], &sbp));
48 if (sbp.has_split_parallel()) {
49 rank += nd_index[i] * world_size;
50 world_size *= hierarchy.At(i);
51 }
52 }
53 }
54 return Maybe<void>::Ok();
55}
56
57} // namespace data
58

Callers 2

COCODataReaderMethod · 0.85
GPTDataLoaderMethod · 0.85

Calls 11

hierarchyMethod · 0.80
parallel_idMethod · 0.80
emptyMethod · 0.45
parallel_descMethod · 0.45
NumAxesMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
OffsetToNdIndexMethod · 0.45
parallel_ctxMethod · 0.45
AtMethod · 0.45

Tested by

no test coverage detected