Skip to content

Commit

Permalink
single-func quantization
Browse files Browse the repository at this point in the history
Addresses #653.
  • Loading branch information
PeiMu committed Aug 7, 2023
1 parent 318d743 commit fdaece9
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 260 deletions.
46 changes: 46 additions & 0 deletions analysis/statistics/6b7355a4d6ed01b8ad7c698f9334a4f20f0a9a20.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

changeset: 1510:6b7355a4d6ed01b8ad7c698f9334a4f20f0a9a20
char kNewtonVersion[] = "0.3-alpha-1510 (6b7355a4d6ed01b8ad7c698f9334a4f20f0a9a20) (build 06-16-2023-14:[email protected]_64)";
\n./src/noisy/noisy-linux-EN -O0 applications/noisy/helloWorld.n -s
\n./src/newton/newton-linux-EN -v 0 -eP applications/newton/invariants/ViolinWithTemperatureDependence-pigroups.nt

Informational Report:
---------------------
Invariant "ViolinWithTemperatureDependenceForPiGroups" has 2 unique kernels, each with 2 column(s)...

Kernel 0 is a valid kernel:

1 1
-0.5 -0
1 0
0.5 0
0 -1
-0 -1


The ordering of parameters is: P1 P0 P3 P2 P4 P5

Pi group 0, Pi 0 is: P0^(-0.5) P1^( 1) P2^(0.5) P3^( 1) P4^( 0) P5^(-0)

Pi group 0, Pi 1 is: P0^(-0) P1^( 1) P2^( 0) P3^( 0) P4^(-1) P5^(-1)


Kernel 1 is a valid kernel:

1 0
-0.5 1
1 -2
0.5 -1
-0 -2
0 -2


The ordering of parameters is: P1 P0 P3 P2 P4 P5

Pi group 1, Pi 0 is: P0^(-0.5) P1^( 1) P2^(0.5) P3^( 1) P4^(-0) P5^( 0)

Pi group 1, Pi 1 is: P0^( 1) P1^( 0) P2^(-1) P3^(-2) P4^(-2) P5^(-2)




31 changes: 16 additions & 15 deletions applications/newton/llvm-ir/c-files/MadgwickAHRS.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ volatile float beta = betaDef; // 2 * proportional gain (Kp)
//---------------------------------------------------------------------------------------------------
// Function declarations

float invSqrt(float x);
//---------------------------------------------------------------------------------------------------
// Fast inverse square-root
// See: http://en.wikipedia.org/wiki/Fast_inverse_square_root

// 1/sqrtf();
float invSqrt(float x) {
float halfx = 0.5f * x;
float y = x;
//#pragma unsupported
long i = *(long*)&y;
i = 0x5f3759df - (i>>1);
y = *(float*)&i;
//#end
y = y * (1.5f - (halfx * y * y));
return y;
}

//====================================================================================================
// Functions
Expand Down Expand Up @@ -244,20 +259,6 @@ void MadgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, flo
*q3_ptr = q3;
}

//---------------------------------------------------------------------------------------------------
// Fast inverse square-root
// See: http://en.wikipedia.org/wiki/Fast_inverse_square_root

float invSqrt(float x) {
float halfx = 0.5f * x;
float y = x;
long i = *(long*)&y;
i = 0x5f3759df - (i>>1);
y = *(float*)&i;
y = y * (1.5f - (halfx * y * y));
return y;
}

//====================================================================================================
// END OF CODE
//====================================================================================================
2 changes: 1 addition & 1 deletion applications/newton/llvm-ir/c-files/MadgwickAHRSfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sqrt_rsqrt(int32_t x, int recip) {
// fp_y = fp_y * (1.5f - (halfx * fp_y * fp_y));
// return fp_y*FRAC_BASE;
} else {
int32_t res = (int32_t)sqrtf(x)<<(FRAC_Q/2);
int32_t res = (int32_t)sqrt((double)x)<<(FRAC_Q/2);
if (FRAC_Q%2)
return res*1.414213562;
else
Expand Down
55 changes: 5 additions & 50 deletions applications/newton/llvm-ir/c-files/vec_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,7 @@
#include <sys/time.h>
#include <time.h>

typedef struct timespec timespec;
timespec diff(timespec start, timespec end)
{
timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) {
temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else {
temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
}
return temp;
}

timespec sum(timespec t1, timespec t2) {
timespec temp;
if (t1.tv_nsec + t2.tv_nsec >= 1000000000) {
temp.tv_sec = t1.tv_sec + t2.tv_sec + 1;
temp.tv_nsec = t1.tv_nsec + t2.tv_nsec - 1000000000;
} else {
temp.tv_sec = t1.tv_sec + t2.tv_sec;
temp.tv_nsec = t1.tv_nsec + t2.tv_nsec;
}
return temp;
}

void printTimeSpec(timespec t, const char* prefix) {
printf("%s: %d.%09d\n", prefix, (int)t.tv_sec, (int)t.tv_nsec);
}

timespec tic( )
{
timespec start_time;
clock_gettime(CLOCK_REALTIME, &start_time);
return start_time;
}

void toc( timespec* start_time, const char* prefix )
{
timespec current_time;
clock_gettime(CLOCK_REALTIME, &current_time);
printTimeSpec( diff( *start_time, current_time ), prefix );
*start_time = current_time;
}

typedef int32_t bmx055fAcceleration;
typedef float bmx055fAcceleration;

#define NUM 102400

Expand All @@ -65,16 +20,16 @@ void vec_add(bmx055fAcceleration *vec_A, bmx055fAcceleration *vec_B, bmx055fAcce
}

int main() {
int32_t x[NUM], y[NUM], z[NUM];
float x[NUM], y[NUM], z[NUM];
for (size_t idx = 0; idx < NUM; idx++) {
x[idx] = rand() % INT8_MAX;
y[idx] = rand() % INT8_MAX;
}
timespec timer = tic();
// timespec timer = tic();
vec_add(x, y, z, NUM);
toc(&timer, "computation delay");
// toc(&timer, "computation delay");
for (size_t idx = 0; idx < NUM; idx++) {
printf("value of z[%d]=%d, ", idx, z[idx]);
printf("value of z[%d]=%f, ", idx, z[idx]);
}
return 0;
}
Loading

0 comments on commit fdaece9

Please sign in to comment.