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

Function EagerLocalTensorZeros

oneflow/api/python/utils/tensor_utils.cpp:37–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35namespace one {
36
37Maybe<void> EagerLocalTensorZeros(const std::shared_ptr<Tensor>& t) {
38 JUST(functional::CheckInplaceValid(t));
39 std::shared_ptr<LocalTensor> local_tensor;
40 if (t->is_local()) {
41 local_tensor = JUST(t->AsLocalTensor());
42 } else {
43 local_tensor = JUST(t->cur_rank_phy_tensor());
44 }
45 CHECK_OR_RETURN(local_tensor->is_eager()) << "eager tensors supported only";
46 JUST(PhysicalRun([&](InstructionsBuilder* builder) -> Maybe<void> {
47 JUST(builder->AccessBlobByCallback(
48 local_tensor,
49 [](ep::Stream* stream, const std::shared_ptr<vm::EagerBlobObject>& eager_blob_object) {
50 AutoMemset(stream, eager_blob_object->mut_dptr(), 0,
51 eager_blob_object->ByteSizeOfBlobBody(), eager_blob_object->mem_case());
52 },
53 "mut"));
54 return Maybe<void>::Ok();
55 }));
56 return Maybe<void>::Ok();
57}
58
59namespace {
60void CopyFromNumpyArray(ep::Stream* stream,

Callers 2

PyTensorObject_zero_Function · 0.85
PyTensorObject_zero_gradFunction · 0.85

Calls 10

CheckInplaceValidFunction · 0.85
PhysicalRunFunction · 0.85
AutoMemsetFunction · 0.85
AccessBlobByCallbackMethod · 0.80
is_localMethod · 0.45
AsLocalTensorMethod · 0.45
cur_rank_phy_tensorMethod · 0.45
is_eagerMethod · 0.45
mut_dptrMethod · 0.45
ByteSizeOfBlobBodyMethod · 0.45

Tested by

no test coverage detected