Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
Tensor.LowPrecision
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
linye
Tensor.LowPrecision
Commits
3800528b
Commit
3800528b
authored
Jul 29, 2019
by
ltb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update setData flaot16 and modify some files which use the setData (main _SetDataFixed)
parent
ccfe71d0
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
154 行增加
和
238 行删除
+154
-238
source/network/XBackwardLoss.cpp
+6
-6
source/sample/transformer/T2TPredictor.cpp
+1
-1
source/tensor/core/getandset/SetData.cpp
+53
-105
source/tensor/core/getandset/SetData.cu
+81
-103
source/tensor/core/getandset/SetData.cuh
+4
-7
source/tensor/core/getandset/SetData.h
+5
-12
source/tensor/function/DropoutWithIndex.cpp
+1
-1
source/tensor/function/Loss.cpp
+3
-3
没有找到文件。
source/network/XBackwardLoss.cpp
查看文件 @
3800528b
...
...
@@ -53,11 +53,11 @@ void XLossGrad::MakeGrad(XTensor * node, bool isEfficient)
if
(
income
.
tailNum
==
1
)
{
if
(
dedy
->
dataType
==
X_FLOAT
)
_SetDataFixed
Float
(
dedy
,
1.0
F
);
_SetDataFixed
(
dedy
,
1.0
F
);
else
if
(
dedy
->
dataType
==
X_DOUBLE
)
_SetDataFixed
Double
(
dedy
,
1.0
);
_SetDataFixed
(
dedy
,
1.0
);
else
if
(
dedy
->
dataType
==
X_INT
)
_SetDataFixed
Int
(
dedy
,
1
);
_SetDataFixed
(
dedy
,
1
);
else
ShowNTErrors
(
"TODO"
);
...
...
@@ -145,11 +145,11 @@ void XLossGrad::Compute(XTensor * gold, XTensor * y,
{
if
(
gold
==
NULL
){
if
(
dedy
->
dataType
==
X_FLOAT
)
_SetDataFixed
Float
(
dedy
,
1.0
F
);
_SetDataFixed
(
dedy
,
1.0
F
);
else
if
(
dedy
->
dataType
==
X_DOUBLE
)
_SetDataFixed
Double
(
dedy
,
1.0
);
_SetDataFixed
(
dedy
,
1.0
);
else
if
(
dedy
->
dataType
==
X_INT
)
_SetDataFixed
Int
(
dedy
,
1
);
_SetDataFixed
(
dedy
,
1
);
else
{
ShowNTErrors
(
"TODO"
);
}
...
...
source/sample/transformer/T2TPredictor.cpp
查看文件 @
3800528b
...
...
@@ -171,7 +171,7 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding,
dims
[
inputEnc
->
order
-
1
]
=
1
;
InitTensor
(
&
first
,
inputEnc
->
order
,
dims
,
X_INT
,
1.0
F
,
inputEnc
->
devID
,
inputEnc
->
mem
);
_SetDataFixed
Int
(
&
first
,
startSymbol
);
_SetDataFixed
(
&
first
,
startSymbol
);
/* add a new word into the input sequence of the decoder side */
if
(
inputLast
==
NULL
)
{
...
...
source/tensor/core/getandset/SetData.cpp
查看文件 @
3800528b
...
...
@@ -25,6 +25,7 @@
#include "SetData.cuh"
#include "../../XUtility.h"
#include "../movement/CopyValues.h"
#include "ConvertDataType.h"
#if !defined( WIN32 ) && !defined( _WIN32 )
#include "sys/time.h"
...
...
@@ -81,82 +82,69 @@ generate data items with a fixed value p
>> tensor - the tensor whose data array would be initialized
>> p - pointer to the number for initializing the tensor
*/
void
_SetDataFixed
(
XTensor
*
tensor
,
void
*
valuePointer
)
template
<
class
T
>
void
_SetDataFixed
(
XTensor
*
tensor
,
T
value
)
{
#ifdef USE_CUDA
if
(
tensor
->
devID
>=
0
)
{
_CudaSetDataFixed
(
tensor
,
value
);
return
;
}
#endif
int
num
=
tensor
->
unitNum
;
if
(
tensor
->
dataType
==
X_INT
){
int
p
=
*
(
int
*
)
valuePointer
;
if
(
tensor
->
devID
<
0
){
int
*
d
=
(
int
*
)
tensor
->
data
;
if
(
num
%
4
==
0
){
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
){
d
[
i
]
=
p
;
d
[
i
+
1
]
=
p
;
d
[
i
+
2
]
=
p
;
d
[
i
+
3
]
=
p
;
}
}
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
p
;
if
(
tensor
->
dataType
==
X_INT
)
{
int
*
d
=
(
int
*
)
tensor
->
data
;
int
v
=
(
int
)
value
;
if
(
num
%
4
==
0
)
{
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
)
{
d
[
i
]
=
v
;
d
[
i
+
1
]
=
v
;
d
[
i
+
2
]
=
v
;
d
[
i
+
3
]
=
v
;
}
}
else
{
#ifdef USE_CUDA
_CudaSetDataFixedInt
(
tensor
,
p
);
#endif
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
v
;
}
}
else
if
(
tensor
->
dataType
==
X_FLOAT
){
float
p
=
*
(
float
*
)
valuePointer
;
if
(
tensor
->
devID
<
0
){
float
*
d
=
(
float
*
)
tensor
->
data
;
if
(
num
%
4
==
0
){
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
){
d
[
i
]
=
p
;
d
[
i
+
1
]
=
p
;
d
[
i
+
2
]
=
p
;
d
[
i
+
3
]
=
p
;
}
}
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
p
;
else
if
(
tensor
->
dataType
==
X_FLOAT
)
{
float
*
d
=
(
float
*
)
tensor
->
data
;
float
v
=
(
float
)
value
;
if
(
num
%
4
==
0
)
{
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
)
{
d
[
i
]
=
v
;
d
[
i
+
1
]
=
v
;
d
[
i
+
2
]
=
v
;
d
[
i
+
3
]
=
v
;
}
}
else
{
#ifdef USE_CUDA
_CudaSetDataFixedFloat
(
tensor
,
p
);
#endif
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
v
;
}
}
else
if
(
tensor
->
dataType
==
X_DOUBLE
){
double
p
=
*
(
double
*
)
valuePointer
;
if
(
tensor
->
devID
<
0
){
double
*
d
=
(
double
*
)
tensor
->
data
;
if
(
num
%
4
==
0
){
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
){
d
[
i
]
=
p
;
d
[
i
+
1
]
=
p
;
d
[
i
+
2
]
=
p
;
d
[
i
+
3
]
=
p
;
}
}
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
p
;
else
if
(
tensor
->
dataType
==
X_DOUBLE
)
{
double
*
d
=
(
double
*
)
tensor
->
data
;
double
v
=
(
double
)
value
;
if
(
num
%
4
==
0
)
{
for
(
int
i
=
0
;
i
<
num
;
i
+=
4
)
{
d
[
i
]
=
v
;
d
[
i
+
1
]
=
v
;
d
[
i
+
2
]
=
v
;
d
[
i
+
3
]
=
v
;
}
}
else
{
#ifdef USE_CUDA
_CudaSetDataFixedDouble
(
tensor
,
p
);
#endif
else
{
for
(
int
i
=
0
;
i
<
num
;
i
++
)
d
[
i
]
=
v
;
}
}
else
{
else
ShowNTErrors
(
"TODO"
);
}
}
/*
...
...
@@ -166,7 +154,7 @@ generate data items with a fixed value p (in default type)
*/
void
SetDataFixed
(
XTensor
&
tensor
,
DTYPE
p
)
{
_SetDataFixed
(
&
tensor
,
&
p
);
_SetDataFixed
(
&
tensor
,
p
);
}
/*
...
...
@@ -177,53 +165,17 @@ generate data items with a fixed value p (in integer)
void
SetDataFixedInt
(
XTensor
&
tensor
,
int
p
)
{
CheckNTErrors
(
tensor
.
dataType
==
X_INT
,
"An integer tensor is required!"
);
_SetDataFixed
(
&
tensor
,
&
p
);
_SetDataFixed
(
&
tensor
,
p
);
}
/*
generate data items with a fixed value p (in integer)
>> tensor - the tensor whose data array would be initialized
>> p - an int-valued number
*/
void
_SetDataFixedInt
(
XTensor
*
tensor
,
int
p
)
{
CheckNTErrors
(
tensor
->
dataType
==
X_INT
,
"the tensor must be in X_INT!"
);
template
void
_SetDataFixed
<
int
>
(
XTensor
*
,
int
);
template
void
_SetDataFixed
<
float
>
(
XTensor
*
,
float
);
template
void
_SetDataFixed
<
double
>
(
XTensor
*
,
double
);
if
(
p
==
0
)
tensor
->
SetZeroAll
();
else
_SetDataFixed
(
tensor
,
&
p
);
}
/*
generate data items with a fixed value p (in float)
>> tensor - the tensor whose data array would be initialized
>> p - a float-valued number
*/
void
_SetDataFixedFloat
(
XTensor
*
tensor
,
float
p
)
{
CheckNTErrors
(
tensor
->
dataType
==
X_FLOAT
,
"the tensor must be in X_FLOAT!"
);
if
(
p
==
0
)
tensor
->
SetZeroAll
();
else
_SetDataFixed
(
tensor
,
&
p
);
}
/*
generate data items with a fixed value p (in double)
>> tensor - the tensor whose data array would be initialized
>> p - a double-valued number
*/
void
_SetDataFixedDouble
(
XTensor
*
tensor
,
double
p
)
{
CheckNTErrors
(
tensor
->
dataType
==
X_DOUBLE
,
"the tensor must be in X_DOUBLE!"
);
if
(
p
==
0
)
tensor
->
SetZeroAll
();
else
_SetDataFixed
(
tensor
,
&
p
);
}
/*
generate data items with a fixed value p only if
...
...
@@ -319,7 +271,6 @@ void _SetDataDim(XTensor * tensor, int beg, int len, int dim, DTYPE p)
{
int
n
=
tensor
->
order
;
CheckNTErrors
(
tensor
->
dataType
==
DEFAULT_DTYPE
,
"TODO!"
);
CheckNTErrors
(
dim
<
n
&&
dim
>=
0
,
"Illegal dimension!"
);
CheckNTErrors
(
beg
>=
0
&&
beg
<
tensor
->
GetDim
(
dim
),
"Illegal beginning position!"
);
CheckNTErrors
(
beg
+
len
>=
0
&&
beg
+
len
<
tensor
->
GetDim
(
dim
),
"Illegal length!"
);
...
...
@@ -372,7 +323,6 @@ void _SetDataIndexed(XTensor * source, XTensor * modify, int dim, int index)
int
order
=
source
->
order
;
int
size
=
source
->
GetDim
(
dim
);
CheckNTErrors
(
source
->
dataType
==
DEFAULT_DTYPE
,
"TODO!"
);
CheckNTErrors
(
dim
>=
0
&&
dim
<
order
,
"Illegal dimension!"
);
CheckNTErrors
(
index
>=
0
&&
index
<
size
,
"Illegal index!"
);
...
...
@@ -527,8 +477,6 @@ the item to a pre-defined value if the item >= p, set the item to 0 otherwise
*/
void
_SetDataRandP
(
const
XTensor
*
tensor
,
DTYPE
lower
,
DTYPE
upper
,
DTYPE
p
,
DTYPE
value
)
{
CheckNTErrors
(
tensor
->
dataType
==
DEFAULT_DTYPE
,
"TODO"
);
if
(
tensor
->
devID
<
0
)
{
_SetDataRand
(
tensor
,
lower
,
upper
);
...
...
source/tensor/core/getandset/SetData.cu
查看文件 @
3800528b
差异被折叠。
点击展开。
source/tensor/core/getandset/SetData.cuh
查看文件 @
3800528b
...
...
@@ -19,6 +19,7 @@
/*
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-18
* I'm surprised that I did not write this file till today.
* $Update by: Lin Ye (email: linye2015@outlook.com) 2019-07-22 float16 added
*/
#ifndef __SETDATA_CUH__
...
...
@@ -28,14 +29,10 @@
namespace nts { // namespace nts(NiuTrans.Tensor)
/* generate data items with a fixed value p (in int) */
void _CudaSetDataFixedInt(XTensor * tensor, int p);
/* generate data items with a fixed value p (in int, float, float16, double) */
template<class T>
void _CudaSetDataFixed(XTensor * tensor, T p);
/* generate data items with a fixed value p (in float) */
void _CudaSetDataFixedFloat(XTensor * tensor, float p);
/* generate data items with a fixed value p (in double) */
void _CudaSetDataFixedDouble(XTensor * tensor, double p);
/* generate data items with a fixed value p (in float) only
if the condition entry is non-zero */
...
...
source/tensor/core/getandset/SetData.h
查看文件 @
3800528b
...
...
@@ -24,29 +24,22 @@
#define __SETDATA_H__
#include "../../XTensor.h"
#include "SetData.cuh"
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* generate data items with a xavier initialization */
void
_SetDataFanInOut
(
XTensor
*
tensor
,
DTYPE
gain
=
1
.
0
F
);
/* generate data items with a fixed value p */
void
_SetDataFixed
(
XTensor
*
tensor
,
void
*
valuePointer
);
/
//
* generate data items with a fixed value p */
//
void _SetDataFixed(XTensor * tensor, void * valuePointer);
/* generate data items with a fixed value p (in default type) */
void
SetDataFixed
(
XTensor
&
tensor
,
DTYPE
p
);
/* generate data items with a fixed value p (in integer) */
void
SetDataFixedInt
(
XTensor
&
tensor
,
int
p
);
/* generate data items with a fixed value p (in int) */
void
_SetDataFixedInt
(
XTensor
*
tensor
,
int
p
);
/* generate data items with a fixed value p (in float) */
void
_SetDataFixedFloat
(
XTensor
*
tensor
,
float
p
);
/* generate data items with a fixed value p (in double) */
void
_SetDataFixedDouble
(
XTensor
*
tensor
,
double
p
);
template
<
class
T
>
void
_SetDataFixed
(
XTensor
*
tensor
,
T
value
);
/* generate data items with a fixed value p only if the condition entry is non-zero */
void
_SetDataFixedCond
(
XTensor
*
tensor
,
XTensor
*
condition
,
DTYPE
p
);
...
...
source/tensor/function/DropoutWithIndex.cpp
查看文件 @
3800528b
...
...
@@ -70,7 +70,7 @@ XTensor DropoutWithIndex(const XTensor &x, XTensor &maskIndex, DTYPE scale)
InitTensor1D
(
&
c
,
x
.
unitNum
,
x
.
dataType
,
x
.
devID
,
x
.
mem
);
_SetDataFixed
Float
(
&
c
,
1.0
F
);
_SetDataFixed
(
&
c
,
1.0
F
);
_DropoutWithIndex
(
&
x
,
&
maskIndex
,
&
c
);
...
...
source/tensor/function/Loss.cpp
查看文件 @
3800528b
...
...
@@ -385,11 +385,11 @@ void _LossBackward(XTensor * dedy, XTensor * t, XTensor * y,
{
if
(
t
==
NULL
){
if
(
dedy
->
dataType
==
X_FLOAT
)
_SetDataFixed
Float
(
dedy
,
1.0
F
);
_SetDataFixed
(
dedy
,
1.0
F
);
else
if
(
dedy
->
dataType
==
X_DOUBLE
)
_SetDataFixed
Double
(
dedy
,
1.0
);
_SetDataFixed
(
dedy
,
1.0
);
else
if
(
dedy
->
dataType
==
X_INT
)
_SetDataFixed
Int
(
dedy
,
1
);
_SetDataFixed
(
dedy
,
1
);
else
{
ShowNTErrors
(
"TODO"
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论