r/learnmachinelearning
•
u/Forward_Confusion902
•
Dec 30 '25
•
1
2
1
1
1
Project I implemented a Convolutional Neural Network (CNN) from scratch entirely in x86 Assembly, Cat vs Dog Classifier
As a small goodbye to 2025, I wanted to share a project I just finished.
I implemented a full Convolutional Neural Network entirely in x86-64 assembly, completely from scratch, with no ML frameworks or libraries. The model performs cat vs dog image classification on a dataset of 25,000 RGB images (128×128×3).
The goal was to understand how CNNs work at the lowest possible level, memory layout, data movement, SIMD arithmetic, and training logic.
What’s implemented in pure assembly: Conv2D, MaxPool, Dense layers ReLU and Sigmoid activations Forward and backward propagation Data loader and training loop AVX-512 vectorization (16 float32 ops in parallel)
The forward and backward passes are SIMD-vectorized, and the implementation is about 10× faster than a NumPy version (which itself relies on optimized C libraries).
It runs inside a lightweight Debian Slim Docker container. Debugging was challenging, GDB becomes difficult at this scale, so I ended up creating custom debugging and validation methods.
The first commit is a Hello World in assembly, and the final commit is a CNN implemented from scratch.
Previously, I implemented a fully connected neural network for the MNIST dataset from scratch in x86-64 assembly.
I’d appreciate any feedback, especially ideas for performance improvements or next steps.



313
u/Ramiil-kun Dec 30 '25
You're the hope of future programming
222
u/Ok_Economics_9267 Dec 30 '25
In times of bubbles and AI marketing bullshit you made an absolute gem. Congrats
120
u/Z_MAN_8-3 Dec 30 '25
No one, absolutely no one can replace you
🙏I bow before you my assembly king🙏
73
u/Mother-Purchase-9447 Dec 30 '25
Great work. Will help me to understand assembly 😀
53
u/v1z1onary Dec 30 '25
Not Hot Dog
45
u/taichi22 Dec 30 '25
No notes, nicely done. These are the kind of posts I like to see. I heard Anthropic was asking this sort of question on one of their interviews, apparently. Maybe try hitting them up?
45
u/LiberFriso Dec 30 '25
Bro you implemented a CNN in assembly. You can give me advice on my next steps.
36
u/hkllopp Dec 30 '25
People like you scare me. This is incredible.
26
u/[deleted] Dec 30 '25
Very good and yep, thats the actually how it should be running.
Here are my findings on running the app as HLS code.
25
u/forbiscuit Dec 30 '25
You’ll definitely be hired anywhere
10
u/avrboi Dec 30 '25
"How to spot a masochist 101"
Congrats man, that's some hardcore stuff you just pulled!
9
u/profesh_amateur Dec 30 '25
Very neat! To tie a bow on this project, it'd be good to include a more detailed benchmark against numpy, as well as against other DNN libraries like Pytorch and tensorflow. Bonus points if you compare against GPU Pytorch/tensorflow to see how close you can get.
As a tip, making your benchmark be reproducible (eg as a script in your repo) is a good idea.
Things to consider in your benchmark: in addition to full end to end training time, also consider more detailed analysis like: comparing data loading/preprocessing time, model forward time, model backward time, etc.
Also, ensuring that your implementation achieves similar loss/accuracy as equivalent implementations in Pytorch/tensorflow is a good sanity check that your implementation is correct.
8
u/bradrlaw Dec 30 '25
Writing in assembly is such a great experience when you are done. I rewrote some key signal processing code for an embedded system for a former employer in x86 with SSE2 and some other vectorization instructions available on our platform. Got over 90% speed up compared to our “optimized” C.
Your work is on another level and you remind me of Steve Gibson of Spinrite fame that made all his tools in assembly for both DOS and Windows. Amazing having a fully featured Windows app in a few dozen kilobytes.
https://en.wikipedia.org/wiki/Steve_Gibson_(computer_programmer)
7
u/cazzobomba Dec 30 '25
Absolutely outstanding. Can’t tell you how many projects I tried and abandoned. Wow the complexity of a CNN model in assembly - mind blown!!
5
u/Context_Core Dec 30 '25
Wow this is fantastic work. Grats
5
u/leocosta_mb Dec 30 '25
And you did it all in one month? 🤯 Congrats!
4
u/zero1581 Dec 30 '25
This is amazing. It would be great if you had some plots to show the difference vs other frameworks.
4
u/Available_Editor_559 Dec 30 '25
My liege 👏👏👏👏 This is great work.
4
u/Palmquistador Dec 30 '25
Once in a great while, I like to imagine that I know things have command of some of them. This is an excellent reminder of how much I don’t know yet. Cheers. 🍻
4
u/Excellent-Student905 Dec 30 '25
impressive!
what's your professional and/or academic background? just curious
4
u/Antidote12- Dec 31 '25
Terry davis is that you?
4
u/Johnnie-Runner Dec 31 '25
I thought knowing to program neural networks with PyTorch already made me stand out in times of vibe coding. Obviously this is not the case 🥲 Congrats to this marvelous achievement!
4
u/StolenApollo Dec 31 '25
Bro what 😭 this is insane oml huge congrats this takes a different level of dedication
4
u/zammypam Dec 31 '25
Bro did it in assembly and i suck at implementing it in python lmao, gg
3
u/always_wear_pyjamas Dec 30 '25
My good sir, you are a mad man and a genius.
3
u/Smarterchild1337 Dec 31 '25
Giga-based
3
u/CarzyCrow076 Dec 31 '25
I’m sorry for breathing the same air as you do, SORRY. I ask for your forgiveness my lord
3
u/Dependent-Shake3906 Dec 31 '25
Holy shit balls, that is actually one of the most impressive things I’ve seen in a while.
Congratulations dude, you’ve made yourself a 6 figure asset to someone in the future.
3
u/AstolfoFr07 Dec 31 '25
Holy nightmare
3
u/ToxicTop2 Dec 31 '25
I can only get so er*ct. Beautiful.
3
u/[deleted] Jan 01 '26
If i ever feel demotivated I will remind myself that there is a guy who did CNN on assembly. Congrats bro.
2
u/Ayano-Keiko 19d ago
The expertise in ASM👍The first time I saw implemnet neural network in ASM🙏It must be hard work🙏
2
u/PabloKaskobar Dec 30 '25
Quite phenomenal, indeed. Did you document your learning by any chance? I'd love to take a look.
2
u/cellatlas010 Dec 30 '25
cool. that's impressive. though not as impressive as then one who crafted cnn using microsoft excel
2
u/Wide-Opportunity-582 Dec 31 '25
That's wonderful OP..
How can someone a beginner like me attempt this ? (Can you share some resources or guidance please)
2
u/TJsaltyNutz Dec 31 '25
Wtf 😳 that’s insane!
2
u/AdventurousGold672 Dec 31 '25
Holy shit, I salute you.
I had to write in Assembly and it was painful.
2
u/laststand1881 Dec 31 '25
Great job OP,
2
u/imavlastimov Dec 31 '25
Art
2
u/m0j0m0j Dec 31 '25
Joke 1: this is what being unemployed for long does to a mf
Joke 2: this is your competition guys. Good luck
Seriously: it is amazing, man.
2
u/red_hash Dec 31 '25
Im so jealous of ur skills man lol, great job!
2
u/Willing_Ad2724 Dec 31 '25
Great work. I love this shit
2
u/Maximum_Guidance4255 Dec 31 '25
How many lines of assembly is it??? U must have spent soo much time on this.
2
u/Axelrod-86 Dec 31 '25
Impressive. Where did you find the dataset of dog and cat picture ?
2
u/ibWickedSmaht Jan 01 '26
You are awesome
2
u/ALittleBitEver Jan 01 '26
Bro is playing in his own league
2
u/elduderino15 Jan 01 '26
Big respect! Have you tried a performance compare with identical CNN built i. standard libs like pytorch to see how performance compares?
2
u/lordrazora Jan 01 '26
Just assuming it runs, absolutely cracked. Keep doing what you’re doing
2
u/NonElectricalNemesis Jan 01 '26
That's impressive to say the least 🙌
2
u/TopConcept570 Jan 01 '26
Wow this is amazing stuff, How long have you been coding if I might ask. I feel like you must have grasped this stuff really early
2
u/youssef_naderr Jan 01 '26
this is very impressive mashalah
2
u/moms_enjoyer Jan 01 '26
I'm sorry if this is a silly question. Will It work on ARM too?
2
u/moms_enjoyer Jan 01 '26
Is It more eficient than using Python/C++?
2
u/MeticulousBioluminid Jan 01 '26
phenomenal work - this kind of implementation is desperately needed
2
u/fustercluck6000 Jan 01 '26
With the AI hype BS, it’s good to know all is right with the force.
2
u/thisisjhatka_altacc Jan 02 '26
i am sorry to breathe the same air as you
(i shall build in ASM too)
2
u/[deleted] Jan 02 '26
Goat
2
u/420by6minuseipiis69 Jan 02 '26
You are THE CHOSEN ONE
2
u/antiquemule Jan 02 '26
Amazing! You must be nuts, in a good way.
2
u/Savings-Giraffe-4007 Jan 03 '26
Dude, you rock, respect
2
u/Thediverdk Jan 03 '26
This is utterly amazing.
WOW
If I was in a position to be able to hire a developer like you, I would and pay you BIG cash.
I am blown away.
2
u/Rich-Speaker-1359 Jan 04 '26
what's your background? This really good
2
u/Master1223347_ Jan 11 '26
I was thinking of doing this but seeing someone actually do it is mindblowing... Amazing mindblowing work
2
u/Top_Bicycle_2430 Jan 12 '26
Good work.
1
u/aniket_afk Jan 11 '26
Holy f'in cow. Can you do a writeup or preferably a series of write ups about this step by step. Absolutely f'in amazing.
1
u/Jason_reyes_dev Jan 25 '26
This is insane work, congrats. Doing a full CNN in pure x86-64 asm is another level of dedication. I’m especially curious about the debugging part: did you rely more on unit tests for each kernel (conv, dense, activations) or mostly on end-to-end loss/accuracy checks to spot bugs? Also, do you plan to write a more detailed blog post about the architecture and the AVX-512 optimisation tricks?
3
u/ju1ceb0xx Dec 31 '25
Great! Can you convert it to ARM? I think this kind of low level code optimization can be particularly useful on edge devices.
2
u/Agile_Web1128 Dec 30 '25
Yoooo
2
u/pokes41 Dec 31 '25
How does this compare in terms of training and inference wall clock time to a pytorch implementation
1
u/150c_vapour Jan 02 '26
CUDA next?
0
u/[deleted] Dec 30 '25
[deleted] — view deleted comment
0
u/[deleted] Dec 31 '25
[deleted] — view deleted comment
19
u/[deleted] Dec 30 '25
[removed] — view removed comment
4
u/[deleted] Dec 30 '25
[removed] — view removed comment
2
u/[deleted] Jan 01 '26
[removed] — view removed comment
2
u/[deleted] Jan 02 '26
[removed] — view removed comment
1
u/[deleted] Jan 22 '26
[removed] — view removed comment
0
u/[deleted] Dec 30 '25
[removed] — view removed comment