19 lines
809 B
Python
19 lines
809 B
Python
"""Extract production CUDA kernels and host helpers for the test-only adapter."""
|
|
|
|
from pathlib import Path
|
|
import re
|
|
import sys
|
|
|
|
|
|
source = (Path(__file__).resolve().parents[1] / "processing/processors/src/sar3d_gpu.cpp").read_text()
|
|
kernel = re.search(r'kKernelSource\s*=\s*R"CUDA\((.*?)\)CUDA";', source, re.DOTALL)
|
|
if kernel is None:
|
|
raise RuntimeError("SAR CUDA kernel literal was not found")
|
|
first = source.index("constexpr std::size_t kMaxIndexedItems")
|
|
last = source.index("} // namespace", first)
|
|
destination = Path(sys.argv[1])
|
|
destination.mkdir(parents=True, exist_ok=True)
|
|
(destination / "sar3d_kernels.inc").write_text(kernel.group(1))
|
|
helpers = re.sub(r"^#(?:ifdef SAR3D_WITH_CUDA|endif)$", "", source[first:last], flags=re.MULTILINE)
|
|
(destination / "sar3d_helpers.inc").write_text(helpers)
|