cpu

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cpu provides a pure Go CPU backend for tensor operations.

Overview

This package implements a CPU backend with:

  • Pure Go implementation (no CGO)
  • Im2col algorithm for efficient convolutions
  • Float32 and Float64 support
  • Batch processing
  • NumPy-compatible broadcasting

Basic Usage

import (
    "github.com/born-ml/born/backend/cpu"
    "github.com/born-ml/born/tensor"
    "github.com/born-ml/born/nn"
)

func main() {
    // Create CPU backend
    backend := cpu.New()

    // Use with tensors
    x := tensor.Zeros[float32](tensor.Shape{2, 3}, backend)
    y := tensor.Ones[float32](tensor.Shape{2, 3}, backend)
    z := x.Add(y)

    // Use with neural networks
    model := nn.NewLinear(784, 10, backend)
}

Performance

The CPU backend is optimized for training on CPUs:

  • Efficient matrix multiplication
  • Im2col-based convolutions
  • SIMD optimizations (where available)

For GPU acceleration, see the cuda package (planned for v0.3.0).

Thread Safety

The CPU backend is safe for concurrent use. Each tensor operation is isolated and does not share mutable state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend = internalcpu.CPUBackend

Backend represents the CPU backend implementation.

CPU backend provides pure Go implementations of all tensor operations with SIMD optimizations where available.

func New

func New() *Backend

New creates a new CPU backend.

Example:

import (
    "github.com/born-ml/born/backend/cpu"
    "github.com/born-ml/born/tensor"
)

func main() {
    backend := cpu.New()
    x := tensor.Zeros[float32](tensor.Shape{2, 3}, backend)
}

Jump to

Keyboard shortcuts

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