Skip to content

Instantly share code, notes, and snippets.

View nihalpasham's full-sized avatar
🦂
regionaltantrums!

nihalpasham

🦂
regionaltantrums!
View GitHub Profile
@nihalpasham
nihalpasham / .md
Last active May 21, 2025 13:03
The "Two-Language Problem" in AI

Rust: A Modern Language for Safe and Fast General-Purpose Programming

Rust is a relatively young, but increasingly popular, systems programming language that emphasizes safety, performance, and concurrency. Developed by Mozilla, its stable version 1.0 was released in 2015.

Here's why Rust is gaining traction, especially in areas like AI:

  • Memory Safety without Garbage Collection: This is a core strength of Rust. Unlike languages like C and C++ which offer low-level memory management but are prone to errors (e.g., buffer overflows, null pointer dereferences, data races), Rust uses an "ownership model" and "borrowing rules" to enforce memory safety at compile time. This catches many potential bugs before the code even runs, leading to more reliable and secure software. Crucially, it achieves this without a garbage collector, which can introduce unpredictable pauses in performance.
  • High Performance: Rust compiles directly to machine code, similar to C and C++. This allows for highly optimized exe
@nihalpasham
nihalpasham / .md
Last active May 24, 2025 10:35
rust-gpu

rust-gpu

What is it?

  • is a custom backend for rustc that compiles native rust code (albeit a sub-set of it) to spir-v
    • MIR -> SPIR-V: to be precise, it takes in rust’s MIR and converts it to SPIR-V

rustc front-end IR(s):

Stuff that happens at each stage in the front-end

  • AST: macro-expansion, name resolution
  • HIR (High-level IR): type-checking, type-inference and trait solving
@nihalpasham
nihalpasham / rust_to_spirv.md
Last active June 15, 2025 10:51
🦀 Mapping Rust Shaders to SPIR-V (via rust-gpu): This Gist demonstrates how a simple Rust fragment shader is compiled into SPIR-V using rust-gpu. It includes the original Rust code, the corresponding SPIR-V output, and a concise mapping between the two. It also outlines how the rustc_codegen_spirv backend translates MIR to SPIR-V and how SPIR-T …

Mapping Rust Shader to SPIR-V

#[spirv(fragment)]				
pub fn main_fs(output: &mut Vec4) {
 *output = vec4(1.0, 0.0, 0.0, 1.0);
}
@nihalpasham
nihalpasham / .md
Last active July 20, 2025 09:52
How does automatic kernel fusion work in burn?

How does automatic kernel fusion work in burn?

Screenshot 2025-07-07 at 10 50 37 AM

Burn’s Tensor Abstraction:

  1. Generic Parameters Tensor<B, D, K> :
    • B: Backend - execution backend (composable)
    • D: usize - dimensionality (compile-time constant)
@nihalpasham
nihalpasham / nova_gpu_driver.md
Last active October 31, 2025 19:24
Implementation specifics of the rust-based Nova Gpu driver, in the linux kernel.

Nova GPU driver

Nova Driver Architecture Overview

The Nova driver is a two-tier GPU driver architecture written in Rust for NVIDIA GPUs. It consists of two main components that work together:

1. Nova-Core (drivers/gpu/nova-core/)

This is the low-level hardware abstraction layer that directly interfaces with the GPU hardware.

Entry Point:

@nihalpasham
nihalpasham / crane lift_gist.md
Last active August 16, 2025 12:51
The Cranelift backend (stream notes)

Cranelift

#idempotent

sketch

Cranelift IR:

  • Functions are compiled individually
  • The instructions in the function body use and produce values in SSA form i.e. Single Static Assignment
@nihalpasham
nihalpasham / luminal_dl_framework.md
Created August 24, 2025 06:15
Luminal - a deep learning framework in Rust.
image

High-level overview focusing on graph structure, search-based compilation, and visualization:

Luminal Architecture Overview

1. Core Graph Structure

Luminal is built around a directed acyclic graph (DAG) representation where:

@nihalpasham
nihalpasham / WebGPU+WGML.md
Created September 10, 2025 02:07
The only true cross-platform GPGPU API —WebGPU (with WGML 🦀)

True cross-platform GPU compute —WebGPU + WGML

image 2 basic-webgpu-stack ![](image.png) image

WebGPU vs WebGL

@nihalpasham
nihalpasham / gpgpu_programming.md
Created September 20, 2025 12:39
Making GP-GPU programming generally accessible

GP-GPU Programming Ramblings

#nvidia #cuda #gpu #arch #metal #rocm #triton

image
  • Tensor Cores and Tensor Memory Accelerator
  • Split Barriers (Ampere and above)
  • Thread Block Cluster (Hopper and above)
  • Producer-Consumer Queues
@nihalpasham
nihalpasham / stable-mir-compile-errors.md
Created September 30, 2025 13:14
stable-mir-compile-errors
./x build
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
$ cargo +nightly-aarch64-apple-darwin build --manifest-path /Users/nihalpasham/devspace/rust/compiler/rustc_public/rustc_public/Cargo.toml --all-targets
   Compiling rustc_public v0.1.0-preview (/Users/nihalpasham/devspace/rust/compiler/rustc_public/rustc_public)
error[E0412]: cannot find type `DynKind` in module `rustc_ty`
   --> rustc_public/src/unstable/convert/internal.rs:464:30
    |
464 |     type T<'tcx> = rustc_ty::DynKind;
    |                              ^^^^^^^