|
| 1 | +{ |
| 2 | + lib, |
| 3 | + fetchFromGitHub, |
| 4 | + llvmPackages_18, |
| 5 | + python3, |
| 6 | + cmake, |
| 7 | + boost, |
| 8 | + libxml2, |
| 9 | + libffi, |
| 10 | + makeWrapper, |
| 11 | + config, |
| 12 | + cudaPackages, |
| 13 | + rocmPackages_6, |
| 14 | + ompSupport ? true, |
| 15 | + openclSupport ? false, |
| 16 | + rocmSupport ? config.rocmSupport, |
| 17 | + cudaSupport ? config.cudaSupport, |
| 18 | + autoAddDriverRunpath, |
| 19 | + runCommand, |
| 20 | + callPackage, |
| 21 | + symlinkJoin, |
| 22 | + nix-update-script, |
| 23 | +}: |
| 24 | +let |
| 25 | + inherit (llvmPackages) stdenv; |
| 26 | + rocmPackages = rocmPackages_6; |
| 27 | + llvmPackages = llvmPackages_18; |
| 28 | +in |
| 29 | +stdenv.mkDerivation (finalAttrs: { |
| 30 | + pname = "adaptivecpp"; |
| 31 | + version = "24.10.0"; |
| 32 | + |
| 33 | + src = fetchFromGitHub { |
| 34 | + owner = "AdaptiveCpp"; |
| 35 | + repo = "AdaptiveCpp"; |
| 36 | + rev = "v${finalAttrs.version}"; |
| 37 | + sha256 = "sha256-ZwHDiwv1ybC+2UhiOe2f7fnfqcul+CD9Uta8PT9ICr4="; |
| 38 | + }; |
| 39 | + |
| 40 | + # we may be able to get away with just wrapping hipcc and nothing more |
| 41 | + # this is mainly so that if acpp tries doing <PATH_TO_HIPCC>/../amdgcn/bitcode |
| 42 | + rocmMerged = symlinkJoin { |
| 43 | + name = "rocm-merged"; |
| 44 | + paths = with rocmPackages; [ |
| 45 | + clr |
| 46 | + rocm-core |
| 47 | + rocm-device-libs |
| 48 | + rocm-runtime |
| 49 | + ]; |
| 50 | + buildInputs = [ makeWrapper ]; |
| 51 | + postBuild = '' |
| 52 | + wrapProgram $out/bin/hipcc \ |
| 53 | + --add-flags "--rocm-device-lib-path=$out/amdgcn/bitcode" |
| 54 | + ''; |
| 55 | + }; |
| 56 | + |
| 57 | + nativeBuildInputs = |
| 58 | + [ |
| 59 | + cmake |
| 60 | + makeWrapper |
| 61 | + ] |
| 62 | + ++ lib.optionals cudaSupport [ |
| 63 | + autoAddDriverRunpath |
| 64 | + cudaPackages.cuda_nvcc |
| 65 | + ]; |
| 66 | + |
| 67 | + buildInputs = |
| 68 | + [ |
| 69 | + libxml2 |
| 70 | + libffi |
| 71 | + boost |
| 72 | + python3 |
| 73 | + llvmPackages.openmp |
| 74 | + llvmPackages.libclang.dev |
| 75 | + llvmPackages.llvm |
| 76 | + ] |
| 77 | + ++ lib.optionals cudaSupport [ |
| 78 | + cudaPackages.cuda_cudart |
| 79 | + (lib.getOutput "stubs" cudaPackages.cuda_cudart) |
| 80 | + ]; |
| 81 | + |
| 82 | + # adaptivecpp makes use of clangs internal headers. Its cmake does not successfully discover them automatically on nixos, so we supply the path manually |
| 83 | + cmakeFlags = |
| 84 | + [ |
| 85 | + (lib.cmakeFeature "CLANG_INCLUDE_PATH" "${llvmPackages.libclang.dev}/include") |
| 86 | + (lib.cmakeBool "WITH_CPU_BACKEND" ompSupport) |
| 87 | + (lib.cmakeBool "WITH_CUDA_BACKEND" cudaSupport) |
| 88 | + (lib.cmakeBool "WITH_ROCM_BACKEND" rocmSupport) |
| 89 | + (lib.cmakeBool "WITH_OPENCL_BACKEND" openclSupport) |
| 90 | + ] |
| 91 | + ++ lib.optionals rocmSupport [ |
| 92 | + (lib.cmakeFeature "HIPCC_COMPILER" "${finalAttrs.rocmMerged}/bin/hipcc") |
| 93 | + (lib.cmakeFeature "ROCM_PATH" "${finalAttrs.rocmMerged}") |
| 94 | + ]; |
| 95 | + |
| 96 | + # this hardening option breaks rocm builds |
| 97 | + hardeningDisable = [ "zerocallusedregs" ]; |
| 98 | + |
| 99 | + passthru = { |
| 100 | + tests = |
| 101 | + # Loosely based on the AdaptiveCpp GitHub CI: https://github.com/AdaptiveCpp/AdaptiveCpp/blob/develop/.github/workflows/linux.yml |
| 102 | + # This may be overkill, especially as this won't be run on GPU on the CI |
| 103 | + let |
| 104 | + runner = targets: enablePstlTests: callPackage ./tests.nix { inherit enablePstlTests; }; |
| 105 | + run = |
| 106 | + runner: cmd: mask: |
| 107 | + runCommand cmd { } '' |
| 108 | + # the test runner wants to write to $HOME/.acpp, so we need to have it point to a real directory |
| 109 | + mkdir home |
| 110 | + export HOME=`pwd`/home |
| 111 | +
|
| 112 | + ACPP_VISIBILITY_MASK="${mask}" ${runner}/bin/${cmd} && touch $out |
| 113 | + ''; |
| 114 | + runSycl = runner: mask: run runner "sycl_tests" mask; |
| 115 | + runPstl = runner: mask: run runner "pstl_tests" mask; |
| 116 | + runner-omp = runner "omp" false; |
| 117 | + runner-sscp = runner "generic" true; |
| 118 | + in |
| 119 | + { |
| 120 | + inherit runner-omp runner-sscp; |
| 121 | + sycl-omp = runSycl runner-omp "omp"; |
| 122 | + sycl-sscp = runSycl runner-sscp "omp"; |
| 123 | + pstl-sscp = runPstl runner-sscp "omp"; |
| 124 | + } |
| 125 | + // lib.optionalAttrs rocmSupport ( |
| 126 | + let |
| 127 | + runner-rocm = runner "hip:gfx906" false; |
| 128 | + runner-rocm-integrated-multipass = runner "omp;hip:gfx906" false; |
| 129 | + runner-rocm-explicit-multipass = runner "omp;hip.explicit-multipass:gfx906;cuda:sm_61" false; |
| 130 | + in |
| 131 | + { |
| 132 | + inherit runner-rocm runner-rocm-integrated-multipass runner-rocm-explicit-multipass; |
| 133 | + sycl-rocm = runSycl runner-rocm "omp;hip"; |
| 134 | + sycl-rocm-imp = runSycl runner-rocm-integrated-multipass "omp;hip"; |
| 135 | + sycl-rocm-emp = runSycl runner-rocm-explicit-multipass "omp;hip"; |
| 136 | + sycl-rocm-sscp = runSycl runner-sscp "omp;hip"; |
| 137 | + pstl-rocm-sscp = runPstl runner-sscp "omp;hip"; |
| 138 | + } |
| 139 | + ) |
| 140 | + // lib.optionalAttrs cudaSupport ( |
| 141 | + let |
| 142 | + runner-cuda = runner "cuda:sm_60" false; |
| 143 | + runner-cuda-integrated-multipass = runner "omp;cuda_61" true; |
| 144 | + runner-cuda-explicit-multipass = runner "omp;cuda.explicit-multipass:sm_61;hip:gfx906" false; |
| 145 | + in |
| 146 | + { |
| 147 | + inherit runner-cuda runner-cuda-integrated-multipass runner-cuda-explicit-multipass; |
| 148 | + sycl-cuda = runSycl runner-cuda "omp;cuda"; |
| 149 | + sycl-cuda-imp = runSycl runner-cuda-integrated-multipass "omp;cuda"; |
| 150 | + sycl-cuda-emp = runSycl runner-cuda-explicit-multipass "omp;cuda"; |
| 151 | + sycl-cuda-sscp = runSycl runner-sscp "omp;cuda"; |
| 152 | + pstl-cuda-imp = runPstl runner-cuda-integrated-multipass "omp;cuda"; |
| 153 | + pstl-cuda-sscp = runPstl runner-sscp "omp;cuda"; |
| 154 | + } |
| 155 | + ); |
| 156 | + |
| 157 | + updateScript = nix-update-script { }; |
| 158 | + }; |
| 159 | + |
| 160 | + meta = with lib; { |
| 161 | + homepage = "https://github.com/AdaptiveCpp/AdaptiveCpp"; |
| 162 | + description = "Multi-backend implementation of SYCL for CPUs and GPUs"; |
| 163 | + mainProgram = "acpp"; |
| 164 | + maintainers = with maintainers; [ yboettcher ]; |
| 165 | + # Broken with current nixpkgs ROCm 6.0.2 |
| 166 | + # Works with updated ROCm, see https://github.com/NixOS/nixpkgs/pull/367695 |
| 167 | + broken = rocmSupport && strings.versionOlder rocmPackages.clr.version "6.3.1"; |
| 168 | + license = licenses.bsd2; |
| 169 | + }; |
| 170 | +}) |
0 commit comments