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_attn_tables.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_attn_tables.h` 165 lines · 7879 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef OMEGA_ATTN_TABLES_H 3 #define OMEGA_ATTN_TABLES_H 4 #include "omega_attn_views.h" 5 #include "omega_api_plan.h" 6 #include "omega_gpu_hostmath.h" 7 static inline void av_ropegen(float *d,uint64_t pos,double theta,uint64_t dim,uint64_t width,size_t rows) { 8 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 9 for(size_t r=0;r`1000000`)count=`1000000`; 61 if(omega_av_touch(&r,start?ids+start:ids,count,slots,nb,touched,nb,g)!=OMEGA_OK)__builtin_trap(); 62 if(count==q[0]-start)break; 63 start+=count; 64 } 65 av_fill32(tab+q[3],1,(uint32_t)q[4]); 66 return result; 67 #endif 68 } 69 static inline int av_blocks(const uint32_t *ids,size_t n,const uint64_t q[16]) { 70 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 71 for(size_t i=0;iUINT32_MAX || (uint64_t)ids[i]*stride+layer>UINT32_MAX)return 0;return 1; 79 #else 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; 81 #endif 82 } 83 static inline void av_gather(const void *s,size_t sn,void *d,size_t dn,const uint64_t q[16]) { 84 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 85 (void)sn;(void)dn; 86 for(size_t t=0;t`1000000`)count=`1000000`; 100 uint64_t wq[16]={count,q[1],q[2],q[3],q[4]+start},r=0; 101 if(omega_av_stage(&r,s,sn,d,dn,start?ids+start:ids,count,wq,16)!=OMEGA_OK || r)__builtin_trap(); 102 if(count==q[0]-start)break; 103 start+=count; 104 } 105 #endif 106 } 107 static inline void av_reset(int32_t *slots,size_t nb,const uint32_t *ids,size_t n) { 108 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 109 (void)nb;for(size_t i=0;ir)r=(uint32_t)p[8];}return r; 132 #else 133 uint64_t r=0;if(omega_av_best(&r,e,n,n,hd)!=OMEGA_OK)__builtin_trap();return (uint32_t)r; 134 #endif 135 } 136 static inline uint32_t av_max(const uint32_t *s,size_t n) { 137 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 138 uint32_t r=1;for(size_t i=0;ir)r=s[i];return r; 139 #else 140 uint64_t r=0;if(omega_av_max(&r,s,n,n)!=OMEGA_OK)__builtin_trap();return (uint32_t)r; 141 #endif 142 } 143 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 144 static inline float av_exp2_oracle(float x) { 145 if(x<=-127.0f)return 0.0f;if(x>127.0f)x=127.0f; 146 int n=(int)(x+(x<0?-0.5f:0.5f));float f=x-(float)n,px=1.`535336188319500e`-4f; 147 px=px*f+1.`339887440266574e`-3f;px=px*f+9.`618437357674640e`-3f;px=px*f+5.`550332471162809e`-2f; 148 px=px*f+2.`402264791363012e`-1f;px=px*f+6.`931472028550421e`-1f;px=1.0f+f*px; 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; 150 } 151 #endif 152 static inline void av_fold(const float *p,float *out,size_t rows,uint32_t S,uint32_t HD) { 153 #if CUDAPP_MIGRATION_PENDING_ATTN_VIEWS 154 size_t pw=HD+2; 155 for(size_t r=0;rmx)mx=p[base+s*pw+HD]; 157 if(!(mx>-__builtin_inff())){memset(out+r*HD,0,HD*4);continue;} 158 float w[16],lsum=0;for(uint32_t s=0;s