Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The sample code encompasses operations associated with the NN model, along with preprocessing and postprocessing related to the NN model. We need to cross-compile this code into an application that can execute on C3V Linux. Additionally, we should utilize it along with the generated NB file.

Table of Contents

1. Building

1.1. Linux Terminal Cross Compile

When compiling NN-related applications, it is necessary to include SDK's headers and libraries.

...

This is an example makefile that just needs to be placed in wksp/ {model_name}_{type}_nbg_unify Folder. And set the relevant VIVIANTE_ SDK_ DIR and TOOLCHAIN can complete the compilation of the app:

Code Block
BIN=sampleApp
#V1.0.1

BIN=yolov8s-sample

# 1.cross compile
# NN_SDK_DIR=Path to NN SDK directory
# TOOLCHAIN=Path to toolchain directory

NN_SDK_INC=$(NN_SDK_DIR)/include
NN_SDK_LIB=$(NN_SDK_DIR)/lib

# CROSS_COMPILE=$(TOOLCHAIN)/aarch64-none-linux-gnu-
# CC=$(CROSS_COMPILE)gcc
# CXX=$(CROSS_COMPILE)g++

# 2.build in c3v
# NN_SDK_DIR=/usr

# CC=gcc
# CXX=g++

NN_SDK_INC=$(NN_SDK_DIR)/include
NN_SDK_LIB=$(NN_SDK_DIR)/lib

CFLAGS=-Wall -O3

INCLUDE += -I$(NN_SDK_INC) -I$(NN_SDK_INC)/HAL -I$(NN_SDK_INC)/ovxlib -I$(NN_SDK_INC)/jpeg
LIBS += -L$(NN_SDK_LIB) -L./ -L$(STD_LOG_INC)
LIBS += -lOpenVX -lOpenVXU -lOpenVX -lCLC -lVSC -lGAL -ljpeg -lovxlib -lm
LIBS += -lNNArchPerf -lArchModelSw
LIBS += -lstdc++ -ldl -lpthread -lgcc_s

CFLAGS += $(INCLUDE) -fPIC 
CFLAGS += -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable

SRCS=${wildcard *.c}
SRCS+=${wildcard *.cpp}

OBJS=$(addsuffix .o, $(basename $(SRCS)))

.SUFFIXES: .hpp .cpp .c 

.cpp.o:
	$(CXX) $(CFLAGS) -std=c++11 -c $<

.c.o:
	$(CC) $(CFLAGS) -c $<

all: $(BIN)

$(BIN): $(OBJS)
	$(CC) $(CFLAGS) $(LFLAGS) $(OBJS) -o $@ $(LIBS) 
	rm -rf *.o

clean:
	rm -rf *.o
	rm -rf $(BIN) $(LIB)
	rm -rf *~

1.2. NN IDE Cross Compile

Environment Preparations

  • C3V toolchain

toolchain\crossgcc\gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu

  • C3V OVXLIB files

...

Import Project

select File->import:

...

select "General->Existing Projects into Workspace":

...

select the checkbox of the project and the checkbox of "copy project into workspace". Then press "Finish" to import the project.

...

Setting

This step sets the cross-compiler as the C3V toolchain and the library search path as the C3V OVXLIB folder. In the IDE main window, select "Project->Properties". Select "Tool Chain Editor" in the pop-up window. In "Current toolchain", select "Cross Gcc with openVX":

...

Choose "Settings" and select "Cross Settings", please configure the Prefix and Path of the C3V toolchain. configure the C3V OVXLIB search path. Then press "OK".

...

Build

Right-click on the model project in the Project Explorer pane, and select Build Project. The build results will appear in the Console pane.

...

After building success, the binary file is in the folder "Project/Debug/"

2. Running on the C3V Linux

Copy the application into C3V Linux and running:

...