{"id":47935027,"url":"https://github.com/fumiama/gozel","last_synced_at":"2026-04-04T07:39:54.681Z","repository":{"id":346843729,"uuid":"1178010314","full_name":"fumiama/gozel","owner":"fumiama","description":"Pure-Go GPU/NPU compute wrapper for Intel NEO driver Level Zero APIs.","archived":false,"fork":false,"pushed_at":"2026-03-29T10:52:09.000Z","size":926,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T07:39:51.427Z","etag":null,"topics":["dpcpp","golang","golang-examples","golang-library","gpgpu","gpgpu-computing","gpu","gpu-acceleration","gpu-computing","gpu-programming","intel","intel-gpu","level-zero","level-zero-loader","llvm","llvm-ir","oneapi","opencl","spirv","sycl"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fumiama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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-10T15:43:02.000Z","updated_at":"2026-03-30T02:32:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fumiama/gozel","commit_stats":null,"previous_names":["fumiama/gozel"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fumiama/gozel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgozel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgozel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgozel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgozel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fumiama","download_url":"https://codeload.github.com/fumiama/gozel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgozel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31392186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dpcpp","golang","golang-examples","golang-library","gpgpu","gpgpu-computing","gpu","gpu-acceleration","gpu-computing","gpu-programming","intel","intel-gpu","level-zero","level-zero-loader","llvm","llvm-ir","oneapi","opencl","spirv","sycl"],"created_at":"2026-04-04T07:39:53.624Z","updated_at":"2026-04-04T07:39:54.658Z","avatar_url":"https://github.com/fumiama.png","language":"Go","readme":"# GoZeL\n\n[![CI](https://github.com/fumiama/gozel/actions/workflows/ci.yml/badge.svg)](https://github.com/fumiama/gozel/actions/workflows/ci.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/fumiama/gozel.svg)](https://pkg.go.dev/github.com/fumiama/gozel)\n[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)\n\n**gozel** is a pure-Go binding for the [Intel oneAPI Level Zero](https://github.com/oneapi-src/level-zero) API — enabling direct GPU/NPU compute from Go **without cgo**.\n\nBuilt on [purego](https://github.com/ebitengine/purego) and Windows syscall, gozel loads `ze_loader` at runtime via FFI, avoiding all C compiler dependencies. The entire API surface is auto-generated from the official Level Zero SDK headers, keeping bindings always in sync with upstream.\n\n| Before Scaling (1272 x 855) | After Scaling (512 x 344) |\n|:--:|:--:|\n|![暖笺贺春.webp](examples/image_scale/暖笺贺春.webp)|![small.png](examples/image_scale/small.png)|\n\n---\n\n## Table of Contents\n\n- [Projects Using gozel](#projects-using-gozel)\n- [Features](#features)\n- [Platform Support](#platform-support)\n- [Quick Start](#quick-start)\n- [The `ze` Package — High-Level API](#the-ze-package--high-level-api)\n- [Contributing](#contributing)\n- [License](#license)\n- [Appendix I. Architecture](#appendix-i-architecture)\n- [Appendix II. Regenerating Bindings from Headers](#appendix-ii-regenerating-bindings-from-headers)\n- [Appendix III. Building SPIR-V Kernels](#appendix-iii-building-spir-v-kernels)\n\n---\n\n## Projects Using gozel\n\nWe maintain a list of projects built with gozel. If your project uses this library, please open a PR to add it here!\n\n| Project | Description | Link |\n|---|---|---|\n| | | |\n\n## Features\n\n- **No cgo** — Pure Go via [purego](https://github.com/ebitengine/purego) and Windows syscall. No C toolchain required at build time.\n- **Auto-generated** — All 200+ Level Zero functions generated directly from the [official C headers](https://github.com/oneapi-src/level-zero/tree/master/include), covering Core, Sysman, Tools and Runtime APIs.\n- **High-level wrapper** — The `ze` sub-package provides an idiomatic Go API over the raw bindings: typed handles, error returns, automatic resource lifetime.\n- **Kernel in Go** — Embed SPIR-V binaries with `//go:embed`, load and launch GPU kernels entirely from Go.\n- **Extensible** — Add new examples, wrap more APIs, or plug in your own SPIR-V pipelines.\n\n## Platform Support\n\u003e gozel targets all Intel GPUs including Intel Arc / Iris Xe / Data Center GPUs that ship a Level Zero driver. Any device visible to `ze_loader` should work.\n\n| OS | Architecture | Runtime Requirement |\n|---|---|---|\n| Windows | amd64 | [Intel GPU driver](https://www.intel.com/content/www/us/en/download/785597/intel-arc-iris-xe-graphics-windows.html) with `ze_loader.dll` |\n| Linux | amd64 | [Intel compute-runtime](https://github.com/intel/compute-runtime) with `libze_loader.so` |\n| More | under | testing... |\n\n## Quick Start\n\n### Install\n\n```bash\ngo get github.com/fumiama/gozel\n```\n\n### Minimal Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/fumiama/gozel/ze\"\n)\n\nfunc main() {\n\tgpus, err := ze.InitGPUDrivers()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"Found %d GPU driver(s)\\n\", len(gpus))\n\n\tdevs, _ := gpus[0].DeviceGet()\n\tfor _, d := range devs {\n\t\tprop, _ := d.DeviceGetProperties()\n\t\tfmt.Printf(\"  Device: %s\\n\", string(prop.Name[:]))\n\t}\n\n\t// Found 1 GPU driver(s)\n\t//   Device:  Graphics\n}\n```\n\n### Vector-Add\n\nThis example adds up two large float32 vectors.\n\n```bash\ncd examples/vadd\n# go generate          # Optional, requires SYCL toolchain (see below)\ngo run main.go\n```\n\nYou will see the result like\n\n```bash\n===============  Device Basic Properties  ===============\nRunning on device: ID = 1 , Name = Graphics @ 4.00 GHz.\n=============== Device Compute Properties ===============\nMax Group Size (X, Y, Z):    (1024, 1024, 1024)\nMax Group Count (X, Y, Z):   (4294967295, 4294967295, 4294967295)\nMax Total Group Size:        1024\nMax Shared Local Memory:     65536\nNum Subgroup Sizes:          3\nSubgroup Sizes:              [8 16 32 0 0 0 0 0]\n=============== Computation Configuration ===============\nGroup Size (X, Y, Z):        (1024, 1, 1)\nGroup Count:                 65536\nTotal Elements (N):          67108864\nBuffer Size:                 256 MiB\n===============    Calculation Results    ===============\nGPU Execution Time:          56.114500 ms\nGPU Throughput:              4.78 GiB/s\n===============    Validation Results    ===============\nCPU Execution Time:          77.190700 ms\nCPU Throughput:              3.48 GiB/s\nTest Passed!!!\n```\n\n### More Examples\n\n| Example | Description | Source |\n|---|---|---|\n| **vadd** | Vector addition | [examples/vadd](examples/vadd/) |\n| **vadd_event** | Vector addition with event | [examples/vadd_event](examples/vadd_event/) |\n| **image_scale** | Scale image using hardware sampler | [examples/image_scale](examples/image_scale/) |\n\n## The `ze` Package — High-Level API\n\nAll examples used `ze` sub-package, which wraps the raw Level Zero bindings into idiomatic Go with typed handles and method chains:\n\n```go\n// Initialize\ngpus, _ := ze.InitGPUDrivers()\n\n// Context + Device\nctx, _ := gpus[0].ContextCreate()\ndevs, _ := gpus[0].DeviceGet()\n\n// Memory\nhostBuf, _ := ctx.MemAllocHost(size, alignment)\ndevBuf, _ := ctx.MemAllocDevice(devs[0], size, alignment)\ndefer ctx.MemFree(hostBuf)\ndefer ctx.MemFree(devBuf)\n\n// Module + Kernel\nmod, _ := ctx.ModuleCreate(devs[0], spirvBytes)\nkrn, _ := mod.KernelCreate(\"my_kernel\")\nkrn.SetArgumentValue(0, unsafe.Sizeof(uintptr(0)), unsafe.Pointer(\u0026devBuf))\nkrn.SetGroupSize(256, 1, 1)\n\n// Command submission\nq, _ := ctx.CommandQueueCreate(devs[0])\ncl, _ := ctx.CommandListCreate(devs[0])\ncl.AppendMemoryCopy(devBuf, hostBuf, size)\ncl.AppendBarrier()\ncl.AppendLaunchKernel(krn, \u0026gozel.ZeGroupCount{Groupcountx: 4, Groupcounty: 1, Groupcountz: 1})\ncl.AppendBarrier()\ncl.Close()\nq.ExecuteCommandLists(cl)\nq.Synchronize()\n```\n\nCompared to the raw `gozel.ZeCommandListCreate(...)` calls, the `ze` package:\n\n- Eliminates boilerplate descriptor initialization (struct types, `Stype` fields)\n- Returns Go `error` instead of `ZeResult` codes\n- Provides method syntax on handles (`ctx.CommandListCreate(dev)` vs standalone functions)\n- Manages handle lifetimes with `defer`-friendly `Destroy()` methods\n\nThe `ze` package currently covers the most common workflows. **Contributions to expand coverage are very welcome** — see [Contributing](#contributing).\n\n\n\n\u003e 🙌 **Have an example to share?** We'd love to grow this table — see [Contributing](#contributing).\n\n## Contributing\n\nContributions of all kinds are welcome. Some particularly impactful areas:\n\n- **Examples** — Add new `examples/` demonstrating different GPU compute patterns (matrix multiply, reduction, image processing, etc.). Every example helps new users get started faster.\n- **`ze` package coverage** — The high-level wrapper doesn't cover the full Level Zero surface yet. Wrapping additional APIs (events, fences, images, sysman queries, etc.) directly benefits all downstream users.\n- **Testing** — Help improve test coverage across packages.\n- **Documentation** — Improve godoc comments, add usage guides, or translate documentation.\n- **Project showcase** — If you use gozel in your project, open a PR to add it to the [Projects Using gozel](#projects-using-gozel) table above.\n\n## License\n\n- This project is generally licensed under the [GNU Affero General Public License v3.0](LICENSE).\n- The files in [gozel](gozel) folder follows their original license, which is [MIT](https://github.com/oneapi-src/level-zero/blob/master/LICENSE).\n\n---\n\n## Appendix I. Architecture\n\nThe FFI layer (`internal/zecall`) loads the Level Zero loader library at runtime, caches procedure addresses, and dispatches calls through `purego` or Windows syscall. All pointer arguments are protected against GC collection during syscalls via `go:uintptrescapes`.\n\n```\ngozel/\n├── api.go                    # Auto-generated: registers all L0 functions at init\n├── core_*.go                 # Auto-generated: Core API bindings (ze*)\n├── rntm_*.go                 # Auto-generated: Runtime API bindings (zer*)\n├── sysm_*.go                 # Auto-generated: Sysman API bindings (zes*)\n├── tols_*.go                 # Auto-generated: Tools API bindings (zet*)\n├── ze/                       # High-level idiomatic Go wrapper\n│   ├── init.go               #   Driver initialization\n│   ├── context.go            #   Context management\n│   ├── device.go             #   Device enumeration \u0026 properties\n│   ├── module.go             #   SPIR-V module loading\n│   ├── kernel.go             #   Kernel creation \u0026 argument binding\n│   ├── mem.go                #   Device/host memory allocation\n│   └── command.go            #   Command queues, lists, barriers\n├── internal/zecall/          # purego FFI layer (loads ze_loader at runtime)\n├── cmd/gen/                  # Code generator: parses L0 headers → Go source\n├── spec/                     # Optional L0 SDK headers for dev purpose (input to cmd/gen)\n└── examples/\n    ├── quick_start/          # The quick start shown in this README\n    └── vadd/                 # Vector addition: SYCL kernel + Go host\n```\n\n## Appendix II. Regenerating Bindings from Headers\n\ngozel includes a code generator (`cmd/gen`) that parses the four Level Zero API headers and produces all `core_*.go`, `rntm_*.go`, `sysm_*.go`, `tols_*.go` files plus `api.go`.\n\n### From a local SDK\n\nPlace (or symlink) the Level Zero SDK under `spec/`:\n\n```\nspec/\n├── include/level_zero/\n│   ├── ze_api.h      # Core\n│   ├── zer_api.h     # Runtime\n│   ├── zes_api.h     # Sysman\n│   └── zet_api.h     # Tools\n└── lib/\n```\n\nThen run:\n\n```bash\ngo run ./cmd/gen -spec ./spec\n```\n\n### From a specific release\n\nThe generator can download the SDK directly from the [level-zero releases](https://github.com/oneapi-src/level-zero/releases):\n\n```bash\ngo run ./cmd/gen -spec v1.28.0\n```\n\n### Via `go generate`\n\n```bash\ngo generate .\n```\n\nThis invokes `cmd/gen` with the local `spec/` directory as configured in `doc.go`.\n\n## Appendix III. Building SPIR-V Kernels\n\nGPU kernels in the [examples](examples) folder are written in SYCL C++ and compiled to SPIR-V for embedding into Go programs, which is a little bit hacky. You can also use `ocloc`, which is a common practice and you can search for the build doc elsewhere. The build pipeline uses `go generate` directives:\n\n```\nmain.cpp ──clang++ -fsycl──▶ device_kern.bc\n                              │\n                        sycl-post-link\n                              │\n                        ▼ device_kern_0.bc\n                              │\n                     llvm-spirv\n                              │\n                        ▼ main.spv          ← embedded via //go:embed\n```\n\n### Prerequisites\n\n- [Intel LLVM SYCL Compiler](https://github.com/intel/llvm) (provides `clang++` with SYCL support, `sycl-post-link`, etc.)\n\n### Build\n\n```bash\ncd examples/vadd\ngo generate    # compiles main.cpp → main.spv\ngo run main.go # runs vector addition on GPU\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumiama%2Fgozel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffumiama%2Fgozel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumiama%2Fgozel/lists"}