From 0ea368e57710f6424cb888cebaff3fbd0e319897 Mon Sep 17 00:00:00 2001 From: Pei Mu Date: Mon, 15 May 2023 16:09:04 +0100 Subject: [PATCH] add debug macro to some micro-benchmarks Addresses #653. --- ...d7464f83d3682d7290233a8c47d2240af80519.txt | 46 ++++++++ .../CHStone_test/dfdiv/float64_div.cpp | 103 +++++++++++++++++ .../CHStone_test/dfmul/float64_mul.cpp | 103 +++++++++++++++++ applications/newton/llvm-ir/c-files/e_acosh.c | 99 ++++++++++++++++ applications/newton/llvm-ir/c-files/e_j0.c | 99 ++++++++++++++++ applications/newton/llvm-ir/c-files/sincosf.c | 106 +++++++++++++++++- 6 files changed, 550 insertions(+), 6 deletions(-) create mode 100644 analysis/statistics/76d7464f83d3682d7290233a8c47d2240af80519.txt diff --git a/analysis/statistics/76d7464f83d3682d7290233a8c47d2240af80519.txt b/analysis/statistics/76d7464f83d3682d7290233a8c47d2240af80519.txt new file mode 100644 index 000000000..5a81a038b --- /dev/null +++ b/analysis/statistics/76d7464f83d3682d7290233a8c47d2240af80519.txt @@ -0,0 +1,46 @@ + +changeset: 1487:76d7464f83d3682d7290233a8c47d2240af80519 +char kNewtonVersion[] = "0.3-alpha-1487 (76d7464f83d3682d7290233a8c47d2240af80519) (build 05-15-2023-13:16-pei@pei-G5-5500-Linux-5.19.0-41-generic-x86_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) + + + + diff --git a/applications/newton/llvm-ir/CHStone_test/dfdiv/float64_div.cpp b/applications/newton/llvm-ir/CHStone_test/dfdiv/float64_div.cpp index cc799e771..bdbefa85c 100644 --- a/applications/newton/llvm-ir/CHStone_test/dfdiv/float64_div.cpp +++ b/applications/newton/llvm-ir/CHStone_test/dfdiv/float64_div.cpp @@ -265,6 +265,10 @@ typedef float64 bmx055yAcceleration; float64 float64_div (bmx055xAcceleration a, bmx055yAcceleration b) { +#ifdef ASSUME + __builtin_assume(a > -16 && a < 16); + __builtin_assume(a > -15.4 && a < 16.3); +#endif flag aSign, bSign, zSign; int16 aExp, bExp, zExp; bits64 aSig, bSig, zSig; @@ -448,3 +452,102 @@ const float64 z_output[N] = { // printf ("%d\n", main_result); // return main_result; // } + + +// clang ../CHStone_test/dfdiv/float64_div.cpp -D DEBUG -D ASSUME -O0 -g -o float64_div_assume -lm +#ifdef DEBUG + +#include +#include +#include +#include +#include + +#define iteration_num 50000 + +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, ¤t_time); + printTimeSpec( diff( *start_time, current_time ), prefix ); + *start_time = current_time; +} + +/* + * random floating point, [min, max] + * */ +static bmx055xAcceleration +randomDouble(bmx055xAcceleration min, bmx055xAcceleration max) +{ + bmx055xAcceleration randDbValue = min + 1.0 * rand() / RAND_MAX * (max - min); + return randDbValue; +} + +int main(int argc, char** argv) { + double parameters[2]; + char *pEnd; + if (argc == 3) { + for (size_t idx = 0; idx < argc - 1; idx++) { + parameters[idx] = strtod(argv[idx + 1], &pEnd); + } + } else { + parameters[0] = 3.0; + parameters[1] = 10.0; + } + double result[iteration_num]; + bmx055xAcceleration xOps[iteration_num]; + bmx055yAcceleration yOps[iteration_num]; + for (size_t idx = 0; idx < iteration_num; idx++) { + xOps[idx] = randomDouble(parameters[0], parameters[1]); + yOps[idx] = randomDouble(parameters[0] + 0.6, parameters[1] + 0.3); + } + + timespec timer = tic(); + for (size_t idx = 0; idx < iteration_num; idx++) { + result[idx] = float64_div((uint64_t)(xOps[idx]), (uint64_t)(yOps[idx])); + } + + toc(&timer, "computation delay"); + + printf("results: %f\t%f\t%f\t%f\t%f\n", result[0], result[1], result[2], result[3], result[4]); + + return 0; +} +#endif diff --git a/applications/newton/llvm-ir/CHStone_test/dfmul/float64_mul.cpp b/applications/newton/llvm-ir/CHStone_test/dfmul/float64_mul.cpp index c9a5f0b79..5bb84c168 100644 --- a/applications/newton/llvm-ir/CHStone_test/dfmul/float64_mul.cpp +++ b/applications/newton/llvm-ir/CHStone_test/dfmul/float64_mul.cpp @@ -263,6 +263,10 @@ typedef float64 bmx055xAcceleration; typedef float64 bmx055yAcceleration; float64 float64_mul (bmx055xAcceleration a, bmx055yAcceleration b) { +#ifdef ASSUME + __builtin_assume(a > -16 && a < 16); + __builtin_assume(a > -15.4 && a < 16.3); +#endif flag aSign, bSign, zSign; int16 aExp, bExp, zExp; bits64 aSig, bSig, zSig0, zSig1; @@ -422,3 +426,102 @@ const float64 z_output[N] = { // printf ("%d\n", main_result); // return main_result; // } + + +// clang ../CHStone_test/dfmul/float64_mul.cpp -D DEBUG -D ASSUME -O0 -g -o float64_mul_assume -lm +#ifdef DEBUG + +#include +#include +#include +#include +#include + +#define iteration_num 50000 + +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, ¤t_time); + printTimeSpec( diff( *start_time, current_time ), prefix ); + *start_time = current_time; +} + +/* + * random floating point, [min, max] + * */ +static bmx055xAcceleration +randomDouble(bmx055xAcceleration min, bmx055xAcceleration max) +{ + bmx055xAcceleration randDbValue = min + 1.0 * rand() / RAND_MAX * (max - min); + return randDbValue; +} + +int main(int argc, char** argv) { + double parameters[2]; + char *pEnd; + if (argc == 3) { + for (size_t idx = 0; idx < argc - 1; idx++) { + parameters[idx] = strtod(argv[idx + 1], &pEnd); + } + } else { + parameters[0] = 3.0; + parameters[1] = 10.0; + } + double result[iteration_num]; + bmx055xAcceleration xOps[iteration_num]; + bmx055yAcceleration yOps[iteration_num]; + for (size_t idx = 0; idx < iteration_num; idx++) { + xOps[idx] = randomDouble(parameters[0], parameters[1]); + yOps[idx] = randomDouble(parameters[0] + 0.6, parameters[1] + 0.3); + } + + timespec timer = tic(); + for (size_t idx = 0; idx < iteration_num; idx++) { + result[idx] = float64_mul((uint64_t)(xOps[idx]), (uint64_t)(yOps[idx])); + } + + toc(&timer, "computation delay"); + + printf("results: %f\t%f\t%f\t%f\t%f\n", result[0], result[1], result[2], result[3], result[4]); + + return 0; +} +#endif diff --git a/applications/newton/llvm-ir/c-files/e_acosh.c b/applications/newton/llvm-ir/c-files/e_acosh.c index ef9053877..bd69c7856 100644 --- a/applications/newton/llvm-ir/c-files/e_acosh.c +++ b/applications/newton/llvm-ir/c-files/e_acosh.c @@ -48,6 +48,9 @@ double __ieee754_acosh(x) bmx055xAcceleration x; #endif { +#ifdef ASSUME + __builtin_assume(x > -16 && x < 16); +#endif double t; int hx; hx = __HI(x); @@ -68,3 +71,99 @@ double __ieee754_acosh(x) return log1p(t+sqrt(2.0*t+t*t)); } } + +// clang ../c-files/e_acosh.c -D DEBUG -D ASSUME -O3 -o e_acosh_assume -lm +#ifdef DEBUG + +#include +#include +#include +#include +#include + +#define iteration_num 500000 + +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, ¤t_time); + printTimeSpec( diff( *start_time, current_time ), prefix ); + *start_time = current_time; +} + +/* + * random floating point, [min, max] + * */ +static bmx055xAcceleration +randomDouble(bmx055xAcceleration min, bmx055xAcceleration max) +{ + bmx055xAcceleration randDbValue = min + 1.0 * rand() / RAND_MAX * (max - min); + return randDbValue; +} + +int main(int argc, char** argv) { + double parameters[2]; + char *pEnd; + if (argc == 3) { + for (size_t idx = 0; idx < argc - 1; idx++) { + parameters[idx] = strtod(argv[idx + 1], &pEnd); + } + } else { + parameters[0] = 3.0; + parameters[1] = 10.0; + } + double result[iteration_num]; + bmx055xAcceleration xOps[iteration_num]; + for (size_t idx = 0; idx < iteration_num; idx++) { + xOps[idx] = randomDouble(parameters[0], parameters[1]); + } + + timespec timer = tic(); + for (size_t idx = 0; idx < iteration_num; idx++) { + result[idx] = __ieee754_acosh(xOps[idx]); + } + + toc(&timer, "computation delay"); + + printf("results: %f\t%f\t%f\t%f\t%f\n", result[0], result[1], result[2], result[3], result[4]); + + return 0; +} +#endif diff --git a/applications/newton/llvm-ir/c-files/e_j0.c b/applications/newton/llvm-ir/c-files/e_j0.c index 15163deab..1320cbdae 100644 --- a/applications/newton/llvm-ir/c-files/e_j0.c +++ b/applications/newton/llvm-ir/c-files/e_j0.c @@ -97,6 +97,9 @@ double __ieee754_j0(x) bmx055xAcceleration x; #endif { +#ifdef ASSUME + __builtin_assume(x > -16 && x < 16); +#endif double z, s,c,ss,cc,r,u,v; int hx,ix; @@ -406,3 +409,99 @@ static double qzero(x) s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); return (-.125 + r/s)/x; } + +// clang ../c-files/e_j0.c -D DEBUG -D ASSUME -O3 -o e_j0_assume -lm +#ifdef DEBUG + +#include +#include +#include +#include +#include + +#define iteration_num 500000 + +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, ¤t_time); + printTimeSpec( diff( *start_time, current_time ), prefix ); + *start_time = current_time; +} + +/* + * random floating point, [min, max] + * */ +static bmx055xAcceleration +randomDouble(bmx055xAcceleration min, bmx055xAcceleration max) +{ + bmx055xAcceleration randDbValue = min + 1.0 * rand() / RAND_MAX * (max - min); + return randDbValue; +} + +int main(int argc, char** argv) { + double parameters[2]; + char *pEnd; + if (argc == 3) { + for (size_t idx = 0; idx < argc - 1; idx++) { + parameters[idx] = strtod(argv[idx + 1], &pEnd); + } + } else { + parameters[0] = 3.0; + parameters[1] = 10.0; + } + double result[iteration_num]; + bmx055xAcceleration xOps[iteration_num]; + for (size_t idx = 0; idx < iteration_num; idx++) { + xOps[idx] = randomDouble(parameters[0], parameters[1]); + } + + timespec timer = tic(); + for (size_t idx = 0; idx < iteration_num; idx++) { + result[idx] = __ieee754_j0(xOps[idx]); + } + + toc(&timer, "computation delay"); + + printf("results: %f\t%f\t%f\t%f\t%f\n", result[0], result[1], result[2], result[3], result[4]); + + return 0; +} +#endif diff --git a/applications/newton/llvm-ir/c-files/sincosf.c b/applications/newton/llvm-ir/c-files/sincosf.c index 6d3f7edc8..ee4a91341 100644 --- a/applications/newton/llvm-ir/c-files/sincosf.c +++ b/applications/newton/llvm-ir/c-files/sincosf.c @@ -43,6 +43,9 @@ typedef double bmx055xAcceleration; void libc_sincosf (bmx055xAcceleration y, float *sinp, float *cosp) { +#ifdef ASSUME + __builtin_assume(y > -16 && y < 16); +#endif double x = y; double s; int n; @@ -105,10 +108,101 @@ libc_sincosf (bmx055xAcceleration y, float *sinp, float *cosp) } } -//#endif +// clang ../c-files/sincosf.c -D DEBUG -D ASSUME -O3 -o sincosf_assume -lm +#ifdef DEBUG + +#include +#include +#include +#include +#include -//int main() { -// float sinp, cosp; -// libc_sincosf (35.85, &sinp, &cosp); -// printf("sinp: %f, cosp: %f\n", sinp, cosp); -//} \ No newline at end of file +#define iteration_num 500000 + +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, ¤t_time); + printTimeSpec( diff( *start_time, current_time ), prefix ); + *start_time = current_time; +} + +/* + * random floating point, [min, max] + * */ +static bmx055xAcceleration +randomDouble(bmx055xAcceleration min, bmx055xAcceleration max) +{ + bmx055xAcceleration randDbValue = min + 1.0 * rand() / RAND_MAX * (max - min); + return randDbValue; +} + +int main(int argc, char** argv) { + double parameters[2]; + char *pEnd; + if (argc == 3) { + for (size_t idx = 0; idx < argc - 1; idx++) { + parameters[idx] = strtod(argv[idx + 1], &pEnd); + } + } else { + parameters[0] = 3.0; + parameters[1] = 10.0; + } + double result[iteration_num]; + bmx055xAcceleration xOps[iteration_num]; + for (size_t idx = 0; idx < iteration_num; idx++) { + xOps[idx] = randomDouble(parameters[0], parameters[1]); + } + + timespec timer = tic(); + float sinp, cosp; + for (size_t idx = 0; idx < iteration_num; idx++) { + sinp = cosp = 0; + libc_sincosf(xOps[idx], &sinp, &cosp); + result[idx] = sinp; + } + + toc(&timer, "computation delay"); + + printf("results: %f\t%f\t%f\t%f\t%f\n", result[0], result[1], result[2], result[3], result[4]); + + return 0; +} +#endif