Skip to content

Commit ae4e287

Browse files
committed
Ralf J's suggestion
1 parent db3d2f0 commit ae4e287

3 files changed

Lines changed: 9 additions & 74 deletions

File tree

‎.github/workflows/coverage.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ jobs:
250250
- name: Set up MSVC
251251
uses: step-security/msvc-dev-cmd@22c98154b708dbd743e6f27a933cf6ceba3305c4 # v1.13.1
252252

253+
- name: Raise the interpreter's stack reserve to 8 MiB
254+
# Importing the coverage-built cuda.bindings.driver overflows the
255+
# 2,000,000-byte main-thread stack of python-build-standalone (#3330).
256+
run: |
257+
base_py="$(.venv/Scripts/python -c 'import sys; print(sys._base_executable)')"
258+
editbin -nologo -stack:8388608 "$base_py"
259+
dumpbin -nologo -headers "$base_py" | grep -i "size of stack reserve"
260+
253261
- name: Set up mini CTK
254262
uses: ./.github/actions/fetch_ctk
255263
continue-on-error: false

‎cuda_core/build_hooks.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import re
1515
import sys
1616
import tempfile
17-
import threading
1817
import zipfile
19-
from concurrent.futures import ThreadPoolExecutor
2018
from pathlib import Path
2119

2220
import Cython as _Cython
@@ -700,17 +698,7 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
700698

701699
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
702700
debug = config_settings.get("debug", False) if config_settings else False
703-
if sys.platform == "win32" and COMPILE_FOR_COVERAGE:
704-
# Importing the coverage-built bindings can exhaust the interpreter's
705-
# main-thread stack. Set the worker stack inside pip's build subprocess.
706-
previous_stack_size = threading.stack_size(8 * 1024 * 1024)
707-
try:
708-
with ThreadPoolExecutor(max_workers=1) as pool:
709-
config_key = pool.submit(_build_cuda_core, debug=debug).result()
710-
finally:
711-
threading.stack_size(previous_stack_size)
712-
else:
713-
config_key = _build_cuda_core(debug=debug)
701+
config_key = _build_cuda_core(debug=debug)
714702
wheel_name = _build_meta.build_wheel(wheel_directory, config_settings, metadata_directory)
715703
record_build_config(config_key)
716704
return wheel_name

‎cuda_core/tests/test_build_hooks.py‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -277,67 +277,6 @@ def test_record_writes_stamp(self, stamp):
277277
assert stamp.read_text().strip() == "cu13-gnu-debug"
278278

279279

280-
class TestCoverageBuildStack:
281-
@pytest.mark.parametrize("platform", ["win32", "linux"])
282-
@pytest.mark.parametrize("coverage", [False, True])
283-
@pytest.mark.agent_authored(model="gpt-6")
284-
def test_wheel_preparation_thread_and_stack_restoration(self, monkeypatch, platform, coverage):
285-
caller = threading.current_thread()
286-
previous_stack_size = threading.stack_size()
287-
prepared = []
288-
recorded = []
289-
290-
def prepare(debug):
291-
prepared.append((threading.current_thread(), debug))
292-
return "prepared-config"
293-
294-
def build(wheel_directory, config_settings, metadata_directory):
295-
assert threading.current_thread() is caller
296-
assert (wheel_directory, config_settings, metadata_directory) == ("dist", {"debug": True}, "metadata")
297-
return "cuda_core.whl"
298-
299-
monkeypatch.setattr(build_hooks, "sys", types.SimpleNamespace(platform=platform))
300-
monkeypatch.setattr(build_hooks, "COMPILE_FOR_COVERAGE", coverage)
301-
monkeypatch.setattr(build_hooks, "_build_cuda_core", prepare)
302-
monkeypatch.setattr(build_hooks._build_meta, "build_wheel", build)
303-
monkeypatch.setattr(build_hooks, "record_build_config", recorded.append)
304-
305-
assert build_hooks.build_wheel("dist", {"debug": True}, "metadata") == "cuda_core.whl"
306-
worker, debug = prepared[0]
307-
assert (worker is not caller) == (platform == "win32" and coverage)
308-
assert debug is True
309-
assert threading.stack_size() == previous_stack_size
310-
assert recorded == ["prepared-config"]
311-
312-
@pytest.mark.agent_authored(model="gpt-6")
313-
def test_preparation_failure_propagates_and_restores_stack(self, monkeypatch):
314-
failure = RuntimeError("preparation failed")
315-
previous_stack_size = threading.stack_size()
316-
317-
def fail(debug):
318-
raise failure
319-
320-
monkeypatch.setattr(build_hooks, "sys", types.SimpleNamespace(platform="win32"))
321-
monkeypatch.setattr(build_hooks, "COMPILE_FOR_COVERAGE", True)
322-
monkeypatch.setattr(build_hooks, "_build_cuda_core", fail)
323-
monkeypatch.setattr(
324-
build_hooks._build_meta,
325-
"build_wheel",
326-
lambda *_args: pytest.fail("failed preparation must not build a wheel"),
327-
)
328-
monkeypatch.setattr(
329-
build_hooks,
330-
"record_build_config",
331-
lambda _key: pytest.fail("failed preparation must not be stamped"),
332-
)
333-
334-
with pytest.raises(RuntimeError) as exc_info:
335-
build_hooks.build_wheel("dist")
336-
337-
assert exc_info.value is failure
338-
assert threading.stack_size() == previous_stack_size
339-
340-
341280
class TestBuildHookStamping:
342281
@pytest.mark.agent_authored(model="grok-4.6")
343282
def test_wheel_records_exact_prepared_config_after_success(self, monkeypatch):

0 commit comments

Comments
 (0)