Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
2b03a447
Commit
2b03a447
authored
Feb 23, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates of XThead
parent
dd7a67bc
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
45 行增加
和
30 行删除
+45
-30
source/tensor/XPRunner.cpp
+3
-4
source/tensor/XPRunner.h
+1
-1
source/tensor/XQueue.cpp
+7
-8
source/tensor/XQueue.h
+4
-4
source/tensor/XThread.cpp
+18
-2
source/tensor/XThread.h
+5
-4
source/tensor/core/utilities/XMatrixSegment.cpp
+7
-7
没有找到文件。
source/tensor/XPRunner.cpp
查看文件 @
2b03a447
...
...
@@ -146,7 +146,7 @@ run a set of jobs in parallel
>> jobArgs - the list of arguments for each job
>> sleepTime - time to sleep (in ms) for each round
*/
void
XPRunner
::
Run
(
TensorList
*
jobFunctions
,
Tensor
List
*
jobArgs
,
float
sleepTime
)
void
XPRunner
::
Run
(
XList
*
jobFunctions
,
X
List
*
jobArgs
,
float
sleepTime
)
{
if
(
threadNum
<=
0
){
XPRINT
(
1
,
stderr
,
"Error! No threads were created!
\n
"
);
...
...
@@ -195,13 +195,12 @@ void XPRunner::Run(TensorList * jobFunctions, TensorList * jobArgs, float sleepT
TFunction
function
=
(
TFunction
)
jobFunctions
->
GetItem
(
jobArgs
->
count
-
c
);
/* the arguments that are passed to the function */
volatile
TensorList
*
args
=
(
Tensor
List
*
)
jobArgs
->
GetItem
(
jobArgs
->
count
-
c
);
XList
*
args
=
(
X
List
*
)
jobArgs
->
GetItem
(
jobArgs
->
count
-
c
);
/* thread */
XThread
*
thread
=
threads
+
availableThreads
[
i
];
thread
->
argv
=
args
;
thread
->
function
=
function
;
thread
->
SetFunc
(
function
,
args
);
MUTEX_LOCK
(
thread
->
workingMutex
);
thread
->
working
=
1
;
...
...
source/tensor/XPRunner.h
查看文件 @
2b03a447
...
...
@@ -106,7 +106,7 @@ public:
void
KillThreads
();
/* run a set of jobs in parallel */
void
Run
(
TensorList
*
jobFunctions
,
Tensor
List
*
jobArgs
,
float
sleepTime
=
0
);
void
Run
(
XList
*
jobFunctions
,
X
List
*
jobArgs
,
float
sleepTime
=
0
);
/* get the number of parallel jobs to run */
int
GetJobNum
(
int
size
);
...
...
source/tensor/XQueue.cpp
查看文件 @
2b03a447
...
...
@@ -42,7 +42,7 @@ job item used in queues
JobQueueNode
::
JobQueueNode
()
{
job
=
NULL
;
args
=
new
Tensor
List
(
1
);
args
=
new
X
List
(
1
);
}
/* de-constructor */
...
...
@@ -67,7 +67,7 @@ XQueue::XQueue(int mySize)
head
=
0
;
tail
=
0
;
isJobQueue
=
false
;
jobDequeuerArgs
=
new
Tensor
List
(
1
);
jobDequeuerArgs
=
new
X
List
(
1
);
jobDequeuerBreak
=
false
;
runningJobCount
=
0
;
...
...
@@ -171,11 +171,10 @@ void XQueue::RunJobConsumer(int jobDevID)
jobDequeuerArgs
->
Clear
();
// warning: this may cause unknown error
jobDequeuerArgs
->
Add
(
(
XTensor
*
)
this
);
jobDequeuerArgs
->
Add
(
jobDevID
>=
0
?
(
XTensor
*
)(
devids
+
jobDevID
)
:
(
XTensor
*
)
&
cpuid
);
jobDequeuerArgs
->
Add
(
this
);
jobDequeuerArgs
->
Add
(
jobDevID
>=
0
?
(
devids
+
jobDevID
)
:
&
cpuid
);
jobDequeuer
.
function
=
(
TFunction
)
DequeueJobs
;
jobDequeuer
.
argv
=
jobDequeuerArgs
;
jobDequeuer
.
SetFunc
((
TFunction
)
DequeueJobs
,
jobDequeuerArgs
);
jobDequeuer
.
Start
();
jobDequeuer
.
LetItGo
();
...
...
@@ -194,7 +193,7 @@ void XQueue::StopJobConsumer()
}
/* add a job item to process */
void
XQueue
::
EnqueueJob
(
void
*
job
,
Tensor
List
*
jobArgs
)
void
XQueue
::
EnqueueJob
(
void
*
job
,
X
List
*
jobArgs
)
{
MUTEX_LOCK
(
jobQueueMutex
);
runningJobCount
++
;
...
...
@@ -208,7 +207,7 @@ void XQueue::EnqueueJob(void * job, TensorList * jobArgs)
}
/* job item consumer */
void
XQueue
::
DequeueJobs
(
Tensor
List
*
args
)
void
XQueue
::
DequeueJobs
(
X
List
*
args
)
{
CheckNTErrors
((
args
->
count
==
2
),
"Illegal arguments!"
);
...
...
source/tensor/XQueue.h
查看文件 @
2b03a447
...
...
@@ -51,7 +51,7 @@ public:
void
*
job
;
/* arguments of the job */
Tensor
List
*
args
;
X
List
*
args
;
public
:
/* constructor */
...
...
@@ -101,7 +101,7 @@ private:
XThread
jobDequeuer
;
/* argument list of jobDequeuer */
Tensor
List
*
jobDequeuerArgs
;
X
List
*
jobDequeuerArgs
;
/* indicates whether jobDequeuer stops */
bool
jobDequeuerBreak
;
...
...
@@ -135,11 +135,11 @@ public:
void
StopJobConsumer
();
/* add a job item to process */
void
EnqueueJob
(
void
*
job
,
Tensor
List
*
jobArgs
);
void
EnqueueJob
(
void
*
job
,
X
List
*
jobArgs
);
/* job item consumer */
static
void
DequeueJobs
(
Tensor
List
*
args
);
void
DequeueJobs
(
X
List
*
args
);
/* get the break flag */
bool
GetJobBreak
();
...
...
source/tensor/XThread.cpp
查看文件 @
2b03a447
...
...
@@ -38,7 +38,7 @@ XThread::XThread()
#endif
MUTEX_INIT
(
gMutex
);
function
=
NULL
;
argv
=
NULL
;
argv
.
Clear
()
;
toBreak
=
false
;
jobCount
=
0
;
working
=
0
;
...
...
@@ -69,6 +69,18 @@ void * XThread::Wrapper(void * ptr)
return
0
;
}
/*
initialize the thread with the function and its parameters
>> myFunc - the function to run
>> myArgv - arguments of the function
*/
void
XThread
::
SetFunc
(
TFunction
myFunc
,
XList
*
myArgv
)
{
function
=
myFunc
;
argv
.
Clear
();
argv
.
AddList
(
myArgv
);
}
/*
Tunning for this thread. It is very very native implementation.
...
...
@@ -77,6 +89,10 @@ After that, we wait again if there is no new job.
*/
void
XThread
::
Run
()
{
if
(
function
==
NULL
)
{
ShowNTErrors
(
"You are running a thread with no function specified!"
);
}
#ifdef _WIN32
//COND_RESET(gCond);
#endif
...
...
@@ -104,7 +120,7 @@ void XThread::Run()
}
/* do what you want to do*/
function
(
argv
);
function
(
&
argv
);
#ifdef USE_PTHREAD
jobCount
--
;
...
...
source/tensor/XThread.h
查看文件 @
2b03a447
...
...
@@ -85,7 +85,7 @@ namespace nts{
#endif
typedef
void
(
*
TFunction
)
(
volatile
Tensor
List
*
);
typedef
void
(
*
TFunction
)
(
volatile
X
List
*
);
/*
This is a class that wraps the standard implementation of threading
...
...
@@ -128,12 +128,10 @@ public:
public
:
/* function to run */
volatile
TFunction
function
;
/* arguments (for the function to run) */
volatile
TensorList
*
argv
;
XList
argv
;
/* a flag to break */
volatile
...
...
@@ -154,6 +152,9 @@ public:
/* a wrapper for the start-routine parameter in pthread_create */
static
void
*
Wrapper
(
void
*
ptr
);
/* initialize the thread with the function and its parameters */
void
SetFunc
(
TFunction
myFunc
,
XList
*
myArgv
);
/*
Core of the thread. It is very very native impelementation.
We loop and wait for a singnal to activate the job processing.
...
...
source/tensor/core/utilities/XMatrixSegment.cpp
查看文件 @
2b03a447
...
...
@@ -51,7 +51,7 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
CheckNTErrors
(
jobNum
!=
0
,
"TODO!"
);
/* argument list of the jobs */
TensorList
*
jobArgList
=
new
Tensor
List
(
argNum
);
XList
*
jobArgList
=
new
X
List
(
argNum
);
va_list
ap
;
va_start
(
ap
,
argNum
);
...
...
@@ -62,8 +62,8 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
va_end
(
ap
);
/* prepare the neccesary argument list for parallel processing */
TensorList
*
jobs
=
new
Tensor
List
(
jobNum
);
TensorList
*
args
=
new
Tensor
List
(
jobNum
);
XList
*
jobs
=
new
X
List
(
jobNum
);
XList
*
args
=
new
X
List
(
jobNum
);
int
*
indexList
=
new
int
[
jobNum
*
4
*
4
];
...
...
@@ -78,7 +78,7 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
*/
for
(
int
i
=
0
;
i
<
jobNum
;
i
++
)
{
IntList
*
indexArgs
=
new
IntList
(
4
);
TensorList
*
blockArgs
=
new
Tensor
List
(
argNum
);
XList
*
blockArgs
=
new
X
List
(
argNum
);
int
*
blockIndex
=
indexList
+
i
*
4
;
indexArgs
->
Add
(
blockIndex
[
0
]);
...
...
@@ -89,10 +89,10 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
for
(
int
j
=
0
;
j
<
argNum
;
j
++
)
blockArgs
->
Add
(
jobArgList
->
GetItem
(
j
));
args
->
Add
((
XTensor
*
)
indexArgs
);
args
->
Add
((
XTensor
*
)
blockArgs
);
args
->
Add
((
void
*
)
indexArgs
);
args
->
Add
((
void
*
)
blockArgs
);
jobs
->
Add
((
XTensor
*
)
job
);
jobs
->
Add
((
void
*
)
job
);
}
args
->
count
=
jobNum
*
2
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论