device

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package device provides device abstraction and memory allocation interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator interface {
	// Allocate allocates a block of memory of the given size in bytes.
	// For the CPU, this will be a Go slice. For a GPU, it would be a device pointer.
	Allocate(size int) (any, error)
	// Free releases the allocated memory.
	// For the CPU allocator, this is a no-op as Go's garbage collector manages memory.
	Free(ptr any) error
}

Allocator defines the interface for a memory allocator. It is responsible for allocating and freeing memory on a specific device.

func NewCPUAllocator

func NewCPUAllocator() Allocator

NewCPUAllocator creates a new CPU memory allocator.

type Device

type Device interface {
	// ID returns the unique identifier for the device (e.g., "cpu", "cuda:0").
	ID() string
	// GetAllocator returns the memory allocator associated with this device.
	GetAllocator() Allocator
	// Type returns the type of the device
	Type() Type
}

Device represents a physical or logical compute device (e.g., CPU, GPU). It provides access to the device's properties and its memory allocator.

func Get

func Get(id string) (Device, error)

Get returns a registered device by its ID. It returns an error if no device with that ID is found.

type Type

type Type int

Type is an enum for the kind of device.

const (
	// CPU represents the Central Processing Unit device type.
	CPU Type = iota
	// CUDA represents the NVIDIA GPU device type.
	CUDA
)

Jump to

Keyboard shortcuts

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