1616#include " context.hpp"
1717#include " device.hpp"
1818#include " memory.hpp"
19+ #include " ur2offload.hpp"
1920
2021UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate (
2122 ur_context_handle_t hContext, ur_mem_flags_t flags, size_t size,
@@ -33,14 +34,20 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
3334 auto AllocMode = BufferMem::AllocMode::Default;
3435
3536 if (flags & UR_MEM_FLAG_ALLOC_HOST_POINTER) {
36- olMemAlloc (OffloadDevice, OL_ALLOC_TYPE_HOST, size, &HostPtr);
37+ auto Res = olMemAlloc (OffloadDevice, OL_ALLOC_TYPE_HOST, size, &HostPtr);
38+ if (Res) {
39+ return offloadResultToUR (Res);
40+ }
3741 // TODO: We (probably) need something like cuMemHostGetDevicePointer
3842 // for this to work everywhere. For now assume the managed host pointer is
3943 // device-accessible.
4044 Ptr = HostPtr;
4145 AllocMode = BufferMem::AllocMode::AllocHostPtr;
4246 } else {
43- olMemAlloc (OffloadDevice, OL_ALLOC_TYPE_DEVICE, size, &Ptr);
47+ auto Res = olMemAlloc (OffloadDevice, OL_ALLOC_TYPE_DEVICE, size, &Ptr);
48+ if (Res) {
49+ return offloadResultToUR (Res);
50+ }
4451 if (flags & UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER) {
4552 AllocMode = BufferMem::AllocMode::CopyIn;
4653 }
@@ -51,8 +58,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
5158 hContext, ParentBuffer, flags, AllocMode, Ptr, HostPtr, size});
5259
5360 if (PerformInitialCopy) {
54- olMemcpy (nullptr , Ptr, OffloadDevice, HostPtr, hContext->OffloadHost , size,
55- nullptr );
61+ auto Res = olMemcpy (nullptr , Ptr, OffloadDevice, HostPtr,
62+ hContext->OffloadHost , size, nullptr );
63+ if (Res) {
64+ return offloadResultToUR (Res);
65+ }
5666 }
5767
5868 *phBuffer = URMemObj.release ();
@@ -74,7 +84,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
7484 if (hMem->MemType == ur_mem_handle_t_::Type::Buffer) {
7585 // TODO: Handle registered host memory
7686 auto &BufferImpl = std::get<BufferMem>(MemObjPtr->Mem );
77- olMemFree (BufferImpl.Ptr );
87+ auto Res = olMemFree (BufferImpl.Ptr );
88+ if (Res) {
89+ return offloadResultToUR (Res);
90+ }
7891 }
7992
8093 return UR_RESULT_SUCCESS;
0 commit comments