MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / make_empty_tensor

Function make_empty_tensor

imperative/python/src/grad_override.cpp:78–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78ValueRef make_empty_tensor(
79 CompNodeValue::ref_t device, ValueRef shape, DTypeValue::ref_t dtype) {
80 HostTensorStorage storage(*device);
81 storage.ensure_size(dtype->size());
82 std::memset(storage.ptr(), 0, dtype->size());
83 auto t = imperative::apply(
84 CreateTensor(CreateTensor::Const, *device, *dtype, ValueShape()),
85 HostStorage::make(storage))[0];
86 auto res = broadcast_to(t, shape);
87 return res;
88}
89
90std::optional<ValueRefList> matrix_mul_grad_rule(
91 const OpDef& op, Span<ValueRef> inputs, Span<bool> inputs_require_grad,

Callers 4

subtensor_grad_ruleFunction · 0.85
indexing_grad_ruleFunction · 0.85

Calls 7

CreateTensorClass · 0.85
ValueShapeClass · 0.85
broadcast_toFunction · 0.70
applyFunction · 0.50
makeFunction · 0.50
sizeMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected