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

403 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-03 02:41 +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=5d36f91a9f04660caaf0a8a7afa443d43899bc6eb70e61a26415485d9a39475a 

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. 

48#: 

49#: Skip installation if version marker exists and version matches. This is 

50#: the default behavior when flags=0. 

51NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS = cynvrtc.NVRTC_INSTALL_HEADERS_SKIP_IF_EXISTS 

52  

53#: Clear existing directory contents before installation. Guarantees 

54#: consistency by removing any existing files first. 

55NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE = cynvrtc.NVRTC_INSTALL_HEADERS_FORCE_OVERWRITE 

56  

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

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

59#: FORCE_OVERWRITE using bitwise OR. 

60NVRTC_INSTALL_HEADERS_NO_WAIT = cynvrtc.NVRTC_INSTALL_HEADERS_NO_WAIT 

61  

62class nvrtcResult(_FastEnum): 

63 """ 

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

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

66 indicate the call result. 

67 """ 

68  

69 NVRTC_SUCCESS = cynvrtc.nvrtcResult.NVRTC_SUCCESS 

70  

71 NVRTC_ERROR_OUT_OF_MEMORY = cynvrtc.nvrtcResult.NVRTC_ERROR_OUT_OF_MEMORY 

72  

73 NVRTC_ERROR_PROGRAM_CREATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_PROGRAM_CREATION_FAILURE 

74  

75 NVRTC_ERROR_INVALID_INPUT = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_INPUT 

76  

77 NVRTC_ERROR_INVALID_PROGRAM = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_PROGRAM 

78  

79 NVRTC_ERROR_INVALID_OPTION = cynvrtc.nvrtcResult.NVRTC_ERROR_INVALID_OPTION 

80  

81 NVRTC_ERROR_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_COMPILATION 

82  

83 NVRTC_ERROR_BUILTIN_OPERATION_FAILURE = cynvrtc.nvrtcResult.NVRTC_ERROR_BUILTIN_OPERATION_FAILURE 

84  

85 NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 

86  

87 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

88  

89 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID = cynvrtc.nvrtcResult.NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

90  

91 NVRTC_ERROR_INTERNAL_ERROR = cynvrtc.nvrtcResult.NVRTC_ERROR_INTERNAL_ERROR 

92  

93 NVRTC_ERROR_TIME_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_FILE_WRITE_FAILED 

94  

95 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED = cynvrtc.nvrtcResult.NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED 

96  

97 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED 

98  

99 NVRTC_ERROR_PCH_CREATE = cynvrtc.nvrtcResult.NVRTC_ERROR_PCH_CREATE 

100  

101 NVRTC_ERROR_CANCELLED = cynvrtc.nvrtcResult.NVRTC_ERROR_CANCELLED 

102  

103 NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED = cynvrtc.nvrtcResult.NVRTC_ERROR_TIME_TRACE_FILE_WRITE_FAILED 

104  

105 NVRTC_ERROR_BUSY = cynvrtc.nvrtcResult.NVRTC_ERROR_BUSY 

106  

107cdef object _nvrtcResult = nvrtcResult 

108cdef object _nvrtcResult_SUCCESS = nvrtcResult.NVRTC_SUCCESS 

109  

110cdef class nvrtcProgram: 

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

112  

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

114  

115 Methods 

116 ------- 

117 getPtr() 

118 Get memory address of class instance 

119  

120 """ 

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

122 if _ptr == 0: 2b 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 j `b{b|b

123 self._pvt_ptr = &self._pvt_val 2b 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 j `b{b|b

124 self._pvt_ptr[0] = <cynvrtc.nvrtcProgram>init_value 2b 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 j `b{b|b

125 else: 

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

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

128 pass 2b 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 j `b{b|b

129 def __repr__(self): 

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

131 def __index__(self): 

132 return self.__int__() 

133 def __eq__(self, other): 

134 if not isinstance(other, nvrtcProgram): 

135 return False 

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

137 def __hash__(self): 

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

139 def __int__(self): 

140 return <void_ptr>self._pvt_ptr[0] 1bcdefghiklmnopqrstuvwxyzABCj

141 def getPtr(self): 

142 return <void_ptr>self._pvt_ptr 1klmnopqrstuvwxyzABj

143  

144cdef class anon_struct0: 

145 """ 

146 Attributes 

147 ---------- 

148  

149 available : int 

150  

151  

152  

153 compressedSize : size_t 

154  

155  

156  

157 uncompressedSize : size_t 

158  

159  

160  

161 cudaVersionMajor : int 

162  

163  

164  

165 cudaVersionMinor : int 

166  

167  

168  

169 numFiles : unsigned int 

170  

171  

172  

173 Methods 

174 ------- 

175 getPtr() 

176 Get memory address of class instance 

177 """ 

178 def __cinit__(self, void_ptr _ptr): 

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

180  

181 def __init__(self, void_ptr _ptr): 

182 pass 

183 def __dealloc__(self): 

184 pass 

185 def getPtr(self): 

186 return <void_ptr>self._pvt_ptr 

187 def __repr__(self): 

188 if self._pvt_ptr is not NULL: 

189 str_list = [] 

190  

191 try: 

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

193 except ValueError: 

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

195  

196  

197 try: 

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

199 except ValueError: 

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

201  

202  

203 try: 

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

205 except ValueError: 

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

207  

208  

209 try: 

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

211 except ValueError: 

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

213  

214  

215 try: 

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

217 except ValueError: 

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

219  

220  

221 try: 

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

223 except ValueError: 

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

225  

226 return '\n'.join(str_list) 

227 else: 

228 return '' 

229  

230 @property 

231 def available(self): 

232 return self._pvt_ptr[0].available 

233 @available.setter 

234 def available(self, int available): 

235 self._pvt_ptr[0].available = available 

236  

237  

238 @property 

239 def compressedSize(self): 

240 return self._pvt_ptr[0].compressedSize 

241 @compressedSize.setter 

242 def compressedSize(self, size_t compressedSize): 

243 self._pvt_ptr[0].compressedSize = compressedSize 

244  

245  

246 @property 

247 def uncompressedSize(self): 

248 return self._pvt_ptr[0].uncompressedSize 

249 @uncompressedSize.setter 

250 def uncompressedSize(self, size_t uncompressedSize): 

251 self._pvt_ptr[0].uncompressedSize = uncompressedSize 

252  

253  

254 @property 

255 def cudaVersionMajor(self): 

256 return self._pvt_ptr[0].cudaVersionMajor 

257 @cudaVersionMajor.setter 

258 def cudaVersionMajor(self, int cudaVersionMajor): 

259 self._pvt_ptr[0].cudaVersionMajor = cudaVersionMajor 

260  

261  

262 @property 

263 def cudaVersionMinor(self): 

264 return self._pvt_ptr[0].cudaVersionMinor 

265 @cudaVersionMinor.setter 

266 def cudaVersionMinor(self, int cudaVersionMinor): 

267 self._pvt_ptr[0].cudaVersionMinor = cudaVersionMinor 

268  

269  

270 @property 

271 def numFiles(self): 

272 return self._pvt_ptr[0].numFiles 

273 @numFiles.setter 

274 def numFiles(self, unsigned int numFiles): 

275 self._pvt_ptr[0].numFiles = numFiles 

276  

277  

278cdef class nvrtcBundledHeadersInfo(anon_struct0): 

279 """ 

280 Attributes 

281 ---------- 

282  

283 available : int 

284  

285  

286  

287 compressedSize : size_t 

288  

289  

290  

291 uncompressedSize : size_t 

292  

293  

294  

295 cudaVersionMajor : int 

296  

297  

298  

299 cudaVersionMinor : int 

300  

301  

302  

303 numFiles : unsigned int 

304  

305  

306  

307 Methods 

308 ------- 

309 getPtr() 

310 Get memory address of class instance 

311 """ 

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

313 if _ptr == 0: 

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

315 else: 

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

317  

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

319 pass 

320  

321@cython.embedsignature(True) 

322def nvrtcGetErrorString(result not None : nvrtcResult): 

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

324  

325 Parameters 

326 ---------- 

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

328 CUDA Runtime Compilation API result code. 

329  

330 Returns 

331 ------- 

332 nvrtcResult.NVRTC_SUCCESS 

333 nvrtcResult.NVRTC_SUCCESS 

334 bytes 

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

336 """ 

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

338 with nogil: 2j }b

339 err = cynvrtc.nvrtcGetErrorString(cyresult) 2j }b

340 return (nvrtcResult.NVRTC_SUCCESS, err) 2j }b

341  

342@cython.embedsignature(True) 

343def nvrtcVersion(): 

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

345  

346 Returns 

347 ------- 

348 nvrtcResult 

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

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

351 major : int 

352 CUDA Runtime Compilation major version number. 

353 minor : int 

354 CUDA Runtime Compilation minor version number. 

355 """ 

356 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:b;b=b?b@b[b]b^b_b

357 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:b;b=b?b@b[b]b^b_b

358 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:b;b=b?b@b[b]b^b_b

359 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:b;b=b?b@b[b]b^b_b

360 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:b;b=b?b@b[b]b^b_b

361 return (_nvrtcResult(err), None, None) 

362 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:b;b=b?b@b[b]b^b_b

363  

364@cython.embedsignature(True) 

365def nvrtcGetNumSupportedArchs(): 

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

367  

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

369  

370 Returns 

371 ------- 

372 nvrtcResult 

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

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

375 numArchs : int 

376 number of supported architectures. 

377 """ 

378 cdef int numArchs = 0 1D

379 with nogil: 1D

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

381 if err != cynvrtc.NVRTC_SUCCESS: 1D

382 return (_nvrtcResult(err), None) 

383 return (_nvrtcResult_SUCCESS, numArchs) 1D

384  

385@cython.embedsignature(True) 

386def nvrtcGetSupportedArchs(): 

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

388  

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

390  

391 Returns 

392 ------- 

393 nvrtcResult 

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

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

396 supportedArchs : list[int] 

397 sorted array of supported architectures. 

398 """ 

399 cdef vector[int] supportedArchs 

400 _, s = nvrtcGetNumSupportedArchs() 1D

401 supportedArchs.resize(s) 1D

402  

403 with nogil: 1D

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

405 if err != cynvrtc.NVRTC_SUCCESS: 1D

406 return (_nvrtcResult(err), None) 

407 return (_nvrtcResult_SUCCESS, supportedArchs) 1D

408  

409@cython.embedsignature(True) 

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

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

412  

413 Parameters 

414 ---------- 

415 src : bytes 

416 CUDA program source. 

417 name : bytes 

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

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

420 numHeaders : int 

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

422 to 0. 

423 headers : list[bytes] 

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

425 is 0. 

426 includeNames : list[bytes] 

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

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

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

430 here. 

431  

432 Returns 

433 ------- 

434 nvrtcResult 

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

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

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

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

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

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

441 CUDA Runtime Compilation program. 

442  

443 See Also 

444 -------- 

445 :py:obj:`~.nvrtcDestroyProgram` 

446 """ 

447 includeNames = [] if includeNames is None else includeNames 1bcdefghiklmnopqrstuvwxyzABj

448 if not all(isinstance(_x, (bytes)) for _x in includeNames): 1bcdefghiklmnopqrstuvwxyzABj

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

450 headers = [] if headers is None else headers 1bcdefghiklmnopqrstuvwxyzABj

451 if not all(isinstance(_x, (bytes)) for _x in headers): 1bcdefghiklmnopqrstuvwxyzABj

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

453 cdef nvrtcProgram prog = nvrtcProgram() 1bcdefghiklmnopqrstuvwxyzABj

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

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

456 cdef vector[const char*] cyheaders = headers 1bcdefghiklmnopqrstuvwxyzABj

457 cdef vector[const char*] cyincludeNames = includeNames 1bcdefghiklmnopqrstuvwxyzABj

458 with nogil: 1bcdefghiklmnopqrstuvwxyzABj

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

460 if err != cynvrtc.NVRTC_SUCCESS: 1bcdefghiklmnopqrstuvwxyzABj

461 return (_nvrtcResult(err), None) 

462 return (_nvrtcResult_SUCCESS, prog) 1bcdefghiklmnopqrstuvwxyzABj

463  

464@cython.embedsignature(True) 

465def nvrtcDestroyProgram(prog): 

466 """ nvrtcDestroyProgram destroys the given program. 

467  

468 Parameters 

469 ---------- 

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

471 CUDA Runtime Compilation program. 

472  

473 Returns 

474 ------- 

475 nvrtcResult 

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

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

478  

479 See Also 

480 -------- 

481 :py:obj:`~.nvrtcCreateProgram` 

482 """ 

483 cdef cynvrtc.nvrtcProgram *cyprog 

484 if prog is None: 1klmnopqrstuvwxyzABj

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

486 elif isinstance(prog, (nvrtcProgram,)): 1klmnopqrstuvwxyzABj

487 pprog = prog.getPtr() 1klmnopqrstuvwxyzABj

488 cyprog = <cynvrtc.nvrtcProgram*><void_ptr>pprog 1klmnopqrstuvwxyzABj

489 elif isinstance(prog, (int)): 

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

491 else: 

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

493 with nogil: 1klmnopqrstuvwxyzABj

494 err = cynvrtc.nvrtcDestroyProgram(cyprog) 1klmnopqrstuvwxyzABj

495 return (_nvrtcResult(err),) 1klmnopqrstuvwxyzABj

496  

497@cython.embedsignature(True) 

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

499 """ nvrtcCompileProgram compiles the given program. 

500  

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

502 Options`. 

503  

504 Parameters 

505 ---------- 

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

507 CUDA Runtime Compilation program. 

508 numOptions : int 

509 Number of compiler options passed. 

510 options : list[bytes] 

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

512 `NULL` when `numOptions` is 0. 

513  

514 Returns 

515 ------- 

516 nvrtcResult 

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

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

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

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

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

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

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

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

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

526 """ 

527 options = [] if options is None else options 1bcdefghiklmnopqrstuvwxyzABj

528 if not all(isinstance(_x, (bytes)) for _x in options): 1bcdefghiklmnopqrstuvwxyzABj

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

530 cdef cynvrtc.nvrtcProgram cyprog 

531 if prog is None: 1bcdefghiklmnopqrstuvwxyzABj

532 pprog = 0 

533 elif isinstance(prog, (nvrtcProgram,)): 1bcdefghiklmnopqrstuvwxyzABj

534 pprog = int(prog) 1bcdefghiklmnopqrstuvwxyzABj

535 else: 

536 pprog = int(nvrtcProgram(prog)) 

537 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1bcdefghiklmnopqrstuvwxyzABj

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

539 cdef vector[const char*] cyoptions = options 1bcdefghiklmnopqrstuvwxyzABj

540 with nogil: 1bcdefghiklmnopqrstuvwxyzABj

541 err = cynvrtc.nvrtcCompileProgram(cyprog, numOptions, cyoptions.data()) 1bcdefghiklmnopqrstuvwxyzABj

542 return (_nvrtcResult(err),) 1bcdefghiklmnopqrstuvwxyzABj

543  

544@cython.embedsignature(True) 

545def nvrtcGetPTXSize(prog): 

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

547  

548 Parameters 

549 ---------- 

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

551 CUDA Runtime Compilation program. 

552  

553 Returns 

554 ------- 

555 nvrtcResult 

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

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

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

559 ptxSizeRet : int 

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

561  

562 See Also 

563 -------- 

564 :py:obj:`~.nvrtcGetPTX` 

565 """ 

566 cdef cynvrtc.nvrtcProgram cyprog 

567 if prog is None: 

568 pprog = 0 

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

570 pprog = int(prog) 

571 else: 

572 pprog = int(nvrtcProgram(prog)) 

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

574 cdef size_t ptxSizeRet = 0 

575 with nogil: 

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

577 if err != cynvrtc.NVRTC_SUCCESS: 

578 return (_nvrtcResult(err), None) 

579 return (_nvrtcResult_SUCCESS, ptxSizeRet) 

580  

581@cython.embedsignature(True) 

582def nvrtcGetPTX(prog, char* ptx): 

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

584  

585 Parameters 

586 ---------- 

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

588 CUDA Runtime Compilation program. 

589 ptx : bytes 

590 Compiled result. 

591  

592 Returns 

593 ------- 

594 nvrtcResult 

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

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

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

598  

599 See Also 

600 -------- 

601 :py:obj:`~.nvrtcGetPTXSize` 

602 """ 

603 cdef cynvrtc.nvrtcProgram cyprog 

604 if prog is None: 

605 pprog = 0 

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

607 pprog = int(prog) 

608 else: 

609 pprog = int(nvrtcProgram(prog)) 

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

611 with nogil: 

612 err = cynvrtc.nvrtcGetPTX(cyprog, ptx) 

613 return (_nvrtcResult(err),) 

614  

615@cython.embedsignature(True) 

616def nvrtcGetCUBINSize(prog): 

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

618  

619 Parameters 

620 ---------- 

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

622 CUDA Runtime Compilation program. 

623  

624 Returns 

625 ------- 

626 nvrtcResult 

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

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

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

630 cubinSizeRet : int 

631 Size of the generated cubin. 

632  

633 See Also 

634 -------- 

635 :py:obj:`~.nvrtcGetCUBIN` 

636 """ 

637 cdef cynvrtc.nvrtcProgram cyprog 

638 if prog is None: 1bcdefghiopqrst

639 pprog = 0 

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

641 pprog = int(prog) 1bcdefghiopqrst

642 else: 

643 pprog = int(nvrtcProgram(prog)) 

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

645 cdef size_t cubinSizeRet = 0 1bcdefghiopqrst

646 with nogil: 1bcdefghiopqrst

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

648 if err != cynvrtc.NVRTC_SUCCESS: 1bcdefghiopqrst

649 return (_nvrtcResult(err), None) 

650 return (_nvrtcResult_SUCCESS, cubinSizeRet) 1bcdefghiopqrst

651  

652@cython.embedsignature(True) 

653def nvrtcGetCUBIN(prog, char* cubin): 

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

655  

656 Parameters 

657 ---------- 

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

659 CUDA Runtime Compilation program. 

660 cubin : bytes 

661 Compiled and assembled result. 

662  

663 Returns 

664 ------- 

665 nvrtcResult 

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

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

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

669  

670 See Also 

671 -------- 

672 :py:obj:`~.nvrtcGetCUBINSize` 

673 """ 

674 cdef cynvrtc.nvrtcProgram cyprog 

675 if prog is None: 1bcdefghiopqrst

676 pprog = 0 

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

678 pprog = int(prog) 1bcdefghiopqrst

679 else: 

680 pprog = int(nvrtcProgram(prog)) 

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

682 with nogil: 1bcdefghiopqrst

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

684 return (_nvrtcResult(err),) 1bcdefghiopqrst

685  

686@cython.embedsignature(True) 

687def nvrtcGetLTOIRSize(prog): 

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

689  

690 Parameters 

691 ---------- 

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

693 CUDA Runtime Compilation program. 

694  

695 Returns 

696 ------- 

697 nvrtcResult 

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

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

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

701 LTOIRSizeRet : int 

702 Size of the generated LTO IR. 

703  

704 See Also 

705 -------- 

706 :py:obj:`~.nvrtcGetLTOIR` 

707 """ 

708 cdef cynvrtc.nvrtcProgram cyprog 

709 if prog is None: 1klmnuvwxyzAB

710 pprog = 0 

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

712 pprog = int(prog) 1klmnuvwxyzAB

713 else: 

714 pprog = int(nvrtcProgram(prog)) 

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

716 cdef size_t LTOIRSizeRet = 0 1klmnuvwxyzAB

717 with nogil: 1klmnuvwxyzAB

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

719 if err != cynvrtc.NVRTC_SUCCESS: 1klmnuvwxyzAB

720 return (_nvrtcResult(err), None) 

721 return (_nvrtcResult_SUCCESS, LTOIRSizeRet) 1klmnuvwxyzAB

722  

723@cython.embedsignature(True) 

724def nvrtcGetLTOIR(prog, char* LTOIR): 

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

726  

727 Parameters 

728 ---------- 

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

730 CUDA Runtime Compilation program. 

731 LTOIR : bytes 

732 Compiled result. 

733  

734 Returns 

735 ------- 

736 nvrtcResult 

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

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

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

740  

741 See Also 

742 -------- 

743 :py:obj:`~.nvrtcGetLTOIRSize` 

744 """ 

745 cdef cynvrtc.nvrtcProgram cyprog 

746 if prog is None: 1klmnuvwxyzAB

747 pprog = 0 

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

749 pprog = int(prog) 1klmnuvwxyzAB

750 else: 

751 pprog = int(nvrtcProgram(prog)) 

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

753 with nogil: 1klmnuvwxyzAB

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

755 return (_nvrtcResult(err),) 1klmnuvwxyzAB

756  

757@cython.embedsignature(True) 

758def nvrtcGetOptiXIRSize(prog): 

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

760  

761 Parameters 

762 ---------- 

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

764 CUDA Runtime Compilation program. 

765  

766 Returns 

767 ------- 

768 nvrtcResult 

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

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

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

772 optixirSizeRet : int 

773 Size of the generated LTO IR. 

774  

775 See Also 

776 -------- 

777 :py:obj:`~.nvrtcGetOptiXIR` 

778 """ 

779 cdef cynvrtc.nvrtcProgram cyprog 

780 if prog is None: 

781 pprog = 0 

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

783 pprog = int(prog) 

784 else: 

785 pprog = int(nvrtcProgram(prog)) 

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

787 cdef size_t optixirSizeRet = 0 

788 with nogil: 

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

790 if err != cynvrtc.NVRTC_SUCCESS: 

791 return (_nvrtcResult(err), None) 

792 return (_nvrtcResult_SUCCESS, optixirSizeRet) 

793  

794@cython.embedsignature(True) 

795def nvrtcGetOptiXIR(prog, char* optixir): 

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

797  

798 Parameters 

799 ---------- 

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

801 CUDA Runtime Compilation program. 

802 optixir : bytes 

803 Optix IR Compiled result. 

804  

805 Returns 

806 ------- 

807 nvrtcResult 

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

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

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

811  

812 See Also 

813 -------- 

814 :py:obj:`~.nvrtcGetOptiXIRSize` 

815 """ 

816 cdef cynvrtc.nvrtcProgram cyprog 

817 if prog is None: 

818 pprog = 0 

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

820 pprog = int(prog) 

821 else: 

822 pprog = int(nvrtcProgram(prog)) 

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

824 with nogil: 

825 err = cynvrtc.nvrtcGetOptiXIR(cyprog, optixir) 

826 return (_nvrtcResult(err),) 

827  

828@cython.embedsignature(True) 

829def nvrtcGetProgramLogSize(prog): 

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

831  

832 Note that compilation log may be generated with warnings and 

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

834  

835 Parameters 

836 ---------- 

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

838 CUDA Runtime Compilation program. 

839  

840 Returns 

841 ------- 

842 nvrtcResult 

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

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

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

846 logSizeRet : int 

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

848  

849 See Also 

850 -------- 

851 :py:obj:`~.nvrtcGetProgramLog` 

852 """ 

853 cdef cynvrtc.nvrtcProgram cyprog 

854 if prog is None: 1bcdefghij

855 pprog = 0 

856 elif isinstance(prog, (nvrtcProgram,)): 1bcdefghij

857 pprog = int(prog) 1bcdefghij

858 else: 

859 pprog = int(nvrtcProgram(prog)) 

860 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1bcdefghij

861 cdef size_t logSizeRet = 0 1bcdefghij

862 with nogil: 1bcdefghij

863 err = cynvrtc.nvrtcGetProgramLogSize(cyprog, &logSizeRet) 1bcdefghij

864 if err != cynvrtc.NVRTC_SUCCESS: 1bcdefghij

865 return (_nvrtcResult(err), None) 

866 return (_nvrtcResult_SUCCESS, logSizeRet) 1bcdefghij

867  

868@cython.embedsignature(True) 

869def nvrtcGetProgramLog(prog, char* log): 

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

871  

872 Parameters 

873 ---------- 

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

875 CUDA Runtime Compilation program. 

876 log : bytes 

877 Compilation log. 

878  

879 Returns 

880 ------- 

881 nvrtcResult 

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

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

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

885  

886 See Also 

887 -------- 

888 :py:obj:`~.nvrtcGetProgramLogSize` 

889 """ 

890 cdef cynvrtc.nvrtcProgram cyprog 

891 if prog is None: 1bcdefghij

892 pprog = 0 

893 elif isinstance(prog, (nvrtcProgram,)): 1bcdefghij

894 pprog = int(prog) 1bcdefghij

895 else: 

896 pprog = int(nvrtcProgram(prog)) 

897 cyprog = <cynvrtc.nvrtcProgram><void_ptr>pprog 1bcdefghij

898 with nogil: 1bcdefghij

899 err = cynvrtc.nvrtcGetProgramLog(cyprog, log) 1bcdefghij

900 return (_nvrtcResult(err),) 1bcdefghij

901  

902@cython.embedsignature(True) 

903def nvrtcAddNameExpression(prog, char* name_expression): 

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

905  

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

907 call to nvrtcGetLoweredName to extract the lowered name. 

908  

909 Parameters 

910 ---------- 

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

912 CUDA Runtime Compilation program. 

913 name_expression : bytes 

914 constant expression denoting the address of a global function or 

915 device/__constant__ variable. 

916  

917 Returns 

918 ------- 

919 nvrtcResult 

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

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

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

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

924  

925 See Also 

926 -------- 

927 :py:obj:`~.nvrtcGetLoweredName` 

928 """ 

929 cdef cynvrtc.nvrtcProgram cyprog 

930 if prog is None: 

931 pprog = 0 

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

933 pprog = int(prog) 

934 else: 

935 pprog = int(nvrtcProgram(prog)) 

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

937 with nogil: 

938 err = cynvrtc.nvrtcAddNameExpression(cyprog, name_expression) 

939 return (_nvrtcResult(err),) 

940  

941@cython.embedsignature(True) 

942def nvrtcGetLoweredName(prog, char* name_expression): 

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

944  

945 Parameters 

946 ---------- 

947 prog : nvrtcProgram 

948 CUDA Runtime Compilation program. 

949 name_expression : bytes 

950 constant expression denoting the address of a global function or 

951 device/__constant__ variable. 

952  

953 Returns 

954 ------- 

955 nvrtcResult 

956 NVRTC_SUCCESS 

957 NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 

958 NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 

959 lowered_name : bytes 

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

961 lowered (mangled) name corresponding to the provided name 

962 expression. 

963  

964 See Also 

965 -------- 

966 nvrtcAddNameExpression 

967 """ 

968 cdef cynvrtc.nvrtcProgram cyprog 

969 if prog is None: 1C

970 pprog = 0 1C

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

972 pprog = int(prog) 

973 else: 

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

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

976 cdef const char* lowered_name = NULL 1C

977 with nogil: 1C

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

979 if err != cynvrtc.NVRTC_SUCCESS: 1C

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

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

982  

983@cython.embedsignature(True) 

984def nvrtcGetPCHHeapSize(): 

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

986  

987 Returns 

988 ------- 

989 nvrtcResult 

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

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

992 ret : int 

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

994 """ 

995 cdef size_t ret = 0 

996 with nogil: 

997 err = cynvrtc.nvrtcGetPCHHeapSize(&ret) 

998 if err != cynvrtc.NVRTC_SUCCESS: 

999 return (_nvrtcResult(err), None) 

1000 return (_nvrtcResult_SUCCESS, ret) 

1001  

1002@cython.embedsignature(True) 

1003def nvrtcSetPCHHeapSize(size_t size): 

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

1005  

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

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

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

1009  

1010 Parameters 

1011 ---------- 

1012 size : size_t 

1013 requested size of the PCH Heap, in bytes 

1014  

1015 Returns 

1016 ------- 

1017 nvrtcResult 

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

1019 """ 

1020 with nogil: 

1021 err = cynvrtc.nvrtcSetPCHHeapSize(size) 

1022 return (_nvrtcResult(err),) 

1023  

1024@cython.embedsignature(True) 

1025def nvrtcGetPCHCreateStatus(prog): 

1026 """ returns the PCH creation status. 

1027  

1028 NVRTC_SUCCESS indicates that the PCH was successfully created. 

1029 NVRTC_ERROR_NO_PCH_CREATE_ATTEMPTED indicates that no PCH creation was 

1030 attempted, either because PCH functionality was not requested during 

1031 the preceding nvrtcCompileProgram call, or automatic PCH processing was 

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

1033 NVRTC_ERROR_PCH_CREATE_HEAP_EXHAUSTED indicates that a PCH file could 

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

1035 PCH heap. In this scenario, the 

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

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

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

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

1040 program instance. NVRTC_ERROR_PCH_CREATE indicates that an error 

1041 condition prevented the PCH file from being created. 

1042  

1043 Parameters 

1044 ---------- 

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

1046 CUDA Runtime Compilation program. 

1047  

1048 Returns 

1049 ------- 

1050 nvrtcResult 

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

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

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

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

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

1056 """ 

1057 cdef cynvrtc.nvrtcProgram cyprog 

1058 if prog is None: 

1059 pprog = 0 

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

1061 pprog = int(prog) 

1062 else: 

1063 pprog = int(nvrtcProgram(prog)) 

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

1065 with nogil: 

1066 err = cynvrtc.nvrtcGetPCHCreateStatus(cyprog) 

1067 return (_nvrtcResult(err),) 

1068  

1069@cython.embedsignature(True) 

1070def nvrtcGetPCHHeapSizeRequired(prog): 

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

1072  

1073 Parameters 

1074 ---------- 

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

1076 CUDA Runtime Compilation program. 

1077  

1078 Returns 

1079 ------- 

1080 nvrtcResult 

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

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

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

1084 size : int 

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

1086 stored 

1087 """ 

1088 cdef cynvrtc.nvrtcProgram cyprog 

1089 if prog is None: 

1090 pprog = 0 

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

1092 pprog = int(prog) 

1093 else: 

1094 pprog = int(nvrtcProgram(prog)) 

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

1096 cdef size_t size = 0 

1097 with nogil: 

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

1099 if err != cynvrtc.NVRTC_SUCCESS: 

1100 return (_nvrtcResult(err), None) 

1101 return (_nvrtcResult_SUCCESS, size) 

1102  

1103@cython.embedsignature(True) 

1104def nvrtcSetFlowCallback(prog, callback, payload): 

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

1106  

1107 The callback function must satisfy the following constraints: 

1108  

1109 (1) Its signature should be: 

1110  

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

1112  

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

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

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

1116 extensions. 

1117  

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

1119 return values are reserved for future use. 

1120  

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

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

1123 nvrtcCompileProgram call in progress. 

1124  

1125 (4) It must be thread-safe. 

1126  

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

1128  

1129 Parameters 

1130 ---------- 

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

1132 CUDA Runtime Compilation program. 

1133 callback : Any 

1134 the callback that issues cancellation signal. 

1135 payload : Any 

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

1137  

1138 Returns 

1139 ------- 

1140 nvrtcResult 

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

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

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

1144 """ 

1145 cdef cynvrtc.nvrtcProgram cyprog 

1146 if prog is None: 

1147 pprog = 0 

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

1149 pprog = int(prog) 

1150 else: 

1151 pprog = int(nvrtcProgram(prog)) 

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

1153 cdef _HelperInputVoidPtrStruct cycallbackHelper 

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

1155 cdef _HelperInputVoidPtrStruct cypayloadHelper 

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

1157 with nogil: 

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

1159 _helper_input_void_ptr_free(&cycallbackHelper) 

1160 _helper_input_void_ptr_free(&cypayloadHelper) 

1161 return (_nvrtcResult(err),) 

1162  

1163@cython.embedsignature(True) 

1164def nvrtcGetTileIRSize(prog): 

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

1166  

1167 Parameters 

1168 ---------- 

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

1170 CUDA Runtime Compilation program. 

1171  

1172 Returns 

1173 ------- 

1174 nvrtcResult 

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

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

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

1178 TileIRSizeRet : int 

1179 Size of the generated cuda_tile IR. 

1180  

1181 See Also 

1182 -------- 

1183 :py:obj:`~.nvrtcGetTileIR` 

1184 """ 

1185 cdef cynvrtc.nvrtcProgram cyprog 

1186 if prog is None: 

1187 pprog = 0 

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

1189 pprog = int(prog) 

1190 else: 

1191 pprog = int(nvrtcProgram(prog)) 

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

1193 cdef size_t TileIRSizeRet = 0 

1194 with nogil: 

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

1196 if err != cynvrtc.NVRTC_SUCCESS: 

1197 return (_nvrtcResult(err), None) 

1198 return (_nvrtcResult_SUCCESS, TileIRSizeRet) 

1199  

1200@cython.embedsignature(True) 

1201def nvrtcGetTileIR(prog, char* TileIR): 

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

1203  

1204 Parameters 

1205 ---------- 

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

1207 CUDA Runtime Compilation program. 

1208 TileIR : bytes 

1209 Generated cuda_tile IR. 

1210  

1211 Returns 

1212 ------- 

1213 nvrtcResult 

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

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

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

1217  

1218 See Also 

1219 -------- 

1220 :py:obj:`~.nvrtcGetTileIRSize` 

1221 """ 

1222 cdef cynvrtc.nvrtcProgram cyprog 

1223 if prog is None: 

1224 pprog = 0 

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

1226 pprog = int(prog) 

1227 else: 

1228 pprog = int(nvrtcProgram(prog)) 

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

1230 with nogil: 

1231 err = cynvrtc.nvrtcGetTileIR(cyprog, TileIR) 

1232 return (_nvrtcResult(err),) 

1233  

1234@cython.embedsignature(True) 

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

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

1237  

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

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

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

1241 requiring a separate CUDA Toolkit installation. The bundled headers 

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

1243  

1244 After extraction, users can compile kernels by passing appropriate 

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

1246 nvrtcCompileProgram. 

1247  

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

1249 installation directory to track the installed version. 

1250  

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

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

1253 default, the function waits for the lock; use 

1254 NVRTC_INSTALL_HEADERS_NO_WAIT to return immediately with 

1255 NVRTC_ERROR_BUSY if another process holds the lock. 

1256  

1257 Parameters 

1258 ---------- 

1259 installPath : bytes 

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

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

1262 flags : unsigned int 

1263 NVRTC_INSTALL_HEADERS_* flags: 

1264  

1265 Returns 

1266 ------- 

1267 nvrtcResult 

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

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

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

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

1272 errorLog : bytes 

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

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

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

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

1277 needed. 

1278  

1279 See Also 

1280 -------- 

1281 :py:obj:`~.nvrtcCompileProgram` 

1282  

1283 Notes 

1284 ----- 

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

1286 """ 

1287 cdef const char* errorLog = NULL 

1288 with nogil: 

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

1290 if err != cynvrtc.NVRTC_SUCCESS: 

1291 return (_nvrtcResult(err), None) 

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

1293  

1294@cython.embedsignature(True) 

1295def nvrtcGetBundledHeadersInfo(): 

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

1297  

1298 This function allows users to determine if bundled headers are 

1299 available and get size estimates before calling 

1300 nvrtcInstallBundledHeaders. 

1301  

1302 Returns 

1303 ------- 

1304 nvrtcResult 

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

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

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

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

1309 Pointer to structure to receive header information. 

1310 errorLog : bytes 

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

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

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

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

1315 needed. 

1316 """ 

1317 cdef nvrtcBundledHeadersInfo info = nvrtcBundledHeadersInfo() 

1318 cdef const char* errorLog = NULL 

1319 with nogil: 

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

1321 if err != cynvrtc.NVRTC_SUCCESS: 

1322 return (_nvrtcResult(err), None, None) 

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

1324  

1325@cython.embedsignature(True) 

1326def nvrtcRemoveBundledHeaders(char* installPath): 

1327 """ nvrtcRemoveBundledHeaders removes previously installed bundled headers. 

1328  

1329 This function removes the headers installed by 

1330 nvrtcInstallBundledHeaders, helping users manage disk space. It 

1331 recursively removes all files and subdirectories within the 

1332 installation directory. 

1333  

1334 Parameters 

1335 ---------- 

1336 installPath : bytes 

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

1338 used with nvrtcInstallBundledHeaders. 

1339  

1340 Returns 

1341 ------- 

1342 nvrtcResult 

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

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

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

1346 errorLog : bytes 

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

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

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

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

1351 needed. 

1352  

1353 Notes 

1354 ----- 

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

1356 """ 

1357 cdef const char* errorLog = NULL 

1358 with nogil: 

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

1360 if err != cynvrtc.NVRTC_SUCCESS: 

1361 return (_nvrtcResult(err), None) 

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

1363  

1364@cython.embedsignature(True) 

1365def sizeof(objType): 

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

1367  

1368 Parameters 

1369 ---------- 

1370 objType : Any 

1371 CUDA Python object 

1372  

1373 Returns 

1374 ------- 

1375 lowered_name : int 

1376 The size of `objType` in bytes 

1377 """ 

1378  

1379 if objType == nvrtcProgram: 

1380 return sizeof(cynvrtc.nvrtcProgram) 

1381  

1382 if objType == nvrtcBundledHeadersInfo: 

1383 return sizeof(cynvrtc.nvrtcBundledHeadersInfo) 

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