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

Method apply

src/serialization/impl/batched_device_value_loader.cpp:20–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20void BatchedDeviceValueLoader::apply() {
21 for (auto&& item : m_cn2tensor_list) {
22 auto alignment = item.first.get_mem_addr_alignment();
23 size_t tot_size = 0;
24 for (auto&& i : item.second.tensors) {
25 tot_size = get_aligned_power2(tot_size, alignment) +
26 i.second->layout().span().dist_byte();
27 }
28
29 HostTensorStorage host_storage{item.first};
30 DeviceTensorStorage dev_storage{item.first};
31 host_storage.ensure_size(tot_size);
32 dev_storage.ensure_size(tot_size);
33 auto ptr_host = host_storage.ptr();
34 size_t offset = 0;
35 for (auto&& i : item.second.tensors) {
36 offset = get_aligned_power2(offset, alignment);
37 auto size = i.second->layout().span().dist_byte();
38 if (i.second->layout().format.is_default()) {
39 mgb_assert(size == i.first.layout().span().dist_byte());
40 memcpy(ptr_host + offset, i.first.raw_ptr(), size);
41 } else {
42 HostTensorND host;
43 host.reset(host_storage.sub(offset), i.second->layout());
44 host.copy_from_fixlayout(i.first);
45 }
46 i.second->reset(dev_storage.sub(offset), i.second->layout());
47 offset += size;
48 }
49 dev_storage.copy_from(host_storage, tot_size);
50 item.first.sync();
51 }
52}
53
54} // namespace serialization
55} // namespace mgb

Callers 2

load_oprsMethod · 0.45
load_oprsMethod · 0.45

Calls 13

dist_byteMethod · 0.80
spanMethod · 0.80
copy_from_fixlayoutMethod · 0.80
get_aligned_power2Function · 0.50
layoutMethod · 0.45
ptrMethod · 0.45
is_defaultMethod · 0.45
raw_ptrMethod · 0.45
resetMethod · 0.45
subMethod · 0.45
copy_fromMethod · 0.45

Tested by

no test coverage detected