gocuda

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gocuda provides a high-performance CUDA + Go concurrency framework for GPU-accelerated computing with intelligent CPU/GPU dispatch and resource management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComputeEngine

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

ComputeEngine provides high-level compute operations

func NewComputeEngine

func NewComputeEngine(engine *Engine) *ComputeEngine

NewComputeEngine creates a new compute engine

func (*ComputeEngine) BatchVectorAdd

func (ce *ComputeEngine) BatchVectorAdd(ctx context.Context, operations []VectorOperation) error

BatchVectorAdd performs batch vector addition operations

func (*ComputeEngine) GetOptimalConfig

func (ce *ComputeEngine) GetOptimalConfig() (*OptimalConfig, error)

GetOptimalConfig returns optimized configuration based on system capabilities

func (*ComputeEngine) MatrixMultiply

func (ce *ComputeEngine) MatrixMultiply(ctx context.Context, a, b []float32, width int) ([]float32, error)

MatrixMultiply performs matrix multiplication

func (*ComputeEngine) VectorAdd

func (ce *ComputeEngine) VectorAdd(ctx context.Context, a, b []float32) ([]float32, error)

VectorAdd performs vector addition with intelligent CPU/GPU dispatch

type Config

type Config struct {
	// Device configuration
	PreferredDevice int   // Preferred CUDA device ID (-1 for auto)
	MaxGPUMemory    int64 // Maximum GPU memory usage in bytes (0 for auto)

	// Performance tuning
	CPUThreshold int // Vector size threshold for CPU vs GPU dispatch
	WorkerCount  int // Number of concurrent workers (0 for auto)
	BatchSize    int // Batch size for operations

	// Memory management
	MemoryPoolSize int64 // Memory pool size in bytes (0 for auto)
	EnableMetrics  bool  // Enable performance metrics collection

	// Logging
	LogLevel  logrus.Level // Log level
	LogOutput string       // Log output file (empty for stdout)

	// Timeouts
	InitTimeout time.Duration // Initialization timeout
	OpTimeout   time.Duration // Operation timeout
}

Config holds configuration for the GoCUDA engine

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

type DeviceInfo

type DeviceInfo struct {
	ID                 int    `json:"id"`
	Name               string `json:"name"`
	MemoryMB           int    `json:"memory_mb"`
	ComputeCapability  string `json:"compute_capability"`
	MultiProcessors    int    `json:"multi_processors"`
	MaxThreadsPerBlock int    `json:"max_threads_per_block"`
	Available          bool   `json:"available"`
}

DeviceInfo represents information about a CUDA device

type DeviceManager

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

DeviceManager manages CUDA devices

func NewDeviceManager

func NewDeviceManager(config *Config, logger *logrus.Logger) (*DeviceManager, error)

NewDeviceManager creates a new device manager

func (*DeviceManager) GetCurrentDevice

func (dm *DeviceManager) GetCurrentDevice() DeviceInfo

GetCurrentDevice returns the currently selected device

func (*DeviceManager) GetDevices

func (dm *DeviceManager) GetDevices() []DeviceInfo

GetDevices returns all available devices

func (*DeviceManager) SetDevice

func (dm *DeviceManager) SetDevice(deviceID int) error

SetDevice sets the current device

func (*DeviceManager) Shutdown

func (dm *DeviceManager) Shutdown() error

Shutdown shuts down the device manager

type Engine

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

Engine represents the main GoCUDA computation engine

func NewEngine

func NewEngine(config *Config) (*Engine, error)

NewEngine creates a new GoCUDA engine with the given configuration

func (*Engine) Context

func (e *Engine) Context() context.Context

Context returns the engine's context

func (*Engine) GetConfig

func (e *Engine) GetConfig() Config

GetConfig returns a copy of the current configuration

func (*Engine) GetDeviceInfo

func (e *Engine) GetDeviceInfo() ([]DeviceInfo, error)

GetDeviceInfo returns information about available CUDA devices

func (*Engine) GetMetrics

func (e *Engine) GetMetrics() (*Metrics, error)

GetMetrics returns performance metrics

func (*Engine) Initialize

func (e *Engine) Initialize() error

Initialize initializes the GoCUDA engine

func (*Engine) IsInitialized

func (e *Engine) IsInitialized() bool

IsInitialized returns true if the engine is initialized

func (*Engine) SetLogLevel

func (e *Engine) SetLogLevel(level logrus.Level)

SetLogLevel changes the log level

func (*Engine) Shutdown

func (e *Engine) Shutdown() error

Shutdown gracefully shuts down the engine

type MemoryManager

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

MemoryManager manages GPU memory allocation and pooling

func NewMemoryManager

func NewMemoryManager(config *Config, logger *logrus.Logger) (*MemoryManager, error)

NewMemoryManager creates a new memory manager

func (*MemoryManager) AllocateMemory

func (mm *MemoryManager) AllocateMemory(size int64) (uintptr, error)

AllocateMemory allocates memory from the pool

func (*MemoryManager) FreeMemory

func (mm *MemoryManager) FreeMemory(ptr uintptr) error

FreeMemory returns memory to the pool

func (*MemoryManager) GetStats

func (mm *MemoryManager) GetStats() (int64, int64)

GetStats returns memory usage statistics

func (*MemoryManager) Shutdown

func (mm *MemoryManager) Shutdown() error

Shutdown shuts down the memory manager

type MemoryPool

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

MemoryPool represents a memory pool for a specific device

type Metrics

type Metrics struct {
	TotalOperations    int64         `json:"total_operations"`
	SuccessfulOps      int64         `json:"successful_operations"`
	FailedOps          int64         `json:"failed_operations"`
	AvgExecutionTime   time.Duration `json:"avg_execution_time"`
	TotalExecutionTime time.Duration `json:"total_execution_time"`
	GPUUtilization     float64       `json:"gpu_utilization"`
	MemoryUsage        int64         `json:"memory_usage"`
	MemoryTotal        int64         `json:"memory_total"`
	LastUpdated        time.Time     `json:"last_updated"`
}

Metrics contains performance metrics

type MetricsCollector

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

MetricsCollector collects and aggregates performance metrics

func NewMetricsCollector

func NewMetricsCollector(logger *logrus.Logger) *MetricsCollector

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) GetMetrics

func (mc *MetricsCollector) GetMetrics() *Metrics

GetMetrics returns current metrics

func (*MetricsCollector) RecordOperation

func (mc *MetricsCollector) RecordOperation(opType string, duration time.Duration, success bool, err error)

RecordOperation records an operation metric

func (*MetricsCollector) Shutdown

func (mc *MetricsCollector) Shutdown()

Shutdown shuts down the metrics collector

func (*MetricsCollector) UpdateGPUUtilization

func (mc *MetricsCollector) UpdateGPUUtilization(utilization float64)

UpdateGPUUtilization updates GPU utilization metrics

func (*MetricsCollector) UpdateMemoryUsage

func (mc *MetricsCollector) UpdateMemoryUsage(used, total int64)

UpdateMemoryUsage updates memory usage metrics

type OperationMetric

type OperationMetric struct {
	Type      string
	StartTime time.Time
	Duration  time.Duration
	Success   bool
	Error     error
}

OperationMetric represents metrics for a single operation

type OptimalConfig

type OptimalConfig struct {
	CPUThreshold   int   `json:"cpu_threshold"`
	OptimalWorkers int   `json:"optimal_workers"`
	BatchSize      int   `json:"batch_size"`
	MemoryPoolSize int64 `json:"memory_pool_size"`
}

OptimalConfig contains optimized configuration parameters

type VectorOperation

type VectorOperation struct {
	A      []float32
	B      []float32
	Result []float32
}

VectorOperation represents a vector operation

Jump to

Keyboard shortcuts

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