8000 vulkan: Set limit for task concurrency (#5427) · mglambda/llama.cpp@4b7b38b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b7b38b

Browse files
authored
vulkan: Set limit for task concurrency (ggml-org#5427)
A common default for the maximum number of open files is 256, which can lead to `asyncio.gather(*tasks)` failing with Too many open files. $ python ggml_vk_generate_shaders.py --glslc=$ANDROID_NDK_PATH/shader-tools/darwin-x86_64/glslc ggml_vulkan: Generating and compiling shaders to SPIR-V Traceback (most recent call last): File "/Users/neuman/Code.noindex/github/llama.cpp/ggml_vk_generate_shaders.py", line 2326, in <module> asyncio.run(main()) File "/Users/neuman/Code.noindex/miniforge3/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Users/neuman/Code.noindex/miniforge3/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/Users/neuman/Code.noindex/github/llama.cpp/ggml_vk_generate_shaders.py", line 2294, in main await asyncio.gather(*tasks) [...snip...] OSError: [Errno 24] Too many open files This change sets a reasonable concurrency limit for tasks (and therefore open files), without significant impact on run time.
1 parent e00d2a6 commit 4b7b38b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ggml_vk_generate_shaders.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,8 @@
20672067

20682068
K_QUANTS_PER_ITERATION = 2
20692069

2070+
ASYNCIO_CONCURRENCY = 64
2071+
20702072
output_dir = gettempdir()
20712073

20722074
lock = asyncio.Lock()
@@ -2291,7 +2293,14 @@ async def main():
22912293
tasks.append(string_to_spv("rope_neox_f32", rope_neox_src, {"A_TYPE": "float", "D_TYPE": "float"}))
22922294
tasks.append(string_to_spv("rope_neox_f16", rope_neox_src, {"A_TYPE": "float16_t", "D_TYPE": "float16_t"}))
22932295

2294-
await asyncio.gather(*tasks)
2296+
# Helper to decorate tasks with semaphore acquisition.
2297+
async def withSemaphore(sem, task):
2298+
async with sem:
2299+
return await task
2300+
2301+
# Run tasks concurrently guarded by a concurrency limit.
2302+
sem = asyncio.Semaphore(ASYNCIO_CONCURRENCY)
2303+
await asyncio.gather(*(withSemaphore(sem, task) for task in tasks))
22952304

22962305
with open("ggml-vulkan-shaders.hpp", "w") as f:
22972306
f.write("#include <cstdint>\n\n")

0 commit comments

Comments
 (0)
0