Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b56572bb
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b56572bb
编写于
5月 11, 2020
作者:
W
wilfChen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
matmul support fp16
上级
dd2062bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
4 deletion
+30
-4
mindspore/ccsrc/kernel/gpu/math/matmul_gpu_kernel.h
mindspore/ccsrc/kernel/gpu/math/matmul_gpu_kernel.h
+1
-1
tests/st/ops/gpu/test_batch_matmul.py
tests/st/ops/gpu/test_batch_matmul.py
+29
-3
未找到文件。
mindspore/ccsrc/kernel/gpu/math/matmul_gpu_kernel.h
浏览文件 @
b56572bb
...
...
@@ -67,7 +67,7 @@ class MatMulGpuKernel : public GpuKernel {
CHECK_CUBLAS_RET_WITH_EXCEPT
(
cublasGemmStridedBatchedEx
(
handle_
,
transpose_x2_
,
transpose_x1_
,
SizeToInt
(
n_
),
SizeToInt
(
m_
),
SizeToInt
(
k_
),
&
alpha
,
input2_addr
,
dtype_b_
,
ldb
,
stride_b
,
input1_addr
,
dtype_a_
,
lda
,
stride_a
,
&
beta
,
output_addr
,
dtype_c_
,
ldc
,
stride_c
,
batch_
,
dtype_c_
,
algo_
),
&
beta
,
output_addr
,
dtype_c_
,
ldc
,
stride_c
,
batch_
,
CUDA_R_32F
,
algo_
),
"cublasSgemm Call Fail"
);
return
true
;
}
...
...
tests/st/ops/gpu/test_batch_matmul.py
浏览文件 @
b56572bb
...
...
@@ -60,7 +60,7 @@ def test_4D():
def
test_4D_transpose_a
():
input_x
=
Tensor
(
np
.
arange
(
2
*
4
*
3
*
1
).
reshape
(
2
,
4
,
3
,
1
),
mstype
.
float32
)
input_y
=
Tensor
(
np
.
arange
(
2
*
4
*
3
*
4
).
reshape
(
2
,
4
,
3
,
4
),
mstype
.
float32
)
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"GPU"
)
net
=
BatchMatMulNet
(
transpose_a
=
True
)
output
=
net
(
input_x
,
input_y
)
...
...
@@ -82,7 +82,7 @@ def test_4D_transpose_a():
def
test_4D_transpose_b
():
input_x
=
Tensor
(
np
.
arange
(
2
*
4
*
1
*
3
).
reshape
(
2
,
4
,
1
,
3
),
mstype
.
float32
)
input_y
=
Tensor
(
np
.
arange
(
2
*
4
*
4
*
3
).
reshape
(
2
,
4
,
4
,
3
),
mstype
.
float32
)
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"GPU"
)
net
=
BatchMatMulNet
(
transpose_b
=
True
)
output
=
net
(
input_x
,
input_y
)
...
...
@@ -104,7 +104,7 @@ def test_4D_transpose_b():
def
test_4D_transpose_ab
():
input_x
=
Tensor
(
np
.
arange
(
2
*
4
*
3
*
1
).
reshape
(
2
,
4
,
3
,
1
),
mstype
.
float32
)
input_y
=
Tensor
(
np
.
arange
(
2
*
4
*
4
*
3
).
reshape
(
2
,
4
,
4
,
3
),
mstype
.
float32
)
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"GPU"
)
net
=
BatchMatMulNet
(
transpose_a
=
True
,
transpose_b
=
True
)
output
=
net
(
input_x
,
input_y
)
...
...
@@ -118,3 +118,29 @@ def test_4D_transpose_ab():
[[
4163
,
4334
,
4505
,
4676
]],
[[
5612
,
5810
,
6008
,
6206
]]]]
assert
(
output
.
asnumpy
()
==
expect
).
all
()
class
BatchMatMulNet
(
nn
.
Cell
):
def
__init__
(
self
,
transpose_a
=
False
,
transpose_b
=
False
):
super
(
BatchMatMulNet
,
self
).
__init__
()
self
.
batch_matmul
=
P
.
BatchMatMul
(
transpose_a
,
transpose_b
)
def
construct
(
self
,
x
,
y
):
return
self
.
batch_matmul
(
x
,
y
)
def
test_4D_fp16
():
input_x
=
Tensor
(
np
.
arange
(
2
*
4
*
1
*
3
).
reshape
(
2
,
4
,
1
,
3
),
mstype
.
float16
)
input_y
=
Tensor
(
np
.
arange
(
2
*
4
*
3
*
4
).
reshape
(
2
,
4
,
3
,
4
),
mstype
.
float16
)
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"GPU"
)
net
=
BatchMatMulNet
()
output
=
net
(
input_x
,
input_y
)
expect
=
[[[[
20
,
23
,
26
,
29
]],
[[
200
,
212
,
224
,
236
]],
[[
596
,
617
,
638
,
659
]],
[[
1208
,
1238
,
1268
,
1298
]]],
[[[
2036
,
2075
,
2114
,
2153
]],
[[
3080
,
3128
,
3176
,
3224
]],
[[
4340
,
4397
,
4454
,
4511
]],
[[
5816
,
5882
,
5948
,
6014
]]]]
assert
(
output
.
asnumpy
()
==
expect
).
all
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录