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 / evidence / attention-views / 2026-11-06 / omega_attn_tables.h.gcov
| 1 | -: 0:Source:src/omega_attn_tables.h |
| 2 | -: 0:Graph:~/work/cudastack/lanes/ApiViewsAttn/build/attn-views-qualified-final/cases-oracle.gcno |
| 3 | -: 0:Data:~/work/cudastack/lanes/ApiViewsAttn/build/attn-views-qualified-final/cases-oracle.gcda |
| 4 | -: 0:Runs:9 |
| 5 | -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 6 | -: 2:#ifndef OMEGA_ATTN_TABLES_H |
| 7 | -: 3:#define OMEGA_ATTN_TABLES_H |
| 8 | -: 4:#include "omega_attn_views.h" |
| 9 | -: 5:#include "omega_api_plan.h" |
| 10 | -: 6:#include "omega_gpu_hostmath.h" |
| 11 | function av_ropegen called 16 returned 100% blocks executed 100% |
| 12 | 16: 7:static inline void av_ropegen(float *d,uint64_t pos,double theta,uint64_t dim,uint64_t width,size_t rows) { |
| 13 | -: 8:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 14 | 4152: 9: for(size_t r=0;r<rows;r++)for(uint64_t i=0;i<width/2;i++) { |
| 15 | branch 0 taken 4096 |
| 16 | branch 1 taken 40 (fallthrough) |
| 17 | branch 2 taken 40 |
| 18 | branch 3 taken 16 (fallthrough) |
| 19 | 4096: 10: double s=0,c=1; |
| 20 | 4096: 11: if(i<dim/2){double inv=omega_hostmath_pow(theta,-2.0*(double)i/(double)dim);omega_hostmath_sincos((double)(pos+r)*inv,&s,&c);} |
| 21 | branch 0 taken 1792 (fallthrough) |
| 22 | branch 1 taken 2304 |
| 23 | call 2 returned 1792 |
| 24 | call 3 returned 1792 |
| 25 | 4096: 12: d[r*width+i]=(float)c;d[r*width+width/2+i]=(float)s; |
| 26 | -: 13: } |
| 27 | -: 14:#else |
| 28 | -: 15: uint64_t bits;memcpy(&bits,&theta,8); |
| 29 | -: 16: uint64_t q[16]={pos,bits,dim,width,rows},r=0; |
| 30 | -: 17: if(omega_av_rope(&r,d,rows*width,q,16)!=OMEGA_OK || r)__builtin_trap(); |
| 31 | -: 18:#endif |
| 32 | 16: 19:} |
| 33 | function av_gentab called 16 returned 100% blocks executed 100% |
| 34 | 16: 20:static inline void av_gentab(const uint32_t *lo,const uint32_t *hi,uint32_t *tab,size_t n,uint64_t off,uint64_t stride) { |
| 35 | -: 21:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 36 | 64: 22: for(size_t i=0;i<n;i++){tab[4*i]=lo[i];tab[4*i+1]=hi[i];tab[4*i+2]=(uint32_t)(off+i*stride);tab[4*i+3]=0;} |
| 37 | branch 0 taken 48 |
| 38 | branch 1 taken 16 (fallthrough) |
| 39 | -: 23:#else |
| 40 | -: 24: uint64_t q[16]={n,off,stride},r=0; |
| 41 | -: 25: if(omega_av_gtab(&r,lo,n,tab,4*n,q,16,0)!=OMEGA_OK || r || |
| 42 | -: 26: omega_av_gtab(&r,hi,n,tab,4*n,q,16,1)!=OMEGA_OK || r)__builtin_trap(); |
| 43 | -: 27:#endif |
| 44 | 16: 28:} |
| 45 | function av_ranges called 8 returned 100% blocks executed 100% |
| 46 | 8: 29:static inline void av_ranges(uint32_t *d,size_t n,const uint64_t q[16]) { |
| 47 | -: 30:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 48 | 72: 31: for(size_t i=0;i<n;i++){uint64_t p[16]={q[0]+i,q[1],q[2],q[3],q[4]};(void)ap_plan(AP_AT,10,p);d[i]=(uint32_t)p[8];d[n+i]=(uint32_t)p[9];} |
| 49 | call 0 returned 64 |
| 50 | branch 1 taken 64 |
| 51 | branch 2 taken 8 (fallthrough) |
| 52 | -: 32:#else |
| 53 | -: 33: uint64_t r=0;if(omega_av_range(&r,q,16,d,2*n,n)!=OMEGA_OK || r)__builtin_trap(); |
| 54 | -: 34:#endif |
| 55 | 8: 35:} |
| 56 | function av_total called 16 returned 100% blocks executed 100% |
| 57 | 16: 36:static inline uint32_t av_total(const uint32_t *e,size_t n,uint64_t bs) { |
| 58 | -: 37:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 59 | 8000104: 38: uint32_t r=0;for(size_t i=0;i<n;i++)r+=e[i]?(e[i]+bs-1)/bs:0;return r; |
| 60 | branch 0 taken 5333440 (fallthrough) |
| 61 | branch 1 taken 2666648 |
| 62 | branch 2 taken 8000088 |
| 63 | branch 3 taken 16 (fallthrough) |
| 64 | -: 39:#else |
| 65 | -: 40: uint64_t r=0;if(omega_av_total(&r,e,n,n,bs)!=OMEGA_OK)__builtin_trap();return (uint32_t)r; |
| 66 | -: 41:#endif |
| 67 | -: 42:} |
| 68 | function av_table called 48 returned 100% blocks executed 100% |
| 69 | 48: 43:static inline uint32_t av_table(const uint32_t *ids,uint32_t *tab,size_t tw,int32_t *slots,uint32_t *touched,size_t nb,const uint64_t q[16],uint32_t g) { |
| 70 | -: 44:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 71 | -: 45: (void)tw;(void)nb; |
| 72 | 16000192: 46: for(size_t b=0;b<q[0];b++){uint32_t id=ids[b],v=g; |
| 73 | branch 0 taken 16000144 |
| 74 | branch 1 taken 48 (fallthrough) |
| 75 | 16000144: 47: if(q[1]==2)v=id; |
| 76 | branch 0 taken 32 (fallthrough) |
| 77 | branch 1 taken 16000112 |
| 78 | 16000112: 48: else if(q[1]){if(slots[id]<0){slots[id]=(int32_t)g;touched[g++]=id;}v=(uint32_t)slots[id];} |
| 79 | branch 0 taken 16000080 (fallthrough) |
| 80 | branch 1 taken 32 |
| 81 | branch 2 taken 32 (fallthrough) |
| 82 | branch 3 taken 16000048 |
| 83 | 32: 49: else g++; |
| 84 | 16000144: 50: tab[q[2]+b]=v; |
| 85 | -: 51: } |
| 86 | 48: 52: tab[q[3]]=(uint32_t)q[4];return g; |
| 87 | -: 53:#else |
| 88 | -: 54: (void)tw;uint64_t r=0; |
| 89 | -: 55: uint32_t *row=tab+q[2]; |
| 90 | -: 56: av_memcpy(row,ids,q[0]*sizeof *ids); |
| 91 | -: 57: if(omega_av_table(&r,row,q[0],slots,nb,q,16,g)!=OMEGA_OK)__builtin_trap(); |
| 92 | -: 58: uint32_t result=(uint32_t)r; |
| 93 | -: 59: if(q[1] && q[1]!=2)for(uint64_t start=0;;) { |
| 94 | -: 60: uint64_t count=q[0]-start;if(count>1000000)count=1000000; |
| 95 | -: 61: if(omega_av_touch(&r,start?ids+start:ids,count,slots,nb,touched,nb,g)!=OMEGA_OK)__builtin_trap(); |
| 96 | -: 62: if(count==q[0]-start)break; |
| 97 | -: 63: start+=count; |
| 98 | -: 64: } |
| 99 | -: 65: av_fill32(tab+q[3],1,(uint32_t)q[4]); |
| 100 | -: 66: return result; |
| 101 | -: 67:#endif |
| 102 | -: 68:} |
| 103 | function av_blocks called 16 returned 100% blocks executed 100% |
| 104 | 16: 69:static inline int av_blocks(const uint32_t *ids,size_t n,const uint64_t q[16]) { |
| 105 | -: 70:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 106 | 64: 71: for(size_t i=0;i<n;i++){uint64_t p[16]={ids[i],q[1],q[2],q[3],q[4],q[5]};if(ap_plan(AP_AT,16,p))return 1;}return 0; |
| 107 | call 0 returned 56 |
| 108 | branch 1 taken 8 (fallthrough) |
| 109 | branch 2 taken 48 |
| 110 | branch 3 taken 56 |
| 111 | branch 4 taken 8 (fallthrough) |
| 112 | -: 72:#else |
| 113 | -: 73: uint64_t r=0;if(omega_av_blks(&r,ids,n,q,16,n)!=OMEGA_OK)__builtin_trap();return (int)r; |
| 114 | -: 74:#endif |
| 115 | -: 75:} |
| 116 | function av_resfit called 24 returned 100% blocks executed 100% |
| 117 | 24: 76:static inline int av_resfit(const uint32_t *ids,size_t n,uint64_t stride,uint64_t layer) { |
| 118 | -: 77:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 119 | 56: 78: for(size_t i=0;i<n;i++)if(stride>UINT32_MAX || (uint64_t)ids[i]*stride+layer>UINT32_MAX)return 0;return 1; |
| 120 | branch 0 taken 40 (fallthrough) |
| 121 | branch 1 taken 8 |
| 122 | branch 2 taken 8 (fallthrough) |
| 123 | branch 3 taken 32 |
| 124 | branch 4 taken 48 |
| 125 | branch 5 taken 8 (fallthrough) |
| 126 | -: 79:#else |
| 127 | -: 80: uint64_t q[16]={stride,layer},r=0;if(omega_av_rfit(&r,ids,n,q,16,n)!=OMEGA_OK)__builtin_trap();return (int)r; |
| 128 | -: 81:#endif |
| 129 | -: 82:} |
| 130 | function av_gather called 8 returned 100% blocks executed 100% |
| 131 | 8: 83:static inline void av_gather(const void *s,size_t sn,void *d,size_t dn,const uint64_t q[16]) { |
| 132 | -: 84:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 133 | -: 85: (void)sn;(void)dn; |
| 134 | 104: 86: for(size_t t=0;t<q[0];t++)for(size_t h=0;h<q[1];h++)memcpy((uint8_t*)d+(t*q[1]+h)*q[2],(const uint8_t*)s+(t*q[3]+h*q[4])*q[5],q[2]); |
| 135 | branch 0 taken 64 |
| 136 | branch 1 taken 32 (fallthrough) |
| 137 | branch 2 taken 32 |
| 138 | branch 3 taken 8 (fallthrough) |
| 139 | -: 87:#else |
| 140 | -: 88: uint64_t r=0;if(omega_av_gath(&r,s,sn,d,dn,q,16)!=OMEGA_OK || r)__builtin_trap(); |
| 141 | -: 89:#endif |
| 142 | 8: 90:} |
| 143 | function av_stage called 24 returned 100% blocks executed 100% |
| 144 | 24: 91:static inline void av_stage(const void *s,size_t sn,void *d,size_t dn,const uint32_t *ids,const uint64_t q[16]) { |
| 145 | -: 92:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 146 | -: 93: (void)sn;(void)dn; |
| 147 | 8000072: 94: for(size_t i=0;i<q[0];i++)memcpy((uint8_t*)d+(q[4]+i)*q[3],(const uint8_t*)s+(uint64_t)ids[i]*q[1]+q[2],q[3]); |
| 148 | branch 0 taken 8000048 |
| 149 | branch 1 taken 24 (fallthrough) |
| 150 | -: 95:#else |
| 151 | -: 96: /* Three independent data views plus metadata exceed six unsized seed slots. |
| 152 | -: 97: * Dispatch pointer windows only; every byte/data access remains in Omega. */ |
| 153 | -: 98: for(uint64_t start=0;;) { |
| 154 | -: 99: uint64_t count=q[0]-start;if(count>1000000)count=1000000; |
| 155 | -: 100: uint64_t wq[16]={count,q[1],q[2],q[3],q[4]+start},r=0; |
| 156 | -: 101: if(omega_av_stage(&r,s,sn,d,dn,start?ids+start:ids,count,wq,16)!=OMEGA_OK || r)__builtin_trap(); |
| 157 | -: 102: if(count==q[0]-start)break; |
| 158 | -: 103: start+=count; |
| 159 | -: 104: } |
| 160 | -: 105:#endif |
| 161 | 24: 106:} |
| 162 | function av_reset called 8 returned 100% blocks executed 100% |
| 163 | 8: 107:static inline void av_reset(int32_t *slots,size_t nb,const uint32_t *ids,size_t n) { |
| 164 | -: 108:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 165 | 32: 109: (void)nb;for(size_t i=0;i<n;i++)slots[ids[i]]=-1; |
| 166 | branch 0 taken 24 |
| 167 | branch 1 taken 8 (fallthrough) |
| 168 | -: 110:#else |
| 169 | -: 111: uint64_t r=0;if(omega_av_reset(&r,slots,nb,ids,n,n)!=OMEGA_OK || r)__builtin_trap(); |
| 170 | -: 112:#endif |
| 171 | 8: 113:} |
| 172 | function av_headmap called 16 returned 100% blocks executed 100% |
| 173 | 16: 114:static inline void av_headmap(uint32_t *d,uint64_t nqh,uint64_t nkv,uint64_t hb,uint64_t mutant) { |
| 174 | -: 115:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 175 | 144: 116: for(uint64_t i=0;i<nqh;i++){uint64_t p[16]={i,nqh,nkv,hb,mutant};(void)ap_plan(AP_AT,25,p);d[i]=(uint32_t)p[8];} |
| 176 | call 0 returned 128 |
| 177 | branch 1 taken 128 |
| 178 | branch 2 taken 16 (fallthrough) |
| 179 | -: 117:#else |
| 180 | -: 118: uint64_t q[16]={0,nqh,nkv,hb,mutant},r=0;if(omega_av_hmap(&r,d,nqh,q,16)!=OMEGA_OK || r)__builtin_trap(); |
| 181 | -: 119:#endif |
| 182 | 16: 120:} |
| 183 | function av_eff called 16 returned 100% blocks executed 100% |
| 184 | 16: 121:static inline void av_eff(uint32_t *d,const uint32_t *ctx,const uint32_t *nb,size_t n,uint64_t bs) { |
| 185 | -: 122:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 186 | 8000104: 123: for(size_t i=0;i<n;i++){uint64_t p[16]={ctx[i],nb[i],bs};(void)ap_plan(AP_AT,15,p);d[i]=(uint32_t)p[8];} |
| 187 | call 0 returned 8000088 |
| 188 | branch 1 taken 8000088 |
| 189 | branch 2 taken 16 (fallthrough) |
| 190 | -: 124:#else |
| 191 | -: 125: av_memcpy(d,ctx,n*sizeof *ctx); |
| 192 | -: 126: uint64_t r=0;if(omega_av_eff(&r,nb,n,d,n,bs)!=OMEGA_OK || r)__builtin_trap(); |
| 193 | -: 127:#endif |
| 194 | 16: 128:} |
| 195 | function av_best called 16 returned 100% blocks executed 100% |
| 196 | 16: 129:static inline uint32_t av_best(const uint32_t *e,size_t n,uint64_t hd) { |
| 197 | -: 130:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 198 | 8000104: 131: uint32_t r=0;for(size_t i=0;i<n;i++){uint64_t p[16]={e[i],hd};(void)ap_plan(AP_AT,3,p);if(p[8]>r)r=(uint32_t)p[8];}return r; |
| 199 | call 0 returned 8000088 |
| 200 | branch 1 taken 8 (fallthrough) |
| 201 | branch 2 taken 8000080 |
| 202 | branch 3 taken 8000088 |
| 203 | branch 4 taken 16 (fallthrough) |
| 204 | -: 132:#else |
| 205 | -: 133: uint64_t r=0;if(omega_av_best(&r,e,n,n,hd)!=OMEGA_OK)__builtin_trap();return (uint32_t)r; |
| 206 | -: 134:#endif |
| 207 | -: 135:} |
| 208 | function av_max called 16 returned 100% blocks executed 100% |
| 209 | 16: 136:static inline uint32_t av_max(const uint32_t *s,size_t n) { |
| 210 | -: 137:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 211 | 8000104: 138: uint32_t r=1;for(size_t i=0;i<n;i++)if(s[i]>r)r=s[i];return r; |
| 212 | branch 0 taken 32 (fallthrough) |
| 213 | branch 1 taken 8000056 |
| 214 | branch 2 taken 8000088 |
| 215 | branch 3 taken 16 (fallthrough) |
| 216 | -: 139:#else |
| 217 | -: 140: uint64_t r=0;if(omega_av_max(&r,s,n,n)!=OMEGA_OK)__builtin_trap();return (uint32_t)r; |
| 218 | -: 141:#endif |
| 219 | -: 142:} |
| 220 | -: 143:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 221 | function av_exp2_oracle called 48 returned 100% blocks executed 92% |
| 222 | 48: 144:static inline float av_exp2_oracle(float x) { |
| 223 | 48*: 145: if(x<=-127.0f)return 0.0f;if(x>127.0f)x=127.0f; |
| 224 | branch 0 taken 8 (fallthrough) |
| 225 | branch 1 taken 40 |
| 226 | branch 2 taken 0 (fallthrough) |
| 227 | branch 3 taken 40 |
| 228 | 40: 146: int n=(int)(x+(x<0?-0.5f:0.5f));float f=x-(float)n,px=1.535336188319500e-4f; |
| 229 | branch 0 taken 16 (fallthrough) |
| 230 | branch 1 taken 24 |
| 231 | 40: 147: px=px*f+1.339887440266574e-3f;px=px*f+9.618437357674640e-3f;px=px*f+5.550332471162809e-2f; |
| 232 | 40: 148: px=px*f+2.402264791363012e-1f;px=px*f+6.931472028550421e-1f;px=1.0f+f*px; |
| 233 | 40: 149: if(n < -126){px*=0.5f;n=-126;}uint32_t b=(uint32_t)(n+127)<<23;float s;memcpy(&s,&b,4);return px*s; |
| 234 | branch 0 taken 8 (fallthrough) |
| 235 | branch 1 taken 32 |
| 236 | -: 150:} |
| 237 | -: 151:#endif |
| 238 | function av_fold called 8 returned 100% blocks executed 100% |
| 239 | 8: 152:static inline void av_fold(const float *p,float *out,size_t rows,uint32_t S,uint32_t HD) { |
| 240 | -: 153:#if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS |
| 241 | 8: 154: size_t pw=HD+2; |
| 242 | 40: 155: for(size_t r=0;r<rows;r++){float mx=-__builtin_inff();size_t base=r*S*pw; |
| 243 | branch 0 taken 32 |
| 244 | branch 1 taken 8 (fallthrough) |
| 245 | 96: 156: for(uint32_t s=0;s<S;s++)if(p[base+s*pw+HD]>mx)mx=p[base+s*pw+HD]; |
| 246 | branch 0 taken 24 (fallthrough) |
| 247 | branch 1 taken 40 |
| 248 | branch 2 taken 64 |
| 249 | branch 3 taken 32 (fallthrough) |
| 250 | 32: 157: if(!(mx>-__builtin_inff())){memset(out+r*HD,0,HD*4);continue;} |
| 251 | branch 0 taken 8 (fallthrough) |
| 252 | branch 1 taken 24 |
| 253 | 72: 158: float w[16],lsum=0;for(uint32_t s=0;s<S;s++){w[s]=av_exp2_oracle(p[base+s*pw+HD]-mx);lsum+=w[s]*p[base+s*pw+HD+1];} |
| 254 | call 0 returned 48 |
| 255 | branch 1 taken 48 |
| 256 | branch 2 taken 24 (fallthrough) |
| 257 | 600: 159: float inv=1.0f/lsum;for(uint32_t d=0;d<HD;d++){float a=0;for(uint32_t s=0;s<S;s++)a+=w[s]*p[base+s*pw+d];out[r*HD+d]=a*inv;} |
| 258 | branch 0 taken 384 |
| 259 | branch 1 taken 192 (fallthrough) |
| 260 | branch 2 taken 192 |
| 261 | branch 3 taken 24 (fallthrough) |
| 262 | -: 160: } |
| 263 | -: 161:#else |
| 264 | -: 162: uint64_t q[16]={rows,S,HD},r=0;if(omega_av_fold(&r,p,rows*S*(HD+2),out,rows*HD,q,16)!=OMEGA_OK || r)__builtin_trap(); |
| 265 | -: 163:#endif |
| 266 | 8: 164:} |
| 267 | -: 165:#endif |