From a6622a70ba4e387c286ee77445a7a6bea8e94330 Mon Sep 17 00:00:00 2001 From: yangjie159 Date: Tue, 25 May 2021 23:37:25 +0800 Subject: [PATCH] enable refactor thread pool --- mindspore/ccsrc/CMakeLists.txt | 1 + .../runtime/framework/graph_scheduler.cc | 8 +- .../ccsrc/runtime/framework/graph_scheduler.h | 3 + mindspore/ccsrc/vm/CMakeLists.txt | 1 + mindspore/core/mindrt/CMakeLists.txt | 1 + mindspore/core/mindrt/include/actor/actor.h | 6 +- mindspore/core/mindrt/include/mindrt.hpp | 3 - mindspore/core/mindrt/src/actor/actormgr.cc | 6 - mindspore/core/mindrt/src/actor/actormgr.h | 17 +- .../core/mindrt/src/actor/actorthread.cc | 138 --- mindspore/core/mindrt/src/actor/actorthread.h | 56 - mindspore/core/mindrt/src/mindrt.cc | 9 +- .../core/mindrt/src/thread/core_affinity.cc | 47 +- .../core/mindrt/src/thread/core_affinity.h | 33 +- .../mindrt/src/thread/inter_threadpool.cc | 16 +- .../core/mindrt/src/thread/inter_threadpool.h | 3 +- .../core/mindrt/src/thread/threadpool.cc | 60 +- mindspore/core/mindrt/src/thread/threadpool.h | 21 +- mindspore/lite/CMakeLists.txt | 5 +- mindspore/lite/src/CMakeLists.txt | 1 - mindspore/lite/src/executor.cc | 9 +- mindspore/lite/src/inner_context.cc | 9 +- mindspore/lite/src/inner_context.h | 3 +- mindspore/lite/src/lite_mindrt.cc | 8 +- mindspore/lite/src/lite_mindrt.h | 9 +- mindspore/lite/src/lite_session.cc | 16 +- .../kernel/arm/base/constant_of_shape.cc | 4 +- .../arm/base/detection_post_process_base.cc | 4 +- .../src/runtime/kernel/arm/base/prior_box.cc | 4 +- .../kernel/arm/base/quant_dtype_cast.cc | 4 +- .../runtime/kernel/arm/base/reshape_base.cc | 4 +- .../src/runtime/kernel/arm/base/slice_base.cc | 4 +- .../src/runtime/kernel/arm/base/split_base.cc | 4 +- .../arm/base/split_with_over_lap_base.cc | 4 +- .../src/runtime/kernel/arm/base/stack_base.cc | 2 +- .../runtime/kernel/arm/base/strided_slice.cc | 4 +- .../src/runtime/kernel/arm/base/tile_base.cc | 4 +- .../kernel/arm/fp16/activation_fp16.cc | 4 +- .../arm/fp16/arithmetic_compare_fp16.cc | 4 +- .../kernel/arm/fp16/arithmetic_fp16.cc | 4 +- .../kernel/arm/fp16/arithmetic_self_fp16.cc | 4 +- .../runtime/kernel/arm/fp16/batchnorm_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/cast_fp16.cc | 4 +- .../kernel/arm/fp16/convolution_1x1_fp16.cc | 8 +- .../arm/fp16/convolution_depthwise_fp16.cc | 4 +- .../convolution_depthwise_slidewindow_fp16.cc | 4 +- .../kernel/arm/fp16/convolution_fp16.cc | 4 +- .../arm/fp16/convolution_winograd_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/crop_fp16.cc | 4 +- .../arm/fp16/deconvolution_depthwise_fp16.cc | 4 +- .../kernel/arm/fp16/deconvolution_fp16.cc | 4 +- .../arm/fp16/deconvolution_winograd_fp16.cc | 8 +- .../runtime/kernel/arm/fp16/gather_fp16.cc | 4 +- .../kernel/arm/fp16/instance_norm_fp16.cc | 4 +- .../kernel/arm/fp16/layer_norm_fp16.cc | 4 +- .../kernel/arm/fp16/log_softmax_fp16.cc | 4 +- .../kernel/arm/fp16/matmul_base_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/pad_fp16.cc | 8 +- .../runtime/kernel/arm/fp16/pooling_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/power_fp16.cc | 4 +- .../kernel/arm/fp16/quant_dtype_cast_fp16.cc | 4 +- .../runtime/kernel/arm/fp16/reduce_fp16.cc | 8 +- .../src/runtime/kernel/arm/fp16/scale_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/slice_fp16.cc | 4 +- .../runtime/kernel/arm/fp16/softmax_fp16.cc | 4 +- .../src/runtime/kernel/arm/fp16/stack_fp16.cc | 2 +- .../arm/fp16_grad/activation_fp16_grad.cc | 4 +- .../fp16_grad/arithmetic_fp16_self_grad.cc | 4 +- .../kernel/arm/fp32/activation_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/adder_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/addn_fp32.cc | 8 +- .../kernel/arm/fp32/arithmetic_fp32.cc | 4 +- .../kernel/arm/fp32/arithmetic_self_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/batchnorm_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/cast_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/concat_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/concat_fp32.h | 1 - .../kernel/arm/fp32/convolution_1x1_fp32.cc | 8 +- .../fp32/convolution_depthwise_3x3_fp32.cc | 4 +- .../arm/fp32/convolution_depthwise_fp32.cc | 4 +- .../convolution_depthwise_indirect_fp32.cc | 4 +- .../convolution_depthwise_slidewindow_fp32.cc | 4 +- .../kernel/arm/fp32/convolution_fp32.cc | 4 +- .../arm/fp32/convolution_slidewindow_fp32.cc | 4 +- .../arm/fp32/convolution_winograd_fp32.cc | 4 +- .../kernel/arm/fp32/crop_and_resize_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/crop_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/cumsum_fp32.cc | 4 +- .../arm/fp32/deconvolution_depthwise_fp32.cc | 4 +- .../kernel/arm/fp32/deconvolution_fp32.cc | 4 +- .../arm/fp32/deconvolution_winograd_fp32.cc | 8 +- .../src/runtime/kernel/arm/fp32/elu_fp32.cc | 4 +- .../kernel/arm/fp32/embedding_lookup_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/exp_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/fill_fp32.cc | 4 +- .../kernel/arm/fp32/fused_batchnorm_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/gatherNd_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/gather_fp32.cc | 4 +- .../kernel/arm/fp32/instance_norm_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/l2_norm_fp32.cc | 12 +- .../kernel/arm/fp32/layer_norm_fp32.cc | 4 +- .../arm/fp32/local_response_norm_fp32.cc | 4 +- .../kernel/arm/fp32/log_softmax_fp32.cc | 4 +- .../kernel/arm/fp32/lsh_projection_fp32.cc | 4 +- .../kernel/arm/fp32/matmul_fp32_base.cc | 4 +- .../runtime/kernel/arm/fp32/one_hot_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/pad_fp32.cc | 8 +- .../runtime/kernel/arm/fp32/pooling_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/power_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/prelu_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/reduce_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/resize_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/reverse_fp32.cc | 4 +- .../kernel/arm/fp32/roi_pooling_fp32.cc | 4 +- .../src/runtime/kernel/arm/fp32/scale_fp32.cc | 4 +- .../kernel/arm/fp32/scatter_nd_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/softmax_fp32.cc | 4 +- .../kernel/arm/fp32/space_to_batch_fp32.cc | 4 +- .../kernel/arm/fp32/space_to_depth_fp32.cc | 4 +- .../kernel/arm/fp32/sparse_to_dense_fp32.cc | 4 +- .../runtime/kernel/arm/fp32/transpose_fp32.cc | 8 +- .../src/runtime/kernel/arm/fp32/where_fp32.cc | 4 +- .../kernel/arm/fp32_grad/activation_grad.cc | 4 +- .../src/runtime/kernel/arm/fp32_grad/adam.cc | 2 +- .../kernel/arm/fp32_grad/apply_momentum.cc | 4 +- .../kernel/arm/fp32_grad/arithmetic_grad.cc | 2 +- .../arm/fp32_grad/arithmetic_self_grad.cc | 4 +- .../runtime/kernel/arm/fp32_grad/assign.cc | 4 +- .../runtime/kernel/arm/fp32_grad/bias_grad.cc | 2 +- .../runtime/kernel/arm/fp32_grad/bn_grad.cc | 8 +- .../kernel/arm/fp32_grad/convolution.cc | 2 +- .../arm/fp32_grad/convolution_grad_filter.cc | 4 +- .../arm/fp32_grad/convolution_grad_input.cc | 4 +- .../fp32_grad/deconvolution_grad_filter.cc | 4 +- .../runtime/kernel/arm/fp32_grad/dropout.cc | 4 +- .../kernel/arm/fp32_grad/dropout_grad.cc | 4 +- .../kernel/arm/fp32_grad/layernorm_grad.cc | 2 +- .../runtime/kernel/arm/fp32_grad/neg_grad.cc | 4 +- .../kernel/arm/fp32_grad/pooling_grad.cc | 4 +- .../kernel/arm/fp32_grad/power_grad.cc | 4 +- .../kernel/arm/fp32_grad/resize_grad.cc | 2 +- .../src/runtime/kernel/arm/fp32_grad/sgd.cc | 8 +- .../sigmoid_cross_entropy_with_logits.cc | 4 +- .../sigmoid_cross_entropy_with_logits_grad.cc | 4 +- .../kernel/arm/fp32_grad/smooth_l1_loss.cc | 4 +- .../arm/fp32_grad/smooth_l1_loss_grad.cc | 4 +- .../softmax_cross_entropy_with_logits.cc | 4 +- .../kernel/arm/fp32_grad/softmax_grad.cc | 2 +- ...parse_softmax_cross_entropy_with_logits.cc | 4 +- .../arm/fp32_grad/strided_slice_grad.cc | 4 +- .../arm/fp32_grad/unsorted_segment_sum.cc | 4 +- .../src/runtime/kernel/arm/int8/add_int8.cc | 4 +- .../kernel/arm/int8/arithmetic_int8.cc | 4 +- .../kernel/arm/int8/arithmetic_self_int8.cc | 4 +- .../runtime/kernel/arm/int8/batchnorm_int8.cc | 4 +- .../runtime/kernel/arm/int8/concat_int8.cc | 4 +- .../kernel/arm/int8/convolution_1x1_int8.cc | 12 +- .../kernel/arm/int8/convolution_3x3_int8.cc | 4 +- .../int8/convolution_depthwise_3x3_int8.cc | 4 +- .../arm/int8/convolution_depthwise_int8.cc | 4 +- .../convolution_depthwise_slidewindow_int8.cc | 4 +- .../kernel/arm/int8/convolution_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/crop_int8.cc | 4 +- .../arm/int8/deconvolution_depthwise_int8.cc | 4 +- .../kernel/arm/int8/deconvolution_int8.cc | 4 +- .../arm/int8/detection_post_process_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/div_int8.cc | 4 +- .../runtime/kernel/arm/int8/gatherNd_int8.cc | 4 +- .../runtime/kernel/arm/int8/gather_int8.cc | 4 +- .../runtime/kernel/arm/int8/hswish_int8.cc | 4 +- .../runtime/kernel/arm/int8/l2_norm_int8.cc | 4 +- .../kernel/arm/int8/layer_norm_int8.cc | 4 +- .../kernel/arm/int8/leaky_relu_int8.cc | 4 +- .../kernel/arm/int8/matmul_base_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/mul_int8.cc | 12 +- .../src/runtime/kernel/arm/int8/pad_int8.cc | 8 +- .../runtime/kernel/arm/int8/pooling_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/power_int8.cc | 4 +- .../runtime/kernel/arm/int8/reduce_int8.cc | 12 +- .../src/runtime/kernel/arm/int8/relux_int8.cc | 4 +- .../runtime/kernel/arm/int8/reshape_int8.cc | 4 +- .../runtime/kernel/arm/int8/resize_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/scale_int8.cc | 8 +- .../runtime/kernel/arm/int8/sigmoid_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/slice_int8.cc | 4 +- .../runtime/kernel/arm/int8/softmax_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/split_int8.cc | 4 +- .../runtime/kernel/arm/int8/squeeze_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/sub_int8.cc | 4 +- .../src/runtime/kernel/arm/int8/tanh_int8.cc | 4 +- .../runtime/kernel/arm/int8/transpose_int8.cc | 4 +- .../runtime/kernel/arm/int8/unsqueeze_int8.cc | 4 +- .../lite/src/runtime/parallel_executor.cc | 6 +- .../lite/src/runtime/parallel_executor.h | 3 +- mindspore/lite/src/runtime/runtime_api.cc | 2 - mindspore/lite/src/runtime/runtime_api.h | 3 - mindspore/lite/src/runtime/thread_pool.c | 962 ------------------ mindspore/lite/src/runtime/thread_pool.h | 74 -- mindspore/lite/test/CMakeLists.txt | 5 +- .../arm/fp32/constant_of_shape_fp32_test.cc | 1 + .../runtime/kernel/arm/fp32/crop_fp32_test.cc | 1 + .../arm/fp32/deconvolution_fp32_tests.cc | 4 + .../arm/fp32/detection_post_process_test.cc | 1 + .../runtime/kernel/arm/fp32/elu_fp32_test.cc | 1 + .../arm/fp32/fullconnection_fp32_tests.cc | 3 + .../kernel/arm/fp32/matmul_fp32_tests.cc | 5 + .../kernel/arm/fp32/power_fp32_tests.cc | 2 + .../runtime/kernel/arm/fp32/skip_gram_fp32.cc | 1 + .../kernel/arm/int8/conv_1x1_int8_tests.cc | 3 + .../kernel/arm/int8/deconv_int8_tests.cc | 1 + .../kernel/arm/int8/matmul_int8_tests.cc | 1 + mindspore/lite/tools/converter/CMakeLists.txt | 9 +- tests/ut/cpp/CMakeLists.txt | 1 + 213 files changed, 587 insertions(+), 1718 deletions(-) delete mode 100644 mindspore/core/mindrt/src/actor/actorthread.cc delete mode 100644 mindspore/core/mindrt/src/actor/actorthread.h delete mode 100644 mindspore/lite/src/runtime/thread_pool.c delete mode 100644 mindspore/lite/src/runtime/thread_pool.h diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index c52b6e8b4f..72e1fb1491 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -3,6 +3,7 @@ include_directories(${CMAKE_SOURCE_DIR}/mindspore/core) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/include) +include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/src) if(ENABLE_CPU) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/backend/kernel_compiler/cpu) diff --git a/mindspore/ccsrc/runtime/framework/graph_scheduler.cc b/mindspore/ccsrc/runtime/framework/graph_scheduler.cc index e28d8796e9..edd0f58afa 100644 --- a/mindspore/ccsrc/runtime/framework/graph_scheduler.cc +++ b/mindspore/ccsrc/runtime/framework/graph_scheduler.cc @@ -312,6 +312,8 @@ GraphScheduler::~GraphScheduler() { // Local maps clear. actor_name_to_actor_.clear(); graph_output_to_actor_.clear(); + delete thread_pool_; + thread_pool_ = nullptr; } void GraphScheduler::Initialize() { @@ -326,11 +328,13 @@ void GraphScheduler::Initialize() { auto actorMgr = ActorMgr::GetActorMgrRef(); MS_EXCEPTION_IF_NULL(actorMgr); + actorMgr->Initialize(); // Create the thread pool of actor runtime. auto max_thread_num = GetMaxThreadNum(); MS_LOG(INFO) << "Max available thread number: " << max_thread_num; - actorMgr->Initialize(max_thread_num); + thread_pool_ = InterThreadPool::CreateThreadPool(max_thread_num); + MS_EXCEPTION_IF_NULL(thread_pool_); // Create memory manager actor. auto memory_manager_actor = std::make_shared(); @@ -338,6 +342,7 @@ void GraphScheduler::Initialize() { memory_manager_aid_ = memory_manager_actor->GetAID(); // Schedule memory manager actor, bind single thread to response to memory alloc and free quickly. auto base_actor = static_cast(memory_manager_actor); + base_actor->set_thread_pool(thread_pool_); (void)actorMgr->Spawn(base_actor, false); } @@ -400,6 +405,7 @@ void GraphScheduler::Schedule(const ActorSet *actor_set) { auto actorMgr = ActorMgr::GetActorMgrRef(); MS_EXCEPTION_IF_NULL(actorMgr); for (auto actor : actors) { + actor->set_thread_pool(thread_pool_); (void)actorMgr->Spawn(actor); } } diff --git a/mindspore/ccsrc/runtime/framework/graph_scheduler.h b/mindspore/ccsrc/runtime/framework/graph_scheduler.h index df1353d30f..c29723121b 100644 --- a/mindspore/ccsrc/runtime/framework/graph_scheduler.h +++ b/mindspore/ccsrc/runtime/framework/graph_scheduler.h @@ -33,6 +33,7 @@ #include "runtime/framework/actor/copy_actor.h" #include "runtime/hardware/device_context.h" #include "backend/session/kernel_graph.h" +#include "thread/inter_threadpool.h" namespace mindspore { namespace runtime { @@ -242,6 +243,8 @@ class GraphScheduler { // The id of memory manager actor. AID memory_manager_aid_; + InterThreadPool *thread_pool_{nullptr}; + bool init_{false}; }; } // namespace runtime diff --git a/mindspore/ccsrc/vm/CMakeLists.txt b/mindspore/ccsrc/vm/CMakeLists.txt index 600a589df2..45c9cef795 100644 --- a/mindspore/ccsrc/vm/CMakeLists.txt +++ b/mindspore/ccsrc/vm/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/include) +include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/src) file(GLOB_RECURSE _VM_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") set_property(SOURCE ${_VM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_VM) diff --git a/mindspore/core/mindrt/CMakeLists.txt b/mindspore/core/mindrt/CMakeLists.txt index d9d65178e8..1a966e89ee 100644 --- a/mindspore/core/mindrt/CMakeLists.txt +++ b/mindspore/core/mindrt/CMakeLists.txt @@ -8,6 +8,7 @@ file(GLOB MINDRT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/async/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/evloop/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/timer/*.cc + ${CMAKE_CURRENT_SOURCE_DIR}/src/thread/*.cc ) add_library(mindrt_mid OBJECT ${MINDRT_SRC}) diff --git a/mindspore/core/mindrt/include/actor/actor.h b/mindspore/core/mindrt/include/actor/actor.h index 5154749dec..b4c5617d0e 100644 --- a/mindspore/core/mindrt/include/actor/actor.h +++ b/mindspore/core/mindrt/include/actor/actor.h @@ -31,6 +31,7 @@ namespace mindspore { class ActorBase; class ActorMgr; class ActorPolicy; +class InterThreadPool; using ActorReference = std::shared_ptr; @@ -78,6 +79,8 @@ class ActorBase { // delete the send/receive message package size void DelRuleUdp(const std::string &peer, bool outputLog); + void set_thread_pool(InterThreadPool *pool) { pool_ = pool; } + protected: using ActorFunction = std::function &msg)>; @@ -146,7 +149,7 @@ class ActorBase { private: friend class ActorMgr; - friend class ActorThread; + friend class InterThreadPool; // KMSG Msg Handler virtual void HandlekMsg(const std::unique_ptr &msg); @@ -194,6 +197,7 @@ class ActorBase { void SetRunningStatus(bool start); std::unique_ptr actorThread; + InterThreadPool *pool_{nullptr}; AID id; std::map actionFunctions; diff --git a/mindspore/core/mindrt/include/mindrt.hpp b/mindspore/core/mindrt/include/mindrt.hpp index beadd092d8..45513075e7 100644 --- a/mindspore/core/mindrt/include/mindrt.hpp +++ b/mindspore/core/mindrt/include/mindrt.hpp @@ -33,9 +33,6 @@ struct MindrtAddress { int Initialize(const std::string &tcpUrl, const std::string &tcpUrlAdv = "", const std::string &udpUrl = "", const std::string &udpUrlAdv = "", int threadCount = 0); -// brief terminate the threads for current session -void TerminateCurThreads(int threadCount = 0); - // brief spawn a process to run an actor AID Spawn(ActorReference actor, bool sharedThread = true, bool start = true); diff --git a/mindspore/core/mindrt/src/actor/actormgr.cc b/mindspore/core/mindrt/src/actor/actormgr.cc index 576a232c31..3446999684 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.cc +++ b/mindspore/core/mindrt/src/actor/actormgr.cc @@ -98,16 +98,11 @@ void ActorMgr::TerminateAll() { } } -void ActorMgr::Initialize(int threadCount) { threadPool.AddThread(threadCount); } - -void ActorMgr::TerminateCurThreads(int threadCount) { threadPool.TerminateThread(threadCount); } - void ActorMgr::Finalize() { this->TerminateAll(); MS_LOG(INFO) << "mindrt Actors finish exiting."; // stop all actor threads; - threadPool.Finalize(); MS_LOG(INFO) << "mindrt Threads finish exiting."; // stop iomgr thread @@ -115,7 +110,6 @@ void ActorMgr::Finalize() { MS_LOG(INFO) << "finalize IOMgr=" << mgrIt->first.c_str(); mgrIt->second->Finish(); } - MS_LOG(INFO) << "mindrt IOMGRS finish exiting."; } diff --git a/mindspore/core/mindrt/src/actor/actormgr.h b/mindspore/core/mindrt/src/actor/actormgr.h index 255ecf851b..1d38224220 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.h +++ b/mindspore/core/mindrt/src/actor/actormgr.h @@ -23,7 +23,8 @@ #include #include -#include "actor/actorthread.h" +#include "actor/actor.h" +#include "thread/inter_threadpool.h" namespace mindspore { @@ -47,8 +48,7 @@ class ActorMgr { ~ActorMgr(); void Finalize(); - void Initialize(int threadCount); - void TerminateCurThreads(int threadCount); + void Initialize() {} void RemoveActor(const std::string &name); ActorReference GetActor(const AID &id); const std::string GetUrl(const std::string &protocol = "tcp"); @@ -62,7 +62,14 @@ class ActorMgr { inline const std::string &GetDelegate() const { return delegate; } inline void SetDelegate(const std::string &d) { delegate = d; } - inline void SetActorReady(const std::shared_ptr &actor) { threadPool.EnqueReadyActor(actor); } + inline void SetActorReady(const std::shared_ptr &actor) const { + auto pool = actor->pool_; + if (pool == nullptr) { + MS_LOG(ERROR) << "ThreadPOol is nullptr, actor: " << actor->GetAID().Name(); + return; + } + pool->EnqueReadyActor(actor); + } void SetActorStatus(const AID &pid, bool start); private: @@ -77,8 +84,6 @@ class ActorMgr { std::map actors; std::mutex actorsMutex; - ActorThread threadPool; - std::map procotols; std::set urls; std::string delegate; diff --git a/mindspore/core/mindrt/src/actor/actorthread.cc b/mindspore/core/mindrt/src/actor/actorthread.cc deleted file mode 100644 index c65de7a0ed..0000000000 --- a/mindspore/core/mindrt/src/actor/actorthread.cc +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "actor/actorthread.h" -#ifdef __WIN32__ -#include -#else -#include -#endif -#include -#include -#include - -namespace mindspore { -constexpr int MAXTHREADNAMELEN = 12; - -size_t GetMaxThreadCount() { - size_t max_num; -#ifdef __WIN32__ - SYSTEM_INFO sys_info; - GetSystemInfo(&sys_info); - max_num = sys_info.dwNumberOfProcessors; -#else - max_num = sysconf(_SC_NPROCESSORS_ONLN); -#endif - return max_num; -} - -ActorThread::ActorThread() : readyActors(), workers() { - readyActors.clear(); - workers.clear(); - - char *envThreadName = getenv("MINDRT_THREAD_NAME"); - if (envThreadName != nullptr) { - threadName = envThreadName; - if (threadName.size() > MAXTHREADNAMELEN) { - threadName.resize(MAXTHREADNAMELEN); - } - } else { - threadName = "MINDRT_ACT"; - } - - maxThreads_ = GetMaxThreadCount(); -} - -ActorThread::~ActorThread() {} -void ActorThread::AddThread(int threadCount) { - std::unique_lock lock(initLock_); - int threadsNeed = threadCount - (workers.size() - threadsInUse_); - for (int i = 0; i < threadsNeed; ++i) { - if (workers.size() >= maxThreads_) { - MS_LOG(DEBUG) << "threads number in mindrt reach upper limit. maxThreads:" << maxThreads_; - break; - } - std::unique_ptr worker(new (std::nothrow) std::thread(&ActorThread::Run, this)); - MINDRT_OOM_EXIT(worker) - - workers.push_back(std::move(worker)); - threadsInUse_ += 1; - } -} - -void ActorThread::TerminateThread(int threadCount) { - // temp scheme, not actually terminate the threads when current session destructs - threadsInUse_ -= threadCount; -} - -void ActorThread::Finalize() { - MS_LOG(INFO) << "Actor's threads are exiting."; - // terminate all thread; enqueue nullptr actor to terminate; - std::shared_ptr exitActor(nullptr); - for (auto it = workers.begin(); it != workers.end(); ++it) { - EnqueReadyActor(exitActor); - } - // wait all thread to exit - for (auto it = workers.begin(); it != workers.end(); ++it) { - std::unique_ptr &worker = *it; - if (worker->joinable()) { - worker->join(); - } - } - workers.clear(); - MS_LOG(INFO) << "Actor's threads finish exiting."; -} - -void ActorThread::DequeReadyActor(std::shared_ptr &actor) { - std::unique_lock lock(readyActorMutex); - conditionVar.wait(lock, [this] { return (this->readyActors.size() > 0); }); - actor = readyActors.front(); - readyActors.pop_front(); -} - -void ActorThread::EnqueReadyActor(const std::shared_ptr &actor) { - { - std::lock_guard lock(readyActorMutex); - readyActors.push_back(actor); - } - conditionVar.notify_one(); -} - -void ActorThread::Run() { -#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12 - static std::atomic actorCount(1); - int ret = pthread_setname_np(pthread_self(), (threadName + std::to_string(actorCount.fetch_add(1))).c_str()); - if (0 != ret) { - MS_LOG(INFO) << "set pthread name fail]ret:" << ret; - } else { - MS_LOG(INFO) << "set pthread name success]threadID:" << pthread_self(); - } -#endif - - bool terminate = false; - do { - std::shared_ptr actor; - DequeReadyActor(actor); - if (actor != nullptr) { - actor->Run(); - } else { - terminate = true; - MS_LOG(DEBUG) << "Actor this Threads have finished exiting."; - } - } while (!terminate); -} - -}; // end of namespace mindspore diff --git a/mindspore/core/mindrt/src/actor/actorthread.h b/mindspore/core/mindrt/src/actor/actorthread.h deleted file mode 100644 index 9c3cd4d406..0000000000 --- a/mindspore/core/mindrt/src/actor/actorthread.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_CORE_MINDRT_SRC_ACTOR_ACTORTHREAD_H -#define MINDSPORE_CORE_MINDRT_SRC_ACTOR_ACTORTHREAD_H - -#include -#include -#include -#include -#include - -#include "actor/actor.h" - -namespace mindspore { - -class ActorThread { - public: - ActorThread(); - ~ActorThread(); - void Finalize(); - void AddThread(int threadCount); - void TerminateThread(int threadCount); - void EnqueReadyActor(const std::shared_ptr &actor); - - private: - void Run(); - void DequeReadyActor(std::shared_ptr &actor); - - std::list> readyActors; - std::mutex readyActorMutex; - std::condition_variable conditionVar; - - std::list> workers; - std::string threadName; - - size_t threadsInUse_ = 0; - size_t maxThreads_; - std::mutex initLock_; -}; - -}; // end of namespace mindspore -#endif diff --git a/mindspore/core/mindrt/src/mindrt.cc b/mindspore/core/mindrt/src/mindrt.cc index 1077bdcae7..86cd98a75e 100644 --- a/mindspore/core/mindrt/src/mindrt.cc +++ b/mindspore/core/mindrt/src/mindrt.cc @@ -57,10 +57,6 @@ const MindrtAddress &GetMindrtAddress() { return *local::g_mindrtAddress; } -void SetThreadCount(int threadCount) { ActorMgr::GetActorMgrRef()->Initialize(threadCount); } - -void TerminateCurThreads(int threadCount) { ActorMgr::GetActorMgrRef()->TerminateCurThreads(threadCount); } - class MindrtExit { public: MindrtExit() { MS_LOG(DEBUG) << "trace: enter MindrtExit()---------"; } @@ -73,10 +69,7 @@ class MindrtExit { int InitializeImp(const std::string &tcpUrl, const std::string &tcpUrlAdv, const std::string &udpUrl, const std::string &udpUrlAdv, int threadCount) { MS_LOG(DEBUG) << "mindrt starts ......"; - - // start actor's thread - SetThreadCount(threadCount); - + ActorMgr::GetActorMgrRef()->Initialize(); MS_LOG(DEBUG) << "mindrt has started."; return MINDRT_OK; } diff --git a/mindspore/core/mindrt/src/thread/core_affinity.cc b/mindspore/core/mindrt/src/thread/core_affinity.cc index 6dba3e5fba..320f86e81c 100644 --- a/mindspore/core/mindrt/src/thread/core_affinity.cc +++ b/mindspore/core/mindrt/src/thread/core_affinity.cc @@ -19,9 +19,6 @@ #include #include #include -#ifdef __ANDROID__ -#include -#endif #ifdef MS_COMPILE_IOS #include #include @@ -29,7 +26,6 @@ #endif // MS_COMPILE_IOS #include "thread/threadpool.h" -#ifdef BIND_CORE namespace mindspore { #define MAX_PATH_SIZE (256) @@ -240,6 +236,8 @@ int CoreAffinity::SortCPUProcessors() { } } } + higher_num_ = 0; + sorted_id_.clear(); int max_freq = freq_set.front().max_freq; for (const auto &info : freq_set) { THREAD_INFO("sorted core id: %d, max frequency: %d, arch: %d", info.core_id, info.max_freq, info.arch); @@ -274,14 +272,15 @@ int CoreAffinity::InitBindCoreId(size_t thread_num, BindMode bind_mode) { return THREAD_OK; } -int CoreAffinity::SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) const { +#ifdef BIND_CORE +int CoreAffinity::SetAffinity(const pthread_t &thread_id, cpu_set_t *cpu_set) const { #ifdef __ANDROID__ #if __ANDROID_API__ >= 21 - THREAD_INFO("thread: %d, mask: %lu", pthread_gettid_np(thread_id), cpuSet->__bits[0]); - int ret = sched_setaffinity(pthread_gettid_np(thread_id), sizeof(cpu_set_t), cpuSet); + THREAD_INFO("thread: %d, mask: %lu", pthread_gettid_np(thread_id), cpu_set->__bits[0]); + int ret = sched_setaffinity(pthread_gettid_np(thread_id), sizeof(cpu_set_t), cpu_set); if (ret != THREAD_OK) { THREAD_ERROR("bind thread %d to cpu failed. ERROR %d", pthread_gettid_np(thread_id), ret); - return THREAD_OK; + return THREAD_ERROR; } #endif #else @@ -289,7 +288,7 @@ int CoreAffinity::SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) const { THREAD_ERROR("not bind thread to apple's cpu."); return THREAD_ERROR; #else - int ret = pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), cpuSet); + int ret = pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), cpu_set); if (ret != THREAD_OK) { THREAD_ERROR("set thread: %lu to cpu failed", thread_id); return THREAD_ERROR; @@ -298,8 +297,10 @@ int CoreAffinity::SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) const { #endif return THREAD_OK; } +#endif // BIND_CORE int CoreAffinity::FreeScheduleThreads(const std::vector &workers) const { +#ifdef BIND_CORE if (thread_num_ != workers.size()) { return THREAD_ERROR; } @@ -315,11 +316,13 @@ int CoreAffinity::FreeScheduleThreads(const std::vector &workers) cons return THREAD_ERROR; } } +#endif // BIND_CORE return THREAD_OK; } int CoreAffinity::BindThreadsToCoreList(const std::vector &workers) const { - if (bind_id_.size() != thread_num_) { +#ifdef BIND_CORE + if (thread_num_ != workers.size()) { THREAD_ERROR("invalid core list"); return THREAD_ERROR; } @@ -330,14 +333,32 @@ int CoreAffinity::BindThreadsToCoreList(const std::vector &workers) co // affinity mask determines the CPU core which it is eligible to run int ret = SetAffinity(workers[i]->thread.native_handle(), &mask); if (ret != THREAD_OK) { - THREAD_ERROR("set thread[%zu] affinity failed", i); + THREAD_ERROR("set thread[%zu] affinity to core[%d] failed", i, bind_id_[i]); return THREAD_ERROR; } - THREAD_INFO("bind thread[%zu] success", i); + THREAD_ERROR("set thread[%zu] affinity to core[%d] success", i, bind_id_[i]); } +#endif // BIND_CORE return THREAD_OK; } +int CoreAffinity::BindProcess(BindMode bind_mode) const { +#ifdef BIND_CORE + cpu_set_t mask; + CPU_ZERO(&mask); + if (bind_mode != Power_NoBind) { + CPU_SET(bind_id_.front(), &mask); + } else { + for (int id : bind_id_) { + CPU_SET(id, &mask); + } + } + return SetAffinity(pthread_self(), &mask); +#else + return THREAD_OK; +#endif // BIND_CORE +} + int CoreAffinity::BindThreads(const std::vector &workers, BindMode bind_mode) const { if (bind_mode == Power_NoBind) { return FreeScheduleThreads(workers); @@ -351,5 +372,3 @@ int CoreAffinity::BindThreads(const std::vector &workers, const std::v return BindThreadsToCoreList(workers); } } // namespace mindspore - -#endif // BIND_CORE diff --git a/mindspore/core/mindrt/src/thread/core_affinity.h b/mindspore/core/mindrt/src/thread/core_affinity.h index 9ffac8b8b8..e101f15bee 100644 --- a/mindspore/core/mindrt/src/thread/core_affinity.h +++ b/mindspore/core/mindrt/src/thread/core_affinity.h @@ -18,28 +18,41 @@ #define MINDSPORE_CORE_MINDRT_RUNTIME_CORE_AFFINITY_H_ #include -#include "thread/threadpool.h" -#ifdef BIND_CORE +#include + +#ifdef __ANDROID__ +#define BIND_CORE +#include +#endif namespace mindspore { + +enum BindMode { + Power_NoBind = 0, // free schedule + Power_Higher = 1, + Power_Middle = 2, +}; + +struct Worker; class CoreAffinity { public: - static CoreAffinity *GetInstance() { - static CoreAffinity affinity; - return &affinity; - } + CoreAffinity() = default; + ~CoreAffinity() = default; + int InitBindCoreId(size_t thread_num, BindMode bind_mode); int BindThreads(const std::vector &workers, const std::vector &core_list); int BindThreads(const std::vector &workers, BindMode bind_mode) const; + int BindProcess(BindMode bind_mode) const; private: - CoreAffinity() = default; - ~CoreAffinity() = default; +#ifdef BIND_CORE + int SetAffinity(const pthread_t &thread_id, cpu_set_t *cpu_set) const; +#endif // BIND_CORE int BindThreadsToCoreList(const std::vector &workers) const; int FreeScheduleThreads(const std::vector &workers) const; - int SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) const; + int SortCPUProcessors(); // bind_id contains the CPU cores to bind @@ -52,7 +65,7 @@ class CoreAffinity { size_t higher_num_{0}; size_t thread_num_{0}; }; + } // namespace mindspore -#endif // BIND_CORE #endif // MINDSPORE_CORE_MINDRT_RUNTIME_CORE_AFFINITY_H_ diff --git a/mindspore/core/mindrt/src/thread/inter_threadpool.cc b/mindspore/core/mindrt/src/thread/inter_threadpool.cc index 707d41e947..0b28ee7311 100644 --- a/mindspore/core/mindrt/src/thread/inter_threadpool.cc +++ b/mindspore/core/mindrt/src/thread/inter_threadpool.cc @@ -20,6 +20,11 @@ namespace mindspore { InterThreadPool::~InterThreadPool() { + { + THREAD_INFO("wait util actor queue is empty"); + std::unique_lock _l(actor_mutex_); + finish_cond_var_.wait(_l, [this]() { return actor_queue_.empty(); }); + } exit_ = true; alive_ = false; actor_cond_var_.notify_all(); @@ -38,15 +43,12 @@ void InterThreadPool::ActorThreadRun() { actor_queue_.pop(); } actor->Run(); + finish_cond_var_.notify_one(); } -void InterThreadPool::ThreadAsyncRun(size_t thread_id) { - { - std::unique_lock _l(pool_mutex_); - start_cond_.wait(_l, [this]() { return workers_.size() == thread_num_; }); - } - Worker *worker = workers_[thread_id]; +void InterThreadPool::ThreadAsyncRun(Worker *worker) { THREAD_RETURN_IF_NULL(worker); + sem_post(&worker->init); while (alive_) { if (worker->type == kKernelThread) { KernelThreadRun(worker); @@ -78,7 +80,7 @@ InterThreadPool *InterThreadPool::CreateThreadPool(size_t inter_thread_num, size return nullptr; } #ifdef BIND_CORE - ret = CoreAffinity::GetInstance()->InitBindCoreId(thread_num, bind_mode); + ret = pool->InitAffinityInfo(bind_mode); if (ret != THREAD_OK) { delete pool; return nullptr; diff --git a/mindspore/core/mindrt/src/thread/inter_threadpool.h b/mindspore/core/mindrt/src/thread/inter_threadpool.h index ffe61aa8e1..843bd4d0c2 100644 --- a/mindspore/core/mindrt/src/thread/inter_threadpool.h +++ b/mindspore/core/mindrt/src/thread/inter_threadpool.h @@ -39,12 +39,13 @@ class InterThreadPool : public ThreadPool { private: explicit InterThreadPool(size_t inter_thread_num) { inter_thread_num_ = inter_thread_num; } - void ThreadAsyncRun(size_t thread_id) override; + void ThreadAsyncRun(Worker *worker) override; void ActorThreadRun(); std::mutex actor_mutex_; std::condition_variable actor_cond_var_; + std::condition_variable finish_cond_var_; std::queue actor_queue_; std::atomic_bool exit_{false}; diff --git a/mindspore/core/mindrt/src/thread/threadpool.cc b/mindspore/core/mindrt/src/thread/threadpool.cc index e6e1d6fabe..ab74795c07 100644 --- a/mindspore/core/mindrt/src/thread/threadpool.cc +++ b/mindspore/core/mindrt/src/thread/threadpool.cc @@ -24,12 +24,11 @@ namespace mindspore { constexpr int kDefaultSpinCount = 30000; ThreadPool::~ThreadPool() { - alive_ = false; + alive_.store(false); DestructThreads(); } void ThreadPool::DestructThreads() { - std::lock_guard lock(pool_mutex_); for (auto &worker : workers_) { sem_post(&worker->sem); if (worker->thread.joinable()) { @@ -39,12 +38,15 @@ void ThreadPool::DestructThreads() { delete worker; worker = nullptr; } - THREAD_INFO("deconstruct threads success"); workers_.clear(); + if (affinity_ != nullptr) { + delete affinity_; + affinity_ = nullptr; + } + THREAD_INFO("deconstruct threads success"); } int ThreadPool::CreateThreads(size_t thread_num) { - std::lock_guard lock(pool_mutex_); size_t core_num = std::thread::hardware_concurrency(); thread_num_ = std::min(thread_num, core_num); if (thread_num_ <= 0) { @@ -54,14 +56,17 @@ int ThreadPool::CreateThreads(size_t thread_num) { for (size_t i = 0; i < thread_num_; ++i) { Worker *worker = new (std::nothrow) Worker(); THREAD_ERROR_IF_NULL(worker); - worker->type = i < inter_thread_num_ ? kActorThread : kKernelThread; - worker->thread = std::thread(&ThreadPool::ThreadAsyncRun, this, i); sem_init(&worker->sem, 0, 0); + sem_init(&worker->init, 0, 0); + worker->type = i < inter_thread_num_ ? kActorThread : kKernelThread; + if (worker->type == kKernelThread) { + freelist_.push_back(worker); + } + worker->thread = std::thread(&ThreadPool::ThreadAsyncRun, this, worker); + sem_wait(&worker->init); workers_.push_back(worker); THREAD_INFO("create thread[%zu]", i); } - freelist_.insert(freelist_.begin(), workers_.begin() + inter_thread_num_, workers_.end()); - start_cond_.notify_all(); return THREAD_OK; } @@ -89,20 +94,16 @@ void ThreadPool::KernelThreadRun(Worker *worker) { } } -void ThreadPool::ThreadAsyncRun(size_t thread_id) { - { - // wait for all threads to be created - std::unique_lock _l(pool_mutex_); - start_cond_.wait(_l, [this]() { return workers_.size() == thread_num_; }); - } - Worker *worker = workers_[thread_id]; +void ThreadPool::ThreadAsyncRun(Worker *worker) { THREAD_RETURN_IF_NULL(worker); + sem_post(&worker->init); while (alive_) { KernelThreadRun(worker); } } int ThreadPool::ParallelLaunch(const Func &func, Contend contend, int task_num) { + THREAD_INFO("parallel launch, task num: %d", task_num); // distribute task to the KernelThread and the free ActorThread, // if the task num is greater than the KernelThread num Task task = Task(func, contend); @@ -136,12 +137,25 @@ void ThreadPool::DistributeTask(Task *task, int task_num) { } } +int ThreadPool::InitAffinityInfo(BindMode bind_mode) { + affinity_ = new (std::nothrow) CoreAffinity(); + THREAD_ERROR_IF_NULL(affinity_); + int ret = affinity_->InitBindCoreId(thread_num_, bind_mode); + if (ret != THREAD_OK) { + delete affinity_; + affinity_ = nullptr; + return THREAD_ERROR; + } + return THREAD_OK; +} + int ThreadPool::SetCpuAffinity(BindMode bind_mode) { if (workers_.empty()) { return THREAD_ERROR; } #ifdef BIND_CORE - return CoreAffinity::GetInstance()->BindThreads(workers_, bind_mode); + THREAD_ERROR_IF_NULL(affinity_); + return affinity_->BindThreads(workers_, bind_mode); #else return THREAD_OK; #endif // BIND_CORE @@ -152,7 +166,17 @@ int ThreadPool::SetCpuAffinity(const std::vector &core_list) { return THREAD_ERROR; } #ifdef BIND_CORE - return CoreAffinity::GetInstance()->BindThreads(workers_, core_list); + THREAD_ERROR_IF_NULL(affinity_); + return affinity_->BindThreads(workers_, core_list); +#else + return THREAD_OK; +#endif // BIND_CORE +} + +int ThreadPool::SetProcessAffinity(BindMode bind_mode) const { +#ifdef BIND_CORE + THREAD_ERROR_IF_NULL(affinity_); + return affinity_->BindProcess(bind_mode); #else return THREAD_OK; #endif // BIND_CORE @@ -169,7 +193,7 @@ ThreadPool *ThreadPool::CreateThreadPool(size_t thread_num, BindMode bind_mode) return nullptr; } #ifdef BIND_CORE - ret = CoreAffinity::GetInstance()->InitBindCoreId(thread_num, bind_mode); + ret = pool->InitAffinityInfo(bind_mode); if (ret != THREAD_OK) { delete pool; return nullptr; diff --git a/mindspore/core/mindrt/src/thread/threadpool.h b/mindspore/core/mindrt/src/thread/threadpool.h index 92a577dab2..15ca2ce87d 100644 --- a/mindspore/core/mindrt/src/thread/threadpool.h +++ b/mindspore/core/mindrt/src/thread/threadpool.h @@ -25,10 +25,7 @@ #include #include #include - -#ifdef __ANDROID__ -#define BIND_CORE -#endif +#include "thread/core_affinity.h" namespace mindspore { @@ -60,12 +57,6 @@ namespace mindspore { enum ThreadRet { THREAD_OK = 0, THREAD_ERROR = 1 }; enum ThreadType { kActorThread = 0, kKernelThread = 1 }; -enum BindMode { - Power_NoBind = 0, // free schedule - Power_Higher = 1, - Power_Middle = 2, -}; - using Func = int (*)(void *arg, int); using Contend = void *; @@ -83,6 +74,7 @@ typedef struct Worker { std::atomic_int type{kActorThread}; Task *task{nullptr}; sem_t sem; + sem_t init; int spin{0}; } Worker; @@ -96,6 +88,8 @@ class ThreadPool { int SetCpuAffinity(const std::vector &core_list); int SetCpuAffinity(BindMode bind_mode); + int SetProcessAffinity(BindMode bind_mode) const; + int ParallelLaunch(const Func &func, Contend contend, int task_num); protected: @@ -104,13 +98,14 @@ class ThreadPool { int CreateThreads(size_t thread_num); void DestructThreads(); - virtual void ThreadAsyncRun(size_t thread_id); + int InitAffinityInfo(BindMode bind_mode); + + virtual void ThreadAsyncRun(Worker *worker); void KernelThreadRun(Worker *worker); void DistributeTask(Task *task, int task_num); std::mutex pool_mutex_; - std::condition_variable start_cond_; std::vector workers_; std::vector freelist_; @@ -118,6 +113,8 @@ class ThreadPool { size_t inter_thread_num_{0}; size_t thread_num_{1}; + + CoreAffinity *affinity_{nullptr}; }; } // namespace mindspore diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 005b837840..f8a86bdb06 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -130,10 +130,6 @@ if(ENABLE_CONVERTER OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL include(${TOP_DIR}/cmake/external_libs/json.cmake) endif() -if(SUPPORT_TRAIN OR WIN32) - set(ENABLE_MINDRT "off") -endif() - if(DEFINED ARCHS) add_definitions(-DMS_COMPILE_IOS) endif() @@ -210,6 +206,7 @@ endif() if(ENABLE_MINDRT) include_directories(${CORE_DIR}/mindrt/include) + include_directories(${CORE_DIR}/mindrt/src) endif() if(NOT WIN32 AND NOT APPLE) diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index e2d41cdbab..4bbbfa847e 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -54,7 +54,6 @@ set(LITE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/quant_utils.cc ${CMAKE_CURRENT_SOURCE_DIR}/runtime/allocator.cc ${CMAKE_CURRENT_SOURCE_DIR}/runtime/runtime_api.cc - ${CMAKE_CURRENT_SOURCE_DIR}/runtime/thread_pool.c ${CMAKE_CURRENT_SOURCE_DIR}/runtime/infer_manager.cc ${CMAKE_CURRENT_SOURCE_DIR}/tensor.cc ${CMAKE_CURRENT_SOURCE_DIR}/ms_tensor.cc diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index 52ec4bbaa5..35d463f0d0 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -23,8 +23,12 @@ namespace mindspore::lite { int Executor::Run(const std::vector &in_tensors, const std::vector &out_tensors, const std::vector &kernels, mindspore::Allocator *allocator, const KernelCallBack &before, const KernelCallBack &after) { + InterThreadPool *thread_pool = ctx_->thread_pool_; + if (thread_pool == nullptr) { + return RET_ERROR; + } CpuBindMode cpu_bind_mode = ctx_->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_; - BindThreads(ctx_->thread_pool_, true, cpu_bind_mode); + thread_pool->SetCpuAffinity(static_cast(cpu_bind_mode)); MS_ASSERT(nullptr != allocator); auto ret = CheckTensorsInvalid(in_tensors); @@ -59,8 +63,7 @@ int Executor::Run(const std::vector &in_tensors, const std::vectorthread_pool_, false, cpu_bind_mode); + thread_pool->SetCpuAffinity(static_cast(NO_BIND)); return RET_OK; } } // namespace mindspore::lite diff --git a/mindspore/lite/src/inner_context.cc b/mindspore/lite/src/inner_context.cc index ad5f48ff0c..3a18d36212 100644 --- a/mindspore/lite/src/inner_context.cc +++ b/mindspore/lite/src/inner_context.cc @@ -72,9 +72,9 @@ int InnerContext::Init() { return RET_NOT_SUPPORT; } if (this->thread_pool_ == nullptr && this->IsCpuEnabled()) { - this->thread_pool_ = - CreateLiteThreadPool(this->thread_num_, this->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_); - if (this->thread_pool_ == nullptr) { + thread_pool_ = InterThreadPool::CreateThreadPool( + 1, this->thread_num_, static_cast(this->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_)); + if (thread_pool_ == nullptr) { MS_LOG(ERROR) << "Create ThreadPool failed"; return RET_NULL_PTR; } @@ -110,8 +110,7 @@ int InnerContext::Init() { InnerContext::~InnerContext() { if (this->thread_pool_ != nullptr) { - DestroyThreadPool(this->thread_pool_); - free(this->thread_pool_); + delete thread_pool_; this->thread_pool_ = nullptr; } #ifdef ENABLE_ARM diff --git a/mindspore/lite/src/inner_context.h b/mindspore/lite/src/inner_context.h index 0e9348b46b..cc3298207c 100644 --- a/mindspore/lite/src/inner_context.h +++ b/mindspore/lite/src/inner_context.h @@ -21,6 +21,7 @@ #include "include/context.h" #include "src/runtime/runtime_api.h" #include "src/runtime/allocator.h" +#include "thread/inter_threadpool.h" #ifdef ENABLE_ARM #include "src/cpu_info.h" #endif @@ -31,7 +32,7 @@ namespace mindspore::lite { struct InnerContext : public Context { public: - struct ThreadPool *thread_pool_ = nullptr; + InterThreadPool *thread_pool_{nullptr}; public: InnerContext() = default; diff --git a/mindspore/lite/src/lite_mindrt.cc b/mindspore/lite/src/lite_mindrt.cc index 41a4560955..8181c4b1c0 100644 --- a/mindspore/lite/src/lite_mindrt.cc +++ b/mindspore/lite/src/lite_mindrt.cc @@ -199,6 +199,11 @@ int LiteOpActor::PrepareOutputData() { std::vector> CreateOpActor(const std::vector &kernels) { std::vector> actors; std::unordered_map partial_map{}; + auto thread_pool = kernels[0]->Context()->thread_pool_; + if (thread_pool == nullptr) { + MS_LOG(ERROR) << "thread pool is nullptr"; + return actors; + } for (size_t i = 0; i < kernels.size(); ++i) { if ((kernel::LiteKernelUtil::IsSwitchCall(kernels[i]))) { auto switch_actor = std::make_shared(kernels[i]); @@ -207,6 +212,7 @@ std::vector> CreateOpActor(const std::vectorset_thread_pool(thread_pool); partial_map[i] = switch_actor->GetAID(); actors.push_back(switch_actor); } else { @@ -216,6 +222,7 @@ std::vector> CreateOpActor(const std::vectorset_thread_pool(thread_pool); partial_map[i] = actor->GetAID(); actors.push_back(actor); } @@ -423,7 +430,6 @@ void MindrtTerminate(const std::vector> &actor_list for (const auto &actor : actor_list) { mindspore::Terminate(actor->GetAID()); } - mindspore::TerminateCurThreads(1); } } // namespace mindspore::lite diff --git a/mindspore/lite/src/lite_mindrt.h b/mindspore/lite/src/lite_mindrt.h index 3b88505582..3c7e2daae7 100644 --- a/mindspore/lite/src/lite_mindrt.h +++ b/mindspore/lite/src/lite_mindrt.h @@ -47,8 +47,13 @@ class LiteOpActor : public OpActor { return; } + InterThreadPool *thread_pool = kernel_->Context()->thread_pool_; + if (thread_pool == nullptr) { + MS_LOG(ERROR) << "ThreadPool is nullptr, kernel: " << kernel_->name(); + return; + } CpuBindMode cpu_bind_mode = kernel_->Context()->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_; - BindThreads(static_cast(kernel_->Context())->thread_pool_, true, cpu_bind_mode); + thread_pool->SetCpuAffinity(static_cast(cpu_bind_mode)); int ret = CheckInputData(); if (ret != RET_OK) { @@ -78,7 +83,7 @@ class LiteOpActor : public OpActor { inputs_data_.clear(); AsyncOutput(context); - BindThreads(static_cast(kernel_->Context())->thread_pool_, false, cpu_bind_mode); + thread_pool->SetCpuAffinity(static_cast(NO_BIND)); SetOutputData(context); for (auto &input_data : inputs_data_) { diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index d63c75cd29..e630639ea4 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -570,11 +570,16 @@ int LiteSession::Init(const Context *context) { is_running_.store(false); return ret; } - BindThreads(context_->thread_pool_, true, - context_->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_); + CpuBindMode cpu_bind_mode = this->context_->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_; + InterThreadPool *thread_pool = this->context_->thread_pool_; + if (thread_pool == nullptr) { + MS_LOG(ERROR) << "thread pool is nullptr"; + is_running_.store(false); + return RET_NULL_PTR; + } + thread_pool->SetProcessAffinity(static_cast(cpu_bind_mode)); ret = InitGPURuntime(); - BindThreads(context_->thread_pool_, false, - context_->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_); + thread_pool->SetProcessAffinity(static_cast(NO_BIND)); if (ret != RET_OK) { MS_LOG(ERROR) << "Init GPU runtime failed."; is_running_.store(false); @@ -614,7 +619,6 @@ LiteSession::~LiteSession() { output_node_map_.clear(); output_tensor_map_.clear(); input_vec_.clear(); - delete this->context_; delete this->executor_; this->executor_ = nullptr; #if SUPPORT_NPU @@ -628,6 +632,8 @@ LiteSession::~LiteSession() { #if GPU_OPENCL delete opencl_runtime_wrapper_; #endif + delete this->context_; + this->context_ = nullptr; delete (model_); is_running_.store(false); } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc index 05a086532b..3fc95c0e95 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/constant_of_shape.cc @@ -73,8 +73,8 @@ int ConstantOfShapeCPUKernel::Run() { int thread_count = MSMIN(op_parameter_->thread_num_, param_->element_size_); thread_stride_ = UP_DIV(param_->element_size_, thread_count); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConstantOfShapeRun, - this, thread_count); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConstantOfShapeRun, this, thread_count); if (ret != RET_OK) { MS_LOG(ERROR) << "ConstantOfShapeRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc index bf7073f8cc..8fadc76140 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc @@ -236,8 +236,8 @@ int DetectionPostProcessBaseCPUKernel::Run() { return status; } } else { - status = ParallelLaunch(static_cast(this->context_)->thread_pool_, - NmsMultiClassesFastCoreRun, this, op_parameter_->thread_num_); + status = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(NmsMultiClassesFastCoreRun, this, op_parameter_->thread_num_); if (status != RET_OK) { MS_LOG(ERROR) << "NmsMultiClassesFastCoreRun error error_code[" << status << "]"; FreeAllocatedBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc index 927fd1919b..7a42a92aa4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc @@ -166,8 +166,8 @@ int RunPriorBox(void *cdata, int task_id) { } int PriorBoxCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, RunPriorBox, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(RunPriorBox, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "PriorBox run error, error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc index 7a01b0e637..758687cb65 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc @@ -172,8 +172,8 @@ int QuantDTypeCastCPUKernel::Run() { uint8_ptr_ = reinterpret_cast(out_tensors_[0]->data_c()); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, QuantDTypeCastRun, - this, thread_n_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(QuantDTypeCastRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; if (in_tensors_[0]->data_type() == TypeId::kNumberTypeInt8 && diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc index 33184bdb2e..0e86d34419 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc @@ -66,8 +66,8 @@ int ReshapeRun(void *cdata, int task_id) { int ReshapeBaseCPUKernel::Run() { input_ptr_ = reinterpret_cast(in_tensors_.at(kInputIndex)->data_c()); output_ptr_ = reinterpret_cast(out_tensors_.at(kOutputIndex)->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ReshapeRun, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReshapeRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Reshape run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc index b51d05cbed..e440ef42de 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc @@ -82,8 +82,8 @@ int SliceCPUKernel::Run() { lite::DataTypeSize(in_tensors_.at(0)->data_type())); return RET_OK; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SliceLaunch, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SliceLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "slice launch fail!ret: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc index b96e5aacb8..2273897a6d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc @@ -126,8 +126,8 @@ int SplitBaseCPUKernel::Run() { output_ptr_.at(i) = output_tensor->data_c(); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SplitRun, this, - thread_n_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SplitRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "split error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_with_over_lap_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/split_with_over_lap_base.cc index bfd310ae70..c886104292 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_with_over_lap_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_with_over_lap_base.cc @@ -118,8 +118,8 @@ int SplitWithOverlapBaseCPUKernel::Run() { inner_stride_ *= input_shape[i]; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SplitWithOverlapRun, - this, param_->num_split_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SplitWithOverlapRun, this, param_->num_split_); if (ret != RET_OK) { MS_LOG(ERROR) << "ParallelLaunch for SplitWIthOverlapRun run fail. errorcode:[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/stack_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/stack_base.cc index 46f599d1d2..70a789b1d2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/stack_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/stack_base.cc @@ -101,7 +101,7 @@ int StackBaseCPUKernel::Run() { // run stack num_threads_ = MSMIN(UP_DIV(outer_size_, 64), this->context_->thread_num_); auto ret = - ParallelLaunch(static_cast(this->context_)->thread_pool_, StackRun, this, num_threads_); + static_cast(this->context_)->thread_pool_->ParallelLaunch(StackRun, this, num_threads_); if (ret != RET_OK) { MS_LOG(ERROR) << "StackBaseCPUKernel Run error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc index ecfdd1a12f..b88643ec9c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc @@ -163,8 +163,8 @@ int StridedSliceCPUKernel::FastRun() { } input_ptr_ = reinterpret_cast(in_tensors_.front()->data_c()); output_ptr_ = reinterpret_cast(out_tensors_.front()->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, StrideRun, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(StrideRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Stride run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/tile_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/tile_base.cc index 6898bcffff..6b170a2e34 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/tile_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/tile_base.cc @@ -128,8 +128,8 @@ int TileCPUKernel::SimpleTileImpl(int task_id) { } int TileCPUKernel::RunSimpleTile() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SimpleTile, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SimpleTile, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunSimpleTile error code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc index 9640e51d87..d57778cb75 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc @@ -100,8 +100,8 @@ int ActivationFp16CPUKernel::Run() { fp16_input_ = reinterpret_cast(input_tensor->data_c()); fp16_output_ = reinterpret_cast(output_tensor->data_c()); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ActivationFp16Run, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ActivationFp16Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc index fbc393ac8f..36315c832d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc @@ -168,8 +168,8 @@ int ArithmeticCompareFP16CPUKernel::Run() { FreeTmpBuffer(); return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticsRunFp16, - this, context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticsRunFp16, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticsRunFp16 run error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc index 1089cda4f5..94a62b1c0e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc @@ -178,8 +178,8 @@ int ArithmeticFP16CPUKernel::Run() { FreeFp16Buffer(); return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticsRun, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticsRun, this, context_->thread_num_); if (out_tensors_.at(0)->data_type() == kNumberTypeFloat32) { Float16ToFloat32(static_cast(output_ptr_), reinterpret_cast(output_tensor->MutableData()), output_tensor->ElementsNum()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc index 50bb2893c8..26e35b7d84 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc @@ -83,8 +83,8 @@ int ArithmeticSelfFp16CPUKernel::Run() { } output_fp16_ptr_ = reinterpret_cast(output_tensor->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticSelfRun, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticSelfRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc index c5ca5e9cb6..929f65ea97 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc @@ -59,8 +59,8 @@ int BatchnormFp16CPUKernel::Run() { return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, BatchNormRun, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc index 5423222b97..6dfbbfc459 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc @@ -132,8 +132,8 @@ int CastFp16CPUKernel::Run() { if (data_num_ == 0) { return RET_OK; } - return ParallelLaunch(static_cast(this->context_)->thread_pool_, CastFp16Run, this, - op_parameter_->thread_num_); + return static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CastFp16Run, this, op_parameter_->thread_num_); } REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Cast, LiteKernelCreator) diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc index dc4aca22c4..dfef5affe1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc @@ -236,16 +236,16 @@ int Convolution1x1FP16CPUKernel::Run() { int ret = RET_ERROR; if (multi_thread_by_hw_) { - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution1x1Fp16RunHw, this, thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Fp16RunHw, this, thread_count_); } else { #ifdef ENABLE_ARM64 RowMajor2Col16MajorFp16Opt(input_ptr_, pack_input_, matmul_param_->row_, matmul_param_->deep_); #else RowMajor2Col12MajorFp16Opt(input_ptr_, pack_input_, matmul_param_->row_, matmul_param_->deep_); #endif - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution1x1Fp16RunOc, this, thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Fp16RunOc, this, thread_count_); } if (ret != RET_OK) { MS_LOG(ERROR) << "ParallelLaunch failed."; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc index f3ffa37a05..5bbeeb4c3a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc @@ -104,8 +104,8 @@ static int ConvDwFp16Run(void *cdata, int task_id) { } int ConvolutionDepthwiseFp16CPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwFp16Run, this, - conv_param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwFp16Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwFp16Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc index 0be1221ef9..f398a56c4f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc @@ -155,8 +155,8 @@ int ConvolutionDepthwiseSWFp16CPUKernel::Run() { packed_output_ = output_ptr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwSWFp16Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwSWFp16Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwSWFp16Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc index 49ebf8ab09..b2afbd7b6a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc @@ -144,8 +144,8 @@ int ConvolutionFP16CPUKernel::Run() { return RET_ERROR; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvolutionFp16Impl, this, - thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionFp16Impl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "conv fp16 error ret[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc index b984a63d9f..6a4436a5b2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc @@ -213,8 +213,8 @@ int ConvolutionWinogradFP16CPUKernel::Run() { return RET_ERROR; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ConvolutionWinogradFp16Impl, this, thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionWinogradFp16Impl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "conv winograd error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc index b1ca2d63ec..46f1405be4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc @@ -53,8 +53,8 @@ int CropFp16CPUKernel::Run() { input_ptr_ = reinterpret_cast(input_tensor->data_c()); output_ptr_ = reinterpret_cast(output_tensor->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, CropFp16Run, this, - crop_para_->thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CropFp16Run, this, crop_para_->thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ParallelLaunch failed: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc index 68c7f99a99..638edccee2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc @@ -173,8 +173,8 @@ int DeconvolutionDepthwiseFp16CPUKernel::Run() { memset(output_ptr, 0, out_tensors_.at(kOutputIndex)->ElementsNum() * sizeof(float16_t)); packed_output_ = output_ptr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeconvDwFp16Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeconvDwFp16Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwFp16Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc index a65ff9dd07..a6e99d793e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc @@ -218,8 +218,8 @@ int DeConvolutionFp16CPUKernel::Run() { RowMajor2Col16MajorFp16Opt(batch_input_, pack_input_, input_plane_, conv_param_->input_channel_); - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvFp16Run, - this, thread_count_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvFp16Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "deconv fp16 run error! error_code[" << error_code << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_winograd_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_winograd_fp16.cc index e3d68b7e65..5cb210b77e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_winograd_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_winograd_fp16.cc @@ -392,12 +392,12 @@ int DeConvWinogradFp16CPUKernel::Run() { nhwc_output_ = output_ptr + batch_index * deconv_param_->output_plane_ * conv_param_->output_channel_; ::memset(nc4hw4_output_, 0, deconv_param_->output_plane_ * deconv_param_->oc_div4_ * C4NUM * sizeof(float16_t)); - ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvWgFp16Run, this, - deconv_param_->thread_num_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvWgFp16Run, this, deconv_param_->thread_num_); /*post bias activate and nhwc */ - ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvWgPostFp16Run, this, - thread_num_hw_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvWgPostFp16Run, this, thread_num_hw_); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/gather_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/gather_fp16.cc index 712990d63b..b0203e73be 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/gather_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/gather_fp16.cc @@ -148,8 +148,8 @@ int GatherFp16CPUKernel::Run() { Float32ToFloat16(reinterpret_cast(input_tensor->data_c()), input_data_, input_tensor->ElementsNum()); } } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, GatherRunFp16, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(GatherRunFp16, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Gather function error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/instance_norm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/instance_norm_fp16.cc index 7f2b7c9897..f8212c6f0b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/instance_norm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/instance_norm_fp16.cc @@ -109,8 +109,8 @@ int InstanceNormFp16Run(void *cdata, int task_id) { int InstanceNormFp16CPUKernel::Run() { src_data_ = reinterpret_cast(in_tensors_[0]->data_c()); dst_data_ = reinterpret_cast(out_tensors_[0]->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, InstanceNormFp16Run, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(InstanceNormFp16Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "InstanceNormFp16Run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/layer_norm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/layer_norm_fp16.cc index 333efd5553..8539ad5130 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/layer_norm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/layer_norm_fp16.cc @@ -95,8 +95,8 @@ int LayerNormFp16CPUKernel::Run() { var_data_ = reinterpret_cast(context_->allocator->Malloc(param_->norm_outer_size_ * sizeof(float16_t))); } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LayerNormFp16Run, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LayerNormFp16Run, this, op_parameter_->thread_num_); if (out_tensors_.size() != 3) { context_->allocator->Free(mean_data_); context_->allocator->Free(var_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/log_softmax_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/log_softmax_fp16.cc index e484ec982f..80d26e1861 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/log_softmax_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/log_softmax_fp16.cc @@ -95,8 +95,8 @@ int LogSoftmaxLastAxisFp16Run(void *cdata, int task_id) { int LogSoftmaxFp16CPUKernel::Run() { if (in_plane_size_ == 1) { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - LogSoftmaxLastAxisFp16Run, this, context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LogSoftmaxLastAxisFp16Run, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "LogSoftmaxFp16CPUKernel ParallelLaunch failed, ret: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc index 5b0e13be2a..6f4ab01a90 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc @@ -294,8 +294,8 @@ int MatmulBaseFP16CPUKernel::Run() { batch_b_ptr_ = b_pack_ptr_ + i * params_->deep_ * params_->col_align_; batch_c_ptr_ = c_ptr + i * params_->row_ * params_->col_; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MatmulBaseFP16Run, - this, thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MatmulBaseFP16Run, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "MatmulBaseFloatRun failed"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc index 6573a340ac..284d8fcee7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc @@ -89,8 +89,8 @@ int PadFp16CPUKernel::Run() { output_[i] = pad_param_->constant_value_; } } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, PadImpl, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PadImpl, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } @@ -102,8 +102,8 @@ int PadFp16CPUKernel::Run() { return ret; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MirrorPadImpl, this, - context_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MirrorPadImpl, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Pad Reflect or Symmetric mode run error, error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc index 03491257a8..43b31fdf18 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc @@ -90,8 +90,8 @@ int PoolingFp16CPUKernel::Run() { fp16_input_ = reinterpret_cast(input_tensor->data_c()); fp16_output_ = reinterpret_cast(output_tensor->data_c()); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - PoolingFp16Impl, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PoolingFp16Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "pooling error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/power_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/power_fp16.cc index 587e48b372..e2e328b188 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/power_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/power_fp16.cc @@ -87,8 +87,8 @@ int PowerFp16CPUKernel::Run() { return ret; } } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, PowerImplFp16, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PowerImplFp16, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerFp16CPUKernel error: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc index acb7219e1d..17f329bfb6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc @@ -164,8 +164,8 @@ int QuantDTypeCastFp16CPUKernel::Run() { return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - QuantDTypeCastFP16Run, this, thread_n_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(QuantDTypeCastFP16Run, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc index c7d0dfc251..fd8bc0e194 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc @@ -93,8 +93,8 @@ int ReduceFp16CPUKernel::Run() { outer_size_ = outer_sizes_.at(i); inner_size_ = inner_sizes_.at(i); axis_size_ = axis_sizes_.at(i); - auto error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ReduceFp16Impl, this, context_->thread_num_); + auto error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceFp16Impl, this, context_->thread_num_); if (error_code != RET_OK) { FreeTmpBuffer(); MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; @@ -109,8 +109,8 @@ int ReduceFp16CPUKernel::Run() { outer_size_ = outer_sizes_.back(); inner_size_ = inner_sizes_.back(); axis_size_ = axis_sizes_.back(); - auto error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ReduceFp16Impl, this, context_->thread_num_); + auto error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceFp16Impl, this, context_->thread_num_); if (error_code != RET_OK) { FreeTmpBuffer(); MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc index 3db787165a..6a4831df58 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc @@ -115,8 +115,8 @@ int ScaleFp16CPUKernel::Run() { return ret; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ScaleFp16Run, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ScaleFp16Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc index 15aef3e1a1..12f7753b0b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc @@ -63,8 +63,8 @@ int SliceFp16CPUKernel::Run() { DoSliceNoParallel(input_data, out_tensors_.at(0)->data_c(), param_, lite::DataTypeSize(kNumberTypeFloat16)); return RET_OK; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SliceFp16Launch, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SliceFp16Launch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "fp16 slice launch fail!ret: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc index ed6e14dfe2..069922970b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc @@ -95,8 +95,8 @@ int SoftmaxLastAxisFp16Run(void *cdata, int task_id) { int SoftmaxFp16CPUKernel::Run() { if (in_plane_size_ == 1) { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SoftmaxLastAxisFp16Run, this, context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SoftmaxLastAxisFp16Run, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SoftmaxFp16CPUKernel ParallelLaunch failed, ret: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc index 0abf39d5ea..b8644ac498 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc @@ -102,7 +102,7 @@ int StackFp16CPUKernel::Run() { // run stack num_threads_ = MSMIN(UP_DIV(outer_size_, 64), this->context_->thread_num_); ret = - ParallelLaunch(static_cast(this->context_)->thread_pool_, StackRun, this, num_threads_); + static_cast(this->context_)->thread_pool_->ParallelLaunch(StackRun, this, num_threads_); if (ret != RET_OK) { MS_LOG(ERROR) << "StackBaseCPUKernel Run error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16_grad/activation_fp16_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp16_grad/activation_fp16_grad.cc index 1f24ba18b7..f0fd2b9321 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16_grad/activation_fp16_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16_grad/activation_fp16_grad.cc @@ -79,8 +79,8 @@ int ActivationGradRunFp16(void *cdata, int task_id) { } int ActivationGradCPUKernelFp16::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ActivationGradRunFp16, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ActivationGradRunFp16, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation Grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16_grad/arithmetic_fp16_self_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp16_grad/arithmetic_fp16_self_grad.cc index 11795bc507..47b7641267 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16_grad/arithmetic_fp16_self_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16_grad/arithmetic_fp16_self_grad.cc @@ -73,8 +73,8 @@ int ArithmeticSelfGradFp16Run(void *cdata, int task_id) { } int ArithmeticSelfGradFp16CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ArithmeticSelfGradFp16Run, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticSelfGradFp16Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation Grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/activation_fp32.cc index 286be906c8..12c3a26654 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/activation_fp32.cc @@ -105,8 +105,8 @@ int ActivationRun(void *cdata, int task_id) { } int ActivationCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ActivationRun, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ActivationRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc index 9a1c865260..fa9bfe2652 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc @@ -122,8 +122,8 @@ int AdderCPUKernel::Run() { return RET_ERROR; } - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, AdderImpl, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(AdderImpl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "adder error error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/addn_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/addn_fp32.cc index 2d0d95024d..efd9f178b1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/addn_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/addn_fp32.cc @@ -89,8 +89,8 @@ int AddNCPUKernel::Run() { in1_addr_ = input0_data; in2_addr_ = input1_data; out_addr_ = output_data; - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, AddNLaunch, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(AddNLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "addn launch fail!ret: " << ret; return RET_ERROR; @@ -98,8 +98,8 @@ int AddNCPUKernel::Run() { for (size_t i = 2; i < in_tensors_.size(); ++i) { in1_addr_ = reinterpret_cast(in_tensors_[i]->MutableData()); in2_addr_ = output_data; - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, AddNLaunch, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(AddNLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "addn launch fail!ret: " << ret << ", input index: " << i; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc index d183b7a287..f62c4108d9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc @@ -419,8 +419,8 @@ int ArithmeticCPUKernel::Run() { input1_ptr_ = in_tensors_[1]->data_c(); } output_ptr_ = out_tensors_[0]->data_c(); - return ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticsRun, this, - context_->thread_num_); + return static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticsRun, this, context_->thread_num_); } REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_MulFusion, LiteKernelCreator) diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self_fp32.cc index bdedb65ec9..3e90291061 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self_fp32.cc @@ -113,8 +113,8 @@ int ArithmeticSelfRun(void *cdata, int task_id) { } int ArithmeticSelfCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticSelfRun, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticSelfRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc index 90aa023017..729b8e597f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc @@ -75,8 +75,8 @@ int BatchnormCPUKernel::InitConstTensor() { } int BatchnormCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, BatchNormRun, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc index 36e0b1b2f8..5eb0316455 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc @@ -141,8 +141,8 @@ int CastCPUKernel::Run() { if (data_num_ == 0) { return RET_OK; } - return ParallelLaunch(static_cast(this->context_)->thread_pool_, CastRun, this, - op_parameter_->thread_num_); + return static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CastRun, this, op_parameter_->thread_num_); } REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Cast, LiteKernelCreator) diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc index a03359a94b..d45f1228a9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc @@ -69,8 +69,8 @@ int ConcatRun(void *cdata, int task_id) { } int ConcatCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConcatRun, - this, op_parameter_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConcatRun, this, op_parameter_->thread_num_); return error_code; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h index 709699c05e..9ac8f20bf2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h @@ -22,7 +22,6 @@ #include "nnacl/concat_parameter.h" #include "include/errorcode.h" #include "src/runtime/runtime_api.h" -#include "src/runtime/thread_pool.h" #include "include/context.h" using mindspore::lite::InnerContext; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc index b40bcec3a8..6ffe46e4e0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc @@ -247,12 +247,12 @@ int Convolution1x1CPUKernel::Run() { } if (multi_thread_by_hw_) { - ParallelLaunch(static_cast(this->context_)->thread_pool_, Convolution1x1RunHw, this, - thread_count_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1RunHw, this, thread_count_); } else { PackMatmulInput(input_ptr_, pack_input_, matmul_param_->row_, matmul_param_->deep_); - ParallelLaunch(static_cast(this->context_)->thread_pool_, Convolution1x1Run, this, - thread_count_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Run, this, thread_count_); } } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc index 3f19ec3015..45ac91e354 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc @@ -126,8 +126,8 @@ int ConvolutionDepthwise3x3CPUKernel::Run() { auto output_tensor = out_tensors_.at(kOutputIndex); output_ptr_ = reinterpret_cast(output_tensor->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDw3x3Run, this, - conv_param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDw3x3Run, this, conv_param_->thread_num_); ctx_->allocator->Free(buffer_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDw3x3Run error: error_code[" << ret << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc index fabb0eb1d6..cacc7d47b0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc @@ -107,8 +107,8 @@ int ConvolutionDepthwiseCPUKernel::Run() { auto output_tensor = out_tensors_.at(kOutputIndex); output_ptr_ = reinterpret_cast(output_tensor->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwRun, this, - conv_param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc index f587c6f452..f706cb24b1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc @@ -194,8 +194,8 @@ int ConvolutionDepthwiseIndirectCPUKernel::Run() { ConvDwInitIndirection(indirect_buffer_, packed_input_, zero_ptr_, conv_param_, step_h, step_w); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwIndirectRun, - this, conv_param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwIndirectRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwIndirectRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc index 4c3d00f430..4ee5271b61 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc @@ -163,8 +163,8 @@ int ConvolutionDepthwiseSWCPUKernel::Run() { packed_output_ = output_ptr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwSWRun, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwSWRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwSWRun error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc index a1c6349e64..3e3eff7a55 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc @@ -152,8 +152,8 @@ int ConvolutionCPUKernel::Run() { PackWeight(); } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvolutionImpl, this, - thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "conv error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow_fp32.cc index 68bbd780f0..bbb3f29400 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow_fp32.cc @@ -179,8 +179,8 @@ int ConvolutionSWCPUKernel::Run() { auto input_data = in_tensors_.at(kInputIndex)->MutableData(); MS_ASSERT(input_data != nullptr); ori_input_data_ = reinterpret_cast(input_data); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ConvolutionSWImpl, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionSWImpl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv error error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc index 367e684b63..a41b0f9224 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc @@ -219,8 +219,8 @@ int ConvolutionWinogradCPUKernel::Run() { InitWeightBias(); } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvolutionWinogradImpl, - this, thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionWinogradImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "conv winograd error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_and_resize_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_and_resize_fp32.cc index fcf5b03186..b13a09b991 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_and_resize_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_and_resize_fp32.cc @@ -159,8 +159,8 @@ int CropAndResizeCPUKernel::Run() { return ret; } - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - CropAndResizeImpl, this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CropAndResizeImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "CropAndResize run error, error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc index da6a6a8951..4dc80a925b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc @@ -62,8 +62,8 @@ int CropCPUKernel::Run() { return RET_OK; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, CropLaunch, this, - crop_para_->thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CropLaunch, this, crop_para_->thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "Crop launch fail!ret: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/cumsum_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/cumsum_fp32.cc index 6762d7b8b5..5817792343 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/cumsum_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/cumsum_fp32.cc @@ -137,8 +137,8 @@ int CumSumCPUKernel::DoCumsumInt(int task_id) { } int CumSumCPUKernel::Run() { - int ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, CumsumLaunch, this, - op_parameter_->thread_num_); + int ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CumsumLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Crop launch fail!ret: " << ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise_fp32.cc index 232da180d8..c611c13161 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise_fp32.cc @@ -168,8 +168,8 @@ int DeconvolutionDepthwiseCPUKernel::Run() { packed_output_ = output_addr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeconvDwRun, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeconvDwRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwRun error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_fp32.cc index 5d54e1d8ee..adf452b0ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_fp32.cc @@ -227,8 +227,8 @@ int DeConvolutionCPUKernel::Run() { RowMajor2Col12Major(input_ptr_, pack_input_, matmul_param_->row_, matmul_param_->deep_); #endif - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvFp32Run, - this, thread_count_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvFp32Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "deconv fp32 run error! error_code[" << error_code << "]"; FreeRunBuf(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_winograd_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_winograd_fp32.cc index d22a146cfd..ba0bed446d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_winograd_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_winograd_fp32.cc @@ -411,12 +411,12 @@ int DeConvolutionWinogradCPUKernel::Run() { nhwc_output_ = src_out + batch_index * deconv_param_->output_plane_ * conv_param_->output_channel_; ::memset(nc4hw4_output_, 0, deconv_param_->output_plane_ * deconv_param_->oc_div4_ * C4NUM * sizeof(float)); - ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvWgFp32Run, this, - deconv_param_->thread_num_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvWgFp32Run, this, deconv_param_->thread_num_); /*post bias activate and nhwc */ - ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvWgPostFp32Run, this, - thread_num_hw_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvWgPostFp32Run, this, thread_num_hw_); } FreeRunBuf(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/elu_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/elu_fp32.cc index 56649e3ff9..fafe276cb3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/elu_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/elu_fp32.cc @@ -55,8 +55,8 @@ int EluRun(void *cdata, int task_id) { } int EluCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, EluRun, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(EluRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Elu error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup_fp32.cc index 0b94fc6de2..e951b3c7b4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup_fp32.cc @@ -87,8 +87,8 @@ int EmbeddingLookupCPUKernel::Run() { memcpy(input_addr_ + dest_loc, input_t, sizeof(float) * in_tensors_.at(i)->ElementsNum()); dest_loc += in_tensors_.at(i)->ElementsNum(); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, EmbeddingLookupRun, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(EmbeddingLookupRun, this, op_parameter_->thread_num_); FreeRunBuff(); if (ret != RET_OK) { MS_LOG(ERROR) << "EmbeddingLookup error: error_code[" << ret << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/exp_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/exp_fp32.cc index 8434785678..137156f9a8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/exp_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/exp_fp32.cc @@ -73,8 +73,8 @@ int ExpCPUKernel::Run() { output_addr_ = reinterpret_cast(out_tensors_.front()->MutableData()); exp_parameter_->element_num_ = in_tensors_.front()->ElementsNum(); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ExpRun, this, - exp_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ExpRun, this, exp_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Exp error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fill_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fill_fp32.cc index 0c99b60919..79a2b2042f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fill_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fill_fp32.cc @@ -91,8 +91,8 @@ int FillCPUKernel::Run() { MS_LOG(ERROR) << "unsupported fill data type " << fill_input->data_type(); return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, FillRun, this, - thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(FillRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "FillRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc index 3a881c607f..37e759928a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc @@ -93,8 +93,8 @@ int FusedBatchnormCPUKernel::Run() { trained_ = true; // trained at least once } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, BatchNormRun, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd_fp32.cc index 219cfe8b8a..98ed88a123 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd_fp32.cc @@ -128,8 +128,8 @@ int GatherNdCPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); InitOffset(); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, GatherNdRun, this, - thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(GatherNdRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "gatherNd error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gather_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gather_fp32.cc index 6e2bebbad9..7d53a78045 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gather_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gather_fp32.cc @@ -92,8 +92,8 @@ int GatherCPUKernel::Run() { return ret; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, GatherRun, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(GatherRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Gather function error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/instance_norm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/instance_norm_fp32.cc index 54cfa9fef8..a6c0a2e013 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/instance_norm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/instance_norm_fp32.cc @@ -66,8 +66,8 @@ int InstanceNormCPUKernel::Run() { gamma_data_ = reinterpret_cast(in_tensors_.at(1)->data_c()); beta_data_ = reinterpret_cast(in_tensors_.at(2)->data_c()); dst_data_ = reinterpret_cast(out_tensors_.at(0)->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, InstanceNormRun, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(InstanceNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "InstanceNormRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm_fp32.cc index bd35bee22e..6b21d4bb84 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm_fp32.cc @@ -146,8 +146,8 @@ int L2NormCPUKernel::Run() { output_ptr_ = reinterpret_cast(out_tensors_.at(kOutputIndex)->MutableData()); if (l2_norm_param_->axis_num_ == 0 || l2_norm_param_->axis_num_ == input_shape.size()) { // all axis - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SquareSumRun, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SquareSumRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; return RET_ERROR; @@ -157,15 +157,15 @@ int L2NormCPUKernel::Run() { sum += tmp_sum_[i]; } sqrt_sum_ = sqrt(sum > l2_norm_param_->epsilon_ ? sum : l2_norm_param_->epsilon_); - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, L2NormRun, this, - context_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(L2NormRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; return RET_ERROR; } } else if (l2_norm_param_->axis_num_ == 1 && l2_norm_param_->axis_[0] == static_cast(input_shape.size()) - 1) { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - L2NormTrailingAxisRun, this, context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(L2NormTrailingAxisRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/layer_norm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/layer_norm_fp32.cc index 8def08a2bb..0371c767ae 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/layer_norm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/layer_norm_fp32.cc @@ -92,8 +92,8 @@ int LayerNormCPUKernel::Run() { mean_data_ = reinterpret_cast(context_->allocator->Malloc(param_->norm_outer_size_ * sizeof(float))); var_data_ = reinterpret_cast(context_->allocator->Malloc(param_->norm_outer_size_ * sizeof(float))); } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LayerNormRun, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LayerNormRun, this, op_parameter_->thread_num_); if (out_tensors_.size() != 3) { context_->allocator->Free(mean_data_); context_->allocator->Free(var_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm_fp32.cc index b3293ce3c7..f9557daaef 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm_fp32.cc @@ -74,8 +74,8 @@ int LocalResponseNormRun(void *cdata, int task_id) { } int LocalResponseNormCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - LocalResponseNormRun, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LocalResponseNormRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "LocalResponseNorm function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/log_softmax_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/log_softmax_fp32.cc index 5bb6863ff9..de79a92166 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/log_softmax_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/log_softmax_fp32.cc @@ -96,8 +96,8 @@ int LogSoftmaxLastAxisRun(void *cdata, int task_id) { int LogSoftmaxCPUKernel::Run() { int ret = RET_OK; if (in_plane_size_ == 1) { - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LogSoftmaxLastAxisRun, - this, context_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LogSoftmaxLastAxisRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "LogSoftmaxCPUKernel ParallelLaunch failed, ret: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection_fp32.cc index 50c4c5e5e5..19fed6c31d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection_fp32.cc @@ -61,8 +61,8 @@ int LshProjectionCPUKernel::Run() { if (ret != RET_OK) { return ret; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LshProjectionRun, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LshProjectionRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "LshProjection kernel parallel launch failed"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc index 17d0d5481d..0259187de2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc @@ -332,8 +332,8 @@ int MatmulFp32BaseCPUKernel::Run() { batch_b_ptr_ = b_pack_ptr_ + i * params_->deep_ * params_->col_align_; batch_c_ptr_ = c_ptr + i * params_->row_ * params_->col_; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MatmulBaseFloatRun, - this, thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MatmulBaseFloatRun, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "MatmulBaseFloatRun failed"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot_fp32.cc index a3cae5ce29..2a63f801c1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot_fp32.cc @@ -181,8 +181,8 @@ int OneHotCPUKernel::GetParams() { } int OneHotCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, RunOneHot, - this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(RunOneHot, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "OneHot function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc index 73eb758ae4..a12d5f632b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc @@ -395,8 +395,8 @@ int PadCPUKernel::Run() { output_data[i] = pad_param_->constant_value_; } } - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, PadImpl, this, - context_->thread_num_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PadImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Pad run error, error_code[" << error_code << "]"; return RET_ERROR; @@ -409,8 +409,8 @@ int PadCPUKernel::Run() { return error_code; } - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, MirrorPadImpl, - this, context_->thread_num_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MirrorPadImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Pad Reflect or Symmetric mode run error, error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc index 74cc4880e6..c7def2f89e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc @@ -85,8 +85,8 @@ int PoolingImpl(void *cdata, int task_id) { } int PoolingCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, PoolingImpl, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PoolingImpl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "pooling error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc index 262af77ab2..ab65e14d2f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc @@ -41,8 +41,8 @@ int PowerImpl(void *cdata, int task_id) { } int PowerCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, PowerImpl, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PowerImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerCPUKernel error: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu_fp32.cc index e80baa2c53..272d4a6a13 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu_fp32.cc @@ -93,8 +93,8 @@ int PReluCPUKernel::Run() { auto negative_slope_tensor = in_tensors_.at(1); prelu_param_->slope_ = reinterpret_cast(negative_slope_tensor->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, PReluRun, this, - prelu_param_->op_parameter_.thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PReluRun, this, prelu_param_->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "PRelu Run error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc index f1e45d47e0..31c4b4c176 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc @@ -121,8 +121,8 @@ int ReduceCPUKernel::Run() { MS_LOG(ERROR) << "axis_size_ is must not be zero!"; return RET_ERROR; } - auto error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ReduceImpl, - this, context_->thread_num_); + auto error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc index ef34cb5994..1358eb1f2c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc @@ -205,8 +205,8 @@ int ResizeCPUKernel::RunImpl(int task_id) { } int ResizeCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ResizeImpl, - this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ResizeImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_fp32.cc index 17d288cbed..c98f3866da 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_fp32.cc @@ -129,8 +129,8 @@ int ReverseCPUKernel::DoReverse(int task_id) { int ReverseCPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_[0]->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_[0]->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ReverseRun, this, - thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReverseRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "Reverse run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling_fp32.cc index 5003fee377..f3de04c7dd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling_fp32.cc @@ -101,8 +101,8 @@ int ROIPoolingCPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); roi_ptr_ = reinterpret_cast(in_tensors_.at(1)->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ROIPoolingRun, this, - param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ROIPoolingRun, this, param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ROIPooling error: error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scale_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scale_fp32.cc index 0de56f6af0..402dde31ee 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scale_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scale_fp32.cc @@ -188,8 +188,8 @@ int ScaleCPUKernel::Run() { auto out_tensor = out_tensors_.front(); output_ptr_ = reinterpret_cast(out_tensor->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ScaleRun, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ScaleRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd_fp32.cc index d16b5de59a..8db67bd373 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd_fp32.cc @@ -149,8 +149,8 @@ int ScatterNDRun(void *cdata, int task_id) { } int ScatterNDCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ScatterNDRun, this, - thread_n_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ScatterNDRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ScatterND error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc index 4fc2381442..c0c6cd8510 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc @@ -96,8 +96,8 @@ int SoftmaxLastAxisRun(void *cdata, int task_id) { int SoftmaxCPUKernel::Run() { int ret = RET_OK; if (in_plane_size_ == 1) { - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SoftmaxLastAxisRun, - this, context_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SoftmaxLastAxisRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SoftmaxCPUKernel ParallelLaunch failed, ret: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch_fp32.cc index 210dac2d6a..6b7df142d6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch_fp32.cc @@ -102,8 +102,8 @@ int SpaceToBatchCPUKernel::Run() { } } - ParallelLaunch(static_cast(this->context_)->thread_pool_, SpaceToBatchFp32Run, this, - op_parameter_->thread_num_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SpaceToBatchFp32Run, this, op_parameter_->thread_num_); return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth_fp32.cc index 84b16ebcee..d3c6a9cef2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth_fp32.cc @@ -93,8 +93,8 @@ int SpaceToDepthCPUKernel::Run() { input_ptr_ = reinterpret_cast(in_tensors_.at(0)->data_c()); output_ptr_ = reinterpret_cast(out_tensors_.at(0)->data_c()); if (in_tensors_.at(0)->format() == schema::Format::Format_NHWC) { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SpaceToDepthRun, - this, thread_h_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SpaceToDepthRun, this, thread_h_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SpaceToDepth error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense_fp32.cc index 5be46ecbcb..2d0b4da841 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense_fp32.cc @@ -175,8 +175,8 @@ int SparseToDenseCPUKernel::Run() { } output_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); count_unit_ = thread_count_ > 1 ? UP_DIV(index_num, thread_count_) : index_num; - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SparseToDenseRun, this, - s2d_param->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SparseToDenseRun, this, s2d_param->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SparseToDenseRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc index 1a6f24ffb9..ef8f7894d1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc @@ -156,8 +156,8 @@ int TransposeCPUKernel::Run() { thread_count_ = op_parameter_->thread_num_; GetNHNCTransposeFunc(in_tensor, out_tensor, param_); if (NHNCTransposeFunc_ != nullptr) { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, TransposeImpl, - this, thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(TransposeImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "NHNCTransposeFunc_ is error!"; } @@ -185,8 +185,8 @@ int TransposeCPUKernel::Run() { } int ret; if (dims_ > DIMENSION_6D) { - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, TransposeImpl, this, - thread_count_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(TransposeImpl, this, thread_count_); } else { ret = DoTransposeFp32(in_data_, out_data_, out_shape_, param_); } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc index a3f5eb5446..478e1c0860 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where_fp32.cc @@ -132,8 +132,8 @@ int WhereCPUKernel::RunWithTripleInputs() { MS_LOG(ERROR) << "Error, inputs' length are zero !!!"; return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, WhereRun, this, - where_param_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(WhereRun, this, where_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "WhereDwRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc index 62caf197e9..cfd1112c47 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc @@ -98,8 +98,8 @@ int ActivationGradRun(void *cdata, int task_id) { } int ActivationGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ActivationGradRun, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ActivationGradRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation Grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/adam.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/adam.cc index 740f4578f1..01c677bc6f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/adam.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/adam.cc @@ -103,7 +103,7 @@ int AdamRun(void *cdata, int task_id) { int AdamCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, AdamRun, this, thread_count_); + static_cast(this->context_)->thread_pool_->ParallelLaunch(AdamRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Adam function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc index af8f1afdff..6cf81c9203 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc @@ -82,8 +82,8 @@ int ApplyMomentumRun(void *cdata, int task_id) { } int ApplyMomentumCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ApplyMomentumRun, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ApplyMomentumRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Apply Momentum function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc index d6f13259a8..48c39a80e2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc @@ -228,7 +228,7 @@ int ArithmeticGradRun(void *cdata, int task_id) { int ArithmeticGradCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, ArithmeticGradRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(ArithmeticGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "Arithmetic Grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_self_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_self_grad.cc index 73820829e9..aeb72b37ee 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_self_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_self_grad.cc @@ -81,8 +81,8 @@ int ArithmeticSelfGradCPUKernel::DoArithmeticSelfGrad(int task_id) { int ArithmeticSelfGradCPUKernel::ReSize() { return RET_OK; } int ArithmeticSelfGradCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ArithmeticSelfGradRun, this, thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticSelfGradRun, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "parallel launch fail!ret: " << ret; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/assign.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/assign.cc index 2300085234..f74b5294a8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/assign.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/assign.cc @@ -59,8 +59,8 @@ int AssignRun(void *cdata, int task_id) { } int AssignCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, AssignRun, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(AssignRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Assign function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc index 05edb3abee..4da4b41e25 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc @@ -84,7 +84,7 @@ int BiasGradRun(void *cdata, int task_id) { int BiasGradCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, BiasGradRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(BiasGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "bias function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc index 5981a5016a..227df26cea 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc @@ -135,8 +135,8 @@ int BNGradCPUKernel::Run() { stage_ = 0; thread_num_ = context_->thread_num_; if (thread_num_ == 1) { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, BNGradRun, - this, thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BNGradRun, this, thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "BN function error error_code[" << error_code << "]"; return RET_ERROR; @@ -145,8 +145,8 @@ int BNGradCPUKernel::Run() { const std::vector threads = {thread_num_, 1, thread_num_}; for (size_t stage = 0; stage < threads.size(); stage++) { stage_ = static_cast(stage); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, BNGradRun, - this, threads.at(stage)); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BNGradRun, this, threads.at(stage)); if (error_code != RET_OK) { MS_LOG(ERROR) << "BN function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc index 035aa3713c..7c6ccede11 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc @@ -165,7 +165,7 @@ int ConvolutionTrainRun(void *cdata, int task_id) { int ConvolutionTrainCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvolutionTrainRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(ConvolutionTrainRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv train function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc index b8ff57f5ae..e0fa4b562e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc @@ -192,8 +192,8 @@ int ConvolutionGradFilterCPUKernel::Run() { auto *out_dw = out_tensors_.at(0); auto dw_addr = reinterpret_cast(out_dw->MutableData()); memset(dw_addr, 0, out_dw->Size()); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ConvolutionGradFilterRun, this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionGradFilterRun, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv filter function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc index 1c4fb8c3df..444f5ad727 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc @@ -144,8 +144,8 @@ int ConvolutionGradInputCPUKernel::Run() { auto *out_dx = out_tensors_.at(0); auto dx_addr = reinterpret_cast(out_dx->MutableData()); memset(dx_addr, 0, sizeof(float) * batch * in_ch * in_h * in_w); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ConvolutionGradInputRun, this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionGradInputRun, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "bias function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/deconvolution_grad_filter.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/deconvolution_grad_filter.cc index 2d291499d0..f8ff99c604 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/deconvolution_grad_filter.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/deconvolution_grad_filter.cc @@ -121,8 +121,8 @@ int DeConvolutionGradFilterRun(void *cdata, int task_id) { } int DeConvolutionGradFilterCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - DeConvolutionGradFilterRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvolutionGradFilterRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv filter function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout.cc index fe098ac18e..bbf9e5bddb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout.cc @@ -101,8 +101,8 @@ int RunDropout(void *cdata, int task_id) { } int DropoutCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, RunDropout, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(RunDropout, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Dropout function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout_grad.cc index 4a7b842fd4..b3ebb26f73 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/dropout_grad.cc @@ -83,8 +83,8 @@ int RunDropoutGrad(void *cdata, int task_id) { } int DropoutGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, RunDropoutGrad, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(RunDropoutGrad, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Dropout Grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc index e36b9cd282..1d45a54b05 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/layernorm_grad.cc @@ -103,7 +103,7 @@ int LayerNormGradRun(void *cdata, int task_id) { int LayerNormGradCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, LayerNormGradRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(LayerNormGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "LayerNorm function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/neg_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/neg_grad.cc index 35c103e1d5..508f6385f1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/neg_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/neg_grad.cc @@ -56,8 +56,8 @@ int NegGradCPUKernel::DoNegGrad(int task_id) { int NegGradCPUKernel::ReSize() { return RET_OK; } int NegGradCPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, NegGradRun, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(NegGradRun, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "parallel launch fail!ret: " << ret; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc index 362806947c..baaf69db9c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc @@ -100,8 +100,8 @@ int PoolingGradImpl(void *cdata, int task_id) { int PoolingGradCPUKernel::Run() { thread_num_ = context_->thread_num_; - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - PoolingGradImpl, this, thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PoolingGradImpl, this, thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "pooling error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc index eab0a0e5fb..b898fdf426 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc @@ -76,8 +76,8 @@ int PowerGradRun(void *cdata, int task_id) { } int PowerGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, PowerGradRun, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PowerGradRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "power grad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/resize_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/resize_grad.cc index f5a4351546..12f7417240 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/resize_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/resize_grad.cc @@ -93,7 +93,7 @@ int ResizeGradCPUKernel::Run() { size_t elem_number = out_tensors_.at(0)->ElementsNum(); std::fill(out_addr, out_addr + elem_number, 0.f); int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, ResizeGradRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(ResizeGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "ResizeGradCPUKernel function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sgd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sgd.cc index 95434c9b1b..83f2638f7c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sgd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sgd.cc @@ -146,11 +146,11 @@ int SgdCPUKernel::Run() { auto stat = reinterpret_cast(in_tensors_.at(5)->MutableData()); auto error_code = RET_OK; if (*stat > 0.0f) { - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, SgdRunInit, this, - thread_count_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SgdRunInit, this, thread_count_); } else { - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, SgdRun, this, - thread_count_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SgdRun, this, thread_count_); } if (error_code != RET_OK) { MS_LOG(ERROR) << "SGD function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits.cc index defb74d0d6..14d2525ba8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits.cc @@ -61,8 +61,8 @@ int SigmoidCrossEntropyWithLogitsRun(void *cdata, int task_id) { } int SigmoidCrossEntropyWithLogitsCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SigmoidCrossEntropyWithLogitsRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SigmoidCrossEntropyWithLogitsRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "SigmoidCrossEntropyWithLogits function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits_grad.cc index 83c29845e7..9a330dc37c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sigmoid_cross_entropy_with_logits_grad.cc @@ -61,8 +61,8 @@ int SigmoidCrossEntropyWithLogitsGradRun(void *cdata, int task_id) { } int SigmoidCrossEntropyWithLogitsGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SigmoidCrossEntropyWithLogitsGradRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SigmoidCrossEntropyWithLogitsGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "SigmoidCrossEntropyWithLogitsGrad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss.cc index 5558c1570f..4480301c85 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss.cc @@ -73,8 +73,8 @@ int SmoothL1LossRun(void *cdata, int task_id) { } int SmoothL1LossCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SmoothL1LossRun, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SmoothL1LossRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "SmoothL1Loss function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss_grad.cc index 4b3162d503..f2a815175d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/smooth_l1_loss_grad.cc @@ -70,8 +70,8 @@ int SmoothL1LossGradRun(void *cdata, int task_id) { } int SmoothL1LossGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SmoothL1LossGradRun, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SmoothL1LossGradRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "SmoothL1LossGrad function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc index df1da4a5c8..0032d59e63 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc @@ -92,8 +92,8 @@ int SoftmaxCrossEntropyWithLogitsRun(void *cdata, int task_id) { } int SoftmaxCrossEntropyWithLogitsCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SoftmaxCrossEntropyWithLogitsRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SoftmaxCrossEntropyWithLogitsRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "SoftmaxCrossEntropy function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc index 9e62e4ec02..3c31bc6f60 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc @@ -81,7 +81,7 @@ int SoftmaxGradRun(void *cdata, int task_id) { int SoftmaxGradCPUKernel::Run() { int error_code = - ParallelLaunch(static_cast(this->context_)->thread_pool_, SoftmaxGradRun, this, 1); + static_cast(this->context_)->thread_pool_->ParallelLaunch(SoftmaxGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "SoftmaxGradRun function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc index 2c0c7242be..5630f5dbaa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc @@ -113,8 +113,8 @@ int SparseSoftmaxCrossEntropyWithLogitsRun(void *cdata, int task_id) { } int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - SparseSoftmaxCrossEntropyWithLogitsRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SparseSoftmaxCrossEntropyWithLogitsRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "SparseSoftmaxCrossEntropyWithLogits function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/strided_slice_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/strided_slice_grad.cc index 6057cc94ec..da0826de9a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/strided_slice_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/strided_slice_grad.cc @@ -124,8 +124,8 @@ int StridedSliceGradImpl(void *cdata, int task_id) { } int StridedSliceGradCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - StridedSliceGradImpl, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(StridedSliceGradImpl, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "Strided slice error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/unsorted_segment_sum.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/unsorted_segment_sum.cc index b274203d7d..5033b8183b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/unsorted_segment_sum.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/unsorted_segment_sum.cc @@ -68,8 +68,8 @@ int UnsortedSegmentSumRun(void *cdata, int task_id) { } int UnsortedSegmentSumCPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - UnsortedSegmentSumRun, this, 1); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(UnsortedSegmentSumRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "Strided slice error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc index 211e99bfc3..abb62b1c07 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc @@ -217,8 +217,8 @@ int QuantizedAddCPUKernel::Run() { input1_data_ = static_cast(in_tensors_.at(1)->data_c()); output_data_ = static_cast(out_tensors_.at(0)->data_c()); - ParallelLaunch(static_cast(this->context_)->thread_pool_, AddInt8Run, this, - thread_count_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(AddInt8Run, this, thread_count_); return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc index e01d2c8f3c..4832bca421 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc @@ -149,8 +149,8 @@ int ArithmeticInt8CPUKernel::Run() { } TileDimensionsInt8(input_data0, input_data1, tile_data0_, tile_data1_, param); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ArithmeticsInt8Launch, this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticsInt8Launch, this, op_parameter_->thread_num_); if (param->broadcasting_) { context_->allocator->Free(tile_data0_); context_->allocator->Free(tile_data1_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc index 7624a22e94..6daed5073c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc @@ -99,8 +99,8 @@ int ArithmeticSelfInt8CPUKernel::Run() { auto out_tensor = out_tensors_.at(0); in_ptr_ = reinterpret_cast(input_tensor->MutableData()); out_ptr_ = reinterpret_cast(out_tensor->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ArithmeticSelfInt8Runs, this, thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ArithmeticSelfInt8Runs, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc index 936257beaf..a29225231d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc @@ -188,8 +188,8 @@ int BatchnormInt8CPUKernel::Run() { in_addr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); out_addr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, BatchNormInt8Run, - this, batchnorm_param_->op_parameter_.thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(BatchNormInt8Run, this, batchnorm_param_->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc index 161d5fdaee..e9d12e327a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc @@ -115,8 +115,8 @@ int ConcatInt8CPUKernel::Run() { } output_data_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConcatInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConcatInt8Run, this, op_parameter_->thread_num_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc index 849e8879dd..609af440b1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc @@ -524,8 +524,8 @@ int Convolution1x1Int8CPUKernel::Run() { if (parallel_by_oc_) { /* input transpose and input sum */ if (support_optimize_) { - ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution1x1Int8OcOptPre, this, thread_count_hw_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Int8OcOptPre, this, thread_count_hw_); } else { RowMajor2Row16x4MajorInt8(input_ptr_, packed_input_, matmul_param_->row_, matmul_param_->deep_); if (filter_peroc_) { @@ -536,12 +536,12 @@ int Convolution1x1Int8CPUKernel::Run() { } } /* matmul parallel by oc */ - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution1x1Int8OcRun, this, thread_count_oc_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Int8OcRun, this, thread_count_oc_); } else { /* matmul parallel by hw */ - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution1x1Int8HwRun, this, thread_count_hw_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution1x1Int8HwRun, this, thread_count_hw_); } if (error_code != RET_OK) { MS_LOG(ERROR) << "ParallelLaunch run error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc index 61f4933846..acc4db50e6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc @@ -219,8 +219,8 @@ int Convolution3x3Int8CPUKernel::Run() { auto input_addr = reinterpret_cast(in_tensors_.at(kInputIndex)->MutableData()); PackInputToC8Int8(input_addr, input_data_, conv_param_); - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - Convolution3x3Int8Impl, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(Convolution3x3Int8Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv3x3 int8 error error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_3x3_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_3x3_int8.cc index 442437d025..885f6a8728 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_3x3_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_3x3_int8.cc @@ -163,8 +163,8 @@ int ConvolutionDepthwise3x3Int8CPUKernel::Run() { ConvDw3x3Int8Pad(output_ptr_, input_ptr_, packed_weight_, reinterpret_cast(bias_data_), conv_param_, sliding_); } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDw3x3Int8Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDw3x3Int8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { context_->allocator->Free(buffer_); MS_LOG(ERROR) << "ConvDwInt8Run error: error_code[" << ret << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc index ad8434c9dd..d260ecbe38 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc @@ -148,8 +148,8 @@ int ConvolutionDepthwiseInt8CPUKernel::Run() { auto output_tensor = out_tensors_.at(kOutputIndex); output_ptr_ = reinterpret_cast(output_tensor->MutableData()); - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwInt8Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwInt8Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc index 839cea5087..74b0730449 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc @@ -312,8 +312,8 @@ int ConvolutionDepthwiseSWInt8CPUKernel::Run() { packed_output_ = output_addr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ConvDwSWInt8Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvDwSWInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwSWInt8Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc index ddb076df4d..4bd306e268 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc @@ -223,8 +223,8 @@ int ConvolutionInt8CPUKernel::Run() { return RET_ERROR; } - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ConvolutionInt8Impl, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ConvolutionInt8Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv int8 error error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc index 262009d7cc..8ea7e22c9d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc @@ -52,8 +52,8 @@ int CropInt8CPUKernel::Init() { int CropInt8CPUKernel::ReSize() { return CropBaseCPUKernel::ReSize(); } int CropInt8CPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, CropInt8Run, this, - crop_para_->thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(CropInt8Run, this, crop_para_->thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc index e522a8e401..e14bd0a0ea 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc @@ -189,8 +189,8 @@ int DeconvolutionDepthwiseInt8CPUKernel::Run() { packed_output_ = output_addr; } - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeconvDwInt8Run, this, - conv_param_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeconvDwInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwInt8Run error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc index f3f1aa41f2..a515d98441 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc @@ -269,8 +269,8 @@ int DeConvInt8CPUKernel::Run() { DeConvPackInputSum(input_ptr_, input_sum_, conv_param_->conv_quant_arg_.filter_quant_args_[0].zp_, UP_ROUND(matmul_param_->row_, C4NUM), UP_ROUND(matmul_param_->deep_, C16NUM), support_optimize_); - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, DeConvInt8Run, - this, thread_count_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DeConvInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "deconv int8 run error! error_code[" << error_code << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc index 8fd190e342..f1f3707f8b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc @@ -64,8 +64,8 @@ int DetectionPostProcessInt8CPUKernel::Dequantize(lite::Tensor *tensor, float ** quant_size_ = tensor->ElementsNum(); thread_n_stride_ = UP_DIV(quant_size_, op_parameter_->thread_num_); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - DequantizeInt8ToFp32Run, this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DequantizeInt8ToFp32Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "QuantDTypeCastRun error error_code[" << ret << "]"; context_->allocator->Free(*data); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc index 6827698ca7..5c0d090d1a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc @@ -129,8 +129,8 @@ int DivInt8CPUKernel::Run() { static_cast(in_tensors_.at(1)->MutableData()), reinterpret_cast(tile0_data_), reinterpret_cast(tile1_data_), &tile_para); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, DivInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(DivInt8Run, this, op_parameter_->thread_num_); if (broadcast_) { context_->allocator->Free(tile0_data_); context_->allocator->Free(tile1_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc index cb3887ff0c..e27fcc47c5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc @@ -135,8 +135,8 @@ int GatherNdInt8CPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); InitOffset(); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, GatherNdInt8Run, - this, thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(GatherNdInt8Run, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "gatherNd error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc index 155db851d7..1d68f2662d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc @@ -98,8 +98,8 @@ int GatherInt8Run(void *cdata, int task_id) { } int GatherInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, GatherInt8Run, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(GatherInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Gather function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc index e4c1c8787f..df5e805fbb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc @@ -89,8 +89,8 @@ int HswishInt8Run(void *cdata, int task_id) { } int HswishInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, HswishInt8Run, - this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(HswishInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "HswishInt8Run function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/l2_norm_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/l2_norm_int8.cc index 43beadeb2e..e14c98e692 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/l2_norm_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/l2_norm_int8.cc @@ -60,8 +60,8 @@ int L2NormInt8CPUKernel::Run() { MS_LOG(ERROR) << "L2Norm only support reduce on all axis and trailing axis with trailing axis"; return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, L2NormInt8Run, this, - context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(L2NormInt8Run, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/layer_norm_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/layer_norm_int8.cc index 0b6719b224..6d64dbac9c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/layer_norm_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/layer_norm_int8.cc @@ -132,8 +132,8 @@ int LayerNormInt8CPUKernel::Run() { src_ptr_ = reinterpret_cast(in_tensors_.at(0)->data_c()); dst_ptr_ = reinterpret_cast(out_tensors_.at(0)->data_c()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LayerNormInt8Run, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LayerNormInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "LayerNormInt8Run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc index c2cff5f6e8..4c42e8eeea 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc @@ -108,8 +108,8 @@ int LeakyReluInt8CPUKernel::ReSize() { } int LeakyReluInt8CPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, LeakyReluInt8Run, - this, op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(LeakyReluInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunPreluParam failed. errorcode: "; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_base_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_base_int8.cc index 2fa8033812..f883bcf8b4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_base_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_base_int8.cc @@ -335,8 +335,8 @@ int MatmulBaseInt8CPUKernel::Run() { batch_sums_ = weight_bias_sums_ + i * param_->col_align_; batch_c_ptr_ = c_ptr + i * param_->row_ * param_->col_; - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MatmulBaseInt8Run, - this, thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MatmulBaseInt8Run, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "MatmulInt8Run error: [" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc index 6377e1b615..bd70a24985 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc @@ -156,8 +156,8 @@ int MulInt8CPUKernel::Run() { if (fast_hw_broadcast_) { elements_num_ = out_tensors_.front()->Batch() * out_tensors_.front()->Height() * out_tensors_.front()->Width(); count_unit_ = thread_count_ > 1 ? UP_DIV(elements_num_, thread_count_) : elements_num_; - return ParallelLaunch(static_cast(this->context_)->thread_pool_, - FastHWBroadcatMulInt8Run, this, thread_count_); + return static_cast(this->context_) + ->thread_pool_->ParallelLaunch(FastHWBroadcatMulInt8Run, this, thread_count_); } elements_num_ = out_tensors_.at(0)->ElementsNum(); @@ -176,15 +176,15 @@ int MulInt8CPUKernel::Run() { } TileDimensionsInt8(static_cast(in_tensors_.at(0)->MutableData()), static_cast(in_tensors_.at(1)->MutableData()), input0_data_, input1_data_, tile_para); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MulInt8Run, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MulInt8Run, this, thread_count_); ctx_->allocator->Free(input0_data_); ctx_->allocator->Free(input1_data_); return ret; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, MulInt8Run, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MulInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc index e9e543c2db..c2222554cf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc @@ -267,8 +267,8 @@ int PadInt8CPUKernel::Run() { int error_code; if (pad_param_->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { memset(out_data_, pad_param_->pad_quant_arg_.constant_value_[0], out_tensors_[0]->ElementsNum() * sizeof(int8_t)); - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, PadInt8Impl, - this, context_->thread_num_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PadInt8Impl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; return RET_ERROR; @@ -281,8 +281,8 @@ int PadInt8CPUKernel::Run() { return error_code; } - error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - MirrorPadImplInt8, this, context_->thread_num_); + error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(MirrorPadImplInt8, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Pad Reflect or Symmetric mode run error, error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc index 0ca39fbcb6..929c601860 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc @@ -96,8 +96,8 @@ int PoolingInt8Impl(void *cdata, int task_id) { } int PoolingInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - PoolingInt8Impl, this, thread_count_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PoolingInt8Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "poolingInt8 error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc index e69bc31903..4325f2173c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc @@ -99,8 +99,8 @@ int PowerInt8Run(void *cdata, int task_id) { } int PowerInt8CPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, PowerInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(PowerInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerInt8Run error, error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc index 433db6eb45..d95242a2b8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc @@ -458,8 +458,8 @@ int ReduceInt8CPUKernel::Fast4DReduceMeanHWImpl() { } PackNHWCToNCHWInt8(reinterpret_cast(input_data), reinterpret_cast(nchw_in_data_), input->Batch(), input->Height() * input->Width(), input->Channel()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ReduceMeanPatternInt8Impl, this, context_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceMeanPatternInt8Impl, this, context_->thread_num_); if (ret != RET_OK) { ctx_->allocator->Free(nchw_in_data_); MS_LOG(ERROR) << "Reduce run error, error_code[" << ret << "]"; @@ -501,8 +501,8 @@ int ReduceInt8CPUKernel::Run() { outer_size_ = outer_sizes_[i]; inner_size_ = inner_sizes_[i]; axis_size_ = axis_sizes_[i]; - auto error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ReduceInt8Impl, this, context_->thread_num_); + auto error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceInt8Impl, this, context_->thread_num_); if (error_code != RET_OK) { FreeTmpBuffer(); MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; @@ -517,8 +517,8 @@ int ReduceInt8CPUKernel::Run() { axis_size_ = axis_sizes_.back(); last_dst_data_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); is_last_axis_ = true; - auto error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, - ReduceInt8Impl, this, context_->thread_num_); + auto error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReduceInt8Impl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc index 589b8cab9c..7e3c056771 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc @@ -72,8 +72,8 @@ int ReluXInt8Run(void *cdata, int task_id) { } int ReluXInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ReluXInt8Run, - this, op_parameter_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReluXInt8Run, this, op_parameter_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "ReluXInt8Run function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc index a5652d43e2..73c3429978 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc @@ -58,8 +58,8 @@ int ReshapeInt8CPUKernel::Run() { elements_num_ = in_tensors_.at(kInputIndex)->ElementsNum(); count_unit_ = op_parameter_->thread_num_ > 1 ? UP_DIV(elements_num_, op_parameter_->thread_num_) : elements_num_; - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ReshapeInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ReshapeInt8Run, this, op_parameter_->thread_num_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc index 787ec3a464..f5748bfc4b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc @@ -359,8 +359,8 @@ int ResizeInt8CPUKernel::RunImpl(int task_id) { } int ResizeInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, ResizeInt8Impl, - this, context_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ResizeInt8Impl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc index f83d91651f..03f229a8bd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc @@ -319,8 +319,8 @@ int ScaleInt8CPUKernel::Run() { tile_para->in_strides1_, tile_para->out_strides_, tile_para->multiples1_); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ScaleRunInt8, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ScaleRunInt8, this, op_parameter_->thread_num_); // free memory malloced from memory pool if (!scale_param_->const_scale_) { ctx_->allocator->Free(input1_data_); @@ -340,8 +340,8 @@ int ScaleInt8CPUKernel::Run() { if (has_bias_ && !scale_param_->const_offset_) { input2_data_ = reinterpret_cast(in_tensors_.at(2)->data_c()); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, ScaleRunInt8, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(ScaleRunInt8, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc index c4db12e020..ac844535d3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc @@ -89,8 +89,8 @@ int SigmoidInt8Run(void *cdata, int task_id) { } int SigmoidInt8CPUKernel::Run() { - int error_code = ParallelLaunch(static_cast(this->context_)->thread_pool_, SigmoidInt8Run, - this, op_parameter_->thread_num_); + int error_code = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SigmoidInt8Run, this, op_parameter_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "SigmoidInt8Run function error error_code[" << error_code << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc index fef53765b0..6b85ae6e3f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc @@ -79,8 +79,8 @@ int SliceInt8Run(void *cdata, int task_id) { int SliceInt8CPUKernel::Run() { // param_ shape info has already been extended to 8d - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SliceInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SliceInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SliceInt8Run error, error_code[" << ret << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc index 05757407e7..de9432caa8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc @@ -133,8 +133,8 @@ int SoftmaxInt8CPUKernel::Run() { context_->allocator->Free(sum_data_); return RET_ERROR; } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SoftmaxRun, this, - thread_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SoftmaxRun, this, thread_count_); context_->allocator->Free(exp_data_); context_->allocator->Free(sum_data_); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc index d01b152441..1a330fea01 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc @@ -98,8 +98,8 @@ int SplitInt8CPUKernel::Run() { output_ptr_[i] = reinterpret_cast(out_tensors_.at(i)->data_c()); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SplitInt8Run, this, - thread_n_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SplitInt8Run, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc index 1b5a2588b5..dad3ad0197 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc @@ -88,8 +88,8 @@ int SqueezeInt8CPUKernel::Init() { int SqueezeInt8CPUKernel::ReSize() { return RET_OK; } int SqueezeInt8CPUKernel::Run() { - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SqueezeInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SqueezeInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunSqueezeParam failed. errorcode: "; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc index fe6ff0006d..f2971ce6be 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc @@ -156,8 +156,8 @@ int SubInt8CPUKernel::Run() { static_cast(in_tensors_.at(1)->data_c()), reinterpret_cast(tile0_data_), reinterpret_cast(tile1_data_), &tile_para); } - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, SubInt8Run, this, - op_parameter_->thread_num_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(SubInt8Run, this, op_parameter_->thread_num_); if (broadcast_) { context_->allocator->Free(tile0_data_); context_->allocator->Free(tile1_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/tanh_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/tanh_int8.cc index 21c0235201..8eceb0693e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/tanh_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/tanh_int8.cc @@ -71,8 +71,8 @@ int TanhInt8CPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_.at(0)->data_c()); out_ptr_ = reinterpret_cast(out_tensors_.at(0)->data_c()); - ParallelLaunch(static_cast(this->context_)->thread_pool_, TanhInt8Run, this, - thread_count_); + static_cast(this->context_) + ->thread_pool_->ParallelLaunch(TanhInt8Run, this, thread_count_); return RET_OK; } } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc index a700d06a3d..d4a3c59284 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc @@ -163,8 +163,8 @@ int TransposeInt8CPUKernel::Run() { MS_LOG(ERROR) << "MallocTmpBuf error_code[" << ret << "]"; } if (extra_dims_) { - ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, TransposeInt8Run, this, - op_parameter_->thread_num_); + ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(TransposeInt8Run, this, op_parameter_->thread_num_); } else { ret = DoTransposeInt8(in_ptr_, out_ptr_, out_shape_, transpose_param_); } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc index 500ed9c7ca..23e03ae920 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc @@ -85,8 +85,8 @@ int UnsqueezeIn8Run(void *cdata, int task_id) { int Unsqueezeint8CPUKernel::Run() { in_ptr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto ret = ParallelLaunch(static_cast(this->context_)->thread_pool_, UnsqueezeIn8Run, - this, thread_sz_count_); + auto ret = static_cast(this->context_) + ->thread_pool_->ParallelLaunch(UnsqueezeIn8Run, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/parallel_executor.cc b/mindspore/lite/src/runtime/parallel_executor.cc index 601cc2d038..d451194965 100644 --- a/mindspore/lite/src/runtime/parallel_executor.cc +++ b/mindspore/lite/src/runtime/parallel_executor.cc @@ -20,10 +20,10 @@ #include "src/lite_kernel_util.h" namespace mindspore::lite { -ParallelExecutor::~ParallelExecutor() { DestroyThreadPool(thread_pool_); } +ParallelExecutor::~ParallelExecutor() { delete thread_pool_; } int ParallelExecutor::Prepare(const std::vector &kernels, const std::vector &inputs, const std::vector &outputs) { - thread_pool_ = CreateLiteThreadPool(max_thread_num_, NO_BIND); + thread_pool_ = InterThreadPool::CreateThreadPool(1, max_thread_num_, static_cast(NO_BIND)); if (thread_pool_ == nullptr) { MS_LOG(ERROR) << "Memory error: fail to new ThreadPool"; return RET_ERROR; @@ -70,7 +70,7 @@ int ParallelExecutor::Run(const std::vector &in_tensors, const std::ve std::vector newReadyKernels; while (!readyKernels.empty()) { results.resize(readyKernels.size(), RET_OK); - if (0 != ParallelLaunch(thread_pool_, RunKernel, this, readyKernels.size())) { + if (0 != thread_pool_->ParallelLaunch(RunKernel, this, readyKernels.size())) { MS_LOG(ERROR) << "ParallelLaunch failed "; return RET_ERROR; } diff --git a/mindspore/lite/src/runtime/parallel_executor.h b/mindspore/lite/src/runtime/parallel_executor.h index 6c679096b3..bd0b793c6f 100644 --- a/mindspore/lite/src/runtime/parallel_executor.h +++ b/mindspore/lite/src/runtime/parallel_executor.h @@ -24,6 +24,7 @@ #include "src/lite_kernel.h" #include "include/lite_session.h" #include "src/executor.h" +#include "mindrt/src/thread/inter_threadpool.h" namespace mindspore::lite { class ParallelExecutor : public Executor { @@ -44,7 +45,7 @@ class ParallelExecutor : public Executor { std::unordered_map refCount; std::vector readyKernels; std::vector results; - struct ThreadPool *thread_pool_ = nullptr; + InterThreadPool *thread_pool_ = nullptr; int max_thread_num_ = std::thread::hardware_concurrency(); }; diff --git a/mindspore/lite/src/runtime/runtime_api.cc b/mindspore/lite/src/runtime/runtime_api.cc index 93b1a477ac..f218a30a2e 100644 --- a/mindspore/lite/src/runtime/runtime_api.cc +++ b/mindspore/lite/src/runtime/runtime_api.cc @@ -23,8 +23,6 @@ static std::mutex gWorkspaceMutex; extern "C" { #endif -ThreadPool *CreateLiteThreadPool(int thread_num, int mode) { return CreateThreadPool(thread_num, mode); } - void LiteAPISetLastError(const char *msg) { MS_LOG(ERROR) << "The lite api set last error is " << msg; } #ifdef __cplusplus } diff --git a/mindspore/lite/src/runtime/runtime_api.h b/mindspore/lite/src/runtime/runtime_api.h index b9f503a67d..575adb2327 100644 --- a/mindspore/lite/src/runtime/runtime_api.h +++ b/mindspore/lite/src/runtime/runtime_api.h @@ -31,10 +31,7 @@ #ifdef __cplusplus extern "C" { -#include "src/runtime/thread_pool.h" -struct ThreadPool; #endif -INTERNAL_API_DLL ThreadPool *CreateLiteThreadPool(int thread_num, int mode); INTERNAL_API_DLL void LiteAPISetLastError(const char *msg); INTERNAL_API_DLL int LiteBackendRegisterSystemLibSymbol(const char *name, void *ptr); #ifdef __cplusplus diff --git a/mindspore/lite/src/runtime/thread_pool.c b/mindspore/lite/src/runtime/thread_pool.c deleted file mode 100644 index b4f0b34d4e..0000000000 --- a/mindspore/lite/src/runtime/thread_pool.c +++ /dev/null @@ -1,962 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "src/runtime/thread_pool.h" -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -#ifdef __WIN32__ -#include -#endif - -#ifdef __ANDROID__ -#define BIND_CORE -#include -#endif -#ifdef MS_COMPILE_IOS -#include -#include -#include -#endif // MS_COMPILE_IOS - -#ifdef THREAD_POOL_DEBUG -#include -#define LOG_INFO(content, args...) \ - { printf("[INFO] %s|%d|%s: " #content "\r\n", __FILE__, __LINE__, __func__, ##args); } -#define LOG_ERROR(content, args...) \ - { printf("[ERROR] %s|%d|%s: " #content "\r\n", __FILE__, __LINE__, __func__, ##args); } -#else -#define LOG_INFO(content, args...) -#define LOG_ERROR(content, args...) -#endif - -#define RET_TP_OK (0) -#define RET_TP_ERROR (-8) -#define RET_TP_SYSTEM_ERROR (-1) - -#define DEFAULT_SPIN_COUNT (30000) - -typedef struct { - int (*func)(void *arg, int); - void *content; - int *return_code; - int task_num; -} Task; - -typedef struct Thread { - void *thread_pool; - int thread_id; - struct Thread *next; - pthread_t pthread; - Task *task_list[MAX_TASK_NUM]; - atomic_int task_size; - atomic_int head; - atomic_int tail; - atomic_bool activate; - atomic_bool is_running; - sem_t sem; - sem_t sem_inited; -} Thread; - -typedef struct { - Thread *head; - Thread *tail; - pthread_mutex_t lock; - int size; -} ThreadList; - -typedef struct ThreadPool { - ThreadList *thread_list; - int thread_num; - BindMode mode; - atomic_bool is_alive; -} ThreadPool; - -Thread *GetThread(struct ThreadPool *thread_pool, int thread_id) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed, thread_id: %d", thread_id); - return NULL; - } - ThreadList *thread_list = thread_pool->thread_list; - if (thread_list == NULL) { - LOG_ERROR("thead list is null"); - return NULL; - } - if (thread_id >= thread_list->size) { - LOG_ERROR("invalid thread id: %d, thread size: %d", thread_id, thread_list->size); - return NULL; - } - if (thread_id == 0) { - return thread_list->head; - } - Thread *thread = thread_list->head; - while (thread != NULL) { - if (thread->thread_id == thread_id) { - break; - } - thread = thread->next; - } - return thread; -} - -void FreeThread(ThreadList *thread_list, Thread *thread) { - if (thread_list == NULL) { - LOG_ERROR("thead list is null"); - return; - } - if (thread == NULL) { - LOG_ERROR("thread is nullptr"); - return; - } - // only support sequential release - thread_list->head = thread->next; - sem_post(&thread->sem); - while (true) { - if (thread != NULL && !thread->is_running) { - (void)sem_destroy(&thread->sem); - free(thread); - thread = NULL; - break; - } - } -} - -#ifdef BIND_CORE -#define MAX_CORE_NUM (16) -static int gCoreNum = 8; -static int gHigNum = 0; -static int gMidNum = 0; -static int cpu_cores[MAX_CORE_NUM]; -static bool run_once = true; - -#define MAX_CPU_ID (9) -#define MAX_PATH_SIZE (256) - -enum Arch { - UnKnown_Arch = 0, - Cortex_A5, - Cortex_A7, - Cortex_A8, - Cortex_A9, - Cortex_A12, - Cortex_A15, - Cortex_A17, - Cortex_A32, - Cortex_A34, - Cortex_A35, - Cortex_A53, - Cortex_A55, - Cortex_A57, - Cortex_A65, - Cortex_A72, - Cortex_A73, - Cortex_A75, - Cortex_A76, - Cortex_A77, - Cortex_A78, - Cortex_X1 -}; - -typedef struct { - int core_id; - int max_freq; - enum Arch arch; -} CpuInfo; - -int GetCpuCoreNum() { return (int)sysconf(_SC_NPROCESSORS_CONF); } - -static int ConcatCPUPath(int cpuID, const char *str1, const char *str2, char *str3) { - if (cpuID > MAX_CPU_ID || str1 == NULL || str2 == NULL) { - return RET_TP_ERROR; - } - memset(str3, 0, strlen(str3)); - char *tmp = str3; - char id = cpuID + '0'; - memcpy(tmp, str1, strlen(str1)); - tmp += strlen(str1); - memcpy(tmp, &id, 1); - tmp += 1; - memcpy(tmp, str2, strlen(str2)); - return RET_TP_OK; -} - -int GetMaxFrequence(int core_id) { - char path[MAX_PATH_SIZE] = ""; - int ret = ConcatCPUPath(core_id, "/sys/devices/system/cpu/cpufreq/stats/cpu", "/time_in_state", path); - if (ret != RET_TP_OK) { - LOG_ERROR("parse cpuid from /sys/devices/system/cpu/cpufreq/stats/cpu/time_in_state failed!"); - return RET_TP_ERROR; - } - FILE *fp = fopen(path, "rb"); - if (fp == NULL) { - ret = ConcatCPUPath(core_id, "/sys/devices/system/cpu/cpufreq/stats/cpu", "/cpufreq/stats/time_in_state", path); - if (ret != RET_TP_OK) { - LOG_ERROR("parse cpuid from /sys/devices/system/cpu/cpufreq/stats/cpu/cpufreq/stats/time_instate failed!"); - return RET_TP_ERROR; - } - fp = fopen(path, "rb"); - if (fp == NULL) { - ret = ConcatCPUPath(core_id, "/sys/devices/system/cpu/cpu", "/cpufreq/cpuinfo_max_freq", path); - if (ret != RET_TP_OK) { - LOG_ERROR("parse cpuid from /sys/devices/system/cpu/cpufreq/cpuinfo_max_freq failed!"); - return RET_TP_ERROR; - } - fp = fopen(path, "rb"); - if (fp == NULL) { - LOG_ERROR("GetCPUMaxFreq failed, cannot find cpuinfo_max_freq."); - return RET_TP_ERROR; - } - int maxFreq = -1; - int result __attribute__((unused)); - result = fscanf(fp, "%d", &maxFreq); - fclose(fp); - return maxFreq; - } - } - int maxFreq = -1; - while (feof(fp) == 0) { - int freq = 0; - int tmp = fscanf(fp, "%d", &freq); - if (tmp != 1) { - break; - } - if (freq > maxFreq) { - maxFreq = freq; - } - } - fclose(fp); - return maxFreq; -} - -int ParseCpuPart(const char *line, int start, int size) { - int cpu_part = 0; - for (int i = start; i < size && i < start + 3; i++) { - char c = line[i]; - int d; - if (c >= '0' && c <= '9') { - d = c - '0'; - } else if ((c - 'A') < 6) { - d = 10 + (c - 'A'); - } else if ((c - 'a') < 6) { - d = 10 + (c - 'a'); - } else { - LOG_ERROR("CPU part in /proc/cpuinfo is ignored due to unexpected non-hex character"); - break; - } - cpu_part = cpu_part * 16 + d; - } - return cpu_part; -} - -enum Arch GetArch(int cpu_part) { - // https://en.wikipedia.org/wiki/Comparison_of_ARMv7-A_cores - // https://en.wikipedia.org/wiki/Comparison_of_ARMv8-A_cores - switch (cpu_part) { - case 0x800: // High-performance Kryo 260 (r10p2) / Kryo 280 (r10p1) "Gold" -> Cortex-A73 - return Cortex_A73; - case 0x801: // Low-power Kryo 260 / 280 "Silver" -> Cortex-A53 - return Cortex_A53; - case 0x802: // High-performance Kryo 385 "Gold" -> Cortex-A75 - return Cortex_A75; - case 0x803: // Low-power Kryo 385 "Silver" -> Cortex-A55r0 - return Cortex_A55; - case 0x804: // High-performance Kryo 485 "Gold" / "Gold Prime" -> Cortex-A76 - return Cortex_A76; - case 0x805: // Low-performance Kryo 485 "Silver" -> Cortex-A55 - return Cortex_A55; - case 0xC05: - return Cortex_A5; - case 0xC07: - return Cortex_A7; - case 0xC08: - return Cortex_A8; - case 0xC09: - return Cortex_A9; - case 0xC0C: - return Cortex_A12; - case 0xC0D: - return Cortex_A12; - case 0xC0E: - return Cortex_A17; - case 0xC0F: - return Cortex_A15; - case 0xD01: // also Huawei Kunpeng 920 series taishan_v110 when not on android - return Cortex_A32; - case 0xD02: - return Cortex_A34; - case 0xD03: - return Cortex_A53; - case 0xD04: - return Cortex_A35; - case 0xD05: - return Cortex_A55; - case 0xD06: - return Cortex_A65; - case 0xD07: - return Cortex_A57; - case 0xD08: - return Cortex_A72; - case 0xD09: - return Cortex_A73; - case 0xD0A: - return Cortex_A75; - case 0xD0B: - return Cortex_A76; - case 0xD0D: - return Cortex_A77; - case 0xD0E: // Cortex-A76AE - return Cortex_A76; - case 0xD40: // Kirin 980 Big/Medium cores -> Cortex-A76 - return Cortex_A76; - case 0xD41: - return Cortex_A78; - case 0xD43: // Cortex-A65AE - return Cortex_A65; - case 0xD44: - return Cortex_X1; - default: - return UnKnown_Arch; - } -} - -int SetArch(CpuInfo *freq_set, int core_num) { - if (core_num <= 0) { - LOG_ERROR("core_num must be greater than 0."); - return RET_TP_ERROR; - } - FILE *fp = fopen("/proc/cpuinfo", "r"); - if (fp == NULL) { - LOG_ERROR("read /proc/cpuinfo error."); - return RET_TP_ERROR; - } - enum Arch *archs = malloc(core_num * sizeof(enum Arch)); - if (archs == NULL) { - fclose(fp); - LOG_ERROR("malloc memory for archs error."); - return RET_TP_ERROR; - } - const int max_line_size = 1024; - char line[max_line_size] = {0}; - int count = 0; - while (!feof(fp)) { - fgets(line, max_line_size, fp); - // line start with "CPU part" - if (0 == memcmp(line, "CPU part", 8)) { - // get number like 0xD03 - for (int i = 0; i < max_line_size - 4; ++i) { - if (line[i] == '0' && line[i + 1] == 'x') { - int cpu_part = ParseCpuPart(line, i + 2, max_line_size); - enum Arch arch = GetArch(cpu_part); - if (arch == UnKnown_Arch) { - LOG_ERROR("cpu's architecture is unknown."); - free(archs); - fclose(fp); - return RET_TP_ERROR; - } - count++; - if (count > core_num) { - LOG_ERROR("number of cpu_part in /proc/cpuinfo is more than core_num."); - free(archs); - fclose(fp); - return RET_TP_ERROR; - } - archs[count - 1] = arch; - } - } - } - } - if (count < core_num) { - LOG_ERROR("number of cpu_part in /proc/cpuinfo is less than core_num."); - free(archs); - fclose(fp); - return RET_TP_ERROR; - } - for (int i = 0; i < core_num; ++i) { - freq_set[i].arch = archs[i]; - } - free(archs); - fclose(fp); - return RET_TP_OK; -} - -int SortCpuProcessor() { - gCoreNum = GetCpuCoreNum(); - if (gCoreNum <= 0) { - LOG_ERROR("invalid cpu count"); - return RET_TP_ERROR; - } - CpuInfo freq_set[gCoreNum]; - for (int i = 0; i < gCoreNum; ++i) { - int max_freq = GetMaxFrequence(i); - freq_set[i].core_id = i; - freq_set[i].max_freq = max_freq; - freq_set[i].arch = UnKnown_Arch; - } - int err_code = SetArch(freq_set, gCoreNum); - if (err_code != RET_TP_OK) { - LOG_INFO("set arch failed, ignoring arch."); - } - // sort core id by frequency into descending order - for (int i = 0; i < gCoreNum; ++i) { - for (int j = i + 1; j < gCoreNum; ++j) { - if (freq_set[i].max_freq < freq_set[j].max_freq || - (freq_set[i].max_freq == freq_set[j].max_freq && freq_set[i].arch <= freq_set[j].arch)) { - CpuInfo temp = freq_set[i]; - freq_set[i] = freq_set[j]; - freq_set[j] = temp; - } - } - } - for (int i = 0; i < gCoreNum; ++i) { - cpu_cores[i] = freq_set[i].core_id; - LOG_INFO("sorted_order: %d, frequency: %d", freq_set[i].core_id, freq_set[i].max_freq); - } - gHigNum = 0; - gMidNum = 0; - int max_freq = freq_set[0].max_freq; - int min_freq = freq_set[gCoreNum - 1].max_freq; - int little = 0; - for (int i = 0; i < gCoreNum; ++i) { - if (freq_set[i].max_freq == max_freq) { - gHigNum++; - } - if (freq_set[i].max_freq == min_freq) { - little++; - } - } - gMidNum = gCoreNum - gHigNum - little; - if (gHigNum == gCoreNum || max_freq == min_freq) { - // fix MTK800 - gHigNum = 2; - gMidNum = 2; - LOG_INFO("core frequency may be wrong."); - } - LOG_INFO("gCoreNum: %d, gHigNum: %d, gMidNum: %d, gLitNum: %d", gCoreNum, gHigNum, gMidNum, little); - return RET_TP_OK; -} - -#ifndef CPU_SET -#define CPU_SETSIZE 1024 -#define __NCPUBITS (8 * sizeof(unsigned long)) -typedef struct { - unsigned long __bits[CPU_SETSIZE / __NCPUBITS]; -} cpu_set_t; -#define CPU_SET(cpu, cpusetp) ((cpusetp)->__bits[(cpu) / __NCPUBITS] |= (1UL << ((cpu) % __NCPUBITS))) -#define CPU_ZERO(cpusetp) memset((cpusetp), 0, sizeof(cpu_set_t)) -#endif // CPU_SET - -int SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) { -#ifdef __ANDROID__ -#if __ANDROID_API__ >= 21 - LOG_INFO("thread: %d, mask: %lu", pthread_gettid_np(thread_id), cpuSet->__bits[0]); - int ret = sched_setaffinity(pthread_gettid_np(thread_id), sizeof(cpu_set_t), cpuSet); - if (ret != RET_TP_OK) { - LOG_ERROR("bind thread %d to cpu failed. ERROR %d", pthread_gettid_np(thread_id), ret); - return RET_TP_OK; - } -#endif -#else -#if defined(__APPLE__) - LOG_ERROR("not bind thread to apple's cpu."); - return RET_TP_ERROR; -#else - int ret = pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), cpuSet); - if (ret != RET_TP_OK) { - LOG_ERROR("set thread: %d to cpu failed", thread_id); - return RET_TP_SYSTEM_ERROR; - } -#endif // __APPLE__ -#endif - return RET_TP_OK; -} - -int BindMasterThread(struct ThreadPool *thread_pool, bool is_bind) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return RET_TP_ERROR; - } - cpu_set_t mask; - CPU_ZERO(&mask); - if (is_bind) { - unsigned int attach_id; - if (thread_pool->mode == MID_MODE) { - attach_id = cpu_cores[gHigNum + gMidNum - 1]; - } else { - attach_id = cpu_cores[0]; - } - LOG_INFO("mode: %d, attach id: %u", thread_pool->mode, attach_id); - CPU_SET(attach_id, &mask); - } else { - for (int i = 0; i < gHigNum + gMidNum; ++i) { - CPU_SET(cpu_cores[i], &mask); - } - } - int ret = SetAffinity(pthread_self(), &mask); - if (ret != RET_TP_OK) { - LOG_ERROR("set master thread affinity failed"); - return RET_TP_ERROR; - } - LOG_INFO("BindMasterThread success."); - return RET_TP_OK; -} - -int FreeBindSalverThreads(struct ThreadPool *thread_pool) { - cpu_set_t mask; - CPU_ZERO(&mask); - for (int i = 0; i < gHigNum + gMidNum; ++i) { - CPU_SET(cpu_cores[i], &mask); - } - for (int i = 0; i < thread_pool->thread_num - 1; ++i) { - Thread *thread = GetThread(thread_pool, i); - if (thread == NULL) { - LOG_ERROR("get thread failed, thread_id: %d", i); - return false; - } - int ret = SetAffinity(thread->pthread, &mask); - if (ret != RET_TP_OK) { - LOG_ERROR("set thread affinity failed"); - return RET_TP_ERROR; - } - } - return RET_TP_OK; -} - -int DoBindSalverThreads(struct ThreadPool *thread_pool) { - cpu_set_t mask; - unsigned int attach_id; - for (int i = 0; i < thread_pool->thread_num - 1; ++i) { - if (thread_pool->mode == MID_MODE) { - int core_id = gHigNum + gMidNum - i - 2; - if (core_id >= 0) { - attach_id = cpu_cores[core_id]; - } else { - attach_id = cpu_cores[0]; - } - } else { - attach_id = cpu_cores[i + 1]; - } - LOG_INFO("mode: %d, attach id: %u", thread_pool->mode, attach_id); - CPU_ZERO(&mask); - CPU_SET(attach_id, &mask); - Thread *thread = GetThread(thread_pool, i); - if (thread == NULL) { - LOG_ERROR("get thread failed, thread_id: %d", i); - return false; - } - int ret = SetAffinity(thread->pthread, &mask); - if (ret != RET_TP_OK) { - LOG_ERROR("set thread affinity failed"); - return RET_TP_ERROR; - } - } - return RET_TP_OK; -} - -int BindSalverThreads(struct ThreadPool *thread_pool, bool is_bind) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return RET_TP_ERROR; - } - int ret; - if (is_bind && thread_pool->mode != NO_BIND_MODE) { - ret = DoBindSalverThreads(thread_pool); - } else { - ret = FreeBindSalverThreads(thread_pool); - } - if (ret == RET_TP_OK) { - LOG_INFO("BindSalverThreads success"); - } - return ret; -} -#endif - -int BindThreads(struct ThreadPool *thread_pool, bool is_bind, int mode) { -#ifdef BIND_CORE - if (mode == NO_BIND_MODE) { - return RET_TP_OK; - } - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return RET_TP_ERROR; - } - thread_pool->mode = mode; - int ret = BindMasterThread(thread_pool, is_bind); - if (ret != RET_TP_OK) { - LOG_ERROR("bind master thread failed."); - } - ret = BindSalverThreads(thread_pool, is_bind); - if (ret != RET_TP_OK) { - LOG_ERROR("bind salver thread failed."); - } - return ret; -#else - return RET_TP_OK; -#endif -} - -bool PushTaskToQueue(struct ThreadPool *thread_pool, int thread_id, Task *task) { - Thread *thread = GetThread(thread_pool, thread_id); - if (thread == NULL) { - LOG_ERROR("get thread failed, thread_id: %d", thread_id); - return false; - } - const int tail_index = atomic_load_explicit(&thread->tail, memory_order_relaxed); - int next = (tail_index + 1) % MAX_TASK_NUM; - if (next == atomic_load_explicit(&thread->head, memory_order_acquire)) { - return false; - } - thread->task_list[tail_index] = task; - atomic_store_explicit(&thread->tail, next, memory_order_release); - atomic_fetch_add_explicit(&thread->task_size, 1, memory_order_relaxed); - sem_post(&thread->sem); - return true; -} - -bool PopTaskFromQueue(Thread *thread, Task **task) { - if (thread == NULL) { - LOG_ERROR("thread is nullptr"); - return false; - } - if (atomic_load_explicit(&thread->task_size, memory_order_relaxed) == 0) { - return false; - } - const int head_index = atomic_load_explicit(&thread->head, memory_order_relaxed); - if (head_index == atomic_load_explicit(&thread->tail, memory_order_acquire)) { - return false; - } - *task = thread->task_list[head_index]; - atomic_store_explicit(&thread->head, (head_index + 1) % MAX_TASK_NUM, memory_order_release); - return true; -} - -void WaitAllThread(struct ThreadPool *thread_pool) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return; - } - bool k_success_flag = false; - while (!k_success_flag) { - k_success_flag = true; - for (int i = 0; i < thread_pool->thread_num - 1; ++i) { - Thread *thread = GetThread(thread_pool, i); - if (thread == NULL) { - LOG_ERROR("get thread failed, thread_id: %d", i); - return; - } - if (atomic_load_explicit(&thread->task_size, memory_order_acquire) != 0) { - k_success_flag = false; - break; - } - } - } -} - -int DistributeTask(struct ThreadPool *thread_pool, Task *task, int task_num) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return RET_TP_ERROR; - } - if (task_num > thread_pool->thread_num || task_num <= 1) { - LOG_ERROR("invalid task num: %d, thread num: %d", task_num, thread_pool->thread_num); - return RET_TP_ERROR; - } - bool k_success_flag = false; - if (thread_pool->thread_num < task_num) { - LOG_ERROR("task_num: %d should not be larger than thread num: %d", task_num, thread_pool->thread_num); - return RET_TP_ERROR; - } - for (int i = 0; i < task_num - 1; ++i) { - do { - k_success_flag = true; - if (!PushTaskToQueue(thread_pool, i, task)) { - k_success_flag = false; - } - } while (!k_success_flag); - } - // master thread - if (task->func == NULL) { - LOG_ERROR("task->func is nullptr"); - return RET_TP_ERROR; - } - if (task->task_num <= task_num - 1) { - LOG_ERROR("task_num out of range in master thread"); - return RET_TP_ERROR; - } - task->return_code[task_num - 1] = task->func(task->content, task_num - 1); - // wait - WaitAllThread(thread_pool); - for (size_t i = 0; i < task->task_num; i++) { - if (task->return_code[i] != 0) { - return task->return_code[i]; - } - } - return RET_TP_OK; -} - -int AddTask(struct ThreadPool *thread_pool, int func(void *, int), void *content, int task_num) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return RET_TP_ERROR; - } - // if single thread, run master thread - if (thread_pool->thread_num <= 1 || task_num <= 1) { - for (int i = 0; i < task_num; ++i) { - int ret = func(content, i); - if (ret != 0) { - return ret; - } - } - return RET_TP_OK; - } - Task task; - task.func = func; - task.content = content; - task.return_code = (int *)malloc(sizeof(int) * task_num); - task.task_num = task_num; - if (task.return_code == NULL) { - LOG_ERROR("malloc return code return nullptr"); - return RET_TP_ERROR; - } - memset(task.return_code, 0, sizeof(int) * task_num); - int ret = DistributeTask(thread_pool, &task, task_num); - free(task.return_code); - return ret; -} - -int ParallelLaunch(struct ThreadPool *thread_pool, int (*func)(void *, int), void *content, int task_num) { - return AddTask(thread_pool, func, content, task_num); -} - -void ThreadRun(Thread *thread) { - thread->is_running = true; - ThreadPool *thread_pool = (ThreadPool *)(thread->thread_pool); - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - thread->is_running = false; - return; - } - Task *task = NULL; - int thread_id = thread->thread_id; - int spin_count = 0; - sem_post(&thread->sem_inited); - while (thread_pool->is_alive) { - while (thread->activate) { - if (PopTaskFromQueue(thread, &task)) { - if (task->func == NULL) { - LOG_ERROR("task->func is nullptr"); - return; - } - if (task->task_num <= thread_id) { - LOG_ERROR("task_num out of range in worker thread"); - return; - } - task->return_code[thread_id] = task->func(task->content, thread_id); - atomic_fetch_sub_explicit(&thread->task_size, 1, memory_order_release); - spin_count = 0; - sem_trywait(&thread->sem); - } else { - sched_yield(); - spin_count++; - } - if (spin_count == DEFAULT_SPIN_COUNT) { - break; - } - } - sem_wait(&thread->sem); - } - thread->is_running = false; -} - -void PushThreadToList(struct ThreadPool *thread_pool, Thread *thread) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return; - } - ThreadList *thread_list = thread_pool->thread_list; - if (thread_list == NULL) { - LOG_ERROR("thread list is null"); - DestroyThreadPool(thread_pool); - return; - } - pthread_mutex_lock(&thread_list->lock); - if (thread_list->size == 0) { - thread_list->head = thread; - thread_list->tail = thread; - } else { - thread_list->tail->next = thread; - thread_list->tail = thread; - } - thread_list->size++; - pthread_mutex_unlock(&thread_list->lock); -} - -int CreateNewThread(struct ThreadPool *thread_pool, int thread_id) { - LOG_INFO("create thread: %d", thread_id); - Thread *thread = (Thread *)malloc(sizeof(Thread)); - if (thread == NULL) { - LOG_ERROR("create thread failed"); - DestroyThreadPool(thread_pool); - return RET_TP_ERROR; - } - thread->thread_pool = thread_pool; - thread->thread_id = thread_id; - thread->head = ATOMIC_VAR_INIT(0); - thread->tail = ATOMIC_VAR_INIT(0); - thread->task_size = ATOMIC_VAR_INIT(0); - thread->activate = ATOMIC_VAR_INIT(true); - thread->is_running = ATOMIC_VAR_INIT(true); - thread->next = NULL; - sem_init(&thread->sem, 0, 0); - sem_init(&thread->sem_inited, 0, 0); - PushThreadToList(thread_pool, thread); - pthread_create(&thread->pthread, NULL, (void *)ThreadRun, thread); - sem_wait(&thread->sem_inited); - pthread_detach(thread->pthread); - return RET_TP_OK; -} - -ThreadPool *CreateThreadPool(int thread_num, int mode) { -#ifdef __WIN32__ - SYSTEM_INFO sys_info; - GetSystemInfo(&sys_info); - long max_thread_num = sys_info.dwNumberOfProcessors; -#else - long max_thread_num = sysconf(_SC_NPROCESSORS_ONLN); -#endif - LOG_INFO("create thread pool, thread_num: %d, mode: %d", thread_num, mode); - if (thread_num <= 0 || thread_num > max_thread_num) { - LOG_ERROR("invalid thread num: %d", thread_num); - return NULL; - } -#ifdef BIND_CORE - if (run_once) { - int ret = SortCpuProcessor(); - run_once = false; - if (ret != RET_TP_OK) { - LOG_ERROR("SortCpuProcessor failed"); - return NULL; - } - } -#endif - ThreadPool *thread_pool = (struct ThreadPool *)(malloc(sizeof(ThreadPool))); - if (thread_pool == NULL) { - LOG_ERROR("Malloc ThreadPool failed"); - return NULL; - } - thread_pool->thread_num = thread_num > max_thread_num ? max_thread_num : thread_num; - thread_pool->is_alive = ATOMIC_VAR_INIT(true); - thread_pool->mode = mode; - thread_pool->thread_list = NULL; - if (thread_num > 1) { - thread_pool->thread_list = (ThreadList *)malloc(sizeof(ThreadList)); - if (thread_pool->thread_list == NULL) { - LOG_ERROR("create thread list failed"); - DestroyThreadPool(thread_pool); - thread_pool = NULL; - return NULL; - } - thread_pool->thread_list->head = NULL; - thread_pool->thread_list->tail = NULL; - thread_pool->thread_list->size = 0; - pthread_mutex_init(&thread_pool->thread_list->lock, NULL); - } - for (int i = 0; i < thread_pool->thread_num - 1; ++i) { - int ret = CreateNewThread(thread_pool, i); - if (ret != RET_TP_OK) { - LOG_ERROR("create thread %d failed", i); - DestroyThreadPool(thread_pool); - thread_pool = NULL; - return NULL; - } - } - if (thread_pool == NULL) { - LOG_ERROR("create thread failed"); - DestroyThreadPool(thread_pool); - return NULL; - } - return thread_pool; -} - -void ActivateThreadPool(struct ThreadPool *thread_pool) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return; - } - ThreadList *thread_list = thread_pool->thread_list; - if (thread_list == NULL) { - LOG_ERROR("thread pool's list is null"); - return; - } - Thread *thread = thread_list->head; - while (thread != NULL) { - sem_post(&thread->sem); - thread->activate = true; - thread = thread->next; - } -} - -void DeactivateThreadPool(struct ThreadPool *thread_pool) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return; - } - ThreadList *thread_list = thread_pool->thread_list; - if (thread_list == NULL) { - LOG_ERROR("thread pool's list is null"); - return; - } - Thread *thread = thread_list->head; - while (thread != NULL) { - thread->activate = false; - thread = thread->next; - } -} - -void DestroyThreadPool(struct ThreadPool *thread_pool) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return; - } - if (thread_pool->thread_list == NULL) { - LOG_ERROR("thread pool's list is null"); - return; - } - DeactivateThreadPool(thread_pool); - thread_pool->is_alive = false; - LOG_ERROR("DestroyThreadPool thread num : %d", thread_pool->thread_num); - for (int i = 0; i < thread_pool->thread_num - 1; ++i) { - Thread *thread = GetThread(thread_pool, i); - if (thread != NULL) { - FreeThread(thread_pool->thread_list, thread); - } - } - free(thread_pool->thread_list); - thread_pool->thread_list = NULL; - LOG_INFO("destroy thread pool success"); -} - -int GetCurrentThreadNum(struct ThreadPool *thread_pool) { - if (thread_pool == NULL) { - LOG_ERROR("get thread pool instance failed"); - return 0; - } - return thread_pool->thread_num; -} diff --git a/mindspore/lite/src/runtime/thread_pool.h b/mindspore/lite/src/runtime/thread_pool.h deleted file mode 100644 index cfde32f7d3..0000000000 --- a/mindspore/lite/src/runtime/thread_pool.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_ - -#include - -#define MAX_TASK_NUM (2) - -/// \brief BindMode defined for holding bind cpu strategy argument. -typedef enum { - NO_BIND_MODE = 0, /**< no bind */ - HIGHER_MODE = 1, /**< bind higher cpu first */ - MID_MODE = 2 /**< bind middle cpu first */ -} BindMode; - -struct ThreadPool; - -struct ThreadPool *CreateThreadPool(int thread_num, int mode); - -/** - * - * @param session_index, support multi session - * @param job - * @param content - * @param task_num - */ -int ParallelLaunch(struct ThreadPool *thread_pool, int (*job)(void *, int), void *content, int task_num); - -/** - * bind each thread to specified cpu core - * @param is_bind - * @param mode - */ -int BindThreads(struct ThreadPool *thread_pool, bool is_bind, int mode); - -/** - * activate the thread pool - * @param thread_pool_id - */ -void ActivateThreadPool(struct ThreadPool *thread_pool); - -/** - * deactivate the thread pool - * @param thread_pool_id - */ -void DeactivateThreadPool(struct ThreadPool *thread_pool); - -/** - * - * @return current thread num - */ -int GetCurrentThreadNum(struct ThreadPool *thread_pool); - -/** - * destroy thread pool, and release resource - */ -void DestroyThreadPool(struct ThreadPool *thread_pool); - -#endif // MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_ diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index d96bdc74b0..7176e3aa44 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -76,7 +76,6 @@ set(TEST_LITE_SRC ${KERNEL_OP_SRC} ${LITE_DIR}/src/runtime/allocator.cc ${LITE_DIR}/src/runtime/runtime_api.cc - ${LITE_DIR}/src/runtime/thread_pool.c ${LITE_DIR}/src/runtime/parallel_executor.cc ${LITE_DIR}/src/runtime/infer_manager.cc ${LITE_DIR}/src/tensor.cc @@ -150,12 +149,14 @@ if(ENABLE_MINDRT) ${CORE_DIR}/mindrt/src/actor/actor.cc ${CORE_DIR}/mindrt/src/actor/actormgr.cc ${CORE_DIR}/mindrt/src/actor/actorpolicy.cc - ${CORE_DIR}/mindrt/src/actor/actorthread.cc ${CORE_DIR}/mindrt/src/actor/aid.cc ${CORE_DIR}/mindrt/src/async/async.cc ${CORE_DIR}/mindrt/src/async/future.cc ${CORE_DIR}/mindrt/src/async/uuid_base.cc ${CORE_DIR}/mindrt/src/async/uuid_generator.cc + ${CORE_DIR}/mindrt/src/thread/threadpool.cc + ${CORE_DIR}/mindrt/src/thread/core_affinity.cc + ${CORE_DIR}/mindrt/src/thread/inter_threadpool.cc ) endif() diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/constant_of_shape_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/constant_of_shape_fp32_test.cc index bf9430e450..7f82a80769 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/constant_of_shape_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/constant_of_shape_fp32_test.cc @@ -66,6 +66,7 @@ TEST_F(TestConstantOfShapeFp32, Simple) { printf("\n"); ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete op; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/crop_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/crop_fp32_test.cc index d966011f76..010181bc58 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/crop_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/crop_fp32_test.cc @@ -283,5 +283,6 @@ TEST_F(CropTestFp32, CropTest11) { } std::cout << "\n"; ASSERT_EQ(0, CompareOutputData(output, expect_out, kOutSize, 0.000001)); + delete ctx; } } // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc index f882642d7f..7aca4d0a61 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc @@ -491,6 +491,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest1) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete deconv_param; delete deconv; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); @@ -558,6 +559,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest2) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete deconv; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); @@ -636,6 +638,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest3) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete deconv; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); @@ -721,6 +724,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest4) { printf("deconv fp32 average time : %f ms\n", time_avg / 1000.0f); delete deconv; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/detection_post_process_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/detection_post_process_test.cc index bd3ef00e34..eb3294451c 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/detection_post_process_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/detection_post_process_test.cc @@ -158,6 +158,7 @@ TEST_F(TestDetectionPostProcessFp32, Fast) { ASSERT_EQ(0, CompareOutputData(output_num_det, correct_num_det, outputs_[3]->ElementsNum(), 0.0001)); delete op; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc index 6be70d436b..0c20c6e203 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc @@ -69,6 +69,7 @@ TEST_F(TestEluFp32, EluTest) { std::cout << out[i] << ' '; } std::cout << std::endl; + delete ctx; } }; // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc index ccbffb38ad..dfcd4b3276 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc @@ -87,6 +87,7 @@ TEST_F(TestFcFp32, FcTest1) { fc->Init(); fc->Run(); ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); + delete ctx; } int FcTestInit2(std::vector *inputs_, std::vector *outputs_, @@ -146,6 +147,7 @@ TEST_F(TestFcFp32, FcTest2) { fc->Init(); fc->Run(); ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); + delete ctx; } void FcTestInit3(std::vector *inputs_, std::vector *outputs_, @@ -198,6 +200,7 @@ TEST_F(TestFcFp32, FcTest3) { for (int i = 0; i < 100000; ++i) fc->Run(); gettimeofday(&end, nullptr); // printf("## elapsed: %llu\n", 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - end.tv_usec); + delete ctx; } } // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc index d0f1282f13..73f9d42b67 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc @@ -142,6 +142,7 @@ TEST_F(TestMatMulFp32, simple) { -0.3049793541431427, -0.027687929570674896, -0.18109679222106934}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete mm; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } @@ -175,6 +176,7 @@ TEST_F(TestMatMulFp32, simple_bias) { -0.3049793541431427 + 1, -0.027687929570674896 + 2, -0.18109679222106934 + 3}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete mm; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } @@ -266,6 +268,7 @@ TEST_F(TestMatMulFp32, simple2) { 243, 319, 346}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete mm; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } @@ -296,6 +299,7 @@ TEST_F(TestMatMulFp32, simple_transb) { float correct[] = {0.00533547, 0.002545945, 0.062974121, -0.445441471, -0.246223617, -0.142070031}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete mm; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } @@ -350,6 +354,7 @@ TEST_F(TestMatMulFp32, batch) { 8.869029998779297, 25.034008026123047}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete mm; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc index c2a1beffc0..f52d817622 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc @@ -81,6 +81,7 @@ TEST_F(TestPowerFp32, Simple) { float correct[] = {1, 64, 2187, 65536}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete op; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } @@ -105,6 +106,7 @@ TEST_F(TestPowerFp32, Broadcast) { float correct[] = {1, 4, 9, 16}; ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 0.0001)); delete op; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; } diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/skip_gram_fp32.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/skip_gram_fp32.cc index f250ff768a..4e4cdf18ff 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/skip_gram_fp32.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/skip_gram_fp32.cc @@ -73,6 +73,7 @@ TEST_F(TestSkipGramFp32, ElTest) { } printf("\n"); } + delete ctx; } } // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/conv_1x1_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/conv_1x1_int8_tests.cc index 5151a149fe..aef8177dd3 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/conv_1x1_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/conv_1x1_int8_tests.cc @@ -133,6 +133,7 @@ TEST_F(TestConv1x1Int8, Conv1x1TestPerChannel) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 70)); delete conv1x1; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); @@ -202,6 +203,7 @@ TEST_F(TestConv1x1Int8, Conv1x1Int8Test1) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 2)); delete conv1x1; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); @@ -279,6 +281,7 @@ TEST_F(TestConv1x1Int8, Conv1x1Int8Test2) { ASSERT_EQ(0, CompareOutputData(reinterpret_cast(outputs_[0]->MutableData()), correct, total_size, 2)); delete conv1x1; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc index 5899902eea..ddba197bdc 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc @@ -331,6 +331,7 @@ TEST_F(TestDeconvInt8, DeConvInt8Test1) { delete deconv_param; delete deconv; + delete ctx; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; free(correct); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc index 5479d6f4cd..db72d08023 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc @@ -137,6 +137,7 @@ TEST_F(TestMatmulInt8, mmtest1) { Dequantize(reinterpret_cast(outputs[0]->MutableData()), outputs[0]->ElementsNum(), out_scale, out_zp, out); ASSERT_EQ(0, CompareOutputData(out, correct, 6, 0.3)); delete mm; + delete ctx; for (auto t : inputs) delete t; for (auto t : outputs) delete t; delete[] out; diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index 59fd14ee26..41f1113476 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -116,7 +116,6 @@ set(LITE_SRC ${SRC_DIR}/common/tensor_util.cc ${SRC_DIR}/runtime/allocator.cc ${SRC_DIR}/runtime/runtime_api.cc - ${SRC_DIR}/runtime/thread_pool.c ${SRC_DIR}/runtime/infer_manager.cc ${SRC_DIR}/inner_context.cc ${SRC_DIR}/tensor.cc @@ -140,23 +139,25 @@ set(LITE_SRC ${SRC_DIR}/train/train_populate_parameter.cc ) -set(ENABLE_MINDRT "off") if(ENABLE_MINDRT) include_directories(${CORE_DIR}/mindrt/) + include_directories(${CORE_DIR}/mindrt/include/) include_directories(${CORE_DIR}/mindrt/src/) set(MINDRT_SRC ${SRC_DIR}/lite_mindrt.cc ${SRC_DIR}/mindrt_executor.cc - ${CORE_DIR}/mindrt/src/litebus.cc + ${CORE_DIR}/mindrt/src/mindrt.cc ${CORE_DIR}/mindrt/src/actor/actor.cc ${CORE_DIR}/mindrt/src/actor/actormgr.cc ${CORE_DIR}/mindrt/src/actor/actorpolicy.cc - ${CORE_DIR}/mindrt/src/actor/actorthread.cc ${CORE_DIR}/mindrt/src/actor/aid.cc ${CORE_DIR}/mindrt/src/async/async.cc ${CORE_DIR}/mindrt/src/async/future.cc ${CORE_DIR}/mindrt/src/async/uuid_base.cc ${CORE_DIR}/mindrt/src/async/uuid_generator.cc + ${CORE_DIR}/mindrt/src/thread/threadpool.cc + ${CORE_DIR}/mindrt/src/thread/core_affinity.cc + ${CORE_DIR}/mindrt/src/thread/inter_threadpool.cc ) endif() diff --git a/tests/ut/cpp/CMakeLists.txt b/tests/ut/cpp/CMakeLists.txt index f12d2cbe7a..962f143ddd 100644 --- a/tests/ut/cpp/CMakeLists.txt +++ b/tests/ut/cpp/CMakeLists.txt @@ -21,6 +21,7 @@ include_directories(${PYTHON_INCLUDE_DIRS}) include_directories(${MS_CCSRC_PATH}) include_directories(${CMAKE_SOURCE_DIR}/mindspore/core) include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/include) +include_directories(${CMAKE_SOURCE_DIR}/mindspore/core/mindrt/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/stub/runtime/) include_directories(${CMAKE_BINARY_DIR})