-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCsub
89 lines (64 loc) · 3.85 KB
/
SCsub
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
import os
import re
from SCons.Errors import UserError
import platform
Import('env')
PLATFORM = env['platform']
ARCH = env['arch']
supported = []
print(PLATFORM)
if PLATFORM == 'windows' or PLATFORM == 'linuxbsd':
supported = ['cpu', 'cuda', 'cublas', 'rocm', 'hipblas']
elif PLATFORM == 'macos':
supported = ['cpu', 'metal']
backend = ARGUMENTS.get('backend', 'cpu')
_libsdir = "/usr/x86_64-w64-mingw32/lib/" if platform.system() == "Linux" else 'C:\\ProgramData\\mingw64\\mingw64\\x86_64-w64-mingw32\\lib'
libsdir = ARGUMENTS.get('mingw_libs', _libsdir)
if backend not in supported:
raise UserError(f'Error: unsupported backend "{backend}" for platform {PLATFORM}. Supported backends: {", ".join(supported)}')
print(f"Using {backend} backend.")
env_sd = env.Clone()
env_sd.add_source_files(env.modules_sources, "*.cpp")
env_sd.Append(CPPPATH=["stable-diffusion_cpp/", "stable-diffusion_cpp/thirdparty", "stable-diffusion_cpp/ggml/include", "stable-diffusion_cpp/ggml/ggml/include", "stable-diffusion_cpp/ggml/ggml/src", "stable-diffusion_cpp/ggml/src",])
if PLATFORM == 'linuxbsd':
env_sd.Append(CCFLAGS=['-fexceptions'])
if backend == 'cpu':
env.Append(LIBPATH=["libs/platform/linuxbsd/cpu/"])
env.Append(LIBS=[env.File("libs/platform/linuxbsd/cpu/libstable-diffusion.a"), env.File("libs/platform/linuxbsd/cpu/libggml.a"), env.File("/usr/lib/libgomp.so"), env.File("/usr/lib/libpthread.a")])
elif backend == 'cuda' or backend == 'cublas':
env.Append(LIBPATH=["libs/platform/linuxbsd/cuda/"])
env.Append(LIBS=[env.File("libs/platform/linuxbsd/cuda/libstable-diffusion.a"), env.File("libs/platform/linuxbsd/cuda/libggml.a"), env.File("/usr/lib/libgomp.so"), env.File("/usr/lib/libpthread.a"), env.File("/opt/cuda/targets/x86_64-linux/lib/libcudart.so"), env.File("/opt/cuda/targets/x86_64-linux/lib/libcublas.so"), env.File("/opt/cuda/targets/x86_64-linux/lib/libculibos.a"), env.File("/opt/cuda/targets/x86_64-linux/lib/libcublasLt.so"), env.File("/opt/cuda/targets/x86_64-linux/lib/stubs/libcuda.so"), "dl", env.File("/usr/lib/librt.a"), "m"])
elif backend == 'rocm' or backend == 'hipblas': # TODO: somebody with an AMD GPU figure out necessary libs to link with hipblas.
raise UserError(f'Error: unsupported backend "{backend}" for {PLATFORM}. Not yet available')
if PLATFORM == 'windows': # TODO: Windows platform
if backend == 'cpu':
env_sd.Append(CCFLAGS=['-fexceptions',])
env.Append(LIBPATH=["libs/platform/win/cpu/", libsdir])
system_libs = [ env.File(os.path.join(libsdir, f"lib{l}.a")) for l in [
"mingwthrd",
"kernel32",
"user32",
"gdi32",
"winspool",
"shell32",
"ole32",
"oleaut32",
"uuid",
"comdlg32",
"advapi32",
]]
gomp = [env.File("C:\\ProgramData\\mingw64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\13.2.0\\libgomp.a")]
libs = [env.File("libs/platform/win/cpu/libstable-diffusion.a"), env.File("libs/platform/win/cpu/libggml.a")] + gomp + system_libs
env.Append(LIBS=libs)
elif backend == 'cuda' or backend == 'cublas':
env.Append(LIBPATH=["libs/platform/win/cuda/"])
raise UserError(f'Error: unsupported backend "{backend}" for {PLATFORM}. Not yet available')
elif backend == 'rocm' or backend == 'hipblas':
env.Append(LIBPATH=["libs/platform/win/rocm/"])
raise UserError(f'Error: unsupported backend "{backend}" for {PLATFORM}. Not yet available')
if PLATFORM == 'macos': # TODO: MacOS Platform
env_sd.Append(CCFLAGS=['-fexceptions'])
if backend == 'cpu':
raise UserError(f'Error: unsupported backend "{backend}" for {PLATFORM}. Not yet available')
elif backend == 'metal':
raise UserError(f'Error: unsupported backend "{backend}" for {PLATFORM}. Not yet available')