2. CPU-only Matrix Multiplication in Zig

This continues from part 1.1 of the ZigLM series. Here we will start by implementing a naive matmul for 2D f32 tensors, and then implement a SIMD optimization to measure the speedup. Following that I will explore Zig and C interop to integrate with the ggml library and call it directly. The naive algorithm The textbook formula for a 2x2 matrix multiplication is: In pseudocode this looks like: // A, B, C are 2x2, indexed [row][col] C[0][0] = A[0][0]*B[0][0] + A[0][1]*B[1][0] C[0][1] = A[0][0]*B[0][1] + A[0][1]*B[1][1] C[1][0] = A[1][0]*B[0][0] + A[1][1]*B[1][0] C[1][1] = A[1][0]*B[0][1] + A[1][1]*B[1][1] Generalizing, if A is an m × n matrix and B is an n × p matrix, C = AB is defined as an m x p matrix which can be written as a loop:...

November 27, 2026 · James Johnstone

Vertfinder: Finding runnable climbs in OpenStreetMap data

The problem Whilst reading “Run Faster from the 5K to the Marathon” by Brad Hudson and Matt Fitzgerald, a problem struck me. One workout they recommend year-round is short hill sprints on a 6-8% grade. How do you find the perfect nearby hill for hill sprints? I used online mapping tools and manually calculated the gradient of various hills near me. Another book I was reading, “Training for the Uphill Athlete” by Steve House, Scott Johnston and Kílian Jornet, suggests 10-minute hill repeats at a runnable 8% grade....

November 24, 2026 · James Johnstone

1.1 Memory-mapping GGUF tensor data in Zig

This continues from part 1 of the ZigLM series. So far we parsed the GGUF file and loaded it into memory, defining Tensor but leaving the data part out. Each Tensor we read contains an offset to a location in the data region of the GGUF file. This data region makes up the majority of the file, and is where mmap gains the most benefit as we don’t need to store multiple copies of the tensor in memory....

October 24, 2026 · James Johnstone

1. Implementing a GGUF Parser in Zig

Part 1 of the ZigLM series. Repo: https://github.com/james-o-johnstone/ziglm GGUF is a file format for storing models for inference with GGML which is a C/C++ ML library. The file contains the complete model definition including weights, tokenizer and architecture. We will start with loading this file as it is the first step to using a model for local inference. It’s also a good first step for learning Zig fundamentals like types, IO, memory etc....

October 5, 2026 · James Johnstone

ZigLM: Learning Zig and local inference

I recently came across this video from the Zig creator which inspired me to check out the language. I have also been playing around with running local LLM models using llama.cpp and wanted to learn a bit more deeply about how that works. I’m trying to use Claude to learn here rather than generate everything, so I can dig more deeply into the code. I think that Claude can be a very useful tool for learning quickly if used responsibly, but it requires a bit of effort to get the balance right to ensure you are still learning....

May 29, 2026 · James Johnstone

Implement DNS in a Weekend (in Rust!) Part 3

Part 3 of “Implement DNS in a weekend” - implementing the resolver.

July 27, 2024 · James Johnstone

Implement DNS in a Weekend (in Rust!) Part 2

Continuing to follow along with “Implement dns in a weekend”, this is part 2.

June 22, 2024 · James Johnstone

Implement DNS in a Weekend (in Rust!) Part 1

To improve my skills in Rust, learn more about how DNS works and eventually learn about Rust/Ruby and Rust/Java interop I have decided to follow along with “Implement dns in a weekend”, reimplementing the Python code in Rust.

June 19, 2024 · James Johnstone

Calculators for Running (Implemented In Rust Using WebAssembly)

Some calculators I use for running, in the format I wanted on a single page. The underlying calculations are performed in Rust.

January 28, 2024 · James Johnstone

Java Performance

10 interesting new things I learned after reading the O’Reilly Java Performance book.

July 29, 2023 · James Johnstone