aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-12 16:55:28 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-12 16:55:28 +0200
commitca68b59475f6b1773fa62e6dbc4b68349602b441 (patch)
treea03251fefc3e39b209770cd96b974150163d9df9
parent762d285f3b914c877887469de06a70cee9028159 (diff)
downloadnissy-core-ca68b59475f6b1773fa62e6dbc4b68349602b441.tar.gz
nissy-core-ca68b59475f6b1773fa62e6dbc4b68349602b441.zip
Update build files to enable multithreading
Diffstat (limited to '')
-rw-r--r--Makefile16
-rwxr-xr-xconfigure.sh73
-rw-r--r--tools/010_stats_tables_h48/stats_tables_h48.c13
3 files changed, 66 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 8ec635c..5c655b7 100644
--- a/Makefile
+++ b/Makefile
@@ -3,34 +3,34 @@ include config.mk
3all: cube.o debugcube.o 3all: cube.o debugcube.o
4 4
5cube.s: clean 5cube.s: clean
6 ${CC} -D${ARCH} ${CFLAGS} -c -S -o cube.s src/nissy.c 6 ${CC} ${MACROS} ${CFLAGS} -c -S -o cube.s src/nissy.c
7 7
8cube.o: clean 8cube.o: clean
9 ${CC} -D${ARCH} ${CFLAGS} -c -o cube.o src/nissy.c 9 ${CC} ${MACROS} ${CFLAGS} -c -o cube.o src/nissy.c
10 10
11debugcube.o: clean 11debugcube.o: clean
12 ${CC} -D${ARCH} ${DBGFLAGS} -c -o debugcube.o src/nissy.c 12 ${CC} ${MACROS} ${DBGFLAGS} -c -o debugcube.o src/nissy.c
13 13
14clean: 14clean:
15 rm -rf *.o run 15 rm -rf *.o run
16 16
17test: debugcube.o 17test: debugcube.o
18 CC="${CC} -D${ARCH} ${DBGFLAGS}" ./test/test.sh 18 CC="${CC} ${MACROS} ${DBGFLAGS}" ./test/test.sh
19 19
20tool: cube.o 20tool: cube.o
21 mkdir -p tools/results 21 mkdir -p tools/results
22 CC="${CC} ${CFLAGS}" CUBEOBJ=cube.o ./tools/run_tool.sh 22 CC="${CC} ${MACROS} ${CFLAGS}" CUBEOBJ=cube.o ./tools/run_tool.sh
23 23
24debugtool: debugcube.o 24debugtool: debugcube.o
25 mkdir -p tools/results 25 mkdir -p tools/results
26 CC="${CC} ${DBGFLAGS}" CUBEOBJ=debugcube.o ./tools/run_tool.sh 26 CC="${CC} ${MACROS} ${DBGFLAGS}" CUBEOBJ=debugcube.o ./tools/run_tool.sh
27 27
28shell: cube.o 28shell: cube.o
29 mkdir -p tables 29 mkdir -p tables
30 ${CC} ${CFLAGS} -o run cube.o shell.c 30 ${CC} ${MACROS} ${CFLAGS} -o run cube.o shell.c
31 31
32debugshell: debugcube.o 32debugshell: debugcube.o
33 mkdir -p tables 33 mkdir -p tables
34 ${CC} ${DBGFLAGS} -o run debugcube.o shell.c 34 ${CC} ${MACROS} ${DBGFLAGS} -o run debugcube.o shell.c
35 35
36.PHONY: all clean test tool debugtool shell debugshell 36.PHONY: all clean test tool debugtool shell debugshell
diff --git a/configure.sh b/configure.sh
index 34da488..03873e5 100755
--- a/configure.sh
+++ b/configure.sh
@@ -1,51 +1,82 @@
1#!/bin/sh 1#!/bin/sh
2 2
3cc=${CC:-cc} 3greparch() {
4 $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1"
5}
6
7grepsan() {
8 $CC -fsanitize=$1 -dM -E -x c - </dev/null 2>/dev/null | grep "SANITIZE"
9}
10
11detectthreads() {
12 echo 16 # TODO: choose based on system
13}
4 14
5detectarch() { 15detectarch() {
6 ${cc} -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" 16 [ -n "$(greparch __AVX2__)" ] && detected="AVX2"
17 [ -n "$(greparch __ARM_NEON)" ] && detected="NEON"
18 [ -z "$detected" ] && detected="PORTABLE"
19
20 echo "$detected"
7} 21}
8detectsan() { 22
9 ${cc} -fsanitize=$1 -dM -E -x c - </dev/null 2>/dev/null \ 23validatecc() {
10 | grep "SANITIZE" 24 if ! (which "$CC" >/dev/null 2>&1) ; then
25 echo "Error: compiler '$CC' not found"
26 exit 1
27 fi
11} 28}
12 29
13[ -n "$(detectarch __AVX2__)" ] && detected="AVX2" 30validatethreads() {
14[ -n "$(detectarch __ARM_NEON)" ] && detected="NEON" 31 if [ "$THREADS" -le 0 ] || [ "$THREADS" -gt 128 ]; then
15[ -z "$detected" ] && detected="PORTABLE" 32 echo "Error: number of threads must be between 1 and 128"
33 exit 1
34 fi
35}
36
37validatearch() {
38 case "$ARCH" in
39 AVX2|NEON|PORTABLE)
40 ;;
41 *)
42 echo "Error: architecture '$ARCH' not supported"
43 exit 1
44 ;;
45 esac
46}
16 47
17ARCH=${ARCH-"$detected"} 48CC=${CC:-cc}
49THREADS=${THREADS-"$(detectthreads)"}
50ARCH=${ARCH-"$(detectarch)"}
18 51
19case "$ARCH" in 52validatecc
20AVX2|NEON|PORTABLE) 53validatethreads
21 ;; 54validatearch
22*)
23 echo "Error: architecture $ARCH not supported"
24 exit 1
25 ;;
26esac
27 55
28STD="-std=c99" 56STD="-std=c99"
29WFLAGS="-pedantic -Wall -Wextra" 57WFLAGS="-pedantic -Wall -Wextra"
30WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" 58WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas"
31 59
32[ "$ARCH" = "AVX2" ] && AVX="-mavx2" 60[ "$ARCH" = "AVX2" ] && AVX="-mavx2"
33[ -n "$(detectsan address)" ] && ADDR="-fsanitize=address" 61[ -n "$(grepsan address)" ] && ADDR="-fsanitize=address"
34[ -n "$(detectsan undefined)" ] && UNDEF="-fsanitize=undefined" 62[ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined"
35SAN="$ADDR $UNDEF" 63SAN="$ADDR $UNDEF"
36LIBS="-lpthread" 64LIBS="-lpthread"
37 65
38CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" 66CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3"
39DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" 67DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG"
68MACROS="-DTHREADS=$THREADS -D$ARCH"
40 69
41echo "Selected architecture: $ARCH" 70echo "Selected architecture: $ARCH"
42echo "Compiler: ${CC:-cc}" 71echo "Number of threads: $THREADS"
72echo "Compiler: $CC"
43 73
44{ 74{
45echo "ARCH = $ARCH"; 75echo "ARCH = $ARCH";
46echo ""; 76echo "";
47echo "CFLAGS = $CFLAGS"; 77echo "CFLAGS = $CFLAGS";
48echo "DBGFLAGS = $DBGFLAGS"; 78echo "DBGFLAGS = $DBGFLAGS";
79echo "MACROS = $MACROS"
49echo ""; 80echo "";
50echo "CC = ${cc}" 81echo "CC = $CC"
51} > config.mk 82} > config.mk
diff --git a/tools/010_stats_tables_h48/stats_tables_h48.c b/tools/010_stats_tables_h48/stats_tables_h48.c
index 8b65862..18fd411 100644
--- a/tools/010_stats_tables_h48/stats_tables_h48.c
+++ b/tools/010_stats_tables_h48/stats_tables_h48.c
@@ -3,7 +3,6 @@
3#include "../tool.h" 3#include "../tool.h"
4 4
5#define MAXMOVES 20 5#define MAXMOVES 20
6#define NTHREADS 32
7#define NCUBES_PER_THREAD 10000 6#define NCUBES_PER_THREAD 10000
8#define LOG_EVERY (NCUBES_PER_THREAD / 10) 7#define LOG_EVERY (NCUBES_PER_THREAD / 10)
9 8
@@ -57,10 +56,10 @@ run_thread(void *arg)
57void run(void) { 56void run(void) {
58 int64_t i, j, k, tot; 57 int64_t i, j, k, tot;
59 double avg; 58 double avg;
60 pthread_t thread[NTHREADS]; 59 pthread_t thread[THREADS];
61 thread_arg_t arg[NTHREADS]; 60 thread_arg_t arg[THREADS];
62 61
63 for (i = 0; i < NTHREADS; i++) { 62 for (i = 0; i < THREADS; i++) {
64 arg[i] = (thread_arg_t) { 63 arg[i] = (thread_arg_t) {
65 .thread_id = i, 64 .thread_id = i,
66 .n = NCUBES_PER_THREAD, 65 .n = NCUBES_PER_THREAD,
@@ -69,18 +68,18 @@ void run(void) {
69 pthread_create(&thread[i], NULL, run_thread, &arg[i]); 68 pthread_create(&thread[i], NULL, run_thread, &arg[i]);
70 } 69 }
71 70
72 for (i = 0; i < NTHREADS; i++) 71 for (i = 0; i < THREADS; i++)
73 pthread_join(thread[i], NULL); 72 pthread_join(thread[i], NULL);
74 73
75 for (j = 0; j < 12; j++) { 74 for (j = 0; j < 12; j++) {
76 printf("Data for h=%" PRId64 "\n", j); 75 printf("Data for h=%" PRId64 "\n", j);
77 for (k = 0, avg = 0.0; k <= 16; k++) { 76 for (k = 0, avg = 0.0; k <= 16; k++) {
78 for (i = 0, tot = 0; i < NTHREADS; i++) 77 for (i = 0, tot = 0; i < THREADS; i++)
79 tot += arg[i].v[j][k]; 78 tot += arg[i].v[j][k];
80 printf("%" PRId64 "\t%" PRId64 "\n", k, tot); 79 printf("%" PRId64 "\t%" PRId64 "\n", k, tot);
81 avg += tot * k; 80 avg += tot * k;
82 } 81 }
83 avg /= (double)(NCUBES_PER_THREAD * NTHREADS); 82 avg /= (double)(NCUBES_PER_THREAD * THREADS);
84 printf("Average: %.4lf\n", avg); 83 printf("Average: %.4lf\n", avg);
85 printf("\n"); 84 printf("\n");
86 } 85 }

Generated with cgit - Back to sebastiano.tronto.net