diff --git a/CMakeLists.txt b/CMakeLists.txt index b8ef4dc..a1d161c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,31 @@ +# Generated Cmake Pico project file cmake_minimum_required(VERSION 3.12) -# Pull in PICO SDK (must be before project) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +# == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work == +if(WIN32) + set(USERHOME $ENV{USERPROFILE}) +else() + set(USERHOME $ENV{HOME}) +endif() +set(sdkVersion 2.0.0) +set(toolchainVersion 13_2_Rel1) +set(picotoolVersion 2.0.0) +set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) +if (EXISTS ${picoVscode}) + include(${picoVscode}) +endif() +# ==================================================================================== + +set(PICO_BOARD pico2 CACHE STRING "Board type") + +# Pull in Raspberry Pi Pico SDK (must be before project) include(pico_sdk_import.cmake) project(pico-tflmicro C CXX ASM) -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 11) pico_sdk_init() @@ -35,14 +54,15 @@ target_compile_definitions( COMPILE_DEFINITIONS TFLITE_USE_CTIME=1 ) -set_target_properties( +target_compile_options( pico-tflmicro - PROPERTIES - COMPILE_FLAGS -Os - COMPILE_FLAGS -fno-rtti - COMPILE_FLAGS -fno-exceptions - COMPILE_FLAGS -fno-threadsafe-statics - COMPILE_FLAGS -nostdlib + PUBLIC + -Os + -fno-exceptions + -nostdlib + $<$: + -fno-rtti + -fno-threadsafe-statics> ) target_link_libraries( @@ -670,7 +690,7 @@ add_subdirectory("tests/arena_allocator_persistent_arena_buffer_allocator_test") add_subdirectory("tests/arena_allocator_recording_single_arena_buffer_allocator_test") add_subdirectory("tests/arena_allocator_single_arena_buffer_allocator_test") add_subdirectory("tests/fake_micro_context_test") -add_subdirectory("tests/flatbuffer_utils_test") +#add_subdirectory("tests/flatbuffer_utils_test") add_subdirectory("tests/kernels_activations_test") add_subdirectory("tests/kernels_add_n_test") add_subdirectory("tests/kernels_add_test") @@ -692,7 +712,7 @@ add_subdirectory("tests/kernels_depthwise_conv_test") add_subdirectory("tests/kernels_dequantize_test") add_subdirectory("tests/kernels_detection_postprocess_test") add_subdirectory("tests/kernels_div_test") -add_subdirectory("tests/kernels_elementwise_test") +#add_subdirectory("tests/kernels_elementwise_test") add_subdirectory("tests/kernels_elu_test") add_subdirectory("tests/kernels_embedding_lookup_test") add_subdirectory("tests/kernels_exp_test") @@ -706,8 +726,8 @@ add_subdirectory("tests/kernels_gather_nd_test") add_subdirectory("tests/kernels_gather_test") add_subdirectory("tests/kernels_hard_swish_test") add_subdirectory("tests/kernels_if_test") -add_subdirectory("tests/kernels_l2_pool_2d_test") -add_subdirectory("tests/kernels_l2norm_test") +#add_subdirectory("tests/kernels_l2_pool_2d_test") +#add_subdirectory("tests/kernels_l2norm_test") add_subdirectory("tests/kernels_leaky_relu_test") add_subdirectory("tests/kernels_log_softmax_test") add_subdirectory("tests/kernels_logical_test") diff --git a/examples/hello_world/main_functions.cpp b/examples/hello_world/main_functions.cpp index ef16104..3c6bfce 100644 --- a/examples/hello_world/main_functions.cpp +++ b/examples/hello_world/main_functions.cpp @@ -89,10 +89,8 @@ void loop() { static_cast(kInferencesPerCycle); float x = position * kXrange; - // Quantize the input from floating-point to integer - int8_t x_quantized = x / input->params.scale + input->params.zero_point; - // Place the quantized input in the model's input tensor - input->data.int8[0] = x_quantized; + // Obtain the input from floating-point to integer + input->data.f[0] = x; // Run inference, and report any error TfLiteStatus invoke_status = interpreter->Invoke(); @@ -101,10 +99,8 @@ void loop() { return; } - // Obtain the quantized output from model's output tensor - int8_t y_quantized = output->data.int8[0]; - // Dequantize the output from integer to floating-point - float y = (y_quantized - output->params.zero_point) * output->params.scale; + // Obtain the output from model's output tensor + float y = output->data.f[0]; // Output the results. A custom HandleOutput function can be implemented // for each supported hardware target. diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake index f63ee3f..a0721d0 100644 --- a/pico_sdk_import.cmake +++ b/pico_sdk_import.cmake @@ -3,8 +3,6 @@ # This can be dropped into an external project to help locate this SDK # It should be include()ed prior to project() -# todo document - if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") @@ -20,9 +18,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") endif () -set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the PICO SDK") -set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO SDK from git if not otherwise locatable") +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG)) + set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG}) + message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')") +endif () + +if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG) + set(PICO_SDK_FETCH_FROM_GIT_TAG "master") + message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG") +endif() + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") +set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK") if (NOT PICO_SDK_PATH) if (PICO_SDK_FETCH_FROM_GIT) @@ -31,20 +40,31 @@ if (NOT PICO_SDK_PATH) if (PICO_SDK_FETCH_FROM_GIT_PATH) get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") endif () - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG master - ) + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + ) + endif () + if (NOT pico_sdk) - message("Downloading PICO SDK") + message("Downloading Raspberry Pi Pico SDK") FetchContent_Populate(pico_sdk) set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) endif () set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) else () message(FATAL_ERROR - "PICO SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." ) endif () endif () @@ -56,9 +76,9 @@ endif () set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) - message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the PICO SDK") + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") endif () -set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the PICO SDK" FORCE) +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) include(${PICO_SDK_INIT_CMAKE_FILE})