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

Function IsOverlappingMemorys

oneflow/core/framework/tensor_methods.cpp:52–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52static bool IsOverlappingMemorys(const std::vector<int64_t>& sizes,
53 const std::vector<int64_t>& strides) {
54 // reference: torch/csrc/autograd/FunctionsManual.cpp _maybe_overlapping_memory()
55 if (sizes.size() > 0) {
56 std::vector<std::size_t> argsort(sizes.size());
57 std::iota(argsort.begin(), argsort.end(), 0);
58 std::sort(argsort.begin(), argsort.end(),
59 [&](std::size_t i, std::size_t j) { return strides[i] < strides[j]; });
60 int64_t max_index_in_slice = 0;
61 for (auto i : argsort) {
62 auto stride_ = strides[i];
63 if (stride_ <= max_index_in_slice) { return true; }
64 max_index_in_slice += stride_ * (sizes[i] - 1);
65 }
66 }
67 return false;
68}
69
70static int64_t MinStorageSize(const std::vector<int64_t>& sizes,
71 const std::vector<int64_t>& strides, int64_t storage_offset) {

Callers 1

AsStridedGradFunction · 0.85

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected