Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Hermann-SW / ecm.cpp
Created October 9, 2026 21:18
After longer discussion with Gemini on Lenstra's ECM factoring method I got sample code that worked ...
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
#include <chrono>
#include <gmpxx.h>
#include <gmp.h>
class FactorFoundException : public std::exception {
public:
@Hermann-SW
Hermann-SW / ec_ipts.gp
Created October 9, 2026 18:36
Script to test differences on how SageMath and PARI/GP determine integral points on elliptic curves
sage(cmd) = eval(externstr(Str("sage -q -c \"", cmd, "\""))[1]);
ellintpoints(E) = {
sage(Str("print([[int(P[0]), int(P[1])] for P in EllipticCurve(",
E[1..5],").integral_points(both_signs=True)])"));
}
as=eval(getenv("as"));
E=ellinit(as);
print(" E[1..5]=",E[1..5]);
@Hermann-SW
Hermann-SW / integral_points_coefficients.gp
Created October 6, 2026 22:19
demonstrate how to call sagemath E.integral_points() from PARI/GP
sage(cmd) = eval(externstr(Str("sage -q -c \"", cmd, "\""))[1]);
ellintpoints(E) = {
sage(Str("print([[int(P[0]), int(P[1])] for P in EllipticCurve(",
E[1..5],").integral_points()])"));
}
xy=eval(getenv("xy"));
[y1,x1]=xy;
[x2,y2]=xy;x2*=-1;
@Hermann-SW
Hermann-SW / is_prime_u32.cpp
Created September 20, 2026 08:50
100% deterministic Miller-Rabin primality test for N < 2^32
#include <iostream>
#include <cstdint>
#include <gmpxx.h>
#include <cassert>
#include <omp.h>
// Single-round Miller-Rabin test using GMP modular exponentiation
inline bool miller_rabin_test(uint32_t n, uint32_t a, uint32_t d, int s) {
mpz_class base(a), exp(d), mod(n), x;
@Hermann-SW
Hermann-SW / build_graph.py
Last active October 14, 2026 23:48
Latex labels for Graphviz (work in progress)
This Python script became obsolete with this new repo:
https://github.com/Hermann-SW/graphviz_latex_pipeline
Because that repo's texdot.py compiles the LaTeX in each node or edge separately, with the real LaTeX.
You can still access this gist's Python code by opening the file at earlier revisions.
@Hermann-SW
Hermann-SW / gfx900_multi_precision_bench.cpp
Last active August 29, 2026 12:37
INT16 add and mul as well as FP16 fma benchmark for gfx900 GPUS
/*
f=gfx900_multi_precision_bench
hipcc -O3 --offload-arch=gfx900 $f.cpp -o $f
*/
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <iostream>
#include <iomanip>
#include <vector>
@Hermann-SW
Hermann-SW / mi50_multi_precision_bench.cpp
Created August 12, 2026 09:53
Multi GPU INT4/INT8/FP16 benchmark from long gemini session
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <iostream>
#include <vector>
#include <thread>
#include <chrono>
#include <iomanip>
#include <atomic>
#include <string>
@Hermann-SW
Hermann-SW / benchmark_fp8_ptx.cu
Created August 2, 2026 20:02
Synthetic benchmark from long gemini session for >170 TFLOPS FP8
#include <iostream>
#include <cstdint>
#include <cuda_runtime.h>
#define CUDA_CHECK(status) \
do { \
cudaError_t err = (status); \
if (err != cudaSuccess) { \
std::cerr << "[CUDA Error] " << cudaGetErrorString(err) \
<< " (" << err << ") at line " << __LINE__ << std::endl; \
@Hermann-SW
Hermann-SW / benchmark_fp16.cu
Created August 1, 2026 22:01
Demonstrate 77 TFLOPS FP16 (__half) on NVIDIA RTX 5060 GPU
#include <iostream>
#include <vector>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#define CUDA_CHECK(status) \
if (status != cudaSuccess) { \
std::cerr << "CUDA Error: " << cudaGetErrorString(status) \
<< " at line " << __LINE__ << std::endl; \
exit(EXIT_FAILURE); \
@Hermann-SW
Hermann-SW / AVX2.vsqrtpd.cpp
Created June 26, 2026 20:23
Demonstrate maximal "double sqrt" GFLOPS performance for AVX2 CPUs
/*
f=AVX2.vsqrtpd
g++ -O3 -fopenmp -Wall -Wextra -pedantic $f.cpp -o $f
cpplint --filter=-legal/copyright $f.cpp
cppcheck --enable=all --suppress=missingIncludeSystem $f.cpp --check-config
echo off | sudo tee /sys/devices/system/cpu/smt/control
echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid
perf stat -a -e cycles,instructions,task-clock ./$f