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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
{
lib,
stdenv,
fetchFromGitHub,
cmake,
ninja,
pkg-config,
python3,
autoAddDriverRunpath,
config ? { },
cudaSupport ? (config.cudaSupport or false),
cudaPackages ? { },
rocmSupport ? (config.rocmSupport or false),
rocmPackages ? { },
rocmGpuTargets ? (rocmPackages.clr.localGpuTargets or rocmPackages.clr.gpuTargets or [ ]),
openclSupport ? false,
clblast,
vulkanSupport ? false,
shaderc,
vulkan-headers,
vulkan-loader,
spirv-tools,
metalSupport ? (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64),
darwin,
apple-sdk,
}:
let
inherit (lib)
cmakeBool
cmakeFeature
optionals
;
effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv;
in
effectiveStdenv.mkDerivation (finalAttrs: {
pname = "stable-diffusion-cpp";
version = "master-849-d04e895";
outputs = [
"out"
"dev"
];
src = fetchFromGitHub {
owner = "leejet";
repo = "stable-diffusion.cpp";
tag = finalAttrs.version;
hash = "sha256-87tEPKu8xq611fa2/tXvWujl3dypniL+DVrczKP34Qs=";
fetchSubmodules = true;
};
nativeBuildInputs = [
cmake
ninja
pkg-config
]
++ optionals cudaSupport [
(cudaPackages.cuda_nvcc)
autoAddDriverRunpath
];
buildInputs =
(optionals cudaSupport (
with cudaPackages;
[
cccl
cuda_cudart
libcublas
]
))
++ (optionals rocmSupport (
with rocmPackages;
[
clr
hipblas
rocblas
]
))
++ (optionals vulkanSupport [
shaderc
vulkan-headers
vulkan-loader
spirv-tools
])
++ (optionals openclSupport [
clblast
])
++ (optionals metalSupport [
apple-sdk
]);
cmakeFlags = [
(cmakeBool "SD_BUILD_EXAMPLES" true)
(cmakeBool "SD_BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic))
(cmakeBool "SD_USE_SYSTEM_GGML" false)
(cmakeBool "SD_CUDA" cudaSupport)
(cmakeBool "SD_HIPBLAS" rocmSupport)
(cmakeBool "SD_VULKAN" vulkanSupport)
(cmakeBool "SD_OPENCL" openclSupport)
(cmakeBool "SD_METAL" metalSupport)
(cmakeBool "SD_FAST_SOFTMAX" false)
]
++ optionals cudaSupport [
(cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaPackages.flags.cmakeCudaArchitecturesString)
]
++ optionals rocmSupport [
(cmakeFeature "CMAKE_HIP_ARCHITECTURES" (builtins.concatStringsSep ";" rocmGpuTargets))
];
meta = {
description = "Stable Diffusion inference in pure C/C++";
homepage = "https://github.com/leejet/stable-diffusion.cpp";
license = lib.licenses.mit;
mainProgram = "sd";
maintainers = with lib.maintainers; [
adriangl
jk
];
platforms = lib.platforms.unix;
badPlatforms = lib.optionals (cudaSupport || openclSupport) lib.platforms.darwin;
broken = metalSupport && !stdenv.hostPlatform.isDarwin;
};
})
|