Commit 8d32c6b8 authored by Paul's avatar Paul
Browse files

Merge branch 'develop' into blas_tuning

parents 23cb7917 f25606f9
......@@ -64,7 +64,7 @@ int main() {}
migraphx::src_file make_src_file(const std::string& name, const std::string& content)
{
return {name, std::make_pair(content.data(), content.data() + content.size())};
return {name, content};
}
hip_stream_ptr get_stream()
......
......@@ -24,16 +24,16 @@
#ifndef MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP
#define MIGRAPHX_GUARD_TEST_INCLUDE_POINTWISE_HPP
#include <migraphx/instruction_ref.hpp>
#include <migraphx/program.hpp>
#include <migraphx/module.hpp>
#include <migraphx/make_op.hpp>
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)
migraphx::module_ref create_pointwise_module(migraphx::program& p,
const std::string& name,
std::vector<migraphx::instruction_ref> inputs,
F f)
{
auto* pm = p.create_module(name);
pm->set_bypass();
......@@ -44,6 +44,17 @@ migraphx::instruction_ref add_pointwise(migraphx::program& p,
});
auto r = f(pm, params);
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});
}
......
......@@ -339,6 +339,8 @@ inline std::ostream& operator<<(std::ostream& os, const color& c)
static const bool use_color = isatty(STDOUT_FILENO) != 0;
if(use_color)
return os << "\033[" << static_cast<std::size_t>(c) << "m";
#else
(void)c;
#endif
return os;
}
......
......@@ -26,7 +26,6 @@
#include <migraphx/pass_manager.hpp>
#include <migraphx/instruction.hpp>
#include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
#include <test.hpp>
......
......@@ -26,8 +26,8 @@
#include <migraphx/insert_pad.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/op/common.hpp>
#include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
#include <test.hpp>
......@@ -58,10 +58,11 @@ create_conv(migraphx::instruction_ref& l_img,
migraphx::shape s_weights{migraphx::shape::int32_type, {4, channels, 3, 3}};
std::vector<int32_t> weights(4 * channels * 3 * 3);
auto l_weights = m.add_literal(migraphx::literal{s_weights, weights});
migraphx::op::convolution op;
op.padding_mode = padding_mode;
op.padding = {0, 0, 1, 1};
return m.add_instruction(op, l_img, l_weights);
return m.add_instruction(
migraphx::make_op("convolution",
{{"padding_mode", padding_mode}, {"padding", {0, 0, 1, 1}}}),
l_img,
l_weights);
}
TEST_CASE(rewrite_pad)
......
......@@ -48,9 +48,7 @@ compile_function(const std::string& src, const std::string& flags, const std::st
migraphx::src_compiler compiler;
compiler.flags = flags + "-std=c++14 -fPIC -shared";
compiler.output = "libsimple.so";
migraphx::src_file f;
f.path = "main.cpp";
f.content = std::make_pair(src.data(), src.data() + src.size());
migraphx::src_file f{"main.cpp", src};
auto image = compiler.compile({f});
return migraphx::dynamic_loader{image}.get_function<F>(fname);
}
......
......@@ -24,7 +24,6 @@
#include <migraphx/layout_nhwc.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/instruction.hpp>
......
......@@ -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
......@@ -73,9 +97,12 @@ TEST_CASE(test_msgpack_bool)
TEST_CASE(test_msgpack_float)
{
migraphx::value v = 3.0;
// changed all double values in this code to not end with .0 because on msgpack for Windows if
// input type is double and ends with .0 it could be converted to uint64_t or int64_t and the
// goal of these functions is to test double without conversions
migraphx::value v = 3.01;
auto buffer = migraphx::to_msgpack(v);
EXPECT(buffer == msgpack_buffer(3.0));
EXPECT(buffer == msgpack_buffer(3.01));
EXPECT(migraphx::from_msgpack(buffer) == v);
}
......@@ -105,10 +132,10 @@ TEST_CASE(test_msgpack_empty_array)
TEST_CASE(test_msgpack_object)
{
migraphx::value v = {{"one", 1.0}, {"three", 3.0}, {"two", 2.0}};
migraphx::value v = {{"one", 1.01}, {"three", 3.01}, {"two", 2.01}};
auto buffer = migraphx::to_msgpack(v);
EXPECT(buffer == msgpack_buffer(std::map<std::string, double>{
{"one", 1.0}, {"three", 3.0}, {"two", 2.0}}));
{"one", 1.01}, {"three", 3.01}, {"two", 2.01}}));
EXPECT(migraphx::from_msgpack(buffer) == v);
}
......@@ -133,18 +160,65 @@ struct foo
TEST_CASE(test_msgpack_object_class)
{
migraphx::value v = {{"a", 1.0}, {"b", "abc"}};
migraphx::value v = {{"a", 1.01}, {"b", "abc"}};
auto buffer = migraphx::to_msgpack(v);
EXPECT(buffer == msgpack_buffer(foo{1.0, "abc"}));
EXPECT(buffer == msgpack_buffer(foo{1.01, "abc"}));
EXPECT(migraphx::from_msgpack(buffer) == v);
}
TEST_CASE(test_msgpack_array_class)
{
migraphx::value v = {{{"a", 1.0}, {"b", "abc"}}, {{"a", 3.0}, {"b", "xyz"}}};
migraphx::value v = {{{"a", 1.01}, {"b", "abc"}}, {{"a", 3.01}, {"b", "xyz"}}};
auto buffer = migraphx::to_msgpack(v);
EXPECT(buffer == msgpack_buffer(std::vector<foo>{foo{1.0, "abc"}, foo{3.0, "xyz"}}));
EXPECT(buffer == msgpack_buffer(std::vector<foo>{foo{1.01, "abc"}, foo{3.01, "xyz"}}));
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); }
......@@ -37,7 +37,6 @@
#include <migraphx/make_op.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/functional.hpp>
#include <basic_ops.hpp>
#include <migraphx/compile_options.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/generate.hpp>
......
e5bb7aba502f5a8783de945258d226c092c14386
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*#
value**B shape_tensor 
value*:B shape_tensor
7
shapey"ConstantOfShape*
value*:
Bvalue constant_of_shapeb
Bvalueconst_of_shape_int64_testb
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