Skip to content
Open
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__/
[Bb]uild/
*.py[cod]
_build
.pytest_cache
.vscode
CMakeLists.txt.user
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright © 2019 Synaptics Incorporated.

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
cmake_minimum_required(VERSION 3.19)
project(SyNAP_RUNTIME)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT CMAKE_CROSSCOMPILING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -Wl,--no-undefined -Wl,--no-allow-shlib-undefined")
endif()
# Release build: Strip shared libraries
add_link_options($<$<CONFIG:RELEASE>:-s>)
if(ENABLE_CPU_PROFILING)
add_compile_options(-pg)
endif()
message("CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

option(ENABLE_EBGRUNTIME "Enable EBGRUNTIME compilation and associated SyNAP support" ON)
option(ENABLE_ONNXRUNTIME "Enable ONNXRUNTIME compilation and associated SyNAP support" OFF)
option(ENABLE_TFLITERUNTIME "Enable TFLITE runtime compilation and associated SyNAP support" OFF)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
message("Old GCC version detected, disabling C++-17 standard filesystem library")
set(ENABLE_CXX_STD_FILESYSTEM OFF)
else()
set(ENABLE_CXX_STD_FILESYSTEM ON)
endif()

if(CMAKE_BUILD_TYPE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# Enable file-based bundle models
set(ENABLE_FILE_BASED_BUNDLE ON)
add_compile_definitions(SYNAP_FILE_BASED_BUNDLE=1)
endif()

# add common dmabuf allocator options here for lib/app
option(ENABLE_DMA_HEAP_ALLOCATOR "Enable synap DMA-BUF heap allocator" ${VSSDK_KERNEL_DMABUF_ENABLED})
message("ENABLE_DMA_HEAP_ALLOCATOR: ${ENABLE_DMA_HEAP_ALLOCATOR}")

message("ENABLE_EBGRUNTIME: ${ENABLE_EBGRUNTIME}")
message("ENABLE_ONNXRUNTIME: ${ENABLE_ONNXRUNTIME}")
message("ENABLE_TFLITERUNTIME: ${ENABLE_TFLITERUNTIME}")

if(ENABLE_ONNXRUNTIME)
find_package(Onnxruntime REQUIRED)
endif()

message("ENABLE_NCNN: ${ENABLE_NCNN}")
if(ENABLE_NCNN)
find_package(NCNN REQUIRED)
endif()

message("ENABLE_TFLITERUNTIME: ${ENABLE_TFLITERUNTIME}")
if(ENABLE_TFLITERUNTIME)
find_package(tensorflow_lite REQUIRED)
endif()

add_subdirectory(lib)

add_subdirectory(app)
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
# runtime
# SyNAP Runtime
SyNAP runtime libraries and utilities

## Build SyNAP Framework
### Setup Astra Cross-compilation Toolchain
#### **Step 1: Download toolchain**
Clone the Astra cross-compilation toolchain for your board from the [SDK releases]():
```bash
wget https://github.com/synaptics-astra/sdk/releases/download/v1.5.0/sl1680-poky-glibc-x86_64-astra-media-cortexa73-sl1680-toolchain-4.0.17.sh
```

#### **Step 2: Install toolchain**
Run the toolchain setup script
```bash
chmod 755 poky-glibc-x86_64-astra-media-cortexa73-sl1680-toolchain-4.0.17.sh
./poky-glibc-x86_64-astra-media-cortexa73-sl1680-toolchain-4.0.17.sh
```

#### **(Optional) Step 3: Alias toolchain activation**
For convenience, set up an alias to activate the toolchain environment
```bash
alias toolchain='source /opt/poky/4.0.17/environment-setup-cortexa73-poky-linux'
```

> [!TIP]
> To check if the cross-compilation environment is active, use the following command in your Ubuntu terminal:
> ```
> echo $CC
> ```
> You should see an output similar to:
> ```
> aarch64-poky-linux-gcc -mcpu=cortex-a73 -march=armv8-a+crc -mbranch-protection=standard -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/4.0.17/sysroots/cortexa73-poky-linux

### Build Process
#### **Step 1: Clone the repository**
```bash
git clone https://github.com/synaptics-synap/runtime.git
cd runtime
```

#### **Step 2: Create a build directory**
```bash
mkdir -p build
cd build
```

#### **Step 3: Configure and build**
Using `Ninja`:
```bash
cmake .. -G Ninja
ninja
```

Using `Unix Makefiles`:
```bash
cmake .. -G "Unix Makefiles"
make
```

### Build Outputs
#### **1. SyNAP runtime library (libsynap.so)**

This shared library object is generated at `build/lib/synapnb/libsynapnb.so`.
<br>To apply updates to the runtime, replace the existing system library on your board at `/usr/lib/libsynapnb.so` with the new one. This ensures that any applications using the SyNAP runtime will link to the updated version.

#### **2. Application binaries**

Each compiled application binary will be placed in its respective folder at `build/app/<app name>/`.
<br>To deploy an application, copy the generated binary to the system binary directory `/usr/bin/` on your board.

> [!WARNING]
> It is highly recommended to make backups before replacing library files and/or binaries in `/usr/lib/` and `/usr/bin/`
34 changes: 34 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if(ENABLE_EBGRUNTIME)
# add_subdirectory(synap_cli_nb)
endif()

if(CMAKE_CROSSCOMPILING OR ENABLE_SYNAP_DEVICE_SIMULATOR)
#add_subdirectory(synap_cli_info)

# FIXME: pybind11 build failed
# add_subdirectory(synap_api_py)

if(ENABLE_TFLITERUNTIME)
add_subdirectory(synap_cli_tflitec)
endif()

add_subdirectory(synap_cli)
add_subdirectory(synap_cli_ic)
if(ENABLE_EBGRUNTIME)
# FIXME: relies on Buffer ctor specific to synap_device
add_subdirectory(synap_cli_ic2)
endif()
add_subdirectory(synap_cli_od)
add_subdirectory(synap_cli_od2)
add_subdirectory(synap_cli_ip)
if(ENABLE_EBGRUNTIME)
add_subdirectory(synap_init)
endif()

# FIXME: why disabling that ?
if(ENABLE_ADVANCED)
add_subdirectory(synap_cli_sr)
add_subdirectory(synap_cli_rnn)
endif()

endif()
37 changes: 37 additions & 0 deletions app/benchmark_model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright © 2019-2025 Synaptics Incorporated.

# ////////////////////////////////////////////////////////////////////////////////
# //! \file CMakeLists.txt
# //!
# //! \brief
# //!
# //! Version Date Author
# //! V 0.01, Feb 3 2020 alek
# //!
# //! Note:
# ////////////////////////////////////////////////////////////////////////////////
#
cmake_minimum_required(VERSION 3.5)

include(ExternalProject)

set(projectname "benchmark_model")

PROJECT(${projectname})

ExternalProject_Add(${projectname}
GIT_REPOSITORY https://github.com/VeriSilicon/tensorflow.git
GIT_TAG nnapi-delegate-2.0
GIT_SHALLOW ON
SOURCE_DIR ""
BUILD_ALWAYS OFF
CONFIGURE_COMMAND <SOURCE_DIR>/tensorflow/lite/tools/make/download_dependencies.sh
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/as371_makefile.inc <SOURCE_DIR>/tensorflow/lite/tools/make/targets
BUILD_COMMAND $(MAKE) TARGET_TOOLCHAIN_ROOT=/opt/bin/toolchain/$ENV{TOOLCHAIN_NAME} TARGET_TOOLCHAIN_PREFIX=${TOOLCHAIN_PREFIX} TARGET=${TARGET_OS} BUILD_WITH_NNAPI=true -C <SOURCE_DIR> -f tensorflow/lite/tools/make/Makefile
INSTALL_COMMAND mkdir -p /opt/target/bin
COMMAND cp <SOURCE_DIR>/tensorflow/lite/tools/make/gen/as371_armv7-a/bin/benchmark_model /opt/target/bin
TEST_COMMAND ""
)

install(CODE "MESSAGE(\"benchmark_model installed.\")")
109 changes: 109 additions & 0 deletions app/benchmark_model/as371_makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#
# NDA AND NEED-TO-KNOW REQUIRED
#
# Copyright (C) 2013-2020 Synaptics Incorporated. All rights reserved.
#
# This file contains information that is proprietary to Synaptics
# Incorporated ("Synaptics"). The holder of this file shall treat all
# information contained herein as confidential, shall use the
# information only for its intended purpose, and shall not duplicate,
# disclose, or disseminate any of this information in any manner
# unless Synaptics has otherwise provided express, written
# permission.
#
# Use of the materials may require a license of intellectual property
# from a third party or from Synaptics. This file conveys no express
# or implied licenses to any intellectual property rights belonging
# to Synaptics.
#
# INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS", AND
# SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES,
# INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY
# INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR
# CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE
# OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND
# BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF
# COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT
# DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY
# TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS.
#
# Settings for generic aarch64 boards such as Odroid C2 or Pine64.
ifeq ($(TARGET),as371)
# The aarch64 architecture covers all 64-bit ARM chips. This arch mandates
# NEON, so FPU flags are not needed below.
TARGET_ARCH := armv7-a
CC_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/

CXXFLAGS += \
-march=armv7-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC

CFLAGS += \
-march=armv7-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC

LDFLAGS := \
-Wl,--no-export-dynamic \
-Wl,--exclude-libs,ALL \
-Wl,--gc-sections \
-Wl,--as-needed \
-lrt


LIBS := \
-lstdc++ \
-lpthread \
-lm \
-ldl

else ifeq ($(TARGET),android_vssdk)
# The aarch64 architecture covers all 64-bit ARM chips. This arch mandates
# NEON, so FPU flags are not needed below.
TARGET_ARCH := armv7-a
CC_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/

CXXFLAGS += \
-march=armv7-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC \
-fPIE \
-pie \
--sysroot=$(SYNAP_ROOT)/sysroot/$(TARGET) \
-std=c++11 \
-fpermissive

CFLAGS += \
-march=armv7-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC \
-fPIE \
-pie \
--sysroot=$(SYNAP_ROOT)/sysroot/$(TARGET) \
-std=c11 \
-fpermissive

LDFLAGS := \
-Wl,--no-export-dynamic \
-Wl,--exclude-libs,ALL \
-Wl,--gc-sections \
-Wl,--as-needed

LIBS := \
-lc++_static \
-lm

INCLUDES += \
-I$(SYNAP_ROOT)/sysroot/$(TARGET)/include/libcxx \
-I$(SYNAP_ROOT)/sysroot/$(TARGET)/include/libcxxabi

endif
15 changes: 15 additions & 0 deletions app/opencv_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright © 2019-2025 Synaptics Incorporated.


set(name "opencv_test")

file(GLOB SRC *.cpp)
add_executable(${name} ${SRC})

target_link_libraries(${name} opencv_imgcodecs)
if(ANDROID)
target_link_libraries(${name} log)
endif()
message("install ${name}")
install(TARGETS ${name})
19 changes: 19 additions & 0 deletions app/opencv_test/magnitude_filter_8u.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
__kernel void magnutude_filter_8u(
__global const uchar* src, int src_step, int src_offset,
__global uchar* dst, int dst_step, int dst_offset, int dst_rows, int dst_cols,
float scale)
{
int x = get_global_id(0);
int y = get_global_id(1);
if (x < dst_cols && y < dst_rows) {
int dst_idx = y * dst_step + x + dst_offset;
if (x > 0 && x < dst_cols - 1 && y > 0 && y < dst_rows - 2) {
int src_idx = y * src_step + x + src_offset;
int dx = (int)src[src_idx]*2 - src[src_idx - 1] - src[src_idx + 1];
int dy = (int)src[src_idx]*2 - src[src_idx - 1*src_step] - src[src_idx + 1*src_step];
dst[dst_idx] = convert_uchar_sat(sqrt((float)(dx*dx + dy*dy)) * scale);
} else {
dst[dst_idx] = 0;
}
}
}
Loading