@@ -1248,36 +1248,34 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap(
12481248 const bool IsPinned =
12491249 BufferImpl.MemAllocMode == BufferMem::AllocMode::AllocHostPtr;
12501250
1251- ur_result_t Result = UR_RESULT_SUCCESS;
1252- if (!IsPinned &&
1253- (mapFlags & (UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE)) {
1254- // Pinned host memory is already on host so it doesn't need to be read.
1255- Result = urEnqueueMemBufferRead (hQueue, hBuffer, blockingMap, offset, size,
1256- MapPtr, numEventsInWaitList,
1257- phEventWaitList, phEvent);
1258- } else {
1259- ScopedContext Active (hQueue->getDevice ());
1251+ try {
1252+ if (!IsPinned && (mapFlags & (UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE))) {
1253+ // Pinned host memory is already on host so it doesn't need to be read.
1254+ UR_CHECK_ERROR (urEnqueueMemBufferRead (
1255+ hQueue, hBuffer, blockingMap, offset, size, MapPtr,
1256+ numEventsInWaitList, phEventWaitList, phEvent));
1257+ } else {
1258+ ScopedContext Active (hQueue->getDevice ());
12601259
1261- if (IsPinned) {
1262- Result = urEnqueueEventsWait (hQueue, numEventsInWaitList, phEventWaitList ,
1263- nullptr );
1264- }
1260+ if (IsPinned) {
1261+ UR_CHECK_ERROR ( urEnqueueEventsWait (hQueue, numEventsInWaitList,
1262+ phEventWaitList, nullptr ) );
1263+ }
12651264
1266- if (phEvent) {
1267- try {
1265+ if (phEvent) {
12681266 *phEvent = ur_event_handle_t_::makeNative (
12691267 UR_COMMAND_MEM_BUFFER_MAP, hQueue, hQueue->getNextTransferStream ());
12701268 UR_CHECK_ERROR ((*phEvent)->start ());
12711269 UR_CHECK_ERROR ((*phEvent)->record ());
1272- } catch (ur_result_t Error) {
1273- Result = Error;
12741270 }
12751271 }
1272+ } catch (ur_result_t Error) {
1273+ return Error;
12761274 }
12771275
12781276 *ppRetMap = MapPtr;
12791277
1280- return Result ;
1278+ return UR_RESULT_SUCCESS ;
12811279}
12821280
12831281// / Implements the unmap from the host, using a BufferWrite operation.
@@ -1297,36 +1295,35 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap(
12971295 const bool IsPinned =
12981296 BufferImpl.MemAllocMode == BufferMem::AllocMode::AllocHostPtr;
12991297
1300- ur_result_t Result = UR_RESULT_SUCCESS;
1301- if (!IsPinned &&
1302- (Map->getMapFlags () &
1303- (UR_MAP_FLAG_WRITE | UR_MAP_FLAG_WRITE_INVALIDATE_REGION))) {
1304- // Pinned host memory is only on host so it doesn't need to be written to.
1305- Result = urEnqueueMemBufferWrite (
1306- hQueue, hMem, true , Map->getMapOffset (), Map->getMapSize (), pMappedPtr ,
1307- numEventsInWaitList, phEventWaitList, phEvent);
1308- } else {
1309- ScopedContext Active (hQueue->getDevice ());
1298+ try {
1299+ if (!IsPinned &&
1300+ (Map->getMapFlags () &
1301+ (UR_MAP_FLAG_WRITE | UR_MAP_FLAG_WRITE_INVALIDATE_REGION))) {
1302+ // Pinned host memory is only on host so it doesn't need to be written to.
1303+ UR_CHECK_ERROR ( urEnqueueMemBufferWrite (
1304+ hQueue, hMem, true , Map->getMapOffset (), Map->getMapSize (),
1305+ pMappedPtr, numEventsInWaitList, phEventWaitList, phEvent) );
1306+ } else {
1307+ ScopedContext Active (hQueue->getDevice ());
13101308
1311- if (IsPinned) {
1312- Result = urEnqueueEventsWait (hQueue, numEventsInWaitList, phEventWaitList ,
1313- nullptr );
1314- }
1309+ if (IsPinned) {
1310+ UR_CHECK_ERROR ( urEnqueueEventsWait (hQueue, numEventsInWaitList,
1311+ phEventWaitList, nullptr ) );
1312+ }
13151313
1316- if (phEvent) {
1317- try {
1314+ if (phEvent) {
13181315 *phEvent = ur_event_handle_t_::makeNative (
13191316 UR_COMMAND_MEM_UNMAP, hQueue, hQueue->getNextTransferStream ());
13201317 UR_CHECK_ERROR ((*phEvent)->start ());
13211318 UR_CHECK_ERROR ((*phEvent)->record ());
1322- } catch (ur_result_t Error) {
1323- Result = Error;
13241319 }
13251320 }
1321+ } catch (ur_result_t Error) {
1322+ return Error;
13261323 }
13271324
13281325 BufferImpl.unmap (pMappedPtr);
1329- return Result ;
1326+ return UR_RESULT_SUCCESS ;
13301327}
13311328
13321329UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill (
0 commit comments