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
968c1e92
Commit
968c1e92
authored
Mar 12, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
roll back
parent
c8da72b4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
7 行增加
和
204 行删除
+7
-204
source/train/XLeader.cpp
+3
-81
source/train/XWorker.cpp
+0
-72
source/train/XWorker.h
+0
-33
source/train/XWorkerBroadcast.cpp
+2
-9
source/train/XWorkerUpdate.cpp
+2
-9
没有找到文件。
source/train/XLeader.cpp
查看文件 @
968c1e92
...
@@ -125,78 +125,6 @@ void XLeader::InitForRun()
...
@@ -125,78 +125,6 @@ void XLeader::InitForRun()
}
}
}
}
/* mark the workers as LOCKED */
void
XLeader
::
LockWorkers
()
{
int
paramNum
=
serverModel
.
paramNum
;
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
{
XWorkerJob
*
worker
=
(
XWorkerJob
*
)
jworkers
[
i
];
worker
->
ResetJobCount
();
worker
->
LockCount
();
}
for
(
int
i
=
0
;
i
<
cworkers
.
count
;
i
++
)
{
XWorkerCollect
*
worker
=
(
XWorkerCollect
*
)
cworkers
[
i
];
worker
->
ResetJobCount
();
worker
->
LockCount
();
}
for
(
int
i
=
0
;
i
<
uworkers
.
count
;
i
++
)
{
XWorkerUpdate
*
worker
=
(
XWorkerUpdate
*
)
uworkers
[
i
];
worker
->
ResetJobCount
(
paramNum
);
worker
->
LockCount
();
}
for
(
int
i
=
0
;
i
<
bworkers
.
count
;
i
++
)
{
XWorkerBroadcast
*
worker
=
(
XWorkerBroadcast
*
)
bworkers
[
i
];
worker
->
ResetJobCount
(
paramNum
);
worker
->
LockCount
();
}
}
/*
wait for unlocked workers (i.e., all workers finish their jobs).
It is used as a response to LockWorkers(). It tries to lock the mutex
in each worker. Because the mutex has been locked in LockWorkers(),
WaitForUnlockedWorkers() must wait until the worker finishes its job and
unlock the mutex. In this way, WaitForUnlockedWorkers() would return only
if all workers finish their jobs.
>> activeJobWorkers - flags that indicat whether a job worker is active
*/
void
XLeader
::
WaitForUnlockedWorkers
(
const
int
*
activeJobWorkers
)
{
int
activeNum
=
0
;
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
{
XWorkerJob
*
worker
=
(
XWorkerJob
*
)
jworkers
[
i
];
if
(
activeJobWorkers
[
i
]
>
0
)
{
worker
->
LockCount
();
CheckNTErrors
(
worker
->
IsFinished
(),
"Something is wrong with the worker!"
);
worker
->
UnlockCount
();
activeNum
++
;
}
}
XList
workers
;
workers
.
AddList
(
&
cworkers
);
workers
.
AddList
(
&
uworkers
);
workers
.
AddList
(
&
bworkers
);
for
(
int
i
=
0
;
i
<
workers
.
count
;
i
++
)
{
XWorker
*
worker
=
(
XWorker
*
)
workers
[
i
];
if
(
activeNum
>
0
)
{
worker
->
LockCount
();
CheckNTErrors
(
worker
->
IsFinished
(),
"Something is wrong with the worker!"
);
worker
->
UnlockCount
();
}
else
{
worker
->
UnlockCount
();
}
}
}
/* get loss */
/* get loss */
float
XLeader
::
GetLoss
()
float
XLeader
::
GetLoss
()
{
{
...
@@ -350,7 +278,7 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
...
@@ -350,7 +278,7 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
InitForRun
();
InitForRun
();
LockWorkers
();
//
LockWorkers();
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
active
[
i
]
=
0
;
active
[
i
]
=
0
;
...
@@ -380,9 +308,6 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
...
@@ -380,9 +308,6 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
/* job in queue 1: make a record of the run */
/* job in queue 1: make a record of the run */
worker
->
AddJobRecord
();
worker
->
AddJobRecord
();
/* job in quene 1: finish the job */
worker
->
AddJobCountFinished
();
active
[
i
]
=
1
;
active
[
i
]
=
1
;
activeJobCount
++
;
activeJobCount
++
;
}
}
...
@@ -415,8 +340,7 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
...
@@ -415,8 +340,7 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
collecter
->
AddJobUpdateAll
(
&
members
,
&
membersAll
,
&
serverModel
,
collecter
->
AddJobUpdateAll
(
&
members
,
&
membersAll
,
&
serverModel
,
optimizer
,
updater
,
broadcaster
);
optimizer
,
updater
,
broadcaster
);
collecter
->
AddJobCollectOther
(
&
memberRecords
,
&
serverRecord
);
collecter
->
AddJobCollectOther
(
&
memberRecords
,
&
serverRecord
);
collecter
->
AddJobCountFinished
();
/* jobs in queue 2: collect the (gradient) data and other stuff. This
/* jobs in queue 2: collect the (gradient) data and other stuff. This
is a reduce process. */
is a reduce process. */
//collecter->AddJobCollect(&members, &serverModel);
//collecter->AddJobCollect(&members, &serverModel);
...
@@ -430,11 +354,9 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
...
@@ -430,11 +354,9 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
not involved in this run. */
not involved in this run. */
//broadcaster->AddJobBroadcast(&serverModel, &membersAll);
//broadcaster->AddJobBroadcast(&serverModel, &membersAll);
//
WaitForFinishing();
WaitForFinishing
();
}
}
WaitForUnlockedWorkers
(
active
);
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
jworkers
.
count
;
i
++
)
{
XWorkerJob
*
worker
=
(
XWorkerJob
*
)
jworkers
[
i
];
XWorkerJob
*
worker
=
(
XWorkerJob
*
)
jworkers
[
i
];
worker
->
Clear
();
worker
->
Clear
();
...
...
source/train/XWorker.cpp
查看文件 @
968c1e92
...
@@ -38,16 +38,12 @@ XWorker::XWorker()
...
@@ -38,16 +38,12 @@ XWorker::XWorker()
id
=
-
1
;
id
=
-
1
;
state
=
XWORKER_UNSTARTED
;
state
=
XWORKER_UNSTARTED
;
isInstantRun
=
false
;
isInstantRun
=
false
;
jobCountFinished
=
0
;
jobCountExpected
=
-
1
;
MUTEX_INIT
(
countMutex
);
}
}
/* de-constructor */
/* de-constructor */
XWorker
::~
XWorker
()
XWorker
::~
XWorker
()
{
{
Stop
();
Stop
();
MUTEX_DELE
(
countMutex
);
}
}
/* set device id */
/* set device id */
...
@@ -113,73 +109,5 @@ bool XWorker::IsEmpty()
...
@@ -113,73 +109,5 @@ bool XWorker::IsEmpty()
{
{
return
queue
.
IsEmpty
();
return
queue
.
IsEmpty
();
}
}
/*
reset the job counts
>> myJobCountExpected - expected count
>> myJobCountFinished - current count
*/
void
XWorker
::
ResetJobCount
(
int
myJobCountExpected
,
int
myJobCountFinished
)
{
jobCountExpected
=
myJobCountExpected
;
jobCountFinished
=
myJobCountFinished
;
}
/* lock the count mutex */
void
XWorker
::
LockCount
()
{
MUTEX_LOCK
(
countMutex
);
}
/* unlock the count mutex */
void
XWorker
::
UnlockCount
()
{
MUTEX_UNLOCK
(
countMutex
);
}
/* check if the worker finishes its job */
bool
XWorker
::
IsFinished
()
{
if
(
jobCountExpected
<=
0
)
return
true
;
if
(
jobCountExpected
==
jobCountFinished
)
return
true
;
return
false
;
}
/* count a finished job */
void
XWorker
::
CountFinishedJob
()
{
jobCountFinished
++
;
if
(
jobCountExpected
<
0
||
jobCountFinished
>=
jobCountExpected
){
MUTEX_UNLOCK
(
countMutex
);
}
else
{
ShowNTErrors
(
"More jobs than expected!"
);
}
}
/* wrapper of CountFinishedJob() */
void
XWorker
::
CountFinished
(
XList
*
args
)
{
XWorker
*
worker
=
(
XWorker
*
)
args
->
GetItem
(
0
);
worker
->
CountFinishedJob
();
}
/* add a new job of counting finished jobs */
void
XWorker
::
AddJobCountFinished
()
{
XList
args
;
args
.
Add
(
this
);
if
(
isInstantRun
)
XWorker
::
CountFinished
(
&
args
);
else
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorker
::
CountFinished
,
&
args
);
}
}
/* end of the nts (NiuTrans.Tensor) namespace */
}
/* end of the nts (NiuTrans.Tensor) namespace */
source/train/XWorker.h
查看文件 @
968c1e92
...
@@ -64,15 +64,6 @@ protected:
...
@@ -64,15 +64,6 @@ protected:
/* fire the flag of instant run */
/* fire the flag of instant run */
bool
isInstantRun
;
bool
isInstantRun
;
/* count how many jobs have been finished */
int
jobCountFinished
;
/* the expected number of jobs */
int
jobCountExpected
;
/* mutex for accessing the job counts */
MUTEX_HANDLE
countMutex
;
public
:
public
:
/* constructor */
/* constructor */
XWorker
();
XWorker
();
...
@@ -109,30 +100,6 @@ public:
...
@@ -109,30 +100,6 @@ public:
/* whether the job queue is empty? */
/* whether the job queue is empty? */
bool
IsEmpty
();
bool
IsEmpty
();
/* reset the job counts */
void
ResetJobCount
(
int
myJobCountExpected
=
-
1
,
int
myJobCountFinished
=
0
);
/* lock the count mutex */
void
LockCount
();
/* unlock the count mutex */
void
UnlockCount
();
/* check if the worker finishes its job */
bool
IsFinished
();
/* count a finished job */
void
CountFinishedJob
();
/* wrapper of CountFinishedJob() */
static
void
CountFinished
(
XList
*
args
);
/* add a new job of counting finished jobs */
void
AddJobCountFinished
();
};
};
}
}
...
...
source/train/XWorkerBroadcast.cpp
查看文件 @
968c1e92
...
@@ -191,17 +191,10 @@ bool XWorkerBroadcast::AddJobBroadcastSingle(XModel * source, XList * targetList
...
@@ -191,17 +191,10 @@ bool XWorkerBroadcast::AddJobBroadcastSingle(XModel * source, XList * targetList
args
.
AddList
(
targetList
);
args
.
AddList
(
targetList
);
args
.
AddInt
(
pid
);
args
.
AddInt
(
pid
);
XList
argsNULL
;
if
(
isInstantRun
)
argsNULL
.
Add
(
this
);
if
(
isInstantRun
)
{
XWorkerBroadcast
::
BroadcastSingle
(
&
args
);
XWorkerBroadcast
::
BroadcastSingle
(
&
args
);
XWorkerBroadcast
::
CountFinished
(
&
argsNULL
);
else
}
else
{
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerBroadcast
::
BroadcastSingle
,
&
args
);
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerBroadcast
::
BroadcastSingle
,
&
args
);
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerBroadcast
::
CountFinished
,
&
argsNULL
);
}
return
true
;
return
true
;
}
}
...
...
source/train/XWorkerUpdate.cpp
查看文件 @
968c1e92
...
@@ -189,17 +189,10 @@ bool XWorkerUpdate::AddJobUpdateSingle(XModel * model, XList * members, int pid,
...
@@ -189,17 +189,10 @@ bool XWorkerUpdate::AddJobUpdateSingle(XModel * model, XList * members, int pid,
args
.
Add
(
optimizer
);
args
.
Add
(
optimizer
);
args
.
Add
(
broadcaster
);
args
.
Add
(
broadcaster
);
XList
argsNULL
;
if
(
isInstantRun
)
argsNULL
.
Add
(
this
);
if
(
isInstantRun
)
{
XWorkerUpdate
::
UpdateSingle
(
&
args
);
XWorkerUpdate
::
UpdateSingle
(
&
args
);
XWorkerUpdate
::
CountFinished
(
&
argsNULL
);
else
}
else
{
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerUpdate
::
UpdateSingle
,
&
args
);
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerUpdate
::
UpdateSingle
,
&
args
);
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerUpdate
::
CountFinished
,
&
argsNULL
);
}
return
true
;
return
true
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论