platform

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 2 Imported by: 40

Documentation

Overview

Package platform defines the interface for a GX

A GX platform manages a host and its associated devices, also providing the means to exchange data among them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostTransfer

func HostTransfer(dstB, srcB HostBuffer) error

HostTransfer transfers data from a source host buffer to another.

Types

type Allocator

type Allocator interface {
	Allocate(*shape.Shape) (HostBuffer, error)
}

Allocator allocates memory on the host.

type Device

type Device interface {
	// Platform returns the host and its devices owning this device.
	Platform() Platform

	// Send raw data to the device.
	Send(buf []byte, sh *shape.Shape) (DeviceHandle, error)

	// Ordinal of the device on the platform.
	Ordinal() int
}

Device running GX code.

type DeviceHandle

type DeviceHandle interface {
	Handle

	// Device on which the array is located.
	Device() Device
}

DeviceHandle is an array located on a device.

type Handle

type Handle interface {
	// Shape of the underlying array.
	Shape() *shape.Shape

	// ToDevice transfers the handle to a device.
	ToDevice(Device) (DeviceHandle, error)

	// ToHost fetches the data from the handle and write it to buffer.
	ToHost(buffer HostBuffer) error
}

Handle to an array managed by the platform.

type HostBuffer

type HostBuffer interface {
	Handle
	// Acquire locks the buffer and returns it.
	// The buffer can be read or written by the caller. All other access is locked.
	// Returns nil if the handle has been freed.
	Acquire() []byte
	// Release the buffer. The caller of that function should not read or write data
	// from the buffer.
	Release()
	// Free the memory occupied by the buffer. The handle is invalid after calling this function.
	Free()
}

HostBuffer is a handle to a buffer of data located locally on the platform, typically in CPU memory, and shared between a platform and its users.

The data needs to be acquired before being written or read. All access to the data is blocked until that is released.

type Platform

type Platform interface {
	// Name of the platform.
	Name() string

	// Device returns the device managed by the backend.
	Device(int) (Device, error)
}

Platform is a host orchestrating one or more devices.

Jump to

Keyboard shortcuts

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