1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, rocm-cmake
6, rocm-runtime
7, rocm-device-libs
8, rocm-comgr
9, hip
10, sqlite
11, python3
12, gtest ? null
13, boost ? null
14, fftw ? null
15, fftwFloat ? null
16, llvmPackages ? null
17, buildTests ? false
18, buildBenchmarks ? false
19}:
20
21assert buildTests -> gtest != null;
22assert buildBenchmarks -> fftw != null;
23assert buildBenchmarks -> fftwFloat != null;
24assert (buildTests || buildBenchmarks) -> boost != null;
25assert (buildTests || buildBenchmarks) -> llvmPackages != null;
26
27stdenv.mkDerivation rec {
28 pname = "rocfft";
29 rocmVersion = "5.3.1";
30 version = "1.0.18-${rocmVersion}";
31
32 outputs = [
33 "out"
34 ] ++ lib.optionals buildTests [
35 "test"
36 ] ++ lib.optionals buildBenchmarks [
37 "benchmark"
38 ];
39
40 src = fetchFromGitHub {
41 owner = "ROCmSoftwarePlatform";
42 repo = "rocFFT";
43 rev = "rocm-${rocmVersion}";
44 hash = "sha256-jb2F1fRe+YLloYJ/KtzrptUDhmdBDBtddeW/g55owKM=";
45 };
46
47 nativeBuildInputs = [
48 cmake
49 rocm-cmake
50 hip
51 ];
52
53 buildInputs = [
54 rocm-runtime
55 rocm-device-libs
56 rocm-comgr
57 sqlite
58 python3
59 ] ++ lib.optionals buildTests [
60 gtest
61 ] ++ lib.optionals (buildTests || buildBenchmarks) [
62 boost
63 fftw
64 fftwFloat
65 llvmPackages.openmp
66 ];
67
68 propogatedBuildInputs = lib.optionals buildTests [
69 fftw
70 fftwFloat
71 ];
72
73 cmakeFlags = [
74 "-DCMAKE_C_COMPILER=hipcc"
75 "-DCMAKE_CXX_COMPILER=hipcc"
76 "-DUSE_HIP_CLANG=ON"
77 "-DSQLITE_USE_SYSTEM_PACKAGE=ON"
78 # Manually define CMAKE_INSTALL_<DIR>
79 # See: https://github.com/NixOS/nixpkgs/pull/197838
80 "-DCMAKE_INSTALL_BINDIR=bin"
81 "-DCMAKE_INSTALL_LIBDIR=lib"
82 "-DCMAKE_INSTALL_INCLUDEDIR=include"
83 ] ++ lib.optionals buildTests [
84 "-DBUILD_CLIENTS_TESTS=ON"
85 ] ++ lib.optionals buildBenchmarks [
86 "-DBUILD_CLIENTS_RIDER=ON"
87 "-DBUILD_CLIENTS_SAMPLES=ON"
88 ];
89
90 postInstall = lib.optionalString buildTests ''
91 mkdir -p $test/{bin,lib/fftw}
92 cp -a $out/bin/* $test/bin
93 ln -s ${fftw}/lib/libfftw*.so $test/lib/fftw
94 ln -s ${fftwFloat}/lib/libfftw*.so $test/lib/fftw
95 rm -r $out/lib/fftw
96 rm $test/bin/{rocfft_rtc_helper,*-rider} || true
97 '' + lib.optionalString buildBenchmarks ''
98 mkdir -p $benchmark/bin
99 cp -a $out/bin/* $benchmark/bin
100 rm $benchmark/bin/{rocfft_rtc_helper,*-test} || true
101 '' + lib.optionalString (buildTests || buildBenchmarks ) ''
102 mv $out/bin/rocfft_rtc_helper $out
103 rm -r $out/bin/*
104 mv $out/rocfft_rtc_helper $out/bin
105 '';
106
107 meta = with lib; {
108 description = "FFT implementation for ROCm ";
109 homepage = "https://github.com/ROCmSoftwarePlatform/rocFFT";
110 license = with licenses; [ mit ];
111 maintainers = with maintainers; [ Madouura ];
112 broken = rocmVersion != hip.version;
113 hydraPlatforms = [ ]; # rocFFT produces an extremely large output
114 };
115}