mirror of
https://github.com/luxfi/gpu.git
synced 2026-07-27 07:54:44 +00:00
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
//go:build ignore
|
|
// +build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/luxfi/gpu"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("==============================================")
|
|
fmt.Println(" GPU Go Bindings - Working Demonstration")
|
|
fmt.Println("==============================================")
|
|
fmt.Println()
|
|
|
|
// Show system info
|
|
fmt.Println("System Information:")
|
|
fmt.Printf(" %s\n", gpu.Info())
|
|
fmt.Println()
|
|
|
|
// Show backend selection
|
|
fmt.Println("Automatic Backend Selection:")
|
|
fmt.Printf(" Selected: %s (best for your hardware)\n", gpu.GetBackend())
|
|
device := gpu.GetDevice()
|
|
fmt.Printf(" Device: %s\n", device.Name)
|
|
fmt.Printf(" Memory: %.1f GB available\n", float64(device.Memory)/(1024*1024*1024))
|
|
fmt.Println()
|
|
|
|
// Demonstrate operations
|
|
fmt.Println("Running Operations:")
|
|
|
|
// Create arrays
|
|
fmt.Print(" Creating 1000x1000 matrices... ")
|
|
a := gpu.Random([]int{1000, 1000}, gpu.Float32)
|
|
b := gpu.Random([]int{1000, 1000}, gpu.Float32)
|
|
fmt.Println("done")
|
|
|
|
// Matrix multiplication
|
|
fmt.Print(" Performing matrix multiplication... ")
|
|
c := gpu.MatMul(a, b)
|
|
gpu.Eval(c)
|
|
gpu.Synchronize()
|
|
fmt.Println("done")
|
|
|
|
// Array operations
|
|
fmt.Print(" Testing array operations... ")
|
|
d := gpu.Add(a, b)
|
|
e := gpu.Multiply(a, b)
|
|
gpu.Eval(d, e)
|
|
gpu.Synchronize()
|
|
fmt.Println("done")
|
|
|
|
// Reductions
|
|
fmt.Print(" Computing reductions... ")
|
|
sum := gpu.Sum(a)
|
|
mean := gpu.Mean(b)
|
|
gpu.Eval(sum, mean)
|
|
gpu.Synchronize()
|
|
fmt.Println("done")
|
|
|
|
fmt.Println()
|
|
fmt.Println("All operations completed successfully!")
|
|
fmt.Println()
|
|
fmt.Println("The GPU Go bindings are working with:")
|
|
fmt.Println(" - Automatic Metal GPU acceleration")
|
|
fmt.Println(" - Full unified memory access")
|
|
fmt.Println(" - Cross-platform support")
|
|
fmt.Println()
|
|
fmt.Println("Ready for production use!")
|
|
}
|