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