From cb95ca08d592b9030e20dc556c83c2d400928ba3 Mon Sep 17 00:00:00 2001 From: Fatih Cetinkaya <965295+devfacet@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:06:12 -0400 Subject: [PATCH 1/3] Improve tests --- .github/workflows/test.yaml | 10 ++++++--- Makefile | 28 ++++++++++++++++++------- scripts/docker/Dockerfile.arm-cmsis-dsp | 2 +- scripts/docker/Dockerfile.arm-neon | 2 +- scripts/docker/Dockerfile.armv7-neon | 2 +- scripts/docker/Dockerfile.armv8-neon | 2 +- scripts/docker/Dockerfile.generic | 2 +- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d955635..311c3b4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -80,12 +80,16 @@ jobs: run: | docker buildx build --platform ${{ matrix.platform }} -f scripts/docker/${{ matrix.dockerfile }} -t ${{ matrix.tag }} . --load if [ "${{ matrix.test }}" == "arm-neon" ]; then - docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} /nn/build/tests/arch/arm/neon/neuron + TESTS=arch/arm/neon/dot_product_perf,arch/arm/neon/neuron,arch/arm/neon/neuron_perf elif [ "${{ matrix.test }}" == "arm-cmsis-dsp" ]; then - docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} /nn/build/tests/arch/arm/cmsis-dsp/neuron + TESTS=arch/arm/cmsis-dsp/dot_product_perf,arch/arm/cmsis-dsp/neuron,arch/arm/cmsis-dsp/neuron_perf elif [ "${{ matrix.test }}" == "generic" ]; then - docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} /nn/build/tests/arch/generic/neuron + TESTS=arch/arm/generic/dot_product,arch/arm/generic/dot_product_perf,arch/arm/generic/layer,arch/arm/generic/neuron,arch/arm/generic/neuron_perf else echo "unknown test" exit 1 fi + IFS=',' read -ra TESTS <<< "$TESTS" + for TEST in "${TESTS[@]}"; do + docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} "/nn/build/tests/${TEST}" + done diff --git a/Makefile b/Makefile index 44be90c..d27b097 100644 --- a/Makefile +++ b/Makefile @@ -27,22 +27,34 @@ clean: echo "build directory does not exist, skipping"; \ fi -## run-test Run a test (e.g., make run-test ARCH=generic TEST=arch/generic/neuron) -run-test: +## test Run tests (e.g., make test ARCH=generic) +test: + @$(MAKE) build-tests ARCH=$(ARCH) TECH=$(TECH) + @echo " " + @$(eval TESTS := $(shell find tests/arch/$(ARCH) -type f -name 'main.c' | grep -E "$(TECH_FILTER)" | sed 's|/main.c||' | sed 's|tests/||')) + @for test in $(TESTS); do \ + $(MAKE) run-test ARCH=$(ARCH) TECH=$(TECH) TEST=$$test || exit 1; \ + done + +## build-test Build a test (e.g., make build-test ARCH=generic TEST=arch/generic/neuron) +build-test: @echo building $(TEST) @ARCH=$(ARCH) TECH=$(TECH) ARTIFACT=tests/$(TEST) scripts/shell/build_artifact.sh - @echo running $(TEST) - @ARCH=$(ARCH) TECH=$(TECH) ARTIFACT=tests/$(TEST) ARGS="$(ARGS)" scripts/shell/run_artifact.sh - @echo " " -## test Run tests (e.g., make test ARCH=generic) -test: +## build-tests Build tests (e.g., make build-tests ARCH=generic) +build-tests: @$(eval TECH_FILTER := $(if $(TECH),$(shell echo $(TECH) | tr ',' '|'),.*)) @$(eval TESTS := $(shell find tests/arch/$(ARCH) -type f -name 'main.c' | grep -E "$(TECH_FILTER)" | sed 's|/main.c||' | sed 's|tests/||')) @for test in $(TESTS); do \ - $(MAKE) run-test ARCH=$(ARCH) TECH=$(TECH) TEST=$$test || exit 1; \ + $(MAKE) build-test ARCH=$(ARCH) TECH=$(TECH) TEST=$$test || exit 1; \ done +## run-test Run a test (e.g., make run-test ARCH=generic TEST=arch/generic/neuron) +run-test: + @echo running $(TEST) + @ARCH=$(ARCH) TECH=$(TECH) ARTIFACT=tests/$(TEST) ARGS="$(ARGS)" scripts/shell/run_artifact.sh + @echo " " + ## build-example Build an example (e.g., make build-example ARCH=generic EXAMPLE=arch/generic/neuron) build-example: @echo building $(EXAMPLE) diff --git a/scripts/docker/Dockerfile.arm-cmsis-dsp b/scripts/docker/Dockerfile.arm-cmsis-dsp index a2690a8..5d49827 100644 --- a/scripts/docker/Dockerfile.arm-cmsis-dsp +++ b/scripts/docker/Dockerfile.arm-cmsis-dsp @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY . /nn WORKDIR /nn RUN make build-examples ARCH=arm TECH=cmsis-dsp LDFLAGS="-lm" -RUN make test ARCH=arm TECH=cmsis-dsp LDFLAGS="-lm" +RUN make build-tests ARCH=arm TECH=cmsis-dsp LDFLAGS="-lm" # Runtime FROM ubuntu:latest diff --git a/scripts/docker/Dockerfile.arm-neon b/scripts/docker/Dockerfile.arm-neon index 19efc6a..f94f089 100644 --- a/scripts/docker/Dockerfile.arm-neon +++ b/scripts/docker/Dockerfile.arm-neon @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY . /nn WORKDIR /nn RUN make build-examples ARCH=arm TECH=neon LDFLAGS="-lm" -RUN make test ARCH=arm TECH=neon LDFLAGS="-lm" +RUN make build-tests ARCH=arm TECH=neon LDFLAGS="-lm" # Runtime FROM ubuntu:latest diff --git a/scripts/docker/Dockerfile.armv7-neon b/scripts/docker/Dockerfile.armv7-neon index 9b3044d..731a9b1 100644 --- a/scripts/docker/Dockerfile.armv7-neon +++ b/scripts/docker/Dockerfile.armv7-neon @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY . /nn WORKDIR /nn RUN make build-examples ARCH=arm TECH=neon LDFLAGS="-lm" CFLAGS="-mfpu=neon-vfpv4" -RUN make test ARCH=arm TECH=neon LDFLAGS="-lm" CFLAGS="-mfpu=neon-vfpv4" +RUN make build-tests ARCH=arm TECH=neon LDFLAGS="-lm" CFLAGS="-mfpu=neon-vfpv4" # Runtime FROM arm32v7/ubuntu:latest diff --git a/scripts/docker/Dockerfile.armv8-neon b/scripts/docker/Dockerfile.armv8-neon index 22006f6..8b9c309 100644 --- a/scripts/docker/Dockerfile.armv8-neon +++ b/scripts/docker/Dockerfile.armv8-neon @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY . /nn WORKDIR /nn RUN make build-examples ARCH=arm TECH=neon LDFLAGS="-lm" -RUN make test ARCH=arm TECH=neon LDFLAGS="-lm" +RUN make build-tests ARCH=arm TECH=neon LDFLAGS="-lm" # Runtime FROM arm64v8/ubuntu:latest diff --git a/scripts/docker/Dockerfile.generic b/scripts/docker/Dockerfile.generic index 68657e0..72d5b06 100644 --- a/scripts/docker/Dockerfile.generic +++ b/scripts/docker/Dockerfile.generic @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY . /nn WORKDIR /nn RUN make build-examples ARCH=generic LDFLAGS="-lm" -RUN make test ARCH=generic LDFLAGS="-lm" +RUN make build-tests ARCH=generic LDFLAGS="-lm" # Runtime FROM ubuntu:latest From e70c633da5d3d833b440495cb89aa4117df6a7af Mon Sep 17 00:00:00 2001 From: Fatih Cetinkaya <965295+devfacet@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:09:58 -0400 Subject: [PATCH 2/3] Fix test --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 311c3b4..290ae1d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -84,7 +84,7 @@ jobs: elif [ "${{ matrix.test }}" == "arm-cmsis-dsp" ]; then TESTS=arch/arm/cmsis-dsp/dot_product_perf,arch/arm/cmsis-dsp/neuron,arch/arm/cmsis-dsp/neuron_perf elif [ "${{ matrix.test }}" == "generic" ]; then - TESTS=arch/arm/generic/dot_product,arch/arm/generic/dot_product_perf,arch/arm/generic/layer,arch/arm/generic/neuron,arch/arm/generic/neuron_perf + TESTS=arch/generic/dot_product,arch/generic/dot_product_perf,arch/generic/layer,arch/generic/neuron,arch/generic/neuron_perf else echo "unknown test" exit 1 From d6af1b48801fcd465317afabd196c80c3b53fabb Mon Sep 17 00:00:00 2001 From: Fatih Cetinkaya <965295+devfacet@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:17:05 -0400 Subject: [PATCH 3/3] Typo --- tests/arch/arm/cmsis-dsp/neuron/main.c | 2 +- tests/arch/arm/neon/neuron/main.c | 2 +- tests/arch/generic/neuron/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/arch/arm/cmsis-dsp/neuron/main.c b/tests/arch/arm/cmsis-dsp/neuron/main.c index 0c29c6f..eb6df61 100644 --- a/tests/arch/arm/cmsis-dsp/neuron/main.c +++ b/tests/arch/arm/cmsis-dsp/neuron/main.c @@ -131,6 +131,6 @@ int main() { .expected_output = 0.000012f, }, }; - run_test_cases(test_cases, N_TEST_CASES, "nn_dot_product_cmsis", nn_dot_product_cmsis); + run_test_cases(test_cases, N_TEST_CASES, "nn_neuron", nn_dot_product_cmsis); return 0; } diff --git a/tests/arch/arm/neon/neuron/main.c b/tests/arch/arm/neon/neuron/main.c index 281e60c..1ed5928 100644 --- a/tests/arch/arm/neon/neuron/main.c +++ b/tests/arch/arm/neon/neuron/main.c @@ -131,6 +131,6 @@ int main() { .expected_output = 0.000012f, }, }; - run_test_cases(test_cases, N_TEST_CASES, "nn_dot_product_neon", nn_dot_product_neon); + run_test_cases(test_cases, N_TEST_CASES, "nn_neuron", nn_dot_product_neon); return 0; } diff --git a/tests/arch/generic/neuron/main.c b/tests/arch/generic/neuron/main.c index 37ed998..8581966 100644 --- a/tests/arch/generic/neuron/main.c +++ b/tests/arch/generic/neuron/main.c @@ -130,6 +130,6 @@ int main() { .expected_output = 0.000012f, }, }; - run_test_cases(test_cases, N_TEST_CASES, "nn_dot_product", nn_dot_product); + run_test_cases(test_cases, N_TEST_CASES, "nn_neuron", nn_dot_product); return 0; }