Commit b9d37172 authored by Khalique Ahmed's avatar Khalique Ahmed
Browse files

manual merge

parents 1af66a1c ea62d7aa
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <migraphx/gpu/fuse_mlir.hpp> #include <migraphx/gpu/fuse_mlir.hpp>
#include <migraphx/operators.hpp> #include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
#include <migraphx/quantization.hpp> #include <migraphx/quantization.hpp>
#include <migraphx/generate.hpp> #include <migraphx/generate.hpp>
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
TEST_CASE(gpu_target_copy) TEST_CASE(gpu_target_copy)
{ {
migraphx::target gpu_t = migraphx::make_target("gpu"); migraphx::target gpu_t = migraphx::make_target("gpu");
migraphx::target ref_t = migraphx::make_target("ref");
migraphx::shape s{migraphx::shape::int8_type, {2, 3, 4, 5}}; migraphx::shape s{migraphx::shape::int8_type, {2, 3, 4, 5}};
auto ref_arg_orig = migraphx::generate_argument(s, 0x123456L); auto ref_arg_orig = migraphx::generate_argument(s, 0x123456L);
...@@ -52,7 +51,7 @@ TEST_CASE(gpu_target_copy) ...@@ -52,7 +51,7 @@ TEST_CASE(gpu_target_copy)
std::vector<int8_t> val_final; std::vector<int8_t> val_final;
ref_arg_final.visit([&](auto v) { val_final.assign(v.begin(), v.end()); }); ref_arg_final.visit([&](auto v) { val_final.assign(v.begin(), v.end()); });
EXPECT(migraphx::verify::verify_range(val_orig, val_final)); EXPECT(migraphx::verify::verify_rms_range(val_orig, val_final));
} }
TEST_CASE(int8_quantization) TEST_CASE(int8_quantization)
...@@ -90,7 +89,7 @@ TEST_CASE(int8_quantization) ...@@ -90,7 +89,7 @@ TEST_CASE(int8_quantization)
migraphx::shape sc{migraphx::shape::float_type, {5, 8}}; migraphx::shape sc{migraphx::shape::float_type, {5, 8}};
auto pa = mm->add_parameter("a", sa); auto pa = mm->add_parameter("a", sa);
auto pb = mm->add_parameter("b", sb); auto pb = mm->add_parameter("b", sb);
mm->add_instruction(migraphx::op::dot{}, pa, pb); mm->add_instruction(migraphx::make_op("dot"), pa, pb);
return p; return p;
}; };
...@@ -118,9 +117,12 @@ TEST_CASE(int8_quantization) ...@@ -118,9 +117,12 @@ TEST_CASE(int8_quantization)
// the regular pipeline uses the rewrite_quantization in the much // the regular pipeline uses the rewrite_quantization in the much
// earlier stage. // earlier stage.
if(migraphx::gpu::mlir_enabled()) if(migraphx::gpu::mlir_enabled())
EXPECT(migraphx::verify::verify_range(ref_result, gpu_result, 1e5)); EXPECT(migraphx::verify::verify_range_with_tolerance(
gpu_result,
migraphx::verify::expected{ref_result},
migraphx::verify::tolerance{0.01}));
else else
EXPECT(migraphx::verify::verify_range(ref_result, gpu_result)); EXPECT(migraphx::verify::verify_rms_range(gpu_result, ref_result));
} }
} }
......
...@@ -24,16 +24,16 @@ ...@@ -24,16 +24,16 @@
#ifndef MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP #ifndef MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP
#define MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP #define MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP
#include <migraphx/instruction_ref.hpp>
#include <migraphx/program.hpp> #include <migraphx/program.hpp>
#include <migraphx/module.hpp> #include <migraphx/module.hpp>
#include <migraphx/make_op.hpp> #include <migraphx/make_op.hpp>
template <class F> template <class F>
migraphx::instruction_ref add_pointwise(migraphx::program& p, migraphx::module_ref create_pointwise_module(migraphx::program& p,
migraphx::module_ref mm, const std::string& name,
const std::string& name, std::vector<migraphx::instruction_ref> inputs,
std::vector<migraphx::instruction_ref> inputs, F f)
F f)
{ {
auto* pm = p.create_module(name); auto* pm = p.create_module(name);
pm->set_bypass(); pm->set_bypass();
...@@ -44,6 +44,17 @@ migraphx::instruction_ref add_pointwise(migraphx::program& p, ...@@ -44,6 +44,17 @@ migraphx::instruction_ref add_pointwise(migraphx::program& p,
}); });
auto r = f(pm, params); auto r = f(pm, params);
pm->add_return({r}); pm->add_return({r});
return pm;
}
template <class F>
migraphx::instruction_ref add_pointwise(migraphx::program& p,
migraphx::module_ref mm,
const std::string& name,
std::vector<migraphx::instruction_ref> inputs,
F f)
{
auto* pm = create_pointwise_module(p, name, inputs, f);
return mm->add_instruction(migraphx::make_op("pointwise"), inputs, {pm}); return mm->add_instruction(migraphx::make_op("pointwise"), inputs, {pm});
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <atomic>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
...@@ -342,11 +343,19 @@ inline std::ostream& operator<<(std::ostream& os, const color& c) ...@@ -342,11 +343,19 @@ inline std::ostream& operator<<(std::ostream& os, const color& c)
return os; return os;
} }
inline std::atomic<int>& failures()
{
// NOLINTNEXTLINE
static std::atomic<int> f = 0;
return f;
}
template <class T, class F> template <class T, class F>
void failed(T x, const char* msg, const char* func, const char* file, int line, F f) void failed(T x, const char* msg, const char* func, const char* file, int line, F f)
{ {
if(not bool(x.value())) if(not bool(x.value()))
{ {
failures()++;
std::cout << func << std::endl; std::cout << func << std::endl;
std::cout << file << ":" << line << ":" << std::endl; std::cout << file << ":" << line << ":" << std::endl;
std::cout << color::bold << color::fg_red << " FAILED: " << color::reset << msg << " " std::cout << color::bold << color::fg_red << " FAILED: " << color::reset << msg << " "
...@@ -586,13 +595,21 @@ struct driver ...@@ -586,13 +595,21 @@ struct driver
{ {
try try
{ {
failures() = 0;
f(); f();
} }
// cppcheck-suppress EmptyCatchStatement
catch(const failure_error&) catch(const failure_error&)
{ {
msg = "Test failure";
} }
} }
if(msg.empty() and failures() != 0)
{
if(failures() == 1)
msg = "Test failure";
else
msg = std::to_string(failures()) + " test failures";
}
if(msg.empty()) if(msg.empty())
{ {
out() << color::fg_green << "[ COMPLETE ] " << color::reset << color::bold << name out() << color::fg_green << "[ COMPLETE ] " << color::reset << color::bold << name
...@@ -683,10 +700,10 @@ inline void run(int argc, const char* argv[]) ...@@ -683,10 +700,10 @@ inline void run(int argc, const char* argv[])
#define TEST_CAPTURE(...) test::capture{}->*__VA_ARGS__ #define TEST_CAPTURE(...) test::capture{}->*__VA_ARGS__
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define CHECK(...) \ #define CHECK(...) \
test::failed( \ test::failed( \
test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __PRETTY_FUNCTION__, __FILE__, __LINE__, [] { \ TEST_CAPTURE(__VA_ARGS__), #__VA_ARGS__, __PRETTY_FUNCTION__, __FILE__, __LINE__, [] {})
})
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define EXPECT(...) \ #define EXPECT(...) \
test::failed(TEST_CAPTURE(__VA_ARGS__), \ test::failed(TEST_CAPTURE(__VA_ARGS__), \
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <migraphx/pass_manager.hpp> #include <migraphx/pass_manager.hpp>
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
#include <basic_ops.hpp> #include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp> #include <migraphx/make_op.hpp>
#include <test.hpp> #include <test.hpp>
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#include <migraphx/insert_pad.hpp> #include <migraphx/insert_pad.hpp>
#include <migraphx/pass_manager.hpp> #include <migraphx/pass_manager.hpp>
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
#include <migraphx/op/common.hpp>
#include <basic_ops.hpp> #include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp> #include <migraphx/make_op.hpp>
#include <test.hpp> #include <test.hpp>
...@@ -58,10 +58,11 @@ create_conv(migraphx::instruction_ref& l_img, ...@@ -58,10 +58,11 @@ create_conv(migraphx::instruction_ref& l_img,
migraphx::shape s_weights{migraphx::shape::int32_type, {4, channels, 3, 3}}; migraphx::shape s_weights{migraphx::shape::int32_type, {4, channels, 3, 3}};
std::vector<int32_t> weights(4 * channels * 3 * 3); std::vector<int32_t> weights(4 * channels * 3 * 3);
auto l_weights = m.add_literal(migraphx::literal{s_weights, weights}); auto l_weights = m.add_literal(migraphx::literal{s_weights, weights});
migraphx::op::convolution op; return m.add_instruction(
op.padding_mode = padding_mode; migraphx::make_op("convolution",
op.padding = {0, 0, 1, 1}; {{"padding_mode", padding_mode}, {"padding", {0, 0, 1, 1}}}),
return m.add_instruction(op, l_img, l_weights); l_img,
l_weights);
} }
TEST_CASE(rewrite_pad) TEST_CASE(rewrite_pad)
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <migraphx/layout_nhwc.hpp> #include <migraphx/layout_nhwc.hpp>
#include <migraphx/dead_code_elimination.hpp> #include <migraphx/dead_code_elimination.hpp>
#include <migraphx/pass_manager.hpp> #include <migraphx/pass_manager.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp> #include <migraphx/generate.hpp>
#include <migraphx/ranges.hpp> #include <migraphx/ranges.hpp>
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
......
...@@ -89,17 +89,13 @@ bool is_overlap_load(migraphx::instruction_ref a, migraphx::instruction_ref b) ...@@ -89,17 +89,13 @@ bool is_overlap_load(migraphx::instruction_ref a, migraphx::instruction_ref b)
bool is_disjoint(const std::vector<migraphx::instruction_ref>& inss) bool is_disjoint(const std::vector<migraphx::instruction_ref>& inss)
{ {
for(auto ins1 : inss) return std::none_of(inss.begin(), inss.end(), [&](auto ins1) {
{ return std::none_of(inss.begin(), inss.end(), [&](auto ins2) {
for(auto ins2 : inss)
{
if(ins1 == ins2) if(ins1 == ins2)
continue; return true;
if(is_overlap_load(ins1, ins2)) return is_overlap_load(ins1, ins2);
return false; });
} });
}
return true;
} }
TEST_CASE(test1) TEST_CASE(test1)
......
...@@ -25,13 +25,37 @@ ...@@ -25,13 +25,37 @@
#include <migraphx/value.hpp> #include <migraphx/value.hpp>
#include <msgpack.hpp> #include <msgpack.hpp>
#include <map> #include <map>
#include <numeric>
#include "test.hpp" #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> template <class T>
std::vector<char> msgpack_buffer(const T& src) std::vector<char> msgpack_buffer(const T& src)
{ {
std::stringstream buffer; std::stringstream buffer;
msgpack::pack(buffer, src); write_msgpack(buffer, src);
buffer.seekg(0); buffer.seekg(0);
std::string str = buffer.str(); std::string str = buffer.str();
return std::vector<char>(str.data(), str.data() + str.size()); // NOLINT return std::vector<char>(str.data(), str.data() + str.size()); // NOLINT
...@@ -147,4 +171,51 @@ TEST_CASE(test_msgpack_array_class) ...@@ -147,4 +171,51 @@ TEST_CASE(test_msgpack_array_class)
EXPECT(migraphx::from_msgpack(buffer) == v); 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); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
21a71d52bd2074b770807b209939ec11e2c64fa7 6d7bc2a097a1a08541cd0d4628831c79ab8092d5
 castlike_error_test:M

0out"CastLikecastlike_error_testZ
0



b
out


B
\ No newline at end of file
  castlike_test:[

0
1out"CastLike castlike_testZ
0



Z
1


b
out


B
\ No newline at end of file
const_of_shape_default_test:
6shape"Constant*#
value*:B shape_tensor

shapey"ConstantOfShapeconst_of_shape_default_testb
y



B
\ No newline at end of file
const_of_shape_dyn_int64_test:
=
output_dimsy"ConstantOfShape*
value*:
Bvalueconst_of_shape_dyn_int64_testZ
output_dims

b
y



B
\ No newline at end of file
constant-of-shape: const_of_shape_int64_test:
6shape"Constant*# 6shape"Constant*#
value**B shape_tensor  value*:B shape_tensor
7 7
shapey"ConstantOfShape* shapey"ConstantOfShape*
value*: value*:
Bvalue constant_of_shapeb Bvalueconst_of_shape_int64_testb
y y
 
 
 
B B
\ No newline at end of file
constant-of-shape: !const_of_shape_no_value_attr_test:
6shape"Constant*# 6shape"Constant*#
value**B shape_tensor  value*:B shape_tensor
 
shapey"ConstantOfShapeconstant_of_shapeb shapey"ConstantOfShape!const_of_shape_no_value_attr_testb
y y
 
 
 
B B
\ No newline at end of file
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