reprospect.tools.binaries.cuobjdump module

Tools that can be used to extract SASS code and kernel attributes from executables.

Note

Whereas cuda.core.ObjectCode focuses on compiling with nvcc and querying a handful of kernel properties, this modules provides an interface to the CUDA binary analysis utilities to allow the SASS code of each kernel to be extracted for more extensive analysis, e.g. with reprospect.tools.sass.

class reprospect.tools.binaries.cuobjdump.CuObjDump(file: ~pathlib.Path, arch: ~reprospect.tools.architecture.NVIDIAArch, *, sass: bool = True, demangler: type[~reprospect.tools.binaries.demangle.CuppFilt | ~reprospect.tools.binaries.demangle.LlvmCppFilt] | None = <class 'reprospect.tools.binaries.demangle.CuppFilt'>, keep: ~typing.Iterable[str] | None = None)View on GitHub

Bases: object

Use cuobjdump for extracting SASS, symbol table, and so on.

References:

__init__(file: ~pathlib.Path, arch: ~reprospect.tools.architecture.NVIDIAArch, *, sass: bool = True, demangler: type[~reprospect.tools.binaries.demangle.CuppFilt | ~reprospect.tools.binaries.demangle.LlvmCppFilt] | None = <class 'reprospect.tools.binaries.demangle.CuppFilt'>, keep: ~typing.Iterable[str] | None = None) NoneView on GitHub
Parameters:
  • file – Either a host binary file containing one or more embedded CUDA binary files, or itself a CUDA binary file.

  • keep – Optionally filter the functions to be kept.

__str__() strView on GitHub

Rich representation.

arch: Final[NVIDIAArch]

The NVIDIA architecture.

property embedded_cubins: tuple[str, ...]View on GitHub

Get the names of the embedded CUDA binary files contained in file.

classmethod extract(*, file: Path, arch: NVIDIAArch, cwd: Path, cubin: str, **kwargs) tuple[CuObjDump, Path]View on GitHub

Extract the embedded CUDA binary file whose name contains cubin, from file, for the given arch.

The file can be inspected with the following command to list all ELF files:

cuobjdump --list-elf <file>

Note that extracting an embedded CUDA binary from a file so as to extract a specific subset of the SASS can be significantly faster than extracting all the SASS straightforwardly from the whole file.

static extract_elf(*, file: Path, cwd: Path | None = None, arch: NVIDIAArch | None = None, name: str | None = None) Generator[str, None, None]View on GitHub

Extract ELF files from file.

Parameters:
  • arch – Optionally filter for a given architecture.

  • name – Optionally filter by name.

file: Final[Path]

The binary file.

property file_is_cubin: boolView on GitHub

Whether file is a CUDA binary file.

functions: Final[dict[str, Function]]
static list_elf(*, file: Path, arch: NVIDIAArch | None = None) Generator[str, None, None]View on GitHub

List ELF files in file.

Parameters:

arch – Optionally filter for a given architecture.

parse_sass(demangler: type[CuppFilt | LlvmCppFilt] | None = None, keep: Iterable[str] | None = None) NoneView on GitHub

Parse SASS from file.

property symtab: DataFrameView on GitHub

Extract the symbol table from file for arch.

This function requires that file is either a host binary file containing only a single embedded CUDA binary file or itself a CUDA binary file.

class reprospect.tools.binaries.cuobjdump.Function(symbol: str, code: str, ru: ResourceUsage)View on GitHub

Bases: object

Data structure holding the SASS code and resource usage of a kernel, as extracted from a binary file.

__init__(symbol: str, code: str, ru: ResourceUsage) None
__str__() strView on GitHub

Rich representation with to_table().

code: str

The SASS code.

ru: ResourceUsage

The resource usage.

symbol: str

The symbol name.

to_table(*, max_code_length: int = 130, descriptors: dict[str, str] | None = None) TableView on GitHub

Convert to a rich.table.Table.

Parameters:

descriptors – Key-value pairs added as descriptor rows at the top of the table, optional.

class reprospect.tools.binaries.cuobjdump.ResourceUsage(register: int = 0, constant: dict[int, int] = <factory>, shared: int = 0, local: int = 0, sampler: int = 0, stack: int = 0, surface: int = 0, texture: int = 0)View on GitHub

Bases: object

Resource usage.

References:

__init__(register: int = 0, constant: dict[int, int] = <factory>, shared: int = 0, local: int = 0, sampler: int = 0, stack: int = 0, surface: int = 0, texture: int = 0) None
__str__() strView on GitHub
constant: dict[int, int]
local: int
classmethod parse(line: str) ResourceUsageView on GitHub

Parse a resource usage line, such as produced by cuobjdump with --dump-resource-usage.

register: int
sampler: int
shared: int
stack: int
surface: int
texture: int