enki-gpu 0.1.1

Pure Rust heterogeneous GPU compute platform with JIT compilation
Documentation
<div align="center">

# Enki

**Pure-Rust Heterogeneous GPU Compute Platform**

Write standard, idiomatic Rust functions and run them natively on your CPU, or compile them just-in-time directly onto GPU silicon.

*No Nightly toolchain required. No foreign shading languages. No descriptor set juggling.*

[![Crates.io](https://img.shields.io/crates/v/enki-gpu.svg)](https://crates.io/crates/enki-gpu)
[![Documentation](https://img.shields.io/badge/docs-enki_book-blue.svg)](https://enkiruntime.github.io/enki/)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)

</div>

---

> ### *"Well basically, if you know Rust, you know Enki."*
> 
> You don't need to learn WGSL, GLSL, mojo, or CUDA. Enki bridges the gap between systems programming and graphics hardware. If you understand Rust's references (`&T`, `&mut T`), slices (`&[T]`), atomics, and pattern matching, you already know how to write high-performance GPU kernels.

---

## Quick Start

Add Enki and your favorite math library to your project:

```bash
cargo add enki-gpu glam
```

Paste this into your `main.rs`:

```rust
use enki::*;
use glam::{Mat4, Vec3};

const N: usize = 5;

// Define a function once with #[nam]
#[nam]
fn mat_mul(_space: &Space, a: &Mat4, b: &Mat4, c: &mut Mat4) {
    *c = *a * *b;
}

fn main() {
    // 1. Initialize the GPU runtime
    let enki = Enki::init();

    // 2. Prepare data
    let a_gpu = gpu_vec![Mat4::from_scale(Vec3::splat(2.0)); N];
    let b_gpu = gpu_vec![Mat4::from_translation(Vec3::splat(5.0)); N];
    let mut c_gpu = gpu_vec![Mat4::ZERO; N];

    // 3. Dispatch directly to GPU silicon
    enki.flow(|_| {
        mat_mul.run(&Space::gpu_x(N), &a_gpu, &b_gpu, &mut c_gpu);
    });

    // 4. (Optional) Run the exact same function natively on the CPU for testing/debugging.
    let a_cpu = vec![Mat4::from_scale(Vec3::splat(2.0)); N];
    let b_cpu = vec![Mat4::from_translation(Vec3::splat(5.0)); N];
    let mut c_cpu = vec![Mat4::ZERO; N];

    for i in 0..N {
        mat_mul(&Space::cpu_x(i, N), &a_cpu[i], &b_cpu[i], &mut c_cpu[i]);
    }

    // Verify & print results
    assert_eq!(&c_cpu[..], &c_gpu.to_vec()[..]);
    println!("{:?}", &c_cpu[..]);
    println!("{:?}", &c_gpu.to_vec()[..]);
    println!("CPU & GPU results match perfectly!");
}
```

Run it:

```bash
cargo run
```

*Note: On your first build, Enki will ask you if you want to automatically configure `--emit=llvm-bc` in `.cargo/config.toml`, If `Y` is entered, Enki will automatically configure `.cargo/config.toml`*

*Note: If `parsu` compiler toolchain is missing, Enki will ask you if you want to install it automatically. if `Y` is entered, enki will automatically install it via [GitHub Release](https://github.com/enkiruntime/enki/releases).*

---

## Key Highlights

* **Runs on Stable Rust:** No pinned nightly toolchains, forks, or broken compiler plugins.
* **The GPU BorrowEngine:** Extends Rust's ownership model to parallel hardware. Prevents spatial collisions, slice overlaps, and temporal data hazards before commands hit the wire.
* **Direct Crate Integration:** Use crates like `glam` and algebraic types directly inside your kernels.
* **Bindless by Default:** Built on Vulkan 1.3 64-bit Buffer Device Addresses (BDA) and Timeline Semaphores. Zero descriptor set management.
* **Automatic Synchronization:** Automatic pipeline barrier generation via a Transitive Reduction Solver (TTRD).
* **Compiler-Grade Diagnostics:** Beautiful, clear rustc-style error messages (`E1001` - `E3011`) for hardware and dispatch invariant checks.

---

## The Enki Book

Looking for in-depth guides, real-world examples, and architecture breakdowns? 

---> **[Read The Enki Book](https://enkiruntime.github.io/enki/)**

The book covers:
- **The Mental Model:** How Rust types map directly to GPU hardware.
- **The BorrowEngine in Depth:** Understanding spatial and temporal safety invariants.
- **Interactive Graphics:** Windowing, swapchains, and real-time display presentation with `flow.present()`.

---

## The Journey: Why We Built Enki

For over two decades, GPU programming has been treated as an alien world. isolated languages, fragile binding tables, separate toolchains, and cryptic runtime crashes. 

We asked a simple question: **Why can't GPU programming feels like writing CPU code?**

Enki was born to unify host and accelerator code. By leveraging LLVM bitcode generated by `rustc` and synthesizing hardware-optimized SPIR-V through our custom JIT pipeline (`parsu`), Enki gives you raw silicon throughput without sacrificing Rust’s safety and expressiveness.

---

## Alpha Status & Licensing

Enki is currently in active **Alpha** and follows a **sustainable open-core model** designed to keep the platform free forever for independent creators while funding continuous compiler R&D:

* **Open-Source Core (MIT / Apache-2.0):** The user-facing API (`enki`), execution engine & BorrowEngine (`anu`), memory manager (`apsu`), Vulkan windowing abstractions (`utu`), and procedural macros are **100% open-source and free forever**. Your code and your applications belong entirely to you with zero restrictive licensing.
* **JIT Compiler Toolchain (`parsu`):** The native compilation backend is distributed as an automated, zero-setup pre-built native binary:
  * **Free forever** for individuals, students, researchers, indie developers, and non-commercial projects.
  * **Commercial licenses** will be available for enterprises deploying Enki in production at scale.
* **A Note on Safety:** While Enki's `BorrowEngine` and type system actively catch spatial collisions, overlapping slices, and temporal presentation hazards, it **does not provide formal mathematical safety proofs**. It makes parallel GPU execution dramatically safer and more intuitive than raw shaders, but it is not a formally verified sound type system. Think of it as a pragmatic, compiler-grade safety net.

Found a bug, want to stress-test the runtime, or have an idea? Please open an [Issue](https://github.com/enkiruntime/enki/issues) or join the discussion!

---

<div align="center">
Core framework released under the MIT OR Apache-2.0 License.
</div>