Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/ampere_numeric_host_test.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / ampere_numeric_host_test.c` 44 lines · 1986 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Host arithmetic and environment checks only. No GPU or native bridge. */ 3 #include "omega_numeric.h" 4 #include "omega_numeric_reduce.h" 5 #include 6 #if defined(__x86_64__) 7 #include 8 #include 9 #endif 10 #define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); return 1; } } while (0) 11 int main(void) { 12 float a[] = {1.0f, -0.0f, 0.0f, 2.0f}; 13 float b[] = {2.0f, 0.0f, -0.0f, 1.0f}; 14 float r[4], expected[4]; 15 CHECK(omega_numeric_fpenv_ok()); 16 const OmegaNumericOp ops[] = {OMEGA_NOP_FADD, OMEGA_NOP_FSUB, OMEGA_NOP_FMUL, 17 OMEGA_NOP_FFMA, OMEGA_NOP_FMNMX_MIN, OMEGA_NOP_FMNMX_MAX, 18 OMEGA_NOP_F2I, OMEGA_NOP_F32_TO_F16, OMEGA_NOP_F32_TO_BF16}; 19 for (size_t i = 0; i < sizeof ops / sizeof ops[0]; ++i) { 20 CHECK(omega_numeric_reference(ops[i], a, b, b, expected, 4) == OMEGA_NUMERIC_OK); 21 CHECK(omega_numeric_cpu_realize(ops[i], a, b, b, r, 4) == OMEGA_NUMERIC_OK); 22 for (size_t j = 0; j < 4; ++j) CHECK(omega_numeric_bits_equal(r[j], expected[j])); 23 } 24 float reduced; 25 CHECK(omega_reduce_cpu(OMEGA_RED_MAX, a, 4, &reduced) == OMEGA_NUMERIC_OK && reduced == 2.0f); 26 #if defined(__x86_64__) 27 unsigned saved = _mm_getcsr(); 28 const unsigned bad[] = {1u << 15, 1u << 6, 1u << 13}; /* FTZ, DAZ, rounding */ 29 for (size_t i = 0; i < sizeof bad / sizeof bad[0]; ++i) { 30 _mm_setcsr(saved | bad[i]); 31 int guarded = !omega_numeric_fpenv_ok(); 32 int rc = omega_numeric_cpu_realize(OMEGA_NOP_FADD, a, b, NULL, r, 4); 33 _mm_setcsr(saved); 34 CHECK(guarded && rc == OMEGA_NUMERIC_ERR_FPENV); 35 } 36 int rounding = fegetround(); 37 CHECK(fesetround(FE_DOWNWARD) == 0); 38 int guarded = !omega_numeric_fpenv_ok(); 39 CHECK(fesetround(rounding) == 0); 40 CHECK(guarded && omega_numeric_fpenv_ok()); 41 #endif 42 puts("AMPERE NUMERIC HOST PASS; device NOT_RUN"); 43 return 0; 44 }