diff --git a/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp b/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp index edab454abd..b332749399 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp @@ -3902,6 +3902,9 @@ HSAILKernel::loadArguments( } if (nativeMem) { gpuMem = *reinterpret_cast(paramaddr); + if (NULL != gpuMem) { + mem = gpuMem->owner(); + } } else { mem = *reinterpret_cast(paramaddr); diff --git a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp index e9a4590329..7a659c15d2 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp @@ -922,8 +922,22 @@ Memory::allocMapTarget( address mapAddress = NULL; size_t offset = origin[0]; - incIndMapCount(); + //For SVM implementation, we cannot use cached map. if svm space, use the svm host pointer + void *initHostPtr = owner()->getSvmPtr(); + if (NULL != initHostPtr) { + owner()->commitSvmMemory(); + } + if (owner()->numDevices() > 1) { + if ((NULL == initHostPtr) && (owner()->getHostMem() == NULL)) { + static const bool forceAllocHostMem = true; + if (!owner()->allocHostMemory(NULL, forceAllocHostMem)) { + return NULL; + } + } + } + + incIndMapCount(); // If host memory exists, use it if ((owner()->getHostMem() != NULL) && isDirectMap()) { mapAddress = reinterpret_cast
(owner()->getHostMem()); @@ -953,8 +967,6 @@ Memory::allocMapTarget( bool failed = false; amd::Memory* memory = NULL; // Search for a possible indirect resource - //For SVM implementation, we cannot use cached map. if svm space, use the svm host pointer - void *initHostPtr = owner()->getSvmPtr(); cl_mem_flags flag = 0; bool canBeCached = true; if (NULL != initHostPtr) { diff --git a/projects/clr/rocclr/runtime/platform/memory.cpp b/projects/clr/rocclr/runtime/platform/memory.cpp index 2b4088997a..8e35fe9764 100644 --- a/projects/clr/rocclr/runtime/platform/memory.cpp +++ b/projects/clr/rocclr/runtime/platform/memory.cpp @@ -251,7 +251,7 @@ Memory::allocHostMemory(void* initFrom, bool allocHostMem, bool forceCopy) pipe->end_idx = asPipe()->getMaxNumPackets(); } - if (flags_ & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + if ((flags_ & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) && (NULL == lastWriter_)) { // Signal write, so coherency mechanism will initialize // memory on all devices signalWrite(NULL);