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

Method apply_lazy_and_get_ptr

src/core/impl/tensor.cpp:262–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260
261template <class Trait>
262dt_byte* TensorStorage<Trait>::apply_lazy_and_get_ptr() {
263 check_comp_node_valid();
264 if (m_size > m_capacity) {
265 mgb_assert(m_allow_realloc && !m_offset);
266 m_data.reset(); // free old ptr
267 m_capacity = 0; // to be exception safe
268 auto ptr = static_cast<dt_byte*>(Trait::alloc(m_comp_node, m_size));
269 mgb_throw_if(!ptr, SystemError, "failed to allocate memory");
270 CompNode cn = m_comp_node;
271 m_data.reset(ptr, [cn](void* p) { Trait::free(cn, p); });
272 m_ref_ptr = std::make_shared<void*>(static_cast<void*>(nullptr));
273 m_capacity = m_size;
274 }
275 *m_ref_ptr = static_cast<void*>(m_data.get());
276 return m_data.get() + m_offset;
277}
278
279template <class Trait>
280TensorStorage<Trait>& TensorStorage<Trait>::comp_node(

Callers 1

ptrMethod · 0.80

Calls 4

allocFunction · 0.85
freeFunction · 0.85
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected