{"id":47668980,"url":"https://github.com/zerfoo/ztensor","last_synced_at":"2026-06-17T01:00:46.697Z","repository":{"id":344714516,"uuid":"1182817985","full_name":"zerfoo/ztensor","owner":"zerfoo","description":"GPU-accelerated tensor, compute engine, and computation graph library for Go. CUDA/ROCm/OpenCL backends via purego — zero CGo required.","archived":false,"fork":false,"pushed_at":"2026-06-16T07:42:24.000Z","size":1703,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-16T07:48:47.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zerfoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-16T01:39:01.000Z","updated_at":"2026-06-16T06:32:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"9f24b01a-b83c-4b85-9a8f-c316c7436d99","html_url":"https://github.com/zerfoo/ztensor","commit_stats":null,"previous_names":["zerfoo/ztensor"],"tags_count":54,"template":false,"template_full_name":null,"purl":"pkg:github/zerfoo/ztensor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerfoo%2Fztensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerfoo%2Fztensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerfoo%2Fztensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerfoo%2Fztensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zerfoo","download_url":"https://codeload.github.com/zerfoo/ztensor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerfoo%2Fztensor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34429493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-02T12:18:15.700Z","updated_at":"2026-06-17T01:00:46.688Z","avatar_url":"https://github.com/zerfoo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ztensor\n\n[![CI](https://github.com/zerfoo/ztensor/actions/workflows/ci.yml/badge.svg)](https://github.com/zerfoo/ztensor/actions/workflows/ci.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/zerfoo/ztensor.svg)](https://pkg.go.dev/github.com/zerfoo/ztensor)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nGPU-accelerated tensor, compute engine, and computation graph library for Go. Zero CGo.\n\nPart of the [Zerfoo](https://github.com/zerfoo) ML ecosystem.\n\n## Features\n\n- **Multi-type tensors** with compile-time type safety via Go generics (`float32`, `float64`, `float16`, `bfloat16`, `float8`, integer types)\n- **GPU backends** — CUDA (cuBLAS, cuDNN, TensorRT, custom kernels), ROCm (HIP, rocBLAS, MIOpen), and OpenCL (CLBlast), all loaded dynamically via purego (zero CGo)\n- **Computation graphs** with fusion passes and CUDA graph capture for optimized inference\n- **CPU SIMD** — ARM NEON and x86 AVX2 hand-written assembly for GEMM, RMSNorm, RoPE, SiLU, softmax\n- **Memory management** — arena-based GPU memory pools with O(1) per-pass reclamation\n- **Quantized storage** — FP8 E4M3/E5M2, FP16, BFloat16 tensor storage with automatic dequantization\n\n## Installation\n\n```bash\ngo get github.com/zerfoo/ztensor\n```\n\nNo CGo required. GPU backends are discovered and loaded at runtime via `dlopen`/purego.\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n\n    \"github.com/zerfoo/ztensor/compute\"\n    \"github.com/zerfoo/ztensor/numeric\"\n    \"github.com/zerfoo/ztensor/tensor\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    // Create a CPU compute engine for float32\n    eng := compute.NewCPUEngine[float32](numeric.Float32Ops{})\n\n    // Create two tensors\n    a, _ := tensor.New[float32]([]int{2, 3}, []float32{1, 2, 3, 4, 5, 6})\n    b, _ := tensor.New[float32]([]int{3, 2}, []float32{1, 2, 3, 4, 5, 6})\n\n    // Matrix multiplication\n    c, _ := eng.MatMul(ctx, a, b)\n    fmt.Println(c.Shape()) // [2, 2]\n    fmt.Println(c.Data())  // [22 28 49 64]\n\n    // Element-wise operations\n    x, _ := tensor.New[float32]([]int{2, 2}, []float32{1, 2, 3, 4})\n    y, _ := tensor.New[float32]([]int{2, 2}, []float32{5, 6, 7, 8})\n    sum, _ := eng.Add(ctx, x, y)\n    fmt.Println(sum.Data()) // [6 8 10 12]\n}\n```\n\n## GPU Backend Example\n\nGPU libraries are loaded at runtime via purego — no CGo, no build tags, no linking. If CUDA/ROCm/OpenCL is not available, the engine constructor returns an error and you fall back to CPU.\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n\n    \"github.com/zerfoo/ztensor/compute\"\n    \"github.com/zerfoo/ztensor/numeric\"\n    \"github.com/zerfoo/ztensor/tensor\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    // Try CUDA first, fall back to CPU\n    eng, err := compute.NewGPUEngine[float32](numeric.Float32Ops{})\n    if err != nil {\n        fmt.Println(\"CUDA not available, using CPU:\", err)\n        cpuEng := compute.NewCPUEngine[float32](numeric.Float32Ops{})\n        run(ctx, cpuEng)\n        return\n    }\n    run(ctx, eng)\n}\n\nfunc run(ctx context.Context, eng compute.Engine[float32]) {\n    a, _ := tensor.New[float32]([]int{2, 3}, []float32{1, 2, 3, 4, 5, 6})\n    b, _ := tensor.New[float32]([]int{3, 2}, []float32{1, 2, 3, 4, 5, 6})\n    c, _ := eng.MatMul(ctx, a, b)\n    fmt.Println(c.Data()) // [22 28 49 64]\n}\n```\n\nOther GPU backends follow the same pattern:\n\n```go\n// ROCm (AMD GPUs)\neng, err := compute.NewROCmEngine[float32](numeric.Float32Ops{})\n\n// OpenCL (cross-vendor)\neng, err := compute.NewOpenCLEngine[float32](numeric.Float32Ops{})\n```\n\n## Type Safety with Generics\n\nThe `tensor.Numeric` type constraint ensures compile-time type safety across all supported numeric types:\n\n```go\n// Works with any Numeric type\nfunc dotProduct[T tensor.Numeric](eng compute.Engine[T], a, b *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error) {\n    return eng.MatMul(context.Background(), a, b)\n}\n```\n\nSupported types include `float32`, `float64`, `float16.Float16`, `float16.BFloat16`, `float8.Float8`, and all Go integer types.\n\n## Use Cases\n\n- **ML inference engines** — ztensor powers the [zerfoo](https://github.com/zerfoo/zerfoo) inference runtime for transformer models\n- **Scientific computing** — GPU-accelerated linear algebra with automatic backend selection\n- **GPU compute from Go** — use CUDA/ROCm/OpenCL from pure Go without CGo or build tags\n- **Custom ML operators** — build neural network layers on top of the `compute.Engine` interface\n\n## Package Overview\n\n| Package | Description |\n|---------|-------------|\n| `tensor/` | Multi-type tensor storage — CPU, GPU, quantized (FP8, FP16, BFloat16) |\n| `compute/` | Compute engine interface with CPU, CUDA, ROCm, and OpenCL implementations |\n| `graph/` | Computation graph compiler with operator fusion and CUDA graph capture |\n| `numeric/` | Type-safe `Arithmetic[T]` interface for all numeric types |\n| `device/` | Device abstraction and memory allocators |\n| `types/` | Shared type definitions |\n| `log/` | Structured logging interface |\n| `metrics/` | Performance metrics and profiling |\n| `internal/cuda/` | Zero-CGo CUDA runtime bindings via purego, 25+ custom kernels |\n| `internal/xblas/` | ARM NEON and x86 AVX2 SIMD assembly (GEMM, RMSNorm, RoPE, SiLU, softmax) |\n| `internal/gpuapi/` | GPU Runtime Abstraction Layer — unified adapter for CUDA, ROCm, OpenCL |\n| `internal/codegen/` | Megakernel code generator |\n\n## Dependencies\n\nztensor depends on:\n\n- [float16](https://github.com/zerfoo/float16) — IEEE 754 half-precision and BFloat16 arithmetic\n- [float8](https://github.com/zerfoo/float8) — FP8 E4M3FN arithmetic for quantized inference\n\nztensor is used by:\n\n- [zerfoo](https://github.com/zerfoo/zerfoo) — ML inference, training, and serving framework\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerfoo%2Fztensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzerfoo%2Fztensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerfoo%2Fztensor/lists"}