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

Method alloc_dynamic

src/core/test/graph/misc.cpp:200–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198
199public:
200 void alloc_dynamic(VarNode* var, DeviceTensorStorage& dest, size_t size) override {
201 ASSERT_LT(dest.size(), size);
202 MGB_LOCK_GUARD(m_mtx);
203 auto ptr = dest.comp_node().alloc_device(size);
204 auto ins = m_alive_vars.insert(var);
205 ASSERT_TRUE(ins.second);
206 auto del = [this, var, cn = dest.comp_node()](void* ptr) {
207 cn.free_device(ptr);
208 MGB_LOCK_GUARD(m_mtx);
209 auto nr = m_alive_vars.erase(var);
210 ASSERT_EQ(1u, nr);
211 };
212 dest.reset(dest.comp_node(), size, {static_cast<dt_byte*>(ptr), del});
213 }
214
215 const ThinHashSet<VarNode*>& alive_vars() const { return m_alive_vars; }
216

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected