package main
import (
"context"
"fmt"
"log"
"time"
"github.com/visent/go-sdk"
)
type BenchmarkSuite struct {
client *visent.Client
}
func NewBenchmarkSuite(apiKey string) *BenchmarkSuite {
return &BenchmarkSuite{
client: visent.NewClient(visent.Config{
APIKey: apiKey,
}),
}
}
func (bs *BenchmarkSuite) RunComparisonBenchmark(ctx context.Context) error {
gpus := []string{"h100", "a100", "v100"}
models := []string{"resnet50", "bert-large", "gpt-3"}
results := make(map[string]map[string]*visent.BenchmarkResult)
for _, gpu := range gpus {
results[gpu] = make(map[string]*visent.BenchmarkResult)
for _, model := range models {
fmt.Printf("Running benchmark: %s on %s\n", model, gpu)
// Start benchmark
benchmark, err := bs.client.Forge.StartBenchmark(ctx, &visent.BenchmarkRequest{
Type: "ml-training",
GPU: gpu,
Config: map[string]interface{}{
"model": model,
"batch_size": 32,
"iterations": 100,
},
})
if err != nil {
log.Printf("Failed to start benchmark %s/%s: %v", gpu, model, err)
continue
}
// Wait for completion
result, err := bs.client.Forge.WaitForCompletion(ctx, benchmark.JobID, visent.WaitOptions{
PollInterval: 30 * time.Second,
Timeout: time.Hour,
})
if err != nil {
log.Printf("Benchmark %s/%s failed: %v", gpu, model, err)
continue
}
results[gpu][model] = result
fmt.Printf("Completed: %s/%s - Throughput: %.1f ops/sec\n",
gpu, model, result.Metrics.Throughput)
}
}
// Generate comparison report
bs.generateReport(results)
return nil
}
func (bs *BenchmarkSuite) generateReport(results map[string]map[string]*visent.BenchmarkResult) {
fmt.Println("\n=== Benchmark Comparison Report ===")
fmt.Printf("%-10s %-15s %-15s %-10s\n", "GPU", "Model", "Throughput", "Latency")
fmt.Println(strings.Repeat("-", 55))
for gpu, modelResults := range results {
for model, result := range modelResults {
if result != nil {
fmt.Printf("%-10s %-15s %-15.1f %-10.1f\n",
gpu, model, result.Metrics.Throughput, result.Metrics.Latency)
}
}
}
}
func main() {
suite := NewBenchmarkSuite(os.Getenv("VISENT_API_KEY"))
ctx := context.Background()
if err := suite.RunComparisonBenchmark(ctx); err != nil {
log.Fatal(err)
}
}