Skip to content

Commit 1ffc1e3

Browse files
Seanst98KornevNikita
authored andcommitted
[AsyncAlloc][CUDA] Don't set pool maxSize if CUDA version < 12.2 (#17733)
CUDA did not introduce the maxSize property to CUmemPoolProps until version 12.2. In the case where the user has set a maxSize > 0, and their CUDA version is < 12.2, return an error. This commit fixes the compilation error associated with setting this property in older CUDA versions. Also fix incorrect error reporting when creating a memory pool.
1 parent 0fc98a6 commit 1ffc1e3

File tree

1 file changed

+14
-3
lines changed
  • unified-runtime/source/adapters/cuda

1 file changed

+14
-3
lines changed

unified-runtime/source/adapters/cuda/usm.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,24 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
431431
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
432432
const ur_usm_pool_limits_desc_t *Limits =
433433
reinterpret_cast<const ur_usm_pool_limits_desc_t *>(BaseDesc);
434+
#if CUDA_VERSION >= 12020
435+
// maxSize as a member of CUmemPoolProps was introduced in CUDA 12.2.
434436
MemPoolProps.maxSize =
435437
Limits->maxPoolableSize; // CUDA lazily reserves memory for pools in
436438
// 32MB chunks. maxSize is elevated to the
437439
// next 32MB multiple. Each 32MB chunk is
438440
// only reserved when it's needed for the
439441
// first time (cuMemAllocFromPoolAsync).
440-
442+
#else
443+
// Only error if the user set a value >0 for the maximum size.
444+
// Otherwise, do nothing.
445+
if (Limits->maxPoolableSize > 0) {
446+
setErrorMessage(
447+
"The memory pool maximum size feature requires CUDA 12.2 or later.",
448+
UR_RESULT_ERROR_ADAPTER_SPECIFIC);
449+
throw UsmAllocationException(UR_RESULT_ERROR_ADAPTER_SPECIFIC);
450+
}
451+
#endif
441452
maxSize = Limits->maxPoolableSize;
442453
size_t chunkSize = 33554432; // 32MB
443454
size_t remainder = Limits->maxPoolableSize % chunkSize;
@@ -485,8 +496,8 @@ urUSMPoolCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
485496
try {
486497
*pPool = reinterpret_cast<ur_usm_pool_handle_t>(
487498
new ur_usm_pool_handle_t_(Context, Device, pPoolDesc));
488-
} catch (ur_result_t err) {
489-
return err;
499+
} catch (const UsmAllocationException &Ex) {
500+
return Ex.getError();
490501
} catch (...) {
491502
return UR_RESULT_ERROR_UNKNOWN;
492503
}

0 commit comments

Comments
 (0)