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