Skip to content

Commit

Permalink
Refactor unions to using std::variant
Browse files Browse the repository at this point in the history
  • Loading branch information
hdelan committed Oct 13, 2023
1 parent b38855e commit 2b2e234
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 433 deletions.
78 changes: 39 additions & 39 deletions source/adapters/cuda/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
ur_result_t Result = UR_RESULT_SUCCESS;
CUdeviceptr DevPtr = hBuffer->Mem.BufferMem.get();
CUdeviceptr DevPtr = std::get<BufferMem>(hBuffer->Mem).get();
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

try {
Expand Down Expand Up @@ -562,7 +562,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWriteRect(
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
ur_result_t Result = UR_RESULT_SUCCESS;
CUdeviceptr DevPtr = hBuffer->Mem.BufferMem.get();
CUdeviceptr DevPtr = std::get<BufferMem>(hBuffer->Mem).get();
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

try {
Expand Down Expand Up @@ -606,9 +606,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferCopy(
ur_mem_handle_t hBufferDst, size_t srcOffset, size_t dstOffset, size_t size,
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
UR_ASSERT(size + dstOffset <= hBufferDst->Mem.BufferMem.getSize(),
UR_ASSERT(size + dstOffset <= std::get<BufferMem>(hBufferDst->Mem).getSize(),
UR_RESULT_ERROR_INVALID_SIZE);
UR_ASSERT(size + srcOffset <= hBufferSrc->Mem.BufferMem.getSize(),
UR_ASSERT(size + srcOffset <= std::get<BufferMem>(hBufferSrc->Mem).getSize(),
UR_RESULT_ERROR_INVALID_SIZE);

std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};
Expand All @@ -628,8 +628,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferCopy(
UR_CHECK_ERROR(RetImplEvent->start());
}

auto Src = hBufferSrc->Mem.BufferMem.get() + srcOffset;
auto Dst = hBufferDst->Mem.BufferMem.get() + dstOffset;
auto Src = std::get<BufferMem>(hBufferSrc->Mem).get() + srcOffset;
auto Dst = std::get<BufferMem>(hBufferDst->Mem).get() + dstOffset;

UR_CHECK_ERROR(cuMemcpyDtoDAsync(Dst, Src, size, Stream));

Expand All @@ -654,8 +654,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferCopyRect(
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
ur_result_t Result = UR_RESULT_SUCCESS;
CUdeviceptr SrcPtr = hBufferSrc->Mem.BufferMem.get();
CUdeviceptr DstPtr = hBufferDst->Mem.BufferMem.get();
CUdeviceptr SrcPtr = std::get<BufferMem>(hBufferSrc->Mem).get();
CUdeviceptr DstPtr = std::get<BufferMem>(hBufferDst->Mem).get();
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

try {
Expand Down Expand Up @@ -726,7 +726,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill(
size_t patternSize, size_t offset, size_t size,
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
ur_event_handle_t *phEvent) {
UR_ASSERT(size + offset <= hBuffer->Mem.BufferMem.getSize(),
UR_ASSERT(size + offset <= std::get<BufferMem>(hBuffer->Mem).getSize(),
UR_RESULT_ERROR_INVALID_SIZE);

std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};
Expand All @@ -745,7 +745,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill(
UR_CHECK_ERROR(RetImplEvent->start());
}

auto DstDevice = hBuffer->Mem.BufferMem.get() + offset;
auto DstDevice = std::get<BufferMem>(hBuffer->Mem).get() + offset;
auto N = size / patternSize;

// pattern size in bytes
Expand Down Expand Up @@ -892,7 +892,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(
Result = enqueueEventsWait(hQueue, CuStream, numEventsInWaitList,
phEventWaitList);

CUarray Array = hImage->Mem.SurfaceMem.getArray();
CUarray Array = std::get<SurfaceMem>(hImage->Mem).getArray();

CUDA_ARRAY_DESCRIPTOR ArrayDesc;
UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array));
Expand All @@ -902,7 +902,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(
size_t ByteOffsetX = origin.x * ElementByteSize * ArrayDesc.NumChannels;
size_t BytesToCopy = ElementByteSize * ArrayDesc.NumChannels * region.width;

ur_mem_type_t ImgType = hImage->Mem.SurfaceMem.getImageType();
ur_mem_type_t ImgType = std::get<SurfaceMem>(hImage->Mem).getImageType();

std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};
if (phEvent) {
Expand Down Expand Up @@ -964,7 +964,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite(
Result = enqueueEventsWait(hQueue, CuStream, numEventsInWaitList,
phEventWaitList);

CUarray Array = hImage->Mem.SurfaceMem.getArray();
CUarray Array = std::get<SurfaceMem>(hImage->Mem).getArray();

CUDA_ARRAY_DESCRIPTOR ArrayDesc;
UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array));
Expand All @@ -982,7 +982,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite(
UR_CHECK_ERROR(RetImplEvent->start());
}

ur_mem_type_t ImgType = hImage->Mem.SurfaceMem.getImageType();
ur_mem_type_t ImgType = std::get<SurfaceMem>(hImage->Mem).getImageType();
if (ImgType == UR_MEM_TYPE_IMAGE1D) {
UR_CHECK_ERROR(
cuMemcpyHtoAAsync(Array, ByteOffsetX, pSrc, BytesToCopy, CuStream));
Expand Down Expand Up @@ -1023,8 +1023,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy(
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(hImageDst->MemType == ur_mem_handle_t_::Type::Surface,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(hImageSrc->Mem.SurfaceMem.getImageType() ==
hImageDst->Mem.SurfaceMem.getImageType(),
UR_ASSERT(std::get<SurfaceMem>(hImageSrc->Mem).getImageType() ==
std::get<SurfaceMem>(hImageDst->Mem).getImageType(),
UR_RESULT_ERROR_INVALID_MEM_OBJECT);

ur_result_t Result = UR_RESULT_SUCCESS;
Expand All @@ -1035,8 +1035,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy(
Result = enqueueEventsWait(hQueue, CuStream, numEventsInWaitList,
phEventWaitList);

CUarray SrcArray = hImageSrc->Mem.SurfaceMem.getArray();
CUarray DstArray = hImageDst->Mem.SurfaceMem.getArray();
CUarray SrcArray = std::get<SurfaceMem>(hImageSrc->Mem).getArray();
CUarray DstArray = std::get<SurfaceMem>(hImageDst->Mem).getArray();

CUDA_ARRAY_DESCRIPTOR SrcArrayDesc;
UR_CHECK_ERROR(cuArrayGetDescriptor(&SrcArrayDesc, SrcArray));
Expand Down Expand Up @@ -1065,7 +1065,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy(
UR_CHECK_ERROR(RetImplEvent->start());
}

ur_mem_type_t ImgType = hImageSrc->Mem.SurfaceMem.getImageType();
ur_mem_type_t ImgType = std::get<SurfaceMem>(hImageSrc->Mem).getImageType();
if (ImgType == UR_MEM_TYPE_IMAGE1D) {
UR_CHECK_ERROR(cuMemcpyAtoA(DstArray, DstByteOffsetX, SrcArray,
SrcByteOffsetX, BytesToCopy));
Expand Down Expand Up @@ -1108,22 +1108,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap(
ur_event_handle_t *phEvent, void **ppRetMap) {
UR_ASSERT(hBuffer->MemType == ur_mem_handle_t_::Type::Buffer,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(offset + size <= hBuffer->Mem.BufferMem.getSize(),
UR_ASSERT(offset + size <= std::get<BufferMem>(hBuffer->Mem).getSize(),
UR_RESULT_ERROR_INVALID_SIZE);

auto &BufferImpl = std::get<BufferMem>(hBuffer->Mem);
ur_result_t Result = UR_RESULT_ERROR_INVALID_MEM_OBJECT;
const bool IsPinned =
hBuffer->Mem.BufferMem.MemAllocMode ==
ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::AllocHostPtr;
BufferImpl.MemAllocMode == BufferMem::AllocMode::AllocHostPtr;

// Currently no support for overlapping regions
if (hBuffer->Mem.BufferMem.getMapPtr() != nullptr) {
if (BufferImpl.getMapPtr() != nullptr) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

// Allocate a pointer in the host to store the mapped information
auto HostPtr = hBuffer->Mem.BufferMem.mapToPtr(size, offset, mapFlags);
*ppRetMap = hBuffer->Mem.BufferMem.getMapPtr();
auto HostPtr = BufferImpl.mapToPtr(size, offset, mapFlags);
*ppRetMap = BufferImpl.getMapPtr();
if (HostPtr) {
Result = UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -1168,21 +1168,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap(
ur_result_t Result = UR_RESULT_SUCCESS;
UR_ASSERT(hMem->MemType == ur_mem_handle_t_::Type::Buffer,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(hMem->Mem.BufferMem.getMapPtr() != nullptr,
UR_ASSERT(std::get<BufferMem>(hMem->Mem).getMapPtr() != nullptr,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(hMem->Mem.BufferMem.getMapPtr() == pMappedPtr,
UR_ASSERT(std::get<BufferMem>(hMem->Mem).getMapPtr() == pMappedPtr,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);

const bool IsPinned =
hMem->Mem.BufferMem.MemAllocMode ==
ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::AllocHostPtr;
const bool IsPinned = std::get<BufferMem>(hMem->Mem).MemAllocMode ==
BufferMem::AllocMode::AllocHostPtr;

if (!IsPinned && (hMem->Mem.BufferMem.getMapFlags() & UR_MAP_FLAG_WRITE)) {
if (!IsPinned &&
(std::get<BufferMem>(hMem->Mem).getMapFlags() & UR_MAP_FLAG_WRITE)) {
// Pinned host memory is only on host so it doesn't need to be written to.
Result = urEnqueueMemBufferWrite(
hQueue, hMem, true, hMem->Mem.BufferMem.getMapOffset(),
hMem->Mem.BufferMem.getMapSize(), pMappedPtr, numEventsInWaitList,
phEventWaitList, phEvent);
hQueue, hMem, true, std::get<BufferMem>(hMem->Mem).getMapOffset(),
std::get<BufferMem>(hMem->Mem).getMapSize(), pMappedPtr,
numEventsInWaitList, phEventWaitList, phEvent);
} else {
ScopedContext Active(hQueue->getContext());

Expand All @@ -1203,7 +1203,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap(
}
}

hMem->Mem.BufferMem.unmap(pMappedPtr);
std::get<BufferMem>(hMem->Mem).unmap(pMappedPtr);
return Result;
}

Expand Down Expand Up @@ -1502,11 +1502,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
size_t offset, size_t size, void *pDst, uint32_t numEventsInWaitList,
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
UR_ASSERT(!hBuffer->isImage(), UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(offset + size <= hBuffer->Mem.BufferMem.Size,
UR_ASSERT(offset + size <= std::get<BufferMem>(hBuffer->Mem).Size,
UR_RESULT_ERROR_INVALID_SIZE);

ur_result_t Result = UR_RESULT_SUCCESS;
CUdeviceptr DevPtr = hBuffer->Mem.BufferMem.get();
CUdeviceptr DevPtr = std::get<BufferMem>(hBuffer->Mem).get();
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

try {
Expand Down Expand Up @@ -1549,11 +1549,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWrite(
size_t offset, size_t size, const void *pSrc, uint32_t numEventsInWaitList,
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
UR_ASSERT(!hBuffer->isImage(), UR_RESULT_ERROR_INVALID_MEM_OBJECT);
UR_ASSERT(offset + size <= hBuffer->Mem.BufferMem.Size,
UR_ASSERT(offset + size <= std::get<BufferMem>(hBuffer->Mem).Size,
UR_RESULT_ERROR_INVALID_SIZE);

ur_result_t Result = UR_RESULT_SUCCESS;
CUdeviceptr DevPtr = hBuffer->Mem.BufferMem.get();
CUdeviceptr DevPtr = std::get<BufferMem>(hBuffer->Mem).get();
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

try {
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/cuda/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
if (hArgValue->MemType == ur_mem_handle_t_::Type::Surface) {
CUDA_ARRAY3D_DESCRIPTOR arrayDesc;
UR_CHECK_ERROR(cuArray3DGetDescriptor(
&arrayDesc, hArgValue->Mem.SurfaceMem.getArray()));
&arrayDesc, std::get<SurfaceMem>(hArgValue->Mem).getArray()));
if (arrayDesc.Format != CU_AD_FORMAT_UNSIGNED_INT32 &&
arrayDesc.Format != CU_AD_FORMAT_SIGNED_INT32 &&
arrayDesc.Format != CU_AD_FORMAT_HALF &&
Expand All @@ -314,10 +314,10 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
UR_RESULT_ERROR_ADAPTER_SPECIFIC);
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}
CUsurfObject CuSurf = hArgValue->Mem.SurfaceMem.getSurface();
CUsurfObject CuSurf = std::get<SurfaceMem>(hArgValue->Mem).getSurface();
hKernel->setKernelArg(argIndex, sizeof(CuSurf), (void *)&CuSurf);
} else {
CUdeviceptr CuPtr = hArgValue->Mem.BufferMem.get();
CUdeviceptr CuPtr = std::get<BufferMem>(hArgValue->Mem).get();
hKernel->setKernelArg(argIndex, sizeof(CUdeviceptr), (void *)&CuPtr);
}
} catch (ur_result_t Err) {
Expand Down
61 changes: 29 additions & 32 deletions source/adapters/cuda/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
CUdeviceptr Ptr = 0;
auto HostPtr = pProperties ? pProperties->pHost : nullptr;

ur_mem_handle_t_::MemImpl::BufferMem::AllocMode AllocMode =
ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::Classic;
BufferMem::AllocMode AllocMode = BufferMem::AllocMode::Classic;

if ((flags & UR_MEM_FLAG_USE_HOST_POINTER) && EnableUseHostPtr) {
UR_CHECK_ERROR(
cuMemHostRegister(HostPtr, size, CU_MEMHOSTREGISTER_DEVICEMAP));
UR_CHECK_ERROR(cuMemHostGetDevicePointer(&Ptr, HostPtr, 0));
AllocMode = ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::UseHostPtr;
AllocMode = BufferMem::AllocMode::UseHostPtr;
} else if (flags & UR_MEM_FLAG_ALLOC_HOST_POINTER) {
UR_CHECK_ERROR(cuMemAllocHost(&HostPtr, size));
UR_CHECK_ERROR(cuMemHostGetDevicePointer(&Ptr, HostPtr, 0));
AllocMode = ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::AllocHostPtr;
AllocMode = BufferMem::AllocMode::AllocHostPtr;
} else {
UR_CHECK_ERROR(cuMemAlloc(&Ptr, size));
if (flags & UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER) {
AllocMode = ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::CopyIn;
AllocMode = BufferMem::AllocMode::CopyIn;
}
}

Expand Down Expand Up @@ -121,21 +120,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
ScopedContext Active(MemObjPtr->getContext());

if (hMem->MemType == ur_mem_handle_t_::Type::Buffer) {
switch (MemObjPtr->Mem.BufferMem.MemAllocMode) {
case ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::CopyIn:
case ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::Classic:
UR_CHECK_ERROR(cuMemFree(MemObjPtr->Mem.BufferMem.Ptr));
auto &BufferImpl = std::get<BufferMem>(MemObjPtr->Mem);
switch (BufferImpl.MemAllocMode) {
case BufferMem::AllocMode::CopyIn:
case BufferMem::AllocMode::Classic:
UR_CHECK_ERROR(cuMemFree(BufferImpl.Ptr));
break;
case ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::UseHostPtr:
UR_CHECK_ERROR(cuMemHostUnregister(MemObjPtr->Mem.BufferMem.HostPtr));
case BufferMem::AllocMode::UseHostPtr:
UR_CHECK_ERROR(cuMemHostUnregister(BufferImpl.HostPtr));
break;
case ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::AllocHostPtr:
UR_CHECK_ERROR(cuMemFreeHost(MemObjPtr->Mem.BufferMem.HostPtr));
case BufferMem::AllocMode::AllocHostPtr:
UR_CHECK_ERROR(cuMemFreeHost(BufferImpl.HostPtr));
};
} else if (hMem->MemType == ur_mem_handle_t_::Type::Surface) {
UR_CHECK_ERROR(
cuSurfObjectDestroy(MemObjPtr->Mem.SurfaceMem.getSurface()));
UR_CHECK_ERROR(cuArrayDestroy(MemObjPtr->Mem.SurfaceMem.getArray()));
auto &SurfaceImpl = std::get<SurfaceMem>(MemObjPtr->Mem);
UR_CHECK_ERROR(cuSurfObjectDestroy(SurfaceImpl.getSurface()));
UR_CHECK_ERROR(cuArrayDestroy(SurfaceImpl.getArray()));
}

} catch (ur_result_t Err) {
Expand Down Expand Up @@ -163,8 +163,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
/// \return UR_RESULT_SUCCESS
UR_APIEXPORT ur_result_t UR_APICALL
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_native_handle_t *phNativeMem) {
*phNativeMem =
reinterpret_cast<ur_native_handle_t>(hMem->Mem.BufferMem.get());
*phNativeMem = reinterpret_cast<ur_native_handle_t>(
std::get<BufferMem>(hMem->Mem).get());
return UR_RESULT_SUCCESS;
}

Expand All @@ -183,8 +183,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
case UR_MEM_INFO_SIZE: {
try {
size_t AllocSize = 0;
UR_CHECK_ERROR(cuMemGetAddressRange(nullptr, &AllocSize,
hMemory->Mem.BufferMem.Ptr));
UR_CHECK_ERROR(cuMemGetAddressRange(
nullptr, &AllocSize, std::get<BufferMem>(hMemory->Mem).Ptr));
return ReturnValue(AllocSize);
} catch (ur_result_t Err) {
return Err;
Expand Down Expand Up @@ -443,25 +443,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition(

UR_ASSERT(pRegion->size != 0u, UR_RESULT_ERROR_INVALID_BUFFER_SIZE);

auto &BufferImpl = std::get<BufferMem>(hBuffer->Mem);

assert((pRegion->origin <= (pRegion->origin + pRegion->size)) && "Overflow");
UR_ASSERT(
((pRegion->origin + pRegion->size) <= hBuffer->Mem.BufferMem.getSize()),
UR_RESULT_ERROR_INVALID_BUFFER_SIZE);
UR_ASSERT(((pRegion->origin + pRegion->size) <= BufferImpl.getSize()),
UR_RESULT_ERROR_INVALID_BUFFER_SIZE);
// Retained indirectly due to retaining parent buffer below.
ur_context_handle_t Context = hBuffer->Context;

ur_mem_handle_t_::MemImpl::BufferMem::AllocMode AllocMode =
ur_mem_handle_t_::MemImpl::BufferMem::AllocMode::Classic;
BufferMem::AllocMode AllocMode = BufferMem::AllocMode::Classic;

assert(hBuffer->Mem.BufferMem.Ptr !=
ur_mem_handle_t_::MemImpl::BufferMem::native_type{0});
ur_mem_handle_t_::MemImpl::BufferMem::native_type Ptr =
hBuffer->Mem.BufferMem.Ptr + pRegion->origin;
assert(BufferImpl.Ptr != BufferMem::native_type{0});
BufferMem::native_type Ptr = BufferImpl.Ptr + pRegion->origin;

void *HostPtr = nullptr;
if (hBuffer->Mem.BufferMem.HostPtr) {
HostPtr =
static_cast<char *>(hBuffer->Mem.BufferMem.HostPtr) + pRegion->origin;
if (BufferImpl.HostPtr) {
HostPtr = static_cast<char *>(BufferImpl.HostPtr) + pRegion->origin;
}

std::unique_ptr<ur_mem_handle_t_> MemObj{nullptr};
Expand Down
Loading

0 comments on commit 2b2e234

Please sign in to comment.