Documentation
¶
Overview ¶
Package cubin reads, edits and writes CUDA ELF images (cubins).
Parse decodes a 64-bit little-endian cubin into a File: its sections, program headers, symbols, relocations and the EIATTR records of its .nv.info sections. File.Bytes serializes the model. The writer lays the file out as the CUDA toolchain does: sections in file order at their alignment, the section header table after the last section and the program header table after it, with each segment spanning the sections it covered when read. Padding the toolchain left beyond alignment is kept. A file that is parsed and written unchanged comes back byte for byte; the tests check this for every cubin in the module and for a corpus built from the module's CUDA sources with several toolkits and targets.
Methods on File edit the model in place and keep sizes, indices and segments consistent:
- File.Text and File.ReplaceText read and replace a kernel's code, its relocations, and the attributes that hold code offsets, such as the EXIT offsets.
- File.SetKernelAttr and File.SetModuleAttr add or change attributes, such as a required block shape or a register count.
- File.AddSection, File.AddSymbol and File.AddSegment add contents; a section is extended by changing its Data or Size.
- File.RenameSymbol, File.RenameKernel and File.RemoveSymbol edit the symbol table, renumbering references where needed.
An edit the package cannot keep consistent is refused: for example, replacing the code of a kernel whose .nv.capmerc copy would go stale (see File.StripCapmerc), or removing a symbol that something refers to.
Link links relocatable cubins, as nvcc -rdc writes them, into an executable cubin, as nvJitLink does for the cases it handles: calls, device globals, constant-bank variables, shared memory, weak definitions and kernels' jump tables across objects. It lays out shared memory its own way, not as nvJitLink does. It returns an *UnsupportedError for the rest, such as a jump table in a function that is not a kernel, so that a caller can fall back to nvJitLink. Its output keeps the code the objects hold, where nvJitLink sometimes rewrites it, and leaves out the .nv.merc and .nv.capmerc sections.
The layout facts the package relies on, such as which section types hold no file bytes and which attributes hold symbol indices or code offsets, come from observing cubins that nvcc, ptxas and nvJitLink write; they are not taken from NVIDIA documentation.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Example ¶
package main
import (
"bytes"
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
data := readCubin("kernels_sm121a.cubin.hex")
f, err := cubin.Parse(data)
if err != nil {
log.Fatal(err)
}
for _, s := range f.Sections {
if name, ok := strings.CutPrefix(s.Name, ".text."); ok {
fmt.Printf("%s: %d bytes of code\n", name, len(s.Data))
}
}
out, err := f.Bytes()
if err != nil {
log.Fatal(err)
}
fmt.Println("unchanged:", bytes.Equal(out, data))
}
Output: bigparam: 640 bytes of code capped: 384 bytes of code shared_k: 512 bytes of code bounded: 512 bytes of code unchanged: true
Index ¶
- Constants
- Variables
- func HVal(attr byte, v uint16) elfinspect.NVInfoRecord
- func SVal(attr byte, words ...uint32) elfinspect.NVInfoRecord
- type File
- func (f *File) AddSection(s *Section) int
- func (f *File) AddSegment(typ elf.ProgType, flags elf.ProgFlag, sections ...int) (*Prog, error)
- func (f *File) AddSymbol(sym Symbol) (int, error)
- func (f *File) Bytes() ([]byte, error)
- func (f *File) Kernels() ([]elfinspect.Kernel, error)
- func (f *File) RemoveSymbol(name string) error
- func (f *File) RenameKernel(kernel, new string) error
- func (f *File) RenameSymbol(old, new string) error
- func (f *File) ReplaceText(kernel string, t Text) error
- func (f *File) Section(name string) *Section
- func (f *File) SectionIndex(name string) int
- func (f *File) SetKernelAttr(kernel string, r elfinspect.NVInfoRecord) error
- func (f *File) SetModuleAttr(kernel string, attr byte, v uint32) error
- func (f *File) StripCapmerc(kernels ...string) []string
- func (f *File) StripCapmercForDriver(driverVersion int, kernels ...string) ([]string, error)
- func (f *File) Symbol(name string) *Symbol
- func (f *File) SymbolIndex(name string) int
- func (f *File) Text(kernel string) (Text, error)
- func (f *File) ToolkitVersion() (major, minor int, ok bool)
- type Header
- type Prog
- type Reloc
- type Section
- type Symbol
- type Text
- type UnsupportedError
Examples ¶
Constants ¶
const ( AttrFrameSize = elfinspect.AttrFrameSize // module-wide, per function AttrMinStackSize = 0x12 // EIATTR_MIN_STACK_SIZE: module-wide, per function AttrMaxStackSize = 0x23 // EIATTR_MAX_STACK_SIZE: module-wide, per function AttrRegCount = elfinspect.AttrRegCount // module-wide, per function AttrParamCBank = elfinspect.AttrParamCBank AttrMaxThreads = elfinspect.AttrMaxThreads AttrReqNTID = elfinspect.AttrReqNTID AttrMaxRegCount = elfinspect.AttrMaxRegCount AttrExitOffsets = 0x1c // EIATTR_EXIT_INSTR_OFFSETS: offsets of EXIT instructions AttrCoopOffsets = 0x28 // EIATTR_COOP_GROUP_INSTR_OFFSETS: offsets, one per mask AttrCoopMasks = 0x29 // EIATTR_COOP_GROUP_MASK_REGIDS: one word per coop offset AttrWarpOffsets = 0x31 // EIATTR_INT_WARP_WIDE_INSTR_OFFSETS AttrBranchTargets = 0x34 // EIATTR_INDIRECT_BRANCH_TARGETS AttrMbarOffsets = 0x39 // EIATTR_MBARRIER_INSTR_OFFSETS AttrLoadOffsets = 0x44 // EIATTR_UNUSED_LOAD_BYTE_OFFSET AttrAnnotations = 0x55 // EIATTR_ANNOTATIONS: records holding code offsets AttrExterns = 0x0f // EIATTR_EXTERNS: symbol indices of external functions )
EIATTR attributes the patch API treats specially, identified by observing the cubins nvcc and ptxas write.
const ( // SHT_CUDA_INFO is the type of .nv.info and .nv.info.<kernel>. SHT_CUDA_INFO elf.SectionType = 0x70000000 )
Section types the CUDA toolchain writes.
Variables ¶
var ErrFormat = errors.New("cubin: malformed image")
ErrFormat reports a malformed or unsupported image.
Functions ¶
func HVal ¶
func HVal(attr byte, v uint16) elfinspect.NVInfoRecord
HVal returns an EIFMT_HVAL attribute record holding v.
func SVal ¶
func SVal(attr byte, words ...uint32) elfinspect.NVInfoRecord
SVal returns an EIFMT_SVAL attribute record whose payload is words, little-endian.
Types ¶
type File ¶
type File struct {
Header Header
Sections []*Section
Progs []*Prog
// Symbols is the .symtab table. It is nil when the file has none.
Symbols []Symbol
// contains filtered or unexported fields
}
A File is a cubin. Sections[i] and Symbols[i] are ELF section i and symbol i, including the null entries at index 0.
Make a File with Parse. The zero File has no ELF header, and its Bytes method returns an error.
func Link ¶
Link links relocatable cubins, as nvcc -rdc writes them, into an executable cubin.
Link resolves global symbols across the objects, merges their .nv.constant3 banks, .nv.global data and call graphs, applies the relocations into constant banks and shared memory, and keeps the relocations the driver applies at load time. A function defined weak in several objects, such as a template instance, keeps its first definition. It recomputes each kernel's register count and minimum stack size over the call graph, as nvJitLink does. The .nv.merc and .nv.capmerc sections, which the driver does not need to load SASS for the objects' own architecture, are dropped.
Link handles only the sections, relocations and attributes whose meaning has been checked against nvJitLink; for anything else, such as a jump table in a function that is not a kernel, or a function's global definition after a weak one, it returns an *UnsupportedError. Shared memory is laid out differently from nvJitLink: each kernel's variables get offsets of Link's choosing, which nvJitLink's may not equal.
Example ¶
This example links two objects that nvcc -rdc built: a.cu's kernel k calls helper and counts into hits, which b.cu defines.
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
func main() {
var objs []*cubin.File
for _, name := range []string{"a", "b"} {
raw, err := os.ReadFile("testdata/link/" + name + ".cubin.hex")
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
f, err := cubin.Parse(data)
if err != nil {
log.Fatal(err)
}
objs = append(objs, f)
}
f, err := cubin.Link(objs...)
if err != nil {
log.Fatal(err)
}
for _, name := range []string{"k", "_Z6helperf", "hits", "bias", "scale"} {
s := f.Symbol(name)
fmt.Println(name, f.Sections[s.Shndx].Name, s.Value)
}
}
Output: k .text.k 0 _Z6helperf .text._Z6helperf 0 hits .nv.global 0 bias .nv.constant3 0 scale .nv.constant3 4
func Parse ¶
Parse decodes a cubin. It accepts any 64-bit little-endian ELF image and keeps a legacy e_version as it is. The returned File does not alias data.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
sym := f.Symbol("capped")
fmt.Println(sym.Type(), sym.Bind(), f.Sections[sym.Shndx].Name, sym.Size)
for _, r := range f.Section(".nv.info.capped").Attrs {
if r.Attr == 0x1b { // EIATTR_MAXREG_COUNT
fmt.Println("register ceiling", r.Value[0])
}
}
}
Output: STT_FUNC STB_GLOBAL .text.capped 384 register ceiling 40
func (*File) AddSection ¶
AddSection appends s to f's sections and returns its index. The writer places it after the sections read; no segment covers it unless one is added with File.AddSegment. A decoded kind of section (SHT_REL, SHT_RELA or SHT_CUDA_INFO) without Data is written from s.Relocs or s.Attrs. A section appended to Sections directly is placed the same way.
Example ¶
This example adds an initialized device global, as a tool injecting a configuration block into a kernel module would.
package main
import (
"debug/elf"
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
i := f.AddSection(&cubin.Section{
Name: ".nv.global.init",
Type: elf.SHT_PROGBITS,
Flags: elf.SHF_ALLOC | elf.SHF_WRITE,
Align: 8,
Data: make([]byte, 16),
})
if _, err := f.AddSymbol(cubin.Symbol{
Name: "config",
Info: elf.ST_INFO(elf.STB_GLOBAL, elf.STT_OBJECT),
Shndx: elf.SectionIndex(i),
Size: 16,
}); err != nil {
log.Fatal(err)
}
// The driver allocates the global only if a segment maps it.
if _, err := f.AddSegment(elf.PT_LOAD, elf.PF_R|elf.PF_W, i); err != nil {
log.Fatal(err)
}
b, err := f.Bytes()
if err != nil {
log.Fatal(err)
}
g, err := cubin.Parse(b)
if err != nil {
log.Fatal(err)
}
sym := g.Symbol("config")
fmt.Println(g.Sections[sym.Shndx].Name, sym.Size, len(g.Progs))
}
Output: .nv.global.init 16 6
func (*File) AddSegment ¶
AddSegment adds a program header covering the given sections and returns it. The sections must have been added in file order after the last section the file was read with, as File.AddSection places them.
func (*File) AddSymbol ¶
AddSymbol appends sym to the symbol table and returns its index. A local symbol is inserted after the existing locals instead, and the references to the symbols after it are renumbered.
func (*File) Bytes ¶
Bytes serializes f.
Sections are placed in index order, each at the next offset that meets its alignment; a section without file bytes is placed at the current offset and takes no space. The section header table follows the last section, unaligned, and the program header table follows it. A segment starts at the first section it covers and spans the sections it covers. These are the rules nvcc, ptxas and nvJitLink follow, so a parsed file that is written unchanged is byte for byte the input.
Names missing from .shstrtab or .strtab are appended to them; names that are no longer used stay.
func (*File) Kernels ¶
func (f *File) Kernels() ([]elfinspect.Kernel, error)
Kernels returns the entry points of f, as elfinspect.Kernels reads them from f's serialized form.
func (*File) RemoveSymbol ¶
RemoveSymbol removes the symbol named name and renumbers the references to the symbols after it. It refuses a symbol that a relocation, an attribute, the call graph or a section refers to.
Example ¶
package main
import (
"debug/elf"
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
fmt.Println(f.RemoveSymbol("capped"))
if _, err := f.AddSymbol(cubin.Symbol{Name: "scratch", Info: elf.ST_INFO(elf.STB_GLOBAL, elf.STT_NOTYPE), Shndx: elf.SHN_ABS}); err != nil {
log.Fatal(err)
}
fmt.Println(f.RemoveSymbol("scratch"), f.Symbol("scratch") != nil)
}
Output: cubin: symbol capped is referenced <nil> false
func (*File) RenameKernel ¶
RenameKernel renames kernel to new: its symbol and the sections named after it, such as .text.<kernel>, .nv.info.<kernel> and .nv.constant0.<kernel>. The copies in .nv.merc sections are left alone; a cubin that has them should have its capmerc sections stripped.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
if err := f.RenameKernel("capped", "capped_v2"); err != nil {
log.Fatal(err)
}
fmt.Println(f.Section(".text.capped_v2") != nil, f.Section(".nv.info.capped_v2") != nil, f.Symbol("capped") != nil)
}
Output: true true false
func (*File) RenameSymbol ¶
RenameSymbol renames the symbol old to new.
func (*File) ReplaceText ¶
ReplaceText gives kernel the code, relocations and code attributes in t. It sets the size of the text section, of the kernel's symbol and of its .debug_frame entry, replaces the section's relocations and the kernel's code attributes, and lays out the sections after it anew.
t.CodeAttrs must hold every code attribute the kernel has, as File.Text returns them; a payload of nil removes the attribute, and an attribute the kernel lacks is added. The offsets in EXIT, cooperative-group and warp-wide offset lists must name instructions inside t.Code.
ReplaceText refuses a kernel with a .nv.capmerc.text.<kernel> section, which would go stale (see File.StripCapmerc), and a symbol inside the section that the new code no longer reaches. Line tables (.debug_line, .nv_debug_line_sass) are left as they are.
Example ¶
This example gives one kernel the code of another, as an editor replacing a kernel's SASS would.
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
f.StripCapmerc() // the kernels' capmerc copies would go stale
t, err := f.Text("bounded")
if err != nil {
log.Fatal(err)
}
fmt.Printf("bounded: %d bytes, EXIT at % x\n", len(t.Code), t.CodeAttrs[cubin.AttrExitOffsets])
if err := f.ReplaceText("capped", t); err != nil {
log.Fatal(err)
}
sym := f.Symbol("capped")
fmt.Printf("capped: %d bytes, symbol size %d\n", len(f.Sections[sym.Shndx].Data), sym.Size)
}
Output: bounded: 512 bytes, EXIT at 70 00 00 00 00 01 00 00 capped: 512 bytes, symbol size 512
func (*File) SectionIndex ¶
SectionIndex returns the index of the section named name, or -1.
func (*File) SetKernelAttr ¶
func (f *File) SetKernelAttr(kernel string, r elfinspect.NVInfoRecord) error
SetKernelAttr sets an attribute of kernel's .nv.info.<kernel> section: it replaces the first record with the same attribute, or appends r. It creates the section when the kernel has none. Attributes that refer to code offsets are set with File.ReplaceText.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
// Require 64x2x1 threads per block and cap registers at 32.
if err := f.SetKernelAttr("capped", cubin.SVal(cubin.AttrReqNTID, 64, 2, 1)); err != nil {
log.Fatal(err)
}
if err := f.SetKernelAttr("capped", cubin.HVal(cubin.AttrMaxRegCount, 32)); err != nil {
log.Fatal(err)
}
printKernel(f, "capped")
}
func printKernel(f *cubin.File, name string) {
ks, err := f.Kernels()
if err != nil {
log.Fatal(err)
}
for _, k := range ks {
if k.Name == name {
fmt.Printf("%s: reqntid %v, maxreg %d, registers %d\n", k.Name, k.ReqNTID, k.MaxReg, k.Registers)
}
}
}
Output: capped: reqntid [64 2 1], maxreg 32, registers 10
func (*File) SetModuleAttr ¶
SetModuleAttr sets a module-wide per-function attribute of kernel in .nv.info, such as its register count (AttrRegCount) or stack frame (AttrFrameSize), to v. It replaces the record for kernel's symbol, or appends one.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
if err := f.SetModuleAttr("capped", cubin.AttrRegCount, 24); err != nil {
log.Fatal(err)
}
printKernel(f, "capped")
}
func printKernel(f *cubin.File, name string) {
ks, err := f.Kernels()
if err != nil {
log.Fatal(err)
}
for _, k := range ks {
if k.Name == name {
fmt.Printf("%s: reqntid %v, maxreg %d, registers %d\n", k.Name, k.ReqNTID, k.MaxReg, k.Registers)
}
}
}
Output: capped: reqntid [0 0 0], maxreg 40, registers 24
func (*File) StripCapmerc ¶
StripCapmerc neutralizes the .nv.capmerc.* sections of the given kernels, or of every kernel when none is given, as elfinspect.StripCapmerc does: each becomes an SHT_NULL section with no name or contents, so section indices are kept.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
fmt.Println(f.StripCapmerc("capped", "bounded"))
}
Output: [.nv.capmerc.text.capped .nv.capmerc.text.bounded]
func (*File) StripCapmercForDriver ¶
StripCapmercForDriver neutralizes matching .nv.capmerc.* sections like File.StripCapmerc, but refuses pre-13.5 cubins when driverVersion >= 13050 (returning an error wrapping elfinspect.ErrCapmercStripUnsupported) without mutating f.
func (*File) Symbol ¶
Symbol returns the first symbol named name, or nil.
Example ¶
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
// readCubin reads a hex-encoded cubin from the elf package's testdata.
func readCubin(name string) []byte {
raw, err := os.ReadFile("../elf/testdata/cuobjdump/" + name)
if err != nil {
log.Fatal(err)
}
data, err := hex.DecodeString(strings.Join(strings.Fields(string(raw)), ""))
if err != nil {
log.Fatal(err)
}
return data
}
func main() {
f, err := cubin.Parse(readCubin("kernels_sm121a.cubin.hex"))
if err != nil {
log.Fatal(err)
}
if s := f.Symbol("capped"); s != nil {
fmt.Println(s.Type(), f.Symbols[f.SymbolIndex("capped")].Name)
}
fmt.Println(f.Symbol("missing") == nil, f.SymbolIndex("missing"))
}
Output: STT_FUNC capped true -1
func (*File) SymbolIndex ¶
SymbolIndex returns the index of the first symbol named name, or -1.
func (*File) ToolkitVersion ¶
ToolkitVersion returns the CUDA toolkit (major, minor) recorded in f's .note.nv.tkinfo, .note.nv.cuinfo, or legacy ABI v7 e_version.
type Header ¶
type Header struct {
Ident [elf.EI_NIDENT]byte
Type elf.Type
Machine elf.Machine
// Version is e_version. Legacy CUDA images (ABI version 7) record
// the toolkit version here, such as 129 for CUDA 12.9.
Version uint32
Entry uint64
Flags uint32
Shstrndx uint16
}
A Header holds the ELF header fields that the layout does not fix.
type Prog ¶
type Prog struct {
Type elf.ProgType
Flags elf.ProgFlag
Vaddr uint64
Paddr uint64
Align uint64
// Off, Filesz and Memsz are the values read. The writer replaces
// them unless the Prog covers nothing.
Off, Filesz, Memsz uint64
// contains filtered or unexported fields
}
A Prog is one program header. The writer derives its offset and sizes from the sections it covers, which Parse records; a Prog that covers no section keeps the values it was read with.
type Section ¶
type Section struct {
Name string
Type elf.SectionType
Flags elf.SectionFlag
Addr uint64
Link uint32
Info uint32
Align uint64
// Entsize is sh_entsize.
Entsize uint64
// Data is the section's file bytes. It is nil for a section without
// file bytes, such as SHT_NOBITS, and for a decoded section.
//
// A section of a decoded kind (SHT_REL, SHT_RELA, SHT_CUDA_INFO or
// SHT_SYMTAB) with nil Data is written from Relocs, Attrs or the
// file's Symbols; with Data, from Data, and Relocs and Attrs must
// then be empty.
Data []byte
// Size is the size of a section without file bytes, such as
// .nv.shared.<kernel>. It is ignored for other sections.
Size uint64
// Relocs are the entries of a decoded SHT_REL or SHT_RELA section.
Relocs []Reloc
// Attrs are the records of a decoded SHT_CUDA_INFO section.
Attrs []elfinspect.NVInfoRecord
// contains filtered or unexported fields
}
A Section is one ELF section.
The contents of most sections are Data. Three kinds are decoded instead and written from their decoded form: the .symtab section (from File.Symbols), SHT_REL and SHT_RELA sections (from Relocs) and SHT_CUDA_INFO sections (from Attrs). A section that fails to decode keeps its bytes in Data, and edits that need its decoded form return an error.
type Symbol ¶
type Symbol struct {
Name string
Info byte
Other byte
// Shndx is st_shndx: a section index, or a reserved index such as
// [elf.SHN_UNDEF] or [elf.SHN_ABS].
Shndx elf.SectionIndex
Value uint64
Size uint64
// contains filtered or unexported fields
}
A Symbol is one entry of the symbol table.
type Text ¶
type Text struct {
Code []byte
// Relocs are the relocations that apply to Code.
Relocs []Reloc
// CodeAttrs holds the payloads of the kernel's .nv.info.<kernel>
// attributes that refer to offsets in Code, such as the EXIT
// offsets (AttrExitOffsets), keyed by attribute. Attributes not
// known to be free of code offsets are included.
CodeAttrs map[byte][]byte
}
A Text is the code of one kernel and the facts that refer to offsets in it.
type UnsupportedError ¶
type UnsupportedError struct {
Object int // index of the object in the call to Link
What string // the unsupported section, symbol, relocation or attribute
}
An UnsupportedError reports input that Link does not handle. Such input may be valid; a caller can link it with nvJitLink instead.
func (*UnsupportedError) Error ¶
func (e *UnsupportedError) Error() string