Просмотр исходного кода

vulkan: use a more appropriate amount of threads when generating shaders (#16418)

* use a more flexible amount of threads

* fix windows compile and 0 thread case

* nominmax
Eve 3 месяцев назад
Родитель
Сommit
86df2c9ae4
1 измененных файлов с 2 добавлено и 3 удалено
  1. 2 3
      ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp

+ 2 - 3
ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp

@@ -1,5 +1,3 @@
-
-
 #include <iostream>
 #include <iostream>
 #include <fstream>
 #include <fstream>
 #include <sstream>
 #include <sstream>
@@ -22,6 +20,7 @@
 #include <sys/types.h>
 #include <sys/types.h>
 
 
 #ifdef _WIN32
 #ifdef _WIN32
+    #define NOMINMAX
     #include <windows.h>
     #include <windows.h>
     #include <direct.h> // For _mkdir on Windows
     #include <direct.h> // For _mkdir on Windows
 #else
 #else
@@ -306,7 +305,7 @@ using compile_count_guard = std::unique_ptr<uint32_t, decltype(&decrement_compil
 compile_count_guard acquire_compile_slot() {
 compile_count_guard acquire_compile_slot() {
     // wait until fewer than N compiles are in progress.
     // wait until fewer than N compiles are in progress.
     // 16 is an arbitrary limit, the goal is to avoid "failed to create pipe" errors.
     // 16 is an arbitrary limit, the goal is to avoid "failed to create pipe" errors.
-    uint32_t N = 16;
+    uint32_t N = std::max(1u, std::min(16u, std::thread::hardware_concurrency()));
     std::unique_lock<std::mutex> guard(compile_count_mutex);
     std::unique_lock<std::mutex> guard(compile_count_mutex);
     compile_count_cond.wait(guard, [N] { return compile_count < N; });
     compile_count_cond.wait(guard, [N] { return compile_count < N; });
     compile_count++;
     compile_count++;