forked from mindspore-Ecosystem/mindspore
!5332 remove include/thread_pool_config.h
Merge pull request !5332 from wangzhe/master
This commit is contained in:
commit
087f73d91d
|
@ -20,7 +20,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/ms_tensor.h"
|
#include "include/ms_tensor.h"
|
||||||
#include "include/thread_pool_config.h"
|
|
||||||
|
|
||||||
namespace mindspore::lite {
|
namespace mindspore::lite {
|
||||||
/// \brief Allocator defined a memory pool for malloc memory and free memory dynamically.
|
/// \brief Allocator defined a memory pool for malloc memory and free memory dynamically.
|
||||||
|
@ -28,6 +27,13 @@ namespace mindspore::lite {
|
||||||
/// \note List public class and interface for reference.
|
/// \note List public class and interface for reference.
|
||||||
class Allocator;
|
class Allocator;
|
||||||
|
|
||||||
|
/// \brief CpuBindMode defined for holding bind cpu strategy argument.
|
||||||
|
typedef enum {
|
||||||
|
MID_CPU = -1, /**< bind middle cpu first */
|
||||||
|
HIGHER_CPU = 1, /**< bind higher cpu first */
|
||||||
|
NO_BIND = 0 /**< no bind */
|
||||||
|
} CpuBindMode;
|
||||||
|
|
||||||
/// \brief DeviceType defined for holding user's preferred backend.
|
/// \brief DeviceType defined for holding user's preferred backend.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DT_CPU, /**< CPU device type */
|
DT_CPU, /**< CPU device type */
|
||||||
|
|
|
@ -1,35 +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_INCLUDE_THREAD_POOL_CONFIG_H_
|
|
||||||
#define MINDSPORE_LITE_INCLUDE_THREAD_POOL_CONFIG_H_
|
|
||||||
|
|
||||||
/// \brief CpuBindMode defined for holding bind cpu strategy argument.
|
|
||||||
typedef enum Mode {
|
|
||||||
MID_CPU = -1, /**< bind middle cpu first */
|
|
||||||
HIGHER_CPU = 1, /**< bind higher cpu first */
|
|
||||||
NO_BIND = 0 /**< no bind */
|
|
||||||
} CpuBindMode;
|
|
||||||
|
|
||||||
/// \brief ThreadPoolId defined for specifying which thread pool to use.
|
|
||||||
typedef enum Id {
|
|
||||||
THREAD_POOL_DEFAULT = 0, /**< default thread pool id */
|
|
||||||
THREAD_POOL_SECOND = 1, /**< the second thread pool id */
|
|
||||||
THREAD_POOL_THIRD = 2, /**< the third thread pool id */
|
|
||||||
THREAD_POOL_FOURTH = 3 /**< the fourth thread pool id */
|
|
||||||
} ThreadPoolId;
|
|
||||||
|
|
||||||
#endif // LITE_MINDSPORE_LITE_INCLUDE_THREAD_POOL_CONFIG_H_
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "src/runtime/parallel_executor.h"
|
#include "src/runtime/parallel_executor.h"
|
||||||
#include "include/thread_pool_config.h"
|
|
||||||
#include "src/runtime/runtime_api.h"
|
#include "src/runtime/runtime_api.h"
|
||||||
|
|
||||||
#define MAX_THREAD_NUM 8
|
#define MAX_THREAD_NUM 8
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#ifndef PREDICT_SRC_RUNTIME_RUNTIME_API_H_
|
#ifndef PREDICT_SRC_RUNTIME_RUNTIME_API_H_
|
||||||
#define PREDICT_SRC_RUNTIME_RUNTIME_API_H_
|
#define PREDICT_SRC_RUNTIME_RUNTIME_API_H_
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/thread_pool_config.h"
|
|
||||||
|
|
||||||
#ifndef INTERNAL_API_DLL
|
#ifndef INTERNAL_API_DLL
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/runtime/thread_pool.h"
|
#include "src/runtime/thread_pool.h"
|
||||||
#include "include/thread_pool_config.h"
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
@ -75,7 +74,7 @@ typedef struct {
|
||||||
typedef struct ThreadPool {
|
typedef struct ThreadPool {
|
||||||
ThreadList *thread_list;
|
ThreadList *thread_list;
|
||||||
int thread_num;
|
int thread_num;
|
||||||
CpuBindMode mode;
|
BindMode mode;
|
||||||
atomic_bool is_alive;
|
atomic_bool is_alive;
|
||||||
} ThreadPool;
|
} ThreadPool;
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ int BindMasterThread(int thread_pool_id, bool is_bind) {
|
||||||
CPU_ZERO(&mask);
|
CPU_ZERO(&mask);
|
||||||
if (is_bind) {
|
if (is_bind) {
|
||||||
unsigned int attach_id;
|
unsigned int attach_id;
|
||||||
if (thread_pool->mode == MID_CPU) {
|
if (thread_pool->mode == MID_MODE) {
|
||||||
attach_id = cpu_cores[gHigNum + gMidNum - 1];
|
attach_id = cpu_cores[gHigNum + gMidNum - 1];
|
||||||
} else {
|
} else {
|
||||||
attach_id = cpu_cores[0];
|
attach_id = cpu_cores[0];
|
||||||
|
@ -343,10 +342,10 @@ int BindSalverThreads(int thread_pool_id, bool is_bind) {
|
||||||
return RET_TP_ERROR;
|
return RET_TP_ERROR;
|
||||||
}
|
}
|
||||||
cpu_set_t mask;
|
cpu_set_t mask;
|
||||||
if (is_bind && thread_pool->mode != NO_BIND) {
|
if (is_bind && thread_pool->mode != NO_BIND_MODE) {
|
||||||
unsigned int attach_id;
|
unsigned int attach_id;
|
||||||
for (int i = 0; i < thread_pool->thread_num - 1; ++i) {
|
for (int i = 0; i < thread_pool->thread_num - 1; ++i) {
|
||||||
if (thread_pool->mode == MID_CPU) {
|
if (thread_pool->mode == MID_MODE) {
|
||||||
int core_id = gHigNum + gMidNum - i - 2;
|
int core_id = gHigNum + gMidNum - i - 2;
|
||||||
if (core_id >= 0) {
|
if (core_id >= 0) {
|
||||||
attach_id = cpu_cores[core_id];
|
attach_id = cpu_cores[core_id];
|
||||||
|
@ -393,9 +392,9 @@ int BindSalverThreads(int thread_pool_id, bool is_bind) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int BindThreads(int thread_pool_id, bool is_bind, CpuBindMode mode) {
|
int BindThreads(int thread_pool_id, bool is_bind, int mode) {
|
||||||
#ifdef BIND_CORE
|
#ifdef BIND_CORE
|
||||||
if (mode == NO_BIND) {
|
if (mode == NO_BIND_MODE) {
|
||||||
return RET_TP_OK;
|
return RET_TP_OK;
|
||||||
}
|
}
|
||||||
ThreadPool *thread_pool = GetInstance(thread_pool_id);
|
ThreadPool *thread_pool = GetInstance(thread_pool_id);
|
||||||
|
@ -605,7 +604,7 @@ int CreateNewThread(int thread_pool_id, int thread_id) {
|
||||||
return RET_TP_OK;
|
return RET_TP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReConfigThreadPool(int thread_pool_id, int thread_num, CpuBindMode mode) {
|
int ReConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
|
||||||
LOG_INFO("reconfig thread pool, thread_pool_id: %d, thread_num: %d, mode: %d", thread_pool_id, thread_num, mode);
|
LOG_INFO("reconfig thread pool, thread_pool_id: %d, thread_num: %d, mode: %d", thread_pool_id, thread_num, mode);
|
||||||
if (thread_num <= 0 || thread_num > MAX_THREAD_NUM) {
|
if (thread_num <= 0 || thread_num > MAX_THREAD_NUM) {
|
||||||
LOG_INFO("invalid thread num: %d", thread_num);
|
LOG_INFO("invalid thread num: %d", thread_num);
|
||||||
|
@ -646,7 +645,7 @@ int ReConfigThreadPool(int thread_pool_id, int thread_num, CpuBindMode mode) {
|
||||||
return BindThreads(thread_pool_id, true, mode);
|
return BindThreads(thread_pool_id, true, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CreateThreadPool(int thread_pool_id, int thread_num, CpuBindMode mode) {
|
int CreateThreadPool(int thread_pool_id, int thread_num, int mode) {
|
||||||
LOG_INFO("create thread pool, thread_pool_id: %d, thread_num: %d, mode: %d", thread_pool_id, thread_num, mode);
|
LOG_INFO("create thread pool, thread_pool_id: %d, thread_num: %d, mode: %d", thread_pool_id, thread_num, mode);
|
||||||
if (thread_num <= 0 || thread_num > MAX_THREAD_NUM) {
|
if (thread_num <= 0 || thread_num > MAX_THREAD_NUM) {
|
||||||
LOG_INFO("invalid thread num: %d", thread_num);
|
LOG_INFO("invalid thread num: %d", thread_num);
|
||||||
|
@ -690,7 +689,7 @@ int CreateThreadPool(int thread_pool_id, int thread_num, CpuBindMode mode) {
|
||||||
return RET_TP_OK;
|
return RET_TP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigThreadPool(int thread_pool_id, int thread_num, CpuBindMode mode) {
|
int ConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
|
||||||
LOG_INFO("config: thread_pool_id: %d, thread_num: %d, mode: %d, is_created: %d, refcount: %d", thread_pool_id,
|
LOG_INFO("config: thread_pool_id: %d, thread_num: %d, mode: %d, is_created: %d, refcount: %d", thread_pool_id,
|
||||||
thread_num, mode, thread_pool_is_created[thread_pool_id], thread_pool_refcount[thread_pool_id]);
|
thread_num, mode, thread_pool_is_created[thread_pool_id], thread_pool_refcount[thread_pool_id]);
|
||||||
if (thread_pool_id >= MAX_THREAD_POOL_NUM) {
|
if (thread_pool_id >= MAX_THREAD_POOL_NUM) {
|
||||||
|
|
|
@ -18,14 +18,28 @@
|
||||||
#define MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
|
#define MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "include/thread_pool_config.h"
|
|
||||||
|
/// \brief BindMode defined for holding bind cpu strategy argument.
|
||||||
|
typedef enum {
|
||||||
|
MID_MODE = -1, /**< bind middle cpu first */
|
||||||
|
HIGHER_MODE = 1, /**< bind higher cpu first */
|
||||||
|
NO_BIND_MODE = 0 /**< no bind */
|
||||||
|
} BindMode;
|
||||||
|
|
||||||
|
/// \brief ThreadPoolId defined for specifying which thread pool to use.
|
||||||
|
typedef enum {
|
||||||
|
THREAD_POOL_DEFAULT = 0, /**< default thread pool id */
|
||||||
|
THREAD_POOL_SECOND = 1, /**< the second thread pool id */
|
||||||
|
THREAD_POOL_THIRD = 2, /**< the third thread pool id */
|
||||||
|
THREAD_POOL_FOURTH = 3 /**< the fourth thread pool id */
|
||||||
|
} ThreadPoolId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create thread pool and init
|
* create thread pool and init
|
||||||
* @param thread_num
|
* @param thread_num
|
||||||
* @param mode
|
* @param mode
|
||||||
*/
|
*/
|
||||||
int ConfigThreadPool(int context_id, int thread_num, CpuBindMode mode);
|
int ConfigThreadPool(int thread_pool_id, int thread_num, int mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -34,36 +48,36 @@ int ConfigThreadPool(int context_id, int thread_num, CpuBindMode mode);
|
||||||
* @param content
|
* @param content
|
||||||
* @param task_num
|
* @param task_num
|
||||||
*/
|
*/
|
||||||
int ParallelLaunch(int context_id, int (*job)(void *, int), void *content, int task_num);
|
int ParallelLaunch(int thread_pool_id, int (*job)(void *, int), void *content, int task_num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bind each thread to specified cpu core
|
* bind each thread to specified cpu core
|
||||||
* @param is_bind
|
* @param is_bind
|
||||||
* @param mode
|
* @param mode
|
||||||
*/
|
*/
|
||||||
int BindThreads(int context_id, bool is_bind, CpuBindMode mode);
|
int BindThreads(int thread_pool_id, bool is_bind, int mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* activate the thread pool
|
* activate the thread pool
|
||||||
* @param context_id
|
* @param thread_pool_id
|
||||||
*/
|
*/
|
||||||
void ActivateThreadPool(int context_id);
|
void ActivateThreadPool(int thread_pool_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deactivate the thread pool
|
* deactivate the thread pool
|
||||||
* @param context_id
|
* @param thread_pool_id
|
||||||
*/
|
*/
|
||||||
void DeactivateThreadPool(int context_id);
|
void DeactivateThreadPool(int thread_pool_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return current thread num
|
* @return current thread num
|
||||||
*/
|
*/
|
||||||
int GetCurrentThreadNum(int context_id);
|
int GetCurrentThreadNum(int thread_pool_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroy thread pool, and release resource
|
* destroy thread pool, and release resource
|
||||||
*/
|
*/
|
||||||
void DestroyThreadPool(int context_id);
|
void DestroyThreadPool(int thread_pool_id);
|
||||||
|
|
||||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
|
#endif // MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
|
||||||
|
|
|
@ -106,7 +106,7 @@ TEST_F(InferTest, TestConvNode) {
|
||||||
meta_graph.reset();
|
meta_graph.reset();
|
||||||
content = nullptr;
|
content = nullptr;
|
||||||
auto context = new lite::Context;
|
auto context = new lite::Context;
|
||||||
context->cpu_bind_mode_ = NO_BIND;
|
context->cpu_bind_mode_ = lite::NO_BIND;
|
||||||
context->device_ctx_.type = lite::DT_CPU;
|
context->device_ctx_.type = lite::DT_CPU;
|
||||||
context->thread_num_ = 4;
|
context->thread_num_ = 4;
|
||||||
auto session = session::LiteSession::CreateSession(context);
|
auto session = session::LiteSession::CreateSession(context);
|
||||||
|
@ -205,7 +205,7 @@ TEST_F(InferTest, TestAddNode) {
|
||||||
meta_graph.reset();
|
meta_graph.reset();
|
||||||
content = nullptr;
|
content = nullptr;
|
||||||
auto context = new lite::Context;
|
auto context = new lite::Context;
|
||||||
context->cpu_bind_mode_ = NO_BIND;
|
context->cpu_bind_mode_ = lite::NO_BIND;
|
||||||
context->device_ctx_.type = lite::DT_CPU;
|
context->device_ctx_.type = lite::DT_CPU;
|
||||||
context->thread_num_ = 4;
|
context->thread_num_ = 4;
|
||||||
auto session = session::LiteSession::CreateSession(context);
|
auto session = session::LiteSession::CreateSession(context);
|
||||||
|
@ -307,7 +307,7 @@ TEST_F(InferTest, TestParallelExecutor) {
|
||||||
meta_graph.reset();
|
meta_graph.reset();
|
||||||
content = nullptr;
|
content = nullptr;
|
||||||
auto context = new lite::Context;
|
auto context = new lite::Context;
|
||||||
context->cpu_bind_mode_ = NO_BIND;
|
context->cpu_bind_mode_ = lite::NO_BIND;
|
||||||
context->device_ctx_.type = lite::DT_CPU;
|
context->device_ctx_.type = lite::DT_CPU;
|
||||||
context->thread_num_ = 4;
|
context->thread_num_ = 4;
|
||||||
auto session = new SessionWithParallelExecutor();
|
auto session = new SessionWithParallelExecutor();
|
||||||
|
@ -348,7 +348,7 @@ TEST_F(InferTest, TestModel) {
|
||||||
ASSERT_NE(nullptr, model);
|
ASSERT_NE(nullptr, model);
|
||||||
delete[] buf[0];
|
delete[] buf[0];
|
||||||
auto context = new lite::Context;
|
auto context = new lite::Context;
|
||||||
context->cpu_bind_mode_ = NO_BIND;
|
context->cpu_bind_mode_ = lite::NO_BIND;
|
||||||
context->device_ctx_.type = lite::DT_CPU;
|
context->device_ctx_.type = lite::DT_CPU;
|
||||||
context->thread_num_ = 4;
|
context->thread_num_ = 4;
|
||||||
auto session = session::LiteSession::CreateSession(context);
|
auto session = session::LiteSession::CreateSession(context);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "src/common/common.h"
|
#include "src/common/common.h"
|
||||||
#include "include/ms_tensor.h"
|
#include "include/ms_tensor.h"
|
||||||
#include "include/context.h"
|
#include "include/context.h"
|
||||||
|
#include "src/runtime/runtime_api.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
|
|
Loading…
Reference in New Issue