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 February 20, 2025 08:50
Pliron Compiler Framework

Pliron

#mlir #llvm #compiler

  • An MLIR-inspired extensible compiler framework written in pure Rust.

⠀Design Evaluation Notes:

  • IR Format: Pliron’s generic IR (Intermediate Representation) format is based on SSA (Static Single Assignment) form and is conceptually similar to MLIR. Like MLIR, it is a nested IR, meaning it supports hierarchical structures such as operations containing regions, which in turn contain blocks and other operations. However, there may be differences in specific implementation details.
@nihalpasham
nihalpasham / cranelift_backend.md
Last active November 2, 2024 02:28
Plan for Building a Backend in Cranelift

Plan for Building a Backend in Cranelift

Steps to Add a New Backend:

  1. Create a Folder for the Backend
    • Place the new backend directory under /cranelift/codegen/src/isa, where each backend resides.
  2. Define Backend and Implement Required Traits
    • Ensure the backend implements these essential traits:
      • TargetIsa: Specifies the target architecture’s interface.
  • LowerBackend: Manages instruction lowering for the architecture.
@nihalpasham
nihalpasham / cubecl_ir_gelu
Last active September 28, 2024 02:00
CubeCL IR for the gelu_example
KernelDefinition { inputs: [Binding { location: Storage, visibility: Read, item: Item { elem: Float(F32), vectorization: Some(1)
}, size: None
}
], outputs: [Binding { location: Storage, visibility: ReadWrite, item: Item { elem: Float(F32), vectorization: Some(1)
}, size: None
}
], named: [("info", Binding { location: Storage, visibility: Read, item: Item { elem: UInt, vectorization: None
}, size: None
})
], cube_dim: CubeDim { x: 4, y: 1, z: 1
@nihalpasham
nihalpasham / CubeCL_Architecture_Overview.md
Last active September 29, 2025 17:47
CubeCL Architecture Overview - Running Rust on your GPU (WebGPU, CUDA)

CubeCL

#gpu #kernel #rust

High Level Overview:

  • GPU kernels in Rust
  • Comptime
    • Automatic vectorization
    • Instruction and shape specialization
  • Loop unrolling
@nihalpasham
nihalpasham / cubecl_gelu_expanded.rs
Last active September 28, 2024 01:44
Expanding CubeCL's gelu example
// 🦀 Generated by Rust Macro Expand 🦀
// 🦀 Timestamp: 16/09/2024, 12:50:30 🦀
#![allow(warnings)]
#![feature(print_internals)]
#![feature(panic_internals)]
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
@nihalpasham
nihalpasham / gelu.wgsl
Created August 28, 2024 03:11
WGSL generated with the CubeCL framework for the gelu example
[START_KERNEL_COMPILATION]
name: gelu::gelu_array::GeluArray<
cubecl_core::frontend::element::float::F32,
cubecl_wgpu::runtime::WgpuRuntime,
>
cube_dim: (4, 1, 1)
shared_memory: 0 bytes
info: (
KernelSettings {
@nihalpasham
nihalpasham / dtb_node_and_property_constructor.rs
Last active March 10, 2022 07:29
Snippet to create flattened dtb nodes and properties
#[derive(Debug)]
#[repr(C)]
/// Constructs a device-tree `node`, given a name and buffer. The buffer must be adequately sized.
pub struct RawNodeConstructor<'a> {
fdt_begin_node: u32,
node_name: &'a [u8],
}
impl<'a> RawNodeConstructor<'a> {
pub fn make_raw_node(buf: &'a mut [u8], name: &'a str) -> Result<Self> {
@nihalpasham
nihalpasham / token_generation.py
Created April 14, 2020 12:09
token generation
real_tokens = []
imag_tokens = []
for i in range(0, len(symbols_real)):
if symbols_real[i] == 15:
token = symbols_real[i:i+9]
checksum = np.sum(token) % 16
if checksum <= 4 or checksum >= 13 :
q = (''.join([format(symbol, 'x') for symbol in token[1:7]]))
# print(q)
@nihalpasham
nihalpasham / symbol_decoding.py
Created April 14, 2020 10:59
symbol decoding
tokens_real = []
tokens_imag = []
for i in range(0, len(symbols_real)-1):
if symbols_real[i] == 15:
token = symbols_real[i:i+8]
tokens_real.append(token)
for i in range(0, len(symbols_imag)-1):
if symbols_imag[i] == 15: