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/omega-mv/blob/main/research/m15/spbm/load.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / research / m15 / spbm / load.c` 73 lines ยท 2803 bytes Raw Blame History 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Bounded CPU calibration load. Does not access firmware or device controls. */ 3 #define _GNU_SOURCE 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 15 static atomic_int stop; 16 struct worker { int cpu, error; uint64_t cpu_ns, iterations; float result; }; 17 static uint64_t cpu_time(void) 18 { 19 struct timespec t; 20 if(clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t)) { perror("thread clock"); exit(1); } 21 return (uint64_t)t.tv_sec*`1000000000`+t.tv_nsec; 22 } 23 static void *run(void *arg) 24 { 25 struct worker *w=arg; 26 cpu_set_t set; 27 uint64_t start, n=0; 28 float32x4_t a[8], scale=vdupq_n_f32(.99999f), bias=vdupq_n_f32(.00001f); 29 CPU_ZERO(&set); CPU_SET(w->cpu,&set); 30 w->error=pthread_setaffinity_np(pthread_self(),sizeof(set),&set); 31 if(w->error) return NULL; 32 for(int i=0;i<8;i++) a[i]=vdupq_n_f32((float)i+2.0f); 33 start=cpu_time(); 34 while(!atomic_load_explicit(&stop,memory_order_relaxed)) { 35 for(int i=0;i<4096;i++) { 36 for(int j=0;j<8;j++) a[j]=vfmaq_f32(bias,a[j],scale); 37 /* Keep all independent vectors live, including when rounded to a fixed point. */ 38 __asm__ volatile("" : "+w"(a[0]), "+w"(a[1]), "+w"(a[2]), "+w"(a[3]), 39 "+w"(a[4]), "+w"(a[5]), "+w"(a[6]), "+w"(a[7])); 40 } 41 n+=4096; 42 } 43 w->cpu_ns=cpu_time()-start; w->iterations=n; w->result=0; 44 for(int i=0;i<8;i++) w->result+=vaddvq_f32(a[i]); 45 return NULL; 46 } 47 int main(int argc,char **argv) 48 { 49 pthread_t threads[10]; struct worker w[10]={0}; 50 char *end; unsigned long seconds; 51 int p,failed=0,n=10; 52 /* Optional third argument: worker count 1..10 (default 10, as in 53 * collections 01-03). */ 54 if((argc!=3 && argc!=4) || (strcmp(argv[1],"p") && strcmp(argv[1],"e"))) return 2; 55 if(argc==4) { n=atoi(argv[3]); if(n<1 || n>10) return 2; } 56 seconds=strtoul(argv[2],&end,10); if(*end || seconds<1 || seconds>120) return 2; 57 p=!strcmp(argv[1],"p"); 58 for(int i=0;i>4)&0xfff)!=(unsigned int)(p?0xd85:0xd87)) return 1; 64 if(pthread_create(&threads[i],NULL,run,&w[i])) exit(1); 65 } 66 sleep(seconds); atomic_store(&stop,1); 67 for(int i=0;i