mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-10 19:06:33 +00:00
fix: limit default MSVC compilation parallelism
This commit is contained in:
1 parent
008b9a20ca
commit
991f825583
2 files changed
+36
-2
No files matched your search
+17
-2
@@ -9,13 +9,28 @@ if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
cmake_host_system_information(RESULT SD_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
|
||||
if (SD_LOGICAL_CORES GREATER 8)
|
||||
math(EXPR SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES} - 2")
|
||||
elseif (SD_LOGICAL_CORES GREATER 2)
|
||||
math(EXPR SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES} - 1")
|
||||
else()
|
||||
set(SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES}")
|
||||
endif()
|
||||
if (NOT SD_DEFAULT_MSVC_MP_COUNT GREATER 0)
|
||||
set(SD_DEFAULT_MSVC_MP_COUNT 1)
|
||||
endif()
|
||||
set(SD_MSVC_MP_COUNT "${SD_DEFAULT_MSVC_MP_COUNT}" CACHE STRING "Maximum parallel MSVC compilations per project")
|
||||
if (NOT SD_MSVC_MP_COUNT MATCHES "^[1-9][0-9]*$" OR SD_MSVC_MP_COUNT GREATER 65536)
|
||||
message(FATAL_ERROR "SD_MSVC_MP_COUNT must be an integer between 1 and 65536")
|
||||
endif()
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_definitions(_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
# /MP is MSVC-only: icx rejects it outright once offloading is enabled.
|
||||
add_compile_options(
|
||||
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:/MP>
|
||||
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:/MP${SD_MSVC_MP_COUNT}>
|
||||
$<$<COMPILE_LANGUAGE:C>:/utf-8>
|
||||
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/MP>
|
||||
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/MP${SD_MSVC_MP_COUNT}>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:/utf-8>
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -21,6 +21,25 @@ git pull origin master
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## MSVC compilation parallelism
|
||||
|
||||
MSVC builds limit parallel C/C++ compilation within each project by default.
|
||||
For `n` logical processors, the limit is `n` when `n <= 2`, `n - 1` when
|
||||
`3 <= n <= 8`, and `n - 2` when `n > 8`. The default is calculated when the
|
||||
build directory is first configured with this setting. Override it with
|
||||
`-DSD_MSVC_MP_COUNT=4`, or pass `-USD_MSVC_MP_COUNT` to recalculate it.
|
||||
|
||||
For Visual Studio builds, keep project-level parallelism at one to avoid
|
||||
multiplying the per-project limit:
|
||||
|
||||
```shell
|
||||
cmake --build build --config Release --parallel 1
|
||||
```
|
||||
|
||||
This setting controls MSVC's `/MP` option, not CUDA compiler parallelism or a
|
||||
hard CPU usage limit. Other build tools, such as Ninja, schedule compilation
|
||||
jobs separately; use `cmake --build build --parallel N` to limit those jobs.
|
||||
|
||||
## Selecting a GGML source tree
|
||||
|
||||
By default, sd.cpp builds the patched GGML submodule in `ggml/`. To build with
|
||||
|
||||
Reference in new issue
Block a user