rocmarch

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rocmarch reports which AMD GPU architectures a ROCm libds4 build supports and which architectures the host has, without cgo and without loading the library.

A HIP fat binary only runs on the architectures it was compiled for, and a mismatch is not a load error: it surfaces as "invalid device function" on the first kernel launch. Checking up front lets ds4go fail with an actionable message instead.

Index

Constants

View Source
const ArchSymbol = "ds4_rocm_offload_archs"

ArchSymbol is the exported libds4 data symbol holding the comma-separated --offload-arch list the library was built with (ds4 Makefile ROCM_ARCHS).

View Source
const SkipEnv = "DS4_SKIP_GPU_ARCH_CHECK"

SkipEnv disables Check when set to a non-empty value other than "0".

Variables

This section is empty.

Functions

func BaseArch

func BaseArch(arch string) string

BaseArch strips target-feature suffixes: "gfx942:sramecc+:xnack-" -> "gfx942".

func Check

func Check(ctx context.Context, libPath string, fallback []string) error

Check returns a *MismatchError when libPath is a ROCm library and none of the detected host GPUs is in its architecture list. It returns nil when the library is not ROCm, either list is unknown, or SkipEnv is set.

func Compatible

func Compatible(libArchs, hostArchs []string) []string

Compatible returns the host architectures that some library architecture supports.

func HostArchs

func HostArchs(ctx context.Context) []string

HostArchs reports the GPU processors present on this host, e.g. ["gfx942"], in device order with duplicates removed.

HSA_OVERRIDE_GFX_VERSION, when set, wins: the ROCm runtime then loads code objects for that version regardless of the real hardware. Otherwise rocminfo is parsed when installed, falling back to the KFD topology in sysfs. An empty result means no GPU was found or detection failed, which callers must treat as unknown.

func ParseKFDProperties

func ParseKFDProperties(data []byte) (string, bool)

ParseKFDProperties returns the processor named by a KFD topology node's gfx_target_version (major*10000 + minor*100 + stepping, e.g. 90402 -> gfx942, 90010 -> gfx90a, 110501 -> gfx1151). ok is false for CPU nodes.

func ParseList

func ParseList(s string) []string

ParseList splits a space- or comma-separated architecture list, dropping empties and duplicates.

func ParseRocminfo

func ParseRocminfo(out []byte) []string

ParseRocminfo extracts agent processor names ("Name: gfx942") from rocminfo output. ISA names ("amdgcn-amd-amdhsa--gfx942:...") are skipped; generic targets are matched through Supports instead.

func Skipped

func Skipped() bool

Skipped reports whether SkipEnv disables the check.

func Supports

func Supports(libArch, hostArch string) bool

Supports reports whether a library built for libArch can run on a host GPU whose processor is hostArch. Target features are ignored: a plain "gfx942" build runs on any sramecc/xnack mode, and builds that pin a feature are rare enough that the HIP runtime's own error is acceptable.

Types

type MismatchError

type MismatchError struct {
	Library      string
	LibraryArchs []string
	Source       Source
	HostArchs    []string
}

MismatchError reports that no host GPU can run a ROCm library.

func (*MismatchError) Error

func (e *MismatchError) Error() string

type Report

type Report struct {
	ROCm         bool     // the library is a ROCm build
	LibraryArchs []string // empty when unknown
	Source       Source
	HostArchs    []string // empty when no GPU was detected
	Compatible   []string // host archs the library supports
}

Report is the outcome of comparing a library with the host.

func Inspect

func Inspect(ctx context.Context, libPath string, fallback []string) (Report, error)

Inspect compares the library at libPath with the host GPUs. fallback is used as the library's list when the file itself does not say (typically the rocm_archs install-metadata field); pass nil when there is none. Host detection runs only for ROCm libraries.

func (Report) Err

func (r Report) Err(libPath string) error

Err returns a *MismatchError for libPath when the report shows no host GPU the library supports, and nil otherwise. It does not consult SkipEnv.

func (Report) Known

func (r Report) Known() bool

Known reports whether both sides of the comparison were determined.

func (Report) OK

func (r Report) OK() bool

OK reports whether the library can run on some host GPU, treating any unknown side as OK.

type Source

type Source string

Source says where a library's architecture list came from.

const (
	// SourceNone means the library is not a ROCm build, or its list is
	// unknown.
	SourceNone Source = ""
	// SourceSymbol is the ds4_rocm_offload_archs symbol in the library.
	SourceSymbol Source = "embedded symbol"
	// SourceFatbin is the uncompressed HIP offload bundle in .hip_fatbin.
	SourceFatbin Source = "HIP fat binary"
	// SourceMetadata is the rocm_archs field of ds4go-install.json.
	SourceMetadata Source = "install metadata"
)

func LibraryArchs

func LibraryArchs(path string) (archs []string, src Source, isROCm bool, err error)

LibraryArchs reports the GPU architectures the ROCm library at path was compiled for.

It reads the ELF file only; nothing is loaded or executed. isROCm is true when the file is recognizably a ROCm build (it has the arch symbol or a .hip_fatbin section). archs is empty when the list cannot be determined, for example an older library whose offload bundle is compressed; callers must treat that as unknown rather than unsupported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL