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 / native / nvrm / units.sh

64 lines · 3863 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Regenerate both hosted instruction streams; portable wire units use om/units.sh.
4set -eu
5ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
6BRIDGE=${OMEGA_NVRM_BRIDGE:?set OMEGA_NVRM_BRIDGE to the pinned hosted/context bridge}
7OMC=${OMEGA_NATIVE_OMC:?set OMEGA_NATIVE_OMC to the native generator compiler}
8ARM=${OMEGA_NATIVE_OMC2:?set OMEGA_NATIVE_OMC2 to the AArch64 context compiler}
9X86=${OMEGA_NATIVE_X86_OMC:?set OMEGA_NATIVE_X86_OMC to the hosted x86 compiler}
10GEN_PIN=734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
11ARM_PIN=d1a3047153e14676c4baf9248fa2b88bb1b68c37cfeb71d76f30f5230c7d2765
12X86_PIN=cf4fcbbb4752c5dd0652b426c0f2d08f82e380e8fc6f5114acf51a4c077bb579
13IDENT=$ROOT/src/cudapp_om_nvrm_transport.ident
14bridge_pin= native_pin= tool_pin=
15set -f
16for field in $(cat "$IDENT"); do
17 case "$field" in
18 bridge=*) bridge_pin=${field#bridge=} ;;
19 bridge_native=*) native_pin=${field#bridge_native=} ;;
20 bridge_tool=*) tool_pin=${field#bridge_tool=} ;;
21 esac
22done
23set +f
24hash() { sha256sum < "$1" | cut -d' ' -f1; }
25require_hash() {
26 [ -n "$2" ] && [ "$(hash "$1")" = "$2" ] || {
27 echo "NOT_RUN: native NVRM pin mismatch: $1" >&2; exit 3;
28 }
29}
30[ -n "$bridge_pin" ] && [ "$(git -C "$BRIDGE" rev-parse HEAD)" = "$bridge_pin" ] || {
31 echo "NOT_RUN: native NVRM bridge revision mismatch" >&2; exit 3;
32}
33require_hash "$BRIDGE/src/native.om" "$native_pin"
34require_hash "$BRIDGE/tools/native" "$tool_pin"
35require_hash "$OMC" "$GEN_PIN"
36require_hash "$ARM" "$ARM_PIN"
37require_hash "$X86" "$X86_PIN"
38case $(uname -m) in
39 aarch64) ARM_CC=${OMEGA_NVRM_CC_AARCH64:-cc}; X86_CC=${OMEGA_NVRM_CC_X86:-x86_64-linux-gnu-gcc} ;;
40 x86_64) ARM_CC=${OMEGA_NVRM_CC_AARCH64:-aarch64-linux-gnu-gcc}; X86_CC=${OMEGA_NVRM_CC_X86:-cc} ;;
41 *) echo "NOT_RUN: native NVRM generation needs Linux AArch64/x86-64 cross compilers" >&2; exit 3 ;;
42esac
43T=$(mktemp -d)
44trap 'rm -rf "$T"' EXIT
45export OMEGA_NATIVE_OMC OMEGA_NATIVE_OMC2 OMEGA_NATIVE_X86_OMC
46CC="$ARM_CC" "$BRIDGE/tools/native" --host --target aarch64linux "$T/arm" "$ROOT/native/nvrm/transport.om" "$ROOT/native/streams/submit.om"
47CC="$X86_CC" "$BRIDGE/tools/native" --host --target x86linux "$T/x86" "$ROOT/native/nvrm/transport.om" "$ROOT/native/streams/submit.om"
48{
49 printf '/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */\n/* Generated by native/nvrm/units.sh; do not edit. */\n#if defined(__aarch64__)\n'
50 cat "$T/arm/omega_native.c"
51 printf '\n#elif defined(__x86_64__)\n'
52 cat "$T/x86/omega_native.c"
53 printf '\n#else\n#error "NVRM hosted transport requires Linux AArch64 or x86-64"\n#endif\n'
54} > "$T/cudapp_om_nvrm_transport.c"
55{
56 printf '/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */\n/* Generated by native/nvrm/units.sh; do not edit. */\n#ifndef CUDAPP_NVRM_NATIVE_H\n#define CUDAPP_NVRM_NATIVE_H\n#if defined(__aarch64__)\n'
57 cat "$T/arm/omega_native.h"
58 printf '\n#elif defined(__x86_64__)\n'
59 cat "$T/x86/omega_native.h"
60 printf '\n#else\n#error "NVRM hosted transport requires Linux AArch64 or x86-64"\n#endif\n#endif\n'
61} > "$T/cudapp_nvrm_native.h"
62printf '%s\n' "omega-native-ident 1 unit=nvrm_transport path=native/nvrm/transport.om+native/streams/submit.om bridge=$bridge_pin bridge_native=$native_pin bridge_tool=$tool_pin omc_generator=$GEN_PIN omc_aarch64=$ARM_PIN omc_x86=$X86_PIN src=$(cat "$ROOT/native/nvrm/transport.om" "$ROOT/native/streams/submit.om" | sha256sum | cut -d" " -f1) c=$(hash "$T/cudapp_om_nvrm_transport.c") h=$(hash "$T/cudapp_nvrm_native.h")" > "$T/cudapp_om_nvrm_transport.ident"
63cp "$T/cudapp_om_nvrm_transport.c" "$T/cudapp_nvrm_native.h" "$T/cudapp_om_nvrm_transport.ident" "$ROOT/src/"
64printf 'NVRM NATIVE GENERATION PASS (AArch64+x86-64, pinned context compilers and bridge)\n'