Skip to content

Commit 0702e7b

Browse files
Merge pull request #1858 from zhaomaosu/buffer-copy-host-ptr
[DeviceSanitizer] Handle mem buffer is created with flag COPY_HOST_POINTER
2 parents 3296886 + 9ee4588 commit 0702e7b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

source/loader/layers/sanitizer/ur_sanddi.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,19 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferCreate(
464464

465465
std::shared_ptr<MemBuffer> pMemBuffer =
466466
std::make_shared<MemBuffer>(hContext, size, hostPtrOrNull);
467+
468+
if (Host && (flags & UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) {
469+
std::shared_ptr<ContextInfo> CtxInfo =
470+
getContext()->interceptor->getContextInfo(hContext);
471+
for (const auto &hDevice : CtxInfo->DeviceList) {
472+
ManagedQueue InternalQueue(hContext, hDevice);
473+
char *Handle = nullptr;
474+
UR_CALL(pMemBuffer->getHandle(hDevice, Handle));
475+
UR_CALL(getContext()->urDdiTable.Enqueue.pfnUSMMemcpy(
476+
InternalQueue, true, Handle, Host, size, 0, nullptr, nullptr));
477+
}
478+
}
479+
467480
ur_result_t result = getContext()->interceptor->insertMemBuffer(pMemBuffer);
468481
*phBuffer = ur_cast<ur_mem_handle_t>(pMemBuffer.get());
469482

0 commit comments

Comments
 (0)