Unverified Commit fc60486e authored by Chris Austen's avatar Chris Austen Committed by GitHub
Browse files

Merge branch 'develop' into enable_navi_32_ci

parents 6041f74c 434a06cf
......@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/permutation.hpp>
#include <migraphx/gpu/prefuse_ops.hpp>
#include <migraphx/match/layernorm.hpp>
#include <migraphx/check_shapes.hpp>
......@@ -45,40 +46,42 @@ struct layernorm_base
}
shape compute_shape(std::vector<shape> inputs, std::vector<module_ref> mods) const
{
std::size_t nargs = 1;
std::size_t nargs = N;
if(not mods.empty())
{
auto* pm = mods.front();
nargs = pm->get_parameter_names().size();
nargs += pm->get_parameter_names().size() - 1;
}
check_shapes{inputs, static_cast<const Derived&>(*this)}.has(nargs + N);
auto s = inputs.at(0);
check_shapes{inputs, static_cast<const Derived&>(*this)}.has(nargs);
auto s = inputs.front();
auto t = s.type();
if(not mods.empty())
t = mods.front()->get_output_shapes().front().type();
if(s.scalar())
{
return s;
}
else if(s.broadcasted())
{
return {t, s.lens()};
}
else
{
return s.with_lens(t, s.lens());
}
// Scalar output if all inputs are scalar
if(inputs.front().elements() == 1 and
all_of(inputs, [](const auto& ss) { return ss.scalar(); }))
return inputs.front();
auto l_s = shape::from_permutation(
t, s.lens(), find_permutation(std::vector<shape>(inputs.begin(), inputs.begin() + N)));
// just prelayernorm or preadd_layernorm
if(nargs <= N)
return l_s;
// else, layernorm + pointwise fusion, preserve layout of fused op
std::vector<shape> lp_s(inputs.begin() + N, inputs.end());
lp_s.insert(lp_s.begin(), l_s);
return shape::from_permutation(t, s.lens(), find_permutation(lp_s));
}
};
struct layernorm : layernorm_base<layernorm, 0>
struct layernorm : layernorm_base<layernorm, 1>
{
std::string name() const { return "gpu::prelayernorm"; }
};
MIGRAPHX_REGISTER_OP(layernorm);
struct add_layernorm : layernorm_base<add_layernorm, 1>
struct add_layernorm : layernorm_base<add_layernorm, 2>
{
std::string name() const { return "gpu::preadd_layernorm"; }
};
......
......@@ -48,6 +48,7 @@
#include <migraphx/rewrite_quantization.hpp>
#include <migraphx/rewrite_rnn.hpp>
#include <migraphx/schedule.hpp>
#include <migraphx/simplify_dyn_ops.hpp>
#include <migraphx/simplify_qdq.hpp>
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/split_single_dyn_dim.hpp>
......@@ -109,6 +110,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
{
split_single_dyn_dim{},
dead_code_elimination{},
simplify_dyn_ops{},
dead_code_elimination{},
normalize_ops{},
dead_code_elimination{},
simplify_qdq{},
......
......@@ -78,16 +78,6 @@ bool verify_args(const std::string& name,
if(verify::range_zero(target))
std::cout << "Target data is all zeros" << std::endl;
// auto mxdiff = max_diff(ref, target);
// std::cout << "Max diff: " << mxdiff << std::endl;
// auto idx = mismatch_idx(ref, target, float_equal);
// if(idx < verify::range_distance(ref))
// {
// std::cout << "Mismatch at " << idx << ": " << ref[idx] << " != " << target[idx]
// << std::endl;
// }
auto ref_nan_idx = find_idx(ref, verify::not_finite);
if(ref_nan_idx >= 0)
std::cout << "Non finite number found in ref at " << ref_nan_idx << ": "
......@@ -97,7 +87,7 @@ bool verify_args(const std::string& name,
if(target_nan_idx >= 0)
std::cout << "Non finite number found in target at " << target_nan_idx << ": "
<< target[target_nan_idx] << std::endl;
// std::cout << std::endl;
std::cout << "MIGraphX verification passed successfully." << std::endl;
}
});
return passed;
......
......@@ -25,92 +25,19 @@
cmake_policy(SET CMP0057 NEW)
find_package(Threads REQUIRED)
include(ProcessorCount)
ProcessorCount(N)
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout 5000)
add_custom_target(tests)
find_program(MIGRAPHX_GDB gdb)
if(MIGRAPHX_GDB)
set(MIGRAPHX_TEST_GDB On CACHE BOOL "")
else()
set(MIGRAPHX_TEST_GDB Off CACHE BOOL "")
endif()
set(SKIP_TESTS)
function(add_test_command NAME EXE)
if(NAME IN_LIST SKIP_TESTS)
add_test(NAME ${NAME} COMMAND echo skipped)
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})
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/gdb/test_${NAME})
file(MAKE_DIRECTORY ${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
file(REMOVE ${TEST_DIR}/core)
execute_process(COMMAND $<TARGET_FILE:${EXE}> ${ARGN} WORKING_DIRECTORY ${TEST_DIR} RESULT_VARIABLE RESULT)
if(NOT RESULT EQUAL 0)
# TODO: check for core files based on pid when setting /proc/sys/kernel/core_uses_pid
if(EXISTS ${TEST_DIR}/core)
set(\$ENV{UBSAN_OPTIONS} print_stacktrace=1)
set(\$ENV{ASAN_OPTIONS} print_stacktrace=1)
execute_process(COMMAND ${MIGRAPHX_GDB} $<TARGET_FILE:${EXE}> ${TEST_DIR}/core -batch -ex bt)
endif()
message(FATAL_ERROR \"Test failed\")
endif()
")
add_test(NAME ${NAME} COMMAND ${CMAKE_COMMAND} -P "${TEST_DIR}/run.cmake")
else()
add_test(NAME ${NAME} COMMAND ${EXE} ${ARGN})
endif()
endif()
rocm_test_link_libraries(Threads::Threads migraphx migraphx_ref migraphx_onnx migraphx_tf)
rocm_test_include_directories(include)
set_tests_properties(${NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED")
endfunction()
function(add_test_executable TEST_NAME)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
set(TEST_COMMAND ${TEST_NAME})
add_test_command(${TEST_NAME} ${TEST_COMMAND})
add_dependencies(tests ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
target_link_libraries(${TEST_NAME} Threads::Threads migraphx migraphx_onnx migraphx_ref)
target_include_directories(${TEST_NAME} PUBLIC include)
endfunction(add_test_executable)
set(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS Off CACHE BOOL "")
if(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS)
add_compile_definitions(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS)
endif()
file(GLOB TESTS CONFIGURE_DEPENDS *.cpp)
foreach(TEST ${TESTS})
get_filename_component(BASE_NAME ${TEST} NAME_WE)
add_test_executable(test_${BASE_NAME} ${TEST})
rocm_add_test_executable(test_${BASE_NAME} ${TEST})
rocm_clang_tidy_check(test_${BASE_NAME})
endforeach()
......@@ -120,7 +47,7 @@ if(MIGRAPHX_ENABLE_GPU)
foreach(TEST ${GPU_TESTS})
get_filename_component(BASE_NAME ${TEST} NAME_WE)
add_test_executable(test_gpu_${BASE_NAME} ${TEST})
rocm_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
......@@ -139,7 +66,7 @@ if(MIGRAPHX_ENABLE_FPGA)
foreach(TEST ${FPGA_TESTS})
get_filename_component(BASE_NAME ${TEST} NAME_WE)
add_test_executable(test_fpga_${BASE_NAME} ${TEST})
rocm_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
......@@ -161,19 +88,17 @@ foreach(ONNX_TEST ${ONNX_TESTS})
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_dependencies(tests ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
rocm_mark_as_test(${TEST_NAME})
endforeach()
# tf test
set(TEST_TF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tf)
add_executable(test_tf tf/tf_test.cpp)
rocm_mark_as_test(test_tf)
rocm_clang_tidy_check(test_tf)
target_link_libraries(test_tf migraphx_tf)
target_include_directories(test_tf PUBLIC include)
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)
......@@ -196,8 +121,7 @@ if(MIGRAPHX_ENABLE_GPU AND MIGRAPHX_ENABLE_CPU AND MIGRAPHX_ENABLE_FPGA)
target_link_libraries(${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets)
target_include_directories(${TEST_NAME} PUBLIC include)
add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}> WORKING_DIRECTORY ${TEST_MULTI_TARGET_DIR})
add_dependencies(tests ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
rocm_mark_as_test(${TEST_NAME})
endforeach()
endif()
......@@ -214,7 +138,7 @@ int main() {}\n"
#endif
\n"
)
add_test_executable(${NAME}
rocm_add_test_executable(${NAME}
${CMAKE_CURRENT_BINARY_DIR}/header-main-include-${NAME}.cpp
${CMAKE_CURRENT_BINARY_DIR}/header-static-include-${NAME}.cpp
)
......@@ -236,13 +160,13 @@ 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 HEADERS ${CMAKE_SOURCE_DIR}/src/targets/gpu/include/migraphx/gpu/*.hpp DEPENDS migraphx_gpu)
endif()
if(MIGRAPHX_ENABLE_CPU)
test_headers(migraphx/cpu ${CMAKE_SOURCE_DIR}/src/targets/cpu/include/migraphx/cpu/*.hpp)
test_headers(migraphx/cpu HEADERS ${CMAKE_SOURCE_DIR}/src/targets/cpu/include/migraphx/cpu/*.hpp migraphx_cpu)
endif()
if(MIGRAPHX_ENABLE_FPGA)
test_headers(migraphx/fpga ${CMAKE_SOURCE_DIR}/src/targets/fpga/include/migraphx/fpga/*.hpp)
test_headers(migraphx/fpga HEADERS ${CMAKE_SOURCE_DIR}/src/targets/fpga/include/migraphx/fpga/*.hpp migraphx_fpga)
endif()
......@@ -218,6 +218,15 @@ TEST_CASE(compile_warnings)
#endif
}
TEST_CASE(has_flags)
{
EXPECT(migraphx::gpu::hip_has_flags({"--std=c++17"}));
EXPECT(not migraphx::gpu::hip_has_flags({"--non-existent-flag-to-test-in-migraphx"}));
EXPECT(migraphx::gpu::hip_has_flags({"-Wunused-parameter"}));
EXPECT(not migraphx::gpu::hip_has_flags(
{"-Wnon-existent-warnings-flag-to-test-in-migraphx", "-Werror"}));
}
TEST_CASE(code_object_hip)
{
auto binaries = migraphx::gpu::compile_hip_src(
......
......@@ -25,13 +25,37 @@
#include <migraphx/value.hpp>
#include <msgpack.hpp>
#include <map>
#include <numeric>
#include "test.hpp"
template <class T, MIGRAPHX_REQUIRES(not std::is_base_of<std::vector<std::uint8_t>, T>{})>
void write_msgpack(std::ostream& os, const T& src)
{
msgpack::pack(os, src);
}
void write_msgpack(std::ostream& os, const std::vector<std::uint8_t>& src)
{
const auto limit = std::numeric_limits<uint32_t>::max() - 1;
std::vector<std::vector<std::uint8_t>> chunks;
if(src.size() > limit)
{
// Only test two chunks
assert(std::distance(src.begin() + limit, src.end()) < limit);
chunks.emplace_back(src.begin(), src.begin() + limit);
chunks.emplace_back(src.begin() + limit, src.end());
}
else
{
chunks = {src};
}
write_msgpack(os, chunks);
}
template <class T>
std::vector<char> msgpack_buffer(const T& src)
{
std::stringstream buffer;
msgpack::pack(buffer, src);
write_msgpack(buffer, src);
buffer.seekg(0);
std::string str = buffer.str();
return std::vector<char>(str.data(), str.data() + str.size()); // NOLINT
......@@ -147,4 +171,51 @@ TEST_CASE(test_msgpack_array_class)
EXPECT(migraphx::from_msgpack(buffer) == v);
}
TEST_CASE(test_msgpack_binary)
{
migraphx::value::binary bin{64};
std::iota(bin.begin(), bin.end(), 1);
auto buffer = migraphx::to_msgpack(bin);
EXPECT(buffer == msgpack_buffer(bin));
EXPECT(migraphx::from_msgpack(buffer) == bin);
}
#ifndef MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS
TEST_CASE(test_msgpack_large_binary1)
{
const std::size_t n = 4LL * 1024 * 1024 * 1024 + 2;
const char fill_value = 2;
migraphx::value v;
{
std::vector<char> buffer;
{
migraphx::value::binary bin{n};
std::fill(bin.begin(), bin.begin() + n / 2, fill_value);
std::fill(bin.begin() + n / 2, bin.end(), fill_value + 1);
buffer = migraphx::to_msgpack(std::move(bin));
}
v = migraphx::from_msgpack(buffer);
}
EXPECT(v.is_binary());
EXPECT(v.get_binary().size() == n);
EXPECT(std::all_of(v.get_binary().begin(), v.get_binary().begin() + n / 2, [](auto c) {
return c == fill_value;
}));
EXPECT(std::all_of(v.get_binary().begin() + n / 2, v.get_binary().end(), [](auto c) {
return c == fill_value + 1;
}));
}
TEST_CASE(test_msgpack_binary2)
{
const std::size_t n = 4LL * 1024 * 1024 * 1024 + 2;
migraphx::value::binary bin{n};
std::size_t i = 0;
std::generate(bin.begin(), bin.end(), [&] {
i++;
return i % 256;
});
EXPECT(migraphx::to_msgpack(bin) == msgpack_buffer(bin));
}
#endif
int main(int argc, const char* argv[]) { test::run(argc, argv); }
ae74a517b62baa6d973e46b5b51ac9a640512c46
6d7bc2a097a1a08541cd0d4628831c79ab8092d5
constant_no_attributes_test:)
"Constantconstant_no_attributes_testB
\ No newline at end of file
constant_value_int_test:7
"Constant*
value_int@ constant_value_int_testB
\ No newline at end of file
constant_value_ints_test:=
!"Constant*
value_ints@@@ constant_value_ints_testB
\ No newline at end of file
......@@ -825,6 +825,76 @@ def constant_test():
return ([node], [], [y])
@onnx_test()
def constant_value_float_test():
node = onnx.helper.make_node('Constant',
inputs=[],
outputs=[],
value_float=[1.0])
return ([node], [], [])
@onnx_test()
def constant_value_floats_test():
node = onnx.helper.make_node('Constant',
inputs=[],
outputs=[],
value_floats=[1.0, 2.0, 3.0])
return ([node], [], [])
@onnx_test()
def constant_value_int_test():
node = onnx.helper.make_node('Constant',
inputs=[],
outputs=[],
value_int=[1])
return ([node], [], [])
@onnx_test()
def constant_value_ints_test():
node = onnx.helper.make_node('Constant',
inputs=[],
outputs=[],
value_ints=[1, 2, 3])
return ([node], [], [])
@onnx_test()
def constant_no_attributes_test():
node = onnx.helper.make_node('Constant', inputs=[], outputs=[])
return ([node], [], [])
@onnx_test()
def constant_multiple_attributes_test():
x = np.array([0, 1, 2])
node = onnx.helper.make_node('Constant',
inputs=[],
outputs=[],
value_floats=[1.0, 2.0],
value_ints=[1, 2],
value=onnx.helper.make_tensor(
name='const_tensor',
data_type=TensorProto.FLOAT,
dims=x.shape,
vals=x.flatten().astype(float)))
return ([node], [], [])
@onnx_test()
def constant_fill_test():
value = helper.make_tensor_value_info('value', TensorProto.FLOAT, [2, 3])
......
......@@ -930,6 +930,58 @@ TEST_CASE(constant_test)
EXPECT(p == prog);
}
TEST_CASE(constant_value_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(migraphx::literal{migraphx::shape{migraphx::shape::float_type, {1}}, {1.0f}});
auto prog = optimize_onnx("constant_value_float_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(constant_value_floats_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(
migraphx::literal{migraphx::shape{migraphx::shape::float_type, {3}}, {1.0f, 2.0f, 3.0f}});
auto prog = optimize_onnx("constant_value_floats_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(constant_value_int_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(migraphx::literal{migraphx::shape{migraphx::shape::int64_type, {1}}, {1}});
auto prog = optimize_onnx("constant_value_int_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(constant_value_ints_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(
migraphx::literal{migraphx::shape{migraphx::shape::int64_type, {3}}, {1, 2, 3}});
auto prog = optimize_onnx("constant_value_ints_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(constant_no_attributes_test)
{
EXPECT(test::throws([&] { optimize_onnx("constant_no_attributes_test.onnx"); }));
}
TEST_CASE(constant_multiple_attributes_test)
{
EXPECT(test::throws([&] { optimize_onnx("constant_multiple_attributes_test.onnx"); }));
}
TEST_CASE(constant_fill_test)
{
migraphx::program p;
......@@ -5899,7 +5951,13 @@ TEST_CASE(roialign_default_test)
auto rois = mm->add_parameter("rois", srois);
auto bi = mm->add_parameter("batch_ind", sbi);
auto r = mm->add_instruction(migraphx::make_op("roialign"), x, rois, bi);
// Due to the onnx model using opset 12, the coordinate_transformation_mode should be set to
// output_half_pixel
auto r = mm->add_instruction(
migraphx::make_op("roialign", {{"coordinate_transformation_mode", "output_half_pixel"}}),
x,
rois,
bi);
mm->add_return({r});
auto prog = migraphx::parse_onnx("roialign_default_test.onnx");
......
......@@ -890,6 +890,50 @@ TEST_CASE(flatten_dyn_axis4)
input);
}
TEST_CASE(fill_static_int)
{
migraphx::shape default_value{migraphx::shape::int64_type, {1}, {0}};
migraphx::shape data{migraphx::shape::int64_type, {3, 4, 4}};
expect_shape(migraphx::shape{migraphx::shape::int64_type, {3, 4, 4}},
migraphx::make_op("fill"),
default_value,
data);
}
TEST_CASE(fill_static_float)
{
migraphx::shape default_value{migraphx::shape::float_type, {1}, {0}};
migraphx::shape data{migraphx::shape::float_type, {4, 8}};
expect_shape(migraphx::shape{migraphx::shape::float_type, {4, 8}},
migraphx::make_op("fill"),
default_value,
data);
}
TEST_CASE(fill_dyn_int)
{
migraphx::shape default_value{migraphx::shape::int64_type, {1}, {0}};
migraphx::shape data{migraphx::shape::int64_type,
{{1, 4}, {4, 8, {4, 6, 8}}, {4, 8, {4, 6, 8}}}};
expect_shape(migraphx::shape{migraphx::shape::int64_type,
{{1, 4}, {4, 8, {4, 6, 8}}, {4, 8, {4, 6, 8}}}},
migraphx::make_op("fill"),
default_value,
data);
}
TEST_CASE(fill_dyn_float)
{
migraphx::shape default_value{migraphx::shape::float_type, {1}, {0}};
migraphx::shape data{migraphx::shape::float_type,
{{1, 4}, {4, 8, {4, 6, 8}}, {4, 8, {4, 6, 8}}}};
expect_shape(migraphx::shape{migraphx::shape::float_type,
{{1, 4}, {4, 8, {4, 6, 8}}, {4, 8, {4, 6, 8}}}},
migraphx::make_op("fill"),
default_value,
data);
}
TEST_CASE(gather)
{
{
......@@ -2260,6 +2304,20 @@ TEST_CASE(prefix_scan_sum_dyn_2d)
}
}
TEST_CASE(random_uniform)
{
std::vector<migraphx::shape::dynamic_dimension> dd{{5, 8}, {3, 7}};
migraphx::shape s0{migraphx::shape::uint64_type, {1}};
migraphx::shape s1{migraphx::shape::float_type, dd};
expect_shape(s1, migraphx::make_op("random_uniform"), s0, s1);
}
TEST_CASE(random_seed)
{
migraphx::shape s{migraphx::shape::uint64_type, {1}, {0}};
expect_shape(s, migraphx::make_op("random_seed"));
}
TEST_CASE(quant_convolution_shape)
{
migraphx::shape output{migraphx::shape::int32_type, {4, 4, 1, 1}};
......
/*
* 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/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/module.hpp>
#include <migraphx/optimize_module.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/serialize.hpp>
#include <test.hpp>
void run_pass(migraphx::module& m) { migraphx::run_passes(m, {migraphx::optimize_module{}}); }
TEST_CASE(broadcast_transpose_inner_broadcast)
{
// first optimizes broadcast+transpose to just a broadcast,
// then finds inner broadcast to become mul+broadcast
migraphx::module m1;
{
auto l1 = m1.add_parameter("x", {migraphx::shape::float_type, {1}, {0}});
auto l2 = m1.add_parameter("y", {migraphx::shape::float_type, {1}, {0}});
auto mb1 =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 2, 3}}}), l1);
auto mb2 =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 2}}}), l2);
auto t1 =
m1.add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1}}}), mb1);
auto mul = m1.add_instruction(migraphx::make_op("mul"), mb2, t1);
m1.add_return({mul});
}
run_pass(m1);
migraphx::module m2;
{
auto l1 = m2.add_parameter("x", {migraphx::shape::float_type, {1}, {0}});
auto l2 = m2.add_parameter("y", {migraphx::shape::float_type, {1}, {0}});
auto mul = m2.add_instruction(migraphx::make_op("mul"), l2, l1);
auto mb =
m2.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 2}}}), mul);
m2.add_return({mb});
}
EXPECT(m1 == m2);
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
......@@ -104,9 +104,209 @@ def disabled_tests_onnx_1_10_0(backend_test):
backend_test.exclude(r'test_shape_start_negative_1_cpu')
def disabled_tests_onnx_1_12_0(backend_test):
def disabled_tests_onnx_1_11_0(backend_test):
# crash
backend_test.exclude(r'test_scatter_elements_with_duplicate_indices_cpu')
# fails
backend_test.exclude(r'test_roialign_aligned_false_cpu')
backend_test.exclude(r'test_roialign_aligned_true_cpu')
backend_test.exclude(r'test_scatternd_add_cpu')
backend_test.exclude(r'test_scatternd_multiply_cpu')
# errors
backend_test.exclude(r'test_identity_opt_cpu')
backend_test.exclude(r'test_if_opt_cpu')
def disabled_tests_onnx_1_12_0(backend_test):
pass
def disabled_tests_onnx_1_13_0(backend_test):
# fails
backend_test.exclude(r'test_reduce_l1_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_l1_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_l1_keep_dims_example_cpu')
backend_test.exclude(r'test_reduce_l1_keep_dims_random_cpu')
backend_test.exclude(r'test_reduce_l1_negative_axes_keep_dims_example_cpu')
backend_test.exclude(r'test_reduce_l1_negative_axes_keep_dims_random_cpu')
backend_test.exclude(r'test_reduce_l2_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_l2_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_l2_keep_dims_example_cpu')
backend_test.exclude(r'test_reduce_l2_keep_dims_random_cpu')
backend_test.exclude(r'test_reduce_l2_negative_axes_keep_dims_example_cpu')
backend_test.exclude(r'test_reduce_l2_negative_axes_keep_dims_random_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_log_sum_exp_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_log_sum_exp_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_log_sum_exp_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_negative_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_sum_square_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_sum_square_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_sum_square_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_sum_square_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_sum_square_negative_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_sum_square_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_scatternd_max_cpu')
backend_test.exclude(r'test_scatternd_min_cpu')
# errors
backend_test.exclude(r'test_constant_pad_axes_cpu')
backend_test.exclude(r'test_reduce_l1_default_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_l1_default_axes_keepdims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l1_default_axes_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_l1_default_axes_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_l1_do_not_keepdims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l1_do_not_keepdims_random_expanded_cpu')
backend_test.exclude(r'test_reduce_l1_keep_dims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l1_keep_dims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_l1_negative_axes_keep_dims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_l1_negative_axes_keep_dims_random_expanded_cpu')
backend_test.exclude(r'test_reduce_l2_default_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_l2_default_axes_keepdims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l2_default_axes_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_l2_default_axes_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_l2_do_not_keepdims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l2_do_not_keepdims_random_expanded_cpu')
backend_test.exclude(r'test_reduce_l2_keep_dims_example_expanded_cpu')
backend_test.exclude(r'test_reduce_l2_keep_dims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_l2_negative_axes_keep_dims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_l2_negative_axes_keep_dims_random_expanded_cpu')
backend_test.exclude(r'test_reduce_log_sum_asc_axes_cpu')
backend_test.exclude(r'test_reduce_log_sum_asc_axes_expanded_cpu')
backend_test.exclude(r'test_reduce_log_sum_default_cpu')
backend_test.exclude(r'test_reduce_log_sum_default_expanded_cpu')
backend_test.exclude(r'test_reduce_log_sum_desc_axes_cpu')
backend_test.exclude(r'test_reduce_log_sum_desc_axes_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_default_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_default_axes_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_default_axes_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_default_axes_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_do_not_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_do_not_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_negative_axes_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_log_sum_exp_negative_axes_keepdims_random_expanded_cpu')
backend_test.exclude(r'test_reduce_log_sum_negative_axes_cpu')
backend_test.exclude(r'test_reduce_log_sum_negative_axes_expanded_cpu')
backend_test.exclude(r'test_reduce_max_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_max_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_max_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_max_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_max_negative_axes_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_max_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_mean_default_axes_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_mean_default_axes_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_mean_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_mean_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_mean_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_mean_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_mean_negative_axes_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_mean_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_min_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_min_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_min_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_min_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_min_negative_axes_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_min_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_prod_do_not_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_prod_do_not_keepdims_random_cpu')
backend_test.exclude(r'test_reduce_prod_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_prod_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_prod_negative_axes_keepdims_example_cpu')
backend_test.exclude(r'test_reduce_prod_negative_axes_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_sum_square_default_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_sum_square_default_axes_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_default_axes_keepdims_random_cpu')
backend_test.exclude(
r'test_reduce_sum_square_default_axes_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_do_not_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_do_not_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_keepdims_random_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_negative_axes_keepdims_example_expanded_cpu')
backend_test.exclude(
r'test_reduce_sum_square_negative_axes_keepdims_random_expanded_cpu')
backend_test.exclude(r'test_scatter_elements_with_reduction_max_cpu')
backend_test.exclude(r'test_scatter_elements_with_reduction_min_cpu')
# The following tests fail due to the CastLike operator being unsupported
backend_test.exclude(r'test_elu_default_expanded_ver18_cpu')
backend_test.exclude(r'test_elu_example_expanded_ver18_cpu')
backend_test.exclude(r'test_elu_expanded_ver18_cpu')
backend_test.exclude(r'test_hardsigmoid_default_expanded_ver18_cpu')
backend_test.exclude(r'test_hardsigmoid_example_expanded_ver18_cpu')
backend_test.exclude(r'test_hardsigmoid_expanded_ver18_cpu')
backend_test.exclude(r'test_leakyrelu_default_expanded_cpu')
backend_test.exclude(r'test_leakyrelu_example_expanded_cpu')
backend_test.exclude(r'test_leakyrelu_expanded_cpu')
backend_test.exclude(r'test_selu_default_expanded_ver18_cpu')
backend_test.exclude(r'test_selu_example_expanded_ver18_cpu')
backend_test.exclude(r'test_selu_expanded_ver18_cpu')
backend_test.exclude(r'test_thresholdedrelu_default_expanded_ver18_cpu')
backend_test.exclude(r'test_thresholdedrelu_example_expanded_ver18_cpu')
backend_test.exclude(r'test_thresholdedrelu_expanded_ver18_cpu')
backend_test.exclude(r'test_relu_expanded_ver18_cpu')
backend_test.exclude(r'test_softsign_example_expanded_ver18_cpu')
backend_test.exclude(r'test_softsign_expanded_ver18_cpu')
def disabled_tests_onnx_1_14_0(backend_test):
# fails
backend_test.exclude(r'test_averagepool_2d_dilations_cpu')
backend_test.exclude(r'test_roialign_mode_max_cpu')
# errors
backend_test.exclude(r'test_constant_pad_negative_axes_cpu')
backend_test.exclude(r'test_dequantizelinear_e4m3fn_cpu')
backend_test.exclude(r'test_dequantizelinear_e5m2_cpu')
backend_test.exclude(r'test_equal_string_broadcast_cpu')
backend_test.exclude(r'test_equal_string_cpu')
backend_test.exclude(r'test_quantizelinear_e4m3fn_cpu')
backend_test.exclude(r'test_quantizelinear_e5m2_cpu')
# The following tests fail due to the CastLike operator being unsupported
backend_test.exclude(r'test_softplus_example_expanded_ver18_cpu')
backend_test.exclude(r'test_softplus_expanded_ver18_cpu')
def create_backend_test(testname=None, target_device=None):
if target_device is not None:
......@@ -331,9 +531,18 @@ def create_backend_test(testname=None, target_device=None):
if version.parse(onnx.__version__) >= version.parse("1.10.0"):
disabled_tests_onnx_1_10_0(backend_test)
if version.parse(onnx.__version__) >= version.parse("1.11.0"):
disabled_tests_onnx_1_11_0(backend_test)
if version.parse(onnx.__version__) >= version.parse("1.12.0"):
disabled_tests_onnx_1_12_0(backend_test)
if version.parse(onnx.__version__) >= version.parse("1.13.0"):
disabled_tests_onnx_1_13_0(backend_test)
if version.parse(onnx.__version__) >= version.parse("1.14.0"):
disabled_tests_onnx_1_14_0(backend_test)
# import all test cases at global scope to make
# them visible to python.unittest.
......
......@@ -24,7 +24,7 @@
file(GLOB REF CONFIGURE_DEPENDS *.cpp)
add_test_executable(test_ref ${REF})
rocm_add_test_executable(test_ref ${REF})
target_include_directories(test_ref PUBLIC ../include)
rocm_clang_tidy_check(test_ref)
......@@ -24,7 +24,7 @@
#include <migraphx/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment