Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cbdc479cf | ||
|
|
f3f1e3d588 |
No files matched your search
@@ -207,8 +207,11 @@ class PeriodicBlockStepper:
|
|||||||
"""Advance n steps: halo refresh, then core pull/collide, per step.
|
"""Advance n steps: halo refresh, then core pull/collide, per step.
|
||||||
|
|
||||||
All n steps are enqueued in order on the one stream and the host waits
|
All n steps are enqueued in order on the one stream and the host waits
|
||||||
once before returning (same launches and bits as n step(1) calls). On a
|
once before returning (same launches and bits as n step(1) calls).
|
||||||
failure the instance is failed and step_count keeps its entry value.
|
Asynchronous device errors surface at that single wait, so they are not
|
||||||
|
attributed to the step that caused them; call step(1) repeatedly to
|
||||||
|
localize one. On any failure the instance is failed and step_count keeps
|
||||||
|
its entry value.
|
||||||
"""
|
"""
|
||||||
if isinstance(n, bool) or not isinstance(n, Integral) or n < 0:
|
if isinstance(n, bool) or not isinstance(n, Integral) or n < 0:
|
||||||
raise ValueError("n must be a nonnegative integer")
|
raise ValueError("n must be a nonnegative integer")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Host contract of PeriodicBlockStepper.step(n): one stream wait per call (mocked driver)."""
|
"""Host contract of PeriodicBlockStepper.step(n): one stream wait per call (mocked driver)."""
|
||||||
import ast
|
import ast
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
|
import importlib.util
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import types
|
import types
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
@@ -8,14 +9,15 @@ import unittest
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import CelerisLab.lbm.block_stepper as b
|
|
||||||
from CelerisLab.config import LBMConfig
|
from CelerisLab.config import LBMConfig
|
||||||
from CelerisLab.lbm.blocks import BlockLayout2D
|
from CelerisLab.lbm.blocks import BlockLayout2D
|
||||||
|
|
||||||
|
|
||||||
def host_module():
|
def host_module():
|
||||||
"""block_stepper with pycuda/compiler replaced by mocks; no GPU context."""
|
"""block_stepper with pycuda/compiler replaced by mocks; no GPU context."""
|
||||||
path = Path(b.__file__)
|
# Locate the source without importing it: importing block_stepper loads pycuda.driver,
|
||||||
|
# which CPU-only import-boundary tests (test_build_contracts) must never see.
|
||||||
|
path = Path(importlib.util.find_spec("CelerisLab.lbm.block_stepper").origin)
|
||||||
tree = ast.parse(path.read_text())
|
tree = ast.parse(path.read_text())
|
||||||
tree.body = [node for node in tree.body if not (
|
tree.body = [node for node in tree.body if not (
|
||||||
isinstance(node, ast.Import) and any(a.name == "pycuda.driver" for a in node.names)
|
isinstance(node, ast.Import) and any(a.name == "pycuda.driver" for a in node.names)
|
||||||
@@ -78,6 +80,25 @@ class BlockStepSync(unittest.TestCase):
|
|||||||
run.step(2)
|
run.step(2)
|
||||||
self.assertEqual((run.step_count, run._status), (1, "failed"))
|
self.assertEqual((run.step_count, run._status), (1, "failed"))
|
||||||
|
|
||||||
|
def test_launch_failure_mid_batch_fails_closed_without_waiting(self):
|
||||||
|
run, log = backend()
|
||||||
|
calls = []
|
||||||
|
step = run._step
|
||||||
|
|
||||||
|
def failing(*args, **kwargs):
|
||||||
|
calls.append(1)
|
||||||
|
if len(calls) == 2:
|
||||||
|
raise RuntimeError("launch failure")
|
||||||
|
return step(*args, **kwargs)
|
||||||
|
|
||||||
|
run._step = failing
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
run.step(3)
|
||||||
|
self.assertNotIn("sync", [name for name, _ in log])
|
||||||
|
self.assertEqual((run.step_count, run._status), (0, "failed"))
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
run.download()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user