1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 rocmUpdateScript,
6 cmake,
7 rocm-cmake,
8 clr,
9 rocrand,
10 gtest,
11 buildTests ? false,
12 gpuTargets ? [ ],
13}:
14
15stdenv.mkDerivation (finalAttrs: {
16 pname = "hiprand";
17 version = "6.3.3";
18
19 outputs = [
20 "out"
21 ]
22 ++ lib.optionals buildTests [
23 "test"
24 ];
25
26 src = fetchFromGitHub {
27 owner = "ROCm";
28 repo = "hipRAND";
29 rev = "rocm-${finalAttrs.version}";
30 hash = "sha256-TVc+qFwRiS5tAo1OKI1Wu5hadlwPZmSVZ9SvVvH1w7Y=";
31 };
32
33 nativeBuildInputs = [
34 cmake
35 rocm-cmake
36 clr
37 ];
38
39 buildInputs = [ rocrand ] ++ (lib.optionals buildTests [ gtest ]);
40
41 cmakeFlags = [
42 "-DHIP_ROOT_DIR=${clr}"
43 # Manually define CMAKE_INSTALL_<DIR>
44 # See: https://github.com/NixOS/nixpkgs/pull/197838
45 "-DCMAKE_INSTALL_BINDIR=bin"
46 "-DCMAKE_INSTALL_LIBDIR=lib"
47 "-DCMAKE_INSTALL_INCLUDEDIR=include"
48 ]
49 ++ lib.optionals (gpuTargets != [ ]) [
50 "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}"
51 ]
52 ++ lib.optionals buildTests [
53 "-DBUILD_TEST=ON"
54 ];
55
56 postInstall = lib.optionalString buildTests ''
57 mkdir -p $test/bin
58 mv $out/bin/test_* $test/bin
59 rm -r $out/bin/hipRAND
60 # Fail if bin/ isn't actually empty
61 rmdir $out/bin
62 '';
63
64 passthru.updateScript = rocmUpdateScript {
65 name = finalAttrs.pname;
66 inherit (finalAttrs.src) owner;
67 inherit (finalAttrs.src) repo;
68 };
69
70 meta = with lib; {
71 description = "HIP wrapper for rocRAND and cuRAND";
72 homepage = "https://github.com/ROCm/hipRAND";
73 license = with licenses; [ mit ];
74 teams = [ teams.rocm ];
75 platforms = platforms.linux;
76 };
77})