@@ -449,7 +449,7 @@ class ObjectCode:
449449 context.
450450 """
451451
452- __slots__ = ("_handle" , "_backend_version" , "_code_type" , "_module" , "_loader" , "_sym_map" )
452+ __slots__ = ("_handle" , "_backend_version" , "_code_type" , "_module" , "_loader" , "_sym_map" , "_name" )
453453 _supported_code_type = ("cubin" , "ptx" , "ltoir" , "fatbin" , "object" , "library" )
454454
455455 def __new__ (self , * args , ** kwargs ):
@@ -459,7 +459,7 @@ def __new__(self, *args, **kwargs):
459459 )
460460
461461 @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 ):
463463 self = super ().__new__ (cls )
464464 assert code_type in self ._supported_code_type , f"{ code_type = } is not supported"
465465 _lazy_init ()
@@ -473,112 +473,131 @@ def _init(cls, module, code_type, *, symbol_mapping: Optional[dict] = None):
473473 self ._code_type = code_type
474474 self ._module = module
475475 self ._sym_map = {} if symbol_mapping is None else symbol_mapping
476+ self ._name = name
476477
477478 return self
478479
479480 @classmethod
480- def _reduce_helper (self , module , code_type , symbol_mapping ):
481+ def _reduce_helper (self , module , code_type , name , symbol_mapping ):
481482 # 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 )
483484
484485 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 )
486487
487488 @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" :
489490 """Create an :class:`ObjectCode` instance from an existing cubin.
490491
491492 Parameters
492493 ----------
493494 module : Union[bytes, str]
494495 Either a bytes object containing the in-memory cubin to load, or
495496 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.
496499 symbol_mapping : Optional[dict]
497500 A dictionary specifying how the unmangled symbol names (as keys)
498501 should be mapped to the mangled names before trying to retrieve
499502 them (default to no mappings).
500503 """
501- return ObjectCode ._init (module , "cubin" , symbol_mapping = symbol_mapping )
504+ return ObjectCode ._init (module , "cubin" , name = name , symbol_mapping = symbol_mapping )
502505
503506 @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" :
505508 """Create an :class:`ObjectCode` instance from an existing PTX.
506509
507510 Parameters
508511 ----------
509512 module : Union[bytes, str]
510513 Either a bytes object containing the in-memory ptx code to load, or
511514 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.
512517 symbol_mapping : Optional[dict]
513518 A dictionary specifying how the unmangled symbol names (as keys)
514519 should be mapped to the mangled names before trying to retrieve
515520 them (default to no mappings).
516521 """
517- return ObjectCode ._init (module , "ptx" , symbol_mapping = symbol_mapping )
522+ return ObjectCode ._init (module , "ptx" , name = name , symbol_mapping = symbol_mapping )
518523
519524 @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" :
521526 """Create an :class:`ObjectCode` instance from an existing LTOIR.
522527
523528 Parameters
524529 ----------
525530 module : Union[bytes, str]
526531 Either a bytes object containing the in-memory ltoir code to load, or
527532 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.
528535 symbol_mapping : Optional[dict]
529536 A dictionary specifying how the unmangled symbol names (as keys)
530537 should be mapped to the mangled names before trying to retrieve
531538 them (default to no mappings).
532539 """
533- return ObjectCode ._init (module , "ltoir" , symbol_mapping = symbol_mapping )
540+ return ObjectCode ._init (module , "ltoir" , name = name , symbol_mapping = symbol_mapping )
534541
535542 @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" :
537546 """Create an :class:`ObjectCode` instance from an existing fatbin.
538547
539548 Parameters
540549 ----------
541550 module : Union[bytes, str]
542551 Either a bytes object containing the in-memory fatbin to load, or
543552 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.
544555 symbol_mapping : Optional[dict]
545556 A dictionary specifying how the unmangled symbol names (as keys)
546557 should be mapped to the mangled names before trying to retrieve
547558 them (default to no mappings).
548559 """
549- return ObjectCode ._init (module , "fatbin" , symbol_mapping = symbol_mapping )
560+ return ObjectCode ._init (module , "fatbin" , name = name , symbol_mapping = symbol_mapping )
550561
551562 @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" :
553566 """Create an :class:`ObjectCode` instance from an existing object code.
554567
555568 Parameters
556569 ----------
557570 module : Union[bytes, str]
558571 Either a bytes object containing the in-memory object code to load, or
559572 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.
560575 symbol_mapping : Optional[dict]
561576 A dictionary specifying how the unmangled symbol names (as keys)
562577 should be mapped to the mangled names before trying to retrieve
563578 them (default to no mappings).
564579 """
565- return ObjectCode ._init (module , "object" , symbol_mapping = symbol_mapping )
580+ return ObjectCode ._init (module , "object" , name = name , symbol_mapping = symbol_mapping )
566581
567582 @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" :
569586 """Create an :class:`ObjectCode` instance from an existing library.
570587
571588 Parameters
572589 ----------
573590 module : Union[bytes, str]
574591 Either a bytes object containing the in-memory library to load, or
575592 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.
576595 symbol_mapping : Optional[dict]
577596 A dictionary specifying how the unmangled symbol names (as keys)
578597 should be mapped to the mangled names before trying to retrieve
579598 them (default to no mappings).
580599 """
581- return ObjectCode ._init (module , "library" , symbol_mapping = symbol_mapping )
600+ return ObjectCode ._init (module , "library" , name = name , symbol_mapping = symbol_mapping )
582601
583602 # TODO: do we want to unload in a finalizer? Probably not..
584603
@@ -632,6 +651,11 @@ def code(self) -> CodeTypeT:
632651 """Return the underlying code object."""
633652 return self ._module
634653
654+ @property
655+ def name (self ) -> str :
656+ """Return a human-readable name of this code object."""
657+ return self ._name
658+
635659 @property
636660 @precondition (_lazy_load_module )
637661 def handle (self ):
0 commit comments