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
218fdfd8
Commit
218fdfd8
authored
May 16, 2019
by
Tianzhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish reduce max
parent
569cb2dd
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
85 行增加
和
10 行删除
+85
-10
source/tensor/core/reduce/ReduceMax.cpp
+66
-5
source/tensor/core/reduce/VectorBuffer.h
+19
-5
没有找到文件。
source/tensor/core/reduce/ReduceMax.cpp
查看文件 @
218fdfd8
...
...
@@ -22,6 +22,7 @@
#include "../../XTensor.h"
#include "../../XName.h"
#include "../../XBLAS.h"
#include "./VectorBuffer.h"
#include "../arithmetic/XTensorBLAS.h"
#include "ReduceMax.h"
#include "ReduceMax.cuh"
...
...
@@ -78,14 +79,73 @@ void _ReduceMax(const XTensor * input, XTensor * output, int dim)
}
blockSize
=
stride
*
strideNum
;
if
(
input
->
dimSizeRDI
[
0
]
%
(
4
*
32
/
sizeof
(
DTYPE
))
==
0
&&
input
->
dimSizeRDI
[
0
]
>=
32
){
int
vecBufLength
=
32
/
sizeof
(
DTYPE
);
if
(
dimRDI
==
0
){
//data is contiguous in dim 0
for
(
int
i
=
0
;
i
<
blockNum
;
i
++
){
// stride = 1
DTYPE
*
ip
=
(
DTYPE
*
)
input
->
data
+
blockSize
*
i
;
DTYPE
*
op
=
(
DTYPE
*
)
output
->
data
+
i
;
VectorBuffer
vecBuf
[
4
];
for
(
int
j
=
0
;
j
<
4
;
j
++
){
// std::cout << isExp << " " << power << " " << bias[0] << std::endl;
vecBuf
[
j
]
=
VectorBuffer
::
loadu
((
DTYPE
*
)(
ip
)
+
j
*
vecBufLength
);
}
for
(
int
j
=
1
;
j
<
strideNum
/
32
;
j
++
){
const
DTYPE
*
ptr
=
(
DTYPE
*
)(
ip
+
j
*
vecBufLength
);
vecBuf
[
0
]
=
vecBuf
[
0
].
max
(
VectorBuffer
::
loadu
(
ptr
+
0
*
vecBufLength
));
vecBuf
[
1
]
=
vecBuf
[
1
].
max
(
VectorBuffer
::
loadu
(
ptr
+
1
*
vecBufLength
));
vecBuf
[
2
]
=
vecBuf
[
2
].
max
(
VectorBuffer
::
loadu
(
ptr
+
2
*
vecBufLength
));
vecBuf
[
3
]
=
vecBuf
[
3
].
max
(
VectorBuffer
::
loadu
(
ptr
+
3
*
vecBufLength
));
}
vecBuf
[
0
]
=
vecBuf
[
0
].
max
(
vecBuf
[
1
]);
vecBuf
[
0
]
=
vecBuf
[
0
].
max
(
vecBuf
[
2
]);
vecBuf
[
0
]
=
vecBuf
[
0
].
max
(
vecBuf
[
3
]);
DTYPE
maxN
=
DTYPE_MIN
;
for
(
int
k
=
0
;
k
<
vecBufLength
;
k
++
){
maxN
=
std
::
max
(
maxN
,
vecBuf
[
0
][
k
]);
}
*
op
=
maxN
;
}
}
else
{
//data is separated
for
(
int
i
=
0
;
i
<
blockNum
;
i
++
){
for
(
int
j
=
0
;
j
<
input
->
dimSizeRDI
[
0
]
/
32
;
j
++
){
DTYPE
*
ip
=
(
DTYPE
*
)
input
->
data
+
blockSize
*
i
;
DTYPE
*
op
=
(
DTYPE
*
)
output
->
data
+
stride
*
i
;
VectorBuffer
vecBuf
[
4
];
for
(
int
k
=
0
;
k
<
4
;
k
++
){
vecBuf
[
k
]
=
VectorBuffer
::
loadu
((
DTYPE
*
)(
ip
)
+
(
j
*
4
+
k
)
*
32
/
sizeof
(
DTYPE
));
}
for
(
int
k
=
1
;
k
<
strideNum
;
k
++
){
DTYPE
*
ptr
=
ip
+
k
*
stride
+
(
j
*
4
)
*
vecBufLength
;
vecBuf
[
0
]
=
vecBuf
[
0
].
max
(
VectorBuffer
::
loadu
(
ptr
+
0
*
vecBufLength
));
vecBuf
[
1
]
=
vecBuf
[
1
].
max
(
VectorBuffer
::
loadu
(
ptr
+
1
*
vecBufLength
));
vecBuf
[
2
]
=
vecBuf
[
2
].
max
(
VectorBuffer
::
loadu
(
ptr
+
2
*
vecBufLength
));
vecBuf
[
3
]
=
vecBuf
[
3
].
max
(
VectorBuffer
::
loadu
(
ptr
+
3
*
vecBufLength
));
}
for
(
int
k
=
0
;
k
<
4
;
k
++
){
for
(
int
l
=
0
;
l
<
vecBufLength
;
l
++
)
*
(
op
+
j
*
32
+
8
*
k
+
l
)
=
vecBuf
[
k
][
l
];
}
}
}
}
}
//run vector buffer
else
{
for
(
int
k
=
0
;
k
<
blockNum
;
k
++
){
DTYPE
*
ip
=
(
DTYPE
*
)
input
->
data
+
blockSize
*
k
;
DTYPE
*
op
=
(
DTYPE
*
)
output
->
data
+
stride
*
k
;
for
(
int
i
=
0
;
i
<
stride
;
i
++
){
//#if defined(USE_BLAS)
// *(op + i) = *(ip + i + (int)(stride * IAMAX(strideNum, ip + i, stride)));
//#else
DTYPE
max
=
FLOAT
_MIN
;
//#if defined(USE_BLAS)
// *(op + i) = *(ip + i + (int)(stride * IAMAX(strideNum, ip + i, stride)));
//#else
DTYPE
max
=
DTYPE
_MIN
;
DTYPE
*
ipe
=
ip
+
blockSize
;
for
(
DTYPE
*
ipb
=
ip
+
i
;
ipb
<
ipe
;
ipb
+=
stride
){
DTYPE
v
=
*
ipb
;
...
...
@@ -93,7 +153,8 @@ void _ReduceMax(const XTensor * input, XTensor * output, int dim)
max
=
v
;
}
*
(
op
+
i
)
=
max
;
//#endif
//#endif
}
}
}
}
...
...
source/tensor/core/reduce/VectorBuffer.h
查看文件 @
218fdfd8
#include <cstring>
#include <cmath>
#include <algorithm>
#include "../../XGlobal.h"
...
...
@@ -20,7 +21,7 @@ class VectorBuffer{
int
count
=
32
/
sizeof
(
DTYPE
);
VectorBuffer
vec
;
if
(
isExp
){
if
(
bias
==
0
){
if
(
bias
==
NULL
){
if
(
power
==
(
DTYPE
)
1
.
0
){
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
vec
.
values
[
i
]
=
(
DTYPE
)
std
::
exp
(
*
(
ptr
+
i
));
...
...
@@ -38,7 +39,7 @@ class VectorBuffer{
vec
.
values
[
i
]
=
(
DTYPE
)
std
::
exp
(
std
::
pow
(
*
(
ptr
+
i
),
power
));
}
}
}
//is bias ==
0
}
//is bias ==
NULL
else
{
if
(
power
==
(
DTYPE
)
1
.
0
){
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
...
...
@@ -61,7 +62,7 @@ class VectorBuffer{
}
}
//isExp
else
{
if
(
bias
==
0
){
if
(
bias
==
NULL
){
if
(
power
==
(
DTYPE
)
1
.
0
){
std
::
memcpy
(
vec
.
values
,
ptr
,
count
*
sizeof
(
DTYPE
));
}
else
if
(
power
==
(
DTYPE
)
2
.
0
){
...
...
@@ -77,7 +78,7 @@ class VectorBuffer{
vec
.
values
[
i
]
=
(
DTYPE
)
std
::
pow
(
*
(
ptr
+
i
),
power
);
}
}
}
// if bias ==
0
}
// if bias ==
NULL
else
{
if
(
power
==
(
DTYPE
)
1
.
0
){
for
(
int
i
=
0
;
i
!=
count
;
i
++
)
{
...
...
@@ -104,10 +105,22 @@ class VectorBuffer{
const
DTYPE
&
operator
[](
int
idx
)
const
{
return
values
[
idx
];
}
VectorBuffer
operator
+
(
const
VectorBuffer
&
a
)
{
inline
VectorBuffer
operator
+
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
a
[
i
]
+
this
->
values
[
i
];
}
return
*
this
;
}
inline
VectorBuffer
max
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
std
::
max
(
a
[
i
],
this
->
values
[
i
]);
}
return
*
this
;
}
inline
VectorBuffer
min
(
const
VectorBuffer
&
a
)
{
for
(
int
i
=
0
;
i
!=
a
.
size
();
i
++
)
{
this
->
values
[
i
]
=
std
::
min
(
a
[
i
],
this
->
values
[
i
]);
}
return
*
this
;
}
};
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论