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

Method alloc_dynamic

src/core/test/graph/mem_fwd.cpp:18–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17public:
18 void alloc_dynamic(VarNode* var, DeviceTensorStorage& dest, size_t size) override {
19 ASSERT_LT(dest.size(), size);
20 MGB_LOCK_GUARD(m_mtx);
21 auto ptr = dest.comp_node().alloc_device(size);
22 auto ins = m_alive_vars.insert(var);
23 ASSERT_TRUE(ins.second);
24 auto del = [this, var, size, cn = dest.comp_node()](void* ptr) {
25 // modify the data to detect access after free
26 DeviceTensorND tensor;
27 DeviceTensorStorage storage;
28 storage.reset(
29 cn, size,
30 {DeviceTensorStorage::RawStorage{}, static_cast<dt_byte*>(ptr)});
31 tensor.reset(storage, {TensorShape{size}, dtype::Byte{}});
32 dev_tensor_memset(tensor, -1);
33
34 storage.comp_node().free_device(ptr);
35 MGB_LOCK_GUARD(m_mtx);
36 auto nr = m_alive_vars.erase(var);
37 ASSERT_EQ(1u, nr);
38 };
39 dest.reset(dest.comp_node(), size, {static_cast<dt_byte*>(ptr), del});
40 }
41
42 const ThinHashSet<VarNode*>& alive_vars() const { return m_alive_vars; }
43

Callers

nothing calls this directly

Calls 7

sizeMethod · 0.45
alloc_deviceMethod · 0.45
comp_nodeMethod · 0.45
insertMethod · 0.45
resetMethod · 0.45
free_deviceMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected