2
2
#
3
3
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4
4
5
-
5
+ from typing import Union
6
6
from warnings import warn
7
7
8
8
from cuda .core .experimental ._utils import driver , get_binding_version , handle_return , precondition
@@ -220,6 +220,12 @@ class ObjectCode:
220
220
221
221
Loads the module library with specified module code and JIT options.
222
222
223
+ Note
224
+ ----
225
+ The public constructor assumes that ``module`` is of code type "cubin".
226
+ For all other possible code types (ex: "ptx"), only :class:`~cuda.core.experimental.Program`
227
+ accepts them and returns an `ObjectCode` instance with its ``compile`` method.
228
+
223
229
Note
224
230
----
225
231
Usage under CUDA 11.x will only load to the current device
@@ -228,32 +234,32 @@ class ObjectCode:
228
234
Parameters
229
235
----------
230
236
module : Union[bytes, str]
231
- Either a bytes object containing the module to load, or
232
- a file path string containing that module for loading.
233
- code_type : Any
234
- String of the compiled type.
235
- Supported options are "ptx", "cubin", "ltoir" and "fatbin".
236
- jit_options : Optional
237
- Mapping of JIT options to use during module loading.
238
- (Default to no options)
239
- symbol_mapping : Optional
240
- Keyword argument dictionary specifying how symbol names
241
- should be mapped before trying to retrieve them.
242
- (Default to no mappings)
243
-
237
+ Either a bytes object containing the cubin to load, or
238
+ a file path string pointing to the cubin to load.
244
239
"""
245
240
246
- __slots__ = ("_handle" , "_backend_version" , "_jit_options" , " _code_type" , "_module" , "_loader" , "_sym_map" )
241
+ __slots__ = ("_handle" , "_backend_version" , "_code_type" , "_module" , "_loader" , "_sym_map" )
247
242
_supported_code_type = ("cubin" , "ptx" , "ltoir" , "fatbin" )
248
243
249
- def __init__ (self , module , code_type , jit_options = None , * , symbol_mapping = None ):
244
+ def __init__ (self , module : Union [bytes , str ]):
245
+ _lazy_init ()
246
+
247
+ # handle is assigned during _lazy_load
248
+ self ._handle = None
249
+ self ._backend_version = "new" if (_py_major_ver >= 12 and _driver_ver >= 12000 ) else "old"
250
+ self ._loader = _backend [self ._backend_version ]
251
+ self ._code_type = "cubin"
252
+ self ._module = module
253
+ self ._sym_map = {}
254
+
255
+ def _init (module , code_type , * , symbol_mapping = None ):
256
+ self = ObjectCode .__new__ (ObjectCode )
250
257
if code_type not in self ._supported_code_type :
251
258
raise ValueError
252
259
_lazy_init ()
253
260
254
261
# handle is assigned during _lazy_load
255
262
self ._handle = None
256
- self ._jit_options = jit_options
257
263
258
264
self ._backend_version = "new" if (_py_major_ver >= 12 and _driver_ver >= 12000 ) else "old"
259
265
self ._loader = _backend [self ._backend_version ]
@@ -262,14 +268,19 @@ def __init__(self, module, code_type, jit_options=None, *, symbol_mapping=None):
262
268
self ._module = module
263
269
self ._sym_map = {} if symbol_mapping is None else symbol_mapping
264
270
271
+ return self
272
+
265
273
# TODO: do we want to unload in a finalizer? Probably not..
266
274
267
275
def _lazy_load_module (self , * args , ** kwargs ):
268
276
if self ._handle is not None :
269
277
return
270
278
module = self ._module
271
279
if isinstance (module , str ):
272
- self ._handle = handle_return (self ._loader ["file" ](module ))
280
+ if self ._backend_version == "new" :
281
+ self ._handle = handle_return (self ._loader ["file" ](module , [], [], 0 , [], [], 0 ))
282
+ else : # "old" backend
283
+ self ._handle = handle_return (self ._loader ["file" ](module ))
273
284
else :
274
285
assert isinstance (module , bytes )
275
286
if self ._backend_version == "new" :
0 commit comments