I have implemented a CUDA library to perform extended precision floating point add, subtract, multiply, divide and compare with number of bits precision between 128 and 4096 bits.
I did this by using the Qwen 3.8 27B model running locally on my system to see what that model was capable of as well as experimenting with a program for animation of zooming into fractals like what a bunch of youtube videos like the Maths Town channel did, trying to approximate real time generation. I wasn’t successful, but results weren’t horrible, maybe 10x slower than real time.
I built this library by prompting the model to build a CUDA library implementing these operations and to match the results generated by GMP on CPU, exact to the last bit.
Over a couple weeks, I got the model to build the library, to build testcases, run those tests and debug the library until it got correct, equivalent results, and some benchmark programs.
I got a working library with numerically equivalent results. I also separately tested this by having the model build tests to compute pi, e, and some irrational square roots to 1000 decimal digits precision and comparing to results from the internet, which compared equivalent.
I had the model generate an equivalent benchmark using GMP and got this comparison where the GMP/CPU program ran 1 thread and 8 threads on an I9-10900X. The GPU is an RTX 4070 TI Super.
4.3 CPU (GMP) vs GPU (CUDA device)
Throughput in ops/s; speedup columns are GPU divided by the GMP column.
| Op | width | GMP (1 thr) | GMP (8 thr) | GPU | GPU/GMP-1t | GPU/GMP-8t |
|---|---|---|---|---|---|---|
| Add | 256-bit | 1,340,027 | 3,589,792 | 2,485,645,358 | 1855x | 692x |
| Sub | 256-bit | 1,445,074 | 5,800,536 | 1,947,230,053 | 1348x | 336x |
| Mul | 256-bit | 1,393,644 | 6,158,445 | 1,820,266,830 | 1306x | 296x |
| Div | 256-bit | 467,192 | 2,931,001 | 540,426,613 | 1157x | 184x |
| Add | 512-bit | 883,994 | 5,064,897 | 1,247,891,064 | 1411x | 246x |
| Sub | 512-bit | 1,029,271 | 4,710,394 | 1,148,414,155 | 1116x | 244x |
| Mul | 512-bit | 910,510 | 4,753,952 | 582,832,777 | 640x | 123x |
| Div | 512-bit | 245,220 | 1,813,422 | 147,948,648 | 603x | 82x |
| Add | 4096-bit | 109,452 | 813,875 | 50,963,849 | 466x | 63x |
| Sub | 4096-bit | 103,742 | 753,854 | 45,517,430 | 438x | 60x |
| Mul | 4096-bit | 74,988 | 604,934 | 2,285,142 | 30.5x | 3.8x |
| Div | 4096-bit | 24,444 | 196,485 | 506,380 | 20.7x | 2.6x |
At this point I have what I consider a working library. I’m willing to create a github repository and upload the library after I clean it up and maybe fine tune it is there is interest, since I haven’t had much luck finding a similar library in the past.
Most importantly, I am a retired software engineer working in HPC that has spent part of my time learning about software including AI. I have a limited math background and understand the basic ideas behind the library, and that’s it. So I’d be uploading it for interested people to use as starting point, but my ability to fix things would be limited.
So if there’s interest in this, I can take it further. If not, I’ll drop it.