mirror of
https://github.com/luxgpu/gpu.git
synced 2026-10-30 20:46:40 +00:00
Provides Go bindings for GPU-accelerated array operations: - Metal backend for Apple Silicon (M1/M2/M3/M4) - CUDA backend for NVIDIA GPUs - CPU fallback with SIMD optimizations - ONNX Runtime fallback for Windows C++ backend: github.com/luxcpp/gpu (Apple MLX fork)
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
// +build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
"github.com/luxfi/gpu"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("=== GPU Performance Test ===")
|
|
fmt.Printf("System: %s\n", gpu.Info())
|
|
fmt.Println()
|
|
|
|
// Test different sizes
|
|
sizes := []int{100, 500, 1000}
|
|
|
|
for _, size := range sizes {
|
|
fmt.Printf("Matrix Size: %dx%d\n", size, size)
|
|
|
|
// Create matrices
|
|
a := gpu.Random([]int{size, size}, gpu.Float32)
|
|
b := gpu.Random([]int{size, size}, gpu.Float32)
|
|
|
|
// Warmup
|
|
c := gpu.MatMul(a, b)
|
|
gpu.Eval(c)
|
|
gpu.Synchronize()
|
|
|
|
// Benchmark
|
|
iterations := 10
|
|
start := time.Now()
|
|
for i := 0; i < iterations; i++ {
|
|
c = gpu.MatMul(a, b)
|
|
gpu.Eval(c)
|
|
gpu.Synchronize()
|
|
}
|
|
elapsed := time.Since(start)
|
|
|
|
// Calculate metrics
|
|
msPerOp := elapsed.Seconds() * 1000 / float64(iterations)
|
|
ops := int64(size * size * size * 2) // multiply-add operations
|
|
gflops := float64(ops*int64(iterations)) / elapsed.Seconds() / 1e9
|
|
|
|
fmt.Printf(" Time: %.2f ms per operation\n", msPerOp)
|
|
fmt.Printf(" Performance: %.1f GFLOPS\n", gflops)
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println("Metal backend automatically selected for optimal performance on Apple Silicon!")
|
|
} |