Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

GPU Prime Generator

Every prime in your range. Saved in order. Tuned to your PC.

A native desktop app and command-line tool for generating, counting, and verifying prime numbers. It combines a CUDA segmented sieve with a fast CPU engine, measures which settings suit your workload, and saves ordinary text, binary values, or compact resumable datasets.

Download · Getting started · Output formats · Hardware support · Build from source

Native tests License: MIT

The native Windows application after a real prime-generation run

A real application screenshot. The dashboard uses engine results and available hardware sensors.

What you can do

  • Generate a list directly to .txt, raw .bin, or compressed .gprime output.
  • Count primes without building or transferring a large list.
  • Optimize for your PC using repeated, checked CPU and NVIDIA measurements.
  • Pause, stop, and resume from saved coverage, including intervals containing no primes.
  • Verify native datasets for corruption or compare their complete sequences mathematically.
  • Work alongside other apps with bounded memory, CPU budgets, and a Coexistence profile.

Both interfaces use the same C++20 engine. Normal operation is offline, with no account, Python environment, or background service required.

Download for Windows

The release focus is Windows x64 with Intel CPUs and NVIDIA GPUs. Version 0.2.0 is available as a portable preview:

Download Choose this for
NVIDIA + CPU ZIP Automatic CPU/NVIDIA selection, with CPU fallback when CUDA is unavailable
CPU ZIP CPU operation without an NVIDIA driver requirement

Release notes · SHA-256 checksums

Extract the entire ZIP before launching. The packages include application runtime dependencies; you do not need Python, Visual Studio, Qt, or the CUDA toolkit installed to run them. The NVIDIA package needs a compatible NVIDIA driver. Downloads are unsigned portable applications; there is no installer or automatic updater.

AMD64 in the filenames means the x64 architecture, which includes Intel x64 processors.

Getting started

  1. Download and extract a Windows ZIP.
  2. Open bin/primegen-gui.exe. Keep the extracted folders together.
  3. Choose Generate, set Start to 2 and End to 1000000, and leave Plain text (.txt) selected.
  4. Choose a new output filename such as my-first-primes.txt, then click Optimize for this PC. Setup measures that workload on the destination drive and saves local settings. You can stop setup safely.
  5. Leave the backend on Auto and click Start.

That first run should save 78,498 primes, one per line. Open the .txt file in a text editor. For later runs, choose your own range and a new filename, or use Resume from output checkpoint to continue a saved job.

Generation complete means the final save and worker cleanup have finished. The banner shows the total, destination, and finish time. Job timers stop. Hardware activity remains a live reading for the whole GPU, including other applications.

Hardware support

Version 0.2.0 is a Windows preview. Compiling for a GPU generation is distinct from testing on a physical example of it.

Configuration Current status
Windows x64, RTX 3090 Ti, Intel i9-12900K Actual CPU, CUDA, GUI, recovery, and portable-package validation
Other Windows x64 Intel or AMD CPUs Portable CPU engine included; other physical CPU models unverified
NVIDIA Turing, Ampere, Ada, Hopper, Blackwell Multi-generation CUDA code included; physical validation beyond the RTX 3090 Ti remains unverified
No NVIDIA GPU or unavailable CUDA runtime CPU operation available; hidden-device fallback tested, physically driverless Windows unverified
AMD Radeon or Intel graphics CPU operation; GPU acceleration for these vendors is not implemented
Linux / CachyOS Ubuntu 24.04 CPU, offscreen GUI, and ASan/UBSan passed in CI; CachyOS and Linux GPU/package execution remain unverified
macOS / Apple Silicon No supported package or validation

The Windows CUDA package uses CUDA 13.2. Use a driver compatible with that runtime and your GPU. The app does not install or change drivers. See NVIDIA's driver compatibility requirements.

The general CUDA build contains native targets 7.5, 8.0, 8.6, 8.9, 9.0, 10.0, and 12.0, plus 12.0 PTX. Older GPUs can use the CPU package. The dedicated 3090ti preset remains available for compute capability 8.6. See platform and packaging notes.

How automatic setup works

Optimize for this PC checks exact candidate results, warms up the engine, and compares three measured samples per candidate. It tests GPU launch settings, workload sizes, one or two compute streams, and one or two encoding workers within the selected resource budget. Complete output timing includes encoding, writing, and final synchronization.

The search has a 120-second time budget, uses at most 100 million integers per sample, and caps sample output at 128 MiB or your lower configured limit. Stopping is cooperative while current work finishes and resources are released. Scratch files are created separately on the destination drive and removed afterward. The selected output file is preserved. Expensive high starting ranges can still exceed the machine's base-prime memory budget and report a resource limitation.

Profiles are specific to the hardware, driver/runtime, resource budget, range class, mode, format, validation, durability, and destination filesystem. Changing those can require another optimization. Heavy GPU activity detected at entry prevents replacing existing tuning. Settings stay local, normally under %LOCALAPPDATA%\GpuPrimeGenerator. The app uploads nothing.

A CPU win is a valid result. Auto selects measured performance for the requested work. Without a matching profile it uses conservative CPU settings. A saved GPU configuration that fails initialization falls back before output is opened; explicit CUDA generation reports an error instead. There is no claim of a globally optimal configuration.

Memory caps and workload size adapt to available RAM and GPU capacity. Advanced limits remain available. Balanced leaves CPU headroom; Coexistence reduces resource use and adds cooperative pacing. No profile changes clocks, power settings, or the Windows GPU watchdog.

Measured on a real PC

On an Intel i9-12900K / RTX 3090 Ti, setup compared 11 configurations with three samples each for direct text output from 2 through 100,000,000. With sampled exact validation, the best tested CPU configuration took 101.83 ms and the best tested CUDA configuration took 133.04 ms at the median. These timings include setup, encoding, writing, and final synchronization. Auto correctly selected the CPU for that workload.

A separate generated text file was checked line by line against an independent sieve: 5,761,455 primes, 51,099,000 bytes. These are results for one machine and workload; performance varies with range, format, validation, storage, and background activity. See the measurements and methodology.

Choose an output format

Format Best for Contents
Plain text .txt Reading and interoperability One decimal prime per line, LF endings
Binary uint64 .bin Fixed-width values for another program Eight bytes per prime, unsigned little-endian, no header
Native .gprime Compression, native verification, recovery Versioned, checksummed chunks with range and codec metadata

Text and binary are written directly during generation. No conversion step is required. An existing native dataset can also be converted using Save as text... or the CLI export command.

For resume, keep the original output and its .checkpoint file together. Resume validates file identity and the committed prefix before continuing. It does not infer completeness from the last prime or scan every line. Copying, replacing, or editing a plain file invalidates its resume identity. A plain file remains readable without its checkpoint, but a missing plain checkpoint cannot be reconstructed. Native recovery has additional support described in the file-format documentation.

Common situations

What you see What it means or what to do
Auto selects CPU CPU won the matching measurement, or no matching profile is saved. Run Optimize for this PC with the intended range, format, and destination.
Setup deferred Other GPU activity made calibration unreliable. Existing settings are preserved; try again when the GPU is less busy.
Output already exists Choose a new filename, or resume the existing job from its checkpoint. Existing prime files are protected from automatic overwrite.
Generation complete, but GPU activity is nonzero The run has finished. The sensor shows current activity across the whole GPU, including other applications.
CUDA is unavailable Use Auto or CPU, and inspect Diagnostics or primegen.exe doctor --json for the device/runtime details. Check that your NVIDIA driver supports the packaged runtime.

Command line

From the extracted package folder, in PowerShell:

# Inspect components and run a compiled CUDA self-test when available.
.\bin\primegen.exe doctor --json

# Optimize direct text output, then use the saved profile.
.\bin\primegen.exe optimize --mode generate --format text --output primes.txt
.\bin\primegen.exe generate --start 2 --end 100000000 --format text --output primes.txt --backend auto

# Count, or write portable binary values.
.\bin\primegen.exe count --start 2 --end 100000000 --backend auto --json
.\bin\primegen.exe generate --end 1000000 --format uint64 --output primes.bin

# Generate a native dataset for up to 60 seconds, then resume it.
.\bin\primegen.exe generate --continuous --max-runtime 60 --output continuous.gprime
.\bin\primegen.exe resume --output continuous.gprime

# Verify native output or save a text copy.
.\bin\primegen.exe verify --input continuous.gprime --level exact --json
.\bin\primegen.exe export --input continuous.gprime --format text --output exported.txt

Use optimize --mode count for count-specific tuning and --report setup.json for an additional setup report. Benchmark mode and benchmark --suite quick run the broader comparison suite; --suite deep is an explicit longer search. See methodology and recorded results.

All bounds are inclusive. Input remains exact through 18446744073709551615; accepting a range does not guarantee that computation fits available memory. Ctrl+C requests a safe stop. Existing outputs are never automatically overwritten. Output paths need an existing parent directory.

--help lists resource limits, time limits, and concurrency overrides. Exit codes: 0 success, 2 invalid input, 3 unavailable backend, 4 validation failure, 5 I/O failure, 6 cancellation or stop policy, 7 resource limitation, 8 internal error.

Correctness and saving

The CUDA engine uses an exact wheel-30 tiled segmented sieve, safe shared-memory updates, presieving, and bounded sparse-prime buckets. The CPU engine uses libprimesieve. Count mode transfers counts instead of a prime array. The output pipeline has bounded queues and one ordered writer.

Validation option What it establishes
Integrity Bounds, order, uniqueness, counts, and applicable checksums; no independent completeness guarantee
Sampled exact, the default Complete comparisons for selected segments; remaining coverage is integrity-only
Full exact Every segment compared before commit; count mode compares exact counts

Durable checkpoints track covered ranges, including empty ones. Batched and per-record saving use operating-system synchronization. Buffered mode is explicitly labeled. Flush guarantees still depend on the storage device and filesystem.

Tests cover arithmetic, independent prime sequences, randomized ranges, codecs, cancellation, ordered concurrency, corrupted files, injected persistence failures, real GUI actions, and resource policies. GPU tests skip when no device is available. The acceptance record separates executed tests from unverified hardware and platforms.

Build from source

Windows

For source builds, install Git and Visual Studio 2022 C++ Build Tools with the C++ workload and CMake/Ninja tools. Use a compatible Qt 6.8+ MSVC x64 SDK, or let the optional bootstrap fetch the pinned Qt 6.8.3 SDK into .deps. The bootstrap requires Python and either 7-Zip or a compatible tar; set Qt6_ROOT to reuse an existing SDK. The scripts locate Visual Studio and initialize its build environment.

To build the general NVIDIA targets, also install CUDA Toolkit 13.2, the tested toolchain. CPU builds do not require it. See complete build and packaging notes.

git clone https://github.com/mgelsinger/gpu-prime-generator.git
cd gpu-prime-generator
.\scripts\bootstrap.ps1 -Qt

# CPU package, no CUDA toolkit required.
.\scripts\build.ps1 -Preset windows-cpu-release -Test
.\scripts\package.ps1 -Preset windows-cpu-release

# General NVIDIA package, using the tested CUDA 13.2 toolchain.
.\scripts\build.ps1 -Preset windows-cuda-release -Test
.\scripts\package.ps1 -Preset windows-cuda-release

Portable applications are staged under artifacts/packages/<preset>/bin/; ZIPs are placed in artifacts/packages/. Direct build-tree GUI launches need Qt DLLs on the launching process's PATH. Packages include required Qt and permitted runtime files.

The tested toolchain is MSVC 19.44, CMake 3.31.6, Ninja 1.12.1, Qt 6.8.3, and CUDA 13.2.78. 3090ti is the dedicated sm_86 preset. scripts/test-msvc-asan.ps1 provides CPU AddressSanitizer checks.

Linux / CachyOS

Additional source-build path and validation status

Use a compatible C++ compiler, CMake 3.28+, Ninja, and Qt. CPU builds require no CUDA toolkit:

cmake --preset linux-cpu-release
cmake --build --preset linux-cpu-release
ctest --preset linux-cpu-release --output-on-failure

CUDA builds use linux-cuda-release. On rolling distributions, select a compatible installed host compiler through CMAKE_CUDA_HOST_COMPILER when needed. See complete instructions, including the optional pinned Qt bootstrap. CachyOS runtime and Linux GPU/package acceptance remain unverified.

Project notes

Architecture · CUDA engine · File format · Benchmarks · GUI validation · Acceptance

The original Python scripts remain at the root and under prototype/ as historical reference. The native application uses neither Python nor the old per-candidate trial-division kernel, and does not alter legacy prime-output files.

Contributions are welcome, especially physical validation on other GPUs and CPUs. Include the app version, OS, component models, workload, and error when reporting a problem. Diagnostic reports contain device identifiers; remove those and private paths before sharing.

Original project code is licensed under MIT. Dependencies retain their own licenses and redistribution requirements. See third-party notices and the license files included with the package.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages