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
2bb8754f
Commit
2bb8754f
authored
Jul 26, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code for inference of fnnlm
parent
f31bc3fb
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
75 行删除
+17
-75
source/sample/fnnlm/FNNLM.cpp
+5
-0
source/tensor/core/arithmetic/MatrixMulBatched.cpp
+12
-75
没有找到文件。
source/sample/fnnlm/FNNLM.cpp
查看文件 @
2bb8754f
...
...
@@ -1106,6 +1106,7 @@ void Test(const char * test, const char * result, FNNModel &model)
/* the gold standard */
XTensor
gold
;
if
(
!
autoDiff
)
{
/* prepare an empty network for building the fnn */
FNNNet
net
;
...
...
@@ -1118,6 +1119,10 @@ void Test(const char * test, const char * result, FNNModel &model)
/* forward computation */
Forward
(
inputs
,
output
,
model
,
net
);
}
else
{
ForwardAutoDiff
(
inputs
,
output
,
model
);
}
/* prediction probabilities */
XTensor
probs
;
...
...
source/tensor/core/arithmetic/MatrixMulBatched.cpp
查看文件 @
2bb8754f
...
...
@@ -57,6 +57,11 @@ void _MatrixMulBatched(const XTensor * a, MATRIX_TRANS_TYPE transposedA,
CheckNTErrors
((
a
->
order
==
b
->
order
&&
a
->
order
==
c
->
order
),
"Input tensor and output tensor must have same order!"
);
if
(
a
->
devID
>=
0
||
b
->
devID
>=
0
||
c
->
devID
>=
0
)
{
_MatrixMulBatchedGPU
(
a
,
transposedA
,
b
,
transposedB
,
c
,
alpha
,
beta
);
return
;
}
int
an
=
transposedA
==
X_TRANS
?
a
->
dimSizeRDI
[
0
]
:
a
->
dimSizeRDI
[
1
];
int
am
=
transposedA
==
X_TRANS
?
a
->
dimSizeRDI
[
1
]
:
a
->
dimSizeRDI
[
0
];
int
bn
=
transposedB
==
X_TRANS
?
b
->
dimSizeRDI
[
0
]
:
b
->
dimSizeRDI
[
1
];
...
...
@@ -213,83 +218,15 @@ void _MatrixMulBatchedGPU(const XTensor * a, MATRIX_TRANS_TYPE transposedA,
blockNum
*=
a
->
dimSizeRDI
[
i
];
}
XList
*
aList
=
new
XList
(
10
);
XList
*
bList
=
new
XList
(
10
);
XList
*
cList
=
new
XList
(
10
);
int
aDimSize
[
2
]
=
{
-
a
->
dimSizeRDI
[
1
],
a
->
dimSizeRDI
[
0
]};
int
bDimSize
[
2
]
=
{
-
b
->
dimSizeRDI
[
1
],
b
->
dimSizeRDI
[
0
]};
int
cDimSize
[
2
]
=
{
-
c
->
dimSizeRDI
[
1
],
c
->
dimSizeRDI
[
0
]};
XTensor
*
tensorBuf
=
new
XTensor
[
blockNum
*
3
];
XTensor
*
aBuf
=
tensorBuf
;
XTensor
*
bBuf
=
tensorBuf
+
blockNum
;
XTensor
*
cBuf
=
tensorBuf
+
blockNum
*
2
;
for
(
int
p
=
0
;
p
<
blockNum
;
p
++
)
{
void
*
ap
=
(
char
*
)
a
->
data
+
aRealBlockSize
*
p
;
void
*
bp
=
(
char
*
)
b
->
data
+
bRealBlockSize
*
p
;
void
*
cp
=
(
char
*
)
c
->
data
+
cRealBlockSize
*
p
;
XTensor
*
ai
=
aBuf
+
p
;
XTensor
*
bi
=
bBuf
+
p
;
XTensor
*
ci
=
cBuf
+
p
;
InitTensor
(
ai
,
2
,
aDimSize
,
a
->
dataType
,
a
->
denseRatio
,
a
->
devID
,
a
->
mem
);
InitTensor
(
bi
,
2
,
bDimSize
,
b
->
dataType
,
b
->
denseRatio
,
b
->
devID
,
b
->
mem
);
InitTensor
(
ci
,
2
,
cDimSize
,
c
->
dataType
,
c
->
denseRatio
,
c
->
devID
,
c
->
mem
);
ai
->
data
=
ap
;
bi
->
data
=
bp
;
ci
->
data
=
cp
;
aList
->
Add
(
ai
);
bList
->
Add
(
bi
);
cList
->
Add
(
ci
);
}
if
(
a
->
devID
>=
0
&&
b
->
devID
>=
0
&&
c
->
devID
>=
0
)
{
#ifdef USE_CUDA
CheckNTErrors
((
a
->
devID
==
b
->
devID
&&
a
->
devID
==
c
->
devID
),
"The code must be run on the same GPU!"
);
int
devIDBackup
;
ProtectCudaDev
(
a
->
devID
,
devIDBackup
);
cublasHandle_t
*
handle
=
a
->
mem
!=
NULL
?
a
->
mem
->
GetCublasHandle
()
:
GDevs
.
GetCudaHandle
(
a
->
devID
);
_CudaBLASMatrixMULList
(
handle
,
aList
,
transposedA
,
bList
,
transposedB
,
cList
,
aList
->
count
,
alpha
,
beta
);
BacktoCudaDev
(
a
->
devID
,
devIDBackup
);
#else
ShowNTErrors
(
"Please specify USE_CUDA and recompile the code!"
);
#endif
}
else
{
CheckNTErrors
((
a
->
dataType
==
DEFAULT_DTYPE
),
"TODO!"
);
_MatrixMULBatchedCPU
(
aList
,
transposedA
,
bList
,
transposedB
,
cList
,
alpha
,
beta
);
}
for
(
int
i
=
0
;
i
<
aList
->
count
;
i
++
)
{
XTensor
*
ai
=
(
XTensor
*
)
aList
->
GetItem
(
i
);
ai
->
data
=
NULL
;;
}
for
(
int
i
=
0
;
i
<
bList
->
count
;
i
++
)
{
XTensor
*
bi
=
(
XTensor
*
)
bList
->
GetItem
(
i
);
bi
->
data
=
NULL
;
}
_CudaBLASMatrixMULBatchedStrided
(
handle
,
a
->
data
,
transposedA
,
a
->
dataType
,
aBlockSize
,
b
->
data
,
transposedB
,
b
->
dataType
,
bBlockSize
,
c
->
data
,
c
->
dataType
,
cBlockSize
,
blockNum
,
a
->
dimSizeRDI
[
1
],
a
->
dimSizeRDI
[
0
],
b
->
dimSizeRDI
[
1
],
b
->
dimSizeRDI
[
0
],
c
->
dimSizeRDI
[
1
],
c
->
dimSizeRDI
[
0
],
alpha
,
beta
);
for
(
int
i
=
0
;
i
<
cList
->
count
;
i
++
)
{
XTensor
*
ci
=
(
XTensor
*
)
cList
->
GetItem
(
i
);
ci
->
data
=
NULL
;
}
delete
[]
tensorBuf
;
delete
aList
;
delete
bList
;
delete
cList
;
}
/*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论