Coverage for cuda/core/_memory/_memory_pool.pyx: 89.18%
194 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
5from __future__ import annotations
7cimport cython
8from libc.limits cimport ULLONG_MAX
9from libc.stdint cimport uint64_t, uintptr_t
10from libc.string cimport memset
12from cuda.bindings cimport cydriver
13from cuda.core._memory._buffer cimport Buffer, Buffer_from_deviceptr_handle, MemoryResource
14from cuda.core._memory cimport _ipc
15# cumemlocation_from_id is referenced only from a CUDA 13 branch. cython-lint
16# does not evaluate compile-time IF blocks, so it needs a pragma to be seen as used.
17from cuda.core._memory._location cimport cumemlocation_from_id # no-cython-lint
18from cuda.core._stream cimport Stream_accept, Stream
19from cuda.core._rt cimport (
20 MemoryPoolHandle,
21 DevicePtrHandle,
22 create_mempool_handle,
23 deviceptr_alloc_from_pool,
24 get_last_error,
25 attach_rollback_failure,
26 as_cu,
27 as_py,
28)
29from cuda.core._rt cimport create_mempool_handle_ref # no-cython-lint
31from cuda.core._utils.cuda_utils cimport (
32 HANDLE_RETURN,
33)
34from cuda.core._utils.version import driver_version # no-cython-lint
36import uuid
37from typing import TYPE_CHECKING
39if TYPE_CHECKING:
40 from cuda.core.graph import GraphBuilder
41 from cuda.core.typing import DevicePointerType
44# Pool attribute reads and writes and cuMemPoolTrimTo are potentially unsafe
45# calls during stream capture: the driver refuses them, and invalidates the
46# capture, while a global-mode capture is active on any thread or a
47# thread-local one on the calling thread. Capture mode is a per-thread
48# property, so the calling thread is switched to relaxed mode around such a
49# call and its previous mode is restored afterwards. This has no observable
50# effect when nothing is capturing. The call executes immediately rather than
51# being recorded into a graph, which is the intent for a process-wide pool.
52cdef inline int _enter_relaxed_capture_mode(cydriver.CUstreamCaptureMode* mode) except?-1 nogil:
53 # On return, mode holds the thread's previous capture mode.
54 mode[0] = cydriver.CU_STREAM_CAPTURE_MODE_RELAXED 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjc+ kclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfOcPcQcRcScTcG Uc^ VcqfxfyfzfWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadCebdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf, #bCfqbnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c td$b%bob[ ] gb$ * DbCbrbDeEeFeGeHeY udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
55 return HANDLE_RETURN(cydriver.cuThreadExchangeStreamCaptureMode(mode)) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjc+ kclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfOcPcQcRcScTcG Uc^ VcqfxfyfzfWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadCebdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf, #bCfqbnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c td$b%bob[ ] gb$ * DbCbrbDeEeFeGeHeY udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
58cdef int _exit_relaxed_capture_mode(
59 cydriver.CUresult err, cydriver.CUstreamCaptureMode* mode) except?-1 nogil:
60 """Restore the thread's capture mode, then raise if the call or the restore failed."""
61 cdef cydriver.CUresult restore_err = cydriver.cuThreadExchangeStreamCaptureMode(mode) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjc+ kclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfOcPcQcRcScTcG Uc^ VcqfxfyfzfWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadCebdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf, #bCfqbnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c td$b%bob[ ] gb$ * DbCbrbDeEeFeGeHeY udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
62 if err != cydriver.CUDA_SUCCESS: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjc+ kclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfOcPcQcRcScTcG Uc^ VcqfxfyfzfWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadCebdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf, #bCfqbnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c td$b%bob[ ] gb$ * DbCbrbDeEeFeGeHeY udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
63 with gil:
64 try:
65 HANDLE_RETURN(err)
66 except:
67 if restore_err != cydriver.CUDA_SUCCESS:
68 # The call's error propagates with the restore failure
69 # attached as a note (error handling policy).
70 attach_rollback_failure(
71 b"cuThreadExchangeStreamCaptureMode", restore_err,
72 b"failed to restore the thread's stream capture mode")
73 raise
74 return HANDLE_RETURN(restore_err) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjc+ kclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfOcPcQcRcScTcG Uc^ VcqfxfyfzfWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadCebdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf, #bCfqbnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c td$b%bob[ ] gb$ * DbCbrbDeEeFeGeHeY udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
77cdef class _MemPoolAttributes:
78 """Provides access to memory pool attributes.
80 Setting an attribute changes the memory pool itself, which other memory
81 resources that share the pool, such as a device's default pool, also see.
82 Reading or setting an attribute does not affect a stream capture in
83 progress on any thread. The driver rejects reading or setting an
84 attribute of a memory resource mapped from another process
85 (``is_mapped``), which raises ``CUDAError``.
86 """
87 cdef:
88 MemoryPoolHandle _h_pool
90 def __init__(self, *args, **kwargs) -> None:
91 raise RuntimeError("_MemPoolAttributes cannot be instantiated directly. Please use MemoryResource APIs.") 2+h
93 @staticmethod
94 cdef _MemPoolAttributes _init(MemoryPoolHandle h_pool):
95 cdef _MemPoolAttributes self = _MemPoolAttributes.__new__(_MemPoolAttributes) 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
96 self._h_pool = h_pool 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
97 return self 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
99 def __repr__(self) -> str:
100 return f"{self.__class__.__name__}(%s)" % ", ".join( 1dia
101 f"{attr}={getattr(self, attr)}" for attr in dir(self) 1dia
102 if not attr.startswith("_") 1dia
103 )
105 cdef int _getattribute(self, cydriver.CUmemPool_attribute attr_enum, void* value) except?-1:
106 cdef cydriver.CUstreamCaptureMode mode
107 cdef cydriver.CUresult err
108 with nogil: 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
109 _enter_relaxed_capture_mode(&mode) 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
110 err = cydriver.cuMemPoolGetAttribute(as_cu(self._h_pool), attr_enum, value) 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
111 _exit_relaxed_capture_mode(err, &mode) 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
112 return 0 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
114 cdef int _setattribute(self, cydriver.CUmemPool_attribute attr_enum, void* value) except?-1:
115 cdef cydriver.CUstreamCaptureMode mode
116 cdef cydriver.CUresult err
117 with nogil: 1pqgstuvwxjkl012345HIJorhefmnbc
118 _enter_relaxed_capture_mode(&mode) 1pqgstuvwxjkl012345HIJorhefmnbc
119 err = cydriver.cuMemPoolSetAttribute(as_cu(self._h_pool), attr_enum, value) 1pqgstuvwxjkl012345HIJorhefmnbc
120 _exit_relaxed_capture_mode(err, &mode) 1pqgstuvwxjkl012345HIJorhefmnbc
121 return 0 1pqgstuvwxjkl012345HIJorhefmnbc
123 cdef int _setflag(self, cydriver.CUmemPool_attribute attr_enum, bint flag) except?-1:
124 cdef int value = flag 1pqgstuvwxjkl
125 return self._setattribute(attr_enum, &value) 1pqgstuvwxjkl
127 cdef int _reset_watermark(self, cydriver.CUmemPool_attribute attr_enum, str name, value) except?-1:
128 if value != 0: 1pqgstuvwxjklefmnbc
129 raise AttributeError(f"Attribute '{name}' may only be set to zero (got {value}).") 1pqg
130 cdef cydriver.cuuint64_t zero = 0 1stuvwxjklefmnbc
131 return self._setattribute(attr_enum, &zero) 1stuvwxjklefmnbc
133 @property
134 def reuse_follow_event_dependencies(self) -> bool:
135 """Allow memory to be reused when there are event dependencies between streams."""
136 cdef int value
137 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES, &value) 1:)@XTdiapqg
138 return bool(value) 1:)@XTdiapqg
140 @reuse_follow_event_dependencies.setter
141 def reuse_follow_event_dependencies(self, value: bool) -> None:
142 self._setflag(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES, value) 1pqg
144 @property
145 def reuse_allow_opportunistic(self) -> bool:
146 """Allow reuse of completed frees without dependencies."""
147 cdef int value
148 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC, &value) 1/(?WSdiapqgstuvwxjkl
149 return bool(value) 1/(?WSdiapqgstuvwxjkl
151 @reuse_allow_opportunistic.setter
152 def reuse_allow_opportunistic(self, value: bool) -> None:
153 self._setflag(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC, value) 1pqgstuvwxjkl
155 @property
156 def reuse_allow_internal_dependencies(self) -> bool:
157 """Allow insertion of new stream dependencies for memory reuse."""
158 cdef int value
159 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES, &value) 1.'=VRdiapqg
160 return bool(value) 1.'=VRdiapqg
162 @reuse_allow_internal_dependencies.setter
163 def reuse_allow_internal_dependencies(self, value: bool) -> None:
164 self._setflag(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES, value) 1pqg
166 @property
167 def release_threshold(self) -> int:
168 """
169 Amount of reserved memory, in bytes, to hold before OS release. When
170 more than this is reserved, the pool returns unused memory to the OS
171 at the next synchronization of an event, stream or device.
172 """
173 cdef cydriver.cuuint64_t value
174 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD, &value) 2HbIbJb- % ; U Q d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J
175 return int(value) 2HbIbJb- % ; U Q d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J
177 @release_threshold.setter
178 def release_threshold(self, uint64_t value) -> None:
179 self._setattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD, &value) 1pqgstuvwxjkl012345HIJorh
181 @property
182 def reserved_mem_current(self) -> int:
183 """Current amount of backing memory allocated."""
184 cdef cydriver.cuuint64_t value
185 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RESERVED_MEM_CURRENT, &value) 1EC86K!AyOMdiaorhemb
186 return int(value) 1EC86K!AyOMdiaorhemb
188 @property
189 def reserved_mem_high(self) -> int:
190 """
191 High watermark of backing memory allocated. It can be set to zero to
192 reset it to the current value.
193 """
194 cdef cydriver.cuuint64_t value
195 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH, &value) 186!OMdiaemb
196 return int(value) 186!OMdiaemb
198 @reserved_mem_high.setter
199 def reserved_mem_high(self, value: int) -> None:
200 self._reset_watermark( 1pqgemb
201 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH, "reserved_mem_high", value)
203 @property
204 def used_mem_current(self) -> int:
205 """Current amount of memory in use."""
206 cdef cydriver.cuuint64_t value
207 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_USED_MEM_CURRENT, &value) 1,FD97L#BzPNdiafncY
208 return int(value) 1,FD97L#BzPNdiafncY
210 @property
211 def used_mem_high(self) -> int:
212 """
213 High watermark of memory in use. It can be set to zero to reset it to
214 the current value.
215 """
216 cdef cydriver.cuuint64_t value
217 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_USED_MEM_HIGH, &value) 197#PN_`Zdiafnc
218 return int(value) 197#PN_`Zdiafnc
220 @used_mem_high.setter
221 def used_mem_high(self, value: int) -> None:
222 self._reset_watermark( 1pqgstuvwxjklfnc
223 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_USED_MEM_HIGH, "used_mem_high", value)
226cdef class _MemPool(MemoryResource):
228 def __cinit__(self) -> None:
229 # Note: subclasses use MP_init_create_pool or MP_init_current_pool to initialize.
230 self._mempool_owned = False 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncocpcqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmgwfDfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVcqfxfyfzf)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadCebdXbYbZb0bEbFbcdddedAffdmeBbnegdhdidjdkdldmdndodpdqdrdsdJe9b!bpbBf'bQe, #bCfGfWe1b#h7engXeYeZe$hGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0etd$b%bob[ ] Ifgb$ * DbCbrb%hDeEeFeGeHeY udvdwdxdSeTeUeVeoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
231 self._ipc_data = None 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncocpcqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmgwfDfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVcqfxfyfzf)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadCebdXbYbZb0bEbFbcdddedAffdmeBbnegdhdidjdkdldmdndodpdqdrdsdJe9b!bpbBf'bQe, #bCfGfWe1b#h7engXeYeZe$hGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0etd$b%bob[ ] Ifgb$ * DbCbrb%hDeEeFeGeHeY udvdwdxdSeTeUeVeoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
232 self._attributes = None 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncocpcqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmgwfDfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVcqfxfyfzf)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadCebdXbYbZb0bEbFbcdddedAffdmeBbnegdhdidjdkdldmdndodpdqdrdsdJe9b!bpbBf'bQe, #bCfGfWe1b#h7engXeYeZe$hGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0etd$b%bob[ ] Ifgb$ * DbCbrb%hDeEeFeGeHeY udvdwdxdSeTeUeVeoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
234 def close(self) -> None:
235 """Release this object's reference to the memory pool.
237 New allocations and operations requiring this object's pool handle are
238 rejected afterward. For owned pools, release of the underlying pool's
239 resources is deferred until all outstanding allocations are freed and
240 pending free operations complete. :meth:`deallocate` remains available
241 after :meth:`close` so existing allocations can still be released.
242 """
243 _MP_close(self) 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h
245 @property
246 def is_closed(self) -> bool:
247 """Whether this memory resource has been closed."""
248 return self._h_pool.get() == NULL 2Je
250 def allocate(self, size_t size, *, stream: Stream | GraphBuilder) -> Buffer:
251 """Allocate a buffer of the requested size.
253 Parameters
254 ----------
255 size : int
256 The size of the buffer to allocate, in bytes.
257 stream : :obj:`~_stream.Stream` | :obj:`~graph.GraphBuilder`
258 Keyword-only. The stream on which to perform the allocation
259 asynchronously. Must be passed explicitly; pass
260 ``device.default_stream`` to use the default stream.
262 Returns
263 -------
264 Buffer
265 The allocated buffer object, which is accessible on the device that this memory
266 resource was created for.
267 """
268 MP_check_open(self) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbkclcmcncoc3fpc4fqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNchbibJfKfjbkbG LfMfNfOfLbMbNbObPbQbRbSbTbUbPfQfRfSfTfUfVfWfXfYfZf0fVbWb1f2fHfbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsdJe9b!bpb'bqbE C F D d (bo e f tdY udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
269 if self.is_mapped: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbkclcmcncoc3fpc4fqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNchbibJfKfjbkbG LfMfNfOfLbMbNbObPbQbRbSbTbUbPfQfRfSfTfUfVfWfXfYfZf0fVbWb1f2fHfbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'bqbE C F D d (bo e f tdY udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
270 raise TypeError("Cannot allocate from a mapped IPC-enabled memory resource")
271 cdef Stream s = Stream_accept(stream) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbkclcmcncoc3fpc4fqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNchbibJfKfjbkbG LfMfNfOfLbMbNbObPbQbRbSbTbUbPfQfRfSfTfUfVfWfXfYfZf0fVbWb1f2fHfbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'bqbE C F D d (bo e f tdY udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
272 return _MP_allocate(self, size, s) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbkclcmcncoc3fpc4fqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNchbibJfKfjbkbG LfMfNfOfLbMbNbObPbQbRbSbTbUbPfQfRfSfTfUfVfWfXfYfZf0fVbWb1f2fHfbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'bqbE C F D d (bo e f tdY udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
274 def deallocate(
275 self,
276 ptr: DevicePointerType,
277 size_t size,
278 *,
279 stream: Stream | GraphBuilder
280 ) -> None:
281 """Deallocate a buffer previously allocated by this resource.
283 Parameters
284 ----------
285 ptr : :obj:`~_memory.DevicePointerType`
286 The pointer or handle to the buffer to deallocate.
287 size : int
288 The size of the buffer to deallocate, in bytes.
289 stream : :obj:`~_stream.Stream` | :obj:`~graph.GraphBuilder`
290 Keyword-only. The stream on which to perform the deallocation
291 asynchronously. Must be passed explicitly; pass
292 ``device.default_stream`` to use the default stream.
293 """
294 cdef Stream s = Stream_accept(stream) 2, 0e
295 _MP_deallocate(self, <uintptr_t>ptr, size, s) 2, 0e
297 def trim(self, size_t min_bytes_to_keep=0) -> None:
298 """Release unused memory held by the memory pool back to the OS.
300 Memory that backs live allocations is not released, nor is memory
301 freed on a stream until the host has observed the free through a
302 synchronization. Trimming does not affect a stream capture in progress
303 on any thread. The driver rejects trimming a memory resource mapped
304 from another process (``is_mapped``), which raises ``CUDAError``.
306 Parameters
307 ----------
308 min_bytes_to_keep : int, optional
309 Reserved memory, in bytes, that the pool keeps. Defaults to 0,
310 which releases all unused memory.
311 """
312 MP_check_open(self) 1stuvwxjklorhefmnbc
313 cdef cydriver.CUstreamCaptureMode mode
314 cdef cydriver.CUresult err
315 with nogil: 1stuvwxjklorhefmnbc
316 _enter_relaxed_capture_mode(&mode) 1stuvwxjklorhefmnbc
317 err = cydriver.cuMemPoolTrimTo(as_cu(self._h_pool), min_bytes_to_keep) 1stuvwxjklorhefmnbc
318 _exit_relaxed_capture_mode(err, &mode) 1stuvwxjklorhefmnbc
320 @property
321 @cython.critical_section
322 def attributes(self) -> _MemPoolAttributes:
323 """:obj:`~_memory._memory_pool._MemPoolAttributes` object with the attributes of the memory pool."""
324 MP_check_open(self) 2HbIbJbJe, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
325 cdef _MemPoolAttributes attributes
326 if self._attributes is None: 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
327 attributes = _MemPoolAttributes._init(self._h_pool) 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
328 if self._attributes is None: 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
329 self._attributes = attributes 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
330 return self._attributes 2HbIbJb, - % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c Y
332 @property
333 def handle(self) -> object:
334 """Handle to the underlying memory pool."""
335 return as_py(self._h_pool) 2lbmbQe, #b
337 @property
338 def is_handle_owned(self) -> bool:
339 """Whether the memory resource handle is owned. If False, ``close`` has no effect."""
340 return self._mempool_owned 2Qe#b
342 @property
343 def is_ipc_enabled(self) -> bool:
344 """Whether this memory resource has IPC enabled."""
345 return self._ipc_data is not None 2,h8e-hOchb9eibPcJf!e6fQcKf#e7fRcjb$ekbScRe'h%e(hTcG .h'e/hUc^ 6e)h(e*hVcqfLf)e8fWcMf*e9fXcNf+e!fYcOf,e#fZc:hLb;h{ =hMb?h| @h-e[h0c]h.e^h1c_h/e`h:e{h;e|h=e}h?e~h@eai2cbi3cci4cdi5cei6cfi7cgi[ehi8cii]eji9ckiNbliObmiPbni} oi~ piabqiQbribbsi^eti!cuiRbvicbwiSbxidbyi#cziTbAiebBiUbCifbDi$cEi%cFi'cGi(cHi_eIi)cJi`eKi{eLi|eMi*cNi+cOi,cPf}eQf~ePiafRfbfSfcfQidfTfefUfffRigf$f-c%f.cSi/c'f:c(f;cTi=c)f?c*f@cUi[cVfhf+f]cWfif,f^cXfjf-f_cYfkf.f`cZflf/f{clbmb0fmf:f|cVbWb1fnf;f}c2fof=f~cHfpf5fadCeXbYbZb0bEbFb9b!b'bGb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N (bgb$ * SeTeUeVe3b4b
347 @property
348 def is_mapped(self) -> bool:
349 """
350 Whether this is a mapping of an IPC-enabled memory resource from
351 another process. If True, allocation is not permitted.
352 """
353 return self._ipc_data is not None and self._ipc_data._is_mapped 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG ^ Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
355 @property
356 def uuid(self) -> uuid.UUID | None:
357 """
358 A universally unique identifier for this memory resource. Meaningful
359 only for IPC-enabled memory resources.
360 """
361 return getattr(self._ipc_data, 'uuid', None) 2hbib'h(hG ^ 6e)h*hHf5fEbFb
364cdef int MP_init_create_pool(
365 _MemPool self,
366 cydriver.CUmemLocationType loc_type,
367 int loc_id,
368 cydriver.CUmemAllocationType alloc_type,
369 bint ipc_enabled,
370 size_t max_size,
371) except? -1:
372 """Initialize a _MemPool by creating a new memory pool with the given
373 parameters.
375 Sets ``_h_pool`` (owning), ``_mempool_owned``, and ``_ipc_data``.
376 """
377 cdef cydriver.CUmemPoolProps properties
378 memset(&properties, 0, sizeof(cydriver.CUmemPoolProps)) 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
380 properties.allocType = alloc_type 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
381 properties.handleTypes = ( 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
382 _ipc.IPC_HANDLE_TYPE if ipc_enabled 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
383 else cydriver.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_NONE 2sbtbubvbwbxbybzbAbKb+ DfEfFfmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- E 8 . / : F 9 ; K ! = ? @ L # U A O V W X B P _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb* DbrbY oepeqereseteuevewexeyezeAeBe
384 )
385 properties.location.id = loc_id 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
386 properties.location.type = loc_type 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
387 properties.maxSize = max_size 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
389 self._mempool_owned = True 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
390 self._h_pool = create_mempool_handle(properties) 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
391 if not self._h_pool: 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] Ifgb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
392 HANDLE_RETURN(get_last_error()) 2If
393 raise RuntimeError(
394 f"Failed to initialize {self.__class__.__name__}: "
395 "cuda-core returned an empty memory pool handle without recording a CUDA error. "
396 "This is an internal cuda-core error; please report it with your CUDA driver, "
397 "CUDA Toolkit, and cuda-python versions."
398 )
400 if ipc_enabled: 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] gb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
401 alloc_handle = _ipc.MP_export_mempool(self) 28eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFb% C 6 ' ( ) D 7 Q y M R S T z N $ CbrbSeTeUeVe3b4b
402 self._ipc_data = _ipc.IPCDataForMR(alloc_handle, False) 28eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFb% C 6 ' ( ) D 7 Q y M R S T z N $ CbrbSeTeUeVe3b4b
404 return 0 2sbtbubvbwbxbybzbAbKb+ DfEfFf8eOchb9eibPc!eQc#eRcjb$ekbScRe%eTcG 'eUc^ 6e(eVc)eWc*eXc+eYc,eZcLb{ Mb| -e0c.e1c/e:e;e=e?e@e2c3c4c5c6c7c[e8c]e9cNbObPb} ~ abQbbb^e!cRbcbSbdb#cTbebUbfb$c%c'c(c_e)c`e{e|e*c+c,c}e~eafbfcfdfefffgf-c.c/c:c;c=c?c@c[chf]cif^cjf_ckf`clf{clbmbmf|cVbWbnf}cof~cpfadXbYbZb0bEbFbmeBbnepb'bQe, #bGfWe1bXeYeZeGb2b- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l (b0 1 2 3 4 5 H I J o r h e f m n b c 0e[ ] gb$ * DbCbrbY SeTeUeVeoepeqeresete3b4buevewexeyezeAeBe
407cdef int MP_init_current_pool(
408 _MemPool self,
409 cydriver.CUmemLocationType loc_type,
410 int loc_id,
411 cydriver.CUmemAllocationType alloc_type,
412) except? -1:
413 """Initialize a _MemPool by getting the driver's current pool for a
414 location and allocation type.
416 Sets ``_h_pool`` (non-owning) via ``cuMemGetMemPool``.
417 Requires CUDA 13+.
418 """
419 IF CUDA_CORE_BUILD_MAJOR >= 13:
420 cdef cydriver.CUmemoryPool pool
421 cdef cydriver.CUmemLocation loc = cumemlocation_from_id(loc_type, loc_id) 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
422 with nogil: 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
423 HANDLE_RETURN(cydriver.cuMemGetMemPool(&pool, &loc, alloc_type)) 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
424 self._h_pool = create_mempool_handle_ref(pool) 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
425 self._mempool_owned = False 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
426 return 0 2KeLeMeNeOePe~fagbgcg1e2edg3eeg4efg5egghgigjgkglgmg7engnb$b%bobDeEeFeGeHe
427 ELSE:
428 raise RuntimeError(
429 "Getting the current memory pool requires CUDA 13.0 or later"
430 )
433cdef int MP_raise_release_threshold(_MemPool self) except? -1:
434 """Raise the pool's release threshold to ULLONG_MAX if currently zero.
436 By default the release threshold is 0, meaning memory is returned to
437 the OS as soon as there are no active suballocations. Setting it to
438 ULLONG_MAX avoids repeated OS round-trips.
440 The read and the write run in relaxed capture mode, like every pool
441 attribute access (see ``_enter_relaxed_capture_mode``).
442 """
443 MP_check_open(self) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
444 cdef cydriver.cuuint64_t current_threshold
445 cdef cydriver.cuuint64_t max_threshold = ULLONG_MAX 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
446 cdef cydriver.CUstreamCaptureMode mode
447 cdef cydriver.CUresult err
448 with nogil: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
449 _enter_relaxed_capture_mode(&mode) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
450 err = cydriver.cuMemPoolGetAttribute( 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
451 as_cu(self._h_pool),
452 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD,
453 ¤t_threshold
454 )
455 if err == cydriver.CUDA_SUCCESS and current_threshold == 0: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
456 err = cydriver.cuMemPoolSetAttribute( 28b
457 as_cu(self._h_pool),
458 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD,
459 &max_threshold
460 )
461 _exit_relaxed_capture_mode(err, &mode) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
462 return 0 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcrfsftf5b6b7bufvfHbIbJbccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcwfqfxfyfzfbdcdddedAffdgdhdidjdkdldmdndodpdqdrdsdJe9b!bBf#bCfqbtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
465cdef int MP_set_access(
466 _MemPool self, const cydriver.CUmemAccessDesc* desc, size_t count,
467 bint retry_already_mapped=False) except? -1:
468 """Set device access to the pool.
470 Runs in relaxed capture mode, like every pool attribute access (see
471 ``_enter_relaxed_capture_mode``): the driver refuses cuMemPoolSetAccess,
472 and invalidates the capture, while a global-mode capture is active on
473 any thread or a thread-local one on the calling thread.
475 With ``retry_already_mapped``, each entry is set on its own, and an
476 identical second call follows a CUDA_ERROR_ALREADY_MAPPED. Importing a
477 pool that is already imported in this process returns the same
478 CUmemoryPool. Once its previous owner has revoked access and destroyed its
479 import, the driver can still hold the pool and fail a grant over the
480 mapping that an unsynchronized free left behind. The identical retry
481 succeeds (seen on drivers 580 and 595); with several devices, one retry of
482 a combined call is not enough. Any other status, and a second failure for
483 an entry, raise.
484 """
485 cdef cydriver.CUstreamCaptureMode mode
486 cdef cydriver.CUresult err = cydriver.CUDA_SUCCESS 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
487 cdef size_t i
488 with nogil: 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
489 _enter_relaxed_capture_mode(&mode) 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
490 if not retry_already_mapped: 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
491 err = cydriver.cuMemPoolSetAccess(as_cu(self._h_pool), desc, count) 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
492 else:
493 for i in range(count):
494 err = cydriver.cuMemPoolSetAccess(as_cu(self._h_pool), desc + i, 1)
495 if err == cydriver.CUDA_ERROR_ALREADY_MAPPED:
496 err = cydriver.cuMemPoolSetAccess(as_cu(self._h_pool), desc + i, 1)
497 if err != cydriver.CUDA_SUCCESS:
498 break
499 _exit_relaxed_capture_mode(err, &mode) 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
500 return 0 2+ OcPcQcRcScTcUcVcWcXcYcZc{ | 0c1c2c3c4c5c6c7c8c9c} ~ abbb!ccbdb#cebfb$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{clbmb|c}c~cadnbU Q A y O M V R W S X T B z P N Z a g j k l H I J h b c $b%bob[ ] gb$ * DbCbrbDeEeFeGeHe
503cdef bint MP_location_query_available() except? -1:
504 """Whether ``MP_get_location`` can query a pool's location.
506 ``CU_MEMPOOL_ATTR_LOCATION_TYPE`` and ``_ID`` are 13.2 driver attributes.
507 Every cuda-bindings at or above the CUDA 13 floor defines them, so only the
508 driver can lack them; an older driver rejects them as invalid.
509 """
510 IF CUDA_CORE_BUILD_MAJOR >= 13:
511 # Not cy_driver_version(): imports run concurrently on free-threaded
512 # builds, and its cache is filled without synchronization. Tests replace
513 # this module's driver_version to exercise the pre-13.2 fallback.
514 return driver_version() >= (13, 2, 0) 2G ^ Ce
515 ELSE:
516 return False
519cdef int MP_get_location(_MemPool self, cydriver.CUmemLocation* loc) except? -1:
520 """Store the pool's location type and ID in ``loc``.
522 Runs in relaxed capture mode, like every pool attribute access (see
523 ``_enter_relaxed_capture_mode``). Requires a CUDA 13 build and a 13.2 or
524 later driver (``MP_location_query_available``).
525 """
526 IF CUDA_CORE_BUILD_MAJOR >= 13:
527 cdef int loc_type = 0 2G ^ Ce
528 cdef int loc_id = 0 2G ^ Ce
529 cdef cydriver.CUstreamCaptureMode mode
530 cdef cydriver.CUresult err
531 with nogil: 2G ^ Ce
532 _enter_relaxed_capture_mode(&mode) 2G ^ Ce
533 err = cydriver.cuMemPoolGetAttribute( 2G ^ Ce
534 as_cu(self._h_pool),
535 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_LOCATION_TYPE,
536 &loc_type
537 )
538 if err == cydriver.CUDA_SUCCESS: 2G ^ Ce
539 err = cydriver.cuMemPoolGetAttribute( 2G ^ Ce
540 as_cu(self._h_pool),
541 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_LOCATION_ID,
542 &loc_id
543 )
544 _exit_relaxed_capture_mode(err, &mode) 2G ^ Ce
545 loc.type = <cydriver.CUmemLocationType>loc_type 2G ^ Ce
546 loc.id = loc_id 2G ^ Ce
547 return 0 2G ^ Ce
548 ELSE:
549 raise RuntimeError(
550 "Querying the location of a memory pool requires a CUDA 13 build of cuda.core"
551 )
554# Raise an exception if the given stream is capturing.
555# A result of CU_STREAM_CAPTURE_STATUS_INVALIDATED is considered an error.
556cdef inline int check_not_capturing(cydriver.CUstream s) except?-1 nogil:
557 cdef cydriver.CUstreamCaptureStatus capturing
558 HANDLE_RETURN(cydriver.cuStreamIsCapturing(s, &capturing)) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
559 if capturing != cydriver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_NONE: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
560 raise RuntimeError("_MemPool cannot perform memory operations on " 25b6b7b
561 "a capturing stream (consider using GraphMemoryResource).")
564cdef Buffer _MP_allocate(_MemPool self, size_t size, Stream stream, type cls = Buffer):
565 MP_check_open(self) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
566 cdef cydriver.CUstream s = as_cu(stream._h_stream) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
567 cdef DevicePtrHandle h_ptr
568 with nogil: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
569 check_not_capturing(s) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
570 h_ptr = deviceptr_alloc_from_pool(size, self._h_pool, stream._h_stream) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
571 if not h_ptr: 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
572 HANDLE_RETURN(get_last_error()) 2pb
573 raise RuntimeError(
574 f"Failed to allocate {size} bytes from {self.__class__.__name__}: "
575 "cuda-core returned an empty allocation handle without recording a CUDA error. "
576 "This is an internal cuda-core error; please report it with your CUDA driver, "
577 "CUDA Toolkit, and cuda-python versions."
578 )
579 return Buffer_from_deviceptr_handle(h_ptr, size, self, None, cls) 2)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbc5b6b7bsbtbubvbwbxbybzbccdcecfcgchcicjcAbKb+ kclcmcncoc3fpc4fqcrcsctcucvcwcxcycKeLeMezcAc8bBcCcDcEcFcGcHcIcJcKcLcMcNcNeOePe?f@f[f1e2e3e4e5e]f^f_f`f{f|f}fhbibJf6fKf7fjbkbG Lf8fMf9fNf!fOf#fLb{ Mb| NbObPb} ~ abQbbbRbcbSbdbTbebUbfbPfQfRfSfTfUf$f%f'f(f)f*fVf+fWf,fXf-fYf.fZf/f0f:fVbWb1f;f2f=fHf5fbdXbYbZb0bEbFbcdddedfdmeBbnegdhdidjdkdldmdndodpdqdrdsd9b!bpb'b1b7eGbqb2bnbE C F D K L A y B z d i a (bo r h e f m n b c td$b%bob[ ] gb$ * Y udvdwdxdoepeqeresete3b4buevewexeyezeAeBeydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekele
582cdef inline void _MP_deallocate(
583 _MemPool self, uintptr_t ptr, size_t size, Stream stream
584) except *:
585 cdef cydriver.CUstream s = as_cu(stream._h_stream) 2, 0e
586 cdef cydriver.CUdeviceptr devptr = <cydriver.CUdeviceptr>ptr 2, 0e
587 with nogil: 2, 0e
588 HANDLE_RETURN(cydriver.cuMemFreeAsync(devptr, s)) 2, 0e
590cdef inline _MP_close(_MemPool self):
591 if not self._h_pool: 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h
592 return 2Qe
594 # Reset members in declaration order.
595 # The RAII deleter calls cuMemPoolDestroy if this is an owning handle.
596 self._h_pool.reset() 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h
597 self._mempool_owned = False 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h
598 self._ipc_data = None 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h
599 self._attributes = None 2sbtbubvbwbxbybzbAbKb+ KeLeMeNeOePeogpghbqgibrgsgtgugvgjbwgkbxgReygzgG AgBg^ CgDgEgFgGgHgIgJgKgLgMgNgOgPgQgRgSgTgUgVgWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g:g;g=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhzhAhBhChDhEhFhGhlbmbHhIhJhKhLhMhNhOhPhQhCeRhShThUhVhWhBbJepbQeWe1bXeYeZeGbqb2bnb- % E C 8 6 . ' / ( : ) F D 9 7 ; K ! = ? @ L # U Q A y O M V R W S X T B z P N _ ` Z d i a p q g s t u v w x j k l 0 1 2 3 4 5 H I J o r h e f m n b c ob[ ] $ * DbCbrbDeEeFeGeHeSeTeUeVeXhYhZh0h1h2h3h4h5h6h7h8h9h!h