diff --git a/components/basic/Kconfig b/components/basic/Kconfig index e69de29b..9b3182d9 100644 --- a/components/basic/Kconfig +++ b/components/basic/Kconfig @@ -0,0 +1,23 @@ +menu "Basic config" +config OMP_ENABLE + bool "Enable omp" + default n if PLATFORM = "maixcam" + default y if PLATFORM = "maixcam2" + help + Enable OMP to accelerate performance on multi-core platforms. +config OMP_ENABLE_DYNAMIC + bool "Enable omp dynamic" + default n if PLATFORM = "maixcam" + default n if PLATFORM = "maixcam2" + depends on OMP_ENABLE + help + Enable or disable dynamic adjustment of the number of threads in a parallel region + +config OMP_THREAD_NUMBER + int "Config omp thread number" + default 1 if PLATFORM = "maixcam" + default 2 if PLATFORM = "maixcam2" + depends on OMP_ENABLE + help + Set the number of threads that will be used in parallel regions +endmenu diff --git a/components/basic/include/maix_util.hpp b/components/basic/include/maix_util.hpp index 58c72662..333e7db0 100644 --- a/components/basic/include/maix_util.hpp +++ b/components/basic/include/maix_util.hpp @@ -19,6 +19,7 @@ namespace maix::util */ #define CATCH_EXCEPTION_RUN_RETURN(func, err_ret_value, ...) \ while(1){ \ + maix::util::init_before_main();\ try \ { \ int ret = (int)func(__VA_ARGS__); \ @@ -67,6 +68,13 @@ namespace maix::util */ void enable_kernel_debug(); + /** + * @brief Initialize before main + * The function is used to add preparatory operations that need to be executed before the main program runs. + * @maixpy maix.util.init_before_main + */ + void init_before_main(); + /** * @brief register exit function * @maixcdk maix.util.register_exit_function diff --git a/components/basic/port/linux/maix_util_linux.cpp b/components/basic/port/linux/maix_util_linux.cpp index 23a2be0d..c397248b 100644 --- a/components/basic/port/linux/maix_util_linux.cpp +++ b/components/basic/port/linux/maix_util_linux.cpp @@ -14,6 +14,10 @@ namespace maix::util (void)process; } + void init_before_main() { + + } + void do_exit_function() { } diff --git a/components/basic/port/maixcam/maix_util_maixcam.cpp b/components/basic/port/maixcam/maix_util_maixcam.cpp index 7dd24e22..216ae517 100644 --- a/components/basic/port/maixcam/maix_util_maixcam.cpp +++ b/components/basic/port/maixcam/maix_util_maixcam.cpp @@ -44,6 +44,10 @@ namespace maix::util static std::vector *exit_function_list; + void init_before_main() { + + } + void register_exit_function(void (*process)(void)) { if (exit_function_list == nullptr) { exit_function_list = new std::vector; diff --git a/components/basic/port/maixcam2/maix_util_maixcam2.cpp b/components/basic/port/maixcam2/maix_util_maixcam2.cpp index 7dd24e22..56926929 100644 --- a/components/basic/port/maixcam2/maix_util_maixcam2.cpp +++ b/components/basic/port/maixcam2/maix_util_maixcam2.cpp @@ -6,6 +6,10 @@ #include #include +#if CONFIG_OMP_ENABLE +#include "omp.h" +#endif + namespace maix::util { void disable_kernel_debug() { @@ -44,6 +48,17 @@ namespace maix::util static std::vector *exit_function_list; + void init_before_main() { +#if CONFIG_OMP_ENABLE +#if OMP_ENABLE_DYNAMIC + omp_set_dynamic(1); +#else + omp_set_dynamic(0); +#endif + omp_set_num_threads(CONFIG_OMP_THREAD_NUMBER); +#endif + } + void register_exit_function(void (*process)(void)) { if (exit_function_list == nullptr) { exit_function_list = new std::vector; diff --git a/components/vision/src/maix_image.cpp b/components/vision/src/maix_image.cpp index d6fce15c..ee46b984 100644 --- a/components/vision/src/maix_image.cpp +++ b/components/vision/src/maix_image.cpp @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include "omp.h" #ifdef PLATFORM_MAIXCAM #include "sophgo_middleware.hpp" #elif defined(PLATFORM_MAIXCAM2) @@ -1551,8 +1554,21 @@ __EXIT: image::Image *Image::copy() { image::Image *ret = new image::Image(_width, _height, _format); - ; + +#if defined(PLATFORM_MAIXCAM2) + auto src = (uint8_t *)_data; + auto dst = (uint8_t *)ret->data(); + auto copy_size = ret->data_size() / 2; +#pragma omp parallel sections +{ +#pragma omp section + memcpy(dst, src, copy_size); +#pragma omp section + memcpy(dst + copy_size, src + copy_size, copy_size); +} +#else memcpy(ret->data(), _data, _width * _height * image::fmt_size[_format]); +#endif return ret; } @@ -1692,6 +1708,26 @@ __EXIT: if (!ok) return err::ERR_RUNTIME; break; + case FMT_YVU420SP: + { + cv::Mat bgr; + img.rows = _height * 3 / 2; + cv::cvtColor(img, bgr, cv::COLOR_YUV2BGR_NV21); + ok = cv::imwrite(path, bgr, params); + if (!ok) + return err::ERR_RUNTIME; + break; + } + case FMT_YUV420SP: + { + cv::Mat bgr; + img.rows = _height * 3 / 2; + cv::cvtColor(img, bgr, cv::COLOR_YUV2BGR_NV12); + ok = cv::imwrite(path, bgr, params); + if (!ok) + return err::ERR_RUNTIME; + break; + } case FMT_JPEG: { std::string lower_path(path);