AI makes fewer and fewer mistakes every month, and that's nearly unbelievable, but it's true; anyone can observe it themselves.
Yesterday. I want to repeat that,
Yesterday I got Claude to help me add matrix operation auto-detection to my compiler. The Apple M4 (and later) range have the SME extension to their cpus, which is a high-speed matrix multiplier. That means the compiler could auto-detect
matrix operations (basically 2 nested loops calculating an array based on 2 other arrays) and schedule it on the SME co-processor.
The time taken in c++ (clang -O3) to run 10,000 128x128 matrix multiplies on the M4 Max was 10.94 secs, reasonably respectable. That dropped to 0.07 secs with the SME - giving ~1.3 TFlops from normal floating-point array multiplication, no special source-code or libraries.
It took 2 (count them, 1,2) days to build
something I have never seen before in a programming language but always wanted, clean interoperation of cpu and gpu, with the compiler managing any data-hazards. If anyone has ever tried compute shaders before, you’ll know all the boiler-plate you have to go through to get the two devices talking, and the scheduling and memory-barriers etc to get data safely where you next need it.
Here’s a
parallel Mandelbrot set calculation that can execute on one of
- you might have to look hard to find what’s different from any normal Mandelbrot algorithm, but there’s 1 line which tells the compiler that this is a data-parallel block of code, and it’s:
par mandel :reduce(+ total) {…}‘Par’ introduces a data-parallel block, ‘mandel’ is just a name, and if you want any reductions (all computations updating a single variable) you declare them afterwards. That’s it.
The compiler will then create multiple versions of the code block, one for each of the above list. At
runtime you can say “run block mandel using
this method”, again, any of the above methods, with the default being ‘auto’ - the fastest. With auto set, it’ll measure one pass through the loop for each method, then run your complete computation using that. For gpus it creates MSL (Apple), PTX (Nvidia) and SPIR-V (AMD, Android) forms of the code block you specified as ‘par’, and auto-detects which hardware it should run, again, at runtime.
Honestly, even if I say it myself this is a game-changer for fast data-parallel code. You use the same language, there’s no marshalling of data, and
the results speak for themselves.
So yes, I agree, these things are getting better and better. They still need to be driven with ideas, they’re really good at creating connections, pulling in knowledge, and executing on test-driven results, but they’re not (yet ?) creative enough to say “hey, why don’t we try and attack this problem by doing…”, at least in an engineering sense. They are amazing at the other bits though, and I wouldn’t have expected to be able to do the above 6 months ago.