Add README.md documentation for: - Main SDK overview with quick start guides - JavaScript/TypeScript SDK - Python SDK - Go SDK - Rust SDK - Java SDK - Kotlin SDK - Swift SDK - Flutter/Dart SDK - C SDK - C++ SDK - C#/.NET SDK - Ruby SDK Each README includes: - Installation instructions - Quick start examples - Tensor operations - Matrix operations (matmul, conv2d, attention) - LLM inference (single and streaming) - Configuration options - Error handling - Type definitions
174 lines
3.3 KiB
Markdown
174 lines
3.3 KiB
Markdown
# Synor Compute SDK for Go
|
|
|
|
Access distributed heterogeneous compute at 90% cost reduction.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
go get github.com/synor/compute-sdk-go
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
synor "github.com/synor/compute-sdk-go"
|
|
)
|
|
|
|
func main() {
|
|
client := synor.NewClient("your-api-key")
|
|
|
|
// Create tensors
|
|
a := synor.NewTensor(data, []int{512, 512}, synor.FP32)
|
|
b := synor.Zeros([]int{512, 512}, synor.FP32)
|
|
|
|
// Matrix multiplication
|
|
ctx := context.Background()
|
|
result, err := client.MatMul(ctx, a, b,
|
|
synor.WithPrecision(synor.FP16),
|
|
synor.WithProcessor(synor.GPU),
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
fmt.Printf("Execution time: %.2fms\n", result.Metrics.ExecutionTimeMs)
|
|
}
|
|
```
|
|
|
|
## Configuration
|
|
|
|
```go
|
|
config := synor.Config{
|
|
APIKey: "your-api-key",
|
|
Endpoint: "https://api.synor.io/compute/v1",
|
|
Strategy: synor.Balanced,
|
|
Precision: synor.FP16,
|
|
Timeout: 30 * time.Second,
|
|
}
|
|
|
|
client := synor.NewClientWithConfig(config)
|
|
```
|
|
|
|
## Tensor Operations
|
|
|
|
```go
|
|
// Create tensors
|
|
zeros := synor.Zeros([]int{3, 3}, synor.FP32)
|
|
ones := synor.Ones([]int{2, 2}, synor.FP32)
|
|
|
|
// From slice
|
|
data := []float32{1, 2, 3, 4, 5, 6}
|
|
tensor := synor.NewTensor(data, []int{2, 3}, synor.FP32)
|
|
|
|
// Serialize for API
|
|
serialized := tensor.Serialize()
|
|
```
|
|
|
|
## Matrix Operations
|
|
|
|
```go
|
|
// Matrix multiplication
|
|
result, err := client.MatMul(ctx, a, b,
|
|
synor.WithPrecision(synor.FP16),
|
|
synor.WithProcessor(synor.GPU),
|
|
synor.WithStrategy(synor.Speed),
|
|
)
|
|
|
|
// 2D Convolution
|
|
conv, err := client.Conv2D(ctx, input, kernel,
|
|
synor.WithStride(1, 1),
|
|
synor.WithPadding(1, 1),
|
|
)
|
|
|
|
// Attention
|
|
attention, err := client.Attention(ctx, query, key, value,
|
|
synor.WithNumHeads(8),
|
|
synor.WithFlash(true),
|
|
)
|
|
```
|
|
|
|
## LLM Inference
|
|
|
|
```go
|
|
// Single response
|
|
response, err := client.Inference(ctx, "llama-3-70b", "Explain quantum computing",
|
|
synor.WithMaxTokens(512),
|
|
synor.WithTemperature(0.7),
|
|
)
|
|
fmt.Println(response.Result)
|
|
|
|
// Streaming (using channel)
|
|
stream, err := client.InferenceStream(ctx, "llama-3-70b", "Write a poem")
|
|
for chunk := range stream {
|
|
fmt.Print(chunk)
|
|
}
|
|
```
|
|
|
|
## Job Management
|
|
|
|
```go
|
|
// Submit async job
|
|
job, err := client.SubmitJob(ctx, "matmul", map[string]interface{}{
|
|
"a": a.Serialize(),
|
|
"b": b.Serialize(),
|
|
})
|
|
|
|
// Get status
|
|
status, err := client.GetJobStatus(ctx, job.ID)
|
|
|
|
// Cancel
|
|
err = client.CancelJob(ctx, job.ID)
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
```go
|
|
result, err := client.MatMul(ctx, a, b)
|
|
if err != nil {
|
|
if synorErr, ok := err.(*synor.SynorError); ok {
|
|
fmt.Printf("API Error: %s (status: %d)\n",
|
|
synorErr.Message, synorErr.StatusCode)
|
|
}
|
|
}
|
|
```
|
|
|
|
## Processor Types
|
|
|
|
```go
|
|
synor.CPU // General-purpose CPU
|
|
synor.GPU // NVIDIA/AMD GPU
|
|
synor.TPU // Google TPU
|
|
synor.NPU // Neural Processing Unit
|
|
synor.LPU // Language Processing Unit
|
|
synor.FPGA // Field-Programmable Gate Array
|
|
synor.WASM // WebAssembly runtime
|
|
synor.WebGPU // Browser GPU
|
|
```
|
|
|
|
## Precision Levels
|
|
|
|
```go
|
|
synor.FP64 // 64-bit float
|
|
synor.FP32 // 32-bit float (default)
|
|
synor.FP16 // 16-bit float
|
|
synor.BF16 // Brain float 16
|
|
synor.INT8 // 8-bit integer
|
|
synor.INT4 // 4-bit integer
|
|
```
|
|
|
|
## Testing
|
|
|
|
```bash
|
|
go test ./...
|
|
```
|
|
|
|
## License
|
|
|
|
MIT
|