Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
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
Emmay
NiuTrans.Tensor
Commits
75124987
Commit
75124987
authored
Jul 31, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixes
parent
a26caf40
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
48 行增加
和
46 行删除
+48
-46
source/network/Main.cpp
+1
-1
source/network/XBackwardMath.cpp
+1
-1
source/sample/fnnlm/FNNLM.cpp
+1
-1
source/sample/fnnlm/FNNLM.h
+2
-2
source/tensor/XTensor.cpp
+6
-7
source/tensor/XTensor.h
+3
-2
source/tensor/function/LogSoftmax.cpp
+34
-32
没有找到文件。
source/network/Main.cpp
查看文件 @
75124987
...
...
@@ -34,7 +34,7 @@ void TransposeTest();
void
SumDimTest
();
using
namespace
nts
;
using
namespace
sample
fnnlm
;
using
namespace
fnnlm
;
int
main
(
int
argc
,
const
char
**
argv
)
{
...
...
source/network/XBackwardMath.cpp
查看文件 @
75124987
...
...
@@ -143,7 +143,7 @@ void XMathGrad::GradSumDim(XTensor * node)
Then reduce along with z and x to obtain dE/db. */
node
->
grad
->
Reshape
(
3
,
reshapedSize
);
XTensor
*
interGrad
=
NewTensorBuf
(
2
,
reshapedSize
,
b
->
d
evID
,
b
->
mem
,
b
->
dataType
,
b
->
denseRatio
);
XTensor
*
interGrad
=
NewTensorBuf
(
2
,
reshapedSize
,
b
->
d
ataType
,
b
->
denseRatio
,
b
->
devID
,
b
->
mem
);
_ReduceSum
(
node
->
grad
,
interGrad
,
2
);
...
...
source/sample/fnnlm/FNNLM.cpp
查看文件 @
75124987
...
...
@@ -33,7 +33,7 @@
#include "../../tensor/function/FHeader.h"
#include "../../network/XNet.h"
namespace
sample
fnnlm
namespace
fnnlm
{
#define MAX_NAME_LENGTH 1024
...
...
source/sample/fnnlm/FNNLM.h
查看文件 @
75124987
...
...
@@ -36,7 +36,7 @@
using
namespace
nts
;
namespace
sample
fnnlm
namespace
fnnlm
{
#define _EXIT_(x)// exit(x)
...
...
@@ -126,7 +126,7 @@ struct FNNNet
XTensor
output
;
};
/* entr
y
of the program */
/* entr
ance
of the program */
int
FNNLMMain
(
int
argc
,
const
char
**
argv
);
};
...
...
source/tensor/XTensor.cpp
查看文件 @
75124987
...
...
@@ -1891,17 +1891,16 @@ generate a XTensor which allocates data on the buffer
>> myDenseRatio - how often an element has non-zero value
*/
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
int
devID
,
XMem
*
myMem
,
const
TENSOR_DATA_TYPE
myDataType
,
const
float
myDenseRatio
)
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
,
const
float
myDenseRatio
,
const
int
devID
,
XMem
*
myMem
)
{
CheckNTErrors
(
myMem
!=
NULL
,
"No memory pool specified!"
);
int
dims
[
MAX_TENSOR_DIM_NUM
];
memcpy
(
dims
,
myDimSize
,
sizeof
(
int
)
*
myOrder
);
dims
[
0
]
=
-
abs
(
dims
[
0
]);
XTensor
*
tensor
=
NewTensor
(
myOrder
,
dims
,
myDataType
,
myDenseRatio
,
-
1
,
myMem
);
XTensor
*
tensor
=
NewTensor
(
myOrder
,
dims
,
myDataType
,
myDenseRatio
,
devID
,
myMem
);
if
(
myMem
!=
NULL
)
tensor
->
data
=
myMem
->
AllocBuf
(
myMem
->
devID
,
tensor
->
unitNum
*
tensor
->
unitSize
);
...
...
@@ -1922,8 +1921,8 @@ generate a XTensor which allocates data on the buffer
XTensor
*
NewTensorBuf
(
const
XTensor
*
reference
,
int
devID
,
XMem
*
myMem
)
{
return
NewTensorBuf
(
reference
->
order
,
reference
->
dimSize
,
devID
,
myMem
,
reference
->
dataType
,
reference
->
denseRatio
);
reference
->
dataType
,
reference
->
denseRatio
,
devID
,
myMem
);
}
/*
...
...
source/tensor/XTensor.h
查看文件 @
75124987
...
...
@@ -391,8 +391,9 @@ XTensor * NewTensor(const int myOrder, const int * myDimSize, const TENSOR_DATA_
const
float
myDenseRatio
=
1
.
0
F
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* generate a XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
int
devID
,
XMem
*
myMem
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
float
myDenseRatio
=
1
.
0
F
);
XTensor
*
NewTensorBuf
(
const
int
myOrder
,
const
int
*
myDimSize
,
const
TENSOR_DATA_TYPE
myDataType
=
X_FLOAT
,
const
float
myDenseRatio
=
1
.
0
F
,
const
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* generate a XTensor which allocates data on the buffer */
XTensor
*
NewTensorBuf
(
const
XTensor
*
reference
,
int
devID
,
XMem
*
myMem
);
...
...
source/tensor/function/LogSoftmax.cpp
查看文件 @
75124987
...
...
@@ -38,6 +38,14 @@ log scale softmax y = log(e^x / \sum_{i} e^{x_i})
*/
void
_LogSoftmax
(
const
XTensor
*
x
,
XTensor
*
y
,
int
leadDim
)
{
CheckNTErrors
(
!
x
->
isSparse
&&
!
y
->
isSparse
,
"TODO!"
);
CheckNTErrors
(
x
&&
y
,
"Empty input tensors!"
);
if
(
y
->
dimSize
[
leadDim
]
==
1
){
y
->
SetZeroAll
();
return
;
}
int
leadDimRDI
=
x
->
order
-
leadDim
-
1
;
if
(
!
x
->
isSparse
&&
!
y
->
isSparse
&&
x
->
dataType
==
DEFAULT_DTYPE
&&
y
->
dataType
==
DEFAULT_DTYPE
)
...
...
@@ -63,30 +71,31 @@ void _LogSoftmax(const XTensor * x, XTensor * y, int leadDim)
int
blockSize
=
1
;
int
blockNum
=
1
;
for
(
int
i
=
0
;
i
<
leadDimRDI
;
i
++
)
stride
*=
y
->
dimSizeRDI
[
i
];
blockSize
=
stride
*
dimensionSize
;
blockNum
=
y
->
unitNum
/
blockSize
;
max
=
NewTensor
(
x
->
order
-
1
,
dimSize
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
sum
=
NewTensor
(
x
->
order
-
1
,
dimSize
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
max
->
data
=
mem
!=
NULL
?
(
char
*
)
mem
->
AllocBuf
(
mem
->
devID
,
max
->
unitNum
*
max
->
unitSize
)
:
XMemAlloc
(
max
->
devID
,
max
->
unitNum
*
max
->
unitSize
);
sum
->
data
=
mem
!=
NULL
?
(
char
*
)
mem
->
AllocBuf
(
mem
->
devID
,
sum
->
unitNum
*
sum
->
unitSize
)
:
XMemAlloc
(
sum
->
devID
,
sum
->
unitNum
*
sum
->
unitSize
);
max
=
NewTensorBuf
(
x
->
order
-
1
,
dimSize
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
sum
=
NewTensorBuf
(
x
->
order
-
1
,
dimSize
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
_ReduceMax
(
x
,
max
,
leadDim
);
_ReduceSum
(
x
,
sum
,
leadDim
,
max
,
1.0
F
,
true
);
if
(
x
->
devID
>=
0
)
{
int
dims
[
2
];
dims
[
0
]
=
-
stride
;
dims
[
1
]
=
dimensionSize
;
blockx
=
NewTensor
(
2
,
dims
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
blocky
=
NewTensor
(
2
,
dims
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
dims
[
0
]
=
-
stride
;
dims
[
1
]
=
1
;
blockMax
=
NewTensor
(
2
,
dims
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
blockSum
=
NewTensor
(
2
,
dims
,
x
->
dataType
,
x
->
denseRatio
,
x
->
devID
,
mem
);
if
(
leadDimRDI
==
0
){
blockSize
=
y
->
unitNum
;
blockNum
=
1
;
blockx
=
NewTensor2D
(
blockSize
/
dimensionSize
,
-
dimensionSize
,
x
->
dataType
,
x
->
devID
,
mem
);
blocky
=
NewTensor2D
(
blockSize
/
dimensionSize
,
-
dimensionSize
,
x
->
dataType
,
x
->
devID
,
mem
);
blockMax
=
NewTensor2D
(
blockSize
/
dimensionSize
,
-
1
,
x
->
dataType
,
x
->
devID
,
mem
);
blockSum
=
NewTensor2D
(
blockSize
/
dimensionSize
,
-
1
,
x
->
dataType
,
x
->
devID
,
mem
);
}
else
{
for
(
int
i
=
0
;
i
<
leadDimRDI
;
i
++
)
stride
*=
y
->
dimSizeRDI
[
i
];
blockSize
=
stride
*
dimensionSize
;
blockNum
=
y
->
unitNum
/
blockSize
;
blockx
=
NewTensor2D
(
-
stride
,
dimensionSize
,
x
->
dataType
,
x
->
devID
,
mem
);
blocky
=
NewTensor2D
(
-
stride
,
dimensionSize
,
x
->
dataType
,
x
->
devID
,
mem
);
blockMax
=
NewTensor2D
(
-
stride
,
1
,
x
->
dataType
,
x
->
devID
,
mem
);
blockSum
=
NewTensor2D
(
-
stride
,
1
,
x
->
dataType
,
x
->
devID
,
mem
);
}
}
for
(
int
k
=
0
;
k
<
blockNum
;
k
++
)
{
...
...
@@ -123,7 +132,10 @@ void _LogSoftmax(const XTensor * x, XTensor * y, int leadDim)
blockMax
->
data
=
mp
;
blockSum
->
data
=
sp
;
#ifdef USE_CUDA
_CudaLogSoftmaxSumMax
(
blockx
,
blocky
,
leadDim
,
blockSum
,
blockMax
);
if
(
leadDimRDI
==
0
)
_CudaLogSoftmaxSumMax
(
blockx
,
blocky
,
1
,
blockSum
,
blockMax
);
else
_CudaLogSoftmaxSumMax
(
blockx
,
blocky
,
leadDim
,
blockSum
,
blockMax
);
#else
ShowNTErrors
(
"Please specify USE_CUDA and recompile the code!"
);
#endif
...
...
@@ -135,18 +147,8 @@ void _LogSoftmax(const XTensor * x, XTensor * y, int leadDim)
}
if
(
x
->
devID
<
0
)
{
if
(
mem
!=
NULL
)
{
mem
->
ReleaseBuf
(
mem
->
devID
,
max
->
unitNum
*
max
->
unitSize
);
mem
->
ReleaseBuf
(
mem
->
devID
,
sum
->
unitNum
*
sum
->
unitSize
);
}
else
{
XMemFree
(
max
->
devID
,
max
->
data
);
XMemFree
(
sum
->
devID
,
sum
->
data
);
max
->
data
=
NULL
;
sum
->
data
=
NULL
;
}
delete
max
;
delete
sum
;
DelTensorBuf
(
max
);
DelTensorBuf
(
sum
);
}
else
{
delete
blockx
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论