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
43331674
Commit
43331674
authored
Jul 10, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new code for Multiply
parent
f1e69d00
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
68 行增加
和
13 行删除
+68
-13
source/core/arithmetic/Multiply.cpp
+48
-4
source/core/arithmetic/Multiply.cu
+5
-5
source/core/arithmetic/Multiply.cuh
+1
-1
source/core/arithmetic/Multiply.h
+14
-3
没有找到文件。
source/core/arithmetic/Multiply.cpp
查看文件 @
43331674
...
...
@@ -34,18 +34,20 @@ where i is the index of the item
>> b - matrix b
>> c - result matrix
>> alpha - the coefficient
>> leadingDim - the dimension along which we perform broadcasting
>>
*/
void
Multiply
(
XTensor
*
a
,
XTensor
*
b
,
XTensor
*
c
,
int
leadingDim
,
DTYPE
alpha
)
void
_Multiply
(
const
XTensor
*
a
,
const
XTensor
*
b
,
XTensor
*
c
,
DTYPE
alpha
,
int
leadingDim
)
{
int
leadingDimRDI
=
a
->
order
-
leadingDim
-
1
;
CheckNTErrors
((
a
->
unitNum
<=
c
->
unitNum
&&
b
->
unitNum
<=
c
->
unitNum
),
"Unmatched tensors in multiplication!"
);
CheckNTErrors
((
a
->
order
==
b
->
order
&&
a
->
order
==
c
->
order
),
"Unmatched tensors!"
);
"Unmatched tensors in multiplication!"
);
CheckNTErrors
((
a
->
order
==
b
->
order
&&
a
->
order
==
c
->
order
),
"Unmatched tensors!"
);
#ifdef USE_CUDA
if
(
a
->
devID
>=
0
||
b
->
devID
>=
0
||
c
->
devID
>=
0
)
{
CudaMultiply
(
a
,
b
,
c
,
leadingDim
,
alpha
);
_CudaMultiply
(
a
,
b
,
c
,
alpha
,
leadingDim
);
return
;
}
#endif
...
...
@@ -118,4 +120,46 @@ void Multiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha
}
}
/*
element-wise product of two tensors and keep the result in the input
a(i) = a(i)*b(i) + \alpha * a(i)
where i is the index of the item
>> a - tensor a (where keep the result)
>> b - tensor b
>> alpha - the coefficient
>> leadingDim - the dimension along which we perform broadcasting
*/
void
_MultiplyMe
(
XTensor
*
a
,
const
XTensor
*
b
,
DTYPE
alpha
,
int
leadingDim
)
{
_Multiply
(
a
,
b
,
a
,
alpha
,
leadingDim
);
}
/*
make a tensor of the element-wise product for two input tensors:
c(i) = a(i)*b(i) + \alpha * c(i)
where i is the index of the item
>> a - tensor a
>> b - tensor b
>> alpha - the coefficient
>> leadingDim - the dimension along which we perform broadcasting
<< return - the product of the tensors
*/
XTensor
Multiply
(
const
XTensor
&
a
,
const
XTensor
&
b
,
DTYPE
alpha
,
int
leadingDim
)
{
CheckNTErrors
(
a
.
dimSize
[
leadingDim
]
==
b
.
dimSize
[
leadingDim
],
"TODO!"
);
XTensor
c
(
&
a
);
c
.
SetTMP
();
/* computation */
_Multiply
(
&
a
,
&
b
,
&
c
,
alpha
,
leadingDim
);
/* tensor connections */
XLink
::
MakeLink
(
&
a
,
&
b
,
&
c
,
MATH_MULTIPLY
);
XLink
::
AddParamToHead
(
&
c
,
alpha
);
XLink
::
AddParamToHeadInt
(
&
c
,
leadingDim
);
return
c
;
}
}
// namespace nts(NiuTrans.Tensor)
source/core/arithmetic/Multiply.cu
查看文件 @
43331674
...
...
@@ -117,15 +117,15 @@ where i is the item index
>> a - tensor a
>> b - tensor b
>> c - result tensor
>> leadingDim - leading dimension
>> alpha - the coefficient
>> leadingDim - dimension along which we perform broadcasting
*/
extern "C"
void
CudaMultiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE alpha
)
void
_CudaMultiply(const XTensor * a, const XTensor * b, XTensor * c, DTYPE alpha, int leadingDim
)
{
int leadingDimRDI = a->order - leadingDim - 1;
CheckNTErrors((a->unitNum <= c->unitNum && b->unitNum <= c->unitNum),
"Unmatched tensors in multiplication!");
"Unmatched tensors in multiplication!");
CheckNTErrors((a->order == b->order && a->order == c->order), "Unmatched tensors!");
int stride = 1;
...
...
@@ -138,8 +138,8 @@ void CudaMultiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim, DTYPE a
for (int i = 0; i < a->order; i++) {
if (i != leadingDimRDI) {
CheckNTErrors((a->dimSizeRDI[i] == b->dimSizeRDI[i] &&
a->dimSizeRDI[i] == c->dimSizeRDI[i]),
"Unmatched tensors!");
a->dimSizeRDI[i] == c->dimSizeRDI[i]),
"Unmatched tensors!");
}
if (i < leadingDimRDI)
stride *= a->dimSizeRDI[i];
...
...
source/core/arithmetic/Multiply.cuh
查看文件 @
43331674
...
...
@@ -42,7 +42,7 @@ void KernelMulElementWiseTensorDynamic(DTYPE * a, DTYPE * b, DTYPE * c, DTYPE al
/* element-wise product of two tensors */
extern "C"
void
CudaMultiply(XTensor * a, XTensor * b, XTensor * c, int leadingDim = 0, DTYPE alpha
= 0);
void
_CudaMultiply(const XTensor * a, const XTensor * b, XTensor * c, DTYPE alpha = 0, int leadingDim
= 0);
#endif // USE_CUDA
...
...
source/core/arithmetic/Multiply.h
查看文件 @
43331674
...
...
@@ -26,9 +26,20 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* element-wise product of two tensors */
extern
"C"
void
Multiply
(
XTensor
*
a
,
XTensor
*
b
,
XTensor
*
c
,
int
leadingDim
=
0
,
DTYPE
alpha
=
0
);
/* element-wise product of two tensors:
c(i) = a(i)*b(i) + \alpha * c(i)
where i is the index of the element */
void
_Multiply
(
const
XTensor
*
a
,
const
XTensor
*
b
,
XTensor
*
c
,
DTYPE
alpha
=
0
,
int
leadingDim
=
0
);
/* element-wise product of two tensors and keep the result in the input tensor:
a(i) = a(i)*b(i) + \alpha * a(i)
where i is the index of the element */
void
_MultiplyMe
(
XTensor
*
a
,
const
XTensor
*
b
,
DTYPE
alpha
=
0
,
int
leadingDim
=
0
);
/* make a tensor of the element-wise product for two input tensors:
c(i) = a(i)*b(i) + \alpha * c(i)
where i is the index of the element */
XTensor
Multiply
(
const
XTensor
&
a
,
const
XTensor
&
b
,
DTYPE
alpha
=
0
,
int
leadingDim
=
0
);
}
// namespace nts(NiuTrans.Tensor)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论