diff options
Diffstat (limited to 'test/mppa/mmult')
-rw-r--r-- | test/mppa/mmult/Makefile | 72 | ||||
-rw-r--r-- | test/mppa/mmult/README.md | 17 | ||||
-rw-r--r-- | test/mppa/mmult/mmult.c | 44 |
3 files changed, 64 insertions, 69 deletions
diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index 9c00f8b0..2e077f5e 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -1,44 +1,28 @@ -PRNG=../lib/prng.c -CCOMP=../../../ccomp +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 -ALL= mmult-test-x86 mmult-test-k1c\ +PRNG=../prng/prng.c -all: $(ALL) - -%-test-x86: %.c $(PRNG) - gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ - -%-test-k1c: %.c $(PRNG) - k1-mbr-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ - -test-x86: mmult.c $(PRNG) - gcc -O2 -std=c99 $^ -o $@ - -test-k1c: mmult.c $(PRNG) - k1-mbr-gcc -O2 -std=c99 $^ -o $@ +ALL= mmult-test-gcc-x86 mmult-test-gcc-k1c mmult-test-ccomp-k1c\ -%.s: %.c $(CCOMP) - ccomp -O2 -S $< -o $@ +all: $(ALL) -test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) - k1-mbr-gcc $^ -o $@ +mmult-test-gcc-x86: mmult.c $(PRNG) + $(CC) $(CFLAGS) $^ -o $@ -.PHONY: -unittest: unittest-x86 unittest-k1c +mmult-test-gcc-k1c: mmult.c $(PRNG) + $(K1CC) $(CFLAGS) $^ -o $@ -.PHONY: -check: check-x86 check-k1c +mmult-test-ccomp-k1c: mmult.c $(PRNG) + $(CCOMP) $(CFLAGS) $^ -o $@ .PHONY: -compc-check: test-ccomp - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: mmult $< failed";\ - else\ - echo "k1c: Test mmult $< succeeded";\ - fi +test: test-x86 test-k1c .PHONY: -check-x86: test-x86 +test-x86: mmult-test-gcc-x86 @if ! ./$<; then\ >&2 echo "ERROR x86: $< failed";\ else\ @@ -46,7 +30,7 @@ check-x86: test-x86 fi .PHONY: -check-k1c: test-k1c +test-k1c: mmult-test-gcc-k1c @if ! k1-cluster -- ./$<; then\ >&2 echo "ERROR k1c: $< failed";\ else\ @@ -54,24 +38,12 @@ check-k1c: test-k1c fi .PHONY: -unittest-x86: mmult-test-x86 - @for test in $^; do\ - if ! ./$$test; then\ - >&2 echo "ERROR x86: $$test failed";\ - else\ - echo "x86: Test $$test Succeeded";\ - fi;\ - done - -.PHONY: -unittest-k1c: mmult-test-k1c - @for test in $^; do\ - if ! k1-cluster -- ./$$test; then\ - >&2 echo "ERROR k1c: $$test failed";\ - else\ - echo "k1c: Test $$test Succeeded";\ - fi;\ - done +check: mmult-test-ccomp-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: mmult $< failed";\ + else\ + echo "k1c: Test mmult $< succeeded";\ + fi .PHONY: clean: diff --git a/test/mppa/mmult/README.md b/test/mppa/mmult/README.md new file mode 100644 index 00000000..ef2bff7e --- /dev/null +++ b/test/mppa/mmult/README.md @@ -0,0 +1,17 @@ +MMULT +===== + +Examples of matrix multiplication using different methods. + +We compute matrix multiplication using column-based matrix multiplication, then row-based, and finally block based. + +The test verifies that the result is the same on the three methods. If it is the same, 0 will be returned. + +The following commands can be run inside the folder: + +- `make`: produces the unitary test binaries + - `mmult-test-gcc-x86` : binary from gcc on x86 + - `mmult-test-k1c-x86` : binary from gcc on k1c + - `mmult-test-ccomp-x86` : binary from ccomp on k1c +- `make test`: tests the return value of the binaries produced by gcc. +- `make check`: tests the return value of the binary produced by CompCert. diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c index b674ca80..aeb91d48 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -1,5 +1,5 @@ -#include "../lib/types.h" -#include "../lib/prng.h" +#include "../prng/types.h" +#include "../prng/prng.h" #define __UNIT_TEST_MMULT__ @@ -10,24 +10,28 @@ #endif void mmult_row(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) C[i][j] = 0; - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) - for (int k = 0 ; k < SIZE ; k++) + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + for (k = 0 ; k < SIZE ; k++) C[i][j] += A[i][k] * B[k][j]; } void mmult_col(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) C[i][j] = 0; - for (int k = 0 ; k < SIZE ; k++) - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + for (k = 0 ; k < SIZE ; k++) + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) C[i][j] += A[i][k] * B[k][j]; } @@ -41,10 +45,11 @@ typedef struct mblock { void divac_mul(mblock *C, const mblock *A, const mblock *B){ const int size = C->imax - C->imin; + int i, j, k; - for (int i = 0 ; i < size ; i++) - for (int j = 0 ; j < size ; j++) - for (int k = 0 ; k < size ; k++) + for (i = 0 ; i < size ; i++) + for (j = 0 ; j < size ; j++) + for (k = 0 ; k < size ; k++) MAT_IJ(C, i, j) += MAT_IJ(A, i, k) * MAT_IJ(B, k, j); } @@ -119,9 +124,10 @@ static uint64_t A[SIZE][SIZE], B[SIZE][SIZE]; int main(void){ srand(42); + int i, j; - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++){ + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++){ A[i][j] = randlong(); B[i][j] = randlong(); } @@ -130,8 +136,8 @@ int main(void){ mmult_col(C2, A, B); mmult_divac(C3, A, B); - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) if (!(C1[i][j] == C2[i][j] && C1[i][j] == C3[i][j])) return -1; |