Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
c43eba64
".github/git@developer.sourcefind.cn:Fzc7075/nunchaku.git" did not exist on "57e50f8db6a3d51facea9898ba346fbe77b61dca"
Commit
c43eba64
authored
Feb 25, 2019
by
Shucai Xiao
Browse files
changes to support the seq2seq translation example.
parent
af90a792
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
41 deletions
+47
-41
src/include/migraphx/operators.hpp
src/include/migraphx/operators.hpp
+23
-2
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+0
-24
src/targets/cpu/gemm.cpp
src/targets/cpu/gemm.cpp
+15
-9
src/targets/gpu/gemm.cpp
src/targets/gpu/gemm.cpp
+9
-6
No files found.
src/include/migraphx/operators.hpp
View file @
c43eba64
...
@@ -843,10 +843,31 @@ struct dot
...
@@ -843,10 +843,31 @@ struct dot
const
shape
&
b
=
inputs
.
at
(
1
);
const
shape
&
b
=
inputs
.
at
(
1
);
auto
t
=
a
.
type
();
auto
t
=
a
.
type
();
if
(
a
.
lens
()[
1
]
!=
b
.
lens
()[
0
])
// change to support cases like {1, 1, 3, 5} X {1, 1, 5, 6},
// which can be handled by numpy. as long as all previous
// dims are 1 except the last two dims, the two matrices
// are multipliable
if
(
std
::
any_of
(
a
.
lens
().
rbegin
()
+
2
,
a
.
lens
().
rend
(),
[](
auto
i
)
{
return
(
i
!=
1
);
}))
{
MIGRAPHX_THROW
(
"DOT: first matrix, dimensions before matrix dims must be 1"
);
}
if
(
std
::
any_of
(
b
.
lens
().
rbegin
()
+
2
,
b
.
lens
().
rend
(),
[](
auto
i
)
{
return
(
i
!=
1
);
}))
{
MIGRAPHX_THROW
(
"DOT: second matrix, dimensions before matrix dims must be 1"
);
}
std
::
size_t
n_dims
=
a
.
lens
().
size
();
if
(
a
.
lens
()[
n_dims
-
1
]
!=
b
.
lens
()[
n_dims
-
2
])
MIGRAPHX_THROW
(
"Inner dimensions do not match: {"
+
to_string_range
(
a
.
lens
())
+
MIGRAPHX_THROW
(
"Inner dimensions do not match: {"
+
to_string_range
(
a
.
lens
())
+
"} x {"
+
to_string_range
(
b
.
lens
())
+
"}"
);
"} x {"
+
to_string_range
(
b
.
lens
())
+
"}"
);
return
{
t
,
{
a
.
lens
()[
0
],
b
.
lens
()[
1
]}};
auto
out_lens
=
a
.
lens
();
out_lens
[
n_dims
-
1
]
=
b
.
lens
()[
n_dims
-
1
];
return
{
t
,
out_lens
};
}
}
};
};
...
...
src/onnx/onnx.cpp
View file @
c43eba64
...
@@ -470,17 +470,6 @@ struct onnx_parser
...
@@ -470,17 +470,6 @@ struct onnx_parser
transb
=
parse_value
(
attributes
.
at
(
"transB"
)).
at
<
bool
>
();
transb
=
parse_value
(
attributes
.
at
(
"transB"
)).
at
<
bool
>
();
}
}
// beginning or end of both args have dimension 1, need to squeeze
// before calling gemm, then doing unsqueeze after getting results
std
::
size_t
num_squeeze
=
args
[
0
]
->
get_shape
().
lens
().
size
();
if
(
num_squeeze
>
2
)
{
std
::
vector
<
int64_t
>
vec_axises
(
num_squeeze
-
2
);
std
::
iota
(
vec_axises
.
begin
(),
vec_axises
.
end
(),
0
);
args
[
0
]
=
prog
.
add_instruction
(
op
::
squeeze
{
vec_axises
},
args
[
0
]);
args
[
1
]
=
prog
.
add_instruction
(
op
::
squeeze
{
vec_axises
},
args
[
1
]);
}
std
::
vector
<
int64_t
>
perm
=
{
1
,
0
};
std
::
vector
<
int64_t
>
perm
=
{
1
,
0
};
auto
l1
=
(
transa
)
?
prog
.
add_instruction
(
op
::
transpose
{
perm
},
args
[
0
])
:
args
[
0
];
auto
l1
=
(
transa
)
?
prog
.
add_instruction
(
op
::
transpose
{
perm
},
args
[
0
])
:
args
[
0
];
auto
l2
=
(
transb
)
?
prog
.
add_instruction
(
op
::
transpose
{
perm
},
args
[
1
])
:
args
[
1
];
auto
l2
=
(
transb
)
?
prog
.
add_instruction
(
op
::
transpose
{
perm
},
args
[
1
])
:
args
[
1
];
...
@@ -489,13 +478,6 @@ struct onnx_parser
...
@@ -489,13 +478,6 @@ struct onnx_parser
if
(
beta
!=
0.
f
)
if
(
beta
!=
0.
f
)
{
{
auto
l3
=
prog
.
add_instruction
(
op
::
dot
{
alpha
},
l1
,
l2
);
auto
l3
=
prog
.
add_instruction
(
op
::
dot
{
alpha
},
l1
,
l2
);
if
(
num_squeeze
>
2
)
{
std
::
vector
<
int64_t
>
vec_axises
(
num_squeeze
-
2
);
std
::
iota
(
vec_axises
.
begin
(),
vec_axises
.
end
(),
0
);
l3
=
prog
.
add_instruction
(
op
::
unsqueeze
{
vec_axises
},
l3
);
}
auto
l4
=
args
[
2
];
auto
l4
=
args
[
2
];
if
(
l4
->
get_shape
().
scalar
())
// ignore args[2] (no C value added to alpha*A*B)
if
(
l4
->
get_shape
().
scalar
())
// ignore args[2] (no C value added to alpha*A*B)
return
l3
;
return
l3
;
...
@@ -510,12 +492,6 @@ struct onnx_parser
...
@@ -510,12 +492,6 @@ struct onnx_parser
}
}
auto
dot_res
=
prog
.
add_instruction
(
op
::
dot
{
alpha
,
beta
},
l1
,
l2
);
auto
dot_res
=
prog
.
add_instruction
(
op
::
dot
{
alpha
,
beta
},
l1
,
l2
);
if
(
num_squeeze
>
2
)
{
std
::
vector
<
int64_t
>
vec_axises
(
num_squeeze
-
2
);
std
::
iota
(
vec_axises
.
begin
(),
vec_axises
.
end
(),
0
);
dot_res
=
prog
.
add_instruction
(
op
::
unsqueeze
{
vec_axises
},
dot_res
);
}
return
dot_res
;
return
dot_res
;
}
}
...
...
src/targets/cpu/gemm.cpp
View file @
c43eba64
...
@@ -14,10 +14,13 @@ template <class T>
...
@@ -14,10 +14,13 @@ template <class T>
static
auto
make_mat
(
tensor_view
<
T
>
x
)
static
auto
make_mat
(
tensor_view
<
T
>
x
)
{
{
const
auto
&
s
=
x
.
get_shape
();
const
auto
&
s
=
x
.
get_shape
();
assert
(
s
.
lens
().
size
()
==
2
);
//assert(s.lens().size() == 2);
std
::
size_t
n_dims
=
s
.
lens
().
size
();
std
::
size_t
dim_0
=
n_dims
-
2
;
std
::
size_t
dim_1
=
n_dims
-
1
;
if
(
s
.
transposed
())
if
(
s
.
transposed
())
return
matrix
<
T
>
{
x
.
data
(),
s
.
lens
()[
1
],
s
.
lens
()[
0
],
s
.
strides
()[
1
]};
return
matrix
<
T
>
{
x
.
data
(),
s
.
lens
()[
dim_
1
],
s
.
lens
()[
dim_
0
],
s
.
strides
()[
dim_
1
]};
return
matrix
<
T
>
{
x
.
data
(),
s
.
lens
()[
0
],
s
.
lens
()[
1
],
s
.
strides
()[
0
]};
return
matrix
<
T
>
{
x
.
data
(),
s
.
lens
()[
dim_
0
],
s
.
lens
()[
dim_
1
],
s
.
strides
()[
dim_
0
]};
}
}
template
<
class
T
,
class
F
>
template
<
class
T
,
class
F
>
...
@@ -64,13 +67,16 @@ void migemm_impl(tensor_view<T> cmat,
...
@@ -64,13 +67,16 @@ void migemm_impl(tensor_view<T> cmat,
float
beta
,
float
beta
,
std
::
false_type
)
std
::
false_type
)
{
{
auto
m
=
cmat
.
get_shape
().
lens
()[
0
];
std
::
size_t
n_dims
=
cmat
.
get_shape
().
lens
().
size
();
auto
n
=
cmat
.
get_shape
().
lens
()[
1
];
std
::
size_t
dim_0
=
n_dims
-
2
;
auto
k
=
amat
.
get_shape
().
lens
()[
1
];
std
::
size_t
dim_1
=
n_dims
-
1
;
auto
m
=
cmat
.
get_shape
().
lens
()[
dim_0
];
auto
n
=
cmat
.
get_shape
().
lens
()[
dim_1
];
auto
k
=
amat
.
get_shape
().
lens
()[
dim_1
];
assert
(
amat
.
get_shape
().
lens
()[
1
]
==
bmat
.
get_shape
().
lens
()[
0
]);
assert
(
amat
.
get_shape
().
lens
()[
dim_
1
]
==
bmat
.
get_shape
().
lens
()[
dim_
0
]);
assert
(
m
==
amat
.
get_shape
().
lens
()[
0
]);
assert
(
m
==
amat
.
get_shape
().
lens
()[
dim_
0
]);
assert
(
n
==
bmat
.
get_shape
().
lens
()[
1
]);
assert
(
n
==
bmat
.
get_shape
().
lens
()[
dim_
1
]);
dfor
(
m
,
n
)([
&
](
auto
ii
,
auto
jj
)
{
dfor
(
m
,
n
)([
&
](
auto
ii
,
auto
jj
)
{
double
s
=
cmat
(
ii
,
jj
)
*
beta
;
double
s
=
cmat
(
ii
,
jj
)
*
beta
;
...
...
src/targets/gpu/gemm.cpp
View file @
c43eba64
...
@@ -80,12 +80,15 @@ argument miopen_gemm::compute(context& ctx,
...
@@ -80,12 +80,15 @@ argument miopen_gemm::compute(context& ctx,
float
beta
=
0.0
f
;
float
beta
=
0.0
f
;
bool
transa
=
args
[
0
].
get_shape
().
transposed
();
bool
transa
=
args
[
0
].
get_shape
().
transposed
();
bool
transb
=
args
[
1
].
get_shape
().
transposed
();
bool
transb
=
args
[
1
].
get_shape
().
transposed
();
rocblas_int
lda
=
args
[
0
].
get_shape
().
strides
()[
transa
?
1
:
0
];
std
::
size_t
n_dims
=
args
[
0
].
get_shape
().
lens
().
size
();
rocblas_int
ldb
=
args
[
1
].
get_shape
().
strides
()[
transb
?
1
:
0
];
std
::
size_t
dim_0
=
n_dims
-
2
;
rocblas_int
ldc
=
args
[
2
].
get_shape
().
strides
()[
0
];
std
::
size_t
dim_1
=
n_dims
-
1
;
rocblas_int
m
=
output_shape
.
lens
()[
0
];
rocblas_int
lda
=
args
[
0
].
get_shape
().
strides
()[
transa
?
dim_1
:
dim_0
];
rocblas_int
n
=
output_shape
.
lens
()[
1
];
rocblas_int
ldb
=
args
[
1
].
get_shape
().
strides
()[
transb
?
dim_1
:
dim_0
];
rocblas_int
k
=
args
[
0
].
get_shape
().
lens
()[
1
];
rocblas_int
ldc
=
args
[
2
].
get_shape
().
strides
()[
dim_0
];
rocblas_int
m
=
output_shape
.
lens
()[
dim_0
];
rocblas_int
n
=
output_shape
.
lens
()[
dim_1
];
rocblas_int
k
=
args
[
0
].
get_shape
().
lens
()[
dim_1
];
output_shape
.
visit_type
([
&
](
auto
as
)
{
output_shape
.
visit_type
([
&
](
auto
as
)
{
auto
alpha_r
=
to_rocblas_type
(
as
(
alpha
));
auto
alpha_r
=
to_rocblas_type
(
as
(
alpha
));
auto
beta_r
=
to_rocblas_type
(
as
(
beta
));
auto
beta_r
=
to_rocblas_type
(
as
(
beta
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment