Skip to content

Commit

Permalink
[function update]
Browse files Browse the repository at this point in the history
1. support rk3399pro
2. rknn_converter can generate report after testing.
  • Loading branch information
zen committed Dec 19, 2022
1 parent 1f53f85 commit a63ce65
Show file tree
Hide file tree
Showing 134 changed files with 14,066 additions and 190 deletions.
14 changes: 9 additions & 5 deletions capi_tools/scaling_frequency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ print_not_support_adjust()
{
echo "Firmware seems not support seting $1 frequency"
echo " wanted "$2
echo " query "$3
echo " check "$3
}


Expand Down Expand Up @@ -150,6 +150,7 @@ case $seting_strategy in
cur_freq=$(cat /sys/class/devfreq/ffbc0000.npu/cur_freq)
print_and_compare_result $NPU_freq $cur_freq

echo "DDR: seting frequency"
print_not_support_adjust DDR $DDR_freq
cat /sys/kernel/debug/clk/clk_summary | grep dpll
;;
Expand Down Expand Up @@ -202,8 +203,8 @@ case $seting_strategy in
print_and_compare_result $CPU_freq $cur_freq


echo "NPU: seting frequency"
if [ -e /sys/class/devfreq/fdab0000.npu/governor ];then
echo "NPU: seting frequency"
echo userspace > /sys/class/devfreq/fdab0000.npu/governor
echo $NPU_freq > /sys/class/devfreq/fdab0000.npu/userspace/set_freq
cur_freq=$(cat /sys/class/devfreq/fdab0000.npu/cur_freq)
Expand All @@ -213,8 +214,8 @@ case $seting_strategy in
print_not_support_adjust NPU $NPU_freq $cur_freq
fi

echo "DDR: seting frequency"
if [ -e /sys/class/devfreq/dmc/governor ];then
echo "DDR: seting frequency"
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
Expand All @@ -226,16 +227,19 @@ case $seting_strategy in

;;

# rv1106, rv1103
5)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $cur_freq

echo "no strategy to seting NPU frequency"
echo "NPU: seting frequency"
echo " no strategy to seting NPU frequency"

echo "no strategy to seting DDR frequency"
echo "DDR: seting frequency"
echo " no strategy to seting DDR frequency"
;;
*)
echo "seting strategy not implement now"
Expand Down
40 changes: 23 additions & 17 deletions capi_tools/toolkit1/rknn_capi_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ cmake_minimum_required(VERSION 3.4.1)

project(rknn_capi_test_linux)

set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lpthread")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# for linux
if (CMAKE_C_COMPILER MATCHES "aarch64")
set(PLATFORM RK1808)
set(LIB_ARCH lib64)
add_definitions(-DRK1808=1)
else()
set(PLATFORM RV1109_1126)
set(LIB_ARCH lib)
add_definitions(-DRK1808=0)
endif()

# for android
if (${TARGET_SOC} STREQUAL "RK3399PRO")
set(LIB_ARCH lib64)
add_definitions(-DRK1808=1)
endif()


# stb
set(STB_DIR ${MZ_ROOT}/libs/common/)
Expand All @@ -28,24 +30,25 @@ set(CNPY_DIR ${MZ_ROOT}/libs/common/cnpy)
include_directories(${CNPY_DIR})

# zlib(used by libpng)
set(ZLIB_DIR ${MZ_ROOT}/libs/platform/${PLATFORM}/zlib)
set(ZLIB_DIR ${MZ_ROOT}/libs/platform/${TARGET_SOC}/zlib)
include_directories(${ZLIB_DIR}/include)
set(ZLIB_LIB ${ZLIB_DIR}/lib/libz.a)
set(ZLIB_LIB ${ZLIB_DIR}/lib/${CMAKE_SYSTEM_NAME}/libz.a)

# drm
set(DRM_DIR ${MZ_ROOT}/libs/common/drm)
include_directories(${DRM_DIR}/include)
include_directories(${DRM_DIR}/include/libdrm)

# rknn api
set(RKNN_API_PATH ${MZ_ROOT}/libs/rklibs/rknpu/rknn/rknn_api/librknn_api)
include_directories(${RKNN_API_PATH}/include)
set(RKNN_API_LIB ${RKNN_API_PATH}/${LIB_ARCH}/librknn_api.so)

# for 3399pro
# set(RKNN_API_PATH ${MZ_ROOT}/libs/rklibs/RK3399Pro_npu/rknn-api/librknn_api)
# include_directories(${RKNN_API_PATH}/include)
# set(RKNN_API_LIB ${RKNN_API_PATH}/Linux/${LIB_ARCH}/librknn_api.so)
if (${TARGET_SOC} STREQUAL "RK3399PRO")
set(RKNN_API_PATH ${MZ_ROOT}/libs/rklibs/RK3399Pro_npu/rknn-api/librknn_api)
include_directories(${RKNN_API_PATH}/include)
set(RKNN_API_LIB ${RKNN_API_PATH}/${CMAKE_SYSTEM_NAME}/${LIB_ARCH}/librknn_api.so)
else()
set(RKNN_API_PATH ${MZ_ROOT}/libs/rklibs/rknpu/rknn/rknn_api/librknn_api)
include_directories(${RKNN_API_PATH}/include)
set(RKNN_API_LIB ${RKNN_API_PATH}/${LIB_ARCH}/librknn_api.so)
endif()

# others
include_directories(${CMAKE_SOURCE_DIR}/include)
Expand Down Expand Up @@ -90,7 +93,10 @@ endif()


# install target and libraries
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/${PLATFORM}/rknn_capi_test)

set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/${TARGET_SOC}/${CMAKE_SYSTEM_NAME}/rknn_capi_test)


if (${ZERO_COPY})
install(TARGETS rknn_capi_test_zero_copy DESTINATION ./)
else()
Expand Down
44 changes: 44 additions & 0 deletions capi_tools/toolkit1/rknn_capi_test/build_rk1808.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -e

RK1808_TOOL_CHAIN="/home/xz/Documents/git_rk/compile_tools/1808/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu"

# for rk1808 aarch64
GCC_COMPILER=${RK1808_TOOL_CHAIN}/bin/aarch64-linux-gnu

ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )

# model_zoo_path root path
MZ_ROOT=$(pwd | sed 's/\(rknn_model_zoo\).*/\1/g')

# build rockx
BUILD_DIR=${ROOT_PWD}/build

if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi

cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RK1808 \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=1
make -j4
make install
cd ..

cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RK1808 \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=0
make -j4
make install

33 changes: 33 additions & 0 deletions capi_tools/toolkit1/rknn_capi_test/build_rk3399pro_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e

# same as rk1808
ANDROID_NDK_PATH="/home/xz/Documents/git_rk/compile_tools/3568/android/android-ndk-r17"

ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )

# model_zoo_path root path
MZ_ROOT=$(pwd | sed 's/\(rknn_model_zoo\).*/\1/g')

# build rockx
BUILD_DIR=${ROOT_PWD}/build

if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi


cd ${BUILD_DIR}
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_PATH/build/cmake/android.toolchain.cmake \
-DMZ_ROOT=${MZ_ROOT} \
-DCMAKE_SYSTEM_NAME=Android \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_PLATFORM=android-23 \
-DANDROID_STL=c++_static \
-DTARGET_SOC=RK3399PRO \
-DZERO_COPY=0
make -j4
make install

33 changes: 33 additions & 0 deletions capi_tools/toolkit1/rknn_capi_test/build_rk3399pro_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e

# same as rk1808
RK3399PRO_TOOL_CHAIN=/home/xz/Documents/git_rk/compile_tools/1808/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu

GCC_COMPILER=${RK3399PRO_TOOL_CHAIN}/bin/aarch64-linux-gnu

ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )

# model_zoo_path root path
MZ_ROOT=$(pwd | sed 's/\(rknn_model_zoo\).*/\1/g')

# build rockx
BUILD_DIR=${ROOT_PWD}/build

if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi


cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RK3399PRO \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=0 \
make -j4
make install

45 changes: 45 additions & 0 deletions capi_tools/toolkit1/rknn_capi_test/build_rv1109_1126.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

RV1109_TOOL_CHAIN="/home/xz/Documents/git_rk/compile_tools/1109/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf"


# for rv1109/rv1126 armhf
GCC_COMPILER=${RV1109_TOOL_CHAIN}/bin/arm-linux-gnueabihf

ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )

# model_zoo_path root path
MZ_ROOT=$(pwd | sed 's/\(rknn_model_zoo\).*/\1/g')

# build rockx
BUILD_DIR=${ROOT_PWD}/build

if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi

cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RV1109_1126 \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=1
make -j4
make install
cd ..

cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++ \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RV1109_1126 \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=0
make -j4
make install

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 27 additions & 7 deletions capi_tools/toolkit1/rknn_capi_test/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,20 @@ int main(int argc, char **argv)
int model_len = 0;
unsigned char *model;


struct timeval start_time, stop_time;
float set_time, run_time_simple, run_time_full, get_time, cvt_type_time, init_time = 0;
float input_io_init_time, output_io_init_time = 0;
long oldTime, newTime;


// Load RKNN Model
model = load_model(model_path, &model_len);
gettimeofday(&start_time, NULL);
ret = rknn_init(&ctx, model, model_len, 0);
gettimeofday(&stop_time, NULL);
init_time += (__get_us(stop_time) - __get_us(start_time)) / 1000;

if (ret < 0)
{
printf("rknn_init fail! ret=%d\n", ret);
Expand Down Expand Up @@ -432,11 +443,14 @@ int main(int argc, char **argv)
&(inputs_mem[i]->fd),
(unsigned int*)&(inputs_mem[i]->handle),
(size_t*)&(inputs_mem[i]->size));
gettimeofday(&start_time, NULL);
rknn_set_io_mem(ctx, inputs_mem[i], &input_attrs[i]);
gettimeofday(&stop_time, NULL);
}
input_io_init_time += (__get_us(stop_time) - __get_us(start_time)) / 1000;

rknn_tensor_mem* outputs_mem[io_num.n_output];
for (int i = 0; i < io_num.n_input; i++){
for (int i = 0; i < io_num.n_output; i++){
outputs_mem[i] = (rknn_tensor_mem*)malloc(sizeof(rknn_tensor_mem));
}

Expand All @@ -451,8 +465,12 @@ int main(int argc, char **argv)
&(outputs_mem[i]->fd),
(unsigned int*)&(outputs_mem[i]->handle),
(size_t*)&(outputs_mem[i]->size));
gettimeofday(&start_time, NULL);
rknn_set_io_mem(ctx, outputs_mem[i], &output_attrs[i]);
gettimeofday(&stop_time, NULL);
}
output_io_init_time += (__get_us(stop_time) - __get_us(start_time)) / 1000;

printf("init drm mem success\n");
#else
printf("using rknn_create_mem to alloc mem\n");
Expand Down Expand Up @@ -498,10 +516,6 @@ int main(int argc, char **argv)
}
#endif

struct timeval start_time, stop_time;
float set_time, run_time_simple, run_time_full, get_time, cvt_type_time = 0;
long oldTime, newTime;


#if USE_ZERO_COPY
float* output_data_fp[io_num.n_output][1];
Expand Down Expand Up @@ -579,6 +593,7 @@ int main(int argc, char **argv)

gettimeofday(&stop_time, NULL);
run_time_simple += (__get_us(stop_time) - __get_us(start_time)) / 1000;
printf("run_time = %f ms\n",(__get_us(stop_time) - __get_us(start_time)) / 1000);

// output get
gettimeofday(&start_time, NULL);
Expand Down Expand Up @@ -625,10 +640,10 @@ int main(int argc, char **argv)
# if USE_ZERO_COPY
fprintf(output_file, "infer type: zero_copy\n");
// fprintf(output_file, "input_syn_time: %f ms\nrun_time: %f ms\noutput_syn_time: %f ms\ncvt_type_time: %f ms\ntotal_time: %f ms\n", set_time, run_time_simple, get_time, cvt_type_time, run_time_full);
fprintf(output_file, "run_time: %f ms\ncvt_type_time: %f ms\ntotal_time: %f ms\n", run_time_simple, cvt_type_time, run_time_full);
fprintf(output_file, "model_init: %f ms\nrun: %f ms\ncpu_dequantize: %f ms\ntotal_time: %f ms\ninput_io_init: %f ms\noutput_io_init: %f ms\n", init_time, run_time_full, cvt_type_time, run_time_full, input_io_init_time, output_io_init_time);
# else
fprintf(output_file, "infer type: normal\n");
fprintf(output_file, "set_time: %f ms\nrun_time: %f ms\nget_time: %f ms\ntotal_time: %f ms\n", set_time, run_time_simple, get_time, run_time_full);
fprintf(output_file, "model_init: %f ms\ninput_set: %f ms\nrun: %f ms\noutput_get: %f ms\ntotal_time: %f ms\n", init_time, set_time, run_time_simple, get_time, run_time_full);
# endif

// save npy
Expand Down Expand Up @@ -687,6 +702,11 @@ int main(int argc, char **argv)
}
#endif

// rknn_perf_detail perf_detail;
// ret = rknn_query(ctx, RKNN_QUERY_PERF_DETAIL, &perf_detail,
// sizeof(rknn_perf_detail));
// printf("%s", perf_detail.perf_data);

// Release
if (ctx >= 0)
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a63ce65

Please sign in to comment.