-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnn.nix
105 lines (102 loc) · 2.76 KB
/
mnn.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
pkgs,
stdenv,
gcc12Stdenv,
darwin,
lib,
cmake,
vulkan-headers,
vulkan-loader,
fetchFromGitHub,
cudatoolkit,
buildPortable ? true,
buildConverter ? false,
buildTools ? false,
buildLlm ? false,
buildDiffusion ? false,
enableVulkan ? stdenv.isLinux,
enableCuda ? false,
enableOpencl ? (stdenv.isLinux || stdenv.isDarwin),
buildOpencv ? buildDiffusion,
imgcodecs ? buildDiffusion,
enableOpenmp ? true,
enableMetal ? stdenv.isDarwin,
enableAppleFramework ? false,
enableShared ? false,
enableSepBuild ? enableShared,
useSystemLib ? false,
src ?
fetchFromGitHub {
owner = "alibaba";
repo = "MNN";
# rev = version;
# hash = "sha256-7kpErL53VHksUurTUndlBRNcCL8NRpVuargMk0EBtxA="; 2.9.0
rev = "d9f7679db27e6beb84703b9757f48af063f48ebb";
sha256 = "sha256-fnoCwZfnnPVZDq0irMRCD/AD0AMxRsHWGKHpuccbr48=";
},
version ? "3.0.1",
patches ? [
],
}: let
cmakeFlag = flag: cflag:
"-D"
+ cflag
+ "="
+ (
if flag
then "ON"
else "OFF"
);
in
(
if enableCuda && stdenv.isDarwin
then throw "Cuda is not supported on darwin"
else if enableCuda
then gcc12Stdenv
else stdenv
)
.mkDerivation rec {
inherit src patches version;
pname = "mnn";
cmakeFlags =
lib.attrsets.mapAttrsToList (name: value: (cmakeFlag value name))
{
"MNN_USE_SYSTEM_LIB" = useSystemLib;
"MNN_BUILD_LLM" = buildLlm;
"MNN_BUILD_DIFFUSION" = buildDiffusion;
"MNN_BUILD_SHARED_LIBS" = enableShared;
"MNN_SEP_BUILD" = enableSepBuild;
"MNN_AAPL_FMWK" = enableAppleFramework;
"MNN_OPENCL" = enableOpencl;
"MNN_BUILD_TOOLS" = buildTools;
"MNN_BUILD_CONVERTER" = buildConverter;
"MNN_PORTABLE_BUILD" = buildPortable;
"MNN_METAL" = enableMetal;
"MNN_OPENMP" = enableOpenmp;
"MNN_VULKAN" = enableVulkan;
"MNN_CUDA" = enableCuda;
"MNN_BUILD_OPENCV" = buildOpencv;
"MNN_IMGCODECS" = imgcodecs;
};
installPhase = ''
runHook preInstall
cmake --build . --target install
${lib.strings.optionalString buildConverter "mkdir -p $out/bin && cp MNNConvert $out/bin"}
${lib.strings.optionalString (buildDiffusion && buildOpencv && imgcodecs) "mkdir -p $out/bin && cp diffusion_demo $out/bin"}
runHook postInstall
'';
nativeBuildInputs = [cmake] ++ lib.optionals enableCuda [cudatoolkit];
buildInputs =
lib.optionals enableCuda [cudatoolkit]
++ (
if stdenv.isDarwin
then
(
[
pkgs.apple-sdk_13
]
++ lib.optionals enableVulkan [darwin.moltenvk]
)
else (lib.optionals enableVulkan [vulkan-headers vulkan-loader])
);
}