@@ -433,7 +433,7 @@ ur_result_t allocateMemObjOnDeviceIfNeeded(ur_mem_handle_t Mem,
433
433
434
434
if (Mem->isBuffer ()) {
435
435
auto &Buffer = std::get<BufferMem>(Mem->Mem );
436
- auto &DevPtr = Buffer.Ptrs [hDevice->getIndex ()];
436
+ auto &DevPtr = Buffer.Ptrs [hDevice->getIndex () % Buffer. Ptrs . size () ];
437
437
438
438
// Allocation has already been made
439
439
if (DevPtr != BufferMem::native_type{0 }) {
@@ -456,11 +456,11 @@ ur_result_t allocateMemObjOnDeviceIfNeeded(ur_mem_handle_t Mem,
456
456
try {
457
457
auto &Image = std::get<SurfaceMem>(Mem->Mem );
458
458
// Allocation has already been made
459
- if (Image.Arrays [hDevice->getIndex ()]) {
459
+ if (Image.Arrays [hDevice->getIndex () % Image. Arrays . size () ]) {
460
460
return UR_RESULT_SUCCESS;
461
461
}
462
462
UR_CHECK_ERROR (cuArray3DCreate (&ImageArray, &Image.ArrayDesc ));
463
- Image.Arrays [hDevice->getIndex ()] = ImageArray;
463
+ Image.Arrays [hDevice->getIndex () % Image. Arrays . size () ] = ImageArray;
464
464
465
465
// CUDA_RESOURCE_DESC is a union of different structs, shown here
466
466
// https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TEXOBJECT.html
@@ -475,7 +475,7 @@ ur_result_t allocateMemObjOnDeviceIfNeeded(ur_mem_handle_t Mem,
475
475
ImageResDesc.flags = 0 ;
476
476
477
477
UR_CHECK_ERROR (cuSurfObjectCreate (&Surface, &ImageResDesc));
478
- Image.SurfObjs [hDevice->getIndex ()] = Surface;
478
+ Image.SurfObjs [hDevice->getIndex () % Image. SurfObjs . size () ] = Surface;
479
479
} catch (ur_result_t Err) {
480
480
if (ImageArray) {
481
481
UR_CHECK_ERROR (cuArrayDestroy (ImageArray));
@@ -590,7 +590,9 @@ ur_result_t migrateMemoryToDeviceIfNeeded(ur_mem_handle_t Mem,
590
590
UR_ASSERT (hDevice, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
591
591
// Device allocation has already been initialized with most up to date
592
592
// data in buffer
593
- if (Mem->HaveMigratedToDeviceSinceLastWrite [hDevice->getIndex ()]) {
593
+ if (Mem->HaveMigratedToDeviceSinceLastWrite
594
+ [hDevice->getIndex () %
595
+ Mem->HaveMigratedToDeviceSinceLastWrite .size ()]) {
594
596
return UR_RESULT_SUCCESS;
595
597
}
596
598
@@ -601,6 +603,8 @@ ur_result_t migrateMemoryToDeviceIfNeeded(ur_mem_handle_t Mem,
601
603
UR_CHECK_ERROR (migrateImageToDevice (Mem, hDevice));
602
604
}
603
605
604
- Mem->HaveMigratedToDeviceSinceLastWrite [hDevice->getIndex ()] = true ;
606
+ Mem->HaveMigratedToDeviceSinceLastWrite
607
+ [hDevice->getIndex () % Mem->HaveMigratedToDeviceSinceLastWrite .size ()] =
608
+ true ;
605
609
return UR_RESULT_SUCCESS;
606
610
}
0 commit comments