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/sqlite/blob/master/ext/vec1/tool/vec1_algo_test.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / vec1 / tool / vec1_algo_test.c` 787 lines ยท 22663 bytes Raw Blame History 1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #include "vec1.c" 10 11 12 #ifdef VEC1_HAVE_NEON 13 /* 14 ** Run nIter iterations of a loop containing N independent, back-to-back 15 ** FMA chains (N float32x4_t accumulators, each updated once per 16 ** iteration) and return the elapsed time on vec1HardwareTimer(). 17 ** 18 ** N is a literal compile-time constant at every call site (see 19 ** MAKE_FMA_TEST below), so the "for(c...)" loop below is unrolled by 20 ** the compiler into straight-line code - there is no loop-control 21 ** instruction diluting the measurement, and for N==1 this is a single 22 ** dependent chain (true FMA latency); for larger N it is N independent 23 ** chains (FMA throughput, once N is large enough to hide the latency). 24 */ 25 #define MAKE_FMA_TEST(N) \ 26 static u64 vec1FmaTest##N(int nIter){ \ 27 float32x4_t acc[N]; \ 28 float32x4_t a = vdupq_n_f32(1.`000001f`); \ 29 float32x4_t b = vdupq_n_f32(0.`999999f`); \ 30 int c, r; \ 31 u64 t; \ 32 for(c=0; cbestRate ) bestRate = fmaPerTick; 99 } 100 101 nOptimal = (int)ceil(latency * bestRate); 102 103 printf("\n"); 104 printf("FMA latency (N=1, dependent chain): %.3f ticks\n", latency); 105 printf("FMA throughput (best of N tested): %.3f FMA/tick\n", bestRate); 106 printf("Little's Law: accumulators needed = latency * throughput\n"); 107 printf(" = %.3f * %.3f = %.2f -> use %d independent accumulators\n", 108 latency, bestRate, latency*bestRate, nOptimal); 109 } 110 #endif /* VEC1_HAVE_NEON */ 111 112 /* 113 ** Populate aTrans[] with transposed version of the array of centroids in 114 ** aCentroid[]. 115 */ 116 static void vec1TransposeCentroids( 117 const float *aCentroid, /* Packed array of centroids */ 118 int nElem, /* Number of elements in each vector */ 119 int nVector, /* Number of centroid vectors */ 120 int nWidth, /* Transpose width */ 121 float *aTrans /* Populate this array with transformation */ 122 ){ 123 int c, d; 124 float *pOut = aTrans; 125 126 /* nVector must be an integer multiple of nWidth */ 127 assert( (nVector % nWidth)==0 ); 128 129 for(c=0; c> 8) * (1.0 / `16777216`.0); // 24-bit mantissa 143 } 144 145 static void vec1RandomArray(Vec1Random *p, float *aRnd, int nRnd){ 146 int ii; 147 for(ii=0; iifBest && (fDist-fBest)/fDist>fTol) 762 || (fDistfTol) 763 ){ 764 fprintf(stderr, "algorithm FAILED...\n"); 765 return 1; 766 } 767 } 768 } 769 #endif 770 771 printf("Cycles: "); 772 if( t>(1000*1000*1000) ){ 773 printf("%.2fG\n", (double)t / `1000000000`.0); 774 }else if( t>(10*1000*1000) ){ 775 printf("%dM\n", (int)(t / (1000*1000))); 776 }else if( t>(1*1000*1000) ){ 777 printf("%.2fM\n", (double)t / (1000*1000)); 778 }else{ 779 printf("%d\n", (int)t); 780 } 781 782 return 0; 783 } 784 785 786 787