mirror of
https://github.com/sipeed/MaixCDK.git
synced 2026-09-12 22:59:44 -05:00
* support omp
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,6 +14,10 @@ namespace maix::util
|
||||
(void)process;
|
||||
}
|
||||
|
||||
void init_before_main() {
|
||||
|
||||
}
|
||||
|
||||
void do_exit_function() {
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ namespace maix::util
|
||||
|
||||
static std::vector<void(*)()> *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<void(*)()>;
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#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<void(*)()> *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<void(*)()>;
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <sched.h>
|
||||
#include <thread>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user