Coverage for cuda/core/_memory/_memory_pool.pyx: 92.62%

122 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-03 02:41 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4  

5from __future__ import annotations 

6  

7cimport cython 

8from libc.limits cimport ULLONG_MAX 

9from libc.stdint cimport uintptr_t 

10from libc.string cimport memset 

11  

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._resource_handles cimport ( 

20 MemoryPoolHandle, 

21 DevicePtrHandle, 

22 create_mempool_handle, 

23 deviceptr_alloc_from_pool, 

24 get_last_error, 

25 as_cu, 

26 as_py, 

27) 

28from cuda.core._resource_handles cimport create_mempool_handle_ref # no-cython-lint 

29  

30from cuda.core._utils.cuda_utils cimport ( 

31 HANDLE_RETURN, 

32) 

33  

34import uuid 

35from typing import TYPE_CHECKING 

36  

37if TYPE_CHECKING: 

38 from cuda.core.graph import GraphBuilder 

39 from cuda.core.typing import DevicePointerType 

40  

41  

42cdef class _MemPoolAttributes: 

43 """Provides access to memory pool attributes.""" 

44 cdef: 

45 MemoryPoolHandle _h_pool 

46  

47 def __init__(self, *args, **kwargs) -> None: 

48 raise RuntimeError("_MemPoolAttributes cannot be instantiated directly. Please use MemoryResource APIs.") 24f

49  

50 @staticmethod 

51 cdef _MemPoolAttributes _init(MemoryPoolHandle h_pool): 

52 cdef _MemPoolAttributes self = _MemPoolAttributes.__new__(_MemPoolAttributes) 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

53 self._h_pool = h_pool 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

54 return self 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

55  

56 def __repr__(self) -> str: 

57 return f"{self.__class__.__name__}(%s)" % ", ".join( 1bac

58 f"{attr}={getattr(self, attr)}" for attr in dir(self) 1bac

59 if not attr.startswith("_") 1bac

60 ) 

61  

62 cdef int _getattribute(self, cydriver.CUmemPool_attribute attr_enum, void* value) except?-1: 

63 with nogil: 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

64 HANDLE_RETURN(cydriver.cuMemPoolGetAttribute(as_cu(self._h_pool), attr_enum, value)) 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

65 return 0 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

66  

67 @property 

68 def reuse_follow_event_dependencies(self) -> bool: 

69 """Allow memory to be reused when there are event dependencies between streams.""" 

70 cdef int value 

71 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES, &value) 1%0I*4bac

72 return bool(value) 1%0I*4bac

73  

74 @property 

75 def reuse_allow_opportunistic(self) -> bool: 

76 """Allow reuse of completed frees without dependencies.""" 

77 cdef int value 

78 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC, &value) 2,d$ Z H ) 3 b a c

79 return bool(value) 1$ZH)3bac

80  

81 @property 

82 def reuse_allow_internal_dependencies(self) -> bool: 

83 """Allow insertion of new stream dependencies for memory reuse.""" 

84 cdef int value 

85 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES, &value) 1#YG(2bac

86 return bool(value) 1#YG(2bac

87  

88 @property 

89 def release_threshold(self) -> int: 

90 """Amount of reserved memory to hold before OS release.""" 

91 cdef cydriver.cuuint64_t value 

92 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD, &value) 1!XF'1bac

93 return int(value) 1!XF'1bac

94  

95 @property 

96 def reserved_mem_current(self) -> int: 

97 """Current amount of backing memory allocated.""" 

98 cdef cydriver.cuuint64_t value 

99 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RESERVED_MEM_CURRENT, &value) 1hfRMdpnkTObac

100 return int(value) 1hfRMdpnkTObac

101  

102 @property 

103 def reserved_mem_high(self) -> int: 

104 """High watermark of backing memory allocated.""" 

105 cdef cydriver.cuuint64_t value 

106 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH, &value) 1RMpTObac

107 return int(value) 1RMpTObac

108  

109 @property 

110 def used_mem_current(self) -> int: 

111 """Current amount of memory in use.""" 

112 cdef cydriver.cuuint64_t value 

113 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_USED_MEM_CURRENT, &value) 1EigSNeqolUPbacj

114 return int(value) 1EigSNeqolUPbacj

115  

116 @property 

117 def used_mem_high(self) -> int: 

118 """High watermark of memory in use.""" 

119 cdef cydriver.cuuint64_t value 

120 self._getattribute(cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_USED_MEM_HIGH, &value) 1SNqUPJmKbac

121 return int(value) 1SNqUPJmKbac

122  

123  

124cdef class _MemPool(MemoryResource): 

125  

126 def __cinit__(self) -> None: 

127 # Note: subclasses use MP_init_create_pool or MP_init_current_pool to initialize. 

128 self._mempool_owned = False 2/d} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbGbHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*eldmdr nds odpdqdrdsdw tdx udvdwdxdydBezdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u 6b7b8b9b!b^ #bgd_ ` Te+ { E | Ue-d+e6 ,ehd-e|c}c~c.eV $b7 id! X h f R M # Y $ Z % 0 i g S N F /ed :ep ;eG =eH ?eI @ee [eq ]e' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad%bjdkd:d- Q W bd{c'b1fj (b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

129 self._ipc_data = None 2/d} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbGbHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*eldmdr nds odpdqdrdsdw tdx udvdwdxdydBezdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u 6b7b8b9b!b^ #bgd_ ` Te+ { E | Ue-d+e6 ,ehd-e|c}c~c.eV $b7 id! X h f R M # Y $ Z % 0 i g S N F /ed :ep ;eG =eH ?eI @ee [eq ]e' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad%bjdkd:d- Q W bd{c'b1fj (b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

130 self._attributes = None 2/d} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbGbHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*eldmdr nds odpdqdrdsdw tdx udvdwdxdydBezdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u 6b7b8b9b!b^ #bgd_ ` Te+ { E | Ue-d+e6 ,ehd-e|c}c~c.eV $b7 id! X h f R M # Y $ Z % 0 i g S N F /ed :ep ;eG =eH ?eI @ee [eq ]e' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad%bjdkd:d- Q W bd{c'b1fj (b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

131  

132 def close(self) -> None: 

133 """Release this object's reference to the memory pool. 

134  

135 New allocations and operations requiring this object's pool handle are 

136 rejected afterward. For owned pools, release of the underlying pool's 

137 resources is deferred until all outstanding allocations are freed and 

138 pending free operations complete. :meth:`deallocate` remains available 

139 after :meth:`close` so existing allocations can still be released. 

140 """ 

141 _MP_close(self) 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b

142  

143 @property 

144 def is_closed(self) -> bool: 

145 """Whether this memory resource has been closed.""" 

146 return self._h_pool.get() == NULL 2gd

147  

148 def allocate(self, size_t size, *, stream: Stream | GraphBuilder) -> Buffer: 

149 """Allocate a buffer of the requested size. 

150  

151 Parameters 

152 ---------- 

153 size : int 

154 The size of the buffer to allocate, in bytes. 

155 stream : :obj:`~_stream.Stream` | :obj:`~graph.GraphBuilder` 

156 Keyword-only. The stream on which to perform the allocation 

157 asynchronously. Must be passed explicitly; pass 

158 ``device.default_stream`` to use the default stream. 

159  

160 Returns 

161 ------- 

162 Buffer 

163 The allocated buffer object, which is accessible on the device that this memory 

164 resource was created for. 

165 """ 

166 MP_check_open(self) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5br s ;d=dw x ?d@d[d]d^d_d`d{d|d}d~daebey z cede.dA B C D t u 6b7b8b9b!b^ #bgd_ ` + $bh f i g b , %bj (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

167 if self.is_mapped: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5br s ;d=dw x ?d@d[d]d^d_d`d{d|d}d~daebey z cede.dA B C D t u 6b7b8b9b!b^ #b_ ` + $bh f i g b , %bj (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

168 raise TypeError("Cannot allocate from a mapped IPC-enabled memory resource") 

169 cdef Stream s = Stream_accept(stream) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5br s ;d=dw x ?d@d[d]d^d_d`d{d|d}d~daebey z cede.dA B C D t u 6b7b8b9b!b^ #b_ ` + $bh f i g b , %bj (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

170 return _MP_allocate(self, size, s) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5br s ;d=dw x ?d@d[d]d^d_d`d{d|d}d~daebey z cede.dA B C D t u 6b7b8b9b!b^ #b_ ` + $bh f i g b , %bj (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

171  

172 def deallocate( 

173 self, 

174 ptr: DevicePointerType, 

175 size_t size, 

176 *, 

177 stream: Stream | GraphBuilder 

178 ) -> None: 

179 """Deallocate a buffer previously allocated by this resource. 

180  

181 Parameters 

182 ---------- 

183 ptr : :obj:`~_memory.DevicePointerType` 

184 The pointer or handle to the buffer to deallocate. 

185 size : int 

186 The size of the buffer to deallocate, in bytes. 

187 stream : :obj:`~_stream.Stream` | :obj:`~graph.GraphBuilder` 

188 Keyword-only. The stream on which to perform the deallocation 

189 asynchronously. Must be passed explicitly; pass 

190 ``device.default_stream`` to use the default stream. 

191 """ 

192 cdef Stream s = Stream_accept(stream) 2E ad

193 _MP_deallocate(self, <uintptr_t>ptr, size, s) 2E ad

194  

195 @property 

196 @cython.critical_section 

197 def attributes(self) -> _MemPoolAttributes: 

198 """Memory pool attributes.""" 

199 MP_check_open(self) 2gdE ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c j

200 cdef _MemPoolAttributes attributes 

201 if self._attributes is None: 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

202 attributes = _MemPoolAttributes._init(self._h_pool) 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

203 if self._attributes is None: 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

204 self._attributes = attributes 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

205 return self._attributes 1E!XhfRM#Y$Z%0igSNFdpGHIeq'1nkTO(2)3*4olUPJmKbacj

206  

207 @property 

208 def handle(self) -> object: 

209 """Handle to the underlying memory pool.""" 

210 return as_py(self._h_pool) 1{E|

211  

212 @property 

213 def is_handle_owned(self) -> bool: 

214 """Whether the memory resource handle is owned. If False, ``close`` has no effect.""" 

215 return self._mempool_owned 1{|

216  

217 @property 

218 def is_ipc_enabled(self) -> bool: 

219 """Whether this memory resource has IPC enabled.""" 

220 return self._ipc_data is not None 25fld6fmdr nds od;dpdCeqd=drdDesdw tdx ud2fvd3fwd7fxd8fydBe?dzdEeAd@dBdFeCd9fDd!fEd#fFd[dGd]dHd$fId%fJd^dKd_dLd'fMd(fNd`dOd{dPd)fQd*fRdGeSdHeTd+fUd,fVdIeWdJeXd-fYd.fZdKe0dLe1d/f2d|d3dMe4d}d5dNe6d~d7dOe8dae9dPe!dbe#dQe$dy z ce%dRe'dde(dSe)d.d*dAe+dA B C D t u _ ` + V ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P , - Q W +b,b-b.b8 9

221  

222 @property 

223 def is_mapped(self) -> bool: 

224 """ 

225 Whether this is a mapping of an IPC-enabled memory resource from 

226 another process. If True, allocation is not permitted. 

227 """ 

228 return self._ipc_data is not None and self._ipc_data._is_mapped 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

229  

230 @property 

231 def uuid(self) -> uuid.UUID | None: 

232 """ 

233 A universally unique identifier for this memory resource. Meaningful 

234 only for IPC-enabled memory resources. 

235 """ 

236 return getattr(self._ipc_data, 'uuid', None) 2r s 2f3f.dAet u

237  

238  

239cdef int MP_init_create_pool( 

240 _MemPool self, 

241 cydriver.CUmemLocationType loc_type, 

242 int loc_id, 

243 cydriver.CUmemAllocationType alloc_type, 

244 bint ipc_enabled, 

245 size_t max_size, 

246) except? -1: 

247 """Initialize a _MemPool by creating a new memory pool with the given 

248 parameters. 

249  

250 Sets ``_h_pool`` (owning), ``_mempool_owned``, and ``_ipc_data``. 

251 """ 

252 cdef cydriver.CUmemPoolProps properties 

253 memset(&properties, 0, sizeof(cydriver.CUmemPoolProps)) 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

254  

255 properties.allocType = alloc_type 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

256 properties.handleTypes = ( 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

257 _ipc.IPC_HANDLE_TYPE if ipc_enabled 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

258 else cydriver.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_NONE 2L v 5 + { E | -d6 |c}c~cV 7 ! h R # $ % i S F d p G H I e q ' n T ( ) * o U J m K b a c , ad:d- W bd'bj

259 ) 

260 properties.location.id = loc_id 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

261 properties.location.type = loc_type 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

262 properties.maxSize = max_size 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

263  

264 self._mempool_owned = True 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

265 self._h_pool = create_mempool_handle(properties) 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

266 if not self._h_pool: 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad:d- Q W bd{c'bj +b,b-b.b8 9

267 HANDLE_RETURN(get_last_error()) 2:d

268 raise RuntimeError( 

269 f"Failed to initialize {self.__class__.__name__}: " 

270 "cuda-core returned an empty memory pool handle without recording a CUDA error. " 

271 "This is an internal cuda-core error; please report it with your CUDA driver, " 

272 "CUDA Toolkit, and cuda-python versions." 

273 ) 

274  

275 if ipc_enabled: 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad- Q W bd{c'bj +b,b-b.b8 9

276 alloc_handle = _ipc.MP_export_mempool(self) 2ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u X f M Y Z 0 g N 1 k O 2 3 4 l P Q {c'b+b,b-b.b8 9

277 self._ipc_data = _ipc.IPCDataForMR(alloc_handle, False) 2ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u X f M Y Z 0 g N 1 k O 2 3 4 l P Q {c'b+b,b-b.b8 9

278  

279 return 0 2L v 5 ldmdr nds odpdqdrdsdw tdx udvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$dy z %d'd(d)d*d+dA B C D t u + { E | -d6 |c}c~cV 7 ! X h f R M # Y $ Z % 0 i g S N F d p G H I e q ' 1 n k T O ( 2 ) 3 * 4 o l U P J m K b a c , ad- Q W bd{c'bj +b,b-b.b8 9

280  

281  

282cdef int MP_init_current_pool( 

283 _MemPool self, 

284 cydriver.CUmemLocationType loc_type, 

285 int loc_id, 

286 cydriver.CUmemAllocationType alloc_type, 

287) except? -1: 

288 """Initialize a _MemPool by getting the driver's current pool for a 

289 location and allocation type. 

290  

291 Sets ``_h_pool`` (non-owning) via ``cuMemGetMemPool``. 

292 Requires CUDA 13+. 

293 """ 

294 IF CUDA_CORE_BUILD_MAJOR >= 13: 

295 cdef cydriver.CUmemoryPool pool 

296 cdef cydriver.CUmemLocation loc = cumemlocation_from_id(loc_type, loc_id) 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

297 with nogil: 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

298 HANDLE_RETURN(cydriver.cuMemGetMemPool(&pool, &loc, alloc_type)) 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

299 self._h_pool = create_mempool_handle_ref(pool) 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

300 self._mempool_owned = False 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

301 return 0 2/dv ; = ? @ [ ] 5e6e7e8ecddd9eed!efd#e$e%e'e(e)e*e+e6 ,ehd-e|c}c~c.eV 7 idF /ed :ep ;eG =eH ?eI @ee [eq ]em a jdkd

302 ELSE: 

303 raise RuntimeError( 

304 "Getting the current memory pool requires CUDA 13.0 or later" 

305 ) 

306  

307  

308cdef int MP_raise_release_threshold(_MemPool self) except? -1: 

309 """Raise the pool's release threshold to ULLONG_MAX if currently zero. 

310  

311 By default the release threshold is 0, meaning memory is returned to 

312 the OS as soon as there are no active suballocations. Setting it to 

313 ULLONG_MAX avoids repeated OS round-trips. 

314 """ 

315 MP_check_open(self) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

316 cdef cydriver.cuuint64_t current_threshold 

317 cdef cydriver.cuuint64_t max_threshold = ULLONG_MAX 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

318 with nogil: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

319 HANDLE_RETURN( 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

320 cydriver.cuMemPoolGetAttribute( 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

321 as_cu(self._h_pool), 

322 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD, 

323 &current_threshold 

324 ) 

325 ) 

326 if current_threshold == 0: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

327 HANDLE_RETURN(cydriver.cuMemPoolSetAttribute( 1^

328 as_cu(self._h_pool), 

329 cydriver.CUmemPool_attribute.CU_MEMPOOL_ATTR_RELEASE_THRESHOLD, 

330 &max_threshold 

331 )) 

332 return 0 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bBe6b7b8b9b!b^ #bgd_ ` Te| Ue$b%b(b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c

333  

334  

335# Raise an exception if the given stream is capturing. 

336# A result of CU_STREAM_CAPTURE_STATUS_INVALIDATED is considered an error. 

337cdef inline int check_not_capturing(cydriver.CUstream s) except?-1 nogil: 

338 cdef cydriver.CUstreamCaptureStatus capturing 

339 HANDLE_RETURN(cydriver.cuStreamIsCapturing(s, &capturing)) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

340 if capturing != cydriver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_NONE: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

341 raise RuntimeError("_MemPool cannot perform memory operations on " 1./:

342 "a capturing stream (consider using GraphMemoryResource).") 

343  

344  

345cdef Buffer _MP_allocate(_MemPool self, size_t size, Stream stream, type cls = Buffer): 

346 MP_check_open(self) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

347 cdef cydriver.CUstream s = as_cu(stream._h_stream) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

348 cdef DevicePtrHandle h_ptr 

349 with nogil: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

350 check_not_capturing(s) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

351 h_ptr = deviceptr_alloc_from_pool(size, self._h_pool, stream._h_stream) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

352 if not h_ptr: 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

353 HANDLE_RETURN(get_last_error()) 

354 raise RuntimeError( 

355 f"Failed to allocate {size} bytes from {self.__class__.__name__}: " 

356 "cuda-core returned an empty allocation handle without recording a CUDA error. " 

357 "This is an internal cuda-core error; please report it with your CUDA driver, " 

358 "CUDA Toolkit, and cuda-python versions." 

359 ) 

360 return Buffer_from_deviceptr_handle(h_ptr, size, self, None, cls) 2} ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb. / : rbsbtbubvbwbxbybzbAbL v 5 BbCbDbEbFbeeGbfeHbIbJbKbLbMbNbObPb; = ? QbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b@ [ ] VeWeXecdddedfdYeZe0e1e2e3e4er s ;dCe=dDew x ?dEe@dFe[d]d^d_d`d{dGeHeIeJeKeLe|dMe}dNe~dOeaePebeQey z ceRedeSe.dAeA B C D t u 6b7b8b9b!b^ #b_ ` + 6 hdV $b7 idh f i g d e n k o l b a c , %bjdkd- Q W j (b)b*b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLc8 9 McNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!cgehe#c$c%c'cie(c)c*c+cje,cke-c.cle/cme:cne;c=coe?cpe@cqe[crese]cte^cuevewexe_c`cyeze

361  

362  

363cdef inline void _MP_deallocate( 

364 _MemPool self, uintptr_t ptr, size_t size, Stream stream 

365) except *: 

366 cdef cydriver.CUstream s = as_cu(stream._h_stream) 2E ad

367 cdef cydriver.CUdeviceptr devptr = <cydriver.CUdeviceptr>ptr 2E ad

368 with nogil: 2E ad

369 HANDLE_RETURN(cydriver.cuMemFreeAsync(devptr, s)) 2E ad

370  

371cdef inline _MP_close(_MemPool self): 

372 if not self._h_pool: 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b

373 return 1{

374  

375 # Reset members in declaration order. 

376 # The RAII deleter calls cuMemPoolDestroy if this is an owning handle. 

377 self._h_pool.reset() 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b

378 self._mempool_owned = False 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b

379 self._ipc_data = None 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b

380 self._attributes = None 2/dL v 5 ; = ? @ [ ] ^e_er `es {e|e}e~eafw bfx cfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzfAfBfCfDfEfFfGfHfIfJfKfLfMfNfOfPfQfRfSfTfUfy z VfWfXfYfZf0fA B C D t u gd{ J m K Q W bd{c'b+b,b-b.b