diff --git a/docs/conf.py b/docs/conf.py index c4717f7341155..ba9ff8700a170 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -309,10 +309,11 @@ def git_describe_version(original_version): "bring_your_own_datatypes.py", ], "micro": [ + "micro_autotune.py", "micro_reference_vm.py", "micro_tflite.py", - "cortex_m_ethosu.py", - ], + "micro_ethosu.py", + ], } @@ -355,6 +356,7 @@ def force_gc(gallery_conf, fname): "gallery_dirs": gallery_dirs, "subsection_order": subsection_order, "filename_pattern": os.environ.get("TVM_TUTORIAL_EXEC_PATTERN", ".py"), + "find_mayavi_figures": False, "download_all_examples": False, "min_reported_time": 60, "expected_failing_examples": [], diff --git a/tutorials/micro/cortex_m_ethosu.py b/gallery/how_to/work_with_microtvm/micro_ethosu.py similarity index 98% rename from tutorials/micro/cortex_m_ethosu.py rename to gallery/how_to/work_with_microtvm/micro_ethosu.py index f0463f7567baf..95766472bd50c 100644 --- a/tutorials/micro/cortex_m_ethosu.py +++ b/gallery/how_to/work_with_microtvm/micro_ethosu.py @@ -49,20 +49,20 @@ # .. code-block:: text # # usage: tvmc [-h] [-v] [--version] {tune,compile,run} ... -# +# # TVM compiler driver -# +# # optional arguments: # -h, --help show this help message and exit # -v, --verbose increase verbosity # --version print the version and exit -# +# # commands: # {tune,compile,run} # tune auto-tune a model # compile compile a model. # run run a compiled module -# +# # TVMC - TVM driver command-line interface # @@ -238,8 +238,8 @@ # import sys # from PIL import Image # import numpy as np -# -# +# +# # def create_header_file(name, section, tensor_name, tensor_data, output_path): # """ # This function generates a header file containing the data from the numpy array provided. @@ -257,21 +257,21 @@ # for i in range(0, len(data_hexstr), 2): # header_file.write(f"\\x{data_hexstr[i:i+2]}") # header_file.write('";\n\n') -# -# +# +# # def create_headers(image_name): # """ # This function generates C header files for the input and output arrays required to run inferences # """ # img_path = os.path.join("./", f"{image_name}") -# +# # # Resize image to 224x224 # resized_image = Image.open(img_path).resize((224, 224)) # img_data = np.asarray(resized_image).astype("float32") -# +# # # Convert input to NCHW # img_data = np.transpose(img_data, (2, 0, 1)) -# +# # # Create input header file # input_data = img_data.astype(np.uint8) # create_header_file("inputs", "ethosu_scratch", "input", input_data, "./include") @@ -284,8 +284,8 @@ # output_data, # "./include", # ) -# -# +# +# # if __name__ == "__main__": # create_headers(sys.argv[1]) # @@ -312,27 +312,27 @@ # import os # import pathlib # import sys -# -# +# +# # def create_labels_header(labels_file, section, output_path): # """ # This function generates a header file containing the ImageNet labels as an array of strings # """ # labels_path = pathlib.Path(labels_file).resolve() # file_path = pathlib.Path(f"{output_path}/labels.h").resolve() -# +# # with open(labels_path) as f: # labels = f.readlines() -# +# # with open(file_path, "w") as header_file: # header_file.write(f'char* labels[] __attribute__((section("{section}"), aligned(16))) = {{') -# +# # for _, label in enumerate(labels): # header_file.write(f'"{label.rstrip()}",') -# +# # header_file.write("};\n") -# -# +# +# # if __name__ == "__main__": # create_labels_header(sys.argv[1], "ethosu_scratch", "./include") # @@ -360,25 +360,25 @@ # # #include # #include -# +# # #include "ethosu_mod.h" # #include "uart.h" -# +# # // Header files generated by convert_image.py and convert_labels.py # #include "inputs.h" # #include "labels.h" # #include "outputs.h" -# +# # int abs(int v) { return v * ((v > 0) - (v < 0)); } -# +# # int main(int argc, char** argv) { # uart_init(); # printf("Starting Demo\n"); # EthosuInit(); -# +# # printf("Allocating memory\n"); # StackMemoryManager_Init(&app_workspace, g_aot_memory, WORKSPACE_SIZE); -# +# # printf("Running inference\n"); # struct tvmgen_default_outputs outputs = { # .output = output, @@ -387,7 +387,7 @@ # .input = input, # }; # tvmgen_default_run(&inputs, &outputs); -# +# # // Calculate index of max value # uint8_t max_value = 0; # int32_t max_index = -1; @@ -398,7 +398,7 @@ # } # } # printf("The image has been classified as '%s'\n", labels[max_index]); -# +# # // The FVP will shut down when it receives "EXITTHESIM" on the UART # printf("EXITTHESIM\n"); # while (1 == 1) @@ -463,10 +463,10 @@ # # #ifndef TVM_RUNTIME_CRT_CONFIG_H_ # #define TVM_RUNTIME_CRT_CONFIG_H_ -# +# # /*! Log level of the CRT runtime */ # #define TVM_CRT_LOG_LEVEL TVM_CRT_LOG_LEVEL_DEBUG -# +# # #endif // TVM_RUNTIME_CRT_CONFIG_H_ # # @@ -479,39 +479,39 @@ # #include # #include # #include -# +# # #ifdef __cplusplus # extern "C" { # #endif -# +# # #define WORKSPACE_SIZE (16384 * 1024) # __attribute__((section("ethosu_scratch"))) static uint8_t g_aot_memory[WORKSPACE_SIZE]; -# +# # tvm_workspace_t app_workspace; -# +# # void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t error_code) { # printf("TVMPlatformAbort: %d\n", error_code); # printf("EXITTHESIM\n"); # exit(-1); # } -# +# # tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr) { # return StackMemoryManager_Allocate(&app_workspace, num_bytes, out_ptr); # } -# +# # tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) { # return StackMemoryManager_Free(&app_workspace, ptr); # } -# +# # void TVMLogf(const char* msg, ...) { # va_list args; # va_start(args, msg); # vfprintf(stdout, msg, args); # va_end(args); # } -# +# # TVM_DLL int TVMFuncRegisterGlobal(const char* name, TVMFunctionHandle f, int override) { return 0; } -# +# # #ifdef __cplusplus # } # #endif @@ -841,7 +841,7 @@ # # Setup build environment # BUILD_DIR := build # STANDALONE_CRT_PATH := $(shell python3 -c "import tvm.micro; print(tvm.micro.get_standalone_crt_dir())") -# +# # ARM_CPU = ARMCM55 # ETHOSU_PATH = /opt/arm/ethosu # ETHOSU_DRIVER_PATH ?= ${ETHOSU_PATH}/core_driver @@ -867,67 +867,67 @@ # -DETHOSU_LOG_SEVERITY=debug \ # -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 # PKG_LDFLAGS = -lm -specs=nosys.specs -static -T corstone300.ld -# +# # $(ifeq VERBOSE,1) # QUIET ?= # $(else) # QUIET ?= @ # $(endif) -# +# # CODEGEN_SRCS = $(wildcard $(abspath $(BUILD_DIR))/codegen/host/src/*.c) # CODEGEN_OBJS = $(subst .c,.o,$(CODEGEN_SRCS)) # CMSIS_STARTUP_SRCS = $(wildcard ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/*.c) # UART_SRCS = $(wildcard ${CORSTONE_300_PATH}/*.c) -# +# # demo: $(BUILD_DIR)/demo -# +# # $(BUILD_DIR)/stack_allocator.o: $(STANDALONE_CRT_PATH)/src/runtime/crt/memory/stack_allocator.c # $(QUIET)mkdir -p $(@D) # $(QUIET)$(CC) -c $(PKG_CFLAGS) -o $@ $^ -# +# # $(BUILD_DIR)/crt_backend_api.o: $(STANDALONE_CRT_PATH)/src/runtime/crt/common/crt_backend_api.c # $(QUIET)mkdir -p $(@D) # $(QUIET)$(CC) -c $(PKG_CFLAGS) -o $@ $^ -# +# # # Build generated code # $(BUILD_DIR)/libcodegen.a: $(CODEGEN_SRCS) # $(QUIET)cd $(abspath $(BUILD_DIR)/codegen/host/src) && $(CC) -c $(PKG_CFLAGS) $(CODEGEN_SRCS) # $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcodegen.a) $(CODEGEN_OBJS) # $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcodegen.a) -# +# # # Build CMSIS startup code # ${BUILD_DIR}/libcmsis_startup.a: $(CMSIS_STARTUP_SRCS) # $(QUIET)mkdir -p $(abspath $(BUILD_DIR)/libcmsis_startup) # $(QUIET)cd $(abspath $(BUILD_DIR)/libcmsis_startup) && $(CC) -c $(PKG_CFLAGS) -D${ARM_CPU} $^ # $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcmsis_startup.a) $(abspath $(BUILD_DIR))/libcmsis_startup/*.o # $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcmsis_startup.a) -# +# # # Build UART code # ${BUILD_DIR}/libuart.a: $(UART_SRCS) # $(QUIET)mkdir -p $(abspath $(BUILD_DIR)/libuart) # $(QUIET)cd $(abspath $(BUILD_DIR)/libuart) && $(CC) -c $(PKG_CFLAGS) $^ # $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libuart.a) $(abspath $(BUILD_DIR))/libuart/*.o # $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libuart.a) -# +# # # Build Arm(R) Ethos(TM)-U core driver # ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a: # $(QUIET)mkdir -p $(@D) # $(QUIET)cd $(ETHOSU_DRIVER_PATH) && $(CMAKE) -B $(abspath $(BUILD_DIR)/ethosu_core_driver) $(DRIVER_CMAKE_FLAGS) # $(QUIET)cd $(abspath $(BUILD_DIR)/ethosu_core_driver) && $(MAKE) -# +# # # Build demo application # $(BUILD_DIR)/demo: src/demo.c $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a ${BUILD_DIR}/libuart.a # $(QUIET)mkdir -p $(@D) # $(QUIET)$(CC) $(PKG_CFLAGS) -o $@ $^ $(PKG_LDFLAGS) -# +# # clean: # $(QUIET)rm -rf $(BUILD_DIR)/crt -# +# # cleanall: # $(QUIET)rm -rf $(BUILD_DIR) -# +# # .SUFFIXES: -# +# # .DEFAULT: demo #