I asked google , lets calculate a factorial in VRAM.

Memory used is GPU
Process running on GPU.

Result
Code:
Selected GPU   : NVIDIA GeForce RTX 2060
VRAM Allocated : 4194300 KB on Type[1] (GDDR6)
Staging Buffer : 64 MB on Type[3] (CPU Ptr: 0x4933A5F000)
Compute Shader : alain.spv loaded & bound to VRAM
Resultaat voor 32000! : 3.245427E+121710 (121711 cijfers)
GPU klaar in 8326.10 ms


Nice, very nice. But the code is ugly as hell... I dont even dare to share.
 
Interesting... would it show you (or save to a file) all the 121711 decimal digits, or does it just calculate 32000! to 6 decimal places?
 
time jot 32000|awk '{print $1 "*\\"} END {print 1}'|bc |head -5
10654949293078496967928882853073336063011399232223553942132323470355\
38320621249942993021993086132241046451576426693382397585204626097232\
94820492415777175897792071296524055278117401714018412629267117619600\
07149902073996152449627473932318229365478620122018677239484459664505\
78589413992961494896147559719422751692335095822083630073459671375917\

real 0m0.396s
user 0m0.384s
sys 0m0.032s
 
The title is misleading a bit, I was wondering what Non Volatile RAM had to do with things.
And this makes me itchy to do this in an FPGA, but alas, no time for that.
 
Note the shader code ie .comp , compiled to .spv , is interesting,
Code:
void main() {
                uint words = {{words}}u;
                if (startStep == 1u) {
                    for (uint i = 0u; i < words; i++) data[i] = (i == 0u) ? 1u : 0u;
                    activeWords = 1u;
                }
                uint activeW = activeWords;
                for (uint step = startStep; step <= endStep; step++) {
                    uint64_t carry = 0ul;
                    for (uint i = 0u; i < activeW; i++) {
                        uint64_t prod = uint64_t(data[i]) * uint64_t(step) + carry;
                        data[i] = uint(prod);
                        carry = prod >> 32;
                    }
                    if (carry > 0ul && activeW < words) {
                        data[activeW++] = uint(carry);
                    }
                }
                activeWords = activeW;
            }
 
time jot 32000|awk '{print $1 "*\\"} END {print 1}'|bc |head -5
10654949293078496967928882853073336063011399232223553942132323470355\
38320621249942993021993086132241046451576426693382397585204626097232\
94820492415777175897792071296524055278117401714018412629267117619600\
07149902073996152449627473932318229365478620122018677239484459664505\
78589413992961494896147559719422751692335095822083630073459671375917\

real 0m0.396s
user 0m0.384s
sys 0m0.032s
nice try Covecat , try,
Code:
time sh -c "jot 65536 | awk '{print \$1 \"*\\\\\"} END {print 1}' | bc > output.txt"

For me 2 seconds. While my gpu program takes 20 seconds....
 
GPU was fast, 0.5 seconds for 131072!,
Ooh , 100 seconds where needed to convert binary result to 10-base.
Code:
Selected GPU   : NVIDIA GeForce RTX 2060
VRAM Allocated : 1 MB on Type[1] (GDDR6)
Staging Buffer : 64 MB on Type[3] (CPU Ptr: 0x4933A5F000)
Compute Shader : alain.spv loaded & bound to VRAM
Resultaat voor 131072! (8x8 threads):
Aantal cijfers : 613842
Eerste 10      : 2358150556
Laatste 10     : 0000000000
GPU klaar in 458.35 ms
      115,70 real       115,00 user         1,93 sys
 
with gmp is 0.06s (60ms)
C:
[titus@utmbox ~]$ cat mpz.c
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>

int main(int argc, char **argv) {
    mpz_t result;
    unsigned long n = argc > 1 ? atol(argv[1]) : 100;

    // 1. Initialize the big integer
    mpz_init(result);

    // 2. Calculate 65536! directly
    mpz_fac_ui(result, n);

    // 3. Check how many decimal digits the result has
    size_t num_digits = mpz_sizeinbase(result, 10);
    printf("%ld! has approximately %zu decimal digits.\n",n, num_digits);

    // 4. Print the full number (Warning: this outputs ~287,194 digits!)
    gmp_printf("%ld! = %Zd\n",n, result);

    // 5. Free allocated memory
    mpz_clear(result);

    return 0;
}
[titus@utmbox ~]$ cc -I /usr/local/include/ -L /usr/local/lib mpz.c -lgmp -o mpz
[titus@utmbox ~]$ time ./mpz 131072|head -c 800
131072! has approximately 613842 decimal digits.
131072! = 235815055653289250396763866787945884511230604741138536272891795112767254625193827424470269533171321341941668449711708427431792450185542563254055975365220086980531348737452602921180622814844893407094924515271202687099074801240180139513316812432419522307118314999137579389352994511786520136341858933527037471458466895712152628207996877080768234260074290838105173454784229383001831669992676990492879840989178522489188259478591567182425650766211084670313164604857457208362192601752047315100448377328519915588773468314293711235764723873389367327529664399928164655354931741358244390592603864985542248297018744431862141774112559578106295792951093926578135893544795298112562032375347248689570550147752253033938668370530485691603061323411767566710104
real    0m0.067s
user    0m0.061s
sys    0m0.011s
 
The title is misleading a bit, I was wondering what Non Volatile RAM had to do with things.
And this makes me itchy to do this in an FPGA, but alas, no time for that.
Giving me bad ideas Crivens :),
https://www.fruugo.be/icesugar-fpga...dge-ai-projecten-whbyv/p-545560629-1102525542

Code:
pkg install yosys nextpnr icestorm riscv64-none-elf-gcc hidapi pkgconf git gmake
PROTO="https://"
DOMAIN="github.com"
REPO="/wuxx/icesugar.git"
git clone "${PROTO}${DOMAIN}${REPO}"
cd icesugar/tools/src
gmake

And i have
Code:
Resultaat voor 262144! (1024 pow2 threads):
Aantal cijfers : 1306594
Eerste 10      : 1396355768
Laatste 10     : 0000000000
GPU klaar in 18474.83 ms
       53,32 real        42,88 user         0,65 sys
 
I wonder if GMP-ECM might yield any gains. Alas, we will never know.... ( gmp-ecm in ports; further docs: pkg info gmp-ecm | grep WWW ) .
 
Huh ... get a load of this folks. From the https://gmplib.org/ homepage.

Screenshot_261113_0809.png
 
Challenge is open.

Covecat is good.
Covecat have a look,

Code:
x@myfreebsd:~/GLEAM2/hello_gpu7 % time gleam run -- 19
   Compiled in 0.26s
    Running hello_gpu.main
Result (524288!):
First 10 digits: 5578452507
Length: 2771010
gleam run -- 19  746,17s user 64,37s system 497% cpu 2:42,92 total
x@myfreebsd:~/GLEAM2/hello_gpu7 %

I used NTT at the end. (integer basesd fft).
 
Back
Top