cpu

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 2 Imported by: ? 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 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