Coverage for cuda/bindings/nvfatbin.pyx: 86.52%

141 statements  

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

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

2# 

3# SPDX-License-Identifier: Apache-2.0 

4# 

5# This code was automatically generated across versions from 12.4.1 to 13.3.0. Do not modify it directly. 

6# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=2be5849c140c1ab6fc0408c1df7e885b2edb2a952aef35fd1c62f7ad5ce7fcb7 

7  

8  

9# <<<< PREAMBLE CONTENT >>>> 

10  

11from cuda.bindings._internal._fast_enum import FastEnum as _cyb_FastEnum 

12  

13  

14# <<<< END OF PREAMBLE CONTENT >>>> 

15  

16cimport cython # NOQA 

17  

18from ._internal.utils cimport (get_resource_ptr, get_nested_resource_ptr, nested_resource, nullable_unique_ptr, 

19 get_buffer_pointer, get_resource_ptrs) 

20  

21from libcpp.vector cimport vector 

22  

23  

24############################################################################### 

25# Enum 

26############################################################################### 

27  

28class Result(_cyb_FastEnum): 

29 """ 

30 The enumerated type `nvFatbinResult` defines API call result codes. 

31 nvFatbin APIs return `nvFatbinResult` codes to indicate the result. 

32  

33 See `nvFatbinResult`. 

34 """ 

35 SUCCESS = NVFATBIN_SUCCESS 

36 ERROR_INTERNAL = NVFATBIN_ERROR_INTERNAL 

37 ERROR_ELF_ARCH_MISMATCH = NVFATBIN_ERROR_ELF_ARCH_MISMATCH 

38 ERROR_ELF_SIZE_MISMATCH = NVFATBIN_ERROR_ELF_SIZE_MISMATCH 

39 ERROR_MISSING_PTX_VERSION = NVFATBIN_ERROR_MISSING_PTX_VERSION 

40 ERROR_NULL_POINTER = NVFATBIN_ERROR_NULL_POINTER 

41 ERROR_COMPRESSION_FAILED = NVFATBIN_ERROR_COMPRESSION_FAILED 

42 ERROR_COMPRESSED_SIZE_EXCEEDED = NVFATBIN_ERROR_COMPRESSED_SIZE_EXCEEDED 

43 ERROR_UNRECOGNIZED_OPTION = NVFATBIN_ERROR_UNRECOGNIZED_OPTION 

44 ERROR_INVALID_ARCH = NVFATBIN_ERROR_INVALID_ARCH 

45 ERROR_INVALID_NVVM = NVFATBIN_ERROR_INVALID_NVVM 

46 ERROR_EMPTY_INPUT = NVFATBIN_ERROR_EMPTY_INPUT 

47 ERROR_MISSING_PTX_ARCH = NVFATBIN_ERROR_MISSING_PTX_ARCH 

48 ERROR_PTX_ARCH_MISMATCH = NVFATBIN_ERROR_PTX_ARCH_MISMATCH 

49 ERROR_MISSING_FATBIN = NVFATBIN_ERROR_MISSING_FATBIN 

50 ERROR_INVALID_INDEX = NVFATBIN_ERROR_INVALID_INDEX 

51 ERROR_IDENTIFIER_REUSE = NVFATBIN_ERROR_IDENTIFIER_REUSE 

52 ERROR_INTERNAL_PTX_OPTION = NVFATBIN_ERROR_INTERNAL_PTX_OPTION 

53  

54  

55############################################################################### 

56# Error handling 

57############################################################################### 

58  

59class nvFatbinError(Exception): 

60  

61 def __init__(self, status): 

62 self.status = status 123)45*

63 s = Result(status) 123)45*

64 cdef str err = f"{s.name} ({s.value})" 123)45*

65 super(nvFatbinError, self).__init__(err) 123)45*

66  

67 def __reduce__(self): 

68 return (type(self), (self.status,)) 

69  

70  

71@cython.profile(False) 

72cdef int check_status(int status) except 1 nogil: 

73 if status != 0: 1aefghSTUV23ijklmnopqrstuvwx6789W+'-)bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(.*

74 with gil: 123)45*

75 raise nvFatbinError(status) 123)45*

76 return status 1aefghSTUV23ijklmnopqrstuvwx6789W+'-bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(.

77  

78  

79############################################################################### 

80# Wrapper functions 

81############################################################################### 

82  

83cpdef destroy(intptr_t handle): 

84 """nvFatbinDestroy frees the memory associated with the given handle. 

85  

86 Args: 

87 handle (intptr_t): nvFatbin handle. 

88  

89 .. seealso:: `nvFatbinDestroy` 

90 """ 

91 cdef Handle h = <Handle>handle 1efghSTUV23ijklmnopqrstuvwx6789W+'bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(

92 with nogil: 1efghSTUV23ijklmnopqrstuvwx6789W+'bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(

93 status = nvFatbinDestroy(&h) 1efghSTUV23ijklmnopqrstuvwx6789W+'bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(

94 check_status(status) 1efghSTUV23ijklmnopqrstuvwx6789W+'bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(

95  

96  

97cpdef str get_error_string(int result): 

98 """nvFatbinGetErrorString returns an error description string for each error code. 

99  

100 Args: 

101 result (Result): error code. 

102  

103 .. seealso:: `nvFatbinGetErrorString` 

104 """ 

105 cdef const char* _output_ 

106 cdef bytes _output_bytes_ 

107 _output_ = nvFatbinGetErrorString(<_Result>result) 2/ : ; = ? @ [ ] ^ _ ` { | } ~ abbbtbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbub

108  

109 if _output_ == NULL: 2/ : ; = ? @ [ ] ^ _ ` { | } ~ abbbtbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbub

110 return "" 2tbub

111  

112 _output_bytes_ = <bytes>_output_ 2/ : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

113 return _output_bytes_.decode() 2/ : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

114  

115  

116cpdef intptr_t create(options, size_t options_count) except -1: 

117 """nvFatbinCreate creates a new handle. 

118  

119 Args: 

120 options (object): An array of strings, each containing a 

121 single option. It can be: 

122  

123 - an :class:`int` as the pointer address to the nested sequence, or 

124 - a Python sequence of :class:`int`\s, each of which is a pointer address 

125 to a valid sequence of 'char', or 

126 - a nested Python sequence of ``str``. 

127  

128 options_count (size_t): Number of options. 

129  

130 Returns: 

131 intptr_t: Address of nvFatbin handle. 

132  

133 .. seealso:: `nvFatbinCreate` 

134 """ 

135 cdef nested_resource[ char ] _options_ 

136 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1efghSTUV23ijklmnopqrstuvwx6789W+')bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(*

137 cdef Handle handle_indirect 

138 with nogil: 1efghSTUV23ijklmnopqrstuvwx6789W+')bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(*

139 __status__ = nvFatbinCreate(&handle_indirect, <const char**>(_options_.ptrs.data()), options_count) 1efghSTUV23ijklmnopqrstuvwx6789W+')bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(*

140 check_status(__status__) 1efghSTUV23ijklmnopqrstuvwx6789W+')bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(*

141 return <intptr_t>handle_indirect 1efghSTUV23ijklmnopqrstuvwx6789W+'bcdyzABXYZ045CDEFGHIJKLMNOPQR!#$%1,(

142  

143  

144cpdef add_ptx(intptr_t handle, code, size_t size, arch, identifier, options_cmd_line): 

145 """nvFatbinAddPTX adds PTX to the fatbinary. 

146  

147 Args: 

148 handle (intptr_t): nvFatbin handle. 

149 code (bytes): The PTX code. 

150 size (size_t): The size of the PTX code. 

151 arch (str): The numerical architecture that this PTX is for 

152 (the XX of any sm_XX, lto_XX, or compute_XX). 

153 identifier (str): Name of the PTX, useful when extracting the 

154 fatbin with tools like cuobjdump. 

155 options_cmd_line (str): Options used during JIT compilation. 

156  

157 .. seealso:: `nvFatbinAddPTX` 

158 """ 

159 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

160 if not isinstance(arch, str): 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

161 raise TypeError("arch must be a Python str") 

162 cdef bytes _temp_arch_ = (<str>arch).encode() 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

163 cdef char* _arch_ = _temp_arch_ 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

164 if not isinstance(identifier, str): 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

165 raise TypeError("identifier must be a Python str") 

166 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

167 cdef char* _identifier_ = _temp_identifier_ 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

168 if not isinstance(options_cmd_line, str): 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

169 raise TypeError("options_cmd_line must be a Python str") 

170 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

171 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

172 with nogil: 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

173 __status__ = nvFatbinAddPTX(<Handle>handle, <const char*>_code_, size, <const char*>_arch_, <const char*>_identifier_, <const char*>_options_cmd_line_) 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

174 check_status(__status__) 1ijklmnopqrstuvwxbcdCDEFGHIJKLMNOPQR

175  

176  

177cpdef add_cubin(intptr_t handle, code, size_t size, arch, identifier): 

178 """nvFatbinAddCubin adds a CUDA binary to the fatbinary. 

179  

180 Args: 

181 handle (intptr_t): nvFatbin handle. 

182 code (bytes): The cubin. 

183 size (size_t): The size of the cubin. 

184 arch (str): The numerical architecture that this cubin is for 

185 (the XX of any sm_XX, lto_XX, or compute_XX). 

186 identifier (str): Name of the cubin, useful when extracting 

187 the fatbin with tools like cuobjdump. 

188  

189 .. seealso:: `nvFatbinAddCubin` 

190 """ 

191 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1STUV23bcdXYZ045

192 if not isinstance(arch, str): 1STUV23bcdXYZ045

193 raise TypeError("arch must be a Python str") 

194 cdef bytes _temp_arch_ = (<str>arch).encode() 1STUV23bcdXYZ045

195 cdef char* _arch_ = _temp_arch_ 1STUV23bcdXYZ045

196 if not isinstance(identifier, str): 1STUV23bcdXYZ045

197 raise TypeError("identifier must be a Python str") 

198 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1STUV23bcdXYZ045

199 cdef char* _identifier_ = _temp_identifier_ 1STUV23bcdXYZ045

200 with nogil: 1STUV23bcdXYZ045

201 __status__ = nvFatbinAddCubin(<Handle>handle, <const void*>_code_, size, <const char*>_arch_, <const char*>_identifier_) 1STUV23bcdXYZ045

202 check_status(__status__) 1STUV23bcdXYZ045

203  

204  

205cpdef add_ltoir(intptr_t handle, code, size_t size, arch, identifier, options_cmd_line): 

206 """nvFatbinAddLTOIR adds LTOIR to the fatbinary. 

207  

208 Args: 

209 handle (intptr_t): nvFatbin handle. 

210 code (bytes): The LTOIR code. 

211 size (size_t): The size of the LTOIR code. 

212 arch (str): The numerical architecture that this LTOIR is for 

213 (the XX of any sm_XX, lto_XX, or compute_XX). 

214 identifier (str): Name of the LTOIR, useful when extracting 

215 the fatbin with tools like cuobjdump. 

216 options_cmd_line (str): Options used during JIT compilation. 

217  

218 .. seealso:: `nvFatbinAddLTOIR` 

219 """ 

220 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1efghyzAB

221 if not isinstance(arch, str): 1efghyzAB

222 raise TypeError("arch must be a Python str") 

223 cdef bytes _temp_arch_ = (<str>arch).encode() 1efghyzAB

224 cdef char* _arch_ = _temp_arch_ 1efghyzAB

225 if not isinstance(identifier, str): 1efghyzAB

226 raise TypeError("identifier must be a Python str") 

227 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1efghyzAB

228 cdef char* _identifier_ = _temp_identifier_ 1efghyzAB

229 if not isinstance(options_cmd_line, str): 1efghyzAB

230 raise TypeError("options_cmd_line must be a Python str") 

231 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1efghyzAB

232 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1efghyzAB

233 with nogil: 1efghyzAB

234 __status__ = nvFatbinAddLTOIR(<Handle>handle, <const void*>_code_, size, <const char*>_arch_, <const char*>_identifier_, <const char*>_options_cmd_line_) 1efghyzAB

235 check_status(__status__) 1efghyzAB

236  

237  

238cpdef size_t size(intptr_t handle) except? 0: 

239 """nvFatbinSize returns the fatbinary's size. 

240  

241 Args: 

242 handle (intptr_t): nvFatbin handle. 

243  

244 Returns: 

245 size_t: The fatbinary's size. 

246  

247 .. seealso:: `nvFatbinSize` 

248 """ 

249 cdef size_t size 

250 with nogil: 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

251 __status__ = nvFatbinSize(<Handle>handle, &size) 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

252 check_status(__status__) 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

253 return size 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

254  

255  

256cpdef get(intptr_t handle, buffer): 

257 """nvFatbinGet returns the completed fatbinary. 

258  

259 Args: 

260 handle (intptr_t): nvFatbin handle. 

261 buffer (bytes): memory to store fatbinary. 

262  

263 .. seealso:: `nvFatbinGet` 

264 """ 

265 cdef void* _buffer_ = get_buffer_pointer(buffer, -1, readonly=False) 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

266 with nogil: 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

267 __status__ = nvFatbinGet(<Handle>handle, <void*>_buffer_) 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

268 check_status(__status__) 1efghSTUVijklmnopqrstuvwx6789W'bcdyzABXYZ0CDEFGHIJKLMNOPQR!#$%1(

269  

270  

271cpdef tuple version(): 

272 """nvFatbinVersion returns the current version of nvFatbin. 

273  

274 Returns: 

275 A 2-tuple containing: 

276  

277 - unsigned int: The major version. 

278 - unsigned int: The minor version. 

279  

280 .. seealso:: `nvFatbinVersion` 

281 """ 

282 cdef unsigned int major 

283 cdef unsigned int minor 

284 with nogil: 1a-.

285 __status__ = nvFatbinVersion(&major, &minor) 1a-.

286 check_status(__status__) 1a-.

287 return (major, minor) 1a-.

288  

289  

290cpdef add_index(intptr_t handle, code, size_t size, identifier): 

291 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 

292 if not isinstance(identifier, str): 

293 raise TypeError("identifier must be a Python str") 

294 cdef bytes _temp_identifier_ = (<str>identifier).encode() 

295 cdef char* _identifier_ = _temp_identifier_ 

296 with nogil: 

297 __status__ = nvFatbinAddIndex(<Handle>handle, <const void*>_code_, size, <const char*>_identifier_) 

298 check_status(__status__) 

299  

300  

301cpdef add_reloc(intptr_t handle, code, size_t size): 

302 """nvFatbinAddReloc adds relocatable PTX entries from a host object to the fatbinary. 

303  

304 Args: 

305 handle (intptr_t): nvFatbin handle. 

306 code (bytes): The host object image. 

307 size (size_t): The size of the host object image code. 

308  

309 .. seealso:: `nvFatbinAddReloc` 

310 """ 

311 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 16789!#$%

312 with nogil: 16789!#$%

313 __status__ = nvFatbinAddReloc(<Handle>handle, <const void*>_code_, size) 16789!#$%

314 check_status(__status__) 16789!#$%

315  

316  

317cpdef add_tile_ir(intptr_t handle, code, size_t size, identifier, options_cmd_line): 

318 """nvFatbinAddTileIR adds Tile IR to the fatbinary. 

319  

320 Args: 

321 handle (intptr_t): nvFatbin handle. 

322 code (bytes): The Tile IR. 

323 size (size_t): The size of the Tile IR. 

324 identifier (str): Name of the Tile IR, useful when extracting 

325 the fatbin with tools like cuobjdump. 

326 options_cmd_line (str): Options used during JIT compilation. 

327  

328 .. seealso:: `nvFatbinAddTileIR` 

329 """ 

330 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1W1

331 if not isinstance(identifier, str): 1W1

332 raise TypeError("identifier must be a Python str") 

333 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1W1

334 cdef char* _identifier_ = _temp_identifier_ 1W1

335 if not isinstance(options_cmd_line, str): 1W1

336 raise TypeError("options_cmd_line must be a Python str") 

337 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1W1

338 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1W1

339 with nogil: 1W1

340 __status__ = nvFatbinAddTileIR(<Handle>handle, <const void*>_code_, size, <const char*>_identifier_, <const char*>_options_cmd_line_) 1W1

341 check_status(__status__) 1W1

342del _cyb_FastEnum