| 18 | UserStaticMemAlloc(std::shared_ptr<Allocator> allocator) : m_allocator(allocator) {} |
| 19 | |
| 20 | void alloc_static( |
| 21 | LComputingGraph*, LDeviceTensorStorage& dest, size_t size) override { |
| 22 | if (size < dest.size()) { |
| 23 | return; |
| 24 | } |
| 25 | auto cn = dest.comp_node_allow_invalid(); |
| 26 | LITE_ASSERT(cn.valid(), "The compnode is invalid when alloc memory."); |
| 27 | LiteDeviceType device_type = get_device_from_locator(cn.locator_logical()); |
| 28 | int device_id = cn.locator_logical().device; |
| 29 | auto ptr_alloc = static_cast<mgb::dt_byte*>(m_allocator->allocate( |
| 30 | device_type, device_id, size, cn.get_mem_addr_alignment())); |
| 31 | auto storage = std::shared_ptr<mgb::dt_byte>( |
| 32 | ptr_alloc, |
| 33 | [allocator = m_allocator, device_type, device_id](void* ptr) { |
| 34 | allocator->free(device_type, device_id, ptr); |
| 35 | }); |
| 36 | dest.reset(cn, size, storage); |
| 37 | } |
| 38 | void alloc_dynamic( |
| 39 | mgb::VarNode*, mgb::DeviceTensorStorage& dest, size_t size) override { |
| 40 | alloc_static(nullptr, dest, size); |
nothing calls this directly
no test coverage detected