Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring for NNTensor #26

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,22 @@ jobs:
- name: Test
run: |
if [ "${{ matrix.test }}" == "arm-neon" ]; then
TESTS=arch/arm/neon/dot_product_perf,arch/arm/neon/neuron,arch/arm/neon/neuron_perf
if [ "${{ matrix.tag }}" == "nntbn:armv7-neon" ]; then
TESTS="make test ARCH=arm FILTERS=neon LDFLAGS='-lm' CFLAGS='-mfpu=neon-vfpv4'"
else
TESTS="make test ARCH=arm FILTERS=neon LDFLAGS='-lm'"
fi
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
TESTS="make test ARCH=arm FILTERS=cmsis-dsp LDFLAGS='-lm'"
elif [ "${{ matrix.test }}" == "amd64-generic" ]; then
TESTS=arch/generic/dot_product,arch/generic/dot_product_perf,arch/generic/layer,arch/generic/layer_multi,arch/generic/neuron,arch/generic/neuron_perf
TESTS="make test ARCH=generic LDFLAGS='-lm'"
else
echo "unknown test"
exit 1
fi
IFS=',' read -ra TESTS <<< "$TESTS"
IFS='|' read -ra TESTS <<< "$TESTS"
for TEST in "${TESTS[@]}"; do
echo "running ${TEST}"
docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} "/nn/build/tests/${TEST}"
docker run --platform ${{ matrix.platform }} ${{ matrix.tag }} "${TEST}"
echo " "
done
92 changes: 30 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARCH := generic
endif
export ARCH

.PHONY: help run-arm-examples
.PHONY: help
all: help
help: Makefile
@echo
Expand All @@ -27,76 +27,44 @@ clean:
echo "build directory does not exist, skipping"; \
fi

## test Run tests (e.g., make test ARCH=generic)
## test Run tests (e.g., make test ARCH=generic OR make test ARCH=arm FILTERS=neon,cmsis-dsp)
test:
@$(MAKE) build-tests ARCH=$(ARCH) TECH=$(TECH)
@echo testing ARCH=$(ARCH) FILTERS=$(FILTERS) ARGS=$(ARGS)
@$(MAKE) build-artifacts PREFIX=tests/arch/$(ARCH) FILTERS=$(FILTERS)
@echo " "
@$(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; \
done
@$(MAKE) run-artifacts PREFIX=tests/arch/$(ARCH) FILTERS=$(FILTERS) ARGS="$(ARGS)"

## test-all Run tests (e.g., make test ARCH=generic)
## test-all Run tests (e.g., make test-all ARCH=generic)
test-all:
@$(MAKE) build-tests ARCH=generic
@$(MAKE) build-tests ARCH=arm TECH=neon
@$(MAKE) build-tests ARCH=arm TECH=cmsis-dsp
@echo " "
@$(MAKE) run-tests ARCH=generic
@$(MAKE) run-tests ARCH=arm TECH=neon
@$(MAKE) run-tests ARCH=arm TECH=cmsis-dsp

## 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

## 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) 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
@$(MAKE) build-artifacts PREFIX=tests/arch/generic
@$(MAKE) build-artifacts PREFIX=tests/arch/arm FILTERS=neon,cmsis-dsp
@echo " "
@$(MAKE) run-artifacts PREFIX=tests/arch/generic
@$(MAKE) run-artifacts PREFIX=tests/arch/arm FILTERS=neon,cmsis-dsp

## run-tests Run tests (e.g., make run-tests ARCH=generic)
run-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; \
done

## build-example Build an example (e.g., make build-example ARCH=generic EXAMPLE=arch/generic/layer)
build-example:
@echo building $(EXAMPLE)
@ARCH=$(ARCH) TECH=$(TECH) ARTIFACT=examples/$(EXAMPLE) scripts/shell/build_artifact.sh
## build-artifact Build an artifact (e.g., make build-artifact ARTIFACT=tests/arch/generic/layer)
build-artifact:
@echo building ARTIFACT=$(ARTIFACT)
@ARTIFACT=$(ARTIFACT) scripts/shell/build_artifact.sh

## build-examples Build examples (e.g., make build-examples ARCH=generic)
build-examples:
@$(eval TECH_FILTER := $(if $(TECH),$(shell echo $(TECH) | tr ',' '|'),.*))
@$(eval EXAMPLES := $(shell find examples/arch/$(ARCH) -type f -name 'main.c' | grep -E "$(TECH_FILTER)" | sed 's|/main.c||' | sed 's|examples/||'))
@for example in $(EXAMPLES); do \
$(MAKE) build-example ARCH=$(ARCH) TECH=$(TECH) EXAMPLE=$$example || exit 1; \
## build-artifacts Build artifacts (e.g., make build-artifacts PREFIX=tests/arch/generic)
build-artifacts:
@$(eval FILTERS_GREP := $(if $(FILTERS),$(shell echo $(FILTERS) | tr ',' '|'),.*))
@$(eval ARTIFACTS := $(shell find $(PREFIX) -type f -name 'main.c' | grep -E "$(FILTERS_GREP)" | sed 's|/main.c||' | sort))
@for artifact in $(ARTIFACTS); do \
$(MAKE) build-artifact ARTIFACT=$$artifact || exit 1; \
done

## run-example Run an examples (e.g., make run-example ARCH=generic EXAMPLE=arch/generic/layer)
run-example:
@echo running $(EXAMPLE) $(ARGS)
@ARCH=$(ARCH) ARTIFACT=examples/$(EXAMPLE) ARGS="$(ARGS)" scripts/shell/run_artifact.sh
## run-artifact Run an artifact (e.g., make run-artifact ARTIFACT=tests/arch/generic/layer)
run-artifact:
@echo running ARTIFACT=$(ARTIFACT) ARGS=$(ARGS)
@ARTIFACT=$(ARTIFACT) ARGS="$(ARGS)" scripts/shell/run_artifact.sh
@echo " "

## run-examples Run examples (e.g., make run-examples ARCH=generic)
run-examples:
@$(eval TECH_FILTER := $(if $(TECH),$(shell echo $(TECH) | tr ',' '|'),.*))
@$(eval EXAMPLES := $(shell find examples/arch/$(ARCH) -type f -name 'main.c' | grep -E "$(TECH_FILTER)" | sed 's|/main.c||' | sed 's|examples/||'))
@for example in $(EXAMPLES); do \
$(MAKE) run-example ARCH=$(ARCH) TECH=$(TECH) EXAMPLE=$$example || exit 1; \
## run-artifacts Run tests (e.g., make run-artifacts PREFIX=tests/arch/generic)
run-artifacts:
@$(eval FILTERS_GREP := $(if $(FILTERS),$(shell echo $(FILTERS) | tr ',' '|'),.*))
@$(eval ARTIFACTS := $(shell find $(PREFIX) -type f -name 'main.c' | grep -E "$(FILTERS_GREP)" | sed 's|/main.c||' | sort))
@for artifact in $(ARTIFACTS); do \
$(MAKE) run-artifact ARTIFACT=$$artifact ARGS="$(ARGS)" || exit 1; \
done
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ git submodule update --init

## Usage

### Build and run examples

```shell
make build-examples ARCH=generic
make run-examples ARCH=generic
```

## Test

```shell
# Test the default architecture (generic)
make test

# Test a specific architecture
make test ARCH=generic
make test ARCH=arm TECH=neon,cmsis-dsp
make test ARCH=arm

# Test a specific architecture with filters
make test ARCH=generic FILTERS=dot_prod
make test ARCH=arm FILTERS=neon,cmsis-dsp

# Test all architectures
make test-all
```

Expand Down
80 changes: 0 additions & 80 deletions examples/arch/generic/layer/main.c

This file was deleted.

18 changes: 18 additions & 0 deletions include/arch/arm/cmsis-dsp/nn_dot_prod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef NN_DOT_PROD_CMSIS_DSP_H
#define NN_DOT_PROD_CMSIS_DSP_H

#include "nn_error.h"
#include "nn_tensor.h"

/**
* @brief Returns the dot product of two 1-dimensional tensors.
*
* @param a The first tensor.
* @param b The second tensor.
* @param error The error instance to set if an error occurs.
*
* @return The result of the dot product or NAN if an error occurs.
*/
NNTensorUnit nn_dot_prod_cmsis_dsp(const NNTensor *a, const NNTensor *b, NNError *error);

#endif // NN_DOT_PROD_CMSIS_DSP_H
14 changes: 0 additions & 14 deletions include/arch/arm/cmsis-dsp/nn_dot_product.h

This file was deleted.

18 changes: 18 additions & 0 deletions include/arch/arm/neon/nn_dot_prod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef NN_DOT_PROD_NEON_H
#define NN_DOT_PROD_NEON_H

#include "nn_error.h"
#include "nn_tensor.h"

/**
* @brief Returns the dot product of two 1-dimensional tensors.
*
* @param a The first tensor.
* @param b The second tensor.
* @param error The error instance to set if an error occurs.
*
* @return The result of the dot product or NAN if an error occurs.
*/
NNTensorUnit nn_dot_prod_neon(const NNTensor *a, const NNTensor *b, NNError *error);

#endif // NN_DOT_PROD_NEON_H
14 changes: 0 additions & 14 deletions include/arch/arm/neon/nn_dot_product.h

This file was deleted.

Loading
Loading