From c2bc810c4a113ad513b05edd79127b1ba3e62a16 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Thu, 16 May 2024 00:21:50 +0530 Subject: [PATCH 1/9] Update .gitmodules Updating .gitmodules --- .gitmodules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitmodules b/.gitmodules index 40af2980839..daed303750b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -68,3 +68,6 @@ [submodule "third-party/ios-cmake"] path = third-party/ios-cmake url = https://github.com/leetal/ios-cmake +[submodule "backends/cadence/hifi/third-party/nnlib"] + path = backends/cadence/hifi/third-party/nnlib + url = https://github.com/foss-xtensa/nnlib-hifi4.git From 82e159e3a8e1ad80edda28322882014ab505f7f0 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Wed, 15 May 2024 12:04:57 -0700 Subject: [PATCH 2/9] adding nnlib repo --- .gitmodules | 3 +++ backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 | 1 + 2 files changed, 4 insertions(+) create mode 160000 backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 diff --git a/.gitmodules b/.gitmodules index daed303750b..8e67a93ad03 100644 --- a/.gitmodules +++ b/.gitmodules @@ -71,3 +71,6 @@ [submodule "backends/cadence/hifi/third-party/nnlib"] path = backends/cadence/hifi/third-party/nnlib url = https://github.com/foss-xtensa/nnlib-hifi4.git +[submodule "backends/cadence/hifi/third-party/nnlib/nnlib-hifi4"] + path = backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 + url = https://github.com/foss-xtensa/nnlib-hifi4.git diff --git a/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 b/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 new file mode 160000 index 00000000000..6a9ea45e23e --- /dev/null +++ b/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 @@ -0,0 +1 @@ +Subproject commit 6a9ea45e23ef591fe207442df33a5ebe88bbe8de From 6dfda8d27127ac50f52a25a231cb47409ece9dd8 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Thu, 16 May 2024 16:24:37 +0530 Subject: [PATCH 3/9] Update .gitmodules Removing extra entry in .gitmodule --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8e67a93ad03..e22780c8e84 100644 --- a/.gitmodules +++ b/.gitmodules @@ -68,9 +68,6 @@ [submodule "third-party/ios-cmake"] path = third-party/ios-cmake url = https://github.com/leetal/ios-cmake -[submodule "backends/cadence/hifi/third-party/nnlib"] - path = backends/cadence/hifi/third-party/nnlib - url = https://github.com/foss-xtensa/nnlib-hifi4.git [submodule "backends/cadence/hifi/third-party/nnlib/nnlib-hifi4"] path = backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 url = https://github.com/foss-xtensa/nnlib-hifi4.git From 8cc2bd8cc2994cce425aae3ac759ce86341ac679 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Fri, 17 May 2024 00:45:45 +0530 Subject: [PATCH 4/9] Adding build support for nnlib --- backends/cadence/CMakeLists.txt | 118 ++---------------- .../hifi/third-party/nnlib/CMakeLists.txt | 35 ++++++ 2 files changed, 44 insertions(+), 109 deletions(-) create mode 100644 backends/cadence/hifi/third-party/nnlib/CMakeLists.txt diff --git a/backends/cadence/CMakeLists.txt b/backends/cadence/CMakeLists.txt index f1d5ccbd2e5..14030719153 100644 --- a/backends/cadence/CMakeLists.txt +++ b/backends/cadence/CMakeLists.txt @@ -12,7 +12,7 @@ if(NOT CMAKE_CXX_STANDARD) endif() # Set the project name. -project(cadence_executorch_example) +project(cadence_backend) # Source root directory for executorch. if(NOT EXECUTORCH_ROOT) @@ -21,121 +21,21 @@ endif() include(${EXECUTORCH_ROOT}/build/Utils.cmake) -if(NOT PYTHON_EXECUTABLE) - resolve_python_executable() -endif() - # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/..) -# Find prebuilt executorch lib -find_package(executorch CONFIG REQUIRED) - -add_compile_options( - -DSDK_DEBUGCONSOLE=1 - -DSERIAL_PORT_TYPE_UART=1 - -DDEBUG_CONSOLE_RX_ENABLE=0 - -DDEBUG - -DCPU_MIMXRT685SFVKB_dsp - -DMCUXPRESSO_SDK - -g - -O0 - -Wall - -fsigned-char - -Wno-missing-braces - -fmessage-length=0 - -DPRINTF_FLOAT_ENABLE=1 -) - -if(NOT DEFINED NXP_SDK_ROOT_DIR) - message(FATAL_ERROR "NXP_SDK_ROOT_DIR is not set") -endif() - -# lint_cmake: -linelength -set(SOURCES - ${NXP_SDK_ROOT_DIR}/components/lists/fsl_component_generic_list.c - ${NXP_SDK_ROOT_DIR}/components/uart/fsl_adapter_usart.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_clock.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common_dsp.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_flexcomm.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_gpio.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_mu.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_reset.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_usart.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/system_MIMXRT685S_dsp.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_assert.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_debug_console.c - ${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/board_hifi4.c - ${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/pin_mux.c - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str/fsl_str.c -) - -add_library(dsp_mu_polling_libs STATIC ${SOURCES}) - -target_include_directories( - dsp_mu_polling_libs - PUBLIC ${NXP_SDK_ROOT_DIR} - ${NXP_SDK_ROOT_DIR}/components/uart - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite - ${NXP_SDK_ROOT_DIR}/components/lists - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S - ${NXP_SDK_ROOT_DIR}/CMSIS/Core/Include - ${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str - ${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp -) - -add_library(extension_runner_util STATIC IMPORTED) -set_property( - TARGET extension_runner_util - PROPERTY - IMPORTED_LOCATION - "${CMAKE_CURRENT_LIST_DIR}/../../cmake-out/extension/runner_util/libextension_runner_util.a" -) - +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/third-party/nnlib) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/operators) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/kernels) -# Generate the model header file -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/model_pte.h - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py - --model_path ${MODEL_PATH} --header_output_path ${CMAKE_BINARY_DIR} - COMMENT "Converting .pte model to header file..." - DEPENDS ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py -) - -add_custom_target(gen_model_header DEPENDS ${CMAKE_BINARY_DIR}/model_pte.h) -add_executable(cadence_executorch_example executor_runner.cpp) -add_dependencies(cadence_executorch_example gen_model_header) - -# lint_cmake: -linelength -target_include_directories( - cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} - ${_common_include_directories} +install( + TARGETS cadence_ops_lib + DESTINATION lib + INCLUDES + DESTINATION ${_common_include_directories} ) -target_link_options( - cadence_executorch_example PRIVATE - -mlsp=${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/xtensa/min-rt -) -target_link_libraries( - cadence_executorch_example dsp_mu_polling_libs cadence_ops_lib - extension_runner_util executorch -) -add_custom_command( - TARGET cadence_executorch_example - POST_BUILD - COMMAND - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR} - COMMENT - "Generating .bin files that can be used to flash the DSP with. Copy over - the dsp_text_release.bin and dsp_data_release.bin that are generated into - your NXP MCUXpresso IDE workspace and flash the DSP with these binaries." - DEPENDS - ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py -) + + diff --git a/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt new file mode 100644 index 00000000000..b7c777fa3ea --- /dev/null +++ b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt @@ -0,0 +1,35 @@ +include(ExternalProject) +cmake_minimum_required(VERSION 3.10.0) +project(cadence_nnlib) + +set(CMAKE_C_COMPILER xt-clang) +set(CMAKE_CXX_COMPILER xt-clang++) +set(CMAKE_LINKER xt-ld) + + +add_custom_target( nnlib_target ALL COMMAND make install_nnlib -f makefile -C ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nnlib/build -j ) + +add_library(xa_nnlib STATIC IMPORTED GLOBAL) +add_dependencies(xa_nnlib nnlib_target) + +set_property( + TARGET xa_nnlib + PROPERTY + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/nnlib-hifi4/xa_nnlib/build/libxa_nnlib.a" +) + +#set(_common_include_directories ${EXECUTORCH_ROOT}/..) +#install( +# TARGETS xa_nnlib +# DESTINATION lib +# DESTINATION ${_common_include_directories} +#) + + + + + + + + + From 2ec6046ba502ffd1db96e4cc23949cb1647af3c9 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Fri, 17 May 2024 11:49:46 -0700 Subject: [PATCH 5/9] Adding cmakelist changes to link nnlib --- CMakeLists.txt | 10 +++++++++- backends/cadence/hifi/kernels/CMakeLists.txt | 2 ++ .../hifi/third-party/nnlib/CMakeLists.txt | 17 ++++------------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b4c31a131c..42568129c02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,7 +417,7 @@ target_link_libraries(executorch_no_prim_ops PRIVATE program_schema) # Check if dl exists for this toolchain and only then link it. find_library(DL_LIBRARY_EXISTS NAMES dl) # Check if the library was found -if(DL_LIBRARY_EXISTS) +if(DL_LIBRARY_EXISTS AND NOT EXECUTORCH_BUILD_CADENCE) target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr() endif() target_include_directories( @@ -443,7 +443,9 @@ target_link_options_shared_lib(executorch) # Real integrations should supply their own YAML file that only lists the # operators necessary for the models that will run. # +if(NOT EXECUTORCH_BUILD_CADENCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable) +endif() if(EXECUTORCH_BUILD_KERNELS_CUSTOM) # TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom @@ -496,6 +498,8 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib) + elseif(EXECUTORCH_BUILD_CADENCE) + list(APPEND _executor_runner_libs cadence_ops_lib) else() list(APPEND _executor_runner_libs portable_ops_lib) endif() @@ -566,6 +570,10 @@ if(EXECUTORCH_BUILD_COREML) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml) endif() +if(EXECUTORCH_BUILD_CADENCE) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cadence) +endif() + if(EXECUTORCH_BUILD_PYBIND) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/pybind11) diff --git a/backends/cadence/hifi/kernels/CMakeLists.txt b/backends/cadence/hifi/kernels/CMakeLists.txt index 9d4d456d8bc..872e62fc970 100644 --- a/backends/cadence/hifi/kernels/CMakeLists.txt +++ b/backends/cadence/hifi/kernels/CMakeLists.txt @@ -20,3 +20,5 @@ target_include_directories( ${NN_LIB_BASE_DIR}/xa_nnlib/algo/ndsp/hifi4/include/ ${NXP_SDK_ROOT_DIR}/middleware/dsp/naturedsp/hifi4/include/ ) + +target_link_libraries(cadence_kernels PRIVATE xa_nnlib) \ No newline at end of file diff --git a/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt index b7c777fa3ea..d038d0caa1f 100644 --- a/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt +++ b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt @@ -1,13 +1,9 @@ -include(ExternalProject) + cmake_minimum_required(VERSION 3.10.0) project(cadence_nnlib) -set(CMAKE_C_COMPILER xt-clang) -set(CMAKE_CXX_COMPILER xt-clang++) -set(CMAKE_LINKER xt-ld) - -add_custom_target( nnlib_target ALL COMMAND make install_nnlib -f makefile -C ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nnlib/build -j ) +add_custom_target( nnlib_target ALL COMMAND make install_nnlib -f makefile -C ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/build -j ) add_library(xa_nnlib STATIC IMPORTED GLOBAL) add_dependencies(xa_nnlib nnlib_target) @@ -15,15 +11,10 @@ add_dependencies(xa_nnlib nnlib_target) set_property( TARGET xa_nnlib PROPERTY - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/nnlib-hifi4/xa_nnlib/build/libxa_nnlib.a" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/nnlib-hifi4/xa_nnlib/build/xa_nnlib.a" ) -#set(_common_include_directories ${EXECUTORCH_ROOT}/..) -#install( -# TARGETS xa_nnlib -# DESTINATION lib -# DESTINATION ${_common_include_directories} -#) + From 2da285eb612474e0d4454e3e1c48791847ebf63f Mon Sep 17 00:00:00 2001 From: dijopaul Date: Wed, 22 May 2024 04:14:31 -0700 Subject: [PATCH 6/9] Adding CFLAG updates --- backends/cadence/cadence.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/cadence/cadence.cmake b/backends/cadence/cadence.cmake index 137b178ab92..25f241f205c 100644 --- a/backends/cadence/cadence.cmake +++ b/backends/cadence/cadence.cmake @@ -41,8 +41,8 @@ set(CMAKE_CROSSCOMPILING TRUE) set(CMAKE_C_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang++) -set(CMAKE_C_FLAGS_INIT "-stdlib=libc++") -set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++") +set(CMAKE_C_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls") +set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls") set(CMAKE_SYSROOT ${TOOLCHAIN_HOME}/${SYSROOT_TARGET}) set(CMAKE_LINKER ${TOOLCHAIN_HOME}/bin/xt-ld) add_link_options(-lm -stdlib=libc++ -Wl,--no-as-needed -static) From 5ad8ab0ad451c5c21b100adc3de14585a7848d78 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Tue, 28 May 2024 12:12:19 -0700 Subject: [PATCH 7/9] Adding quantizer and dequantizer from nnlib --- backends/cadence/hifi/kernels/kernels.h | 25 +++++++++++++++++++ .../hifi/operators/dequantize_per_tensor.cpp | 17 ++++++++----- .../hifi/operators/quantize_per_tensor.cpp | 17 ++++++++----- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/backends/cadence/hifi/kernels/kernels.h b/backends/cadence/hifi/kernels/kernels.h index 13e0470b382..59bf4c41f65 100644 --- a/backends/cadence/hifi/kernels/kernels.h +++ b/backends/cadence/hifi/kernels/kernels.h @@ -12,6 +12,31 @@ #include "stddef.h" #include "xa_type_def.h" + +extern "C" WORD32 xa_nn_elm_quantize_f32_asym8s(WORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp, + FLOAT32 out_scale, + WORD32 out_zero_bias, + WORD32 num_elm); + +/*extern "C" WORD32 xa_nn_elm_quantize_f32_asym8u(UWORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp, + FLOAT32 out_scale, + WORD32 out_zero_bias, + WORD32 num_elm); */ + +extern "C" WORD32 xa_nn_elm_dequantize_asym8s_f32(FLOAT32 * __restrict__ p_out, + const WORD8 * __restrict__ p_inp, + WORD32 inp_zero_bias, + FLOAT32 inp_scale, + WORD32 num_elm); + +/*extern "C" WORD32 xa_nn_elm_dequantize_asym8u_f32(FLOAT32 * __restrict__ p_out, + const UWORD8 * __restrict__ p_inp, + WORD32 inp_zero_bias, + FLOAT32 inp_scale, + WORD32 num_elm);*/ + namespace impl { namespace HiFi { namespace kernels { diff --git a/backends/cadence/hifi/operators/dequantize_per_tensor.cpp b/backends/cadence/hifi/operators/dequantize_per_tensor.cpp index dcc4ace7898..24984a89a66 100644 --- a/backends/cadence/hifi/operators/dequantize_per_tensor.cpp +++ b/backends/cadence/hifi/operators/dequantize_per_tensor.cpp @@ -31,16 +31,21 @@ void dequantize_per_tensor_out( if (input.scalar_type() == ScalarType::Byte) { const uint8_t* input_data = input.const_data_ptr(); - impl::HiFi::kernels::dequantize( - out_data, input_data, scale, zero_point, numel); +#if 0 //NNLIB_OPT + xa_nn_elm_dequantize_asym8u_f32(out_data, input_data, zero_point, scale, numel); +#else + impl::HiFi::kernels::dequantize(out_data, input_data, scale, zero_point, numel); +#endif } else if (input.scalar_type() == ScalarType::Char) { const int8_t* input_data = input.const_data_ptr(); - impl::HiFi::kernels::dequantize( - out_data, input_data, scale, zero_point, numel); +#if 1 //NNLIB_OPT + xa_nn_elm_dequantize_asym8s_f32(out_data, input_data, zero_point, scale, numel); +#else + impl::HiFi::kernels::dequantize(out_data, input_data, scale, zero_point, numel); +#endif } else if (input.scalar_type() == ScalarType::Int) { const int32_t* input_data = input.const_data_ptr(); - impl::HiFi::kernels::dequantize( - out_data, input_data, scale, zero_point, numel); + impl::HiFi::kernels::dequantize(out_data, input_data, scale, zero_point, numel); } else { ET_CHECK_MSG(false, "Unhandled input dtype %hhd", input.scalar_type()); } diff --git a/backends/cadence/hifi/operators/quantize_per_tensor.cpp b/backends/cadence/hifi/operators/quantize_per_tensor.cpp index ec186cc68e2..ea595d12cbc 100644 --- a/backends/cadence/hifi/operators/quantize_per_tensor.cpp +++ b/backends/cadence/hifi/operators/quantize_per_tensor.cpp @@ -33,16 +33,21 @@ void quantize_per_tensor_out( if (out.scalar_type() == ScalarType::Byte) { uint8_t* out_data = out.mutable_data_ptr(); - impl::HiFi::kernels::quantize( - out_data, input_data, 1. / scale, zero_point, numel); +#if 0 //NNLIB_OPT + xa_nn_elm_quantize_f32_asym8u(out_data, input_data, scale, zero_point, numel); +#else + impl::HiFi::kernels::quantize(out_data, input_data, 1. / scale, zero_point, numel); +#endif } else if (out.scalar_type() == ScalarType::Char) { int8_t* out_data = out.mutable_data_ptr(); - impl::HiFi::kernels::quantize( - out_data, input_data, 1. / scale, zero_point, numel); +#if 1//NNLIB_OPT + xa_nn_elm_quantize_f32_asym8s(out_data, input_data, scale, zero_point, numel); +#else + impl::HiFi::kernels::quantize(out_data, input_data, 1. / scale, zero_point, numel); +#endif } else if (out.scalar_type() == ScalarType::Int) { int32_t* out_data = out.mutable_data_ptr(); - impl::HiFi::kernels::quantize( - out_data, input_data, 1. / scale, zero_point, numel); + impl::HiFi::kernels::quantize(out_data, input_data, 1. / scale, zero_point, numel); } else { ET_CHECK_MSG(false, "Unhandled input dtype %hhd", out.scalar_type()); } From 6b6b80b8aa4b47e174c22fc059e09c4c3859a47a Mon Sep 17 00:00:00 2001 From: dijopaul Date: Wed, 29 May 2024 13:24:11 -0700 Subject: [PATCH 8/9] Moving nnlib obj and lib files to cmake build dir --- .../cadence/hifi/third-party/nnlib/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt index d038d0caa1f..d8f2b4eb3d9 100644 --- a/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt +++ b/backends/cadence/hifi/third-party/nnlib/CMakeLists.txt @@ -3,15 +3,22 @@ cmake_minimum_required(VERSION 3.10.0) project(cadence_nnlib) -add_custom_target( nnlib_target ALL COMMAND make install_nnlib -f makefile -C ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/build -j ) +add_custom_target( nnlib_target ALL COMMAND + make install_nnlib -f makefile -C ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/build + OBJDIR=${CMAKE_CURRENT_BINARY_DIR}/obj + LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/lib + -j8 ) add_library(xa_nnlib STATIC IMPORTED GLOBAL) add_dependencies(xa_nnlib nnlib_target) +message("NNLIB") +message("${CMAKE_CURRENT_BINARY_DIR}") + set_property( TARGET xa_nnlib PROPERTY - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/nnlib-hifi4/xa_nnlib/build/xa_nnlib.a" + IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/lib/xa_nnlib.a" ) From 33286466e4f9dcebda1c04ecdfcf12bb84253dc8 Mon Sep 17 00:00:00 2001 From: dijopaul Date: Wed, 29 May 2024 13:40:03 -0700 Subject: [PATCH 9/9] Clean up quantize and dequantize --- backends/cadence/hifi/operators/dequantize_per_tensor.cpp | 4 ++-- backends/cadence/hifi/operators/quantize_per_tensor.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backends/cadence/hifi/operators/dequantize_per_tensor.cpp b/backends/cadence/hifi/operators/dequantize_per_tensor.cpp index 24984a89a66..3f683a6d713 100644 --- a/backends/cadence/hifi/operators/dequantize_per_tensor.cpp +++ b/backends/cadence/hifi/operators/dequantize_per_tensor.cpp @@ -31,14 +31,14 @@ void dequantize_per_tensor_out( if (input.scalar_type() == ScalarType::Byte) { const uint8_t* input_data = input.const_data_ptr(); -#if 0 //NNLIB_OPT +#if 0 //NNLIB_OPT (not available in nnlib) xa_nn_elm_dequantize_asym8u_f32(out_data, input_data, zero_point, scale, numel); #else impl::HiFi::kernels::dequantize(out_data, input_data, scale, zero_point, numel); #endif } else if (input.scalar_type() == ScalarType::Char) { const int8_t* input_data = input.const_data_ptr(); -#if 1 //NNLIB_OPT +#if NNLIB_OPT xa_nn_elm_dequantize_asym8s_f32(out_data, input_data, zero_point, scale, numel); #else impl::HiFi::kernels::dequantize(out_data, input_data, scale, zero_point, numel); diff --git a/backends/cadence/hifi/operators/quantize_per_tensor.cpp b/backends/cadence/hifi/operators/quantize_per_tensor.cpp index ea595d12cbc..3137b91f6be 100644 --- a/backends/cadence/hifi/operators/quantize_per_tensor.cpp +++ b/backends/cadence/hifi/operators/quantize_per_tensor.cpp @@ -33,14 +33,14 @@ void quantize_per_tensor_out( if (out.scalar_type() == ScalarType::Byte) { uint8_t* out_data = out.mutable_data_ptr(); -#if 0 //NNLIB_OPT +#if 0 //NNLIB_OPT (not available in nnlib) xa_nn_elm_quantize_f32_asym8u(out_data, input_data, scale, zero_point, numel); #else impl::HiFi::kernels::quantize(out_data, input_data, 1. / scale, zero_point, numel); #endif } else if (out.scalar_type() == ScalarType::Char) { int8_t* out_data = out.mutable_data_ptr(); -#if 1//NNLIB_OPT +#if NNLIB_OPT xa_nn_elm_quantize_f32_asym8s(out_data, input_data, scale, zero_point, numel); #else impl::HiFi::kernels::quantize(out_data, input_data, 1. / scale, zero_point, numel);