@@ -449,7 +449,7 @@ class ObjectCode:
449
449
context.
450
450
"""
451
451
452
- __slots__ = ("_handle" , "_backend_version" , "_code_type" , "_module" , "_loader" , "_sym_map" )
452
+ __slots__ = ("_handle" , "_backend_version" , "_code_type" , "_module" , "_loader" , "_sym_map" , "_name" )
453
453
_supported_code_type = ("cubin" , "ptx" , "ltoir" , "fatbin" , "object" , "library" )
454
454
455
455
def __new__ (self , * args , ** kwargs ):
@@ -459,7 +459,7 @@ def __new__(self, *args, **kwargs):
459
459
)
460
460
461
461
@classmethod
462
- def _init (cls , module , code_type , * , symbol_mapping : Optional [dict ] = None ):
462
+ def _init (cls , module , code_type , * , name : str = "" , symbol_mapping : Optional [dict ] = None ):
463
463
self = super ().__new__ (cls )
464
464
assert code_type in self ._supported_code_type , f"{ code_type = } is not supported"
465
465
_lazy_init ()
@@ -473,112 +473,131 @@ def _init(cls, module, code_type, *, symbol_mapping: Optional[dict] = None):
473
473
self ._code_type = code_type
474
474
self ._module = module
475
475
self ._sym_map = {} if symbol_mapping is None else symbol_mapping
476
+ self ._name = name
476
477
477
478
return self
478
479
479
480
@classmethod
480
- def _reduce_helper (self , module , code_type , symbol_mapping ):
481
+ def _reduce_helper (self , module , code_type , name , symbol_mapping ):
481
482
# just for forwarding kwargs
482
- return ObjectCode ._init (module , code_type , symbol_mapping = symbol_mapping )
483
+ return ObjectCode ._init (module , code_type , name = name , symbol_mapping = symbol_mapping )
483
484
484
485
def __reduce__ (self ):
485
- return ObjectCode ._reduce_helper , (self ._module , self ._code_type , self ._sym_map )
486
+ return ObjectCode ._reduce_helper , (self ._module , self ._code_type , self ._name , self . _sym_map )
486
487
487
488
@staticmethod
488
- def from_cubin (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
489
+ def from_cubin (module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
489
490
"""Create an :class:`ObjectCode` instance from an existing cubin.
490
491
491
492
Parameters
492
493
----------
493
494
module : Union[bytes, str]
494
495
Either a bytes object containing the in-memory cubin to load, or
495
496
a file path string pointing to the on-disk cubin to load.
497
+ name : Optional[str]
498
+ A human-readable identifier representing this code object.
496
499
symbol_mapping : Optional[dict]
497
500
A dictionary specifying how the unmangled symbol names (as keys)
498
501
should be mapped to the mangled names before trying to retrieve
499
502
them (default to no mappings).
500
503
"""
501
- return ObjectCode ._init (module , "cubin" , symbol_mapping = symbol_mapping )
504
+ return ObjectCode ._init (module , "cubin" , name = name , symbol_mapping = symbol_mapping )
502
505
503
506
@staticmethod
504
- def from_ptx (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
507
+ def from_ptx (module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
505
508
"""Create an :class:`ObjectCode` instance from an existing PTX.
506
509
507
510
Parameters
508
511
----------
509
512
module : Union[bytes, str]
510
513
Either a bytes object containing the in-memory ptx code to load, or
511
514
a file path string pointing to the on-disk ptx file to load.
515
+ name : Optional[str]
516
+ A human-readable identifier representing this code object.
512
517
symbol_mapping : Optional[dict]
513
518
A dictionary specifying how the unmangled symbol names (as keys)
514
519
should be mapped to the mangled names before trying to retrieve
515
520
them (default to no mappings).
516
521
"""
517
- return ObjectCode ._init (module , "ptx" , symbol_mapping = symbol_mapping )
522
+ return ObjectCode ._init (module , "ptx" , name = name , symbol_mapping = symbol_mapping )
518
523
519
524
@staticmethod
520
- def from_ltoir (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
525
+ def from_ltoir (module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
521
526
"""Create an :class:`ObjectCode` instance from an existing LTOIR.
522
527
523
528
Parameters
524
529
----------
525
530
module : Union[bytes, str]
526
531
Either a bytes object containing the in-memory ltoir code to load, or
527
532
a file path string pointing to the on-disk ltoir file to load.
533
+ name : Optional[str]
534
+ A human-readable identifier representing this code object.
528
535
symbol_mapping : Optional[dict]
529
536
A dictionary specifying how the unmangled symbol names (as keys)
530
537
should be mapped to the mangled names before trying to retrieve
531
538
them (default to no mappings).
532
539
"""
533
- return ObjectCode ._init (module , "ltoir" , symbol_mapping = symbol_mapping )
540
+ return ObjectCode ._init (module , "ltoir" , name = name , symbol_mapping = symbol_mapping )
534
541
535
542
@staticmethod
536
- def from_fatbin (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
543
+ def from_fatbin (
544
+ module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None
545
+ ) -> "ObjectCode" :
537
546
"""Create an :class:`ObjectCode` instance from an existing fatbin.
538
547
539
548
Parameters
540
549
----------
541
550
module : Union[bytes, str]
542
551
Either a bytes object containing the in-memory fatbin to load, or
543
552
a file path string pointing to the on-disk fatbin to load.
553
+ name : Optional[str]
554
+ A human-readable identifier representing this code object.
544
555
symbol_mapping : Optional[dict]
545
556
A dictionary specifying how the unmangled symbol names (as keys)
546
557
should be mapped to the mangled names before trying to retrieve
547
558
them (default to no mappings).
548
559
"""
549
- return ObjectCode ._init (module , "fatbin" , symbol_mapping = symbol_mapping )
560
+ return ObjectCode ._init (module , "fatbin" , name = name , symbol_mapping = symbol_mapping )
550
561
551
562
@staticmethod
552
- def from_object (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
563
+ def from_object (
564
+ module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None
565
+ ) -> "ObjectCode" :
553
566
"""Create an :class:`ObjectCode` instance from an existing object code.
554
567
555
568
Parameters
556
569
----------
557
570
module : Union[bytes, str]
558
571
Either a bytes object containing the in-memory object code to load, or
559
572
a file path string pointing to the on-disk object code to load.
573
+ name : Optional[str]
574
+ A human-readable identifier representing this code object.
560
575
symbol_mapping : Optional[dict]
561
576
A dictionary specifying how the unmangled symbol names (as keys)
562
577
should be mapped to the mangled names before trying to retrieve
563
578
them (default to no mappings).
564
579
"""
565
- return ObjectCode ._init (module , "object" , symbol_mapping = symbol_mapping )
580
+ return ObjectCode ._init (module , "object" , name = name , symbol_mapping = symbol_mapping )
566
581
567
582
@staticmethod
568
- def from_library (module : Union [bytes , str ], * , symbol_mapping : Optional [dict ] = None ) -> "ObjectCode" :
583
+ def from_library (
584
+ module : Union [bytes , str ], * , name : str = "" , symbol_mapping : Optional [dict ] = None
585
+ ) -> "ObjectCode" :
569
586
"""Create an :class:`ObjectCode` instance from an existing library.
570
587
571
588
Parameters
572
589
----------
573
590
module : Union[bytes, str]
574
591
Either a bytes object containing the in-memory library to load, or
575
592
a file path string pointing to the on-disk library to load.
593
+ name : Optional[str]
594
+ A human-readable identifier representing this code object.
576
595
symbol_mapping : Optional[dict]
577
596
A dictionary specifying how the unmangled symbol names (as keys)
578
597
should be mapped to the mangled names before trying to retrieve
579
598
them (default to no mappings).
580
599
"""
581
- return ObjectCode ._init (module , "library" , symbol_mapping = symbol_mapping )
600
+ return ObjectCode ._init (module , "library" , name = name , symbol_mapping = symbol_mapping )
582
601
583
602
# TODO: do we want to unload in a finalizer? Probably not..
584
603
@@ -632,6 +651,11 @@ def code(self) -> CodeTypeT:
632
651
"""Return the underlying code object."""
633
652
return self ._module
634
653
654
+ @property
655
+ def name (self ) -> str :
656
+ """Return a human-readable name of this code object."""
657
+ return self ._name
658
+
635
659
@property
636
660
@precondition (_lazy_load_module )
637
661
def handle (self ):
0 commit comments