summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ll/llrCUDA/package.nix
blob: bcb3ad1f6cc5187faf6cdbfe6d3cf2b0bd7b0ed1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
  fetchzip,
  lib,
  gmp,
  cudaPackages,
  autoPatchelfHook,
}:
let
  inherit (cudaPackages) backendStdenv;
in
backendStdenv.mkDerivation (finalAttrs: {
  pname = "llrCUDA";
  version = "4.0.0";

  src = fetchzip {
    url = "http://jpenne.free.fr/llr4/llrcuda${
      builtins.replaceStrings [ "." ] [ "" ] finalAttrs.version
    }srcgpu12.zip";
    hash = "sha256-/v89jsTKCpkmCMKp9nUf7VAnSobE8pDdwLw5n3Hz9dw=";
  };

  enableParallelBuilding = true;

  # Disable _chdir in lprime.cu to prevent segmentation fault when fopen returns NULL
  postPatch = ''
    substituteInPlace lprime.cu \
      --replace-fail "_chdir (buf)" "0/* _chdir (buf) */"

    substituteInPlace Makefile \
      --replace-fail "/usr/local/cuda" "${cudaPackages.cuda_nvcc}"
  '';

  nativeBuildInputs = [
    autoPatchelfHook
    cudaPackages.cuda_nvcc
  ];

  buildInputs = [
    gmp
    cudaPackages.cuda_cudart
    cudaPackages.libcufft
    cudaPackages.cccl
  ];

  env = {
    NIX_LDFLAGS = lib.concatStringsSep " " [
      "-L${lib.getLib gmp}/lib"
      "-L${lib.getLib cudaPackages.cuda_cudart}/lib"
    ];
  };

  installPhase = ''
    runHook preInstall

    install -Dm755 dllrCUDA $out/bin/llrCUDA

    runHook postInstall
  '';

  meta = {
    description = "GPU version of the LLR program";
    longDescription = ''
      Primality proving program for numbers of the form N = k*b^n +/- 1, (k < b^n),
      or numbers which can be rewritten in this form, like
      Gaussian-Mersenne norms or b^n-b^m +/- 1 with n>m (new feature).
      The identity Phi(3,-X) = X^2-X+1 is now used with X=b^n to search for
      Generalized Unique Primes.
    '';
    homepage = "http://jpenne.free.fr/index2.html";
    maintainers = with lib.maintainers; [ dstremur ];
    license = lib.licenses.unfree;
    # Restricted by GWNUM terms and CUDA dependencies.
    # Its CUDA code is based on GWNUM.
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "llrCUDA";
  };
})