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 ¶
- type ComputeEngine
- func (ce *ComputeEngine) BatchVectorAdd(ctx context.Context, operations []VectorOperation) error
- func (ce *ComputeEngine) GetOptimalConfig() (*OptimalConfig, error)
- func (ce *ComputeEngine) MatrixMultiply(ctx context.Context, a, b []float32, width int) ([]float32, error)
- func (ce *ComputeEngine) VectorAdd(ctx context.Context, a, b []float32) ([]float32, error)
- type Config
- type DeviceInfo
- type DeviceManager
- type Engine
- func (e *Engine) Context() context.Context
- func (e *Engine) GetConfig() Config
- func (e *Engine) GetDeviceInfo() ([]DeviceInfo, error)
- func (e *Engine) GetMetrics() (*Metrics, error)
- func (e *Engine) Initialize() error
- func (e *Engine) IsInitialized() bool
- func (e *Engine) SetLogLevel(level logrus.Level)
- func (e *Engine) Shutdown() error
- type MemoryManager
- type MemoryPool
- type Metrics
- type MetricsCollector
- func (mc *MetricsCollector) GetMetrics() *Metrics
- func (mc *MetricsCollector) RecordOperation(opType string, duration time.Duration, success bool, err error)
- func (mc *MetricsCollector) Shutdown()
- func (mc *MetricsCollector) UpdateGPUUtilization(utilization float64)
- func (mc *MetricsCollector) UpdateMemoryUsage(used, total int64)
- type OperationMetric
- type OptimalConfig
- type VectorOperation
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
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
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 (*Engine) GetDeviceInfo ¶
func (e *Engine) GetDeviceInfo() ([]DeviceInfo, error)
GetDeviceInfo returns information about available CUDA devices
func (*Engine) GetMetrics ¶
GetMetrics returns performance metrics
func (*Engine) Initialize ¶
Initialize initializes the GoCUDA engine
func (*Engine) IsInitialized ¶
IsInitialized returns true if the engine is initialized
func (*Engine) SetLogLevel ¶
SetLogLevel changes the log level
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 ¶
VectorOperation represents a vector operation