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

Method alloc_static

lite/src/mge/memory_allocator.h:20–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 8

sizeMethod · 0.45
validMethod · 0.45
locator_logicalMethod · 0.45
allocateMethod · 0.45
freeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected