diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/benchmark_gendata_h48/benchmark_gendata_h48.c | 47 | ||||
| -rwxr-xr-x | tools/run_tool.sh | 27 | ||||
| -rw-r--r-- | tools/timerun.h | 39 |
3 files changed, 113 insertions, 0 deletions
diff --git a/tools/benchmark_gendata_h48/benchmark_gendata_h48.c b/tools/benchmark_gendata_h48/benchmark_gendata_h48.c new file mode 100644 index 0000000..efb6f6f --- /dev/null +++ b/tools/benchmark_gendata_h48/benchmark_gendata_h48.c | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include "../timerun.h" | ||
| 2 | #include "../../src/cube.h" | ||
| 3 | |||
| 4 | #define MAXDEPTH 10 | ||
| 5 | #define HVALUE 2 | ||
| 6 | #define OPTIONS "2;10" | ||
| 7 | #define LONGOPTIONS "h = 2, max depth = 10" | ||
| 8 | |||
| 9 | #define COCSEPSIZE 1119792 | ||
| 10 | #define ETABLESIZE(h) (((3393 * 495 * 70) >> 1) << (size_t)(h)) | ||
| 11 | |||
| 12 | char *buf; | ||
| 13 | |||
| 14 | void run(void) { | ||
| 15 | uint32_t *h48info; | ||
| 16 | int i; | ||
| 17 | int64_t s; | ||
| 18 | |||
| 19 | s = nissy_gendata("H48", OPTIONS, buf); | ||
| 20 | |||
| 21 | if (s == -1) { | ||
| 22 | printf("Error generating table\n"); | ||
| 23 | } else { | ||
| 24 | printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); | ||
| 25 | h48info = (uint32_t *)buf + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; | ||
| 26 | for (i = 0; i < MAXDEPTH+1; i++) | ||
| 27 | printf("%d:\t%" PRIu32 "\n", i, h48info[i+1]); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | int main() { | ||
| 32 | int64_t size; | ||
| 33 | |||
| 34 | size = nissy_datasize("H48", OPTIONS); | ||
| 35 | if (size == -1) { | ||
| 36 | printf("gendata_h48 benchmark: error in datasize\n"); | ||
| 37 | return 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | buf = malloc(size); | ||
| 41 | |||
| 42 | timerun(run, "benchmark gendata_h48 " LONGOPTIONS); | ||
| 43 | |||
| 44 | free(buf); | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
diff --git a/tools/run_tool.sh b/tools/run_tool.sh new file mode 100755 index 0000000..21b6ce9 --- /dev/null +++ b/tools/run_tool.sh | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | if [ -z "$TOOL" ]; then | ||
| 4 | echo "No tool selected (TOOL variable must be set)" | ||
| 5 | exit 1 | ||
| 6 | fi | ||
| 7 | |||
| 8 | CC="cc -std=c99 -pedantic -Wall -Wextra \ | ||
| 9 | -Wno-unused-parameter -Wno-unused-function -O3 -D$CUBETYPE \ | ||
| 10 | -D_POSIX_C_SOURCE=199309L" | ||
| 11 | |||
| 12 | [ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" | ||
| 13 | |||
| 14 | BIN="tools/run" | ||
| 15 | CUBEOBJ="cube.o" | ||
| 16 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | ||
| 17 | |||
| 18 | for t in tools/*; do | ||
| 19 | if [ ! -d "$t" ] || [ -z "$(echo "$t" | grep "$TOOL")" ]; then | ||
| 20 | continue | ||
| 21 | fi | ||
| 22 | $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; | ||
| 23 | $BIN | ||
| 24 | break | ||
| 25 | done | ||
| 26 | |||
| 27 | rm -rf $BIN $CUBEOBJ | ||
diff --git a/tools/timerun.h b/tools/timerun.h new file mode 100644 index 0000000..dabfde0 --- /dev/null +++ b/tools/timerun.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <inttypes.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <time.h> | ||
| 6 | |||
| 7 | double | ||
| 8 | timerun(void (*run)(void), char *name) | ||
| 9 | { | ||
| 10 | struct timespec start, end; | ||
| 11 | double tdiff, tdsec, tdnano; | ||
| 12 | |||
| 13 | printf("\n"); | ||
| 14 | fflush(stdout); | ||
| 15 | |||
| 16 | if (run == NULL) { | ||
| 17 | printf("> %s: nothing to run!\n", name); | ||
| 18 | fflush(stdout); | ||
| 19 | return -1.0; | ||
| 20 | } | ||
| 21 | |||
| 22 | printf("Running tool: %s\n", name); | ||
| 23 | printf("==========\n"); | ||
| 24 | fflush(stdout); | ||
| 25 | |||
| 26 | clock_gettime(CLOCK_MONOTONIC, &start); | ||
| 27 | run(); | ||
| 28 | clock_gettime(CLOCK_MONOTONIC, &end); | ||
| 29 | |||
| 30 | tdsec = end.tv_sec - start.tv_sec; | ||
| 31 | tdnano = end.tv_nsec - start.tv_nsec; | ||
| 32 | tdiff = tdsec + 1e-9 * tdnano; | ||
| 33 | |||
| 34 | printf("==========\n"); | ||
| 35 | printf("\nTotal time: %.4fs\n", tdiff); | ||
| 36 | fflush(stdout); | ||
| 37 | |||
| 38 | return tdiff; | ||
| 39 | } | ||
