forked from mindspore-Ecosystem/mindspore
!31615 [MSLITE][CPU] OP Dynamic thread use DYNAMIC_THREAD_DISTRIBUTE
Merge pull request !31615 from Greatpan/dynamic_thread
This commit is contained in:
commit
5af32769e3
|
@ -152,7 +152,6 @@ if(MSLITE_ENABLE_SHARING_MODEL_WEIGHT)
|
|||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pack_weight_manager.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/thread_cost_model.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "include/api/context.h"
|
||||
#include "include/api/kernel.h"
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
#include "src/thread_cost_model.h"
|
||||
#endif
|
||||
|
||||
|
@ -59,7 +59,7 @@ class InnerKernel : public Kernel {
|
|||
FreeWorkspace();
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (thread_cost_context_ != nullptr) {
|
||||
free(thread_cost_context_);
|
||||
thread_cost_context_ = nullptr;
|
||||
|
@ -207,7 +207,7 @@ class InnerKernel : public Kernel {
|
|||
const lite::Context *ms_context_ = nullptr;
|
||||
|
||||
int thread_num_ = 1;
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
lite::ThreadCostContext *thread_cost_context_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ using mindspore::lite::RET_OK;
|
|||
|
||||
namespace mindspore::kernel {
|
||||
namespace {
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
const std::map<std::pair<int, int>, float> arithmetic_compute_cost_map_ = {
|
||||
{{schema::PrimitiveType_MulFusion, schema::ActivationType_RELU}, 1.806f}, // dataNum about 100k
|
||||
{{schema::PrimitiveType_MulFusion, schema::ActivationType_RELU6}, 1.806f}, // dataNum about 100k
|
||||
|
@ -332,7 +332,7 @@ void ArithmeticBaseCPUKernel::ComputeOfflineInfo() {
|
|||
|
||||
int ArithmeticBaseCPUKernel::ChooseThreadCuttingstrategy() {
|
||||
auto total_num = out_tensors_.front()->ElementsNum();
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ void ArithmeticBaseCPUKernel::ComputeOffset(int task_id) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int ArithmeticBaseCPUKernel::UpdateThreadNumPass() {
|
||||
std::pair<int, int> fusion_type = std::make_pair(primitive_type_, param_->activation_type_);
|
||||
if (thread_cost_context_ == nullptr && arithmetic_compute_cost_map_.count(fusion_type) > 0) {
|
||||
|
|
|
@ -89,7 +89,7 @@ class ArithmeticBaseCPUKernel : public InnerKernel {
|
|||
int BroadCastConstTensor();
|
||||
void ComputeOfflineInfo();
|
||||
int ChooseThreadCuttingstrategy();
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
void ComputeOffset(int task_id);
|
||||
|
|
|
@ -25,7 +25,7 @@ using mindspore::lite::RET_OK;
|
|||
using mindspore::schema::PrimitiveType_Split;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int SplitBaseCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr && num_unit_ > 0) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
@ -122,7 +122,7 @@ int SplitBaseCPUKernel::ReSize() {
|
|||
MS_CHECK_FALSE(INT_MUL_OVERFLOW(param->split_count_, param->num_split_), RET_ERROR);
|
||||
num_unit_ = param->split_count_ * param->num_split_;
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class SplitBaseCPUKernel : public InnerKernel {
|
|||
int Run() override;
|
||||
virtual int Split(int task_id);
|
||||
static int CheckAndInitSplitParam(const lite::Tensor &in_tensor, SplitParameter *param);
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static inline int GetOuterSize(const std::vector<int> &in_shape, int axis) {
|
|||
return outer_size;
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int StackBaseCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
@ -88,7 +88,7 @@ int StackBaseCPUKernel::ReSize() {
|
|||
outer_size_ = GetOuterSize(input0_shape, axis_);
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class StackBaseCPUKernel : public InnerKernel {
|
|||
int ReSize() override;
|
||||
int Run() override;
|
||||
int StackExecute(int task_id);
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ void StridedSliceCPUKernel::InitFastRunParam() {
|
|||
|
||||
outer_ == 1 ? (parallel_on_split_axis_ = true) : (parallel_on_outer_ = true);
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
MS_LOG(ERROR) << "thread num update thread file.";
|
||||
return;
|
||||
|
@ -75,7 +75,7 @@ void StridedSliceCPUKernel::InitFastRunParam() {
|
|||
parallel_on_split_axis_ ? UP_DIV(out_shape[split_axis_], thread_num_) : UP_DIV(outer_, thread_num_);
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int StridedSliceCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
|
|
@ -39,7 +39,7 @@ class StridedSliceCPUKernel : public InnerKernel {
|
|||
int NormalRun();
|
||||
int FastRun();
|
||||
int FastRunImpl(int task_id);
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ using mindspore::schema::PrimitiveType_Activation;
|
|||
|
||||
namespace mindspore::kernel {
|
||||
namespace {
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
const std::map<int, float> activation_compute_cost_map_ = {
|
||||
{schema::ActivationType_RELU, 1.806f}, // dataNum about 100k
|
||||
{schema::ActivationType_RELU6, 1.806f}, // dataNum about 100k
|
||||
|
@ -47,7 +47,7 @@ const std::map<int, float> activation_compute_cost_map_ = {
|
|||
#endif
|
||||
} // namespace
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int ActivationCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr && activation_compute_cost_map_.count(type_) > 0) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
@ -96,7 +96,7 @@ int ActivationCPUKernel::Prepare() {
|
|||
}
|
||||
|
||||
int ActivationCPUKernel::ReSize() {
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class ActivationCPUKernel : public InnerKernel {
|
|||
}
|
||||
~ActivationCPUKernel() override = default;
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ struct TYPE_FUNC_INFO {
|
|||
ArithmeticSelfFunc func_ = nullptr;
|
||||
};
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
const std::map<int, float> arithmetic_self_compute_cost_map_ = {
|
||||
// {schema::PrimitiveType_Abs, 0.5f},
|
||||
// {schema::PrimitiveType_Cos, 1.0f},
|
||||
|
@ -48,7 +48,7 @@ const std::map<int, float> arithmetic_self_compute_cost_map_ = {
|
|||
#endif
|
||||
} // namespace
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int ArithmeticSelfCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr && arithmetic_self_compute_cost_map_.count(type_) > 0) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
@ -108,7 +108,7 @@ int ArithmeticSelfCPUKernel::Prepare() {
|
|||
}
|
||||
|
||||
int ArithmeticSelfCPUKernel::ReSize() {
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class ArithmeticSelfCPUKernel : public InnerKernel {
|
|||
}
|
||||
~ArithmeticSelfCPUKernel() override = default;
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
int Prepare() override;
|
||||
|
|
|
@ -43,7 +43,7 @@ int SoftmaxCPUKernel::Prepare() {
|
|||
return ReSize();
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int SoftmaxCPUKernel::UpdateThreadNumPass() {
|
||||
if (thread_cost_context_ == nullptr) {
|
||||
thread_cost_context_ = new (std::nothrow) lite::ThreadCostContext();
|
||||
|
@ -91,7 +91,7 @@ int SoftmaxCPUKernel::ReSize() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
if (UpdateThreadNumPass() != RET_OK) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class SoftmaxCPUKernel : public SoftmaxBaseCPUKernel {
|
|||
int ReSize() override;
|
||||
int Run() override;
|
||||
int DoSoftmaxLastAxis(int task_id);
|
||||
#ifdef SERVER_INFERENCE
|
||||
#ifdef DYNAMIC_THREAD_DISTRIBUTE
|
||||
int UpdateThreadNumPass();
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue