biome: 1.9.2 -> 1.9.3 (#349335)
[NixPkgs.git] / pkgs / development / rocm-modules / 5 / mivisionx / default.nix
blobb7d9762869793ad9015f20ca78a0d18fe44ef0e5
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , rocmUpdateScript
5 , cmake
6 , rocm-cmake
7 , rocm-device-libs
8 , clr
9 , pkg-config
10 , rpp
11 , rocblas
12 , miopengemm
13 , miopen
14 , migraphx
15 , clang
16 , openmp
17 , protobuf
18 , qtcreator
19 , opencv
20 , ffmpeg
21 , boost
22 , libjpeg_turbo
23 , half
24 , lmdb
25 , rapidjson
26 , rocm-docs-core
27 , python3Packages
28 , useOpenCL ? false
29 , useCPU ? false
30 , buildDocs ? false # Needs internet
31 , gpuTargets ? [ ]
34 stdenv.mkDerivation (finalAttrs: {
35   pname = "mivisionx-" + (
36     if (!useOpenCL && !useCPU) then "hip"
37     else if (!useOpenCL && !useCPU) then "opencl"
38     else "cpu"
39   );
41   version = "5.7.1";
43   src = fetchFromGitHub {
44     owner = "ROCm";
45     repo = "MIVisionX";
46     rev = "rocm-${finalAttrs.version}";
47     hash = "sha256-jmOgwESNALQt7ctmUY9JHgKq47tCwsW1ybynkX9236U=";
48   };
50   patches = [
51     ../../6/mivisionx/0001-set-__STDC_CONSTANT_MACROS-to-make-rocAL-compile.patch
52   ];
54   nativeBuildInputs = [
55     cmake
56     rocm-cmake
57     clr
58     pkg-config
59   ] ++ lib.optionals buildDocs [
60     rocm-docs-core
61     python3Packages.python
62   ];
64   buildInputs = [
65     miopengemm
66     miopen
67     migraphx
68     rpp
69     rocblas
70     openmp
71     half
72     protobuf
73     qtcreator
74     opencv
75     ffmpeg
76     boost
77     libjpeg_turbo
78     lmdb
79     rapidjson
80     python3Packages.pybind11
81     python3Packages.numpy
82     python3Packages.torchWithRocm
83   ];
85   cmakeFlags = [
86     "-DROCM_PATH=${clr}"
87     "-DAMDRPP_PATH=${rpp}"
88     # Manually define CMAKE_INSTALL_<DIR>
89     # See: https://github.com/NixOS/nixpkgs/pull/197838
90     "-DCMAKE_INSTALL_BINDIR=bin"
91     "-DCMAKE_INSTALL_LIBDIR=lib"
92     "-DCMAKE_INSTALL_INCLUDEDIR=include"
93     "-DCMAKE_INSTALL_PREFIX_PYTHON=lib"
94     # "-DAMD_FP16_SUPPORT=ON" `error: typedef redefinition with different types ('__half' vs 'half_float::half')`
95   ] ++ lib.optionals (gpuTargets != [ ]) [
96     "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}"
97   ] ++ lib.optionals (!useOpenCL && !useCPU) [
98     "-DBACKEND=HIP"
99   ] ++ lib.optionals (useOpenCL && !useCPU) [
100     "-DBACKEND=OCL"
101   ] ++ lib.optionals useCPU [
102     "-DBACKEND=CPU"
103   ];
105   postPatch = ''
106     # We need to not use hipcc and define the CXXFLAGS manually due to `undefined hidden symbol: tensorflow:: ...`
107     export CXXFLAGS+="--rocm-path=${clr} --rocm-device-lib-path=${rocm-device-libs}/amdgcn/bitcode"
108     patchShebangs rocAL/rocAL_pybind/examples
110     # Properly find miopengemm and miopen
111     substituteInPlace amd_openvx_extensions/CMakeLists.txt \
112       --replace "miopengemm PATHS \''${ROCM_PATH} QUIET" "miopengemm PATHS ${miopengemm} QUIET" \
113       --replace "miopen     PATHS \''${ROCM_PATH} QUIET" "miopen PATHS ${miopen} QUIET" \
114       --replace "\''${ROCM_PATH}/include/miopen/config.h" "${miopen}/include/miopen/config.h"
116     # Properly find turbojpeg
117     substituteInPlace amd_openvx/cmake/FindTurboJpeg.cmake \
118       --replace "\''${TURBO_JPEG_PATH}/include" "${libjpeg_turbo.dev}/include" \
119       --replace "\''${TURBO_JPEG_PATH}/lib" "${libjpeg_turbo.out}/lib"
121     # Fix bad paths
122     substituteInPlace rocAL/rocAL/rocAL_hip/CMakeLists.txt amd_openvx_extensions/amd_nn/nn_hip/CMakeLists.txt amd_openvx/openvx/hipvx/CMakeLists.txt \
123       --replace "COMPILER_FOR_HIP \''${ROCM_PATH}/llvm/bin/clang++" "COMPILER_FOR_HIP ${clang}/bin/clang++"
124   '';
126   postBuild = lib.optionalString buildDocs ''
127     python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en ../docs _build/html
128   '';
130   postInstall = lib.optionalString (!useOpenCL && !useCPU) ''
131     patchelf $out/lib/rocal_pybind*.so --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE"
132     chmod +x $out/lib/rocal_pybind*.so
133   '';
135   passthru.updateScript = rocmUpdateScript {
136     name = finalAttrs.pname;
137     owner = finalAttrs.src.owner;
138     repo = finalAttrs.src.repo;
139   };
141   meta = with lib; {
142     description = "Set of comprehensive computer vision and machine intelligence libraries, utilities, and applications";
143     homepage = "https://github.com/ROCm/MIVisionX";
144     license = with licenses; [ mit ];
145     maintainers = teams.rocm.members;
146     platforms = platforms.linux;
147     broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version || versionAtLeast finalAttrs.version "6.0.0";
148   };