| 16 | |
| 17 | public: |
| 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 |
nothing calls this directly
no test coverage detected