Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
549e6d0f
Commit
549e6d0f
authored
Mar 18, 2020
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge with XU Chen branch (Don't use this! It's an incomplete version)
1. Clean the codes. 2. Fix minor errors.
parent
2c3c2c86
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
1 行增加
和
153 行删除
+1
-153
source/Main.cpp
+0
-152
source/tensor/XCall.cpp
+1
-1
没有找到文件。
source/Main.cpp
查看文件 @
549e6d0f
...
...
@@ -63,155 +63,3 @@ int main( int argc, const char ** argv )
return
0
;
}
void
BackwardTest
()
{
XNet
net
;
XTensor
a
;
XTensor
b
;
XTensor
c
;
a
.
enableGrad
=
true
;
b
.
enableGrad
=
false
;
c
.
enableGrad
=
false
;
XTensor
mean
;
XTensor
origin
;
InitTensor2DV2
(
&
a
,
2
,
3
);
InitTensor1DV2
(
&
b
,
2
);
a
.
SetZeroAll
();
b
.
SetZeroAll
();
a
.
Set2D
(
1.0
F
,
0
,
0
);
a
.
Set2D
(
2.0
F
,
0
,
1
);
a
.
Set2D
(
3.0
F
,
0
,
2
);
a
.
Set2D
(
4.0
F
,
1
,
0
);
a
.
Set2D
(
5.0
F
,
1
,
1
);
a
.
Set2D
(
6.0
F
,
1
,
2
);
b
.
Set1D
(
2.0
F
,
0
);
b
.
Set1D
(
1.0
F
,
1
);
DivDim
(
a
,
b
,
c
,
0
);
c
.
Dump
(
stderr
,
"c:"
);
auto
loss
=
CrossEntropy
(
c
,
a
);
//XLink::ShowNetwork(stderr, &c);
net
.
Backward
(
loss
);
a
.
grad
->
Dump
(
stderr
);
}
void
TransposeTest
()
{
#ifdef USE_CUDA
XMem
mem0
(
0
,
UNI_FREE
,
MILLION
*
64
,
1024
,
MILLION
*
64
);
//XMem mem1(1, UNI_FREE, MILLION * 64, 1024, MILLION * 64);
XTensor
x
;
XTensor
y
;
XTensor
z
;
int
loops
=
2000
;
int
B
=
3
*
2
*
4
;
int
K
=
8
*
1
;
int
N
=
50
;
int
H
=
512
*
4
;
int
nnn
=
GDevs
.
nGPU
;
InitTensor3DV2
(
&
x
,
B
,
N
,
H
,
X_FLOAT
,
0
);
InitTensor4DV2
(
&
y
,
K
,
B
,
N
,
H
/
K
,
X_FLOAT
,
0
);
InitTensor3DV2
(
&
z
,
B
,
N
,
H
,
X_FLOAT
,
0
);
cudaEvent_t
ctime0
;
cudaEvent_t
ctime1
;
cudaEvent_t
ctime2
;
cudaEvent_t
ctime3
;
cudaEvent_t
ctime4
;
cudaEvent_t
ctime5
;
float
elapsedSplit
=
0.0
;
float
elapsedMerge
=
0.0
;
float
elapsedSum
=
0.0
;
cudaEventCreate
(
&
ctime0
);
cudaEventCreate
(
&
ctime1
);
cudaEventCreate
(
&
ctime2
);
cudaEventCreate
(
&
ctime3
);
cudaEventCreate
(
&
ctime4
);
cudaEventCreate
(
&
ctime5
);
cudaEventRecord
(
ctime0
,
0
);
double
time0
=
GetClock
();
for
(
int
i
=
0
;
i
<
loops
;
i
++
)
_Split
(
&
x
,
&
y
,
2
,
K
);
double
time1
=
GetClock
();
cudaEventRecord
(
ctime1
,
0
);
cudaEventSynchronize
(
ctime1
);
cudaEventElapsedTime
(
&
elapsedSplit
,
ctime0
,
ctime1
);
cudaEventRecord
(
ctime2
,
0
);
double
time2
=
GetClock
();
for
(
int
i
=
0
;
i
<
loops
;
i
++
)
_Merge
(
&
y
,
&
x
,
3
);
double
time3
=
GetClock
();
cudaEventRecord
(
ctime3
,
0
);
cudaEventSynchronize
(
ctime3
);
cudaEventElapsedTime
(
&
elapsedMerge
,
ctime2
,
ctime3
);
cudaEventRecord
(
ctime4
,
0
);
double
time4
=
GetClock
();
for
(
int
i
=
0
;
i
<
loops
;
i
++
)
_Sum
(
&
x
,
&
z
,
&
x
);
double
time5
=
GetClock
();
cudaEventRecord
(
ctime5
,
0
);
cudaEventSynchronize
(
ctime5
);
cudaEventElapsedTime
(
&
elapsedSum
,
ctime4
,
ctime5
);
fprintf
(
stderr
,
"split:%f merge:%f sum:%f
\n
"
,
time1
-
time0
,
time3
-
time2
,
time5
-
time4
);
fprintf
(
stderr
,
"split:%f merge:%f sum:%f
\n
"
,
elapsedSplit
,
elapsedMerge
,
elapsedSum
);
#endif
}
void
SumDimTest
()
{
XTensor
x
;
XTensor
y
;
XTensor
z
;
int
a
=
5
;
int
b
=
7
;
int
c
=
3
;
InitTensor3DV2
(
&
x
,
a
,
b
,
c
,
X_FLOAT
,
-
1
);
InitTensor1DV2
(
&
y
,
c
,
X_FLOAT
,
-
1
);
InitTensor3DV2
(
&
z
,
a
,
b
,
c
,
X_FLOAT
,
-
1
);
x
.
SetZeroAll
();
y
.
SetZeroAll
();
z
.
SetZeroAll
();
DTYPE
*
data
=
new
DTYPE
[
x
.
unitNum
];
for
(
int
i
=
0
;
i
<
x
.
unitNum
;
i
++
)
data
[
i
]
=
(
DTYPE
)
i
;
x
.
SetData
(
data
,
x
.
unitNum
);
for
(
int
i
=
0
;
i
<
y
.
unitNum
;
i
++
)
data
[
i
]
=
-
(
DTYPE
)
i
;
y
.
SetData
(
data
,
y
.
unitNum
);
_SumDim
(
&
x
,
&
y
,
&
z
,
2
);
z
.
Dump
(
stderr
,
"z:"
);
delete
[]
data
;
}
source/tensor/XCall.cpp
查看文件 @
549e6d0f
...
...
@@ -842,7 +842,7 @@ XTensor * NewTensor5D(const int d0, const int d1, const int d2, const int d3, co
XTensor
*
NewTensorRange
(
int
lower
,
int
upper
,
int
step
,
const
TENSOR_DATA_TYPE
myDataType
,
const
int
myDevID
,
const
bool
isEnableGrad
)
{
int
size
=
abs
(
upper
-
lower
);
int
unitNum
=
ceil
(
1.0
*
size
/
abs
(
step
));
int
unitNum
=
(
int
)
ceil
(
1.0
*
size
/
abs
(
step
));
XTensor
*
tensor
=
NewTensor1D
(
unitNum
,
myDataType
,
myDevID
,
isEnableGrad
);
tensor
->
Range
(
lower
,
upper
,
step
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论