Skip to content

Commit

Permalink
Add stable-diffusion.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kurnevsky committed Dec 12, 2024
1 parent 63f8f17 commit c3f47ae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions machines/pc/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

environment.systemPackages = with pkgs; [
radeontop
(pkgs.callPackage ../../modules/stable-diffusion-cpp.nix {
useRocm = true;
gpuTargets = "gfx1100";
})
((python3.withPackages (pkgs:
with pkgs; [
# TODO: broken
Expand Down
47 changes: 47 additions & 0 deletions modules/stable-diffusion-cpp.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ lib, stdenv, config, fetchFromGitHub, cmake, rocmPackages
, useRocm ? config.rocmSupport
, gpuTargets ? builtins.concatStringsSep ";" rocmPackages.clr.gpuTargets }:

stdenv.mkDerivation {
pname = "stable-diffusion-cpp";
version = "0";

src = fetchFromGitHub {
owner = "leejet";
repo = "stable-diffusion.cpp";
rev = "4570715727f35e5a07a76796d823824c8f42206c";
hash = "sha256-1w7OokrQflasvauDEADLDJf2530m5a7WP+X1KgwxCks=";
fetchSubmodules = true;
};

nativeBuildInputs = [ cmake ];

buildInputs =
lib.optionals useRocm (with rocmPackages; [ clr hipblas rocblas ]);

cmakeFlags =
[ (lib.cmakeBool "GGML_HIP" useRocm) (lib.cmakeBool "SD_HIPBLAS" useRocm) ]
++ lib.optionals useRocm [
(lib.cmakeFeature "CMAKE_HIP_COMPILER"
"${rocmPackages.llvm.clang}/bin/clang")
(lib.cmakeFeature "CMAKE_HIP_ARCHITECTURES" gpuTargets)
(lib.cmakeFeature "AMDGPU_TARGETS" gpuTargets)
];

env = lib.optionals useRocm {
ROCM_PATH = "${rocmPackages.clr}";
HIP_DEVICE_LIB_PATH = "${rocmPackages.rocm-device-libs}/amdgcn/bitcode";
};

NIX_CFLAGS_COMPILE = [ "-O3" "-march=native" "-mtune=native" ];
NIX_ENFORCE_NO_NATIVE = false;
preferLocalBuild = true;
allowSubstitutes = false;

meta = {
description = "Stable Diffusion in pure C/C++";
homepage = "https://github.com/leejet/stable-diffusion.cpp";
license = lib.licenses.mit;
mainProgram = "sd";
};
}

0 comments on commit c3f47ae

Please sign in to comment.