forked from huawei/mindspore2022
!21609 [MSLITE] MSLITE_ENABLE_RUNTIME_PASS
Merge pull request !21609 from ling/sr
This commit is contained in:
commit
14ed247eeb
|
|
@ -31,6 +31,7 @@ option(MSLITE_ENABLE_CONVERTER "enable converter, only x86_64 support" on)
|
|||
option(MSLITE_ENABLE_TOOLS "enable tools" on)
|
||||
option(MSLITE_ENABLE_TESTCASES "enable testcase" off)
|
||||
option(MSLITE_ENABLE_NNIE "enable NNIE" off)
|
||||
option(MSLITE_ENABLE_RUNTIME_PASS "enable runtime pass" on)
|
||||
option(MSLITE_COMPILE_NNIE "compile NNIE" off)
|
||||
option(MSLITE_ENABLE_HIGH_PERFORMANCE "enable high performance" on)
|
||||
option(MSLITE_STRING_KERNEL "enable string kernel" on)
|
||||
|
|
@ -83,6 +84,9 @@ endif()
|
|||
if(DEFINED ENV{MSLITE_COMPILE_NNIE})
|
||||
set(MSLITE_COMPILE_NNIE $ENV{MSLITE_COMPILE_NNIE})
|
||||
endif()
|
||||
if(DEFINED ENV{MSLITE_ENABLE_RUNTIME_PASS})
|
||||
set(MSLITE_ENABLE_RUNTIME_PASS $ENV{MSLITE_ENABLE_RUNTIME_PASS})
|
||||
endif()
|
||||
if(DEFINED ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
|
||||
set(MSLITE_ENABLE_HIGH_PERFORMANCE $ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
|
||||
endif()
|
||||
|
|
@ -112,6 +116,9 @@ endif()
|
|||
if(MSLITE_HUFFMAN_DECODE)
|
||||
add_compile_definitions(ENABLE_HUFFMAN_DECODE)
|
||||
endif()
|
||||
if(MSLITE_ENABLE_RUNTIME_PASS)
|
||||
add_compile_definitions(ENABLE_RUNTIME_PASS)
|
||||
endif()
|
||||
|
||||
if(PLATFORM_ARM64)
|
||||
if(MSLITE_GPU_BACKEND STREQUAL "")
|
||||
|
|
@ -183,6 +190,7 @@ message(STATUS "\tMSLITE_ENABLE_CONVERTER = \t${MSLITE_ENABLE_CONVERTER}")
|
|||
message(STATUS "\tMSLITE_ENABLE_TOOLS = \t${MSLITE_ENABLE_TOOLS}")
|
||||
message(STATUS "\tMSLITE_ENABLE_TESTCASES = \t${MSLITE_ENABLE_TESTCASES}")
|
||||
message(STATUS "\tMSLITE_ENABLE_HIGH_PERFORMANCE = \t${MSLITE_ENABLE_HIGH_PERFORMANCE}")
|
||||
message(STATUS "\tMSLITE_ENABLE_RUNTIME_PASS = \t${MSLITE_ENABLE_RUNTIME_PASS}")
|
||||
|
||||
if(MSLITE_ENABLE_HIGH_PERFORMANCE)
|
||||
add_compile_definitions(ENABLE_HIGH_PERFORMANCE)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_RUNTIME_PASS
|
||||
#include "src/runtime/runtime_pass.h"
|
||||
#include "nnacl/conv_parameter.h"
|
||||
|
||||
|
|
@ -95,9 +96,11 @@ bool Nc4hw4PassValid(const InnerContext *context, std::vector<kernel::LiteKernel
|
|||
}
|
||||
|
||||
for (auto kernel : *kernels) {
|
||||
if (kernel->op_parameter()->quant_type_ == schema::QuantType_AwareTraining ||
|
||||
kernel->op_parameter()->quant_type_ == schema::QuantType_PostTraining) {
|
||||
return false;
|
||||
if (kernel->op_parameter() != nullptr) {
|
||||
if (kernel->op_parameter()->quant_type_ == schema::QuantType_AwareTraining ||
|
||||
kernel->op_parameter()->quant_type_ == schema::QuantType_PostTraining) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -106,7 +109,7 @@ bool Nc4hw4PassValid(const InnerContext *context, std::vector<kernel::LiteKernel
|
|||
void Nc4hw4Pass(std::vector<kernel::LiteKernel *> *kernels, std::vector<Tensor *> *tensors) {
|
||||
size_t kernel_size = kernels->size();
|
||||
size_t index = 0;
|
||||
for (; index < kernel_size - 2; index++) {
|
||||
for (; index + 2 < kernel_size; index++) {
|
||||
kernel::LiteKernel *kernel = kernels->at(index);
|
||||
|
||||
if (kernel->subgraph_type() != kernel::kNotSubGraph) {
|
||||
|
|
@ -124,3 +127,4 @@ void Nc4hw4Pass(std::vector<kernel::LiteKernel *> *kernels, std::vector<Tensor *
|
|||
return;
|
||||
}
|
||||
} // namespace mindspore::lite
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#ifndef MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_PASS_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_PASS_H_
|
||||
|
||||
#ifdef ENABLE_RUNTIME_PASS
|
||||
#include <vector>
|
||||
#include "src/lite_kernel.h"
|
||||
#include "src/sub_graph_kernel.h"
|
||||
|
|
@ -37,5 +38,5 @@ bool Nc4hw4PassValid(const InnerContext *context, std::vector<kernel::LiteKernel
|
|||
void Nc4hw4Pass(std::vector<kernel::LiteKernel *> *kernels, std::vector<Tensor *> *tensors);
|
||||
|
||||
} // namespace mindspore::lite
|
||||
|
||||
#endif
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_PASS_H_
|
||||
|
|
|
|||
|
|
@ -88,16 +88,10 @@ int Scheduler::InitKernels(std::vector<kernel::LiteKernel *> dst_kernels) {
|
|||
}
|
||||
|
||||
int Scheduler::Schedule(std::vector<kernel::LiteKernel *> *dst_kernels) {
|
||||
if (dst_kernels == nullptr) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (src_model_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Input model is nullptr";
|
||||
return RET_PARAM_INVALID;
|
||||
}
|
||||
if (src_model_->sub_graphs_.empty()) {
|
||||
MS_LOG(ERROR) << "Model should have a subgraph at least";
|
||||
return RET_PARAM_INVALID;
|
||||
int check_input_ret = CheckInputParam(dst_kernels);
|
||||
if (check_input_ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "CheckInputParam failed! ret: " << check_input_ret;
|
||||
return check_input_ret;
|
||||
}
|
||||
|
||||
this->graph_output_node_indexes_ = GetGraphOutputNodes(src_model_);
|
||||
|
|
@ -137,9 +131,11 @@ int Scheduler::Schedule(std::vector<kernel::LiteKernel *> *dst_kernels) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_RUNTIME_PASS
|
||||
if (Nc4hw4PassValid(context_, dst_kernels)) {
|
||||
Nc4hw4Pass(dst_kernels, src_tensors_);
|
||||
}
|
||||
#endif
|
||||
|
||||
FindAllInoutKernels(*dst_kernels);
|
||||
#ifdef ENABLE_CONTROL_TENSORLIST
|
||||
|
|
@ -173,6 +169,21 @@ int Scheduler::Schedule(std::vector<kernel::LiteKernel *> *dst_kernels) {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int Scheduler::CheckInputParam(std::vector<kernel::LiteKernel *> *dst_kernels) {
|
||||
if (dst_kernels == nullptr) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
if (src_model_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Input model is nullptr";
|
||||
return RET_PARAM_INVALID;
|
||||
}
|
||||
if (src_model_->sub_graphs_.empty()) {
|
||||
MS_LOG(ERROR) << "Model should have a subgraph at least";
|
||||
return RET_PARAM_INVALID;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Scheduler::ReplaceDelegateKernels(std::vector<kernel::LiteKernel *> *dst_kernels) {
|
||||
std::vector<kernel::Kernel *> kernels;
|
||||
for (size_t i = 0; i < dst_kernels->size(); i++) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ class Scheduler {
|
|||
void SetupSchedulerCb(std::unique_ptr<SchedulerCb> cb) { sched_cb_ = std::move(cb); }
|
||||
|
||||
private:
|
||||
int CheckInputParam(std::vector<kernel::LiteKernel *> *dst_kernels);
|
||||
void FindNodeInoutTensors(const Model::Node &node, std::vector<Tensor *> *inputs, std::vector<Tensor *> *outputs);
|
||||
Model::Node *NodeInputIsPartial(const Model::Node *node);
|
||||
int InferPartialShape(const Model::Node *node);
|
||||
|
|
|
|||
Loading…
Reference in New Issue