Documentation
¶
Overview ¶
Package nvjitlink links device PTX, CUBIN, fatbin, and LTO-IR inputs via libnvJitLink.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
Name string
Kind rawnvjitlink.InputType
Data []byte
}
Input is one named device-code input. Kind must describe Data's format. Link copies Data before passing it to the native linker. The caller must not mutate Data concurrently with Link.
func InputFromArtifact ¶
func InputFromArtifact(name string, cm *nvrtc.CompiledModule) (Input, error)
InputFromArtifact selects the linkable output of an NVRTC compilation. It prefers CUBIN for OutputAuto and requires explicit LTO for LTOIR inputs.
type Option ¶
type Option func(*linkOptions) error
Option configures a link. The zero value is invalid.
func WithMaxRegisters ¶
WithMaxRegisters sets the maximum register count.
type Result ¶
type Result struct {
CUBIN []byte
PTX []byte
InfoLog string
ErrorLog string
// contains filtered or unexported fields
}
Result owns linked output and diagnostics. Exactly one of CUBIN or PTX is set after successful linking. A non-nil Result may accompany an error so diagnostics remain available; its output must not be used when Link reports an error.
func Link ¶
Link synchronously links inputs using native nvJitLink options, including a required -arch= target. The -ptx option selects PTX and requires -lto; otherwise CUBIN is returned. LTOIR inputs require -lto. Toolkit compatibility and unknown options are checked by the loaded linker and reported with its diagnostic log. Link does not install a library or cache results.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/compile/nvjitlink"
)
func main() {
_, err := nvjitlink.Link(nil, "-arch=sm_80")
fmt.Println(err)
}
Output: nvjitlinkx: no inputs
func LinkRelocatable ¶
LinkRelocatable links relocatable cubins, as nvcc -rdc writes them, into an executable cubin. It links them in Go with cubin.Link when every input is a cubin, the only option is -arch=sm_<N> naming the inputs' SM, and cubin.Link handles the inputs; otherwise it calls Link. The Result's InfoLog says which linker ran and, when Link ran, why cubin.Link did not.
An error cubin.Link reports in inputs it handles, such as an undefined or duplicate symbol, is returned without calling Link.
Example ¶
This example links two objects that nvcc -rdc built for sm_121a: one calls a function and uses a global the other defines.
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
rawnvjitlink "github.com/tmc/lib/nvidia/nvjitlink"
"github.com/tmc/lib/nvidia/x/compile/nvjitlink"
"github.com/tmc/lib/nvidia/x/host/cubin"
)
func main() {
var in []nvjitlink.Input
for _, name := range []string{"a", "b"} {
raw, err := os.ReadFile("../../host/cubin/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)
}
in = append(in, nvjitlink.Input{Name: name + ".o", Kind: rawnvjitlink.InputCubin, Data: data})
}
r, err := nvjitlink.LinkRelocatable(in, "-arch=sm_121a")
if err != nil {
log.Fatal(err)
}
fmt.Print(r.InfoLog)
f, err := cubin.Parse(r.CUBIN)
if err != nil {
log.Fatal(err)
}
fmt.Println(f.Header.Type, f.Symbol("_Z6helperf").Size)
}
Output: linked by cubin.Link ET_EXEC 256
func LinkWithOptions ¶
LinkWithOptions links inputs using validated nvJitLink options. Link remains available for callers that pass native option strings.
func (*Result) Close ¶
Close retries native destruction after a cleanup failure. It is safe to call repeatedly or concurrently. nvJitLink binds a handle to the thread that created it, so a retry from another thread may itself fail. Successful Link already closed its native resources. A Result returned with an error must be closed if its initial cleanup failed; until then it retains the linker and input pins.