okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b0fc432ed
main
1#!/usr/bin/env bash 2# CUDA -> SYCL migration of the Strata engine with SYCLomatic (dpct), run inside strata-sycl-dev. 3# sycl/tools/migrate.sh [repo] [out] repo defaults to the Strata_B70 checkout beside this dir 4# Writes a compilation database first (there is no nvcc here, so CMake cannot make one), then migrates every 5# CUDA-touching source into <out> mirroring the tree. Files dpct leaves alone are not copied - the port's 6# CMake falls back to the original for those, so the diff against upstream stays the port itself. 7set -euo pipefail 8repo =${ 1 :-/work/Strata_B70} 9out =${ 2 :- $ repo /sycl} 10hdr =${ CUDA_HEADERS :-/cuda-headers/include} 11set +u;source /opt/intel/oneapi/setvars.sh> /dev/null2 >&1 ||true ;set -u 12export PATH =/opt/intel/oneapi/dpcpp-ct/latest/bin:$ PATH 13cd " $ repo " 14# the compilation database: every .cu plus every .cpp/.hpp that includes a CUDA header 15db_dir =$( mktemp -d ) # outside the checkout: nothing to ignore in git 16trap 'rm -rf "$db_dir"' EXIT 17python3 - " $ repo " " $ hdr " " $ db_dir " <<'PY' 18import json, os, re, sys, subprocess 19repo, hdr, db_dir = sys.argv[1], sys.argv[2], sys.argv[3] 20files = subprocess.check_output(["bash", "-c", 21r"find src -name '*.cu'; grep -rl 'cuda_runtime\|cublas_v2\|cuda_fp16\|cuda\.h' src --include='*.cpp'"], 22cwd=repo, text=True).split() 23if os.environ.get("MIGRATE_ONLY"): # explicit list: host files that reach CUDA only through the headers (verify.cpp, mtp.cpp) 24files = os.environ["MIGRATE_ONLY"].split() 25db = [] 26# not in this tree: the optional ggml MMQ prefill path needs llama.cpp's ggml-cuda sources, and one parity test needs 27# ggml-cpu.h. Both stay CUDA-only for now. 28skip = {"src/prefill/moe_mmq.cu", "src/prefill/ggml_cuda_host.cu", "src/kernels/native_expert_parity.cpp"} 29for f in sorted(set(files) - skip): 30tool = "nvcc" if f.endswith(".cu") else "g++" 31cmd = [tool, "-std=c++20", "-Iinclude", "-Ithird_party/ggml", "-I" + hdr, "-DSTRATA_VERSION=\"port\""] 32if tool == "nvcc": cmd += ["--cuda-gpu-arch=sm_80", "-x", "cuda"] 33cmd += ["-c", f, "-o", f + ".o"] 34db.append({"directory": repo, "file": os.path.join(repo, f), "arguments": cmd}) 35json.dump(db, open(os.path.join(db_dir, "compile_commands.json"), "w"), indent=1) 36print(len(db), "translation units") 37PY 38mkdir -p " $ out " 39# --use-experimental-features: graph (cudaGraph -> sycl_ext_oneapi_graph), matrix (mma -> joint_matrix) 40# --gen-helper-function: copy the dpct helper headers next to the output so the port builds without the tool 41dpct -p " $ db_dir " --in-root= " $ repo " --out-root= " $ out " \ 42--cuda-include-path= " $ hdr " \ 43--use-experimental-features=graph,matrix,logical-group,masked-sub-group-operation,occupancy-calculation,free-function-queries,local-memory-kernel-scope-allocation,bindless_images,virtual_mem,root-group,non-uniform-groups \ 44--gen-helper-function --always-use-async-handler --sycl-named-lambda \ 45--enable-ctad --optimize-migration --assume-nd-range-dim=3 \ 46--report-type=all --report-file-prefix=dpct_report --report-format=csv \ 47--stop-on-parse-err=false ${ DPCT_EXTRA :-} 2 >&1| tee " $ out /migrate.log" | tail -40 48echo "MIGRATE EXIT ${ PIPESTATUS [0]} " 49find " $ out " -type f| wc -l