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
4f12db9e
Unverified
Commit
4f12db9e
authored
Jan 31, 2023
by
Paul Fultz II
Committed by
GitHub
Jan 31, 2023
Browse files
Merge branch 'develop' into jit-reduce-reg
parents
c2923b44
91cc7242
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
266 additions
and
41 deletions
+266
-41
src/targets/gpu/prefuse_ops.cpp
src/targets/gpu/prefuse_ops.cpp
+3
-1
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+3
-10
test/CMakeLists.txt
test/CMakeLists.txt
+38
-26
test/api/test_save_load.cpp
test/api/test_save_load.cpp
+0
-1
test/gpu/jit.cpp
test/gpu/jit.cpp
+5
-3
test/onnx/gather_dyn_test.onnx
test/onnx/gather_dyn_test.onnx
+0
-0
test/onnx/gather_scalar_test.onnx
test/onnx/gather_scalar_test.onnx
+0
-0
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+34
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+40
-0
test/op_shape_test.cpp
test/op_shape_test.cpp
+71
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+72
-0
No files found.
src/targets/gpu/prefuse_ops.cpp
View file @
4f12db9e
...
...
@@ -108,7 +108,9 @@ struct find_add_layernorm
{
auto
ins
=
r
.
result
;
auto
add_ins
=
r
.
instructions
[
"add"
];
auto
eps
=
r
.
instructions
[
"eps"
]
->
eval
().
at
<
float
>
();
float
eps
=
0
;
if
(
contains
(
r
.
instructions
,
"eps"
))
eps
=
r
.
instructions
[
"eps"
]
->
eval
().
at
<
float
>
();
m
.
replace_instruction
(
ins
,
add_layernorm
{
eps
},
add_ins
->
inputs
());
}
...
...
src/targets/gpu/target.cpp
View file @
4f12db9e
...
...
@@ -38,6 +38,7 @@
#include <migraphx/layout_nhwc.hpp>
#include <migraphx/memory_coloring.hpp>
#include <migraphx/normalize_ops.hpp>
#include <migraphx/optimize_module.hpp>
#include <migraphx/preallocate_param.hpp>
#include <migraphx/propagate_constant.hpp>
#include <migraphx/register_target.hpp>
...
...
@@ -118,21 +119,13 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
rewrite_pooling
{},
dead_code_elimination
{},
rewrite_gelu
{},
dead_code_elimination
{},
eliminate_common_subexpression
{},
dead_code_elimination
{},
simplify_algebra
{},
simplify_reshapes
{},
optimize_module
{},
enable_pass
(
enabled
(
MIGRAPHX_ENABLE_NHWC
{}),
layout_nhwc
{}),
dead_code_elimination
{},
simplify_reshapes
{},
simplify_algebra
{},
prefuse_ops
{},
dead_code_elimination
{},
auto_contiguous
{},
simplify_reshapes
{},
propagate_constant
{},
dead_code_elimination
{},
optimize_module
{},
enable_pass
(
not
enabled
(
MIGRAPHX_DISABLE_POINTWISE_FUSION
{}),
fuse_pointwise
{}),
dead_code_elimination
{},
fuse_mlir
{
&
ctx
},
...
...
test/CMakeLists.txt
View file @
4f12db9e
#####################################################################################
#
####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
...
...
@@ -20,7 +20,7 @@
# 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.
#####################################################################################
#
####################################################################################
cmake_policy
(
SET CMP0057 NEW
)
...
...
@@ -49,27 +49,31 @@ function(add_test_command NAME EXE)
set_tests_properties
(
${
NAME
}
PROPERTIES DISABLED On
)
elseif
(
WIN32
)
set
(
WINPATH
)
foreach
(
PATH
${
CMAKE_FIND_ROOT_PATH
}
)
list
(
APPEND WINPATH
${
PATH
}
/bin
)
endforeach
()
file
(
GENERATE OUTPUT
"
${
CMAKE_CURRENT_BINARY_DIR
}
/test_
${
NAME
}
.cmd"
CONTENT
"set PATH=
${
WINPATH
}
;%PATH%
%1
${
ARGN
}
"
)
add_test
(
NAME
${
NAME
}
COMMAND
${
WINE_CMD
}
cmd /c
"
${
CMAKE_CURRENT_BINARY_DIR
}
/test_
${
NAME
}
.cmd"
$<TARGET_FILE:
${
EXE
}
>
)
else
()
if
(
MIGRAPHX_TEST_GDB
)
# add_test(NAME ${NAME} COMMAND ${MIGRAPHX_GDB}
#
--batch
#
--return-child-result
#
-ex "set disable-randomization off"
#
-ex run
#
-ex backtrace
#
--args $<TARGET_FILE:${EXE}> ${ARGN})
# add_test(NAME ${NAME} COMMAND ${MIGRAPHX_GDB}
# --batch
# --return-child-result
# -ex "set disable-randomization off"
# -ex run
# -ex backtrace
# --args $<TARGET_FILE:${EXE}> ${ARGN})
set
(
TEST_DIR
${
CMAKE_CURRENT_BINARY_DIR
}
/gdb/test_
${
NAME
}
)
file
(
MAKE_DIRECTORY
${
TEST_DIR
}
)
if
(
NOT EXISTS
${
TEST_DIR
}
)
if
(
NOT EXISTS
${
TEST_DIR
}
)
message
(
FATAL_ERROR
"Failed to create test directory:
${
TEST_DIR
}
"
)
endif
()
file
(
GENERATE OUTPUT
"
${
TEST_DIR
}
/run.cmake"
CONTENT
"
# Remove previous core dump
...
...
@@ -90,22 +94,27 @@ function(add_test_command NAME EXE)
add_test
(
NAME
${
NAME
}
COMMAND
${
EXE
}
${
ARGN
}
)
endif
()
endif
()
set_tests_properties
(
${
NAME
}
PROPERTIES FAIL_REGULAR_EXPRESSION
"FAILED"
)
endfunction
()
function
(
add_test_executable TEST_NAME
)
add_executable
(
${
TEST_NAME
}
EXCLUDE_FROM_ALL
${
ARGN
}
)
add_executable
(
${
TEST_NAME
}
EXCLUDE_FROM_ALL
${
ARGN
}
)
target_link_libraries
(
${
TEST_NAME
}
${
CMAKE_THREAD_LIBS_INIT
}
)
# Cmake does not add flags correctly for gcc
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"GNU"
)
if
(
CMAKE_CXX_COMPILER_ID MATCHES
"GNU"
)
set_target_properties
(
${
TEST_NAME
}
PROPERTIES COMPILE_FLAGS -pthread LINK_FLAGS -pthread
)
endif
()
separate_arguments
(
MIOPEN_TEST_FLAGS_ARGS UNIX_COMMAND
${
MIOPEN_TEST_FLAGS
}
)
if
(
MIOPEN_TEST_ALL
)
set
(
TEST_COMMAND
${
TEST_NAME
}
${
MIOPEN_TEST_FLOAT_ARG
}
--all
${
MIOPEN_TEST_FLAGS_ARGS
}
)
else
()
set
(
TEST_COMMAND
${
TEST_NAME
}
${
MIOPEN_TEST_FLOAT_ARG
}
${
MIOPEN_TEST_FLAGS_ARGS
}
)
endif
()
add_test_command
(
${
TEST_NAME
}
${
TEST_COMMAND
}
)
add_dependencies
(
tests
${
TEST_NAME
}
)
add_dependencies
(
check
${
TEST_NAME
}
)
...
...
@@ -129,11 +138,11 @@ if(MIGRAPHX_ENABLE_GPU)
get_filename_component
(
BASE_NAME
${
TEST
}
NAME_WE
)
add_test_executable
(
test_gpu_
${
BASE_NAME
}
${
TEST
}
)
rocm_clang_tidy_check
(
test_gpu_
${
BASE_NAME
}
)
set_tests_properties
(
test_gpu_
${
BASE_NAME
}
PROPERTIES
COST 10
set_tests_properties
(
test_gpu_
${
BASE_NAME
}
PROPERTIES
COST 10
RESOURCE_LOCK gpu
)
target_link_libraries
(
test_gpu_
${
BASE_NAME
}
migraphx_gpu
)
target_link_libraries
(
test_gpu_
${
BASE_NAME
}
migraphx_gpu
migraphx_kernels
)
endforeach
()
endif
()
...
...
@@ -145,8 +154,8 @@ if(MIGRAPHX_ENABLE_FPGA)
get_filename_component
(
BASE_NAME
${
TEST
}
NAME_WE
)
add_test_executable
(
test_fpga_
${
BASE_NAME
}
${
TEST
}
)
rocm_clang_tidy_check
(
test_fpga_
${
BASE_NAME
}
)
set_tests_properties
(
test_fpga_
${
BASE_NAME
}
PROPERTIES
COST 10
set_tests_properties
(
test_fpga_
${
BASE_NAME
}
PROPERTIES
COST 10
RESOURCE_LOCK fpga
)
target_link_libraries
(
test_fpga_
${
BASE_NAME
}
migraphx_fpga
)
...
...
@@ -155,7 +164,8 @@ endif()
# Onnx test
set
(
TEST_ONNX_DIR
${
CMAKE_CURRENT_SOURCE_DIR
}
/onnx
)
file
(
GLOB ONNX_TESTS
${
TEST_ONNX_DIR
}
/*.cpp
)
file
(
GLOB ONNX_TESTS
${
TEST_ONNX_DIR
}
/*.cpp
)
foreach
(
ONNX_TEST
${
ONNX_TESTS
}
)
get_filename_component
(
BASE_NAME
${
ONNX_TEST
}
NAME_WE
)
set
(
TEST_NAME test_
${
BASE_NAME
}
)
...
...
@@ -163,7 +173,7 @@ foreach(ONNX_TEST ${ONNX_TESTS})
rocm_clang_tidy_check
(
${
TEST_NAME
}
)
target_link_libraries
(
${
TEST_NAME
}
migraphx_onnx migraphx_ref
)
target_include_directories
(
${
TEST_NAME
}
PUBLIC include
)
add_test
(
NAME
${
TEST_NAME
}
COMMAND $<TARGET_FILE:
${
TEST_NAME
}
> WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
add_test
(
NAME
${
TEST_NAME
}
COMMAND $<TARGET_FILE:
${
TEST_NAME
}
> WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
add_dependencies
(
tests
${
TEST_NAME
}
)
add_dependencies
(
check
${
TEST_NAME
}
)
endforeach
()
...
...
@@ -174,26 +184,26 @@ add_executable(test_tf tf/tf_test.cpp)
rocm_clang_tidy_check
(
test_tf
)
target_link_libraries
(
test_tf migraphx_tf migraphx_ref
)
target_include_directories
(
test_tf PUBLIC include
)
add_test
(
NAME test_tf COMMAND $<TARGET_FILE:test_tf> WORKING_DIRECTORY
${
TEST_TF_DIR
}
)
add_test
(
NAME test_tf COMMAND $<TARGET_FILE:test_tf> WORKING_DIRECTORY
${
TEST_TF_DIR
}
)
add_dependencies
(
tests test_tf
)
add_dependencies
(
check test_tf
)
add_subdirectory
(
api
)
add_subdirectory
(
verify
)
if
(
MIGRAPHX_ENABLE_PYTHON
)
add_subdirectory
(
py
)
add_subdirectory
(
py
)
endif
()
function
(
test_header NAME HEADER
)
file
(
WRITE
${
CMAKE_CURRENT_BINARY_DIR
}
/header-main-include-
${
NAME
}
.cpp
file
(
WRITE
${
CMAKE_CURRENT_BINARY_DIR
}
/header-main-include-
${
NAME
}
.cpp
"#include <
${
HEADER
}
>
\n
int main() {}
\n
"
)
file
(
WRITE
${
CMAKE_CURRENT_BINARY_DIR
}
/header-static-include-
${
NAME
}
.cpp
file
(
WRITE
${
CMAKE_CURRENT_BINARY_DIR
}
/header-static-include-
${
NAME
}
.cpp
"#include <
${
HEADER
}
>
\n
"
)
add_test_executable
(
${
NAME
}
${
CMAKE_CURRENT_BINARY_DIR
}
/header-main-include-
${
NAME
}
.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/header-main-include-
${
NAME
}
.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/header-static-include-
${
NAME
}
.cpp
)
endfunction
()
...
...
@@ -206,6 +216,7 @@ function(test_headers PREFIX)
string
(
MAKE_C_IDENTIFIER
${
HEADER_REL
}
TEST_NAME
)
get_filename_component
(
BASE_NAME
${
HEADER
}
NAME_WE
)
test_header
(
header_
${
TEST_NAME
}
${
PREFIX
}
/
${
BASE_NAME
}
.hpp
)
if
(
MIGRAPHX_ENABLE_GPU
)
target_link_libraries
(
header_
${
TEST_NAME
}
migraphx_gpu
)
endif
()
...
...
@@ -214,6 +225,7 @@ endfunction()
test_headers
(
migraphx
${
CMAKE_SOURCE_DIR
}
/src/include/migraphx/*.hpp
)
test_headers
(
migraphx/ref
${
CMAKE_SOURCE_DIR
}
/src/targets/ref/include/migraphx/ref/*.hpp
)
if
(
MIGRAPHX_ENABLE_GPU
)
test_headers
(
migraphx/gpu
${
CMAKE_SOURCE_DIR
}
/src/targets/gpu/include/migraphx/gpu/*.hpp
)
test_headers
(
migraphx/gpu
${
CMAKE_SOURCE_DIR
}
/src/targets/gpu/include/migraphx/gpu/*.hpp
)
endif
()
test/api/test_save_load.cpp
View file @
4f12db9e
...
...
@@ -30,7 +30,6 @@ TEST_CASE(load_save_default)
std
::
string
filename
=
"migraphx_api_load_save.mxr"
;
auto
p1
=
migraphx
::
parse_onnx
(
"conv_relu_maxpool_test.onnx"
);
auto
s1
=
p1
.
get_output_shapes
();
migraphx
::
save
(
p1
,
filename
.
c_str
());
auto
p2
=
migraphx
::
load
(
filename
.
c_str
());
auto
s2
=
p2
.
get_output_shapes
();
...
...
test/gpu/jit.cpp
View file @
4f12db9e
...
...
@@ -35,13 +35,14 @@
#include <migraphx/gpu/compile_hip.hpp>
#include <migraphx/gpu/compile_hip_code_object.hpp>
#include <migraphx/gpu/compiler.hpp>
#include <migraphx_kernels.hpp>
// NOLINTNEXTLINE
const
std
::
string
write_2s
=
R"__migraphx__(
#include <hip/hip_runtime.h>
extern "C" {
__global__ void write(
int8_t
* data)
__global__ void write(
char
* data)
{
int num = threadIdx.x + blockDim.x * blockIdx.x;
data[num] = 2;
...
...
@@ -58,7 +59,7 @@ const std::string add_2s_binary = R"__migraphx__(
#include <hip/hip_runtime.h>
extern "C" {
__global__ void add_2(
std::int8_t* x, std::int8_t
* y)
__global__ void add_2(
char* x, char
* y)
{
int num = threadIdx.x + blockDim.x * blockIdx.x;
y[num] = x[num] + 2;
...
...
@@ -137,7 +138,8 @@ int main() {}
const
std
::
string
math_template
=
R"__migraphx__(
#include <migraphx/kernels/pointwise.hpp>
#include <migraphx/kernels/math.hpp>
#include <migraphx/kernels/types.hpp>
using namespace migraphx;
extern "C" {
__global__ void kernel(${type}* p)
{
...
...
test/onnx/gather_dyn_test.onnx
0 → 100644
View file @
4f12db9e
File added
test/onnx/gather_scalar_test.onnx
0 → 100644
View file @
4f12db9e
File added
test/onnx/gen_onnx.py
View file @
4f12db9e
...
...
@@ -2053,6 +2053,40 @@ def gather_test():
return
([
node
],
[
x
,
i
],
[
y
])
@
onnx_test
()
def
gather_scalar_test
():
x
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
3
,
4
,
5
,
6
])
i
=
helper
.
make_tensor_value_info
(
'indices'
,
TensorProto
.
INT32
,
[])
y
=
helper
.
make_tensor_value_info
(
'y'
,
TensorProto
.
FLOAT
,
[
4
,
5
,
6
])
node
=
onnx
.
helper
.
make_node
(
'Gather'
,
inputs
=
[
'data'
,
'indices'
],
outputs
=
[
'y'
],
axis
=
1
,
)
return
([
node
],
[
x
,
i
],
[
y
])
@
onnx_test
()
def
gather_dyn_test
():
x
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
None
,
4
,
5
,
6
])
i
=
helper
.
make_tensor_value_info
(
'indices'
,
TensorProto
.
INT32
,
[
None
,
3
,
4
,
5
])
y
=
helper
.
make_tensor_value_info
(
'y'
,
TensorProto
.
FLOAT
,
[
2
,
3
,
4
,
5
])
node
=
onnx
.
helper
.
make_node
(
'Gather'
,
inputs
=
[
'data'
,
'indices'
],
outputs
=
[
'y'
],
axis
=
1
,
)
return
([
node
],
[
x
,
i
],
[
y
])
@
onnx_test
()
def
gather_elements_axis0_test
():
x
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
3
,
4
])
...
...
test/onnx/onnx_test.cpp
View file @
4f12db9e
...
...
@@ -2048,6 +2048,46 @@ TEST_CASE(gather_test)
EXPECT(p == prog);
}
TEST_CASE(gather_scalar_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
std::vector<size_t> idims{1};
auto l1 =
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int32_type, idims, {0}});
int axis = 1;
mm->add_instruction(migraphx::make_op("gather", {{"axis", axis}}), l0, l1);
auto prog = optimize_onnx("gather_scalar_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(gather_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter(
"data",
migraphx::shape{migraphx::shape::float_type, {{1, 4, 0}, {4, 4, 0}, {5, 5, 0}, {6, 6, 0}}});
auto l1 = mm->add_parameter(
"indices",
migraphx::shape{migraphx::shape::int32_type, {{1, 4, 0}, {3, 3, 0}, {4, 4, 0}, {5, 5, 0}}});
auto cont_l0 = mm->add_instruction(migraphx::make_op("contiguous"), l0);
auto cont_l1 = mm->add_instruction(migraphx::make_op("contiguous"), l1);
int axis = 1;
auto gather_op = migraphx::make_op("gather", {{"axis", axis}});
auto ret = mm->add_instruction(gather_op, cont_l0, cont_l1);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {1, 4, 0};
auto prog = parse_onnx("gather_dyn_test.onnx", options);
EXPECT(p == prog);
}
TEST_CASE(gather_elements_axis0_test)
{
migraphx::program p;
...
...
test/op_shape_test.cpp
View file @
4f12db9e
...
...
@@ -831,6 +831,77 @@ TEST_CASE(gather)
}
}
TEST_CASE
(
gather_dyn0
)
{
// Insert dynamic index into dynamic shape
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}};
migraphx
::
shape
indices
{
migraphx
::
shape
::
int32_type
,
{{
2
,
7
,
3
},
{
3
,
3
,
0
}}};
int
axis
=
1
;
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
2
,
7
,
3
},
{
3
,
3
,
0
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}},
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
input
,
indices
);
}
TEST_CASE
(
gather_dyn1
)
{
// Insert static index into dynamic shape
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}};
migraphx
::
shape
indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
int
axis
=
1
;
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
2
,
2
,
0
},
{
3
,
3
,
0
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}},
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
input
,
indices
);
}
TEST_CASE
(
gather_dyn2
)
{
// Insert scalar (static) index into dynamic shape
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}};
std
::
vector
<
std
::
size_t
>
mins
;
std
::
vector
<
std
::
size_t
>
maxes
;
std
::
vector
<
std
::
size_t
>
opts
;
migraphx
::
shape
indices
{
migraphx
::
shape
::
int32_type
,
mins
,
maxes
,
opts
};
int
axis
=
1
;
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
6
,
9
,
7
},
{
12
,
14
,
13
}}},
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
input
,
indices
);
}
TEST_CASE
(
gather_dyn3
)
{
// Insert dynamic index into static shape, axis 1
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
6
,
12
}};
migraphx
::
shape
indices
{
migraphx
::
shape
::
int32_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
}}};
int
axis
=
1
;
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
2
,
2
,
0
},
{
2
,
3
,
2
},
{
3
,
4
,
3
},
{
6
,
6
,
0
},
{
12
,
12
,
0
}}},
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
input
,
indices
);
}
TEST_CASE
(
gather_dyn4
)
{
// Insert dynamic index into static shape, axis 0
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
6
,
12
}};
migraphx
::
shape
indices
{
migraphx
::
shape
::
int32_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
}}};
int
axis
=
0
;
expect_shape
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
2
,
3
,
2
},
{
3
,
4
,
3
},
{
3
,
3
,
0
},
{
6
,
6
,
0
},
{
12
,
12
,
0
}}},
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
input
,
indices
);
}
TEST_CASE
(
get_tuple_elem_test
)
{
migraphx
::
shape
s0
{
migraphx
::
shape
::
bool_type
,
{
1
,
1
}};
...
...
test/ref_ops_test.cpp
View file @
4f12db9e
...
...
@@ -2524,6 +2524,78 @@ TEST_CASE(gather_test)
}
}
TEST_CASE(gather_dyn_test0)
{
// Dynamic data, static indices
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {{2, 5, 0}, {3, 3, 0}}};
auto x = mm->add_parameter("x", s);
std::vector<int> indices{1, 2};
migraphx::shape s_ind{migraphx::shape::int32_type, {1, 2}};
auto ind = mm->add_parameter("indices", s_ind);
mm->add_instruction(migraphx::make_op("gather", {{"axis", 1}}), x, ind);
migraphx::shape sresult{migraphx::shape::int32_type, {{2, 5, 0}, {1, 1, 0}, {2, 2, 0}}};
EXPECT(p.get_output_shapes().back() == sresult);
p.compile(migraphx::ref::target{});
migraphx::shape input_fixed_shape{migraphx::shape::int32_type, {2, 3}};
migraphx::shape input_indices{migraphx::shape::int32_type, {1, 2}};
migraphx::parameter_map params;
std::vector<int> data(2 * 3);
std::iota(data.begin(), data.end(), 0);
params["x"] = migraphx::argument(input_fixed_shape, data.data());
params["indices"] = migraphx::argument(input_indices, indices.data());
auto result = p.eval(params).back();
std::vector<int> gold = {1, 2, 4, 5};
std::vector<int> results_vector(2 * 1 * 2);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(results_vector, gold));
migraphx::shape sfinal{migraphx::shape::int32_type, {2, 1, 2}};
EXPECT(result.get_shape() == sfinal);
}
TEST_CASE(gather_dyn_test1)
{
// Dynamic data, dynamic indices
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {{2, 5, 0}, {4, 4, 0}}};
auto x = mm->add_parameter("x", s);
migraphx::shape s_ind{migraphx::shape::int32_type, {{1, 8, 7}, {2, 3, 3}}};
auto ind = mm->add_parameter("indices", s_ind);
mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), x, ind);
migraphx::shape sresult{migraphx::shape::int32_type, {{1, 8, 7}, {2, 3, 3}, {4, 4, 0}}};
EXPECT(p.get_output_shapes().back() == sresult);
p.compile(migraphx::ref::target{});
migraphx::shape input_fixed_shape{migraphx::shape::int32_type, {3, 4}};
migraphx::shape input_indices_shape{migraphx::shape::int32_type, {1, 2}};
std::vector<int> indices{2, 0};
migraphx::parameter_map params;
std::vector<int> data(3 * 4);
std::iota(data.begin(), data.end(), 0);
params["x"] = migraphx::argument(input_fixed_shape, data.data());
params["indices"] = migraphx::argument(input_indices_shape, indices.data());
auto result = p.eval(params).back();
std::vector<int> gold = {8, 9, 10, 11, 0, 1, 2, 3};
std::vector<int> results_vector(1 * 2 * 4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(results_vector, gold));
migraphx::shape sfinal{migraphx::shape::int32_type, {1, 2, 4}};
EXPECT(result.get_shape() == sfinal);
}
TEST_CASE(gathernd_test)
{
{
...
...
Prev
1
2
Next
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