# Tensor Is the Might: Building a GPU-Accelerated Library from Scratch

> Hacker News story 48906123 · language: en · submitted 2026-07-14
> Web version: https://zeli.app/story/48906123
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 11 · by [eatonphil](<https://news.ycombinator.com/user?id=eatonphil>) · 💬 2
[original](<https://zserge.com/posts/tensor/>) · [HN discussion](<https://news.ycombinator.com/item?id=48906123>)

## Summary

I built a complete, accelerated tensor library from scratch in C to demystify the math behind neural networks. Starting with flat arrays and metadata, I implemented elementwise operations before tackling the complexities of GPU acceleration. To keep things manageable, I chose Metal for Apple Silicon, leveraging its unified memory to write custom kernels and achieve performance that CPU-only frameworks simply cannot match.

## Key quote

> I tried many times to get the most out of CPU-only tensors, but even with BLAS, LAPACK, OpenMP – I could not reach the same magnitude of performance as GPU-accelerated frameworks.

## HN discussion (2 comments)

### [srean](<https://news.ycombinator.com/item?id=48906982>)

> If one wants to add the capability to reason about shape and shape compatibility, Barry Jay's FiSh would be an interesting detour.
>
> https://web.archive.org/web/20111015133833/http://www-staff....
>
> This was used in his shape aware language FiSh, for dealing with multidimensional arrays. Shape compatibilities were statically type checked, if I recall correctly. Shapes were also used to optimize the loops.
>
> [Programming in FISh] https://link.springer.com/article/10.1007/s100090050037
>
> [Towards Dynamic Shaping] https://www.researchgate.net/publication/265975794_Towards_D...

### [hasteg](<https://news.ycombinator.com/item?id=48908636>)

> I just recently watched some (not all) of this video "coding a machine learning library in c from scratch" and seems like he's going through a similar process in this blog as this video. I would recommend watching the video to get an idea of what the fundamentals of a ML library look like. From someone who has recently been getting interested in actually writing ML code and trying to make sense of it myself (from the perspective of just a typical backend engineer) it was very interesting to see. Previously my experience with ML libs (PyTorch specific) was writing my own Mini-GPT and training it on a small dataset using my own GPU (5090). Cool to see the behind the scenes and took away some o the handwaveyness... https://www.youtube.com/watch?v=hL_n_GljC0I

### [srean](<https://news.ycombinator.com/item?id=48906724>)

> \> A tensor is nothing but a flat array of numbers, plus some metadata telling you how to interpret those numbers as a multi-dimensional object.
>
> Erm... many would disagree. I think what he means is just a multidimensional array.

---

## Cite

- Page: https://zeli.app/story/48906123
- Date: 2026-07-14
- Source: zserge.com (https://zserge.com/posts/tensor/)
- Hacker News: https://news.ycombinator.com/item?id=48906123

## Other languages

- zh: https://zeli.app/zh/story/48906123 · markdown: https://zeli.app/zh/story/48906123.md
- ja: https://zeli.app/ja/story/48906123 · markdown: https://zeli.app/ja/story/48906123.md
- ko: https://zeli.app/ko/story/48906123 · markdown: https://zeli.app/ko/story/48906123.md
- de: https://zeli.app/de/story/48906123 · markdown: https://zeli.app/de/story/48906123.md
- es: https://zeli.app/es/story/48906123 · markdown: https://zeli.app/es/story/48906123.md
