Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/test-neureka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ jobs:
export PULP_RISCV_GCC_TOOLCHAIN=$GITHUB_WORKSPACE/toolchain/gnu
source pulp-sdk/configs/siracusa.sh
cd pulp-nnx/test
pytest test.py -T tests -R -A neureka --build-flow=make --wmem=tcdm
pytest test.py -T tests -R -A neureka --build-flow=make --wmem=sram
pytest test.py --test-dir tests --recursive --accelerator neureka --build-flow=make --wmem=tcdm
pytest test.py --test-dir tests --recursive --accelerator neureka --build-flow=make --wmem=sram
3 changes: 2 additions & 1 deletion .github/workflows/test-neureka_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ jobs:
export TOOLCHAIN_GNU_INSTALL_DIR=$GITHUB_WORKSPACE/toolchain/gnu
export GVSOC=$GITHUB_WORKSPACE/gvsoc/install/bin/gvsoc
cd pulp-nnx/test
pytest test.py -T tests -R -A neureka_v2 --build-flow=cmake --wmem=mram
pytest test.py --test-dir=tests --recursive --accelerator=neureka_v2 --build-flow=cmake --wmem=mram --app=pulp-nnx
pytest test.py --test-dir=tests --recursive --accelerator=neureka_v2 --build-flow=cmake --wmem=mram --app=pulp-nnx-hal
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ run_ne16_test:
artifacts:
untracked: true
script:
- cd test && pytest test.py --test-dir tests --recursive -A ne16
- cd test && pytest test.py --test-dir tests --recursive --accelerator ne16
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ project(pulp-nnx

add_library(pulp-nnx STATIC)

target_sources(pulp-nnx PRIVATE util/pulp_nnx_util.c util/hwpe.c)
target_include_directories(pulp-nnx PUBLIC inc util)
target_include_directories(pulp-nnx PUBLIC inc)

option(USE_NE16 "Use the NE16 accelerator.")
option(USE_NEUREKA "Use the N-EUREKA accelerator.")
Expand All @@ -20,6 +19,8 @@ endif()

if (${USE_NE16})
message(STATUS "[PULP-NNX] Using the NE16 accelerator.")
add_subdirectory(ne16/hal)
target_link_libraries(pulp-nnx PUBLIC pulp-nnx-hal-ne16)
target_sources(pulp-nnx
PRIVATE
ne16/bsp/ne16_pulp_bsp.c
Expand All @@ -37,34 +38,32 @@ endif()

if (${USE_NEUREKA})
message(STATUS "[PULP-NNX] Using the N-EUREKA accelerator.")
add_subdirectory(neureka/hal)
target_link_libraries(pulp-nnx PUBLIC pulp-nnx-hal-neureka)
target_sources(pulp-nnx
PRIVATE
neureka/bsp/neureka_siracusa_bsp.c
neureka/hal/neureka.c
neureka/hal/neureka_task.c
src/pulp_nnx_neureka.c
)
target_include_directories(pulp-nnx
PUBLIC
neureka/bsp
neureka/hal
neureka/gvsoc
)
endif()

if (${USE_NEUREKA_V2})
message(STATUS "[PULP-NNX] Using the N-EUREKA v2 accelerator.")
add_subdirectory(neureka_v2/hal)
target_link_libraries(pulp-nnx PUBLIC pulp-nnx-hal-neureka-v2)
target_sources(pulp-nnx
PRIVATE
neureka_v2/bsp/neureka_v2_siracusa_bsp.c
neureka_v2/hal/neureka_v2.c
neureka_v2/hal/neureka_v2_task.c
src/pulp_nnx_neureka_v2.c
)
target_include_directories(pulp-nnx
PUBLIC
neureka_v2/bsp
neureka_v2/hal
neureka_v2/gvsoc
)
endif()
14 changes: 14 additions & 0 deletions ne16/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.18)

project(pulp-nnx-hal-ne16 LANGUAGES C)

add_library(pulp-nnx-hal-ne16
STATIC
ne16.c
ne16_task.c
)

target_include_directories(pulp-nnx-hal-ne16 PUBLIC .)

add_subdirectory(../../util pulp-nnx-util)
target_link_libraries(pulp-nnx-hal-ne16 PUBLIC pulp-nnx-util)
14 changes: 14 additions & 0 deletions neureka/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.18)

project(pulp-nnx-hal-neureka LANGUAGES C)

add_library(pulp-nnx-hal-neureka
STATIC
neureka.c
neureka_task.c
)

target_include_directories(pulp-nnx-hal-neureka PUBLIC .)

add_subdirectory(../../util pulp-nnx-util)
target_link_libraries(pulp-nnx-hal-neureka PUBLIC pulp-nnx-util)
14 changes: 14 additions & 0 deletions neureka_v2/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.18)

project(pulp-nnx-hal-neureka-v2 LANGUAGES C)

add_library(pulp-nnx-hal-neureka-v2
STATIC
neureka_v2.c
neureka_v2_task.c
)

target_include_directories(pulp-nnx-hal-neureka-v2 PUBLIC .)

add_subdirectory(../../util pulp-nnx-util)
target_link_libraries(pulp-nnx-hal-neureka-v2 PUBLIC pulp-nnx-util)
4 changes: 2 additions & 2 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BUILD
build
app/build*
apps/**/build*
apps/**/gen
__pycache__
.cache
.pytest_cache
app/gen
**/compile_commands.json
**/*.log
**/*.pt
59 changes: 45 additions & 14 deletions test/NnxBuildFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,34 @@
from NnxMapping import NnxName


class AppName(Enum):
pulp_nnx = "pulp-nnx"
pulp_nnx_hal = "pulp-nnx-hal"

def __str__(self):
return self.value

def path(self):
return f"apps/{self}"


class Toolchain(Enum):
gnu = "gnu"
llvm = "llvm"

def __str__(self):
return self.value


class NnxBuildFlow(ABC):

@abstractmethod
def __init__(self, nnxName: NnxName) -> None: ...
def __init__(
self, nnxName: NnxName, appName: AppName, toolchain: Toolchain
) -> None:
self.nnxName = nnxName
self.appName = appName
self.toolchain = toolchain

@abstractmethod
def build(self) -> None: ...
Expand All @@ -31,43 +55,50 @@ def cmd_run(cmd: str, env=None) -> str:


class MakeBuildFlow(NnxBuildFlow):
BUILD_CMD = "make -C app all platform=gvsoc"
RUN_CMD = "make -C app run platform=gvsoc"

def __init__(self, nnxName: NnxName) -> None:
self.nnxName = nnxName
def __init__(
self, nnxName: NnxName, appName: AppName, toolchain: Toolchain
) -> None:
super().__init__(nnxName, appName, toolchain)

def env(self) -> os._Environ:
_env = os.environ
_env["ACCELERATOR"] = str(self.nnxName)
return _env

def build(self) -> None:
Path("app/src/nnx_layer.c").touch()
_ = NnxBuildFlow.cmd_run(MakeBuildFlow.BUILD_CMD, self.env())
Path(f"{self.appName.path()}/src/nnx_layer.c").touch()
_ = NnxBuildFlow.cmd_run(
f"make -C {self.appName.path()} all platform=gvsoc", self.env()
)

def run(self) -> str:
return NnxBuildFlow.cmd_run(MakeBuildFlow.RUN_CMD, self.env())
return NnxBuildFlow.cmd_run(
f"make -C {self.appName.path()} run platform=gvsoc", self.env()
)

def __str__(self) -> str:
return "make"


class CmakeBuildFlow(NnxBuildFlow):
BINARY_NAME = "test-pulp-nnx"
TOOLCHAIN_FILE = "cmake/toolchain_gnu.cmake"
GVSOC_TARGET = "siracusa"

def __init__(self, nnxName: NnxName) -> None:
self.nnxName = nnxName
self.build_dir = os.path.abspath(f"app/build_{nnxName}")
def __init__(
self, nnxName: NnxName, appName: AppName, toolchain: Toolchain
) -> None:
super().__init__(nnxName, appName, toolchain)
self.build_dir = os.path.abspath(
f"{self.appName.path()}/build_{nnxName}_{toolchain}"
)
self.gvsoc_workdir = os.path.join(self.build_dir, "gvsoc_workdir")
assert "GVSOC" in os.environ, "The GVSOC environment variable is not set."
self.toolchain_file = f"../../cmake/toolchain_{self.toolchain}.cmake"

def prepare(self) -> None:
os.makedirs(self.gvsoc_workdir, exist_ok=True)
subprocess.run(
f"cmake -Sapp -B{self.build_dir} -GNinja -DCMAKE_TOOLCHAIN_FILE={CmakeBuildFlow.TOOLCHAIN_FILE} -DACCELERATOR={self.nnxName}".split(),
f"cmake -S{self.appName.path()} -B{self.build_dir} -GNinja -DCMAKE_TOOLCHAIN_FILE={self.toolchain_file} -DACCELERATOR={self.nnxName}".split(),
check=True,
)

Expand Down
6 changes: 1 addition & 5 deletions test/NnxTestClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,11 @@ def source_generate(


class NnxTestHeaderGenerator:
DEFAULT_HEADERS_DIR = "app/gen"

def __init__(
self,
nnxWeight: NnxWeight,
headers_dir: Optional[Union[str, os.PathLike]] = None,
headers_dir: Union[str, os.PathLike],
):
if headers_dir is None:
headers_dir = NnxTestHeaderGenerator.DEFAULT_HEADERS_DIR
self.header_writer = HeaderWriter(headers_dir)
# function that takes the weights in CoutCinK format, bitwidth, and a depthwise flag,
# and returns a numpy array of dtype=np.uint8 of data in a layout correct for the accelerator
Expand Down
7 changes: 4 additions & 3 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Repository structure

- app: test application
- app_*: test application
- inc: test application headers
- src: test application sources
- gen_inc: generated test headers for data and test information
Expand Down Expand Up @@ -36,6 +36,7 @@ $ pytest test.py --help

For more information you can run the script with the `-h` flag.

## Application
## Applications

For information on the testing application and how to build it, take a look in its [README.md](app/README.md).
There are 2 applications provided, one testing the more abstract pulp_nnx interface and another one just the hardware abstraction layer, called `app_pulp_nnx` and `app_pulp_nnx_hal`.
For information on the testing applications and how to build them, take a look in their dedicated readmes: [app_pulp_nnx/README.md](app_pulp_nnx/README.md) and [app_pulp_nnx_hal/README.md](app_pulp_nnx_hal/README.md).
62 changes: 0 additions & 62 deletions test/app/cmake/pulp-sdk-siracusa.cmake

This file was deleted.

19 changes: 14 additions & 5 deletions test/app/README.md → test/apps/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# Test application
# Test applications

There are 2 testing applications:
1. pulp-nnx - tests the whole library
2. pulp-nnx-hal - tests just the hardware abstraction layer parts

Both apps are very similar except for the fact that the Make build flow is not implemented for the pulp-nnx-hal app.

## Build

There are two build flows given for the test app, the Make one and the CMake one.
Both flows use a flag `ACCELERATOR` to decide which accelerator to build the application for.
Choices are _neureka_ and _neureka_v2_.

### Environment variables

Both build fows expect some environment variables to be set and will fail if they are not set:
- `GVSOC` - path to the `gvsoc` executable (not the directory)
- `TOOLCHAIN_LLVM_INSTALL_DIR` - path to the llvm install directory
- `PULP_SDK_HOME` - path to the pulp-sdk directory

### Make

For the Make flow you need to specify the `ACCELERATOR` flag either as an environment variable
Expand All @@ -30,7 +43,3 @@ cmake --build build
```

No need to regenerate the project (1st cmake command) after altering the sources, just rerun the build.

## TODO

- environment variables that need to be set
Loading