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