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
f02f5d98
"vscode:/vscode.git/clone" did not exist on "847a461bd77cad4513a6942f2a11b0552c387ef8"
Commit
f02f5d98
authored
Sep 22, 2022
by
charlie
Browse files
Initial
parent
e0cb7b9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
9 deletions
+112
-9
src/include/migraphx/operation.hpp
src/include/migraphx/operation.hpp
+54
-1
src/targets/ref/lowering.cpp
src/targets/ref/lowering.cpp
+4
-7
tools/include/operation.hpp
tools/include/operation.hpp
+54
-1
No files found.
src/include/migraphx/operation.hpp
View file @
f02f5d98
...
...
@@ -222,7 +222,7 @@ template <class T>
auto
compute_op
(
rank
<
1
>
,
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
output_shape
,
input
))
{
return
x
.
compute
(
output_shape
,
input
);
return
x
.
compute
(
make_compute_output_shape
(
x
,
output_shape
,
input
)
,
input
);
}
template
<
class
T
>
...
...
@@ -1278,6 +1278,59 @@ inline const ValueType& any_cast(const operation& x)
inline
bool
operator
!=
(
const
operation
&
x
,
const
operation
&
y
)
{
return
not
(
x
==
y
);
}
// used for dynamic operators
struct
dyn_output
{
// original instruction output shape
shape
ins_shape
;
std
::
function
<
shape
()
>
compute_shape
;
shape
get_output_shape
()
{
if
(
output_shape
.
element_space
()
==
0
)
{
output_shape
=
compute_shape
();
}
return
output_shape
;
}
private:
// shape computed at eval time using input arguments
shape
output_shape
;
};
/**
* Handle dynamic and static shape at evaluation time.
* If converted to shape type, returns original ins_shape
* If converted to dyn_output type, will compute an output shape using the input arguments
*/
template
<
class
F
>
struct
compute_output_shape
{
F
ins_inputs
;
operator
dyn_output
()
const
{
return
unpack
(
[](
const
auto
&
x
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
args
)
{
return
dyn_output
{
ins_shape
,
[
&
]()
{
compute_shape
(
x
,
to_shapes
(
args
));
}};
},
ins_inputs
);
}
operator
shape
()
const
{
return
unpack
(
[](
const
auto
&
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
)
{
return
ins_shape
;
},
ins_inputs
);
}
};
template
<
class
T
>
auto
make_compute_output_shape
(
const
T
&
x
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
input
)
{
return
compute_output_shape
{
pack
(
x
,
ins_shape
,
input
)};
}
inline
value
compile
(
operation
&
op
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
shape
>&
input
)
{
...
...
src/targets/ref/lowering.cpp
View file @
f02f5d98
...
...
@@ -234,8 +234,9 @@ struct ref_convolution : auto_register_op<ref_convolution<Op>>
return
op
.
normalize_compute_shape
(
inputs
);
}
argument
compute
(
context
&
,
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
argument
compute
(
context
&
,
migraphx
::
dyn_output
dyn_output
,
std
::
vector
<
argument
>
args
)
const
{
shape
output_shape
;
std
::
vector
<
std
::
size_t
>
padding
;
if
(
op
.
padding_mode
!=
op
::
padding_mode_t
::
default_
)
{
...
...
@@ -250,12 +251,8 @@ struct ref_convolution : auto_register_op<ref_convolution<Op>>
}
else
{
padding
=
op
.
padding
;
if
(
output_shape
.
dynamic
())
{
output_shape
=
op
.
normalize_compute_shape
({
args
.
at
(
0
).
get_shape
(),
args
.
at
(
1
).
get_shape
()});
}
padding
=
op
.
padding
;
output_shape
=
dyn_output
.
get_output_shape
();
}
argument
result
{
output_shape
};
...
...
tools/include/operation.hpp
View file @
f02f5d98
...
...
@@ -222,7 +222,7 @@ template <class T>
auto
compute_op
(
rank
<
1
>
,
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
output_shape
,
input
))
{
return
x
.
compute
(
output_shape
,
input
);
return
x
.
compute
(
make_compute_output_shape
(
x
,
output_shape
,
input
)
,
input
);
}
template
<
class
T
>
...
...
@@ -563,6 +563,59 @@ lifetime get_lifetime_op(const T&)
return
not
(
x
==
y
);
}
// used for dynamic operators
struct
dyn_output
{
// original instruction output shape
shape
ins_shape
;
std
::
function
<
shape
()
>
compute_shape
;
shape
get_output_shape
()
{
if
(
output_shape
.
element_space
()
==
0
)
{
output_shape
=
compute_shape
();
}
return
output_shape
;
}
private:
// shape computed at eval time using input arguments
shape
output_shape
;
};
/**
* Handle dynamic and static shape at evaluation time.
* If converted to shape type, returns original ins_shape
* If converted to dyn_output type, will compute an output shape using the input arguments
*/
template
<
class
F
>
struct
compute_output_shape
{
F
ins_inputs
;
operator
dyn_output
()
const
{
return
unpack
(
[](
const
auto
&
x
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
args
)
{
return
dyn_output
{
ins_shape
,
[
&
]()
{
compute_shape
(
x
,
to_shapes
(
args
));
}};
},
ins_inputs
);
}
operator
shape
()
const
{
return
unpack
(
[](
const
auto
&
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
)
{
return
ins_shape
;
},
ins_inputs
);
}
};
template
<
class
T
>
auto
make_compute_output_shape
(
const
T
&
x
,
shape
ins_shape
,
const
std
::
vector
<
argument
>&
input
)
{
return
compute_output_shape
{
pack
(
x
,
ins_shape
,
input
)};
}
inline
value
compile
(
operation
&
op
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
shape
>&
input
)
{
...
...
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