!34251 copy data from old device address to new device address when allocate continuous memory

Merge pull request !34251 from laiyongqiang/allocate_continuous_copy
This commit is contained in:
i-robot 2022-05-12 12:24:19 +00:00 committed by Gitee
commit 1d51009090
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 15 additions and 0 deletions

View File

@ -63,6 +63,13 @@ void GPUBucket::AllocateContinuousMemory(const std::vector<DeviceAddressPtr> &to
}
for (size_t i = 0; i < to_allocate_address.size(); i++) {
if (to_allocate_address[i]->GetPtr() != nullptr) {
auto old_dev_addr = to_allocate_address[i];
auto new_dev_addr = device_context->CreateDeviceAddress(dev_ptr_list[i], size_list[i], old_dev_addr->format(),
old_dev_addr->type_id(), old_dev_addr->host_shape());
new_dev_addr->SyncDeviceToDevice(old_dev_addr.get());
device_context->FreeMemory(old_dev_addr.get());
}
to_allocate_address[i]->set_ptr(dev_ptr_list[i]);
to_allocate_address[i]->SetSize(size_list[i]);
to_allocate_address[i]->set_from_mem_pool(true);

View File

@ -85,6 +85,14 @@ void MemoryManagerActor::AllocateContinuousMemory(const std::vector<std::vector<
}
for (size_t index = 0; index < alloc_list.size(); index++) {
if (alloc_list[index]->GetPtr() != nullptr) {
auto old_dev_addr = alloc_list[index];
auto new_dev_addr =
device_context->CreateDeviceAddress(dev_ptr_list[index], size_list[index], old_dev_addr->format(),
old_dev_addr->type_id(), old_dev_addr->host_shape());
new_dev_addr->SyncDeviceToDevice(old_dev_addr.get());
device_context->FreeMemory(old_dev_addr.get());
}
alloc_list[index]->set_ptr(dev_ptr_list[index]);
alloc_list[index]->SetSize(size_list[index]);
alloc_list[index]->set_from_mem_pool(true);