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
fbd915c6
Commit
fbd915c6
authored
Mar 11, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
d69372b3
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
101 行增加
和
2 行删除
+101
-2
source/tensor/XUtility.cpp
+3
-0
source/train/XModel.cpp
+31
-2
source/train/XModel.h
+12
-0
source/train/XWorkerBroadcast.cpp
+45
-0
source/train/XWorkerBroadcast.h
+10
-0
没有找到文件。
source/tensor/XUtility.cpp
查看文件 @
fbd915c6
...
...
@@ -485,6 +485,9 @@ unsigned int GetNextPower2(unsigned int n)
/* sleep for a while */
void
XSleep
(
int
sleepTime
)
{
if
(
sleepTime
<=
0
)
return
;
#ifdef _WIN32
Sleep
((
DWORD
)
sleepTime
);
#else
...
...
source/train/XModel.cpp
查看文件 @
fbd915c6
...
...
@@ -39,6 +39,7 @@ XParamKeeper::XParamKeeper()
{
param
=
NULL
;
flag
=
PARAM_STATE_NOT_READY
;
trainFlag
=
PARAM_STATE_NOT_READY
;
MUTEX_INIT
(
accessLock
);
MUTEX_INIT
(
trainLock
);
}
...
...
@@ -153,9 +154,36 @@ bool XModel::CheckParam()
/* initial model for running the it */
void
XModel
::
InitForRun
()
{
RefreshMe
();
}
/* lock the parameter states (wait for unlocking them when
a run of training is finished) */
void
XModel
::
LockParamsForTraining
()
{
for
(
int
i
=
0
;
i
<
paramNum
;
i
++
)
{
params
[
i
].
param
->
isGradFinished
=
false
;
params
[
i
].
flag
=
PARAM_STATE_NOT_READY
;
params
[
i
].
trainFlag
=
PARAM_STATE_NOT_READY
;
MUTEX_LOCK
(
params
[
i
].
trainLock
);
/* where is UNLOCK? We will do this when the training (a step)
is finsished. Then, WaitForUnlockedParams() can continue. In
such a way, we implement a START-WAIT process in each run
of training (a step) */
}
}
/* unlock the parameter states */
void
XModel
::
WaitForUnlockedParams
()
{
for
(
int
i
=
0
;
i
<
paramNum
;
i
++
)
{
/* the lock proceeds only when the trainLock is unlocked
in training. In this way, we are actually waiting for
the FINISHED signal from other workers/threads. */
MUTEX_LOCK
(
params
[
i
].
trainLock
);
CheckNTErrors
(
params
[
i
].
trainFlag
==
PARAM_STATE_UPDATED
,
"the state of the parameter is wrong!"
);
MUTEX_UNLOCK
(
params
[
i
].
trainLock
);
}
}
...
...
@@ -165,6 +193,7 @@ void XModel::RefreshMe()
for
(
int
i
=
0
;
i
<
paramNum
;
i
++
)
{
params
[
i
].
param
->
isGradFinished
=
false
;
params
[
i
].
flag
=
PARAM_STATE_NOT_READY
;
params
[
i
].
trainFlag
=
PARAM_STATE_NOT_READY
;
}
}
...
...
source/train/XModel.h
查看文件 @
fbd915c6
...
...
@@ -60,6 +60,11 @@ public:
/* the parameter state */
PARAM_STATE
flag
;
/* the state of the entire training process
(choosing from PARAM_STATE_NOT_READY and
PARAM_STATE_UPDATED */
PARAM_STATE
trainFlag
;
/* a mutex for locking and unlocking the parameter */
MUTEX_HANDLE
accessLock
;
...
...
@@ -119,6 +124,13 @@ public:
/* check if the parameters are well-defined for training */
bool
CheckParam
();
/* lock the parameter states (wait for unlocking them when
a run of training is finished) */
void
LockParamsForTraining
();
/* wait for unlocked the parameter states */
void
WaitForUnlockedParams
();
/* initial model for running the it */
void
InitForRun
();
...
...
source/train/XWorkerBroadcast.cpp
查看文件 @
fbd915c6
...
...
@@ -223,4 +223,49 @@ bool XWorkerBroadcast::AddJobBroadcast(XModel * source, XList * targetList)
return
true
;
}
/*
mark the state of the parameter to FINISHED
>> source - the model that we are updating
>> pid - the parameter index
*/
void
XWorkerBroadcast
::
FinishUpdateSingle
(
XModel
*
source
,
int
pid
)
{
source
->
params
[
pid
].
trainFlag
=
PARAM_STATE_UPDATED
;
MUTEX_UNLOCK
(
source
->
params
[
pid
].
trainLock
);
}
/* wrapper of FinishUpdateSingle */
void
XWorkerBroadcast
::
FinishSingle
(
XList
*
args
)
{
XWorkerBroadcast
*
broadcaster
=
(
XWorkerBroadcast
*
)
args
->
GetItem
(
0
);
XModel
*
source
=
(
XModel
*
)
args
->
GetItem
(
1
);
int
pid
=
args
->
GetInt
(
2
);
broadcaster
->
FinishUpdateSingle
(
source
,
pid
);
}
/*
add a new job of finishing the update
>> source - the model that we are updating
>> pid - the parameter index
*/
bool
XWorkerBroadcast
::
AddJobFinish
(
XModel
*
source
,
int
pid
)
{
CheckNTErrors
(
source
!=
NULL
,
"no input source tensor!"
);
CheckNTErrors
(
pid
>=
0
&&
pid
<
source
->
paramNum
,
"illegal parameter index!"
);
XList
args
;
args
.
Add
(
this
);
args
.
Add
(
source
);
args
.
AddInt
(
pid
);
if
(
isInstantRun
)
XWorkerBroadcast
::
FinishSingle
(
&
args
);
else
queue
.
EnqueueJob
((
void
*
)(
char
*
)
XWorkerBroadcast
::
FinishSingle
,
&
args
);
return
true
;
}
}
source/train/XWorkerBroadcast.h
查看文件 @
fbd915c6
...
...
@@ -82,6 +82,16 @@ public:
/* add a new job of broadcasting data (for a model) */
bool
AddJobBroadcast
(
XModel
*
source
,
XList
*
targetList
);
/* mark the state of the parameter to FINISHED */
void
FinishUpdateSingle
(
XModel
*
source
,
int
pid
);
/* wrapper of FinishUpdateSingle */
static
void
FinishSingle
(
XList
*
args
);
/* add a new job of finishing the update */
bool
AddJobFinish
(
XModel
*
source
,
int
pid
);
};
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论