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
杨迪
NiuTrans.Tensor
Commits
6ba61279
Commit
6ba61279
authored
Dec 26, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add broadcasting
parent
947db8fb
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
56 行增加
和
1 行删除
+56
-1
source/tensor/core/arithmetic/SumDim.cpp
+45
-0
source/tensor/core/arithmetic/SumDim.cu
+3
-1
source/tensor/core/arithmetic/SumDim.cuh
+2
-0
source/tensor/core/arithmetic/SumDim.h
+6
-0
没有找到文件。
source/tensor/core/arithmetic/SumDim.cpp
查看文件 @
6ba61279
...
...
@@ -17,6 +17,8 @@
/*
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-29
* &Updated by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-12-26
* Add summation by broadcasting.
*/
#include "Sum.h"
...
...
@@ -162,5 +164,48 @@ XTensor SumDim(const XTensor &a, const XTensor &b, int n, DTYPE beta)
return
c
;
}
/*
tensor broadcast summation c = a + b * \beta where some of dimensions of b can be of size 1
c = a + b * \beta
>> a - a tensor
>> b - another tensor that would be broadcasted
>> c - the resulting tensor
>> beta - the scaling factor
*/
void
_SumBroadcast
(
const
XTensor
*
a
,
const
XTensor
*
b
,
XTensor
*
c
,
DTYPE
beta
=
(
DTYPE
)
1.0
)
{
CheckNTErrors
(
a
->
order
==
b
->
order
,
"Wrong tensor orders!"
);
CheckNTErrors
(
a
->
order
==
c
->
order
,
"Wrong tensor orders!"
);
CheckNTErrors
(
a
->
order
>
0
,
"TODO!"
);
int
stride
=
1
;
int
strideNum
=
1
;
int
blockNum
=
1
;
int
count
=
0
;
for
(
int
i
=
a
->
order
-
1
;
i
>=
0
;
i
--
){
if
(
a
->
GetDim
(
i
)
==
b
->
GetDim
(
i
)){
stride
*=
b
->
GetDim
(
i
);
continue
;
}
else
if
(
b
->
GetDim
(
i
)
==
1
){
strideNum
*=
b
->
GetDim
(
i
);
if
(
i
>
0
&&
b
->
GetDim
(
i
-
1
)
==
1
)
continue
;
}
else
{
ShowNTErrors
(
"Wrong dimension size in broadcasting"
);
}
if
(
stride
>
0
){
blockNum
=
b
->
unitNum
/
(
stride
*
strideNum
);
stride
*=
strideNum
;
}
else
{
}
}
}
}
source/tensor/core/arithmetic/SumDim.cu
查看文件 @
6ba61279
...
...
@@ -17,6 +17,8 @@
/*
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-29
* &Updated by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-12-26
* Add summation by broadcasting.
*/
#include "SumDim.cuh"
...
...
@@ -28,7 +30,7 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
/*
tensor summation of a tensor and a row vector
c = a + b * \beta
c = a + b * \beta
where a is a tensor and b is a row vector
>> a - pointer to the data array of a
>> b - pointer to the data array of b
...
...
source/tensor/core/arithmetic/SumDim.cuh
查看文件 @
6ba61279
...
...
@@ -17,6 +17,8 @@
/*
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-29
* &Updated by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-12-26
* Add summation by broadcasting.
*/
#ifndef __SUMDIM_CUH__
...
...
source/tensor/core/arithmetic/SumDim.h
查看文件 @
6ba61279
...
...
@@ -18,6 +18,9 @@
/*
* $Created by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-07-29
* It reached to 39 centigrade around 3:00 pm in Shenyang
* &Updated by: XIAO Tong (email: xiaotong@mail.neu.edu.cn) 2018-12-26
* Add summation by broadcasting.
* Four of my master students graduated. Good luck to them for their future work!
*/
#ifndef __SUMDIM_H__
...
...
@@ -38,6 +41,9 @@ void _SumDim(XTensor * a, const XTensor * b, int n, DTYPE beta = (DTYPE)1.0);
/* tensor summation c = a + b * \beta where the size of b is equal to the n-th dimension of a,
i.e., a is summed with b by broadcasting. We make a new tensor c to keep the result and return it */
XTensor
SumDim
(
const
XTensor
&
a
,
const
XTensor
&
b
,
int
n
,
DTYPE
beta
=
(
DTYPE
)
1
.
0
);
/* tensor broadcast summation c = a + b * \beta where some of dimensions of b can be of size 1 */
void
_SumBroadcast
(
const
XTensor
*
a
,
const
XTensor
*
b
,
XTensor
*
c
,
DTYPE
beta
=
(
DTYPE
)
1
.
0
);
}
// namespace nts(NiuTrans.Tensor)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论