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

403 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-19 01:12 +0000

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

2# SPDX-License-Identifier: Apache-2.0 

3  

4# This code was automatically generated with version 13.3.0. Do not modify it directly. 

5# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=ac1af34ecd1468ac91074ce7f18423af19fbc7727653cdfc1cd9b6f33f6cec72 

6from typing import Any, Optional 

7import cython 

8import ctypes 

9from libc.stdlib cimport calloc, malloc, free 

10from libc cimport string 

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

12from libc.stddef cimport wchar_t 

13from libc.limits cimport CHAR_MIN 

14from libcpp.vector cimport vector 

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

16from cpython.bytes cimport PyBytes_FromStringAndSize 

17from ._internal._fast_enum import FastEnum as _FastEnum 

18  

19import cuda.bindings.driver as _driver 

20_driver = _driver.__dict__ 

21include "_lib/utils.pxi" 

22  

23ctypedef unsigned long long signed_char_ptr 

24ctypedef unsigned long long unsigned_char_ptr 

25ctypedef unsigned long long char_ptr 

26ctypedef unsigned long long short_ptr 

27ctypedef unsigned long long unsigned_short_ptr 

28ctypedef unsigned long long int_ptr 

29ctypedef unsigned long long long_int_ptr 

30ctypedef unsigned long long long_long_int_ptr 

31ctypedef unsigned long long unsigned_int_ptr 

32ctypedef unsigned long long unsigned_long_int_ptr 

33ctypedef unsigned long long unsigned_long_long_int_ptr 

34ctypedef unsigned long long uint32_t_ptr 

35ctypedef unsigned long long uint64_t_ptr 

36ctypedef unsigned long long int32_t_ptr 

37ctypedef unsigned long long int64_t_ptr 

38ctypedef unsigned long long unsigned_ptr 

39ctypedef unsigned long long unsigned_long_long_ptr 

40ctypedef unsigned long long long_long_ptr 

41ctypedef unsigned long long size_t_ptr 

42ctypedef unsigned long long long_ptr 

43ctypedef unsigned long long float_ptr 

44ctypedef unsigned long long double_ptr 

45ctypedef unsigned long long void_ptr 

46  

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

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

49NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS = cynvrtc.NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS 

50  

51#: Clear existing directory contents before installation. Guarantees 

52#: consistency by removing any existing files first. 

53NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE = cynvrtc.NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE 

54  

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

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

57#: FORCE_OVERWRITE using bitwise OR. 

58NVRTC_INSTALL_HEADERS_NO_WAIT = cynvrtc.NVRTC_INSTALL_HEADERS_NO_WAIT 

59  

60class nvrtcResult(_FastEnum): 

61 """ 

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

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

64 indicate the call result. 

65 """ 

66  

67 NVRTC_SUCCESS = cynvrtc.nvrtcResult.NVRTC_SUCCESS 

68  

69 NVRTC_ERROR_OUT_OF_MEMORY = cynvrtc.nvrtcResult.NVRTC_ERROR_OUT_OF_MEMORY 

70  

71 NVRTC_ERROR_PROGRAM_CREATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_PROGRAM_CREATION_FAILURE 

72  

73 NVRTC_ERROR_INVALID_INPUT = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_INPUT 

74  

75 NVRTC_ERROR_INVALID_PROGRAM = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_PROGRAM 

76  

77 NVRTC_ERROR_INVALID_OPTION = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_OPTION 

78  

79 NVRTC_ERROR_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_COMPILATION 

80  

81 NVRTC_ERROR_BUILTIN_OPERATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE 

82  

83 NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 

84  

85 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

86  

87 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID = cynvrtc.nvrtcResult.NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

88  

89 NVRTC_ERROR_INTERNAL_ERROR = cynvrtc.nvrtcResult.NVRTC_ERROR_INTERNAL_ERROR 

90  

91 NVRTC_ERROR_TIME_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_FILE_WRITE_FAILED 

92  

93 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED 

94  

95 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED 

96  

97 NVRTC_ERROR_PCH_CREATE = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE 

98  

99 NVRTC_ERROR_CANCELLED = cynvrtc.nvrtcResult.NVRTC_ERROR_CANCELLED 

100  

101 NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED 

102  

103 NVRTC_ERROR_BUSY = cynvrtc.nvrtcResult.NVRTC_ERROR_BUSY 

104  

105cdef object _nvrtcResult = nvrtcResult 

106cdef object _nvrtcResult_SUCCESS = nvrtcResult.NVRTC_SUCCESS 

107  

108cdef class nvrtcProgram: 

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

110  

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

112  

113 Methods 

114 ------- 

115 getPtr() 

116 Get memory address of class instance 

117  

118 """ 

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

120 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 z A B C :b;b

121 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 z A B C :b;b

122 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 z A B C :b;b

123 else: 

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

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

126 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 z A B C :b;b

127 def __repr__(self): 

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

129 def __index__(self): 

130 return self.__int__() 

131 def __eq__(self, other): 

132 if not isinstance(other, nvrtcProgram): 

133 return False 

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

135 def __hash__(self): 

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

137 def __int__(self): 

138 return <void_ptr>self._pvt_ptr[0] 1jbcdefghiklmnopqrstuvwxyzABC

139 def getPtr(self): 

140 return <void_ptr>self._pvt_ptr 1jklmnopqrstuvwxyzAB

141  

142cdef class anon_struct0: 

143 """ 

144 Attributes 

145 ---------- 

146  

147 available : int 

148  

149  

150  

151 compressedSize : size_t 

152  

153  

154  

155 uncompressedSize : size_t 

156  

157  

158  

159 cudaVersionMajor : int 

160  

161  

162  

163 cudaVersionMinor : int 

164  

165  

166  

167 numFiles : unsigned int 

168  

169  

170  

171 Methods 

172 ------- 

173 getPtr() 

174 Get memory address of class instance 

175 """ 

176 def __cinit__(self, void_ptr _ptr): 

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

178  

179 def __init__(self, void_ptr _ptr): 

180 pass 

181 def __dealloc__(self): 

182 pass 

183 def getPtr(self): 

184 return <void_ptr>self._pvt_ptr 

185 def __repr__(self): 

186 if self._pvt_ptr is not NULL: 

187 str_list = [] 

188  

189 try: 

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

191 except ValueError: 

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

193  

194  

195 try: 

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

197 except ValueError: 

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

199  

200  

201 try: 

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

203 except ValueError: 

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

205  

206  

207 try: 

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

209 except ValueError: 

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

211  

212  

213 try: 

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

215 except ValueError: 

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

217  

218  

219 try: 

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

221 except ValueError: 

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

223  

224 return '\n'.join(str_list) 

225 else: 

226 return '' 

227  

228 @property 

229 def available(self): 

230 return self._pvt_ptr[0].available 

231 @available.setter 

232 def available(self, int available): 

233 self._pvt_ptr[0].available = available 

234  

235  

236 @property 

237 def compressedSize(self): 

238 return self._pvt_ptr[0].compressedSize 

239 @compressedSize.setter 

240 def compressedSize(self, size_t compressedSize): 

241 self._pvt_ptr[0].compressedSize = compressedSize 

242  

243  

244 @property 

245 def uncompressedSize(self): 

246 return self._pvt_ptr[0].uncompressedSize 

247 @uncompressedSize.setter 

248 def uncompressedSize(self, size_t uncompressedSize): 

249 self._pvt_ptr[0].uncompressedSize = uncompressedSize 

250  

251  

252 @property 

253 def cudaVersionMajor(self): 

254 return self._pvt_ptr[0].cudaVersionMajor 

255 @cudaVersionMajor.setter 

256 def cudaVersionMajor(self, int cudaVersionMajor): 

257 self._pvt_ptr[0].cudaVersionMajor = cudaVersionMajor 

258  

259  

260 @property 

261 def cudaVersionMinor(self): 

262 return self._pvt_ptr[0].cudaVersionMinor 

263 @cudaVersionMinor.setter 

264 def cudaVersionMinor(self, int cudaVersionMinor): 

265 self._pvt_ptr[0].cudaVersionMinor = cudaVersionMinor 

266  

267  

268 @property 

269 def numFiles(self): 

270 return self._pvt_ptr[0].numFiles 

271 @numFiles.setter 

272 def numFiles(self, unsigned int numFiles): 

273 self._pvt_ptr[0].numFiles = numFiles 

274  

275  

276cdef class nvrtcBundledHeadersInfo(anon_struct0): 

277 """ 

278 Attributes 

279 ---------- 

280  

281 available : int 

282  

283  

284  

285 compressedSize : size_t 

286  

287  

288  

289 uncompressedSize : size_t 

290  

291  

292  

293 cudaVersionMajor : int 

294  

295  

296  

297 cudaVersionMinor : int 

298  

299  

300  

301 numFiles : unsigned int 

302  

303  

304  

305 Methods 

306 ------- 

307 getPtr() 

308 Get memory address of class instance 

309 """ 

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

311 if _ptr == 0: 

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

313 else: 

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

315  

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

317 pass 

318  

319@cython.embedsignature(True) 

320def nvrtcGetErrorString(result not None : nvrtcResult): 

321 """ 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"`. 

322  

323 Parameters 

324 ---------- 

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

326 CUDA Runtime Compilation API result code. 

327  

328 Returns 

329 ------- 

330 nvrtcResult.NVRTC_SUCCESS 

331 nvrtcResult.NVRTC_SUCCESS 

332 bytes 

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

334 """ 

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

336 with nogil: 2j =b

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

338 return (nvrtcResult.NVRTC_SUCCESS, err) 2j =b

339  

340@cython.embedsignature(True) 

341def nvrtcVersion(): 

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

343  

344 Returns 

345 ------- 

346 nvrtcResult 

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

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

349 major : int 

350 CUDA Runtime Compilation major version number. 

351 minor : int 

352 CUDA Runtime Compilation minor version number. 

353 """ 

354 cdef int major = 0 2a b c d e f g h i 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,b-b.b/b

355 cdef int minor = 0 2a b c d e f g h i 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,b-b.b/b

356 with nogil: 2a b c d e f g h i 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,b-b.b/b

357 err = cynvrtc.nvrtcVersion(&major, &minor) 2a b c d e f g h i 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,b-b.b/b

358 if err != cynvrtc.NVRTC_SUCCESS: 2a b c d e f g h i 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,b-b.b/b

359 return (_nvrtcResult(err), None, None) 

360 return (_nvrtcResult_SUCCESS, major, minor) 2a b c d e f g h i 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,b-b.b/b

361  

362@cython.embedsignature(True) 

363def nvrtcGetNumSupportedArchs(): 

364 """ 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. 

365  

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

367  

368 Returns 

369 ------- 

370 nvrtcResult 

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

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

373 numArchs : int 

374 number of supported architectures. 

375 """ 

376 cdef int numArchs = 0 1D

377 with nogil: 1D

378 err = cynvrtc.nvrtcGetNumSupportedArchs(&numArchs) 1D

379 if err != cynvrtc.NVRTC_SUCCESS: 1D

380 return (_nvrtcResult(err), None) 

381 return (_nvrtcResult_SUCCESS, numArchs) 1D

382  

383@cython.embedsignature(True) 

384def nvrtcGetSupportedArchs(): 

385 """ 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`. 

386  

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

388  

389 Returns 

390 ------- 

391 nvrtcResult 

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

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

394 supportedArchs : list[int] 

395 sorted array of supported architectures. 

396 """ 

397 cdef vector[int] supportedArchs 

398 _, s = nvrtcGetNumSupportedArchs() 1D

399 supportedArchs.resize(s) 1D

400  

401 with nogil: 1D

402 err = cynvrtc.nvrtcGetSupportedArchs(supportedArchs.data()) 1D

403 if err != cynvrtc.NVRTC_SUCCESS: 1D

404 return (_nvrtcResult(err), None) 

405 return (_nvrtcResult_SUCCESS, supportedArchs) 1D

406  

407@cython.embedsignature(True) 

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

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

410  

411 Parameters 

412 ---------- 

413 src : bytes 

414 CUDA program source. 

415 name : bytes 

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

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

418 numHeaders : int 

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

420 to 0. 

421 headers : list[bytes] 

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

423 is 0. 

424 includeNames : list[bytes] 

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

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

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

428 here. 

429  

430 Returns 

431 ------- 

432 nvrtcResult 

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

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

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

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

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

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

439 CUDA Runtime Compilation program. 

440  

441 See Also 

442 -------- 

443 :py:obj:`~.nvrtcDestroyProgram` 

444 """ 

445 includeNames = [] if includeNames is None else includeNames 1jbcdefghiklmnopqrstuvwxyzAB

446 if not all(isinstance(_x, (bytes)) for _x in includeNames): 1jbcdefghiklmnopqrstuvwxyzAB

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

448 headers = [] if headers is None else headers 1jbcdefghiklmnopqrstuvwxyzAB

449 if not all(isinstance(_x, (bytes)) for _x in headers): 1jbcdefghiklmnopqrstuvwxyzAB

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

451 cdef nvrtcProgram prog = nvrtcProgram() 1jbcdefghiklmnopqrstuvwxyzAB

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

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

454 cdef vector[const char*] cyheaders = headers 1jbcdefghiklmnopqrstuvwxyzAB

455 cdef vector[const char*] cyincludeNames = includeNames 1jbcdefghiklmnopqrstuvwxyzAB

456 with nogil: 1jbcdefghiklmnopqrstuvwxyzAB

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

458 if err != cynvrtc.NVRTC_SUCCESS: 1jbcdefghiklmnopqrstuvwxyzAB

459 return (_nvrtcResult(err), None) 

460 return (_nvrtcResult_SUCCESS, prog) 1jbcdefghiklmnopqrstuvwxyzAB

461  

462@cython.embedsignature(True) 

463def nvrtcDestroyProgram(prog): 

464 """ nvrtcDestroyProgram destroys the given program. 

465  

466 Parameters 

467 ---------- 

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

469 CUDA Runtime Compilation program. 

470  

471 Returns 

472 ------- 

473 nvrtcResult 

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

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

476  

477 See Also 

478 -------- 

479 :py:obj:`~.nvrtcCreateProgram` 

480 """ 

481 cdef cynvrtc.nvrtcProgram *cyprog 

482 if prog is None: 1jklmnopqrstuvwxyzAB

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

484 elif isinstance(prog, (nvrtcProgram,)): 1jklmnopqrstuvwxyzAB

485 pprog = prog.getPtr() 1jklmnopqrstuvwxyzAB

486 cyprog = <cynvrtc.nvrtcProgram*><void_ptr>pprog 1jklmnopqrstuvwxyzAB

487 elif isinstance(prog, (int)): 

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

489 else: 

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

491 with nogil: 1jklmnopqrstuvwxyzAB

492 err = cynvrtc.nvrtcDestroyProgram(cyprog) 1jklmnopqrstuvwxyzAB

493 return (_nvrtcResult(err),) 1jklmnopqrstuvwxyzAB

494  

495@cython.embedsignature(True) 

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

497 """ nvrtcCompileProgram compiles the given program. 

498  

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

500 Options`. 

501  

502 Parameters 

503 ---------- 

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

505 CUDA Runtime Compilation program. 

506 numOptions : int 

507 Number of compiler options passed. 

508 options : list[bytes] 

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

510 `NULL` when `numOptions` is 0. 

511  

512 Returns 

513 ------- 

514 nvrtcResult 

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

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

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

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

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

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

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

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

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

524 """ 

525 options = [] if options is None else options 1jbcdefghiklmnopqrstuvwxyzAB

526 if not all(isinstance(_x, (bytes)) for _x in options): 1jbcdefghiklmnopqrstuvwxyzAB

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

528 cdef cynvrtc.nvrtcProgram cyprog 

529 if prog is None: 1jbcdefghiklmnopqrstuvwxyzAB

530 pprog = 0 

531 elif isinstance(prog, (nvrtcProgram,)): 1jbcdefghiklmnopqrstuvwxyzAB

532 pprog = int(prog) 1jbcdefghiklmnopqrstuvwxyzAB

533 else: 

534 pprog = int(nvrtcProgram(prog)) 

535 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1jbcdefghiklmnopqrstuvwxyzAB

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

537 cdef vector[const char*] cyoptions = options 1jbcdefghiklmnopqrstuvwxyzAB

538 with nogil: 1jbcdefghiklmnopqrstuvwxyzAB

539 err = cynvrtc.nvrtcCompileProgram(cyprog, numOptions, cyoptions.data()) 1jbcdefghiklmnopqrstuvwxyzAB

540 return (_nvrtcResult(err),) 1jbcdefghiklmnopqrstuvwxyzAB

541  

542@cython.embedsignature(True) 

543def nvrtcGetPTXSize(prog): 

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

545  

546 Parameters 

547 ---------- 

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

549 CUDA Runtime Compilation program. 

550  

551 Returns 

552 ------- 

553 nvrtcResult 

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

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

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

557 ptxSizeRet : int 

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

559  

560 See Also 

561 -------- 

562 :py:obj:`~.nvrtcGetPTX` 

563 """ 

564 cdef cynvrtc.nvrtcProgram cyprog 

565 if prog is None: 

566 pprog = 0 

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

568 pprog = int(prog) 

569 else: 

570 pprog = int(nvrtcProgram(prog)) 

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

572 cdef size_t ptxSizeRet = 0 

573 with nogil: 

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

575 if err != cynvrtc.NVRTC_SUCCESS: 

576 return (_nvrtcResult(err), None) 

577 return (_nvrtcResult_SUCCESS, ptxSizeRet) 

578  

579@cython.embedsignature(True) 

580def nvrtcGetPTX(prog, char* ptx): 

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

582  

583 Parameters 

584 ---------- 

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

586 CUDA Runtime Compilation program. 

587 ptx : bytes 

588 Compiled result. 

589  

590 Returns 

591 ------- 

592 nvrtcResult 

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

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

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

596  

597 See Also 

598 -------- 

599 :py:obj:`~.nvrtcGetPTXSize` 

600 """ 

601 cdef cynvrtc.nvrtcProgram cyprog 

602 if prog is None: 

603 pprog = 0 

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

605 pprog = int(prog) 

606 else: 

607 pprog = int(nvrtcProgram(prog)) 

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

609 with nogil: 

610 err = cynvrtc.nvrtcGetPTX(cyprog, ptx) 

611 return (_nvrtcResult(err),) 

612  

613@cython.embedsignature(True) 

614def nvrtcGetCUBINSize(prog): 

615 """ 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. 

616  

617 Parameters 

618 ---------- 

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

620 CUDA Runtime Compilation program. 

621  

622 Returns 

623 ------- 

624 nvrtcResult 

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

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

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

628 cubinSizeRet : int 

629 Size of the generated cubin. 

630  

631 See Also 

632 -------- 

633 :py:obj:`~.nvrtcGetCUBIN` 

634 """ 

635 cdef cynvrtc.nvrtcProgram cyprog 

636 if prog is None: 1bcdefghiopqrst

637 pprog = 0 

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

639 pprog = int(prog) 1bcdefghiopqrst

640 else: 

641 pprog = int(nvrtcProgram(prog)) 

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

643 cdef size_t cubinSizeRet = 0 1bcdefghiopqrst

644 with nogil: 1bcdefghiopqrst

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

646 if err != cynvrtc.NVRTC_SUCCESS: 1bcdefghiopqrst

647 return (_nvrtcResult(err), None) 

648 return (_nvrtcResult_SUCCESS, cubinSizeRet) 1bcdefghiopqrst

649  

650@cython.embedsignature(True) 

651def nvrtcGetCUBIN(prog, char* cubin): 

652 """ 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. 

653  

654 Parameters 

655 ---------- 

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

657 CUDA Runtime Compilation program. 

658 cubin : bytes 

659 Compiled and assembled result. 

660  

661 Returns 

662 ------- 

663 nvrtcResult 

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

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

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

667  

668 See Also 

669 -------- 

670 :py:obj:`~.nvrtcGetCUBINSize` 

671 """ 

672 cdef cynvrtc.nvrtcProgram cyprog 

673 if prog is None: 1bcdefghiopqrst

674 pprog = 0 

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

676 pprog = int(prog) 1bcdefghiopqrst

677 else: 

678 pprog = int(nvrtcProgram(prog)) 

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

680 with nogil: 1bcdefghiopqrst

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

682 return (_nvrtcResult(err),) 1bcdefghiopqrst

683  

684@cython.embedsignature(True) 

685def nvrtcGetLTOIRSize(prog): 

686 """ 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`. 

687  

688 Parameters 

689 ---------- 

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

691 CUDA Runtime Compilation program. 

692  

693 Returns 

694 ------- 

695 nvrtcResult 

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

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

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

699 LTOIRSizeRet : int 

700 Size of the generated LTO IR. 

701  

702 See Also 

703 -------- 

704 :py:obj:`~.nvrtcGetLTOIR` 

705 """ 

706 cdef cynvrtc.nvrtcProgram cyprog 

707 if prog is None: 1klmnuvwxyzAB

708 pprog = 0 

709 elif isinstance(prog, (nvrtcProgram,)): 1klmnuvwxyzAB

710 pprog = int(prog) 1klmnuvwxyzAB

711 else: 

712 pprog = int(nvrtcProgram(prog)) 

713 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1klmnuvwxyzAB

714 cdef size_t LTOIRSizeRet = 0 1klmnuvwxyzAB

715 with nogil: 1klmnuvwxyzAB

716 err = cynvrtc.nvrtcGetLTOIRSize(cyprog, &LTOIRSizeRet) 1klmnuvwxyzAB

717 if err != cynvrtc.NVRTC_SUCCESS: 1klmnuvwxyzAB

718 return (_nvrtcResult(err), None) 

719 return (_nvrtcResult_SUCCESS, LTOIRSizeRet) 1klmnuvwxyzAB

720  

721@cython.embedsignature(True) 

722def nvrtcGetLTOIR(prog, char* LTOIR): 

723 """ 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`. 

724  

725 Parameters 

726 ---------- 

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

728 CUDA Runtime Compilation program. 

729 LTOIR : bytes 

730 Compiled result. 

731  

732 Returns 

733 ------- 

734 nvrtcResult 

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

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

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

738  

739 See Also 

740 -------- 

741 :py:obj:`~.nvrtcGetLTOIRSize` 

742 """ 

743 cdef cynvrtc.nvrtcProgram cyprog 

744 if prog is None: 1klmnuvwxyzAB

745 pprog = 0 

746 elif isinstance(prog, (nvrtcProgram,)): 1klmnuvwxyzAB

747 pprog = int(prog) 1klmnuvwxyzAB

748 else: 

749 pprog = int(nvrtcProgram(prog)) 

750 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1klmnuvwxyzAB

751 with nogil: 1klmnuvwxyzAB

752 err = cynvrtc.nvrtcGetLTOIR(cyprog, LTOIR) 1klmnuvwxyzAB

753 return (_nvrtcResult(err),) 1klmnuvwxyzAB

754  

755@cython.embedsignature(True) 

756def nvrtcGetOptiXIRSize(prog): 

757 """ 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. 

758  

759 Parameters 

760 ---------- 

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

762 CUDA Runtime Compilation program. 

763  

764 Returns 

765 ------- 

766 nvrtcResult 

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

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

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

770 optixirSizeRet : int 

771 Size of the generated LTO IR. 

772  

773 See Also 

774 -------- 

775 :py:obj:`~.nvrtcGetOptiXIR` 

776 """ 

777 cdef cynvrtc.nvrtcProgram cyprog 

778 if prog is None: 

779 pprog = 0 

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

781 pprog = int(prog) 

782 else: 

783 pprog = int(nvrtcProgram(prog)) 

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

785 cdef size_t optixirSizeRet = 0 

786 with nogil: 

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

788 if err != cynvrtc.NVRTC_SUCCESS: 

789 return (_nvrtcResult(err), None) 

790 return (_nvrtcResult_SUCCESS, optixirSizeRet) 

791  

792@cython.embedsignature(True) 

793def nvrtcGetOptiXIR(prog, char* optixir): 

794 """ 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. 

795  

796 Parameters 

797 ---------- 

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

799 CUDA Runtime Compilation program. 

800 optixir : bytes 

801 Optix IR Compiled result. 

802  

803 Returns 

804 ------- 

805 nvrtcResult 

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

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

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

809  

810 See Also 

811 -------- 

812 :py:obj:`~.nvrtcGetOptiXIRSize` 

813 """ 

814 cdef cynvrtc.nvrtcProgram cyprog 

815 if prog is None: 

816 pprog = 0 

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

818 pprog = int(prog) 

819 else: 

820 pprog = int(nvrtcProgram(prog)) 

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

822 with nogil: 

823 err = cynvrtc.nvrtcGetOptiXIR(cyprog, optixir) 

824 return (_nvrtcResult(err),) 

825  

826@cython.embedsignature(True) 

827def nvrtcGetProgramLogSize(prog): 

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

829  

830 Note that compilation log may be generated with warnings and 

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

832  

833 Parameters 

834 ---------- 

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

836 CUDA Runtime Compilation program. 

837  

838 Returns 

839 ------- 

840 nvrtcResult 

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

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

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

844 logSizeRet : int 

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

846  

847 See Also 

848 -------- 

849 :py:obj:`~.nvrtcGetProgramLog` 

850 """ 

851 cdef cynvrtc.nvrtcProgram cyprog 

852 if prog is None: 1jbcdefghi

853 pprog = 0 

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

855 pprog = int(prog) 1jbcdefghi

856 else: 

857 pprog = int(nvrtcProgram(prog)) 

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

859 cdef size_t logSizeRet = 0 1jbcdefghi

860 with nogil: 1jbcdefghi

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

862 if err != cynvrtc.NVRTC_SUCCESS: 1jbcdefghi

863 return (_nvrtcResult(err), None) 

864 return (_nvrtcResult_SUCCESS, logSizeRet) 1jbcdefghi

865  

866@cython.embedsignature(True) 

867def nvrtcGetProgramLog(prog, char* log): 

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

869  

870 Parameters 

871 ---------- 

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

873 CUDA Runtime Compilation program. 

874 log : bytes 

875 Compilation log. 

876  

877 Returns 

878 ------- 

879 nvrtcResult 

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

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

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

883  

884 See Also 

885 -------- 

886 :py:obj:`~.nvrtcGetProgramLogSize` 

887 """ 

888 cdef cynvrtc.nvrtcProgram cyprog 

889 if prog is None: 1jbcdefghi

890 pprog = 0 

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

892 pprog = int(prog) 1jbcdefghi

893 else: 

894 pprog = int(nvrtcProgram(prog)) 

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

896 with nogil: 1jbcdefghi

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

898 return (_nvrtcResult(err),) 1jbcdefghi

899  

900@cython.embedsignature(True) 

901def nvrtcAddNameExpression(prog, char* name_expression): 

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

903  

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

905 call to nvrtcGetLoweredName to extract the lowered name. 

906  

907 Parameters 

908 ---------- 

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

910 CUDA Runtime Compilation program. 

911 name_expression : bytes 

912 constant expression denoting the address of a global function or 

913 device/__constant__ variable. 

914  

915 Returns 

916 ------- 

917 nvrtcResult 

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

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

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

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

922  

923 See Also 

924 -------- 

925 :py:obj:`~.nvrtcGetLoweredName` 

926 """ 

927 cdef cynvrtc.nvrtcProgram cyprog 

928 if prog is None: 

929 pprog = 0 

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

931 pprog = int(prog) 

932 else: 

933 pprog = int(nvrtcProgram(prog)) 

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

935 with nogil: 

936 err = cynvrtc.nvrtcAddNameExpression(cyprog, name_expression) 

937 return (_nvrtcResult(err),) 

938  

939@cython.embedsignature(True) 

940def nvrtcGetLoweredName(prog, char* name_expression): 

941 """ 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. 

942  

943 Parameters 

944 ---------- 

945 prog : nvrtcProgram 

946 CUDA Runtime Compilation program. 

947 name_expression : bytes 

948 constant expression denoting the address of a global function or 

949 device/__constant__ variable. 

950  

951 Returns 

952 ------- 

953 nvrtcResult 

954 NVRTC_SUCCESS 

955 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

956 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

957 lowered_name : bytes 

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

959 lowered (mangled) name corresponding to the provided name 

960 expression. 

961  

962 See Also 

963 -------- 

964 nvrtcAddNameExpression 

965 """ 

966 cdef cynvrtc.nvrtcProgram cyprog 

967 if prog is None: 1C

968 pprog = 0 1C

969 elif isinstance(prog, (nvrtcProgram,)): 1C

970 pprog = int(prog) 

971 else: 

972 pprog = int(nvrtcProgram(prog)) 1C

973 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1C

974 cdef const char* lowered_name = NULL 1C

975 with nogil: 1C

976 err = cynvrtc.nvrtcGetLoweredName(cyprog, name_expression, &lowered_name) 1C

977 if err != cynvrtc.NVRTC_SUCCESS: 1C

978 return (_nvrtcResult(err), None) 1C

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

980  

981@cython.embedsignature(True) 

982def nvrtcGetPCHHeapSize(): 

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

984  

985 Returns 

986 ------- 

987 nvrtcResult 

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

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

990 ret : int 

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

992 """ 

993 cdef size_t ret = 0 

994 with nogil: 

995 err = cynvrtc.nvrtcGetPCHHeapSize(&ret) 

996 if err != cynvrtc.NVRTC_SUCCESS: 

997 return (_nvrtcResult(err), None) 

998 return (_nvrtcResult_SUCCESS, ret) 

999  

1000@cython.embedsignature(True) 

1001def nvrtcSetPCHHeapSize(size_t size): 

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

1003  

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

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

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

1007  

1008 Parameters 

1009 ---------- 

1010 size : size_t 

1011 requested size of the PCH Heap, in bytes 

1012  

1013 Returns 

1014 ------- 

1015 nvrtcResult 

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

1017 """ 

1018 with nogil: 

1019 err = cynvrtc.nvrtcSetPCHHeapSize(size) 

1020 return (_nvrtcResult(err),) 

1021  

1022@cython.embedsignature(True) 

1023def nvrtcGetPCHCreateStatus(prog): 

1024 """ returns the PCH creation status. 

1025  

1026 NVRTC_SUCCESS indicates that the PCH was successfully created. 

1027 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED indicates that no PCH creation was 

1028 attempted, either because PCH functionality was not requested during 

1029 the preceding nvrtcCompileProgram call, or automatic PCH processing was 

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

1031 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED indicates that a PCH file could 

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

1033 PCH heap. In this scenario, the 

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

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

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

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

1038 program instance. NVRTC_ERROR_PCH_CREATE indicates that an error 

1039 condition prevented the PCH file from being created. 

1040  

1041 Parameters 

1042 ---------- 

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

1044 CUDA Runtime Compilation program. 

1045  

1046 Returns 

1047 ------- 

1048 nvrtcResult 

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

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

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

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

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

1054 """ 

1055 cdef cynvrtc.nvrtcProgram cyprog 

1056 if prog is None: 

1057 pprog = 0 

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

1059 pprog = int(prog) 

1060 else: 

1061 pprog = int(nvrtcProgram(prog)) 

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

1063 with nogil: 

1064 err = cynvrtc.nvrtcGetPCHCreateStatus(cyprog) 

1065 return (_nvrtcResult(err),) 

1066  

1067@cython.embedsignature(True) 

1068def nvrtcGetPCHHeapSizeRequired(prog): 

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

1070  

1071 Parameters 

1072 ---------- 

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

1074 CUDA Runtime Compilation program. 

1075  

1076 Returns 

1077 ------- 

1078 nvrtcResult 

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

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

1081 - :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 

1082 size : int 

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

1084 stored 

1085 """ 

1086 cdef cynvrtc.nvrtcProgram cyprog 

1087 if prog is None: 

1088 pprog = 0 

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

1090 pprog = int(prog) 

1091 else: 

1092 pprog = int(nvrtcProgram(prog)) 

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

1094 cdef size_t size = 0 

1095 with nogil: 

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

1097 if err != cynvrtc.NVRTC_SUCCESS: 

1098 return (_nvrtcResult(err), None) 

1099 return (_nvrtcResult_SUCCESS, size) 

1100  

1101@cython.embedsignature(True) 

1102def nvrtcSetFlowCallback(prog, callback, payload): 

1103 """ 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. 

1104  

1105 The callback function must satisfy the following constraints: 

1106  

1107 (1) Its signature should be: 

1108  

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

1110  

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

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

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

1114 extensions. 

1115  

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

1117 return values are reserved for future use. 

1118  

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

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

1121 nvrtcCompileProgram call in progress. 

1122  

1123 (4) It must be thread-safe. 

1124  

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

1126  

1127 Parameters 

1128 ---------- 

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

1130 CUDA Runtime Compilation program. 

1131 callback : Any 

1132 the callback that issues cancellation signal. 

1133 payload : Any 

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

1135  

1136 Returns 

1137 ------- 

1138 nvrtcResult 

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

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

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

1142 """ 

1143 cdef cynvrtc.nvrtcProgram cyprog 

1144 if prog is None: 

1145 pprog = 0 

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

1147 pprog = int(prog) 

1148 else: 

1149 pprog = int(nvrtcProgram(prog)) 

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

1151 cdef _HelperInputVoidPtrStruct cycallbackHelper 

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

1153 cdef _HelperInputVoidPtrStruct cypayloadHelper 

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

1155 with nogil: 

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

1157 _helper_input_void_ptr_free(&cycallbackHelper) 

1158 _helper_input_void_ptr_free(&cypayloadHelper) 

1159 return (_nvrtcResult(err),) 

1160  

1161@cython.embedsignature(True) 

1162def nvrtcGetTileIRSize(prog): 

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

1164  

1165 Parameters 

1166 ---------- 

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

1168 CUDA Runtime Compilation program. 

1169  

1170 Returns 

1171 ------- 

1172 nvrtcResult 

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

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

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

1176 TileIRSizeRet : int 

1177 Size of the generated cuda_tile IR. 

1178  

1179 See Also 

1180 -------- 

1181 :py:obj:`~.nvrtcGetTileIR` 

1182 """ 

1183 cdef cynvrtc.nvrtcProgram cyprog 

1184 if prog is None: 

1185 pprog = 0 

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

1187 pprog = int(prog) 

1188 else: 

1189 pprog = int(nvrtcProgram(prog)) 

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

1191 cdef size_t TileIRSizeRet = 0 

1192 with nogil: 

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

1194 if err != cynvrtc.NVRTC_SUCCESS: 

1195 return (_nvrtcResult(err), None) 

1196 return (_nvrtcResult_SUCCESS, TileIRSizeRet) 

1197  

1198@cython.embedsignature(True) 

1199def nvrtcGetTileIR(prog, char* TileIR): 

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

1201  

1202 Parameters 

1203 ---------- 

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

1205 CUDA Runtime Compilation program. 

1206 TileIR : bytes 

1207 Generated cuda_tile IR. 

1208  

1209 Returns 

1210 ------- 

1211 nvrtcResult 

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

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

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

1215  

1216 See Also 

1217 -------- 

1218 :py:obj:`~.nvrtcGetTileIRSize` 

1219 """ 

1220 cdef cynvrtc.nvrtcProgram cyprog 

1221 if prog is None: 

1222 pprog = 0 

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

1224 pprog = int(prog) 

1225 else: 

1226 pprog = int(nvrtcProgram(prog)) 

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

1228 with nogil: 

1229 err = cynvrtc.nvrtcGetTileIR(cyprog, TileIR) 

1230 return (_nvrtcResult(err),) 

1231  

1232@cython.embedsignature(True) 

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

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

1235  

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

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

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

1239 requiring a separate CUDA Toolkit installation. The bundled headers 

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

1241  

1242 After extraction, users can compile kernels by passing appropriate 

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

1244 nvrtcCompileProgram. 

1245  

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

1247 installation directory to track the installed version. 

1248  

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

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

1251 default, the function waits for the lock; use 

1252 NVRTC_INSTALL_HEADERS_NO_WAIT to return immediately with 

1253 NVRTC_ERROR_BUSY if another process holds the lock. 

1254  

1255 Parameters 

1256 ---------- 

1257 installPath : bytes 

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

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

1260 flags : unsigned int 

1261 NVRTC_INSTALL_HEADERS_* flags: 

1262  

1263 Returns 

1264 ------- 

1265 nvrtcResult 

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

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

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

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

1270 errorLog : bytes 

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

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

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

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

1275 needed. 

1276  

1277 See Also 

1278 -------- 

1279 :py:obj:`~.nvrtcCompileProgram` 

1280  

1281 Notes 

1282 ----- 

1283 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. 

1284 """ 

1285 cdef const char* errorLog = NULL 

1286 with nogil: 

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

1288 if err != cynvrtc.NVRTC_SUCCESS: 

1289 return (_nvrtcResult(err), None) 

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

1291  

1292@cython.embedsignature(True) 

1293def nvrtcGetBundledHeadersInfo(): 

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

1295  

1296 This function allows users to determine if bundled headers are 

1297 available and get size estimates before calling 

1298 nvrtcInstallBundledHeaders. 

1299  

1300 Returns 

1301 ------- 

1302 nvrtcResult 

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

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

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

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

1307 Pointer to structure to receive header information. 

1308 errorLog : bytes 

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

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

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

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

1313 needed. 

1314 """ 

1315 cdef nvrtcBundledHeadersInfo info = nvrtcBundledHeadersInfo() 

1316 cdef const char* errorLog = NULL 

1317 with nogil: 

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

1319 if err != cynvrtc.NVRTC_SUCCESS: 

1320 return (_nvrtcResult(err), None, None) 

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

1322  

1323@cython.embedsignature(True) 

1324def nvrtcRemoveBundledHeaders(char* installPath): 

1325 """ nvrtcRemoveBundledHeaders removes previously installed bundled headers. 

1326  

1327 This function removes the headers installed by 

1328 nvrtcInstallBundledHeaders, helping users manage disk space. It 

1329 recursively removes all files and subdirectories within the 

1330 installation directory. 

1331  

1332 Parameters 

1333 ---------- 

1334 installPath : bytes 

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

1336 used with nvrtcInstallBundledHeaders. 

1337  

1338 Returns 

1339 ------- 

1340 nvrtcResult 

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

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

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

1344 errorLog : bytes 

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

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

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

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

1349 needed. 

1350  

1351 Notes 

1352 ----- 

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

1354 """ 

1355 cdef const char* errorLog = NULL 

1356 with nogil: 

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

1358 if err != cynvrtc.NVRTC_SUCCESS: 

1359 return (_nvrtcResult(err), None) 

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

1361  

1362@cython.embedsignature(True) 

1363def sizeof(objType): 

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

1365  

1366 Parameters 

1367 ---------- 

1368 objType : Any 

1369 CUDA Python object 

1370  

1371 Returns 

1372 ------- 

1373 lowered_name : int 

1374 The size of `objType` in bytes 

1375 """ 

1376  

1377 if objType == nvrtcProgram: 

1378 return sizeof(cynvrtc.nvrtcProgram) 

1379  

1380 if objType == nvrtcBundledHeadersInfo: 

1381 return sizeof(cynvrtc.nvrtcBundledHeadersInfo) 

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