nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
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 miopen,
14 migraphx,
15 openmp,
16 protobuf,
17 qtcreator,
18 opencv,
19 ffmpeg,
20 boost,
21 libjpeg_turbo,
22 half,
23 lmdb,
24 rapidjson,
25 rocm-docs-core,
26 python3Packages,
27 useOpenCL ? false,
28 useCPU ? false,
29 buildDocs ? false, # Needs internet
30 gpuTargets ? [ ],
31}:
32
33stdenv.mkDerivation (finalAttrs: {
34 pname =
35 "mivisionx-"
36 + (
37 if (!useOpenCL && !useCPU) then
38 "hip"
39 else if (!useOpenCL && !useCPU) then
40 "opencl"
41 else
42 "cpu"
43 );
44
45 version = "6.3.3";
46
47 src = fetchFromGitHub {
48 owner = "ROCm";
49 repo = "MIVisionX";
50 rev = "rocm-${finalAttrs.version}";
51 hash = "sha256-SisCbUDCAiWQ1Ue7qrtoT6vO/1ztzqji+3cJD6MXUNw=";
52 };
53
54 patches = [
55 ./0001-set-__STDC_CONSTANT_MACROS-to-make-rocAL-compile.patch
56 ];
57
58 nativeBuildInputs = [
59 cmake
60 rocm-cmake
61 clr
62 pkg-config
63 ]
64 ++ lib.optionals buildDocs [
65 rocm-docs-core
66 python3Packages.python
67 ];
68
69 buildInputs = [
70 miopen
71 migraphx
72 rpp
73 rocblas
74 openmp
75 half
76 protobuf
77 qtcreator
78 opencv
79 ffmpeg
80 boost
81 libjpeg_turbo
82 lmdb
83 rapidjson
84 python3Packages.pybind11
85 python3Packages.numpy
86 python3Packages.torchWithRocm
87 ];
88
89 cmakeFlags = [
90 "-DROCM_PATH=${clr}"
91 "-DAMDRPP_PATH=${rpp}"
92 # Manually define CMAKE_INSTALL_<DIR>
93 # See: https://github.com/NixOS/nixpkgs/pull/197838
94 "-DCMAKE_INSTALL_BINDIR=bin"
95 "-DCMAKE_INSTALL_LIBDIR=lib"
96 "-DCMAKE_INSTALL_INCLUDEDIR=include"
97 "-DCMAKE_INSTALL_PREFIX_PYTHON=lib"
98 "-DOpenMP_C_INCLUDE_DIR=${openmp.dev}/include"
99 "-DOpenMP_CXX_INCLUDE_DIR=${openmp.dev}/include"
100 "-DOpenMP_omp_LIBRARY=${openmp}/lib"
101 # "-DAMD_FP16_SUPPORT=ON" `error: typedef redefinition with different types ('__half' vs 'half_float::half')`
102 ]
103 ++ lib.optionals (gpuTargets != [ ]) [
104 "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}"
105 ]
106 ++ lib.optionals (!useOpenCL && !useCPU) [
107 "-DBACKEND=HIP"
108 ]
109 ++ lib.optionals (useOpenCL && !useCPU) [
110 "-DBACKEND=OCL"
111 ]
112 ++ lib.optionals useCPU [
113 "-DBACKEND=CPU"
114 ];
115
116 postPatch = ''
117 # We need to not use hipcc and define the CXXFLAGS manually due to `undefined hidden symbol: tensorflow:: ...`
118 export CXXFLAGS+=" --rocm-path=${clr} --rocm-device-lib-path=${rocm-device-libs}/amdgcn/bitcode"
119 # Properly find miopen, fix ffmpeg version detection
120 substituteInPlace amd_openvx_extensions/CMakeLists.txt \
121 --replace-fail "miopen PATHS \''${ROCM_PATH} QUIET" "miopen PATHS ${miopen} QUIET" \
122 --replace-fail "\''${ROCM_PATH}/include/miopen/config.h" "${miopen}/include/miopen/config.h"
123
124 # Properly find turbojpeg
125 substituteInPlace cmake/FindTurboJpeg.cmake \
126 --replace-fail "\''${TURBO_JPEG_PATH}/include" "${libjpeg_turbo.dev}/include" \
127 --replace-fail "\''${TURBO_JPEG_PATH}/lib" "${libjpeg_turbo.out}/lib"
128 '';
129
130 postBuild = lib.optionalString buildDocs ''
131 python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en ../docs _build/html
132 '';
133
134 passthru.updateScript = rocmUpdateScript {
135 name = finalAttrs.pname;
136 inherit (finalAttrs.src) owner;
137 inherit (finalAttrs.src) repo;
138 };
139
140 meta = with lib; {
141 description = "Set of comprehensive computer vision and machine intelligence libraries, utilities, and applications";
142 homepage = "https://github.com/ROCm/MIVisionX";
143 license = with licenses; [ mit ];
144 teams = [ teams.rocm ];
145 platforms = platforms.linux;
146 broken = useOpenCL;
147 };
148})