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
44683b39
Commit
44683b39
authored
Jul 25, 2019
by
张裕浩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update TopK unit test
parent
cbe68108
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
195 行增加
和
12 行删除
+195
-12
source/tensor/test/TTopK.cpp
+195
-12
没有找到文件。
source/tensor/test/TTopK.cpp
查看文件 @
44683b39
...
...
@@ -105,10 +105,62 @@ bool TestTopK1()
TopK
(
sUser
,
tUser2
,
indexUser2
,
dim
,
k
);
/* check results */
cpuTest
=
t1
->
CheckData
(
tAnswer1
,
tUnitNum
)
&&
tUser1
.
CheckData
(
tAnswer1
,
tUnitNum
)
&&
t2
->
CheckData
(
tAnswer2
,
tUnitNum
)
&&
tUser2
.
CheckData
(
tAnswer2
,
tUnitNum
)
&&
index1
->
CheckData
(
indexAnswer1
,
tUnitNum
)
&&
indexUser1
.
CheckData
(
indexAnswer1
,
tUnitNum
)
&&
index2
->
CheckData
(
indexAnswer2
,
tUnitNum
)
&&
indexUser2
.
CheckData
(
indexAnswer2
,
tUnitNum
);
for
(
int
i
=
0
;
i
<
tDimSize
[
1
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
0
];
++
j
)
{
float
tmpData
=
((
float
*
)
t1
->
data
)[
i
+
tDimSize
[
1
]
*
j
];
int
tmpIndex
=
((
int
*
)
index1
->
data
)[
i
+
tDimSize
[
1
]
*
j
];
float
tmpDataUser
=
((
float
*
)
tUser1
.
data
)[
i
+
tDimSize
[
1
]
*
j
];
int
tmpIndexUser
=
((
int
*
)
indexUser1
.
data
)[
i
+
tDimSize
[
1
]
*
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
0
];
++
k
)
{
float
*
ans
=
tAnswer1
[
0
];
int
*
ansIndex
=
indexAnswer1
[
0
];
if
(
tmpData
==
ans
[
i
+
tDimSize
[
1
]
*
k
]
&&
tmpIndex
==
ansIndex
[
i
+
tDimSize
[
1
]
*
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
+
tDimSize
[
1
]
*
k
]
&&
tmpIndexUser
==
ansIndex
[
i
+
tDimSize
[
1
]
*
k
])
{
flagUser
=
true
;
}
}
cpuTest
=
cpuTest
&&
flag
&&
flagUser
;
}
}
for
(
int
i
=
0
;
i
<
tDimSize
[
0
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
1
];
++
j
)
{
float
tmpData
=
((
float
*
)
t2
->
data
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndex
=
((
int
*
)
index2
->
data
)[
i
*
tDimSize
[
1
]
+
j
];
float
tmpDataUser
=
((
float
*
)
tUser2
.
data
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndexUser
=
((
int
*
)
indexUser2
.
data
)[
i
*
tDimSize
[
1
]
+
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
1
];
++
k
)
{
float
*
ans
=
tAnswer2
[
0
];
int
*
ansIndex
=
indexAnswer2
[
0
];
if
(
tmpData
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndex
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndexUser
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flagUser
=
true
;
}
}
cpuTest
=
cpuTest
&&
flag
&&
flagUser
;
}
}
#ifdef USE_CUDA
/* GPU test */
...
...
@@ -152,10 +204,74 @@ bool TestTopK1()
TopK
(
sUserGPU
,
tUserGPU2
,
indexUserGPU2
,
dim
,
k
);
/* check results */
gpuTest
=
tGPU1
->
CheckData
(
tAnswer1
,
tUnitNum
)
&&
tUserGPU1
.
CheckData
(
tAnswer1
,
tUnitNum
)
&&
tGPU2
->
CheckData
(
tAnswer2
,
tUnitNum
)
&&
tUserGPU2
.
CheckData
(
tAnswer2
,
tUnitNum
)
&&
indexGPU1
->
CheckData
(
indexAnswer1
,
tUnitNum
)
&&
indexUserGPU1
.
CheckData
(
indexAnswer1
,
tUnitNum
)
&&
indexGPU2
->
CheckData
(
indexAnswer2
,
tUnitNum
)
&&
indexUserGPU2
.
CheckData
(
indexAnswer2
,
tUnitNum
);
float
*
checkData
=
new
float
[
tUnitNum
];
int
*
checkIndex
=
new
int
[
tUnitNum
];
float
*
checkDataUser
=
new
float
[
tUnitNum
];
int
*
checkIndexUser
=
new
int
[
tUnitNum
];
cudaMemcpy
(
checkData
,
tGPU1
->
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndex
,
indexGPU1
->
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkDataUser
,
tUserGPU1
.
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndexUser
,
indexUserGPU1
.
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
for
(
int
i
=
0
;
i
<
tDimSize
[
1
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
0
];
++
j
)
{
float
tmpData
=
((
float
*
)
checkData
)[
i
+
tDimSize
[
1
]
*
j
];
int
tmpIndex
=
((
int
*
)
checkIndex
)[
i
+
tDimSize
[
1
]
*
j
];
float
tmpDataUser
=
((
float
*
)
checkDataUser
)[
i
+
tDimSize
[
1
]
*
j
];
int
tmpIndexUser
=
((
int
*
)
checkIndexUser
)[
i
+
tDimSize
[
1
]
*
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
0
];
++
k
)
{
float
*
ans
=
tAnswer1
[
0
];
int
*
ansIndex
=
indexAnswer1
[
0
];
if
(
tmpData
==
ans
[
i
+
tDimSize
[
1
]
*
k
]
&&
tmpIndex
==
ansIndex
[
i
+
tDimSize
[
1
]
*
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
+
tDimSize
[
1
]
*
k
]
&&
tmpIndexUser
==
ansIndex
[
i
+
tDimSize
[
1
]
*
k
])
{
flagUser
=
true
;
}
}
gpuTest
=
gpuTest
&&
flag
&&
flagUser
;
}
}
cudaMemcpy
(
checkData
,
tGPU2
->
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndex
,
indexGPU2
->
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkDataUser
,
tUserGPU2
.
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndexUser
,
indexUserGPU2
.
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
for
(
int
i
=
0
;
i
<
tDimSize
[
0
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
1
];
++
j
)
{
float
tmpData
=
((
float
*
)
checkData
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndex
=
((
int
*
)
checkIndex
)[
i
*
tDimSize
[
1
]
+
j
];
float
tmpDataUser
=
((
float
*
)
checkDataUser
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndexUser
=
((
int
*
)
checkIndexUser
)[
i
*
tDimSize
[
1
]
+
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
1
];
++
k
)
{
float
*
ans
=
tAnswer2
[
0
];
int
*
ansIndex
=
indexAnswer2
[
0
];
if
(
tmpData
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndex
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndexUser
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flagUser
=
true
;
}
}
gpuTest
=
gpuTest
&&
flag
&&
flagUser
;
}
}
/* destroy variables */
delete
s
;
...
...
@@ -170,6 +286,10 @@ bool TestTopK1()
delete
indexGPU2
;
delete
[]
sDimSize
;
delete
[]
tDimSize
;
delete
[]
checkData
;
delete
[]
checkIndex
;
delete
[]
checkDataUser
;
delete
[]
checkIndexUser
;
return
cpuTest
&&
gpuTest
;
#else
...
...
@@ -247,8 +367,33 @@ bool TestTopK2()
TopK
(
sUser
,
tUser
,
indexUser
,
dim
,
k
);
/* check results */
cpuTest
=
t
->
CheckData
(
tAnswer
,
tUnitNum
)
&&
tUser
.
CheckData
(
tAnswer
,
tUnitNum
)
&&
index
->
CheckData
(
indexAnswer
,
tUnitNum
)
&&
indexUser
.
CheckData
(
indexAnswer
,
tUnitNum
);
for
(
int
i
=
0
;
i
<
tDimSize
[
0
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
1
];
++
j
)
{
float
tmpData
=
((
float
*
)
t
->
data
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndex
=
((
int
*
)
index
->
data
)[
i
*
tDimSize
[
1
]
+
j
];
float
tmpDataUser
=
((
float
*
)
tUser
.
data
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndexUser
=
((
int
*
)
indexUser
.
data
)[
i
*
tDimSize
[
1
]
+
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
1
];
++
k
)
{
float
*
ans
=
tAnswer
[
0
];
int
*
ansIndex
=
indexAnswer
[
0
];
if
(
tmpData
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndex
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndexUser
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flagUser
=
true
;
}
}
cpuTest
=
cpuTest
&&
flag
&&
flagUser
;
}
}
#ifdef USE_CUDA
/* GPU test */
...
...
@@ -279,8 +424,42 @@ bool TestTopK2()
TopK
(
sUserGPU
,
tUserGPU
,
indexUserGPU
,
dim
,
k
);
/* check results */
gpuTest
=
tGPU
->
CheckData
(
tAnswer
,
tUnitNum
)
&&
tUserGPU
.
CheckData
(
tAnswer
,
tUnitNum
)
&&
indexGPU
->
CheckData
(
indexAnswer
,
tUnitNum
)
&&
indexUserGPU
.
CheckData
(
indexAnswer
,
tUnitNum
);
float
*
checkData
=
new
float
[
tUnitNum
];
int
*
checkIndex
=
new
int
[
tUnitNum
];
float
*
checkDataUser
=
new
float
[
tUnitNum
];
int
*
checkIndexUser
=
new
int
[
tUnitNum
];
cudaMemcpy
(
checkData
,
tGPU
->
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndex
,
indexGPU
->
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkDataUser
,
tUserGPU
.
data
,
sizeof
(
DTYPE
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
cudaMemcpy
(
checkIndexUser
,
indexUserGPU
.
data
,
sizeof
(
int
)
*
tUnitNum
,
cudaMemcpyDeviceToHost
);
for
(
int
i
=
0
;
i
<
tDimSize
[
0
];
++
i
)
{
for
(
int
j
=
0
;
j
<
tDimSize
[
1
];
++
j
)
{
float
tmpData
=
((
float
*
)
checkData
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndex
=
((
int
*
)
checkIndex
)[
i
*
tDimSize
[
1
]
+
j
];
float
tmpDataUser
=
((
float
*
)
checkDataUser
)[
i
*
tDimSize
[
1
]
+
j
];
int
tmpIndexUser
=
((
int
*
)
checkIndexUser
)[
i
*
tDimSize
[
1
]
+
j
];
bool
flag
=
false
;
bool
flagUser
=
false
;
for
(
int
k
=
0
;
k
<
tDimSize
[
1
];
++
k
)
{
float
*
ans
=
tAnswer
[
0
];
int
*
ansIndex
=
indexAnswer
[
0
];
if
(
tmpData
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndex
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flag
=
true
;
}
if
(
tmpDataUser
==
ans
[
i
*
tDimSize
[
1
]
+
k
]
&&
tmpIndexUser
==
ansIndex
[
i
*
tDimSize
[
1
]
+
k
])
{
flagUser
=
true
;
}
}
gpuTest
=
gpuTest
&&
flag
&&
flagUser
;
}
}
/* destroy variables */
delete
s
;
...
...
@@ -291,6 +470,10 @@ bool TestTopK2()
delete
indexGPU
;
delete
[]
sDimSize
;
delete
[]
tDimSize
;
delete
[]
checkData
;
delete
[]
checkIndex
;
delete
[]
checkDataUser
;
delete
[]
checkIndexUser
;
return
cpuTest
&&
gpuTest
;
#else
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论