-
Notifications
You must be signed in to change notification settings - Fork 769
/
Copy pathusm.cpp
569 lines (507 loc) · 19.1 KB
/
usm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
//===--------- usm.cpp - CUDA Adapter -------------------------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <cassert>
#include "adapter.hpp"
#include "common.hpp"
#include "context.hpp"
#include "device.hpp"
#include "event.hpp"
#include "platform.hpp"
#include "queue.hpp"
#include "ur_util.hpp"
#include "usm.hpp"
#include <cuda.h>
/// USM: Implements USM Host allocations using CUDA Pinned Memory
/// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#page-locked-host-memory
UR_APIEXPORT ur_result_t UR_APICALL
urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
ur_usm_pool_handle_t hPool, size_t size, void **ppMem) {
auto alignment = pUSMDesc ? pUSMDesc->align : 0u;
auto pool = hPool ? hPool->HostMemPool.get() : hContext->MemoryPoolHost;
if (alignment) {
UR_ASSERT(isPowerOf2(alignment), UR_RESULT_ERROR_INVALID_VALUE);
*ppMem = umfPoolAlignedMalloc(pool, size, alignment);
} else {
*ppMem = umfPoolMalloc(pool, size);
}
if (*ppMem == nullptr) {
auto umfErr = umfPoolGetLastAllocationError(pool);
return umf::umf2urResult(umfErr);
}
return UR_RESULT_SUCCESS;
}
/// USM: Implements USM device allocations using a normal CUDA device pointer
///
UR_APIEXPORT ur_result_t UR_APICALL
urUSMDeviceAlloc(ur_context_handle_t, ur_device_handle_t hDevice,
const ur_usm_desc_t *pUSMDesc, ur_usm_pool_handle_t hPool,
size_t size, void **ppMem) {
auto alignment = pUSMDesc ? pUSMDesc->align : 0u;
ScopedContext SC(hDevice);
auto pool = hPool ? hPool->DeviceMemPool.get() : hDevice->MemoryPoolDevice;
if (alignment) {
UR_ASSERT(isPowerOf2(alignment), UR_RESULT_ERROR_INVALID_VALUE);
*ppMem = umfPoolAlignedMalloc(pool, size, alignment);
} else {
*ppMem = umfPoolMalloc(pool, size);
}
if (*ppMem == nullptr) {
auto umfErr = umfPoolGetLastAllocationError(pool);
return umf::umf2urResult(umfErr);
}
return UR_RESULT_SUCCESS;
}
/// USM: Implements USM Shared allocations using CUDA Managed Memory
///
UR_APIEXPORT ur_result_t UR_APICALL
urUSMSharedAlloc(ur_context_handle_t, ur_device_handle_t hDevice,
const ur_usm_desc_t *pUSMDesc, ur_usm_pool_handle_t hPool,
size_t size, void **ppMem) {
auto alignment = pUSMDesc ? pUSMDesc->align : 0u;
ScopedContext SC(hDevice);
auto pool = hPool ? hPool->SharedMemPool.get() : hDevice->MemoryPoolShared;
if (alignment) {
UR_ASSERT(isPowerOf2(alignment), UR_RESULT_ERROR_INVALID_VALUE);
*ppMem = umfPoolAlignedMalloc(pool, size, alignment);
} else {
*ppMem = umfPoolMalloc(pool, size);
}
if (*ppMem == nullptr) {
auto umfErr = umfPoolGetLastAllocationError(pool);
return umf::umf2urResult(umfErr);
}
return UR_RESULT_SUCCESS;
}
/// USM: Frees the given USM pointer associated with the context.
///
UR_APIEXPORT ur_result_t UR_APICALL urUSMFree(ur_context_handle_t hContext,
void *pMem) {
(void)hContext; // unused
return umf::umf2urResult(umfFree(pMem));
}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
ur_usm_alloc_info_t propName, size_t propValueSize,
void *pPropValue, size_t *pPropValueSizeRet) {
ur_result_t Result = UR_RESULT_SUCCESS;
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
try {
switch (propName) {
case UR_USM_ALLOC_INFO_TYPE: {
unsigned int Value;
// do not throw if cuPointerGetAttribute returns CUDA_ERROR_INVALID_VALUE
CUresult Ret = cuPointerGetAttribute(
&Value, CU_POINTER_ATTRIBUTE_IS_MANAGED, (CUdeviceptr)pMem);
if (Ret == CUDA_ERROR_INVALID_VALUE) {
// pointer not known to the CUDA subsystem
return ReturnValue(UR_USM_TYPE_UNKNOWN);
}
checkErrorUR(Ret, __func__, __LINE__ - 5, __FILE__);
if (Value) {
// pointer to managed memory
return ReturnValue(UR_USM_TYPE_SHARED);
}
UR_CHECK_ERROR(cuPointerGetAttribute(
&Value, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, (CUdeviceptr)pMem));
UR_ASSERT(Value == CU_MEMORYTYPE_DEVICE || Value == CU_MEMORYTYPE_HOST,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
if (Value == CU_MEMORYTYPE_DEVICE) {
// pointer to device memory
return ReturnValue(UR_USM_TYPE_DEVICE);
}
if (Value == CU_MEMORYTYPE_HOST) {
// pointer to host memory
return ReturnValue(UR_USM_TYPE_HOST);
}
// should never get here
ur::unreachable();
}
case UR_USM_ALLOC_INFO_BASE_PTR: {
#if CUDA_VERSION >= 10020
// CU_POINTER_ATTRIBUTE_RANGE_START_ADDR was introduced in CUDA 10.2
void *Base;
UR_CHECK_ERROR(cuPointerGetAttribute(
&Base, CU_POINTER_ATTRIBUTE_RANGE_START_ADDR, (CUdeviceptr)pMem));
return ReturnValue(Base);
#else
return UR_RESULT_ERROR_INVALID_VALUE;
#endif
}
case UR_USM_ALLOC_INFO_SIZE: {
#if CUDA_VERSION >= 10020
// CU_POINTER_ATTRIBUTE_RANGE_SIZE was introduced in CUDA 10.2
size_t Value;
UR_CHECK_ERROR(cuPointerGetAttribute(
&Value, CU_POINTER_ATTRIBUTE_RANGE_SIZE, (CUdeviceptr)pMem));
return ReturnValue(Value);
#else
return UR_RESULT_ERROR_INVALID_VALUE;
#endif
}
case UR_USM_ALLOC_INFO_DEVICE: {
// get device index associated with this pointer
unsigned int DeviceIndex;
UR_CHECK_ERROR(cuPointerGetAttribute(&DeviceIndex,
CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
(CUdeviceptr)pMem));
// cuda backend has only one platform containing all devices
ur_platform_handle_t platform;
ur_adapter_handle_t AdapterHandle = ur::cuda::adapter;
Result = urPlatformGet(AdapterHandle, 1, &platform, nullptr);
// get the device from the platform
ur_device_handle_t Device = platform->Devices[DeviceIndex].get();
return ReturnValue(Device);
}
case UR_USM_ALLOC_INFO_POOL: {
auto UMFPool = umfPoolByPtr(pMem);
if (!UMFPool) {
return UR_RESULT_ERROR_INVALID_VALUE;
}
ur_usm_pool_handle_t Pool = hContext->getOwningURPool(UMFPool);
if (!Pool) {
return UR_RESULT_ERROR_INVALID_VALUE;
}
return ReturnValue(Pool);
}
default:
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
} catch (ur_result_t Err) {
Result = Err;
}
return Result;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMImportExp(ur_context_handle_t, void *,
size_t Size) {
UR_ASSERT(Size > 0, UR_RESULT_ERROR_INVALID_VALUE);
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMReleaseExp(ur_context_handle_t,
void *) {
return UR_RESULT_SUCCESS;
}
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
ur_usm_pool_desc_t *PoolDesc)
: Context{Context} {
const void *pNext = PoolDesc->pNext;
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
switch (BaseDesc->stype) {
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
const ur_usm_pool_limits_desc_t *Limits =
reinterpret_cast<const ur_usm_pool_limits_desc_t *>(BaseDesc);
for (auto &config : DisjointPoolConfigs.Configs) {
config.MaxPoolableSize = Limits->maxPoolableSize;
config.SlabMinSize = Limits->minDriverAllocSize;
}
break;
}
default: {
throw UR_RESULT_ERROR_INVALID_ARGUMENT;
}
}
pNext = BaseDesc->pNext;
}
auto UmfHostParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host]);
HostMemPool = umf::poolMakeUniqueFromOpsProviderHandle(
umfDisjointPoolOps(), Context->MemoryProviderHost,
UmfHostParamsHandle.get())
.second;
for (const auto &Device : Context->getDevices()) {
auto UmfDeviceParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Device]);
DeviceMemPool = umf::poolMakeUniqueFromOpsProviderHandle(
umfDisjointPoolOps(), Device->MemoryProviderDevice,
UmfDeviceParamsHandle.get())
.second;
auto UmfSharedParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Shared]);
SharedMemPool = umf::poolMakeUniqueFromOpsProviderHandle(
umfDisjointPoolOps(), Device->MemoryProviderShared,
UmfSharedParamsHandle.get())
.second;
Context->addPool(this);
}
}
bool ur_usm_pool_handle_t_::hasUMFPool(umf_memory_pool_t *umf_pool) {
return DeviceMemPool.get() == umf_pool || SharedMemPool.get() == umf_pool ||
HostMemPool.get() == umf_pool;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreate(
/// [in] handle of the context object
ur_context_handle_t Context,
/// [in] pointer to USM pool descriptor. Can be chained with
/// ::ur_usm_pool_limits_desc_t
ur_usm_pool_desc_t *PoolDesc,
/// [out] pointer to USM memory pool
ur_usm_pool_handle_t *Pool) {
// Without pool tracking we can't free pool allocations.
if (PoolDesc->flags & UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
try {
*Pool = reinterpret_cast<ur_usm_pool_handle_t>(
new ur_usm_pool_handle_t_(Context, PoolDesc));
} catch (ur_result_t e) {
return e;
} catch (umf_result_t e) {
return umf::umf2urResult(e);
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolRetain(
/// [in] pointer to USM memory pool
ur_usm_pool_handle_t Pool) {
Pool->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolRelease(
/// [in] pointer to USM memory pool
ur_usm_pool_handle_t Pool) {
if (Pool->decrementReferenceCount() > 0) {
return UR_RESULT_SUCCESS;
}
Pool->Context->removePool(Pool);
delete Pool;
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetInfo(
/// [in] handle of the USM memory pool
ur_usm_pool_handle_t hPool,
/// [in] name of the pool property to query
ur_usm_pool_info_t propName,
/// [in] size in bytes of the pool property value provided
size_t propSize,
/// [out][optional][typename(propName, propSize)] value of the pool property
void *pPropValue,
/// [out][optional] size in bytes returned in pool property value
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
switch (propName) {
case UR_USM_POOL_INFO_REFERENCE_COUNT: {
return ReturnValue(hPool->getReferenceCount());
}
case UR_USM_POOL_INFO_CONTEXT: {
return ReturnValue(hPool->Context);
}
default: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
}
}
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_pool_desc_t *PoolDesc)
: Context{Context}, Device{Device} {
if (!(PoolDesc->flags & UR_USM_POOL_FLAG_USE_NATIVE_MEMORY_POOL_EXP))
throw UR_RESULT_ERROR_INVALID_ARGUMENT;
CUmemPoolProps MemPoolProps{};
size_t threshold = 0;
const void *pNext = PoolDesc->pNext;
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
switch (BaseDesc->stype) {
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
const ur_usm_pool_limits_desc_t *Limits =
reinterpret_cast<const ur_usm_pool_limits_desc_t *>(BaseDesc);
#if CUDA_VERSION >= 12020
// maxSize as a member of CUmemPoolProps was introduced in CUDA 12.2.
MemPoolProps.maxSize =
Limits->maxPoolableSize; // CUDA lazily reserves memory for pools in
// 32MB chunks. maxSize is elevated to the
// next 32MB multiple. Each 32MB chunk is
// only reserved when it's needed for the
// first time (cuMemAllocFromPoolAsync).
#else
// Only warn if the user set a value >0 for the maximum size.
// Otherwise, do nothing.
// Set maximum size is effectively ignored.
if (Limits->maxPoolableSize > 0)
UR_LOG(WARN, "The memory pool maximum size feature requires CUDA "
"12.2 or later.\n");
#endif
maxSize = Limits->maxPoolableSize;
size_t chunkSize = 33554432; // 32MB
size_t remainder = Limits->maxPoolableSize % chunkSize;
if (remainder != 0) {
maxSize = maxSize + chunkSize - remainder;
}
threshold = Limits->minDriverAllocSize;
break;
}
default: {
throw UR_RESULT_ERROR_INVALID_ARGUMENT;
}
}
pNext = BaseDesc->pNext;
}
MemPoolProps.allocType = CU_MEM_ALLOCATION_TYPE_PINNED;
// Clarification of what id means here:
// https://forums.developer.nvidia.com/t/incomplete-description-in-cumemlocation-v1-struct-reference/318701
MemPoolProps.location.id = Device->getIndex();
MemPoolProps.location.type = CU_MEM_LOCATION_TYPE_DEVICE;
UR_CHECK_ERROR(cuMemPoolCreate(&CUmemPool, &MemPoolProps));
// Release threshold is not a property when creating a pool.
// It must be set separately.
UR_CHECK_ERROR(urUSMPoolSetInfoExp(this,
UR_USM_POOL_INFO_RELEASE_THRESHOLD_EXP,
&threshold, 8 /*uint64_t*/));
}
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
ur_device_handle_t Device,
CUmemoryPool CUmemPool)
: Context{Context}, Device{Device}, CUmemPool(CUmemPool) {}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMPoolCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
ur_usm_pool_desc_t *pPoolDesc, ur_usm_pool_handle_t *pPool) {
// This entry point only supports native mem pools.
if (!(pPoolDesc->flags & UR_USM_POOL_FLAG_USE_NATIVE_MEMORY_POOL_EXP))
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
// Zero-init is on by default in CUDA.
// Read-only has no support in CUDA.
try {
*pPool = reinterpret_cast<ur_usm_pool_handle_t>(
new ur_usm_pool_handle_t_(Context, Device, pPoolDesc));
} catch (ur_result_t e) {
return e;
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMPoolDestroyExp(ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_usm_pool_handle_t hPool) {
UR_ASSERT(std::find(hContext->getDevices().begin(),
hContext->getDevices().end(),
hDevice) != hContext->getDevices().end(),
UR_RESULT_ERROR_INVALID_CONTEXT);
ScopedContext Active(hDevice);
try {
UR_CHECK_ERROR(cuMemPoolDestroy(hPool->getCudaPool()));
} catch (ur_result_t Err) {
return Err;
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetDefaultDevicePoolExp(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_usm_pool_handle_t *pPool) {
UR_ASSERT(std::find(hContext->getDevices().begin(),
hContext->getDevices().end(),
hDevice) != hContext->getDevices().end(),
UR_RESULT_ERROR_INVALID_CONTEXT);
ScopedContext Active(hDevice);
try {
CUmemoryPool cuPool;
UR_CHECK_ERROR(cuDeviceGetDefaultMemPool(&cuPool, hDevice->get()));
*pPool = reinterpret_cast<ur_usm_pool_handle_t>(
new ur_usm_pool_handle_t_(hContext, hDevice, cuPool));
} catch (ur_result_t Err) {
return Err;
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMPoolGetInfoExp(ur_usm_pool_handle_t hPool, ur_usm_pool_info_t propName,
void *pPropValue, size_t *pPropSizeRet) {
CUmemPool_attribute attr;
switch (propName) {
case UR_USM_POOL_INFO_RELEASE_THRESHOLD_EXP:
attr = CU_MEMPOOL_ATTR_RELEASE_THRESHOLD;
break;
case UR_USM_POOL_INFO_RESERVED_CURRENT_EXP:
attr = CU_MEMPOOL_ATTR_RESERVED_MEM_CURRENT;
break;
case UR_USM_POOL_INFO_RESERVED_HIGH_EXP:
attr = CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH;
break;
case UR_USM_POOL_INFO_USED_CURRENT_EXP:
attr = CU_MEMPOOL_ATTR_USED_MEM_CURRENT;
break;
case UR_USM_POOL_INFO_USED_HIGH_EXP:
attr = CU_MEMPOOL_ATTR_USED_MEM_HIGH;
break;
default:
// Unknown enumerator
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
uint64_t value = 0;
UR_CHECK_ERROR(
cuMemPoolGetAttribute(hPool->getCudaPool(), attr, (void *)&value));
if (pPropValue) {
*(size_t *)pPropValue = value;
}
if (pPropSizeRet) {
*(size_t *)pPropSizeRet = sizeof(size_t);
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMPoolSetInfoExp(ur_usm_pool_handle_t hPool, ur_usm_pool_info_t propName,
void *pPropValue, size_t) {
CUmemPool_attribute attr;
// All current values are expected to be of size uint64_t
switch (propName) {
case UR_USM_POOL_INFO_RELEASE_THRESHOLD_EXP:
attr = CU_MEMPOOL_ATTR_RELEASE_THRESHOLD;
break;
case UR_USM_POOL_INFO_RESERVED_HIGH_EXP:
attr = CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH;
break;
case UR_USM_POOL_INFO_USED_HIGH_EXP:
attr = CU_MEMPOOL_ATTR_USED_MEM_HIGH;
break;
default:
// Unknown enumerator
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
try {
UR_CHECK_ERROR(
cuMemPoolSetAttribute(hPool->getCudaPool(), attr, pPropValue));
} catch (ur_result_t Err) {
return Err;
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetDevicePoolExp(
ur_context_handle_t, ur_device_handle_t, ur_usm_pool_handle_t *) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolSetDevicePoolExp(
ur_context_handle_t, ur_device_handle_t, ur_usm_pool_handle_t) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
UR_APIEXPORT ur_result_t UR_APICALL
urUSMPoolTrimToExp(ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_usm_pool_handle_t hPool, size_t minBytesToKeep) {
UR_ASSERT(std::find(hContext->getDevices().begin(),
hContext->getDevices().end(),
hDevice) != hContext->getDevices().end(),
UR_RESULT_ERROR_INVALID_CONTEXT);
ScopedContext Active(hDevice);
try {
UR_CHECK_ERROR(cuMemPoolTrimTo(hPool->getCudaPool(), minBytesToKeep));
} catch (ur_result_t Err) {
return Err;
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}