Skip to content

Commit 4aaca63

Browse files
committed
test(core.utils): drop SUPPORTED_TARGETS cross-check
The test parsed `_program.pyx` to extract `SUPPORTED_TARGETS` and compare against `_SUPPORTED_TARGETS_BY_CODE_TYPE` in the cache. Source parsing for a duplication check is not worth the maintenance cost -- a reviewer eyeballing both definitions catches drift just as well, and the test was already broken once by upstream's StrEnum migration.
1 parent 547d3f3 commit 4aaca63

1 file changed

Lines changed: 0 additions & 56 deletions

File tree

cuda_core/tests/test_program_cache.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -341,62 +341,6 @@ def test_make_program_cache_key_rejects(kwargs, exc_type, match):
341341
_make_key(**kwargs)
342342

343343

344-
def test_make_program_cache_key_supported_targets_matches_program_compile():
345-
"""``_SUPPORTED_TARGETS_BY_CODE_TYPE`` duplicates the backend target
346-
matrix in ``_program.pyx``. Guard against drift: parse the pyx source
347-
with :mod:`tokenize` (which skips string literals and comments) to
348-
extract ``SUPPORTED_TARGETS`` and assert the two views agree."""
349-
import ast
350-
import io
351-
import tokenize
352-
from pathlib import Path
353-
354-
from cuda.core.utils._program_cache._keys import _SUPPORTED_TARGETS_BY_CODE_TYPE
355-
356-
backend_to_code_type = {"NVRTC": "c++", "NVVM": "nvvm"}
357-
linker_backends = ("nvJitLink", "driver")
358-
359-
pyx = Path(__file__).parent.parent / "cuda" / "core" / "_program.pyx"
360-
text = pyx.read_text()
361-
marker_idx = text.index("cdef dict SUPPORTED_TARGETS")
362-
tokens = tokenize.generate_tokens(io.StringIO(text[marker_idx:]).readline)
363-
364-
depth = 0
365-
start_offset = None
366-
end_offset = None
367-
lines = text[marker_idx:].splitlines(keepends=True)
368-
line_starts = [0]
369-
for line in lines[:-1]:
370-
line_starts.append(line_starts[-1] + len(line))
371-
372-
def _offset(row, col):
373-
return line_starts[row - 1] + col
374-
375-
for tok in tokens:
376-
if tok.type != tokenize.OP:
377-
continue
378-
if tok.string == "{":
379-
if depth == 0:
380-
start_offset = _offset(tok.start[0], tok.start[1])
381-
depth += 1
382-
elif tok.string == "}":
383-
depth -= 1
384-
if depth == 0:
385-
end_offset = _offset(tok.end[0], tok.end[1])
386-
break
387-
assert start_offset is not None and end_offset is not None, "could not locate SUPPORTED_TARGETS literal"
388-
pyx_targets = ast.literal_eval(text[marker_idx + start_offset : marker_idx + end_offset])
389-
390-
for backend, code_type in backend_to_code_type.items():
391-
assert frozenset(pyx_targets[backend]) == _SUPPORTED_TARGETS_BY_CODE_TYPE[code_type], (
392-
backend,
393-
code_type,
394-
)
395-
linker_sets = [frozenset(pyx_targets[b]) for b in linker_backends]
396-
assert all(s == linker_sets[0] for s in linker_sets)
397-
assert linker_sets[0] == _SUPPORTED_TARGETS_BY_CODE_TYPE["ptx"]
398-
399-
400344
@pytest.mark.parametrize(
401345
"code_type, code, target_type",
402346
[

0 commit comments

Comments
 (0)