Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
akg
提交
7decc565
A
akg
项目概览
MindSpore
/
akg
通知
58
Star
7
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
akg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7decc565
编写于
7月 02, 2020
作者:
C
chenlei_autodiff
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify matmul tuning.
上级
2be38102
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
40 deletion
+21
-40
python/akg/ops/nn/matmul.py
python/akg/ops/nn/matmul.py
+3
-3
tests/common/test_run/matmul_run.py
tests/common/test_run/matmul_run.py
+15
-15
tests/fuzz/tune/autotuning/kernel_compiler.py
tests/fuzz/tune/autotuning/kernel_compiler.py
+3
-22
未找到文件。
python/akg/ops/nn/matmul.py
浏览文件 @
7decc565
...
@@ -80,7 +80,7 @@ matmul_set_dim_map = {
...
@@ -80,7 +80,7 @@ matmul_set_dim_map = {
}
}
def
matmul_set_dim
(
A
,
B
,
b
,
out_dtype
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
,
attrs
):
def
matmul_set_dim
(
A
,
B
,
b
,
out_dtype
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
):
shape_A
=
A
.
shape
[
1
:
5
]
if
len
(
A
.
shape
)
==
5
else
A
.
shape
shape_A
=
A
.
shape
[
1
:
5
]
if
len
(
A
.
shape
)
==
5
else
A
.
shape
shape_B
=
B
.
shape
[
1
:
5
]
if
len
(
B
.
shape
)
==
5
else
B
.
shape
shape_B
=
B
.
shape
[
1
:
5
]
if
len
(
B
.
shape
)
==
5
else
B
.
shape
bias
=
0
if
b
is
None
else
1
bias
=
0
if
b
is
None
else
1
...
@@ -199,7 +199,7 @@ def matmul4D_compute(x, y, bias_value, out_dtype, left_format, right_format, out
...
@@ -199,7 +199,7 @@ def matmul4D_compute(x, y, bias_value, out_dtype, left_format, right_format, out
elif
left_format
==
"zN"
:
elif
left_format
==
"zN"
:
x_indices
=
indices
[:(
N
-
4
)]
+
(
ko
,)
+
indices
[(
N
-
3
):(
N
-
2
)]
+
indices
[(
N
-
2
):(
N
-
1
)]
+
(
ki
,)
x_indices
=
indices
[:(
N
-
4
)]
+
(
ko
,)
+
indices
[(
N
-
3
):(
N
-
2
)]
+
indices
[(
N
-
2
):(
N
-
1
)]
+
(
ki
,)
if
adj_x
:
if
adj_x
:
x_indices
=
indices
[:(
N
-
4
)]
+
indices
[(
N
-
3
):(
N
-
2
)]
+
(
ko
,)
+
(
ki
,)
+
indices
[(
N
-
2
):(
N
-
1
)]
x_indices
=
indices
[:(
N
-
4
)]
+
indices
[(
N
-
3
):(
N
-
2
)]
+
(
ko
,)
+
(
ki
,)
+
indices
[(
N
-
2
):(
N
-
1
)]
if
right_format
==
"nZ"
:
if
right_format
==
"nZ"
:
y_indices
=
indices
[:(
N
-
4
)]
+
(
ko
,
)
+
indices
[(
N
-
4
):(
N
-
3
)]
+
indices
[(
N
-
1
):]
+
(
ki
,)
y_indices
=
indices
[:(
N
-
4
)]
+
(
ko
,
)
+
indices
[(
N
-
4
):(
N
-
3
)]
+
indices
[(
N
-
1
):]
+
(
ki
,)
...
@@ -341,7 +341,7 @@ def matmul(x, y, b, out_dtype, left_format="zZ", right_format="nZ", out_format="
...
@@ -341,7 +341,7 @@ def matmul(x, y, b, out_dtype, left_format="zZ", right_format="nZ", out_format="
out
=
matmul4D_compute
(
x
,
y
,
b
,
out_dtype
,
left_format
,
right_format
,
out_format
,
transpose_x
,
transpose_y
,
attrs
)
out
=
matmul4D_compute
(
x
,
y
,
b
,
out_dtype
,
left_format
,
right_format
,
out_format
,
transpose_x
,
transpose_y
,
attrs
)
attr_map
=
{
"pragma_rmselfdep"
:
False
}
attr_map
=
{
"pragma_rmselfdep"
:
False
}
dims_info
,
_
=
matmul_set_dim
(
x
,
y
,
b
,
out_dtype
,
left_format
,
right_format
,
out_format
,
transpose_x
,
transpose_y
,
attrs
)
dims_info
,
_
=
matmul_set_dim
(
x
,
y
,
b
,
out_dtype
,
left_format
,
right_format
,
out_format
,
transpose_x
,
transpose_y
)
attr_map
[
"dim"
]
=
dims_info
attr_map
[
"dim"
]
=
dims_info
return
out
,
attr_map
return
out
,
attr_map
tests/common/test_run/matmul_run.py
浏览文件 @
7decc565
...
@@ -67,13 +67,13 @@ def get_shapes(batch_tuple, M, K, N, trans_data=False, trans_weight=False):
...
@@ -67,13 +67,13 @@ def get_shapes(batch_tuple, M, K, N, trans_data=False, trans_weight=False):
return
shape_x
,
shape_y
return
shape_x
,
shape_y
def
getMatmulType
(
m
,
n
,
k
):
def
getMatmulType
(
m
,
n
):
type
=
MatmulType
.
gemm
matmul_
type
=
MatmulType
.
gemm
if
m
//
cce
.
BLOCK_IN
==
0
:
if
m
//
cce
.
BLOCK_IN
==
0
:
type
=
MatmulType
.
gevm
matmul_
type
=
MatmulType
.
gevm
elif
n
==
1
:
elif
n
==
1
:
type
=
MatmulType
.
gemv
matmul_
type
=
MatmulType
.
gemv
return
type
return
matmul_
type
def
np_matmul
(
matrix_a
,
matrix_b
,
batch_tuple
,
M
,
K
,
N
,
trans_data
=
False
,
trans_weight
=
False
,
output_format
=
None
):
def
np_matmul
(
matrix_a
,
matrix_b
,
batch_tuple
,
M
,
K
,
N
,
trans_data
=
False
,
trans_weight
=
False
,
output_format
=
None
):
...
@@ -100,7 +100,7 @@ def np_matmul(matrix_a, matrix_b, batch_tuple, M, K, N, trans_data=False, trans_
...
@@ -100,7 +100,7 @@ def np_matmul(matrix_a, matrix_b, batch_tuple, M, K, N, trans_data=False, trans_
for
b
in
range
(
mul
):
for
b
in
range
(
mul
):
out
[
b
,
:]
=
np
.
dot
(
reshape_x
[
b
,
:],
reshape_y
[
b
,
:])
out
[
b
,
:]
=
np
.
dot
(
reshape_x
[
b
,
:],
reshape_y
[
b
,
:])
#out[b,:] = np.matmul(reshape_x[b,:], reshape_y[b,:])
#out[b,:] = np.matmul(reshape_x[b,:], reshape_y[b,:])
matmul_type
=
getMatmulType
(
M
,
N
,
K
)
matmul_type
=
getMatmulType
(
M
,
N
)
out_shape
=
()
out_shape
=
()
if
matmul_type
==
MatmulType
.
gemm
:
if
matmul_type
==
MatmulType
.
gemm
:
out_shape
=
batch_tuple
+
(
M
//
cce
.
BLOCK_IN
,
cce
.
BLOCK_IN
,
N
//
cce
.
BLOCK_OUT
,
cce
.
BLOCK_OUT
)
out_shape
=
batch_tuple
+
(
M
//
cce
.
BLOCK_IN
,
cce
.
BLOCK_IN
,
N
//
cce
.
BLOCK_OUT
,
cce
.
BLOCK_OUT
)
...
@@ -132,7 +132,7 @@ def genData(batch_tuple, M, K, N, trans_data=False, trans_weight=False,
...
@@ -132,7 +132,7 @@ def genData(batch_tuple, M, K, N, trans_data=False, trans_weight=False,
matrix_a_for_np
=
matrix_a
.
astype
(
np
.
float32
)
matrix_a_for_np
=
matrix_a
.
astype
(
np
.
float32
)
matrix_b_for_np
=
matrix_b
.
astype
(
np
.
float32
)
matrix_b_for_np
=
matrix_b
.
astype
(
np
.
float32
)
matmul_type
=
getMatmulType
(
M
,
N
,
K
)
matmul_type
=
getMatmulType
(
M
,
N
)
out
=
np_matmul
(
matrix_a_for_np
,
matrix_b_for_np
,
batch_tuple
,
M
,
K
,
N
,
trans_data
,
trans_weight
,
output_format
).
astype
(
out_dtype
)
out
=
np_matmul
(
matrix_a_for_np
,
matrix_b_for_np
,
batch_tuple
,
M
,
K
,
N
,
trans_data
,
trans_weight
,
output_format
).
astype
(
out_dtype
)
if
dtype
==
"float16"
:
if
dtype
==
"float16"
:
out
.
astype
(
np
.
float16
)
out
.
astype
(
np
.
float16
)
...
@@ -226,24 +226,24 @@ def reduce_data(reduce_type):
...
@@ -226,24 +226,24 @@ def reduce_data(reduce_type):
return
res
return
res
def
get_fractal_shape
(
dim1
,
dim2
,
reduce1
=
"in"
,
reduce2
=
"reduce"
,
format
=
"zZ"
):
def
get_fractal_shape
(
dim1
,
dim2
,
reduce1
=
"in"
,
reduce2
=
"reduce"
,
matrix_
format
=
"zZ"
):
result
=
()
result
=
()
dim1_reduce
=
reduce_data
(
reduce1
)
dim1_reduce
=
reduce_data
(
reduce1
)
dim2_reduce
=
reduce_data
(
reduce2
)
dim2_reduce
=
reduce_data
(
reduce2
)
if
format
==
"zZ"
:
if
matrix_
format
==
"zZ"
:
result
=
(
dim1
//
dim1_reduce
,
dim2
//
dim2_reduce
,
dim1_reduce
,
dim2_reduce
)
result
=
(
dim1
//
dim1_reduce
,
dim2
//
dim2_reduce
,
dim1_reduce
,
dim2_reduce
)
elif
format
==
"nZ"
:
elif
matrix_
format
==
"nZ"
:
result
=
(
dim1
//
dim1_reduce
,
dim2
//
dim2_reduce
,
dim2_reduce
,
dim1_reduce
)
result
=
(
dim1
//
dim1_reduce
,
dim2
//
dim2_reduce
,
dim2_reduce
,
dim1_reduce
)
elif
format
==
"nN"
:
elif
matrix_
format
==
"nN"
:
result
=
(
dim2
//
dim2_reduce
,
dim1
//
dim1_reduce
,
dim2_reduce
,
dim1_reduce
)
result
=
(
dim2
//
dim2_reduce
,
dim1
//
dim1_reduce
,
dim2_reduce
,
dim1_reduce
)
elif
format
==
"zN"
:
elif
matrix_
format
==
"zN"
:
result
=
(
dim2
//
dim2_reduce
,
dim1
//
dim1_reduce
,
dim1_reduce
,
dim2_reduce
)
result
=
(
dim2
//
dim2_reduce
,
dim1
//
dim1_reduce
,
dim1_reduce
,
dim2_reduce
)
return
result
return
result
def
get_converted_shapes
(
m
,
n
,
k
,
batch_tuple
,
adj_x
,
adj_y
,
bias
,
left_format
=
"zZ"
,
right_format
=
"nZ"
,
out_format
=
"zN"
):
def
get_converted_shapes
(
m
,
n
,
k
,
batch_tuple
,
adj_x
,
adj_y
,
bias
,
left_format
=
"zZ"
,
right_format
=
"nZ"
,
out_format
=
"zN"
):
matmul_type
=
getMatmulType
(
m
,
n
,
k
)
matmul_type
=
getMatmulType
(
m
,
n
)
if
matmul_type
==
MatmulType
.
gemm
:
if
matmul_type
==
MatmulType
.
gemm
:
# left_format zZ process
# left_format zZ process
if
left_format
==
"zZ"
:
if
left_format
==
"zZ"
:
...
@@ -341,7 +341,7 @@ def matmul_execute(shape_x, shape_y, bias, left_format, right_format, out_format
...
@@ -341,7 +341,7 @@ def matmul_execute(shape_x, shape_y, bias, left_format, right_format, out_format
return
(
m_x
,
m_y
),
output
,
bench_mark
,
compare_result
return
(
m_x
,
m_y
),
output
,
bench_mark
,
compare_result
def
matmul_compile
(
shape_x
,
shape_y
,
bias
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
,
dtype
,
out_dtype
,
kernel_name
,
attrs
):
def
matmul_compile
(
shape_x
,
shape_y
,
bias
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
,
dtype
,
out_dtype
,
kernel_name
,
attrs
,
tuning
=
False
):
batch_tuple
,
m
,
k
,
n
=
extract_dim
(
shape_x
,
shape_y
,
adj_x
,
adj_y
)
batch_tuple
,
m
,
k
,
n
=
extract_dim
(
shape_x
,
shape_y
,
adj_x
,
adj_y
)
m
=
(
m
+
15
)
//
16
*
16
m
=
(
m
+
15
)
//
16
*
16
n
=
(
n
+
15
)
//
16
*
16
n
=
(
n
+
15
)
//
16
*
16
...
@@ -358,4 +358,4 @@ def matmul_compile(shape_x, shape_y, bias, left_format, right_format, output_for
...
@@ -358,4 +358,4 @@ def matmul_compile(shape_x, shape_y, bias, left_format, right_format, output_for
input_shapes
=
[
shape_xx
,
shape_yy
]
input_shapes
=
[
shape_xx
,
shape_yy
]
input_types
=
[
dtype
,
dtype
]
input_types
=
[
dtype
,
dtype
]
op_attrs
=
[
None
,
out_dtype
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
,
attrs
]
op_attrs
=
[
None
,
out_dtype
,
left_format
,
right_format
,
output_format
,
adj_x
,
adj_y
,
attrs
]
return
utils
.
op_build_test
(
matmul
.
matmul
,
input_shapes
,
input_types
,
op_attrs
,
kernel_name
,
attrs
)
return
utils
.
op_build_test
(
matmul
.
matmul
,
input_shapes
,
input_types
,
op_attrs
,
kernel_name
,
attrs
,
tuning
=
tuning
)
tests/fuzz/tune/autotuning/kernel_compiler.py
浏览文件 @
7decc565
...
@@ -100,16 +100,6 @@ def gen_kernel_matmul_cube(op_desc: MatmulCubeDesc, _, index_table,
...
@@ -100,16 +100,6 @@ def gen_kernel_matmul_cube(op_desc: MatmulCubeDesc, _, index_table,
kernel_name
=
"matmul_cube_poly"
kernel_name
=
"matmul_cube_poly"
if
idx
is
not
None
:
if
idx
is
not
None
:
kernel_name
+=
str
(
idx
)
kernel_name
+=
str
(
idx
)
batch_tuple
,
m
,
k
,
n
=
matmul_run
.
extract_dim
(
op_desc
.
x_shape
,
op_desc
.
y_shape
,
op_desc
.
adj_x
,
op_desc
.
adj_y
)
m
=
(
m
+
15
)
//
16
*
16
n
=
(
n
+
15
)
//
16
*
16
k
=
(
k
+
15
)
//
16
*
16
shape_xx
,
shape_yy
,
bias_shape
,
_
,
_
=
matmul_run
.
get_converted_shapes
(
m
,
n
,
k
,
batch_tuple
,
op_desc
.
adj_x
,
op_desc
.
adj_y
,
op_desc
.
bias
,
op_desc
.
left_format
,
op_desc
.
right_format
,
op_desc
.
out_format
)
input_shapes
=
[
shape_xx
,
shape_yy
,
bias_shape
]
input_types
=
[
op_desc
.
dtype
,
op_desc
.
dtype
,
op_desc
.
dtype
]
if
config
is
None
:
if
config
is
None
:
attrs
=
{
'dim'
:
""
}
attrs
=
{
'dim'
:
""
}
else
:
else
:
...
@@ -123,18 +113,9 @@ def gen_kernel_matmul_cube(op_desc: MatmulCubeDesc, _, index_table,
...
@@ -123,18 +113,9 @@ def gen_kernel_matmul_cube(op_desc: MatmulCubeDesc, _, index_table,
tiling_param
.
extend
([(
16
,
16
),
(
16
,
16
),
(
config
.
k_l1
,
config
.
k_l0
)])
tiling_param
.
extend
([(
16
,
16
),
(
16
,
16
),
(
config
.
k_l1
,
config
.
k_l0
)])
dim_info
=
ct_util
.
set_dims
(
tuple
(
tiling_param
))
dim_info
=
ct_util
.
set_dims
(
tuple
(
tiling_param
))
attrs
=
{
'dim'
:
dim_info
,
'bypass'
:
config
.
bypass
}
attrs
=
{
'dim'
:
dim_info
,
'bypass'
:
config
.
bypass
}
has_bias
=
False
return
matmul_run
.
matmul_compile
(
op_desc
.
x_shape
,
op_desc
.
y_shape
,
op_desc
.
bias
,
op_desc
.
left_format
,
if
op_desc
.
bias
==
1
:
op_desc
.
right_format
,
op_desc
.
out_format
,
op_desc
.
adj_x
,
op_desc
.
adj_y
,
has_bias
=
True
op_desc
.
dtype
,
op_desc
.
out_dtype
,
kernel_name
,
attrs
,
gen_tiling_spaces
)
op_attrs
=
[
op_desc
.
out_dtype
,
op_desc
.
left_format
,
op_desc
.
right_format
,
op_desc
.
out_format
,
op_desc
.
adj_x
,
op_desc
.
adj_y
,
has_bias
,
attrs
]
if
has_bias
==
False
:
input_shapes
=
[
shape_xx
,
shape_yy
]
input_types
=
[
op_desc
.
dtype
,
op_desc
.
dtype
]
op_attrs
=
[
None
,
op_desc
.
out_dtype
,
op_desc
.
left_format
,
op_desc
.
right_format
,
op_desc
.
out_format
,
op_desc
.
adj_x
,
op_desc
.
adj_y
,
has_bias
,
attrs
]
return
utils
.
op_build
(
matmul
.
matmul
,
input_shapes
,
input_types
,
op_attrs
,
kernel_name
=
kernel_name
,
attrs
=
attrs
,
polyhedral
=
True
,
tuning
=
gen_tiling_spaces
)
def
gen_kernel_conv_backprop_input
(
op_desc
:
ConvBackpropDesc
,
_
,
index_table
,
config
:
ConvBackpropInputConfig
=
None
,
def
gen_kernel_conv_backprop_input
(
op_desc
:
ConvBackpropDesc
,
_
,
index_table
,
config
:
ConvBackpropInputConfig
=
None
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录