Documentation
¶
Overview ¶
Package deps manages external dependencies for GPU Go, including downloading and managing vgpu libraries from the CDN.
Package deps manages GPU binary tools like nvidia-smi, amdsmi
Index ¶
- Constants
- Variables
- func CompareVersions(v1, v2 string) bool
- func EnsureGPUBinary(ctx context.Context, paths *platform.Paths, vendor string) (string, error)
- func EnsureGPUBinaryForPlatform(ctx context.Context, paths *platform.Paths, vendor, osName, arch string) (string, error)
- func GetGPUBinaryName(vendor string) string
- func GetGPUBinaryPath(paths *platform.Paths, binaryName string) string
- type DepsManifest
- type DownloadResult
- type DownloadStatus
- type DownloadedManifest
- type GPUBinaryInfo
- type Library
- type LocalManifest
- type Manager
- func (m *Manager) CheckUpdates(ctx context.Context) ([]Library, error)
- func (m *Manager) CleanCache() error
- func (m *Manager) ComputeUpdateDiff() (*UpdateDiff, error)
- func (m *Manager) DownloadAllRequired(ctx context.Context, progressFn func(lib Library, downloaded, total int64)) ([]DownloadResult, error)
- func (m *Manager) DownloadLibrary(ctx context.Context, lib Library, progressFn func(downloaded, total int64)) error
- func (m *Manager) DownloadLibraryToDir(ctx context.Context, lib Library, libsDir string, ...) error
- func (m *Manager) EnsureLibrariesByTypes(ctx context.Context, libTypes []string, vendorSlug string, ...) ([]Library, error)
- func (m *Manager) EnsureLibrariesByTypesForPlatform(ctx context.Context, libTypes []string, ...) ([]Library, error)
- func (m *Manager) EnsureLibraryByType(ctx context.Context, libType string, vendorSlug string) (string, error)
- func (m *Manager) FetchManifest(ctx context.Context) (*ReleaseManifest, bool, error)
- func (m *Manager) FetchReleaseManifest(ctx context.Context) (*ReleaseManifest, bool, error)
- func (m *Manager) FetchReleaseManifestForPlatform(ctx context.Context, targetOS, targetArch string) (*ReleaseManifest, bool, error)
- func (m *Manager) GetAllLibraries(manifest *ReleaseManifest) []Library
- func (m *Manager) GetDownloadedLibraries() (*DownloadedManifest, error)
- func (m *Manager) GetInstalledLibraries() (*DepsManifest, error)
- func (m *Manager) GetLibrariesForPlatform(manifest *ReleaseManifest, osStr, arch, libType string) []Library
- func (m *Manager) GetLibraryPath(name string) string
- func (m *Manager) GetLibraryPathInDir(name string, libsDir string) string
- func (m *Manager) GetLibsDir() string
- func (m *Manager) GetRemoteGPUWorkerPath(ctx context.Context) (string, error)
- func (m *Manager) InstallLibrary(lib Library) error
- func (m *Manager) LoadCachedManifest() (*ReleaseManifest, error)
- func (m *Manager) LoadDepsManifest() (*DepsManifest, error)
- func (m *Manager) LoadDownloadedManifest() (*DownloadedManifest, error)
- func (m *Manager) LoadReleaseManifest() (*ReleaseManifest, error)
- func (m *Manager) SaveDepsManifest(manifest *DepsManifest) error
- func (m *Manager) SelectRequiredDeps(manifest *ReleaseManifest) *DepsManifest
- func (m *Manager) SyncReleases(ctx context.Context, osStr, arch string) (*ReleaseManifest, error)
- func (m *Manager) UpdateDepsManifest(ctx context.Context) (*DepsManifest, []Library, error)
- func (m *Manager) VerifyLibrary(path, expectedHash string) bool
- type ManagerOption
- type Manifest
- type ReleaseManifest
- type UpdateDiff
Constants ¶
const ( // DefaultCDNBaseURL is the default CDN for downloading dependencies DefaultCDNBaseURL = "https://cdn.tensor-fusion.ai" // ReleaseManifestFile is the filename for the cached releases manifest (from API sync) ReleaseManifestFile = "releases-manifest.json" // DepsManifestFile is the filename for the required dependencies manifest DepsManifestFile = "deps-manifest.json" // DownloadedManifestFile is the filename for the downloaded dependencies manifest DownloadedManifestFile = "downloaded-manifest.json" // AutoSyncInterval is the interval for auto-syncing the manifest AutoSyncInterval = 7 * 24 * time.Hour )
const ( LibraryTypeVGPULibrary = "vgpu-library" LibraryTypeRemoteGPUWorker = "remote-gpu-worker" LibraryTypeRemoteGPUClient = "remote-gpu-client" )
Library type constants
Variables ¶
var GPUBinaryRegistry = map[string]map[string]map[string]GPUBinaryInfo{
"nvidia": {
"linux": {
"amd64": {URL: "https://cdn.tensor-fusion.ai/nvidia-smi-linux-amd64-550.54.15.zip", BinaryName: "nvidia-smi"},
"arm64": {URL: "https://cdn.tensor-fusion.ai/nvidia-smi-linux-arm64-550.54.15.zip", BinaryName: "nvidia-smi"},
},
"windows": {
"amd64": {URL: "https://cdn.tensor-fusion.ai/nvidia-smi-windows-amd64-550.54.15.zip", BinaryName: "nvidia-smi"},
},
},
"amd": {
"linux": {
"amd64": {URL: "", BinaryName: "amdsmi"},
"arm64": {URL: "", BinaryName: "amdsmi"},
},
},
}
GPUBinaryRegistry maps vendor -> os -> arch -> GPUBinaryInfo TODO: Fill in actual CDN URLs
Functions ¶
func CompareVersions ¶ added in v1.1.16
CompareVersions compares two version strings using semantic versioning rules Returns true if v1 > v2, false otherwise Handles versions like "2.7.9", "2.7.10", "rgpu-2.6.3", etc. Removes any \w- prefix (word characters followed by hyphen) before comparison
func EnsureGPUBinary ¶ added in v1.1.18
EnsureGPUBinary ensures the GPU binary (like nvidia-smi) exists in the cache Downloads and extracts if not present Returns the path to the binary, or empty string if not available for this platform
func EnsureGPUBinaryForPlatform ¶ added in v1.1.18
func EnsureGPUBinaryForPlatform(ctx context.Context, paths *platform.Paths, vendor, osName, arch string) (string, error)
EnsureGPUBinaryForPlatform ensures the GPU binary exists for a specific platform Used when preparing binaries for containers (e.g., Linux containers on macOS)
func GetGPUBinaryName ¶ added in v1.1.18
GetGPUBinaryName returns the expected binary name for a vendor (without extension)
Types ¶
type DepsManifest ¶ added in v1.1.7
type DepsManifest struct {
UpdatedAt time.Time `json:"updated_at"`
Libraries map[string]Library `json:"libraries"` // key -> library
}
DepsManifest represents the required dependencies for current environment
type DownloadResult ¶ added in v1.1.7
type DownloadResult struct {
Library Library `json:"library"`
Status DownloadStatus `json:"status"`
Error string `json:"error,omitempty"`
}
DownloadResult represents the result of downloading a library
type DownloadStatus ¶ added in v1.1.7
type DownloadStatus string
DownloadStatus represents the status of a library during download
const ( DownloadStatusNew DownloadStatus = "new" DownloadStatusUpdated DownloadStatus = "updated" DownloadStatusExisting DownloadStatus = "existing" DownloadStatusFailed DownloadStatus = "failed" )
type DownloadedManifest ¶
type DownloadedManifest struct {
UpdatedAt time.Time `json:"updated_at"`
Libraries map[string]Library `json:"libraries"` // key -> library
}
DownloadedManifest represents locally downloaded dependencies
type GPUBinaryInfo ¶ added in v1.1.18
type GPUBinaryInfo struct {
URL string // CDN download URL (zip file)
BinaryName string // Expected binary name (e.g., "nvidia-smi", "amdsmi")
}
GPUBinaryInfo contains the download URL and expected binary name for a GPU tool
func GetGPUBinaryInfo ¶ added in v1.1.18
func GetGPUBinaryInfo(vendor, osName, arch string) *GPUBinaryInfo
GetGPUBinaryInfo returns the download URL and binary name for a GPU vendor/os/arch combination Returns nil if no binary is available for this combination
type Library ¶
type Library struct {
Name string `json:"name"`
Version string `json:"version"`
Platform string `json:"platform"` // linux, darwin, windows
Arch string `json:"arch"` // amd64, arm64
URL string `json:"url"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
Type string `json:"type,omitempty"` // e.g., "vgpu-library", "remote-gpu-worker", "remote-gpu-client"
// Vendor information from release
VendorSlug string `json:"vendorSlug,omitempty"` // e.g., "stub", "nvidia", "amd"
VendorName string `json:"vendorName,omitempty"` // e.g., "STUB", "NVIDIA", "AMD"
}
Library represents a downloadable library
type LocalManifest ¶
type LocalManifest = DepsManifest
LocalManifest is an alias for DepsManifest for backward compatibility
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages dependency downloads and versions
func NewManager ¶
func NewManager(opts ...ManagerOption) *Manager
NewManager creates a new dependency manager
func (*Manager) CheckUpdates ¶
CheckUpdates checks if deps manifest has updates compared to downloaded manifest Returns the libraries that need to be downloaded
func (*Manager) CleanCache ¶
CleanCache removes all cached downloads
func (*Manager) ComputeUpdateDiff ¶ added in v1.1.7
func (m *Manager) ComputeUpdateDiff() (*UpdateDiff, error)
ComputeUpdateDiff computes the difference between deps manifest and downloaded manifest
func (*Manager) DownloadAllRequired ¶ added in v1.1.7
func (m *Manager) DownloadAllRequired(ctx context.Context, progressFn func(lib Library, downloaded, total int64)) ([]DownloadResult, error)
DownloadAllRequired downloads all libraries in deps manifest that need downloading Returns the download results for each library
func (*Manager) DownloadLibrary ¶
func (m *Manager) DownloadLibrary(ctx context.Context, lib Library, progressFn func(downloaded, total int64)) error
DownloadLibrary downloads a library to the default (flat) libs directory
func (*Manager) DownloadLibraryToDir ¶ added in v1.5.0
func (m *Manager) DownloadLibraryToDir(ctx context.Context, lib Library, libsDir string, progressFn func(downloaded, total int64)) error
DownloadLibraryToDir downloads a library to a specific libs directory.
func (*Manager) EnsureLibrariesByTypes ¶ added in v1.1.11
func (m *Manager) EnsureLibrariesByTypes(ctx context.Context, libTypes []string, vendorSlug string, progressFn func(lib Library, downloaded, total int64)) ([]Library, error)
EnsureLibrariesByTypes ensures ALL libraries of the specified types exist and are downloaded This is different from EnsureLibraryByType which only returns one library vendorSlug filters by vendor (e.g., "nvidia", "amd"). Empty string matches all vendors. Returns the list of all libraries that were checked/downloaded
func (*Manager) EnsureLibrariesByTypesForPlatform ¶ added in v1.1.17
func (m *Manager) EnsureLibrariesByTypesForPlatform(ctx context.Context, libTypes []string, vendorSlug, targetOS, targetArch string, progressFn func(lib Library, downloaded, total int64)) ([]Library, error)
EnsureLibrariesByTypesForPlatform ensures ALL libraries of the specified types exist and are downloaded for a specific platform targetOS and targetArch specify the target platform (e.g., "linux", "arm64") If both are empty, uses the current platform and the flat libs directory (agent/worker path). If targetOS is specified, uses arch-specific subdirectory (e.g., libs/linux-amd64/) to avoid collisions between different architectures (studio/use/launch path).
func (*Manager) EnsureLibraryByType ¶ added in v1.1.7
func (m *Manager) EnsureLibraryByType(ctx context.Context, libType string, vendorSlug string) (string, error)
EnsureLibraryByType ensures a library of the specified type exists and is downloaded If not available, it will auto-sync and download on demand Returns the path to the library
func (*Manager) FetchManifest ¶
FetchManifest is an alias for FetchReleaseManifest
func (*Manager) FetchReleaseManifest ¶ added in v1.1.7
FetchReleaseManifest loads the release manifest, and syncs from API if not available or outdated Returns (manifest, synced, error) where synced is true if auto-sync was performed
func (*Manager) FetchReleaseManifestForPlatform ¶ added in v1.1.17
func (m *Manager) FetchReleaseManifestForPlatform(ctx context.Context, targetOS, targetArch string) (*ReleaseManifest, bool, error)
FetchReleaseManifestForPlatform loads the release manifest for a specific platform If targetOS and targetArch are empty, uses the current platform Returns (manifest, synced, error) where synced is true if auto-sync was performed
func (*Manager) GetAllLibraries ¶
func (m *Manager) GetAllLibraries(manifest *ReleaseManifest) []Library
GetAllLibraries returns all libraries from the manifest
func (*Manager) GetDownloadedLibraries ¶
func (m *Manager) GetDownloadedLibraries() (*DownloadedManifest, error)
GetDownloadedLibraries returns the downloaded manifest
func (*Manager) GetInstalledLibraries ¶
func (m *Manager) GetInstalledLibraries() (*DepsManifest, error)
GetInstalledLibraries returns the deps manifest (renamed from installed)
func (*Manager) GetLibrariesForPlatform ¶
func (m *Manager) GetLibrariesForPlatform(manifest *ReleaseManifest, osStr, arch, libType string) []Library
GetLibrariesForPlatform returns libraries matching the specified platform and type If both os and arch are empty strings, uses the current platform If type is empty string, matches any type
func (*Manager) GetLibraryPath ¶
GetLibraryPath returns the path to a library in cache For .so/.dll files, returns path in libs subdirectory For binaries (executables), returns path in cache root directory
func (*Manager) GetLibraryPathInDir ¶ added in v1.5.0
GetLibraryPathInDir returns the path to a library in a specific libs directory. For shared libraries, uses the given libsDir; for binaries, uses cache root.
func (*Manager) GetLibsDir ¶ added in v1.1.18
GetLibsDir returns the directory for .so/.dll library files This directory is used for LD_LIBRARY_PATH, ld.so.conf, and ld.so.preload
func (*Manager) GetRemoteGPUWorkerPath ¶
GetRemoteGPUWorkerPath returns the path to the remote-gpu-worker binary It ensures the library exists, downloading if necessary
func (*Manager) InstallLibrary ¶
InstallLibrary marks a library as required (adds to deps manifest)
func (*Manager) LoadCachedManifest ¶
func (m *Manager) LoadCachedManifest() (*ReleaseManifest, error)
LoadCachedManifest is an alias for LoadReleaseManifest
func (*Manager) LoadDepsManifest ¶ added in v1.1.7
func (m *Manager) LoadDepsManifest() (*DepsManifest, error)
LoadDepsManifest loads the deps manifest from local storage
func (*Manager) LoadDownloadedManifest ¶ added in v1.1.7
func (m *Manager) LoadDownloadedManifest() (*DownloadedManifest, error)
LoadDownloadedManifest loads the downloaded manifest from local storage
func (*Manager) LoadReleaseManifest ¶ added in v1.1.7
func (m *Manager) LoadReleaseManifest() (*ReleaseManifest, error)
LoadReleaseManifest loads the release manifest from local storage
func (*Manager) SaveDepsManifest ¶ added in v1.1.7
func (m *Manager) SaveDepsManifest(manifest *DepsManifest) error
SaveDepsManifest saves the deps manifest to local storage
func (*Manager) SelectRequiredDeps ¶ added in v1.1.7
func (m *Manager) SelectRequiredDeps(manifest *ReleaseManifest) *DepsManifest
SelectRequiredDeps selects the required dependencies from release manifest For each library type, it selects all artifacts from the latest version This ensures that types with multiple files (like remote-gpu-client) get all files
func (*Manager) SyncReleases ¶
SyncReleases fetches releases from the API and caches them locally as release-manifest If os and arch are empty strings, uses the current platform Returns the synced manifest for verbose output
func (*Manager) UpdateDepsManifest ¶ added in v1.1.7
UpdateDepsManifest syncs releases and updates the deps manifest with latest versions Returns (updated deps manifest, list of changes from old deps)
func (*Manager) VerifyLibrary ¶
VerifyLibrary checks if a file exists and has the expected hash
type ManagerOption ¶
type ManagerOption func(*Manager)
ManagerOption configures the dependency manager
func WithAPIBaseURL ¶
func WithAPIBaseURL(url string) ManagerOption
WithAPIBaseURL sets a custom API base URL
func WithAPIClient ¶
func WithAPIClient(client *api.Client) ManagerOption
WithAPIClient sets a custom API client
func WithCDNBaseURL ¶
func WithCDNBaseURL(url string) ManagerOption
WithCDNBaseURL sets a custom CDN base URL
type Manifest ¶
type Manifest = ReleaseManifest
Manifest is an alias for ReleaseManifest for backward compatibility
type ReleaseManifest ¶ added in v1.1.7
type ReleaseManifest struct {
Version string `json:"version"`
UpdatedAt time.Time `json:"updated_at"`
Libraries []Library `json:"libraries"`
}
ReleaseManifest represents the global releases manifest synced from API
type UpdateDiff ¶ added in v1.1.7
type UpdateDiff struct {
ToDownload []Library `json:"to_download"` // new or version mismatch
UpToDate []Library `json:"up_to_date"` // already downloaded with correct version
}
UpdateDiff represents the difference between deps-manifest and downloaded-manifest