Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
62e7746e
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
62e7746e
编写于
8月 31, 2020
作者:
L
lyvette
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean
modify log
上级
03ff5f33
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
56 deletion
+71
-56
mindspore/lite/src/runtime/thread_pool.c
mindspore/lite/src/runtime/thread_pool.c
+68
-55
mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc
...lite/tools/converter/parser/tflite/tflite_model_parser.cc
+3
-1
未找到文件。
mindspore/lite/src/runtime/thread_pool.c
浏览文件 @
62e7746e
...
...
@@ -32,8 +32,11 @@
#include <stdio.h>
#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)
...
...
@@ -84,7 +87,7 @@ static atomic_bool thread_pool_is_created[MAX_THREAD_POOL_NUM] = {ATOMIC_VAR_INI
ThreadPool
*
GetInstance
(
int
thread_pool_id
)
{
if
(
thread_pool_id
<
0
||
thread_pool_id
>=
MAX_THREAD_POOL_NUM
)
{
LOG_
INFO
(
"invaid context id: %d"
,
thread_pool_id
);
LOG_
ERROR
(
"invaid context id: %d"
,
thread_pool_id
);
// DestroyThreadPool(thread_pool_id);
return
NULL
;
}
...
...
@@ -94,16 +97,16 @@ ThreadPool *GetInstance(int thread_pool_id) {
Thread
*
GetThread
(
int
thread_pool_id
,
int
thread_id
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
thread_id
);
LOG_
ERROR
(
"get thread pool instane failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
thread_id
);
return
NULL
;
}
ThreadList
*
thread_list
=
thread_pool
->
thread_list
;
if
(
thread_list
==
NULL
)
{
LOG_
INFO
(
"thead list is null"
);
LOG_
ERROR
(
"thead list is null"
);
return
NULL
;
}
if
(
thread_id
>=
thread_list
->
size
)
{
LOG_
INFO
(
"invalid thread id: %d, thread_pool_id: %d, thread size: %d"
,
thread_id
,
thread_pool_id
,
LOG_
ERROR
(
"invalid thread id: %d, thread_pool_id: %d, thread size: %d"
,
thread_id
,
thread_pool_id
,
thread_list
->
size
);
return
NULL
;
}
...
...
@@ -122,11 +125,11 @@ Thread *GetThread(int thread_pool_id, int thread_id) {
void
FreeThread
(
ThreadList
*
thread_list
,
Thread
*
thread
)
{
if
(
thread_list
==
NULL
)
{
LOG_
INFO
(
"thead list is null"
);
LOG_
ERROR
(
"thead list is null"
);
return
;
}
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"thread is nullptr"
);
LOG_
ERROR
(
"thread is nullptr"
);
return
;
}
// only support sequential release
...
...
@@ -175,26 +178,26 @@ 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_
INFO
(
"parse cpuid from /sys/devices/system/cpu/cpufreq/stats/cpu/time_in_state failed!"
);
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_
INFO
(
"parse cpuid from /sys/devices/system/cpu/cpufreq/stats/cpu/cpufreq/stats/time_instate failed!"
);
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_
INFO
(
"parse cpuid from /sys/devices/system/cpu/cpufreq/cpuinfo_max_freq failed!"
);
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_
INFO
(
"GetCPUMaxFreq failed, cannot find cpuinfo_max_freq."
);
LOG_
ERROR
(
"GetCPUMaxFreq failed, cannot find cpuinfo_max_freq."
);
return
RET_TP_ERROR
;
}
int
maxFreq
=
-
1
;
...
...
@@ -222,7 +225,7 @@ int GetMaxFrequence(int core_id) {
int
SortCpuProcessor
()
{
gCoreNum
=
GetCpuCoreNum
();
if
(
gCoreNum
<=
0
)
{
LOG_
INFO
(
"invalid cpu count"
);
LOG_
ERROR
(
"invalid cpu count"
);
return
RET_TP_ERROR
;
}
CpuInfo
freq_set
[
gCoreNum
];
...
...
@@ -285,18 +288,18 @@ int SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) {
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_
INFO
(
"bind thread %d to cpu failed. ERROR %d"
,
pthread_gettid_np
(
thread_id
),
ret
);
LOG_
ERROR
(
"bind thread %d to cpu failed. ERROR %d"
,
pthread_gettid_np
(
thread_id
),
ret
);
return
RET_TP_OK
;
}
#endif
#else
#ifdef __APPLE__
LOG_
INFO
(
"not bind thread to apple's cpu."
);
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_
INFO
(
"set thread: %lu to cpu failed"
,
thread_id
);
LOG_
ERROR
(
"set thread: %lu to cpu failed"
,
thread_id
);
return
RET_TP_SYSTEM_ERROR
;
}
#endif // __APPLE__
...
...
@@ -307,7 +310,7 @@ int SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) {
int
BindMasterThread
(
int
thread_pool_id
,
bool
is_bind
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
cpu_set_t
mask
;
...
...
@@ -328,7 +331,7 @@ int BindMasterThread(int thread_pool_id, bool is_bind) {
}
int
ret
=
SetAffinity
(
pthread_self
(),
&
mask
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"set master thread affinity failed"
);
LOG_
ERROR
(
"set master thread affinity failed"
);
return
RET_TP_ERROR
;
}
LOG_INFO
(
"BindMasterThread success."
);
...
...
@@ -338,7 +341,7 @@ int BindMasterThread(int thread_pool_id, bool is_bind) {
int
BindSalverThreads
(
int
thread_pool_id
,
bool
is_bind
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
cpu_set_t
mask
;
...
...
@@ -360,12 +363,12 @@ int BindSalverThreads(int thread_pool_id, bool is_bind) {
CPU_SET
(
attach_id
,
&
mask
);
Thread
*
thread
=
GetThread
(
thread_pool_id
,
i
);
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
LOG_
ERROR
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
return
false
;
}
int
ret
=
SetAffinity
(
thread
->
pthread
,
&
mask
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"set thread affinity failed"
);
LOG_
ERROR
(
"set thread affinity failed"
);
return
RET_TP_ERROR
;
}
}
...
...
@@ -377,12 +380,12 @@ int BindSalverThreads(int thread_pool_id, bool is_bind) {
for
(
int
i
=
0
;
i
<
thread_pool
->
thread_num
-
1
;
++
i
)
{
Thread
*
thread
=
GetThread
(
thread_pool_id
,
i
);
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
LOG_
ERROR
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
return
false
;
}
int
ret
=
SetAffinity
(
thread
->
pthread
,
&
mask
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"set thread affinity failed"
);
LOG_
ERROR
(
"set thread affinity failed"
);
return
RET_TP_ERROR
;
}
}
...
...
@@ -399,17 +402,17 @@ int BindThreads(int thread_pool_id, bool is_bind, int mode) {
}
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
thread_pool
->
mode
=
mode
;
int
ret
=
BindMasterThread
(
thread_pool_id
,
is_bind
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"bind master thread failed."
);
LOG_
ERROR
(
"bind master thread failed."
);
}
ret
=
BindSalverThreads
(
thread_pool_id
,
is_bind
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"bind salver thread failed."
);
LOG_
ERROR
(
"bind salver thread failed."
);
}
return
ret
;
#else
...
...
@@ -420,7 +423,7 @@ int BindThreads(int thread_pool_id, bool is_bind, int mode) {
bool
PushTaskToQueue
(
int
thread_pool_id
,
int
thread_id
,
Task
*
task
)
{
Thread
*
thread
=
GetThread
(
thread_pool_id
,
thread_id
);
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
thread_id
);
LOG_
ERROR
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
thread_id
);
return
false
;
}
const
int
tail_index
=
atomic_load_explicit
(
&
thread
->
tail
,
memory_order_relaxed
);
...
...
@@ -438,7 +441,7 @@ bool PushTaskToQueue(int thread_pool_id, int thread_id, Task *task) {
bool
PopTaskFromQueue
(
Thread
*
thread
,
Task
**
task
)
{
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"thread is nullptr"
);
LOG_
ERROR
(
"thread is nullptr"
);
return
false
;
}
if
(
thread
->
task_size
==
0
)
{
...
...
@@ -456,7 +459,7 @@ bool PopTaskFromQueue(Thread *thread, Task **task) {
void
WaitAllThread
(
int
thread_pool_id
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
bool
k_success_flag
=
false
;
...
...
@@ -465,7 +468,7 @@ void WaitAllThread(int thread_pool_id) {
for
(
int
i
=
0
;
i
<
thread_pool
->
thread_num
-
1
;
++
i
)
{
Thread
*
thread
=
GetThread
(
thread_pool_id
,
i
);
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
LOG_
ERROR
(
"get thread failed, thread_pool_id: %d, thread_id: %d"
,
thread_pool_id
,
i
);
return
;
}
if
(
thread
->
task_size
!=
0
)
{
...
...
@@ -479,11 +482,11 @@ void WaitAllThread(int thread_pool_id) {
int
DistributeTask
(
int
thread_pool_id
,
Task
*
task
,
int
task_num
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
if
(
task_num
>
thread_pool
->
thread_num
||
task_num
<=
1
)
{
LOG_
INFO
(
"invalid task num: %d, thread num: %d"
,
task_num
,
thread_pool
->
thread_num
);
LOG_
ERROR
(
"invalid task num: %d, thread num: %d"
,
task_num
,
thread_pool
->
thread_num
);
return
RET_TP_ERROR
;
}
bool
k_success_flag
=
false
;
...
...
@@ -498,6 +501,11 @@ int DistributeTask(int thread_pool_id, Task *task, int task_num) {
}
// master thread
task
->
func
(
task
->
content
,
size
-
1
);
if
(
task
->
func
==
NULL
)
{
LOG_ERROR
(
"task->func is nullptr"
);
return
RET_TP_ERROR
;
}
// wait
WaitAllThread
(
thread_pool_id
);
return
RET_TP_OK
;
...
...
@@ -506,7 +514,7 @@ int DistributeTask(int thread_pool_id, Task *task, int task_num) {
int
AddTask
(
int
thread_pool_id
,
int
func
(
void
*
,
int
),
void
*
content
,
int
task_num
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
// if single thread, run master thread
...
...
@@ -529,7 +537,7 @@ int ParallelLaunch(int thread_pool_id, int (*func)(void *, int), void *content,
void
ThreadRun
(
Thread
*
thread
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread
->
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
Task
*
task
=
NULL
;
...
...
@@ -540,6 +548,10 @@ void ThreadRun(Thread *thread) {
while
(
thread
->
activate
)
{
if
(
PopTaskFromQueue
(
thread
,
&
task
))
{
task
->
func
(
task
->
content
,
thread_id
);
if
(
task
->
func
==
NULL
)
{
LOG_ERROR
(
"task->func is nullptr"
);
return
;
}
atomic_fetch_sub_explicit
(
&
thread
->
task_size
,
1
,
memory_order_relaxed
);
// atomic_store_explicit(&thread->task_size, thread->task_size - 1, memory_order_relaxed);
spin_count
=
0
;
...
...
@@ -560,12 +572,12 @@ void ThreadRun(Thread *thread) {
void
PushThreadToList
(
int
thread_pool_id
,
Thread
*
thread
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
ThreadList
*
thread_list
=
thread_pool
->
thread_list
;
if
(
thread_list
==
NULL
)
{
LOG_
INFO
(
"thread list is null"
);
LOG_
ERROR
(
"thread list is null"
);
DestroyThreadPool
(
thread_pool_id
);
return
;
}
...
...
@@ -585,7 +597,7 @@ int CreateNewThread(int thread_pool_id, int thread_id) {
LOG_INFO
(
"thread_pool_id: %d, create thread: %d"
,
thread_pool_id
,
thread_id
);
Thread
*
thread
=
(
Thread
*
)
malloc
(
sizeof
(
Thread
));
if
(
thread
==
NULL
)
{
LOG_
INFO
(
"create thread failed"
);
LOG_
ERROR
(
"create thread failed"
);
DestroyThreadPool
(
thread_pool_id
);
return
RET_TP_ERROR
;
}
...
...
@@ -607,12 +619,12 @@ int CreateNewThread(int thread_pool_id, int thread_id) {
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
);
if
(
thread_num
<=
0
||
thread_num
>
MAX_THREAD_NUM
)
{
LOG_
INFO
(
"invalid thread num: %d"
,
thread_num
);
LOG_
ERROR
(
"invalid thread num: %d"
,
thread_num
);
return
RET_TP_ERROR
;
}
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
if
(
thread_num
<=
thread_pool
->
thread_num
)
{
...
...
@@ -625,7 +637,7 @@ int ReConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
if
(
thread_pool
->
thread_list
==
NULL
)
{
thread_pool
->
thread_list
=
(
ThreadList
*
)
malloc
(
sizeof
(
ThreadList
));
if
(
thread_pool
->
thread_list
==
NULL
)
{
LOG_
INFO
(
"create thread list failed"
);
LOG_
ERROR
(
"create thread list failed"
);
DestroyThreadPool
(
thread_pool_id
);
return
RET_TP_ERROR
;
}
...
...
@@ -638,7 +650,7 @@ int ReConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
for
(
int
i
=
curr_thread_num
-
1
,
j
=
0
;
j
<
add_thread_num
;
++
i
,
++
j
)
{
int
ret
=
CreateNewThread
(
thread_pool_id
,
i
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"create new thread failed"
);
LOG_
ERROR
(
"create new thread failed"
);
return
RET_TP_ERROR
;
}
}
...
...
@@ -648,7 +660,7 @@ int ReConfigThreadPool(int thread_pool_id, int thread_num, int 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
);
if
(
thread_num
<=
0
||
thread_num
>
MAX_THREAD_NUM
)
{
LOG_
INFO
(
"invalid thread num: %d"
,
thread_num
);
LOG_
ERROR
(
"invalid thread num: %d"
,
thread_num
);
return
RET_TP_ERROR
;
}
#ifdef BIND_CORE
...
...
@@ -659,7 +671,7 @@ int CreateThreadPool(int thread_pool_id, int thread_num, int mode) {
#endif
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
RET_TP_ERROR
;
}
thread_pool
->
thread_num
=
thread_num
>
MAX_THREAD_NUM
?
MAX_THREAD_NUM
:
thread_num
;
...
...
@@ -669,7 +681,7 @@ int CreateThreadPool(int thread_pool_id, int thread_num, int mode) {
if
(
thread_num
>
1
)
{
thread_pool
->
thread_list
=
(
ThreadList
*
)
malloc
(
sizeof
(
ThreadList
));
if
(
thread_pool
->
thread_list
==
NULL
)
{
LOG_
INFO
(
"create thread list failed"
);
LOG_
ERROR
(
"create thread list failed"
);
DestroyThreadPool
(
thread_pool_id
);
return
RET_TP_ERROR
;
}
...
...
@@ -681,7 +693,7 @@ int CreateThreadPool(int thread_pool_id, int thread_num, int mode) {
for
(
int
i
=
0
;
i
<
thread_pool
->
thread_num
-
1
;
++
i
)
{
int
ret
=
CreateNewThread
(
thread_pool_id
,
i
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"create thread %d failed"
,
i
);
LOG_
ERROR
(
"create thread %d failed"
,
i
);
DestroyThreadPool
(
thread_pool_id
);
return
RET_TP_ERROR
;
}
...
...
@@ -693,11 +705,11 @@ 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
,
thread_num
,
mode
,
thread_pool_is_created
[
thread_pool_id
],
thread_pool_refcount
[
thread_pool_id
]);
if
(
thread_pool_id
>=
MAX_THREAD_POOL_NUM
)
{
LOG_
INFO
(
"invalid context id: %d"
,
thread_pool_id
);
LOG_
ERROR
(
"invalid context id: %d"
,
thread_pool_id
);
return
RET_TP_ERROR
;
}
if
(
thread_num
<=
0
||
thread_num
>
MAX_THREAD_NUM
)
{
LOG_
INFO
(
"invalid thread num: %d"
,
thread_num
);
LOG_
ERROR
(
"invalid thread num: %d"
,
thread_num
);
return
RET_TP_ERROR
;
}
thread_pool_refcount
[
thread_pool_id
]
+=
1
;
...
...
@@ -705,14 +717,14 @@ int ConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
if
(
thread_pool_is_created
[
thread_pool_id
])
{
ret
=
ReConfigThreadPool
(
thread_pool_id
,
thread_num
,
mode
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"reconfig thread pool failed, thread_pool_id: %d, thread_num: %d, mode: %d"
,
thread_pool_id
,
thread_num
,
LOG_
ERROR
(
"reconfig thread pool failed, thread_pool_id: %d, thread_num: %d, mode: %d"
,
thread_pool_id
,
thread_num
,
mode
);
}
}
else
{
thread_pool_is_created
[
thread_pool_id
]
=
true
;
ret
=
CreateThreadPool
(
thread_pool_id
,
thread_num
,
mode
);
if
(
ret
!=
RET_TP_OK
)
{
LOG_
INFO
(
"create thread pool failed, thread_pool_id: %d, thread_num: %d, mode: %d"
,
thread_pool_id
,
thread_num
,
LOG_
ERROR
(
"create thread pool failed, thread_pool_id: %d, thread_num: %d, mode: %d"
,
thread_pool_id
,
thread_num
,
mode
);
}
}
...
...
@@ -722,12 +734,12 @@ int ConfigThreadPool(int thread_pool_id, int thread_num, int mode) {
void
ActivateThreadPool
(
int
thread_pool_id
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
ThreadList
*
thread_list
=
thread_pool
->
thread_list
;
if
(
thread_list
==
NULL
)
{
LOG_
INFO
(
"thread pool: %d list is null"
,
thread_pool_id
);
LOG_
ERROR
(
"thread pool: %d list is null"
,
thread_pool_id
);
return
;
}
Thread
*
thread
=
thread_list
->
head
;
...
...
@@ -741,12 +753,12 @@ void ActivateThreadPool(int thread_pool_id) {
void
DeactivateThreadPool
(
int
thread_pool_id
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
ThreadList
*
thread_list
=
thread_pool
->
thread_list
;
if
(
thread_list
==
NULL
)
{
LOG_
INFO
(
"thread pool: %d list is null"
,
thread_pool_id
);
LOG_
ERROR
(
"thread pool: %d list is null"
,
thread_pool_id
);
return
;
}
Thread
*
thread
=
thread_list
->
head
;
...
...
@@ -759,16 +771,17 @@ void DeactivateThreadPool(int thread_pool_id) {
void
DestroyThreadPool
(
int
thread_pool_id
)
{
thread_pool_refcount
[
thread_pool_id
]
--
;
if
(
thread_pool_refcount
[
thread_pool_id
]
>
0
)
{
LOG_INFO
(
"no need to free, thread_pool_id: %d, refcount: %d"
,
thread_pool_id
,
thread_pool_refcount
[
thread_pool_id
]);
LOG_ERROR
(
"no need to free, thread_pool_id: %d, refcount: %d"
,
thread_pool_id
,
thread_pool_refcount
[
thread_pool_id
]);
return
;
}
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
;
}
if
(
thread_pool
->
thread_list
==
NULL
)
{
LOG_
INFO
(
"thread pool: %d list is null"
,
thread_pool_id
);
LOG_
ERROR
(
"thread pool: %d list is null"
,
thread_pool_id
);
return
;
}
DeactivateThreadPool
(
thread_pool_id
);
...
...
@@ -789,7 +802,7 @@ void DestroyThreadPool(int thread_pool_id) {
int
GetCurrentThreadNum
(
int
thread_pool_id
)
{
ThreadPool
*
thread_pool
=
GetInstance
(
thread_pool_id
);
if
(
thread_pool
==
NULL
)
{
LOG_
INFO
(
"get thread pool instane failed"
);
LOG_
ERROR
(
"get thread pool instane failed"
);
return
0
;
}
return
thread_pool
->
thread_num
;
...
...
mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc
浏览文件 @
62e7746e
...
...
@@ -53,7 +53,9 @@ STATUS TfliteModelParser::CopyConstTensorData(const std::vector<std::unique_ptr<
auto
buffer_idx
=
tflite_tensor
->
buffer
;
if
(
!
tflite_model_buffer
[
buffer_idx
]
->
data
.
empty
())
{
tensor
->
data
.
resize
(
data_size
);
if
(
memcpy_s
(
tensor
->
data
.
data
(),
data_size
,
tflite_model_buffer
[
buffer_idx
]
->
data
.
data
(),
data_size
))
{
if
(
memcpy_s
(
tensor
->
data
.
data
(),
tensor
->
data
.
size
(),
tflite_model_buffer
[
buffer_idx
]
->
data
.
data
(),
tflite_model_buffer
[
buffer_idx
]
->
data
.
size
()))
{
MS_LOG
(
ERROR
)
<<
"memcpy tensor data failed"
;
return
RET_ERROR
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录