Fix: Cycles: Avoid unnecessary move to host with multi-device

If one of the devices already used host happed memory but another not,
it would previously realloc both.

Thanks to Jorn Visser for investigating and finding this problem.

Pull Request: https://projects.blender.org/blender/blender/pulls/132912
This commit is contained in:
Brecht Van Lommel
2025-01-17 09:24:45 +01:00
parent 2cfe2e0bfe
commit fec593ec3b
3 changed files with 24 additions and 0 deletions

View File

@@ -601,6 +601,14 @@ void CUDADevice::mem_copy_to(device_memory &mem)
void CUDADevice::mem_move_to_host(device_memory &mem)
{
{
/* If already host mapped, nothing to do. */
thread_scoped_lock lock(device_mem_map_mutex);
if (device_mem_map[&mem].use_mapped_host) {
return;
}
}
if (mem.type == MEM_GLOBAL) {
global_free(mem);
global_alloc(mem);

View File

@@ -563,6 +563,14 @@ void HIPDevice::mem_copy_to(device_memory &mem)
void HIPDevice::mem_move_to_host(device_memory &mem)
{
{
/* If already host mapped, nothing to do. */
thread_scoped_lock lock(device_mem_map_mutex);
if (device_mem_map[&mem].use_mapped_host) {
return;
}
}
if (mem.type == MEM_GLOBAL) {
global_free(mem);
global_alloc(mem);

View File

@@ -444,6 +444,14 @@ void OneapiDevice::mem_move_to_host(device_memory &mem)
return;
}
{
/* If already host mapped, nothing to do. */
thread_scoped_lock lock(device_mem_map_mutex);
if (device_mem_map[&mem].use_mapped_host) {
return;
}
}
if (mem.type == MEM_GLOBAL) {
global_free(mem);
global_alloc(mem);