interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / platform-linux / gen_effects.sh

65 lines · 3328 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Regenerates om/platform-linux/gen/*.c from the platform .om units.
4# Output is not src/cudapp_om_*.c: that glob is one link, and each generated
5# runtime defines omega_native_context_create. Callers compile these with
6# -D renames (mk/platform-linux.mk). Needs the retire-compiler pair and
7# BridgeX86 tools/native. The pinned CUDApp omc rejects cpufence and mapget.
8set -eu
9ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
10BRIDGE=${CUDAPP_EFFECTS_BRIDGE:-/home/drakestapleton/work/cudastack/lanes/BridgeX86}
11X86_OMC=${OMEGA_NATIVE_X86_OMC:-/home/drakestapleton/work/cudastack/lanes/omega-mv-x86/seed/out/omc}
12X86_CC=${OMEGA_NATIVE_X86_CC:-x86_64-linux-gnu-gcc}
13OMC2=${OMEGA_NATIVE_OMC2:-/home/drakestapleton/work/cudastack/lanes/omega-mv-bh-retire/seed/out/omc}
14OMC=${OMEGA_NATIVE_OMC:-/home/drakestapleton/work/cudastack/lanes/omega-mv-c6/seed/out/omc}
15GEN="$ROOT/om/platform-linux/gen"
16mkdir -p "$GEN"
17export OMEGA_NATIVE_OMC2="$OMC2" OMEGA_NATIVE_OMC="$OMC" OMEGA_NATIVE_X86_OMC="$X86_OMC"
18one() {
19 name=$1
20 src=$2
21 T=$(mktemp -d)
22 "$BRIDGE/tools/native" --host --target aarch64linux "$T/arm" "$src"
23 CC="$X86_CC" "$BRIDGE/tools/native" --host --target x86linux "$T/x86" "$src"
24 {
25 printf '/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */\n/* Generated by om/platform-linux/gen_effects.sh; do not edit. */\n#if defined(__aarch64__)\n'
26 cat "$T/arm/omega_native.c"
27 printf '\n#elif defined(__x86_64__)\n'
28 cat "$T/x86/omega_native.c"
29 printf '\n#else\n#error "platform omega units require Linux AArch64 or x86-64"\n#endif\n'
30 } > "$GEN/$name.c"
31 {
32 printf '/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */\n/* Generated by om/platform-linux/gen_effects.sh; do not edit. */\n#ifndef CUDAPP_PLAT_%s_H\n#define CUDAPP_PLAT_%s_H\n#include <stdint.h>\n#if defined(__aarch64__)\n' "$name" "$name"
33 cat "$T/arm/omega_native.h"
34 printf '\n#elif defined(__x86_64__)\n'
35 cat "$T/x86/omega_native.h"
36 printf '\n#else\n#error "platform omega units require Linux AArch64 or x86-64"\n#endif\n#endif\n'
37 } > "$GEN/$name.h"
38 rm -rf "$T"
39}
40one plat_effects "$ROOT/om/platform-linux/plat_effects.om"
41one plat_wait "$ROOT/om/platform-linux/plat_wait.om"
42# The carried test-platform-linux-wait mutant: the 2^31 deadline bound replaced by 0.
43# Committed like the units above, so the gate compiles it without these compilers.
44MT=$(mktemp -d)
45grep -q 2147483648 "$ROOT/om/platform-linux/plat_wait.om"
46sed 's/2147483648/0/' "$ROOT/om/platform-linux/plat_wait.om" > "$MT/plat_wait_mutant.om"
47! grep -q 2147483648 "$MT/plat_wait_mutant.om"
48one plat_wait_mutant "$MT/plat_wait_mutant.om"
49rm -rf "$MT"
50rename() {
51 src=$1
52 dst=$2
53 p=$3
54 # Symbols immediately following an escaped newline have no regex word boundary.
55 sed -e "s/ombr_enter/${p}_ombr_enter/g" \
56 -e "s/ombr_trap/${p}_ombr_trap/g" \
57 -e "s/ombr_no_entry/${p}_ombr_no_entry/g" \
58 -e "s/\\bomega_native_context_create\\b/${p}_context_create/g" \
59 -e "s/\\bomega_native_context_destroy\\b/${p}_context_destroy/g" \
60 "$src" > "$dst"
61}
62mkdir -p "$GEN/link"
63rename "$GEN/plat_effects.c" "$GEN/link/plat_fx_effects.c" plat_fx
64rename "$GEN/plat_wait.c" "$GEN/link/plat_fx_wait.c" plat_wt
65echo "PASS platform effects generation"