| 18 | } |
| 19 | |
| 20 | void 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 |
no test coverage detected