Browse Source

fix micro thread_pool

tags/v1.2.0-rc1
z00512249 5 years ago
parent
commit
60bd9248f2
6 changed files with 15 additions and 47 deletions
  1. +0
    -1
      mindspore/lite/micro/cmake/file_list.cmake
  2. +4
    -2
      mindspore/lite/micro/coder/generator/component/parallel_component.cc
  3. +2
    -1
      mindspore/lite/micro/coder/generator/component/weight_component.cc
  4. +2
    -3
      mindspore/lite/micro/coder/generator/generator.cc
  5. +0
    -33
      mindspore/lite/micro/coder/opcoders/parallel.cc
  6. +7
    -7
      mindspore/lite/micro/coder/opcoders/parallel.h

+ 0
- 1
mindspore/lite/micro/cmake/file_list.cmake View File

@@ -43,7 +43,6 @@ set(CODER_OPCODERS_SRC
${MICRO_DIR}/coder/opcoders/op_coder.cc
${MICRO_DIR}/coder/opcoders/op_coder_builder.cc
${MICRO_DIR}/coder/opcoders/op_coder_register.cc
${MICRO_DIR}/coder/opcoders/parallel.cc
#### serializer
${MICRO_DIR}/coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.cc
${MICRO_DIR}/coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.cc


+ 4
- 2
mindspore/lite/micro/coder/generator/component/parallel_component.cc View File

@@ -16,6 +16,7 @@

#include "coder/generator/component/parallel_component.h"
#include <string>
#include "coder/opcoders/parallel.h"

namespace mindspore::lite::micro {

@@ -51,13 +52,14 @@ void CodeSetGlobalThreadPoolState(std::ofstream &ofs) {
}

void CodeSetGlobalThreadPoolImplement(std::ofstream &ofs) {
ofs << "struct ThreadPool *g_thread_pool = NULL;\n"
ofs << "struct ThreadPool *" << gThreadPool << " = NULL;\n"
<< "int "
<< "SetThreadPool(struct ThreadPool *thread_pool) {\n"
<< " if (thread_pool == NULL) {\n"
" return RET_ERROR;\n"
" }\n"
" g_thread_pool = thread_pool;\n"
<< gThreadPool
<< " = thread_pool;\n"
" return RET_OK;\n"
"}\n";
}


+ 2
- 1
mindspore/lite/micro/coder/generator/component/weight_component.cc View File

@@ -35,6 +35,8 @@ void CodeWeightFileHeader(std::ofstream &ofs, const std::unique_ptr<CoderContext
" RET_OK = 0,\n"
" RET_ERROR = 1,\n"
"};\n\n";
// set a global var for thread_pool
ofs << "static int" << gThreadNum << " = 1;\n";
}

void CodeModelParamsState(std::ofstream &ofs, const std::map<std::string, Tensor *> &weights) {
@@ -100,7 +102,6 @@ void CodeWeightInitFunc(std::ofstream &ofs, const std::unique_ptr<CoderContext>
<< " if (weight_buffer == NULL) {\n"
<< " return RET_ERROR;\n"
<< " }\n";
ofs << " int " << gThreadNum << " = 1;\n\n";
ofs << " struct ModelParameter {\n"
<< " void *addr;\n"
<< " size_t size;\n"


+ 2
- 3
mindspore/lite/micro/coder/generator/generator.cc View File

@@ -30,6 +30,7 @@
#include "coder/generator/component/const_blocks/benchmark.h"
#include "coder/generator/component/const_blocks/license.h"
#include "coder/log.h"
#include "coder/opcoders/parallel.h"

namespace mindspore::lite::micro {
int WriteContentToFile(const std::string &file, const std::string &content) {
@@ -62,9 +63,7 @@ void Generator::CodeNetRunFunc(std::ofstream &ofs) {
// generate net inference code
ofs << "void Inference() {\n";
if (config_->support_parallel()) {
ofs << " const int g_thread_num = GetCurrentThreadNum(g_thread_pool);\n";
} else {
ofs << " const int g_thread_num = 1;\n";
ofs << gThreadNum << " = GetCurrentThreadNum(" << gThreadPool << ");\n ";
}
for (const auto &block : ctx_->code_blocks()) {
ofs << " {\n" << block << " }\n";


+ 0
- 33
mindspore/lite/micro/coder/opcoders/parallel.cc View File

@@ -1,33 +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 "coder/opcoders/parallel.h"

namespace mindspore::lite::micro {

// ParallelLaunch is defined in thread_pool
const char *kParallelLaunch = "ParallelLaunch";

// g_thread_pool and g_thread_num are global variable,
// assign g_thread_pool by CreateThreadPool,
// and g_thread_num is equal to GetCurrentThreadNum
const char *gThreadNum = "g_thread_num";
const char *gThreadPool = "g_thread_pool";

// args represents the parameters required for operator to run
const char *kRunArgs = "args";
const char *kRunArgsAddr = "&args";

} // namespace mindspore::lite::micro

+ 7
- 7
mindspore/lite/micro/coder/opcoders/parallel.h View File

@@ -19,22 +19,22 @@

namespace mindspore::lite::micro {

constexpr int kDefaultTaskId = 0;
constexpr auto kDefaultTaskId = 0;

constexpr int kMaxThreadNumSupported = 4;
constexpr auto kMaxThreadNumSupported = 4;

// ParallelLaunch is defined in thread_pool
extern const char *kParallelLaunch;
constexpr auto kParallelLaunch = "ParallelLaunch";

// g_thread_pool and g_thread_num are global variable,
// assign g_thread_pool by CreateThreadPool,
// and g_thread_num is equal to GetCurrentThreadNum
extern const char *gThreadNum;
extern const char *gThreadPool;
constexpr auto gThreadNum = "g_thread_num";
constexpr auto gThreadPool = "g_thread_pool";

// args represents the parameters required for operator to run
extern const char *kRunArgs;
extern const char *kRunArgsAddr;
constexpr auto kRunArgs = "args";
constexpr auto kRunArgsAddr = "&args";

} // namespace mindspore::lite::micro



Loading…
Cancel
Save