memory

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 4 Imported by: 0 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

Index

Constants

View Source
const (
	BackendCPU   = types.BackendCPU
	BackendCUDA  = types.BackendCUDA
	BackendMetal = types.BackendMetal
)

Variables

This section is empty.

Functions

func NewMetalIndexImpl

func NewMetalIndexImpl(cfg types.GPUConfig) (types.Index, error)

NewMetalIndexImpl is a stub for non-Metal platforms

Types

type DoubleBuffer

type DoubleBuffer struct {
	// contains filtered or unexported fields
}

func NewDoubleBuffer

func NewDoubleBuffer(capacity int, opts ...DoubleBufferOption) *DoubleBuffer

NewDoubleBuffer allocates two slabs of the given capacity with optional configuration.

func NewDoubleBufferWithHeadroom

func NewDoubleBufferWithHeadroom(capacity int, memPool *GPUMemPool, minHeadroomBytes int64) (*DoubleBuffer, error)

NewDoubleBufferWithHeadroom allocates two slabs after validating that the GPU memory pool has sufficient headroom.

func (*DoubleBuffer) ActiveSize

func (db *DoubleBuffer) ActiveSize() int

ActiveSize returns the current active size.

func (*DoubleBuffer) Capacity

func (db *DoubleBuffer) Capacity() int

Capacity returns the total capacity of each buffer.

func (*DoubleBuffer) CheckHeadroom

func (db *DoubleBuffer) CheckHeadroom(requiredBytes int64) error

CheckHeadroom validates that the attached GPU memory pool has sufficient headroom for an upcoming operation.

func (*DoubleBuffer) GetActive

func (db *DoubleBuffer) GetActive() []byte

GetActive returns the current active buffer that can be written to by Go CPU code.

func (*DoubleBuffer) GetInactive

func (db *DoubleBuffer) GetInactive() []byte

GetInactive returns the current inactive buffer that is currently being copied or processed on the GPU.

func (*DoubleBuffer) Reset

func (db *DoubleBuffer) Reset()

Reset clears the active size.

func (*DoubleBuffer) Swap

func (db *DoubleBuffer) Swap()

Swap toggles the active and inactive buffers, resetting the active buffer size.

func (*DoubleBuffer) Write

func (db *DoubleBuffer) Write(data []byte) (int, error)

Write appends data to the active buffer.

type DoubleBufferOption

type DoubleBufferOption func(*DoubleBuffer)

DoubleBufferOption defines functional configuration for DoubleBuffer.

func WithMemPool

func WithMemPool(pool *GPUMemPool, minHeadroomBytes int64) DoubleBufferOption

WithMemPool attaches a GPUMemPool to validate device memory headroom.

type GPUBackend

type GPUBackend = types.GPUBackend

Re-export common types from types subpackage for convenience

type GPUMemPool

type GPUMemPool struct {
	// contains filtered or unexported fields
}

func NewGPUMemPool

func NewGPUMemPool(backend types.GPUBackend, deviceID int32) (*GPUMemPool, error)

NewGPUMemPool creates a new GPU memory pool. totalBytes should be set after creation via SetTotalMemory once the device limit is known.

func (*GPUMemPool) AllocateGPU

func (p *GPUMemPool) AllocateGPU(size int64) (unsafe.Pointer, error)

func (*GPUMemPool) Backend

func (p *GPUMemPool) Backend() GPUBackend

func (*GPUMemPool) Close

func (p *GPUMemPool) Close() error

func (*GPUMemPool) DeviceID

func (p *GPUMemPool) DeviceID() int32

func (*GPUMemPool) FreeGPU

func (p *GPUMemPool) FreeGPU(ptr unsafe.Pointer) error

func (*GPUMemPool) GetAvailableMemory

func (p *GPUMemPool) GetAvailableMemory() int64

func (*GPUMemPool) GetTotalMemory

func (p *GPUMemPool) GetTotalMemory() int64

func (*GPUMemPool) GetUsedMemory

func (p *GPUMemPool) GetUsedMemory() int64

func (*GPUMemPool) MemcpyDeviceToDevice

func (p *GPUMemPool) MemcpyDeviceToDevice(dstPtr, srcPtr unsafe.Pointer, size int64) error

func (*GPUMemPool) MemcpyDeviceToHost

func (p *GPUMemPool) MemcpyDeviceToHost(hostPtr, devicePtr unsafe.Pointer, size int64) error

func (*GPUMemPool) MemcpyHostToDevice

func (p *GPUMemPool) MemcpyHostToDevice(devicePtr, hostPtr unsafe.Pointer, size int64) error

func (*GPUMemPool) Memset

func (p *GPUMemPool) Memset(ptr unsafe.Pointer, value int, size int64) error

func (*GPUMemPool) SetTotalMemory

func (p *GPUMemPool) SetTotalMemory(total int64)

SetTotalMemory sets the total memory limit for this pool (from GPUConfig.MaxMemory or device query).

type GPUPager

type GPUPager struct{}

Stub for non-GPU builds. GPU paging is only available on CUDA Linux.

func NewGPUPager

func NewGPUPager(pool *GPUMemPool, maxVRAM, pageSize int64) *GPUPager

func (*GPUPager) Alloc

func (p *GPUPager) Alloc(id PageID) (*PageInfo, error)

func (*GPUPager) Close

func (p *GPUPager) Close() error

func (*GPUPager) GetCPUBuf

func (p *GPUPager) GetCPUBuf(pi *PageInfo) []byte

func (*GPUPager) PageInfo

func (p *GPUPager) PageInfo(id PageID) *PageInfo

func (*GPUPager) Promote

func (p *GPUPager) Promote(pi *PageInfo) error

type MTLBufferPool

type MTLBufferPool struct{}

MTLBufferPool stubs for non-Metal platforms

func GetMTLBufferPool

func GetMTLBufferPool(_ interface{}) *MTLBufferPool

func (*MTLBufferPool) Get

func (p *MTLBufferPool) Get(_ int) interface{}

func (*MTLBufferPool) Put

func (p *MTLBufferPool) Put(_ interface{})

func (*MTLBufferPool) Stats

func (p *MTLBufferPool) Stats() (int64, int64)

type PageID

type PageID uint64

type PageInfo

type PageInfo struct{}

type PooledBuffer

type PooledBuffer struct{}

func NewPooledBuffer

func NewPooledBuffer(_ interface{}, _ int, _ *MTLBufferPool) (*PooledBuffer, error)

func (*PooledBuffer) Buffer

func (pb *PooledBuffer) Buffer() interface{}

func (*PooledBuffer) Release

func (pb *PooledBuffer) Release()

Jump to

Keyboard shortcuts

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