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/src/omega_gpu_api_hostrest.h # 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 / src / omega_gpu_api_hostrest.h` 75 lines · 3524 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef OMEGA_GPU_API_HOSTREST_H 3 #define OMEGA_GPU_API_HOSTREST_H 4 #include "cudapp_native.h" 5 #include 6 #include 7 #include 8 /* Default-OFF frozen C oracle. Pointer acquisition and effects stay in callers. */ 9 #if defined(CUDAPP_MIGRATION_PENDING_C_API_FP8_GDN_HOST) || defined(CUDAPP_API_HOSTREST_DIFF) 10 static inline uint64_t omega_ah_c(unsigned op, const uint64_t p[16]) { 11 const uint32_t a=p[0], b=p[1], c=p[2], d=p[3], e=p[4]; 12 switch (op) { 13 case 0: return p[1]==0 && p[0]=='0' ? 0 : p[1]==0 && p[0]=='1' ? 1 : p[2]; 14 case 1: return p[0]=='2' && !p[1] ? 2 : 1; 15 case 2: return b ? b : c==0 ? (a%512==0 ? 16 : 8) : c==1 ? 1 : 8; 16 case 3: return p[0]*p[1]<=65536; 17 case 4: { if (b>0 && b<=256) return b; if (!p[2] || !a) return 6; uint32_t n=48/a; if (!n) n=1; return n<6?n:6; } 18 case 5: return b<'0'||b>'9'||a>=1000 ? UINT64_C(`4294967296`) : (uint32_t)(a*10u+b-'0'); 19 case 6: return c ? c : p[4]==2 ? 16 : b>1 ? 32 : b==1 && a>4096 && p[3] ? 16 : 8; 20 case 7: return p[0] && b*c<=32; 21 case 8: { 22 uint32_t ks=a/(32u*b); 23 int partial=ks*c*b>128u && a>4096u && e==1 && p[5]; 24 if (partial) { do ks--; while (ks>1u && (a/(32u*b)%ks || ks*c*b>128u)); if (ks<2u) return 0; } 25 if (ks*c*b>128u || a%(32u*d) || a>512u*d) return 0; 26 return ks | ((uint64_t)partial<<32); 27 } 28 case 9: return a%b || !p[2]; 29 case 10: { 30 uint32_t gx=(a/b+c-1u)/c, budget=d; 31 if (p[4]) { uint32_t waves=(gx+383u)/384u; if (waves<2u) waves=2u; gx=(gx+waves-1u)/waves; budget=gx; } 32 if (gx>budget) gx=budget; 33 return gx ? gx : 1; 34 } 35 case 11: return p[0] && p[1] ? 1 : p[0] && p[2] ? 2 : 0; 36 case 12: return (p[0]!=4 && p[0]!=5)||!p[1]||!p[2]||p[2]%p[3]||p[2]/p[3]>0x7fffffffu ? 0 : p[2]/p[3]; 37 case 13: return !(a>=b || ce); 38 case 14: return !(p[0] && (!p[1] || p[2]1 ? (p[3]==2 ? 12 : p[4]) : 256; 42 case 19: return !p[0] && p[1]==1 && p[2]>4096 && p[3]; 43 case 20: return p[0]==1 && p[1] && p[2]<=p[3]; 44 case 21: return p[0]>p[1]; 45 case 22: return p[0]/p[1]; 46 case 23: 47 if(p[0]==0) return !p[1] || (p[2] && p[3] && p[4]); 48 if(p[0]==1) return p[1] && (p[2] || p[3]) && (p[4] || p[5] || p[6]) && (p[7] || p[8]); 49 return p[1] ? p[2] && p[3] && p[4] : p[5] && p[6] && p[7] && p[8]; 50 case 24: return (uint32_t)(a/(32u*b)*c*b)>128u && a>4096u && d==1; 51 case 25: return p[2] && p[3]==1 && p[1] && !p[4] && a%(32u*b) && !(a%128u); 52 default: return d==0 ? (a+b-1u)/b : d==1 ? c : a; 53 } 54 } 55 #endif 56 static inline uint64_t omega_ah_call(unsigned op, const uint64_t p[16]) { 57 #if defined(CUDAPP_MIGRATION_PENDING_C_API_FP8_GDN_HOST) && !defined(CUDAPP_API_HOSTREST_DIFF) 58 return omega_ah_c(op,p); 59 #else 60 uint64_t r=0; 61 if (omega_ah_rest(&r,op,p,16)!=OMEGA_OK) abort(); 62 #ifdef CUDAPP_API_HOSTREST_RED 63 r ^= 1; 64 #endif 65 #ifdef CUDAPP_API_HOSTREST_DIFF 66 if (r!=omega_ah_c(op,p)) { fprintf(stderr,"hostrest differential op=%u\n",op); abort(); } 67 #endif 68 return r; 69 #endif 70 } 71 #define OMEGA_AH(op, ...) omega_ah_call((op), (const uint64_t[16]){__VA_ARGS__}) 72 static inline uint64_t omega_ah_flag(const char *s, unsigned dflt) { 73 return OMEGA_AH(0, s ? (unsigned char)s[0] : 0, s && s[0] ? (unsigned char)s[1] : 1, dflt); 74 } 75 #endif