Coverage for cuda/bindings/nvrtc.pyx: 44.91%

403 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-03 01:38 +0000

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

2# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE 

3  

4# This code was automatically generated with version 13.3.0, generator version 0.3.1.dev1752+g89e531539. Do not modify it directly. 

5from typing import Any, Optional 

6import cython 

7import ctypes 

8from libc.stdlib cimport calloc, malloc, free 

9from libc cimport string 

10from libc.stdint cimport int32_t, uint32_t, int64_t, uint64_t, uintptr_t 

11from libc.stddef cimport wchar_t 

12from libc.limits cimport CHAR_MIN 

13from libcpp.vector cimport vector 

14from cpython.buffer cimport PyObject_CheckBuffer, PyObject_GetBuffer, PyBuffer_Release, PyBUF_SIMPLE, PyBUF_ANY_CONTIGUOUS 

15from cpython.bytes cimport PyBytes_FromStringAndSize 

16from ._internal._fast_enum import FastEnum as _FastEnum 

17  

18import cuda.bindings.driver as _driver 

19_driver = _driver.__dict__ 

20include "_lib/utils.pxi" 

21  

22ctypedef unsigned long long signed_char_ptr 

23ctypedef unsigned long long unsigned_char_ptr 

24ctypedef unsigned long long char_ptr 

25ctypedef unsigned long long short_ptr 

26ctypedef unsigned long long unsigned_short_ptr 

27ctypedef unsigned long long int_ptr 

28ctypedef unsigned long long long_int_ptr 

29ctypedef unsigned long long long_long_int_ptr 

30ctypedef unsigned long long unsigned_int_ptr 

31ctypedef unsigned long long unsigned_long_int_ptr 

32ctypedef unsigned long long unsigned_long_long_int_ptr 

33ctypedef unsigned long long uint32_t_ptr 

34ctypedef unsigned long long uint64_t_ptr 

35ctypedef unsigned long long int32_t_ptr 

36ctypedef unsigned long long int64_t_ptr 

37ctypedef unsigned long long unsigned_ptr 

38ctypedef unsigned long long unsigned_long_long_ptr 

39ctypedef unsigned long long long_long_ptr 

40ctypedef unsigned long long size_t_ptr 

41ctypedef unsigned long long long_ptr 

42ctypedef unsigned long long float_ptr 

43ctypedef unsigned long long double_ptr 

44ctypedef unsigned long long void_ptr 

45  

46#: Flags for nvrtcInstallBundledHeaders.Skip installation if version marker 

47#: exists and version matches. This is the default behavior when flags=0. 

48NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS = cynvrtc.NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS 

49  

50#: Clear existing directory contents before installation. Guarantees 

51#: consistency by removing any existing files first. 

52NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE = cynvrtc.NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE 

53  

54#: Return NVRTC_ERROR_BUSY immediately if installation is in progress by 

55#: another process, instead of waiting for the lock. Can be combined with 

56#: FORCE_OVERWRITE using bitwise OR. 

57NVRTC_INSTALL_HEADERS_NO_WAIT = cynvrtc.NVRTC_INSTALL_HEADERS_NO_WAIT 

58  

59class nvrtcResult(_FastEnum): 

60 """ 

61 The enumerated type :py:obj:`~.nvrtcResult` defines API call result 

62 codes. NVRTC API functions return :py:obj:`~.nvrtcResult` to 

63 indicate the call result. 

64 """ 

65  

66 NVRTC_SUCCESS = cynvrtc.nvrtcResult.NVRTC_SUCCESS 

67  

68 NVRTC_ERROR_OUT_OF_MEMORY = cynvrtc.nvrtcResult.NVRTC_ERROR_OUT_OF_MEMORY 

69  

70 NVRTC_ERROR_PROGRAM_CREATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_PROGRAM_CREATION_FAILURE 

71  

72 NVRTC_ERROR_INVALID_INPUT = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_INPUT 

73  

74 NVRTC_ERROR_INVALID_PROGRAM = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_PROGRAM 

75  

76 NVRTC_ERROR_INVALID_OPTION = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_OPTION 

77  

78 NVRTC_ERROR_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_COMPILATION 

79  

80 NVRTC_ERROR_BUILTIN_OPERATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE 

81  

82 NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 

83  

84 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

85  

86 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID = cynvrtc.nvrtcResult.NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

87  

88 NVRTC_ERROR_INTERNAL_ERROR = cynvrtc.nvrtcResult.NVRTC_ERROR_INTERNAL_ERROR 

89  

90 NVRTC_ERROR_TIME_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_FILE_WRITE_FAILED 

91  

92 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED 

93  

94 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED 

95  

96 NVRTC_ERROR_PCH_CREATE = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE 

97  

98 NVRTC_ERROR_CANCELLED = cynvrtc.nvrtcResult.NVRTC_ERROR_CANCELLED 

99  

100 NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED 

101  

102 NVRTC_ERROR_BUSY = cynvrtc.nvrtcResult.NVRTC_ERROR_BUSY 

103  

104cdef object _nvrtcResult = nvrtcResult 

105cdef object _nvrtcResult_SUCCESS = nvrtcResult.NVRTC_SUCCESS 

106  

107cdef class nvrtcProgram: 

108 """ nvrtcProgram is the unit of compilation, and an opaque handle for a program. 

109  

110 To compile a CUDA program string, an instance of nvrtcProgram must be created first with nvrtcCreateProgram, then compiled with nvrtcCompileProgram. 

111  

112 Methods 

113 ------- 

114 getPtr() 

115 Get memory address of class instance 

116  

117 """ 

118 def __cinit__(self, void_ptr init_value = 0, void_ptr _ptr = 0): 

119 if _ptr == 0: 2j b c d e f g h i k l m n o p q r s t u v w x y ,b-b

120 self._pvt_ptr = &self._pvt_val 2j b c d e f g h i k l m n o p q r s t u v w x y ,b-b

121 self._pvt_ptr[0] = <cynvrtc.nvrtcProgram>init_value 2j b c d e f g h i k l m n o p q r s t u v w x y ,b-b

122 else: 

123 self._pvt_ptr = <cynvrtc.nvrtcProgram *>_ptr 

124 def __init__(self, *args, **kwargs): 

125 pass 2j b c d e f g h i k l m n o p q r s t u v w x y ,b-b

126 def __repr__(self): 

127 return '<nvrtcProgram ' + str(hex(self.__int__())) + '>' 

128 def __index__(self): 

129 return self.__int__() 

130 def __eq__(self, other): 

131 if not isinstance(other, nvrtcProgram): 

132 return False 

133 return self._pvt_ptr[0] == (<nvrtcProgram>other)._pvt_ptr[0] 

134 def __hash__(self): 

135 return hash(<uintptr_t><void*>(self._pvt_ptr[0])) 

136 def __int__(self): 

137 return <void_ptr>self._pvt_ptr[0] 1jbcdefghiklmnopqrstuvwxy

138 def getPtr(self): 

139 return <void_ptr>self._pvt_ptr 1jklmnopqrstuvwx

140  

141cdef class anon_struct0: 

142 """ 

143 Attributes 

144 ---------- 

145  

146 available : int 

147  

148  

149  

150 compressedSize : size_t 

151  

152  

153  

154 uncompressedSize : size_t 

155  

156  

157  

158 cudaVersionMajor : int 

159  

160  

161  

162 cudaVersionMinor : int 

163  

164  

165  

166 numFiles : unsigned int 

167  

168  

169  

170 Methods 

171 ------- 

172 getPtr() 

173 Get memory address of class instance 

174 """ 

175 def __cinit__(self, void_ptr _ptr): 

176 self._pvt_ptr = <cynvrtc.nvrtcBundledHeadersInfo *>_ptr 

177  

178 def __init__(self, void_ptr _ptr): 

179 pass 

180 def __dealloc__(self): 

181 pass 

182 def getPtr(self): 

183 return <void_ptr>self._pvt_ptr 

184 def __repr__(self): 

185 if self._pvt_ptr is not NULL: 

186 str_list = [] 

187  

188 try: 

189 str_list += ['available : ' + str(self.available)] 

190 except ValueError: 

191 str_list += ['available : <ValueError>'] 

192  

193  

194 try: 

195 str_list += ['compressedSize : ' + str(self.compressedSize)] 

196 except ValueError: 

197 str_list += ['compressedSize : <ValueError>'] 

198  

199  

200 try: 

201 str_list += ['uncompressedSize : ' + str(self.uncompressedSize)] 

202 except ValueError: 

203 str_list += ['uncompressedSize : <ValueError>'] 

204  

205  

206 try: 

207 str_list += ['cudaVersionMajor : ' + str(self.cudaVersionMajor)] 

208 except ValueError: 

209 str_list += ['cudaVersionMajor : <ValueError>'] 

210  

211  

212 try: 

213 str_list += ['cudaVersionMinor : ' + str(self.cudaVersionMinor)] 

214 except ValueError: 

215 str_list += ['cudaVersionMinor : <ValueError>'] 

216  

217  

218 try: 

219 str_list += ['numFiles : ' + str(self.numFiles)] 

220 except ValueError: 

221 str_list += ['numFiles : <ValueError>'] 

222  

223 return '\n'.join(str_list) 

224 else: 

225 return '' 

226  

227 @property 

228 def available(self): 

229 return self._pvt_ptr[0].available 

230 @available.setter 

231 def available(self, int available): 

232 self._pvt_ptr[0].available = available 

233  

234  

235 @property 

236 def compressedSize(self): 

237 return self._pvt_ptr[0].compressedSize 

238 @compressedSize.setter 

239 def compressedSize(self, size_t compressedSize): 

240 self._pvt_ptr[0].compressedSize = compressedSize 

241  

242  

243 @property 

244 def uncompressedSize(self): 

245 return self._pvt_ptr[0].uncompressedSize 

246 @uncompressedSize.setter 

247 def uncompressedSize(self, size_t uncompressedSize): 

248 self._pvt_ptr[0].uncompressedSize = uncompressedSize 

249  

250  

251 @property 

252 def cudaVersionMajor(self): 

253 return self._pvt_ptr[0].cudaVersionMajor 

254 @cudaVersionMajor.setter 

255 def cudaVersionMajor(self, int cudaVersionMajor): 

256 self._pvt_ptr[0].cudaVersionMajor = cudaVersionMajor 

257  

258  

259 @property 

260 def cudaVersionMinor(self): 

261 return self._pvt_ptr[0].cudaVersionMinor 

262 @cudaVersionMinor.setter 

263 def cudaVersionMinor(self, int cudaVersionMinor): 

264 self._pvt_ptr[0].cudaVersionMinor = cudaVersionMinor 

265  

266  

267 @property 

268 def numFiles(self): 

269 return self._pvt_ptr[0].numFiles 

270 @numFiles.setter 

271 def numFiles(self, unsigned int numFiles): 

272 self._pvt_ptr[0].numFiles = numFiles 

273  

274  

275cdef class nvrtcBundledHeadersInfo(anon_struct0): 

276 """ 

277 Attributes 

278 ---------- 

279  

280 available : int 

281  

282  

283  

284 compressedSize : size_t 

285  

286  

287  

288 uncompressedSize : size_t 

289  

290  

291  

292 cudaVersionMajor : int 

293  

294  

295  

296 cudaVersionMinor : int 

297  

298  

299  

300 numFiles : unsigned int 

301  

302  

303  

304 Methods 

305 ------- 

306 getPtr() 

307 Get memory address of class instance 

308 """ 

309 def __cinit__(self, void_ptr _ptr = 0): 

310 if _ptr == 0: 

311 self._pvt_ptr = <cynvrtc.nvrtcBundledHeadersInfo *>&self._pvt_val 

312 else: 

313 self._pvt_ptr = <cynvrtc.nvrtcBundledHeadersInfo *>_ptr 

314  

315 def __init__(self, void_ptr _ptr = 0): 

316 pass 

317  

318@cython.embedsignature(True) 

319def nvrtcGetErrorString(result not None : nvrtcResult): 

320 """ nvrtcGetErrorString is a helper function that returns a string describing the given :py:obj:`~.nvrtcResult` code, e.g., NVRTC_SUCCESS to `"NVRTC_SUCCESS"`. For unrecognized enumeration values, it returns `"NVRTC_ERROR unknown"`. 

321  

322 Parameters 

323 ---------- 

324 result : :py:obj:`~.nvrtcResult` 

325 CUDA Runtime Compilation API result code. 

326  

327 Returns 

328 ------- 

329 nvrtcResult.NVRTC_SUCCESS 

330 nvrtcResult.NVRTC_SUCCESS 

331 bytes 

332 Message string for the given :py:obj:`~.nvrtcResult` code. 

333 """ 

334 cdef cynvrtc.nvrtcResult cyresult = int(result) 2j .b

335 with nogil: 2j .b

336 err = cynvrtc.nvrtcGetErrorString(cyresult) 2j .b

337 return (nvrtcResult.NVRTC_SUCCESS, err) 2j .b

338  

339@cython.embedsignature(True) 

340def nvrtcVersion(): 

341 """ nvrtcVersion sets the output parameters `major` and `minor` with the CUDA Runtime Compilation version number. 

342  

343 Returns 

344 ------- 

345 nvrtcResult 

346 - :py:obj:`~.NVRTC_SUCCESS` 

347 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

348 major : int 

349 CUDA Runtime Compilation major version number. 

350 minor : int 

351 CUDA Runtime Compilation minor version number. 

352 """ 

353 cdef int major = 0 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

354 cdef int minor = 0 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

355 with nogil: 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

356 err = cynvrtc.nvrtcVersion(&major, &minor) 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

357 if err != cynvrtc.NVRTC_SUCCESS: 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

358 return (_nvrtcResult(err), None, None) 

359 return (_nvrtcResult_SUCCESS, major, minor) 2a b c d e f g h i A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b

360  

361@cython.embedsignature(True) 

362def nvrtcGetNumSupportedArchs(): 

363 """ nvrtcGetNumSupportedArchs sets the output parameter `numArchs` with the number of architectures supported by NVRTC. This can then be used to pass an array to :py:obj:`~.nvrtcGetSupportedArchs` to get the supported architectures. 

364  

365 see :py:obj:`~.nvrtcGetSupportedArchs` 

366  

367 Returns 

368 ------- 

369 nvrtcResult 

370 - :py:obj:`~.NVRTC_SUCCESS` 

371 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

372 numArchs : int 

373 number of supported architectures. 

374 """ 

375 cdef int numArchs = 0 1z

376 with nogil: 1z

377 err = cynvrtc.nvrtcGetNumSupportedArchs(&numArchs) 1z

378 if err != cynvrtc.NVRTC_SUCCESS: 1z

379 return (_nvrtcResult(err), None) 

380 return (_nvrtcResult_SUCCESS, numArchs) 1z

381  

382@cython.embedsignature(True) 

383def nvrtcGetSupportedArchs(): 

384 """ nvrtcGetSupportedArchs populates the array passed via the output parameter `supportedArchs` with the architectures supported by NVRTC. The array is sorted in the ascending order. The size of the array to be passed can be determined using :py:obj:`~.nvrtcGetNumSupportedArchs`. 

385  

386 see :py:obj:`~.nvrtcGetNumSupportedArchs` 

387  

388 Returns 

389 ------- 

390 nvrtcResult 

391 - :py:obj:`~.NVRTC_SUCCESS` 

392 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

393 supportedArchs : list[int] 

394 sorted array of supported architectures. 

395 """ 

396 cdef vector[int] supportedArchs 

397 _, s = nvrtcGetNumSupportedArchs() 1z

398 supportedArchs.resize(s) 1z

399  

400 with nogil: 1z

401 err = cynvrtc.nvrtcGetSupportedArchs(supportedArchs.data()) 1z

402 if err != cynvrtc.NVRTC_SUCCESS: 1z

403 return (_nvrtcResult(err), None) 

404 return (_nvrtcResult_SUCCESS, supportedArchs) 1z

405  

406@cython.embedsignature(True) 

407def nvrtcCreateProgram(char* src, char* name, int numHeaders, headers : Optional[tuple[bytes] | list[bytes]], includeNames : Optional[tuple[bytes] | list[bytes]]): 

408 """ nvrtcCreateProgram creates an instance of :py:obj:`~.nvrtcProgram` with the given input parameters, and sets the output parameter `prog` with it. 

409  

410 Parameters 

411 ---------- 

412 src : bytes 

413 CUDA program source. 

414 name : bytes 

415 CUDA program name. `name` can be `NULL`; `"default_program"` is 

416 used when `name` is `NULL` or "". 

417 numHeaders : int 

418 Number of headers used. `numHeaders` must be greater than or equal 

419 to 0. 

420 headers : list[bytes] 

421 Sources of the headers. `headers` can be `NULL` when `numHeaders` 

422 is 0. 

423 includeNames : list[bytes] 

424 Name of each header by which they can be included in the CUDA 

425 program source. `includeNames` can be `NULL` when `numHeaders` is 

426 0. These headers must be included with the exact names specified 

427 here. 

428  

429 Returns 

430 ------- 

431 nvrtcResult 

432 - :py:obj:`~.NVRTC_SUCCESS` 

433 - :py:obj:`~.NVRTC_ERROR_OUT_OF_MEMORY` 

434 - :py:obj:`~.NVRTC_ERROR_PROGRAM_CREATION_FAILURE` 

435 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

436 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

437 prog : :py:obj:`~.nvrtcProgram` 

438 CUDA Runtime Compilation program. 

439  

440 See Also 

441 -------- 

442 :py:obj:`~.nvrtcDestroyProgram` 

443 """ 

444 includeNames = [] if includeNames is None else includeNames 1jbcdefghiklmnopqrstuvwx

445 if not all(isinstance(_x, (bytes)) for _x in includeNames): 1jbcdefghiklmnopqrstuvwx

446 raise TypeError("Argument 'includeNames' is not instance of type (expected tuple[bytes] or list[bytes]") 

447 headers = [] if headers is None else headers 1jbcdefghiklmnopqrstuvwx

448 if not all(isinstance(_x, (bytes)) for _x in headers): 1jbcdefghiklmnopqrstuvwx

449 raise TypeError("Argument 'headers' is not instance of type (expected tuple[bytes] or list[bytes]") 

450 cdef nvrtcProgram prog = nvrtcProgram() 1jbcdefghiklmnopqrstuvwx

451 if numHeaders > len(headers): raise RuntimeError("List is too small: " + str(len(headers)) + " < " + str(numHeaders)) 1jbcdefghiklmnopqrstuvwx

452 if numHeaders > len(includeNames): raise RuntimeError("List is too small: " + str(len(includeNames)) + " < " + str(numHeaders)) 1jbcdefghiklmnopqrstuvwx

453 cdef vector[const char*] cyheaders = headers 1jbcdefghiklmnopqrstuvwx

454 cdef vector[const char*] cyincludeNames = includeNames 1jbcdefghiklmnopqrstuvwx

455 with nogil: 1jbcdefghiklmnopqrstuvwx

456 err = cynvrtc.nvrtcCreateProgram(<cynvrtc.nvrtcProgram*>prog._pvt_ptr, src, name, numHeaders, cyheaders.data(), cyincludeNames.data()) 1jbcdefghiklmnopqrstuvwx

457 if err != cynvrtc.NVRTC_SUCCESS: 1jbcdefghiklmnopqrstuvwx

458 return (_nvrtcResult(err), None) 

459 return (_nvrtcResult_SUCCESS, prog) 1jbcdefghiklmnopqrstuvwx

460  

461@cython.embedsignature(True) 

462def nvrtcDestroyProgram(prog): 

463 """ nvrtcDestroyProgram destroys the given program. 

464  

465 Parameters 

466 ---------- 

467 prog : :py:obj:`~.nvrtcProgram` 

468 CUDA Runtime Compilation program. 

469  

470 Returns 

471 ------- 

472 nvrtcResult 

473 - :py:obj:`~.NVRTC_SUCCESS` 

474 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

475  

476 See Also 

477 -------- 

478 :py:obj:`~.nvrtcCreateProgram` 

479 """ 

480 cdef cynvrtc.nvrtcProgram *cyprog 

481 if prog is None: 1jklmnopqrstuvwx

482 cyprog = <cynvrtc.nvrtcProgram*><void_ptr>NULL 

483 elif isinstance(prog, (nvrtcProgram,)): 1jklmnopqrstuvwx

484 pprog = prog.getPtr() 1jklmnopqrstuvwx

485 cyprog = <cynvrtc.nvrtcProgram*><void_ptr>pprog 1jklmnopqrstuvwx

486 elif isinstance(prog, (int)): 

487 cyprog = <cynvrtc.nvrtcProgram*><void_ptr>prog 

488 else: 

489 raise TypeError("Argument 'prog' is not instance of type (expected <class 'int, nvrtc.nvrtcProgram'>, found " + str(type(prog))) 

490 with nogil: 1jklmnopqrstuvwx

491 err = cynvrtc.nvrtcDestroyProgram(cyprog) 1jklmnopqrstuvwx

492 return (_nvrtcResult(err),) 1jklmnopqrstuvwx

493  

494@cython.embedsignature(True) 

495def nvrtcCompileProgram(prog, int numOptions, options : Optional[tuple[bytes] | list[bytes]]): 

496 """ nvrtcCompileProgram compiles the given program. 

497  

498 It supports compile options listed in :py:obj:`~.Supported Compile 

499 Options`. 

500  

501 Parameters 

502 ---------- 

503 prog : :py:obj:`~.nvrtcProgram` 

504 CUDA Runtime Compilation program. 

505 numOptions : int 

506 Number of compiler options passed. 

507 options : list[bytes] 

508 Compiler options in the form of C string array. `options` can be 

509 `NULL` when `numOptions` is 0. 

510  

511 Returns 

512 ------- 

513 nvrtcResult 

514 - :py:obj:`~.NVRTC_SUCCESS` 

515 - :py:obj:`~.NVRTC_ERROR_OUT_OF_MEMORY` 

516 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

517 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

518 - :py:obj:`~.NVRTC_ERROR_INVALID_OPTION` 

519 - :py:obj:`~.NVRTC_ERROR_COMPILATION` 

520 - :py:obj:`~.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE` 

521 - :py:obj:`~.NVRTC_ERROR_TIME_FILE_WRITE_FAILED` 

522 - :py:obj:`~.NVRTC_ERROR_CANCELLED` 

523 """ 

524 options = [] if options is None else options 1jbcdefghiklmnopqrstuvwx

525 if not all(isinstance(_x, (bytes)) for _x in options): 1jbcdefghiklmnopqrstuvwx

526 raise TypeError("Argument 'options' is not instance of type (expected tuple[bytes] or list[bytes]") 

527 cdef cynvrtc.nvrtcProgram cyprog 

528 if prog is None: 1jbcdefghiklmnopqrstuvwx

529 pprog = 0 

530 elif isinstance(prog, (nvrtcProgram,)): 1jbcdefghiklmnopqrstuvwx

531 pprog = int(prog) 1jbcdefghiklmnopqrstuvwx

532 else: 

533 pprog = int(nvrtcProgram(prog)) 

534 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1jbcdefghiklmnopqrstuvwx

535 if numOptions > len(options): raise RuntimeError("List is too small: " + str(len(options)) + " < " + str(numOptions)) 1jbcdefghiklmnopqrstuvwx

536 cdef vector[const char*] cyoptions = options 1jbcdefghiklmnopqrstuvwx

537 with nogil: 1jbcdefghiklmnopqrstuvwx

538 err = cynvrtc.nvrtcCompileProgram(cyprog, numOptions, cyoptions.data()) 1jbcdefghiklmnopqrstuvwx

539 return (_nvrtcResult(err),) 1jbcdefghiklmnopqrstuvwx

540  

541@cython.embedsignature(True) 

542def nvrtcGetPTXSize(prog): 

543 """ nvrtcGetPTXSize sets the value of `ptxSizeRet` with the size of the PTX generated by the previous compilation of `prog` (including the trailing `NULL`). 

544  

545 Parameters 

546 ---------- 

547 prog : :py:obj:`~.nvrtcProgram` 

548 CUDA Runtime Compilation program. 

549  

550 Returns 

551 ------- 

552 nvrtcResult 

553 - :py:obj:`~.NVRTC_SUCCESS` 

554 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

555 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

556 ptxSizeRet : int 

557 Size of the generated PTX (including the trailing `NULL`). 

558  

559 See Also 

560 -------- 

561 :py:obj:`~.nvrtcGetPTX` 

562 """ 

563 cdef cynvrtc.nvrtcProgram cyprog 

564 if prog is None: 

565 pprog = 0 

566 elif isinstance(prog, (nvrtcProgram,)): 

567 pprog = int(prog) 

568 else: 

569 pprog = int(nvrtcProgram(prog)) 

570 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

571 cdef size_t ptxSizeRet = 0 

572 with nogil: 

573 err = cynvrtc.nvrtcGetPTXSize(cyprog, &ptxSizeRet) 

574 if err != cynvrtc.NVRTC_SUCCESS: 

575 return (_nvrtcResult(err), None) 

576 return (_nvrtcResult_SUCCESS, ptxSizeRet) 

577  

578@cython.embedsignature(True) 

579def nvrtcGetPTX(prog, char* ptx): 

580 """ nvrtcGetPTX stores the PTX generated by the previous compilation of `prog` in the memory pointed by `ptx`. 

581  

582 Parameters 

583 ---------- 

584 prog : :py:obj:`~.nvrtcProgram` 

585 CUDA Runtime Compilation program. 

586 ptx : bytes 

587 Compiled result. 

588  

589 Returns 

590 ------- 

591 nvrtcResult 

592 - :py:obj:`~.NVRTC_SUCCESS` 

593 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

594 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

595  

596 See Also 

597 -------- 

598 :py:obj:`~.nvrtcGetPTXSize` 

599 """ 

600 cdef cynvrtc.nvrtcProgram cyprog 

601 if prog is None: 

602 pprog = 0 

603 elif isinstance(prog, (nvrtcProgram,)): 

604 pprog = int(prog) 

605 else: 

606 pprog = int(nvrtcProgram(prog)) 

607 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

608 with nogil: 

609 err = cynvrtc.nvrtcGetPTX(cyprog, ptx) 

610 return (_nvrtcResult(err),) 

611  

612@cython.embedsignature(True) 

613def nvrtcGetCUBINSize(prog): 

614 """ nvrtcGetCUBINSize sets the value of `cubinSizeRet` with the size of the cubin generated by the previous compilation of `prog`. The value of cubinSizeRet is set to 0 if the value specified to `-arch` is a virtual architecture instead of an actual architecture. 

615  

616 Parameters 

617 ---------- 

618 prog : :py:obj:`~.nvrtcProgram` 

619 CUDA Runtime Compilation program. 

620  

621 Returns 

622 ------- 

623 nvrtcResult 

624 - :py:obj:`~.NVRTC_SUCCESS` 

625 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

626 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

627 cubinSizeRet : int 

628 Size of the generated cubin. 

629  

630 See Also 

631 -------- 

632 :py:obj:`~.nvrtcGetCUBIN` 

633 """ 

634 cdef cynvrtc.nvrtcProgram cyprog 

635 if prog is None: 1bcdefghiopqrst

636 pprog = 0 

637 elif isinstance(prog, (nvrtcProgram,)): 1bcdefghiopqrst

638 pprog = int(prog) 1bcdefghiopqrst

639 else: 

640 pprog = int(nvrtcProgram(prog)) 

641 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1bcdefghiopqrst

642 cdef size_t cubinSizeRet = 0 1bcdefghiopqrst

643 with nogil: 1bcdefghiopqrst

644 err = cynvrtc.nvrtcGetCUBINSize(cyprog, &cubinSizeRet) 1bcdefghiopqrst

645 if err != cynvrtc.NVRTC_SUCCESS: 1bcdefghiopqrst

646 return (_nvrtcResult(err), None) 

647 return (_nvrtcResult_SUCCESS, cubinSizeRet) 1bcdefghiopqrst

648  

649@cython.embedsignature(True) 

650def nvrtcGetCUBIN(prog, char* cubin): 

651 """ nvrtcGetCUBIN stores the cubin generated by the previous compilation of `prog` in the memory pointed by `cubin`. No cubin is available if the value specified to `-arch` is a virtual architecture instead of an actual architecture. The cubin does not contain code for the Tile functions (`__tile__` / `__tile_global__`) or variables (`__tile__`); use `nvrtcGetTileIR()` to extract the cuda_tile IR generated for Tile code. 

652  

653 Parameters 

654 ---------- 

655 prog : :py:obj:`~.nvrtcProgram` 

656 CUDA Runtime Compilation program. 

657 cubin : bytes 

658 Compiled and assembled result. 

659  

660 Returns 

661 ------- 

662 nvrtcResult 

663 - :py:obj:`~.NVRTC_SUCCESS` 

664 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

665 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

666  

667 See Also 

668 -------- 

669 :py:obj:`~.nvrtcGetCUBINSize` 

670 """ 

671 cdef cynvrtc.nvrtcProgram cyprog 

672 if prog is None: 1bcdefghiopqrst

673 pprog = 0 

674 elif isinstance(prog, (nvrtcProgram,)): 1bcdefghiopqrst

675 pprog = int(prog) 1bcdefghiopqrst

676 else: 

677 pprog = int(nvrtcProgram(prog)) 

678 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1bcdefghiopqrst

679 with nogil: 1bcdefghiopqrst

680 err = cynvrtc.nvrtcGetCUBIN(cyprog, cubin) 1bcdefghiopqrst

681 return (_nvrtcResult(err),) 1bcdefghiopqrst

682  

683@cython.embedsignature(True) 

684def nvrtcGetLTOIRSize(prog): 

685 """ nvrtcGetLTOIRSize sets the value of `LTOIRSizeRet` with the size of the LTO IR generated by the previous compilation of `prog`. The value of LTOIRSizeRet is set to 0 if the program was not compiled with `-dlto`. 

686  

687 Parameters 

688 ---------- 

689 prog : :py:obj:`~.nvrtcProgram` 

690 CUDA Runtime Compilation program. 

691  

692 Returns 

693 ------- 

694 nvrtcResult 

695 - :py:obj:`~.NVRTC_SUCCESS` 

696 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

697 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

698 LTOIRSizeRet : int 

699 Size of the generated LTO IR. 

700  

701 See Also 

702 -------- 

703 :py:obj:`~.nvrtcGetLTOIR` 

704 """ 

705 cdef cynvrtc.nvrtcProgram cyprog 

706 if prog is None: 1klmnuvwx

707 pprog = 0 

708 elif isinstance(prog, (nvrtcProgram,)): 1klmnuvwx

709 pprog = int(prog) 1klmnuvwx

710 else: 

711 pprog = int(nvrtcProgram(prog)) 

712 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1klmnuvwx

713 cdef size_t LTOIRSizeRet = 0 1klmnuvwx

714 with nogil: 1klmnuvwx

715 err = cynvrtc.nvrtcGetLTOIRSize(cyprog, &LTOIRSizeRet) 1klmnuvwx

716 if err != cynvrtc.NVRTC_SUCCESS: 1klmnuvwx

717 return (_nvrtcResult(err), None) 

718 return (_nvrtcResult_SUCCESS, LTOIRSizeRet) 1klmnuvwx

719  

720@cython.embedsignature(True) 

721def nvrtcGetLTOIR(prog, char* LTOIR): 

722 """ nvrtcGetLTOIR stores the LTO IR generated by the previous compilation of `prog` in the memory pointed by `LTOIR`. No LTO IR is available if the program was compiled without `-dlto`. 

723  

724 Parameters 

725 ---------- 

726 prog : :py:obj:`~.nvrtcProgram` 

727 CUDA Runtime Compilation program. 

728 LTOIR : bytes 

729 Compiled result. 

730  

731 Returns 

732 ------- 

733 nvrtcResult 

734 - :py:obj:`~.NVRTC_SUCCESS` 

735 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

736 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

737  

738 See Also 

739 -------- 

740 :py:obj:`~.nvrtcGetLTOIRSize` 

741 """ 

742 cdef cynvrtc.nvrtcProgram cyprog 

743 if prog is None: 1klmnuvwx

744 pprog = 0 

745 elif isinstance(prog, (nvrtcProgram,)): 1klmnuvwx

746 pprog = int(prog) 1klmnuvwx

747 else: 

748 pprog = int(nvrtcProgram(prog)) 

749 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1klmnuvwx

750 with nogil: 1klmnuvwx

751 err = cynvrtc.nvrtcGetLTOIR(cyprog, LTOIR) 1klmnuvwx

752 return (_nvrtcResult(err),) 1klmnuvwx

753  

754@cython.embedsignature(True) 

755def nvrtcGetOptiXIRSize(prog): 

756 """ nvrtcGetOptiXIRSize sets the value of `optixirSizeRet` with the size of the OptiX IR generated by the previous compilation of `prog`. The value of nvrtcGetOptiXIRSize is set to 0 if the program was compiled with options incompatible with OptiX IR generation. 

757  

758 Parameters 

759 ---------- 

760 prog : :py:obj:`~.nvrtcProgram` 

761 CUDA Runtime Compilation program. 

762  

763 Returns 

764 ------- 

765 nvrtcResult 

766 - :py:obj:`~.NVRTC_SUCCESS` 

767 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

768 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

769 optixirSizeRet : int 

770 Size of the generated LTO IR. 

771  

772 See Also 

773 -------- 

774 :py:obj:`~.nvrtcGetOptiXIR` 

775 """ 

776 cdef cynvrtc.nvrtcProgram cyprog 

777 if prog is None: 

778 pprog = 0 

779 elif isinstance(prog, (nvrtcProgram,)): 

780 pprog = int(prog) 

781 else: 

782 pprog = int(nvrtcProgram(prog)) 

783 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

784 cdef size_t optixirSizeRet = 0 

785 with nogil: 

786 err = cynvrtc.nvrtcGetOptiXIRSize(cyprog, &optixirSizeRet) 

787 if err != cynvrtc.NVRTC_SUCCESS: 

788 return (_nvrtcResult(err), None) 

789 return (_nvrtcResult_SUCCESS, optixirSizeRet) 

790  

791@cython.embedsignature(True) 

792def nvrtcGetOptiXIR(prog, char* optixir): 

793 """ nvrtcGetOptiXIR stores the OptiX IR generated by the previous compilation of `prog` in the memory pointed by `optixir`. No OptiX IR is available if the program was compiled with options incompatible with OptiX IR generation. 

794  

795 Parameters 

796 ---------- 

797 prog : :py:obj:`~.nvrtcProgram` 

798 CUDA Runtime Compilation program. 

799 optixir : bytes 

800 Optix IR Compiled result. 

801  

802 Returns 

803 ------- 

804 nvrtcResult 

805 - :py:obj:`~.NVRTC_SUCCESS` 

806 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

807 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

808  

809 See Also 

810 -------- 

811 :py:obj:`~.nvrtcGetOptiXIRSize` 

812 """ 

813 cdef cynvrtc.nvrtcProgram cyprog 

814 if prog is None: 

815 pprog = 0 

816 elif isinstance(prog, (nvrtcProgram,)): 

817 pprog = int(prog) 

818 else: 

819 pprog = int(nvrtcProgram(prog)) 

820 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

821 with nogil: 

822 err = cynvrtc.nvrtcGetOptiXIR(cyprog, optixir) 

823 return (_nvrtcResult(err),) 

824  

825@cython.embedsignature(True) 

826def nvrtcGetProgramLogSize(prog): 

827 """ nvrtcGetProgramLogSize sets `logSizeRet` with the size of the log generated by the previous compilation of `prog` (including the trailing `NULL`). 

828  

829 Note that compilation log may be generated with warnings and 

830 informative messages, even when the compilation of `prog` succeeds. 

831  

832 Parameters 

833 ---------- 

834 prog : :py:obj:`~.nvrtcProgram` 

835 CUDA Runtime Compilation program. 

836  

837 Returns 

838 ------- 

839 nvrtcResult 

840 - :py:obj:`~.NVRTC_SUCCESS` 

841 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

842 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

843 logSizeRet : int 

844 Size of the compilation log (including the trailing `NULL`). 

845  

846 See Also 

847 -------- 

848 :py:obj:`~.nvrtcGetProgramLog` 

849 """ 

850 cdef cynvrtc.nvrtcProgram cyprog 

851 if prog is None: 1jbcdefghi

852 pprog = 0 

853 elif isinstance(prog, (nvrtcProgram,)): 1jbcdefghi

854 pprog = int(prog) 1jbcdefghi

855 else: 

856 pprog = int(nvrtcProgram(prog)) 

857 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1jbcdefghi

858 cdef size_t logSizeRet = 0 1jbcdefghi

859 with nogil: 1jbcdefghi

860 err = cynvrtc.nvrtcGetProgramLogSize(cyprog, &logSizeRet) 1jbcdefghi

861 if err != cynvrtc.NVRTC_SUCCESS: 1jbcdefghi

862 return (_nvrtcResult(err), None) 

863 return (_nvrtcResult_SUCCESS, logSizeRet) 1jbcdefghi

864  

865@cython.embedsignature(True) 

866def nvrtcGetProgramLog(prog, char* log): 

867 """ nvrtcGetProgramLog stores the log generated by the previous compilation of `prog` in the memory pointed by `log`. 

868  

869 Parameters 

870 ---------- 

871 prog : :py:obj:`~.nvrtcProgram` 

872 CUDA Runtime Compilation program. 

873 log : bytes 

874 Compilation log. 

875  

876 Returns 

877 ------- 

878 nvrtcResult 

879 - :py:obj:`~.NVRTC_SUCCESS` 

880 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

881 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

882  

883 See Also 

884 -------- 

885 :py:obj:`~.nvrtcGetProgramLogSize` 

886 """ 

887 cdef cynvrtc.nvrtcProgram cyprog 

888 if prog is None: 1jbcdefghi

889 pprog = 0 

890 elif isinstance(prog, (nvrtcProgram,)): 1jbcdefghi

891 pprog = int(prog) 1jbcdefghi

892 else: 

893 pprog = int(nvrtcProgram(prog)) 

894 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1jbcdefghi

895 with nogil: 1jbcdefghi

896 err = cynvrtc.nvrtcGetProgramLog(cyprog, log) 1jbcdefghi

897 return (_nvrtcResult(err),) 1jbcdefghi

898  

899@cython.embedsignature(True) 

900def nvrtcAddNameExpression(prog, char* name_expression): 

901 """ nvrtcAddNameExpression notes the given name expression denoting the address of a global function or device/__constant__ variable. 

902  

903 The identical name expression string must be provided on a subsequent 

904 call to nvrtcGetLoweredName to extract the lowered name. 

905  

906 Parameters 

907 ---------- 

908 prog : :py:obj:`~.nvrtcProgram` 

909 CUDA Runtime Compilation program. 

910 name_expression : bytes 

911 constant expression denoting the address of a global function or 

912 device/__constant__ variable. 

913  

914 Returns 

915 ------- 

916 nvrtcResult 

917 - :py:obj:`~.NVRTC_SUCCESS` 

918 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

919 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

920 - :py:obj:`~.NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION` 

921  

922 See Also 

923 -------- 

924 :py:obj:`~.nvrtcGetLoweredName` 

925 """ 

926 cdef cynvrtc.nvrtcProgram cyprog 

927 if prog is None: 

928 pprog = 0 

929 elif isinstance(prog, (nvrtcProgram,)): 

930 pprog = int(prog) 

931 else: 

932 pprog = int(nvrtcProgram(prog)) 

933 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

934 with nogil: 

935 err = cynvrtc.nvrtcAddNameExpression(cyprog, name_expression) 

936 return (_nvrtcResult(err),) 

937  

938@cython.embedsignature(True) 

939def nvrtcGetLoweredName(prog, char* name_expression): 

940 """ nvrtcGetLoweredName extracts the lowered (mangled) name for a global function or device/__constant__ variable, and updates lowered_name to point to it. The memory containing the name is released when the NVRTC program is destroyed by nvrtcDestroyProgram. The identical name expression must have been previously provided to nvrtcAddNameExpression. 

941  

942 Parameters 

943 ---------- 

944 prog : nvrtcProgram 

945 CUDA Runtime Compilation program. 

946 name_expression : bytes 

947 constant expression denoting the address of a global function or 

948 device/__constant__ variable. 

949  

950 Returns 

951 ------- 

952 nvrtcResult 

953 NVRTC_SUCCESS 

954 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

955 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

956 lowered_name : bytes 

957 initialized by the function to point to a C string containing the 

958 lowered (mangled) name corresponding to the provided name 

959 expression. 

960  

961 See Also 

962 -------- 

963 nvrtcAddNameExpression 

964 """ 

965 cdef cynvrtc.nvrtcProgram cyprog 

966 if prog is None: 1y

967 pprog = 0 1y

968 elif isinstance(prog, (nvrtcProgram,)): 1y

969 pprog = int(prog) 

970 else: 

971 pprog = int(nvrtcProgram(prog)) 1y

972 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1y

973 cdef const char* lowered_name = NULL 1y

974 with nogil: 1y

975 err = cynvrtc.nvrtcGetLoweredName(cyprog, name_expression, &lowered_name) 1y

976 if err != cynvrtc.NVRTC_SUCCESS: 1y

977 return (_nvrtcResult(err), None) 1y

978 return (_nvrtcResult_SUCCESS, <bytes>lowered_name if lowered_name != NULL else None) 

979  

980@cython.embedsignature(True) 

981def nvrtcGetPCHHeapSize(): 

982 """ retrieve the current size of the PCH Heap. 

983  

984 Returns 

985 ------- 

986 nvrtcResult 

987 - :py:obj:`~.NVRTC_SUCCESS` 

988 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

989 ret : int 

990 pointer to location where the size of the PCH Heap will be stored 

991 """ 

992 cdef size_t ret = 0 

993 with nogil: 

994 err = cynvrtc.nvrtcGetPCHHeapSize(&ret) 

995 if err != cynvrtc.NVRTC_SUCCESS: 

996 return (_nvrtcResult(err), None) 

997 return (_nvrtcResult_SUCCESS, ret) 

998  

999@cython.embedsignature(True) 

1000def nvrtcSetPCHHeapSize(size_t size): 

1001 """ set the size of the PCH Heap. 

1002  

1003 The requested size may be rounded up to a platform dependent alignment 

1004 (e.g. page size). If the PCH Heap has already been allocated, the heap 

1005 memory will be freed and a new PCH Heap will be allocated. 

1006  

1007 Parameters 

1008 ---------- 

1009 size : size_t 

1010 requested size of the PCH Heap, in bytes 

1011  

1012 Returns 

1013 ------- 

1014 nvrtcResult 

1015 - :py:obj:`~.NVRTC_SUCCESS` 

1016 """ 

1017 with nogil: 

1018 err = cynvrtc.nvrtcSetPCHHeapSize(size) 

1019 return (_nvrtcResult(err),) 

1020  

1021@cython.embedsignature(True) 

1022def nvrtcGetPCHCreateStatus(prog): 

1023 """ returns the PCH creation status. 

1024  

1025 NVRTC_SUCCESS indicates that the PCH was successfully created. 

1026 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED indicates that no PCH creation was 

1027 attempted, either because PCH functionality was not requested during 

1028 the preceding nvrtcCompileProgram call, or automatic PCH processing was 

1029 requested, and compiler chose not to create a PCH file. 

1030 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED indicates that a PCH file could 

1031 potentially have been created, but the compiler ran out space in the 

1032 PCH heap. In this scenario, the 

1033 :py:obj:`~.nvrtcGetPCHHeapSizeRequired()` can be used to query the 

1034 required heap size, the heap can be reallocated for this size with 

1035 :py:obj:`~.nvrtcSetPCHHeapSize()` and PCH creation may be reattempted 

1036 again invoking :py:obj:`~.nvrtcCompileProgram()` with a new NVRTC 

1037 program instance. NVRTC_ERROR_PCH_CREATE indicates that an error 

1038 condition prevented the PCH file from being created. 

1039  

1040 Parameters 

1041 ---------- 

1042 prog : :py:obj:`~.nvrtcProgram` 

1043 CUDA Runtime Compilation program. 

1044  

1045 Returns 

1046 ------- 

1047 nvrtcResult 

1048 - :py:obj:`~.NVRTC_SUCCESS` 

1049 - :py:obj:`~.NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED` 

1050 - :py:obj:`~.NVRTC_ERROR_PCH_CREATE` 

1051 - :py:obj:`~.NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED` 

1052 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

1053 """ 

1054 cdef cynvrtc.nvrtcProgram cyprog 

1055 if prog is None: 

1056 pprog = 0 

1057 elif isinstance(prog, (nvrtcProgram,)): 

1058 pprog = int(prog) 

1059 else: 

1060 pprog = int(nvrtcProgram(prog)) 

1061 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

1062 with nogil: 

1063 err = cynvrtc.nvrtcGetPCHCreateStatus(cyprog) 

1064 return (_nvrtcResult(err),) 

1065  

1066@cython.embedsignature(True) 

1067def nvrtcGetPCHHeapSizeRequired(prog): 

1068 """ retrieve the required size of the PCH heap required to compile the given program. 

1069  

1070 Parameters 

1071 ---------- 

1072 prog : :py:obj:`~.nvrtcProgram` 

1073 CUDA Runtime Compilation program. 

1074  

1075 Returns 

1076 ------- 

1077 nvrtcResult 

1078 - :py:obj:`~.NVRTC_SUCCESS` 

1079 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

1080 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` The size retrieved using this function is only valid if :py:obj:`~.nvrtcGetPCHCreateStatus()` returned NVRTC_SUCCESS or NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED 

1081 size : int 

1082 pointer to location where the required size of the PCH Heap will be 

1083 stored 

1084 """ 

1085 cdef cynvrtc.nvrtcProgram cyprog 

1086 if prog is None: 

1087 pprog = 0 

1088 elif isinstance(prog, (nvrtcProgram,)): 

1089 pprog = int(prog) 

1090 else: 

1091 pprog = int(nvrtcProgram(prog)) 

1092 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

1093 cdef size_t size = 0 

1094 with nogil: 

1095 err = cynvrtc.nvrtcGetPCHHeapSizeRequired(cyprog, &size) 

1096 if err != cynvrtc.NVRTC_SUCCESS: 

1097 return (_nvrtcResult(err), None) 

1098 return (_nvrtcResult_SUCCESS, size) 

1099  

1100@cython.embedsignature(True) 

1101def nvrtcSetFlowCallback(prog, callback, payload): 

1102 """ nvrtcSetFlowCallback registers a callback function that the compiler will invoke at different points during a call to nvrtcCompileProgram, and the callback function can decide whether to cancel compilation by returning specific values. 

1103  

1104 The callback function must satisfy the following constraints: 

1105  

1106 (1) Its signature should be: 

1107  

1108 **View CUDA Toolkit Documentation for a C++ code example** 

1109  

1110 When invoking the callback, the compiler will always pass `payload` to 

1111 param1 so that the callback may make decisions based on `payload` . 

1112 It'll always pass NULL to param2 for now which is reserved for future 

1113 extensions. 

1114  

1115 (2) It must return 1 to cancel compilation or 0 to continue. Other 

1116 return values are reserved for future use. 

1117  

1118 (3) It must return consistent values. Once it returns 1 at one point, 

1119 it must return 1 in all following invocations during the current 

1120 nvrtcCompileProgram call in progress. 

1121  

1122 (4) It must be thread-safe. 

1123  

1124 (5) It must not invoke any nvrtc/libnvvm/ptx APIs. 

1125  

1126 Parameters 

1127 ---------- 

1128 prog : :py:obj:`~.nvrtcProgram` 

1129 CUDA Runtime Compilation program. 

1130 callback : Any 

1131 the callback that issues cancellation signal. 

1132 payload : Any 

1133 to be passed as a parameter when invoking the callback. 

1134  

1135 Returns 

1136 ------- 

1137 nvrtcResult 

1138 - :py:obj:`~.NVRTC_SUCCESS` 

1139 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

1140 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

1141 """ 

1142 cdef cynvrtc.nvrtcProgram cyprog 

1143 if prog is None: 

1144 pprog = 0 

1145 elif isinstance(prog, (nvrtcProgram,)): 

1146 pprog = int(prog) 

1147 else: 

1148 pprog = int(nvrtcProgram(prog)) 

1149 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

1150 cdef _HelperInputVoidPtrStruct cycallbackHelper 

1151 cdef void* cycallback = _helper_input_void_ptr(callback, &cycallbackHelper) 

1152 cdef _HelperInputVoidPtrStruct cypayloadHelper 

1153 cdef void* cypayload = _helper_input_void_ptr(payload, &cypayloadHelper) 

1154 with nogil: 

1155 err = cynvrtc.nvrtcSetFlowCallback(cyprog, cycallback, cypayload) 

1156 _helper_input_void_ptr_free(&cycallbackHelper) 

1157 _helper_input_void_ptr_free(&cypayloadHelper) 

1158 return (_nvrtcResult(err),) 

1159  

1160@cython.embedsignature(True) 

1161def nvrtcGetTileIRSize(prog): 

1162 """ nvrtcGetTileIRSize sets the value of `TileIRSizeRet` with the size of the cuda_tile IR generated by the previous compilation of `prog`. 

1163  

1164 Parameters 

1165 ---------- 

1166 prog : :py:obj:`~.nvrtcProgram` 

1167 CUDA Runtime Compilation program. 

1168  

1169 Returns 

1170 ------- 

1171 nvrtcResult 

1172 - :py:obj:`~.NVRTC_SUCCESS` 

1173 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

1174 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

1175 TileIRSizeRet : int 

1176 Size of the generated cuda_tile IR. 

1177  

1178 See Also 

1179 -------- 

1180 :py:obj:`~.nvrtcGetTileIR` 

1181 """ 

1182 cdef cynvrtc.nvrtcProgram cyprog 

1183 if prog is None: 

1184 pprog = 0 

1185 elif isinstance(prog, (nvrtcProgram,)): 

1186 pprog = int(prog) 

1187 else: 

1188 pprog = int(nvrtcProgram(prog)) 

1189 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

1190 cdef size_t TileIRSizeRet = 0 

1191 with nogil: 

1192 err = cynvrtc.nvrtcGetTileIRSize(cyprog, &TileIRSizeRet) 

1193 if err != cynvrtc.NVRTC_SUCCESS: 

1194 return (_nvrtcResult(err), None) 

1195 return (_nvrtcResult_SUCCESS, TileIRSizeRet) 

1196  

1197@cython.embedsignature(True) 

1198def nvrtcGetTileIR(prog, char* TileIR): 

1199 """ nvrtcGetTileIR stores the cuda_tile IR generated by the previous compilation of `prog` in the memory pointed by `TileIR`. 

1200  

1201 Parameters 

1202 ---------- 

1203 prog : :py:obj:`~.nvrtcProgram` 

1204 CUDA Runtime Compilation program. 

1205 TileIR : bytes 

1206 Generated cuda_tile IR. 

1207  

1208 Returns 

1209 ------- 

1210 nvrtcResult 

1211 - :py:obj:`~.NVRTC_SUCCESS` 

1212 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` 

1213 - :py:obj:`~.NVRTC_ERROR_INVALID_PROGRAM` 

1214  

1215 See Also 

1216 -------- 

1217 :py:obj:`~.nvrtcGetTileIRSize` 

1218 """ 

1219 cdef cynvrtc.nvrtcProgram cyprog 

1220 if prog is None: 

1221 pprog = 0 

1222 elif isinstance(prog, (nvrtcProgram,)): 

1223 pprog = int(prog) 

1224 else: 

1225 pprog = int(nvrtcProgram(prog)) 

1226 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 

1227 with nogil: 

1228 err = cynvrtc.nvrtcGetTileIR(cyprog, TileIR) 

1229 return (_nvrtcResult(err),) 

1230  

1231@cython.embedsignature(True) 

1232def nvrtcInstallBundledHeaders(char* installPath, unsigned int flags): 

1233 """ nvrtcInstallBundledHeaders extracts CUDA headers bundled with NVRTC to a specified directory for use during compilation. 

1234  

1235 NVRTC bundles a set of CUDA Toolkit headers and CUDA C++ Core Libraries 

1236 (CCCL) within libnvrtc-builtins. This function extracts these headers 

1237 to the specified directory, allowing NVRTC programs to compile without 

1238 requiring a separate CUDA Toolkit installation. The bundled headers 

1239 match those available in the CUDA Toolkit plus CCCL libraries. 

1240  

1241 After extraction, users can compile kernels by passing appropriate 

1242 include paths (such as "-I<installPath>" and "-I<installPath>/cccl") to 

1243 nvrtcCompileProgram. 

1244  

1245 A version marker file (.nvrtc_headers_version) is created in the 

1246 installation directory to track the installed version. 

1247  

1248 This function is thread-safe and process-safe. Concurrent calls from 

1249 multiple threads or processes will be serialized using file locking. By 

1250 default, the function waits for the lock; use 

1251 NVRTC_INSTALL_HEADERS_NO_WAIT to return immediately with 

1252 NVRTC_ERROR_BUSY if another process holds the lock. 

1253  

1254 Parameters 

1255 ---------- 

1256 installPath : bytes 

1257 Path where headers should be extracted (UTF-8 encoded). The 

1258 directory will be created if it doesn't exist. 

1259 flags : unsigned int 

1260 NVRTC_INSTALL_HEADERS_* flags: 

1261  

1262 Returns 

1263 ------- 

1264 nvrtcResult 

1265 - :py:obj:`~.NVRTC_SUCCESS` 

1266 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` (invalid path or conflicting flags like SKIP_IF_EXISTS | FORCE_OVERWRITE) 

1267 - :py:obj:`~.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE` (extraction failed or version mismatch) 

1268 - :py:obj:`~.NVRTC_ERROR_BUSY` (lock held by another process and NVRTC_INSTALL_HEADERS_NO_WAIT was specified) 

1269 errorLog : bytes 

1270 Optional pointer to receive detailed error message on failure. If 

1271 non-NULL, `*errorLog` will be set to point to a string describing 

1272 the error cause. Note: subsequent API calls from the same thread 

1273 may overwrite this message. May be NULL if error details are not 

1274 needed. 

1275  

1276 See Also 

1277 -------- 

1278 :py:obj:`~.nvrtcCompileProgram` 

1279  

1280 Notes 

1281 ----- 

1282 Use NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS to avoid reinstalling if headers already exist. Use NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE to guarantee consistency by clearing the directory first. 

1283 """ 

1284 cdef const char* errorLog = NULL 

1285 with nogil: 

1286 err = cynvrtc.nvrtcInstallBundledHeaders(installPath, flags, &errorLog) 

1287 if err != cynvrtc.NVRTC_SUCCESS: 

1288 return (_nvrtcResult(err), None) 

1289 return (_nvrtcResult_SUCCESS, <bytes>errorLog if errorLog != NULL else None) 

1290  

1291@cython.embedsignature(True) 

1292def nvrtcGetBundledHeadersInfo(): 

1293 """ nvrtcGetBundledHeadersInfo queries information about the bundled headers without extracting them. 

1294  

1295 This function allows users to determine if bundled headers are 

1296 available and get size estimates before calling 

1297 nvrtcInstallBundledHeaders. 

1298  

1299 Returns 

1300 ------- 

1301 nvrtcResult 

1302 - :py:obj:`~.NVRTC_SUCCESS` 

1303 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` (info is NULL) 

1304 - :py:obj:`~.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE` (failed to query bundled headers) 

1305 info : :py:obj:`~.nvrtcBundledHeadersInfo` 

1306 Pointer to structure to receive header information. 

1307 errorLog : bytes 

1308 Optional pointer to receive detailed error message on failure. If 

1309 non-NULL, `*errorLog` will be set to point to a string describing 

1310 the error cause. Note: subsequent API calls from the same thread 

1311 may overwrite this message. May be NULL if error details are not 

1312 needed. 

1313 """ 

1314 cdef nvrtcBundledHeadersInfo info = nvrtcBundledHeadersInfo() 

1315 cdef const char* errorLog = NULL 

1316 with nogil: 

1317 err = cynvrtc.nvrtcGetBundledHeadersInfo(<cynvrtc.nvrtcBundledHeadersInfo*>info._pvt_ptr, &errorLog) 

1318 if err != cynvrtc.NVRTC_SUCCESS: 

1319 return (_nvrtcResult(err), None, None) 

1320 return (_nvrtcResult_SUCCESS, info, <bytes>errorLog if errorLog != NULL else None) 

1321  

1322@cython.embedsignature(True) 

1323def nvrtcRemoveBundledHeaders(char* installPath): 

1324 """ nvrtcRemoveBundledHeaders removes previously installed bundled headers. 

1325  

1326 This function removes the headers installed by 

1327 nvrtcInstallBundledHeaders, helping users manage disk space. It 

1328 recursively removes all files and subdirectories within the 

1329 installation directory. 

1330  

1331 Parameters 

1332 ---------- 

1333 installPath : bytes 

1334 Path where headers were previously installed. Must be the same path 

1335 used with nvrtcInstallBundledHeaders. 

1336  

1337 Returns 

1338 ------- 

1339 nvrtcResult 

1340 - :py:obj:`~.NVRTC_SUCCESS` 

1341 - :py:obj:`~.NVRTC_ERROR_INVALID_INPUT` (invalid path) 

1342 - :py:obj:`~.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE` (removal failed) 

1343 errorLog : bytes 

1344 Optional pointer to receive detailed error message on failure. If 

1345 non-NULL, `*errorLog` will be set to point to a string describing 

1346 the error cause. Note: subsequent API calls from the same thread 

1347 may overwrite this message. May be NULL if error details are not 

1348 needed. 

1349  

1350 Notes 

1351 ----- 

1352 This function will remove ALL contents of the specified directory, not just files installed by NVRTC. Use with caution. 

1353 """ 

1354 cdef const char* errorLog = NULL 

1355 with nogil: 

1356 err = cynvrtc.nvrtcRemoveBundledHeaders(installPath, &errorLog) 

1357 if err != cynvrtc.NVRTC_SUCCESS: 

1358 return (_nvrtcResult(err), None) 

1359 return (_nvrtcResult_SUCCESS, <bytes>errorLog if errorLog != NULL else None) 

1360  

1361@cython.embedsignature(True) 

1362def sizeof(objType): 

1363 """ Returns the size of provided CUDA Python structure in bytes 

1364  

1365 Parameters 

1366 ---------- 

1367 objType : Any 

1368 CUDA Python object 

1369  

1370 Returns 

1371 ------- 

1372 lowered_name : int 

1373 The size of `objType` in bytes 

1374 """ 

1375  

1376 if objType == nvrtcProgram: 

1377 return sizeof(cynvrtc.nvrtcProgram) 

1378  

1379 if objType == nvrtcBundledHeadersInfo: 

1380 return sizeof(cynvrtc.nvrtcBundledHeadersInfo) 

1381 raise TypeError("Unknown type: " + str(objType))