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
b50aa56c
Commit
b50aa56c
authored
Feb 06, 2023
by
charlie
Browse files
progress
parent
32b1f924
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
22 deletions
+115
-22
src/include/migraphx/op/select_module.hpp
src/include/migraphx/op/select_module.hpp
+15
-19
src/targets/gpu/include/migraphx/gpu/select_module.hpp
src/targets/gpu/include/migraphx/gpu/select_module.hpp
+60
-0
src/targets/gpu/select_module.cpp
src/targets/gpu/select_module.cpp
+33
-0
test/op_shape_test.cpp
test/op_shape_test.cpp
+7
-3
No files found.
src/include/migraphx/op/select_module.hpp
View file @
b50aa56c
...
@@ -33,7 +33,6 @@ namespace migraphx {
...
@@ -33,7 +33,6 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
// Make this work just for exact matches
// Make this work just for exact matches
// can get rid of the other attributes and just check all the parameters are the same
// can get rid of the other attributes and just check all the parameters are the same
// GPU version of this might have to deal with output parameters
// GPU version of this might have to deal with output parameters
...
@@ -41,8 +40,7 @@ namespace op {
...
@@ -41,8 +40,7 @@ namespace op {
// Can have multiple inputs but only one output?
// Can have multiple inputs but only one output?
struct
select_module
struct
select_module
{
{
// output shape of the dynamic model
shape
output_dyn_shapes
;
shape
output_dyn_shape
;
template
<
class
Self
,
class
F
>
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
static
auto
reflect
(
Self
&
self
,
F
f
)
...
@@ -52,11 +50,7 @@ struct select_module
...
@@ -52,11 +50,7 @@ struct select_module
std
::
string
name
()
const
{
return
"select_module"
;
}
std
::
string
name
()
const
{
return
"select_module"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
shape
compute_shape
(
std
::
vector
<
shape
>
)
const
{
return
shape
{
output_dyn_shapes
};
}
{
check_shapes
{
inputs
,
*
this
,
true
};
return
shape
{
output_dyn_shape
};
}
argument
compute
(
const
shape
&
,
argument
compute
(
const
shape
&
,
const
std
::
vector
<
argument
>&
args
,
const
std
::
vector
<
argument
>&
args
,
...
@@ -64,21 +58,23 @@ struct select_module
...
@@ -64,21 +58,23 @@ struct select_module
const
std
::
function
<
std
::
vector
<
argument
>
(
const
std
::
function
<
std
::
vector
<
argument
>
(
module_ref
&
,
const
std
::
unordered_map
<
std
::
string
,
argument
>&
)
>&
run
)
const
module_ref
&
,
const
std
::
unordered_map
<
std
::
string
,
argument
>&
)
>&
run
)
const
{
{
// find submodule with parameter shapes exactly the same as the input arguments
// find submodule with parameter shapes exactly the same as the input arguments
// assuming arguments are in the same order as the parameters
// assuming arguments are in the same order as the parameters
auto
module_to_run
=
std
::
find_if
(
submodule_list
.
begin
(),
submodule_list
.
end
(),
[
&
](
module_ref
mr
)
{
auto
module_iter
=
auto
param_names
=
mr
.
get_parameter_names
();
std
::
find_if
(
submodule_list
.
cbegin
(),
submodule_list
.
cend
(),
[
&
](
module_ref
mr
)
{
std
::
equal
(
args
.
cbegin
(),
args
.
cend
(),
param_names
.
cbegin
(),
[
&
](
auto
a
,
auto
p_name
)
{
auto
param_names
=
mr
->
get_parameter_names
();
return
a
.
get_shape
()
==
mr
.
get_parameter_shape
(
p_name
);
std
::
equal
(
});
args
.
cbegin
(),
args
.
cend
(),
param_names
.
cbegin
(),
[
&
](
auto
a
,
auto
p_name
)
{
});
return
a
.
get_shape
()
==
mr
->
get_parameter_shape
(
p_name
);
});
});
if
(
module_
to_run
==
submodule_list
.
end
())
if
(
module_
iter
==
submodule_list
.
end
())
{
{
MIGRAPHX_THROW
(
"SELECT_MODULE: no compatible submodules found for given input shapes"
);
MIGRAPHX_THROW
(
"SELECT_MODULE: no compatible submodules found for given input shapes"
);
}
}
auto
module_to_run
=
*
module_iter
;
auto
param_names
=
module_to_run
.
get_parameter_names
();
auto
param_names
=
module_to_run
->
get_parameter_names
();
assert
(
pnames
.
size
()
<=
args
.
size
());
assert
(
pnames
.
size
()
<=
args
.
size
());
std
::
unordered_map
<
std
::
string
,
argument
>
params
;
std
::
unordered_map
<
std
::
string
,
argument
>
params
;
std
::
transform
(
param_names
.
begin
(),
std
::
transform
(
param_names
.
begin
(),
...
...
src/targets/gpu/include/migraphx/gpu/select_module.hpp
0 → 100644
View file @
b50aa56c
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_RTGLIB_SELECT_MODULE_HPP
#define MIGRAPHX_GUARD_RTGLIB_SELECT_MODULE_HPP
#include <migraphx/argument.hpp>
#include <migraphx/module.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
hip_select_module
{
std
::
string
name
()
const
{
return
"gpu::select_module"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
,
std
::
vector
<
module_ref
>
mods
)
const
;
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
,
const
std
::
vector
<
module_ref
>&
mods
,
const
std
::
function
<
std
::
vector
<
argument
>
(
module_ref
&
,
const
std
::
unordered_map
<
std
::
string
,
argument
>&
)
>&
run
)
const
;
std
::
ptrdiff_t
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/select_module.cpp
0 → 100644
View file @
b50aa56c
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/gpu/select_module.hpp>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
test/op_shape_test.cpp
View file @
b50aa56c
...
@@ -2293,17 +2293,21 @@ TEST_CASE(rnn)
...
@@ -2293,17 +2293,21 @@ TEST_CASE(rnn)
TEST_CASE
(
select_module_dyn
)
TEST_CASE
(
select_module_dyn
)
{
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
3
,
3
},
{
255
,
255
},
{
255
,
255
}}};
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
3
,
3
},
{
255
,
255
},
{
255
,
255
}}};
migraphx
::
shape
out_attr
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}};
std
::
vector
<
migraphx
::
shape
>
sub_shapes
=
{};
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}});
migraphx
::
shape
out_attr
=
migraphx
::
shape
{
sub_shapes
};
expect_shape
(
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}},
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}},
migraphx
::
make_op
(
"select_module"
,
{{
"output_dyn_shape"
,
migraphx
::
to_value
(
out_attr
)}}),
migraphx
::
make_op
(
"select_module"
,
{{
"output_dyn_shape
s
"
,
migraphx
::
to_value
(
out_attr
)}}),
input
);
input
);
}
}
TEST_CASE
(
select_module_static
)
TEST_CASE
(
select_module_static
)
{
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
3
,
3
,
255
,
255
}};
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
3
,
3
,
255
,
255
}};
migraphx
::
shape
out_attr
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}};
std
::
vector
<
migraphx
::
shape
>
sub_shapes
=
{};
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
1000
,
1000
}}});
migraphx
::
shape
out_attr
=
migraphx
::
shape
{
sub_shapes
};
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
1000
}},
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
1000
}},
migraphx
::
make_op
(
"select_module"
,
migraphx
::
make_op
(
"select_module"
,
{{
"output_dyn_shape"
,
migraphx
::
to_value
(
out_attr
)},
{{
"output_dyn_shape"
,
migraphx
::
to_value
(
out_attr
)},
...
...
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