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
CUDApp / src / omega_blackwell_realize.c
| 1 | /* ORACLE: retained default-OFF C realization identity; production cg_bind and bw_identity are Omega on both host ABIs. */ |
| 2 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 3 | #include "omega_blackwell_realize.h" |
| 4 | #include "sha256.h" |
| 5 | #include <string.h> |
| 6 | #include "omega_bw_policy.h" |
| 7 | #include "omega_bw_bind.h" |
| 8 | |
| 9 | #ifndef BW_BIND_C_PRIMARY |
| 10 | int omega_blackwell_get_machine_id(SemanticId *out_machine_id) { |
| 11 | uint8_t w[256] = {0}; |
| 12 | if (!out_machine_id) return -1; |
| 13 | if (omega_bw_bind(2, 0, 0, w) != 27) return -1; |
| 14 | if (omega_bw_id(w, 27, out_machine_id->bytes) != 0) return -1; |
| 15 | return 0; |
| 16 | } |
| 17 | |
| 18 | /* The Omega message carries sm_architecture little-endian; the C oracle hashes its host bytes (equal on LE hosts). */ |
| 19 | int omega_blackwell_realization_compute_id(OmegaBlackwellRealization *real) { |
| 20 | uint8_t w[256] = {0}; |
| 21 | if (!real) return -1; |
| 22 | memcpy(w + 128, real->spec_id.bytes, OMEGA_ID_BYTES); |
| 23 | memcpy(w + 160, real->machine_id.bytes, OMEGA_ID_BYTES); |
| 24 | memcpy(w + 192, real->code_digest, sizeof(real->code_digest)); |
| 25 | if (omega_bw_bind(1, real->sm_architecture, 0, w) != 100) return -1; |
| 26 | if (omega_bw_id(w, 100, real->realization_digest) != 0) return -1; |
| 27 | memcpy(real->realization_id.bytes, real->realization_digest, OMEGA_ID_BYTES); |
| 28 | return 0; |
| 29 | } |
| 30 | #else |
| 31 | /* Default-OFF C_BIND differential oracle. Both production ABIs use Omega SHA. */ |
| 32 | |
| 33 | int omega_blackwell_get_machine_id(SemanticId *out_machine_id) { |
| 34 | if (!out_machine_id) return -1; |
| 35 | sha256_ctx ctx; |
| 36 | sha256_init(&ctx); |
| 37 | const char *machine_str = "NVIDIA_DGX_SPARK_GB10_SM121"; |
| 38 | sha256_update(&ctx, (const uint8_t *)machine_str, strlen(machine_str)); |
| 39 | sha256_final(&ctx, out_machine_id->bytes); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | int omega_blackwell_realization_compute_id(OmegaBlackwellRealization *real) { |
| 44 | if (!real) return -1; |
| 45 | sha256_ctx ctx; |
| 46 | sha256_init(&ctx); |
| 47 | sha256_update(&ctx, real->spec_id.bytes, OMEGA_ID_BYTES); |
| 48 | sha256_update(&ctx, real->machine_id.bytes, OMEGA_ID_BYTES); |
| 49 | sha256_update(&ctx, real->code_digest, sizeof(real->code_digest)); |
| 50 | sha256_update(&ctx, (const uint8_t *)&real->sm_architecture, sizeof(real->sm_architecture)); |
| 51 | sha256_final(&ctx, real->realization_digest); |
| 52 | |
| 53 | memcpy(real->realization_id.bytes, real->realization_digest, OMEGA_ID_BYTES); |
| 54 | return 0; |
| 55 | } |
| 56 | #endif /* BW_BIND_C_PRIMARY */ |
| 57 | |
| 58 | int omega_blackwell_realize_vector(const OmegaVectorSpec *spec, OmegaBlackwellRealization *out_real) { |
| 59 | if (!spec || !out_real) return -1; |
| 60 | memset(out_real, 0, sizeof(*out_real)); |
| 61 | |
| 62 | out_real->spec_id = spec->spec_id; |
| 63 | if (omega_blackwell_get_machine_id(&out_real->machine_id) != 0) return -1; |
| 64 | |
| 65 | #ifndef BW_BIND_C_PRIMARY |
| 66 | uint8_t w[256] = {0}; |
| 67 | int64_t arch = omega_bw_bind(9, 0, 0, w); |
| 68 | if (arch < 0) return -1; |
| 69 | out_real->sm_architecture = (uint32_t)arch; |
| 70 | #else |
| 71 | out_real->sm_architecture = OMEGA_BW_SM_ARCH_121; |
| 72 | #endif |
| 73 | out_real->code_len = OMEGA_BW_VECADD_CODE_SIZE; |
| 74 | |
| 75 | /* Verify and digest generated Blackwell machine code */ |
| 76 | uint8_t code_buf[OMEGA_BW_VECADD_CODE_SIZE]; |
| 77 | size_t encoded_len = 0; |
| 78 | if (omega_blackwell_encode_vecadd(code_buf, sizeof(code_buf), &encoded_len) != 0) return -1; |
| 79 | if (omega_blackwell_compute_code_digest(code_buf, encoded_len, out_real->code_digest) != 0) return -1; |
| 80 | |
| 81 | /* Default launch geometry */ |
| 82 | out_real->qmd_cfg.num_elements = spec->element_count; |
| 83 | #ifndef BW_BIND_C_PRIMARY |
| 84 | int64_t geo = omega_bw_bind(4, spec->element_count, 0, w); |
| 85 | if (geo < 0) return -1; |
| 86 | out_real->qmd_cfg.grid_width = (uint32_t)geo; |
| 87 | out_real->qmd_cfg.threads_per_block = (uint32_t)((uint64_t)geo >> 32); |
| 88 | #else |
| 89 | out_real->qmd_cfg.threads_per_block = 64; |
| 90 | out_real->qmd_cfg.grid_width = (spec->element_count + 63) / 64; |
| 91 | if (out_real->qmd_cfg.grid_width == 0) out_real->qmd_cfg.grid_width = 1; |
| 92 | #endif |
| 93 | |
| 94 | return omega_blackwell_realization_compute_id(out_real); |
| 95 | } |