Documentation
¶
Overview ¶
Package mlx provides Go bindings for the MLX machine learning framework. MLX is an array framework for machine learning with multiple backend support:
- Metal: Apple Silicon GPUs (macOS) - CUDA: NVIDIA GPUs (Linux/Windows) - CPU: Fallback with SIMD optimizations (all platforms)
The package automatically detects and uses the best available backend. Build with CGO_ENABLED=1 and appropriate build tags for GPU support:
- cuda: Enable CUDA backend (requires CUDA toolkit) - metal: Enable Metal backend (automatic on macOS)
Index ¶
- Variables
- func Eval(arrays ...*Array)
- func Info() string
- func SetBackend(backend Backend) error
- func Synchronize()
- type Array
- func Add(a, b *Array) *Array
- func Arange(start, stop, step float64) *Array
- func ArrayFromSlice[T int64 | float64 | float32 | int32](data []T, shape []int, dtype Dtype) *Array
- func FromSlice(data []float32, shape []int, dtype Dtype) *Array
- func MatMul(a, b *Array) *Array
- func Maximum(a, b *Array) *Array
- func Mean(a *Array, axis ...int) *Array
- func Multiply(a, b *Array) *Array
- func Ones(shape []int, dtype Dtype) *Array
- func Random(shape []int, dtype Dtype) *Array
- func Sum(a *Array, axis ...int) *Array
- func Zeros(shape []int, dtype Dtype) *Array
- type Backend
- type CPUDevice
- type Context
- func (c *Context) Add(a, b *Array) *Array
- func (c *Context) Arange(start, stop, step float64) *Array
- func (c *Context) ArrayFromSlice(data any, shape []int, dtype Dtype) *Array
- func (c *Context) Eval(arrays ...*Array)
- func (c *Context) Free(a *Array)
- func (c *Context) FreeStream(s *Stream)
- func (c *Context) FromSlice(data []float32, shape []int, dtype Dtype) *Array
- func (c *Context) GetBackend() Backend
- func (c *Context) GetDevice() *Device
- func (c *Context) MatMul(a, b *Array) *Array
- func (c *Context) Maximum(a, b *Array) *Array
- func (c *Context) Mean(a *Array, axis ...int) *Array
- func (c *Context) Multiply(a, b *Array) *Array
- func (c *Context) NewStream() *Stream
- func (c *Context) Ones(shape []int, dtype Dtype) *Array
- func (c *Context) Random(shape []int, dtype Dtype) *Array
- func (c *Context) SetBackend(backend Backend) error
- func (c *Context) Sum(a *Array, axis ...int) *Array
- func (c *Context) Synchronize()
- func (c *Context) Zeros(shape []int, dtype Dtype) *Array
- type Device
- type DeviceInfo
- type Dtype
- type Stream
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultContext is the global MLX context DefaultContext *Context // ErrNoGPU is returned when GPU is requested but not available ErrNoGPU = errors.New("no GPU available") // ErrInvalidBackend is returned for invalid backend selection ErrInvalidBackend = errors.New("invalid backend") // Version is the MLX library version Version = "0.1.0" )
Functions ¶
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents a multi-dimensional array
func ArrayFromSlice ¶ added in v0.10.1
ArrayFromSlice creates an array from a typed Go slice with specified shape and dtype. Supports []int64, []float64, []float32, []int32 data types.
type CPUDevice ¶ added in v0.2.0
type CPUDevice struct {
// contains filtered or unexported fields
}
CPUDevice represents CPU-based computation fallback
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context manages MLX runtime and resources
func (*Context) ArrayFromSlice ¶ added in v0.10.1
ArrayFromSlice creates an array from a typed slice (Context method)
func (*Context) FreeStream ¶ added in v0.2.0
FreeStream releases resources for a stream
func (*Context) GetBackend ¶
GetBackend returns the current backend for this context
func (*Context) SetBackend ¶
SetBackend sets the compute backend for this context
func (*Context) Synchronize ¶
func (c *Context) Synchronize()
Synchronize waits for all operations to complete
type DeviceInfo ¶ added in v0.10.1
type DeviceInfo = Device
DeviceInfo is an alias for Device (for compatibility)