Commit 350bbea2 authored by Umang Yadav's avatar Umang Yadav
Browse files

Merge branch 'develop' into resnet50_partition

parents 848a476d 74ba9649
......@@ -112,7 +112,10 @@ TEST_CASE_REGISTER(test_limits<double, int>);
TEST_CASE_REGISTER(test_limits<double, migraphx::half>);
TEST_CASE_REGISTER(test_limits<float, int>);
TEST_CASE_REGISTER(test_limits<int, migraphx::half>);
#ifndef _WIN32
// On Windows, types int and long have the same min and max values.
TEST_CASE_REGISTER(test_limits<long, int>);
#endif
TEST_CASE_REGISTER(test_limits<long, char>);
int main(int argc, const char* argv[]) { test::run(argc, argv); }
......@@ -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); }
a476dbf430ac8315550474a78d47bf182f202d7c
ae74a517b62baa6d973e46b5b51ac9a640512c46
......@@ -82,6 +82,33 @@ void throws_shape(const migraphx::shape&, Ts...)
"An expected shape should not be passed to throws_shape function");
}
TEST_CASE(allocate_static)
{
migraphx::shape out_shape{migraphx::shape::float_type, {2, 3, 4}};
expect_shape(out_shape, migraphx::make_op("allocate", {{"shape", to_value(out_shape)}}));
}
TEST_CASE(allocate_dyn)
{
migraphx::shape input{migraphx::shape::int64_type, {2}};
auto max_val = std::numeric_limits<std::size_t>::max();
std::vector<migraphx::shape::dynamic_dimension> dyn_dims(
2, migraphx::shape::dynamic_dimension{0, max_val});
expect_shape(migraphx::shape{migraphx::shape::float_type, dyn_dims},
migraphx::make_op("allocate", {{"buf_type", migraphx::shape::float_type}}),
input);
}
TEST_CASE(allocate_dyn_with_shape_attr)
{
migraphx::shape input{migraphx::shape::int64_type, {4}};
migraphx::shape shape_attr{migraphx::shape::float_type,
{{1, 4}, {3, 3}, {4, 8, {4, 6}}, {4, 8}, {4, 6}}};
expect_shape(shape_attr,
migraphx::make_op("allocate", {{"shape", migraphx::to_value(shape_attr)}}),
input);
}
TEST_CASE(argmax_axis0)
{
migraphx::shape input{migraphx::shape::half_type, {2, 3, 4, 5}};
......@@ -2233,6 +2260,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/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <test.hpp>
TEST_CASE(allocate_dyn)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int64_type, {4}};
auto out_dims = mm->add_parameter("out_dims", s);
mm->add_instruction(migraphx::make_op("allocate", {{"buf_type", migraphx::shape::float_type}}),
out_dims);
p.compile(migraphx::make_target("ref"));
migraphx::parameter_map params;
std::vector<int64_t> data = {2, 3, 4, 4};
params["out_dims"] = migraphx::argument(s, data.data());
auto result = p.eval(params).back();
migraphx::shape sresult{migraphx::shape::float_type, {2, 3, 4, 4}};
result.visit([&](auto output) { EXPECT(output.get_shape() == sresult); });
}
/*
* 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/instruction.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <random>
#include <test.hpp>
/**
* Reference test for the random_seed operation
*/
TEST_CASE(random_seed_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_instruction(migraphx::make_op("random_seed"));
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<uint64_t> result_vec1(1);
result.visit([&](auto output) { result_vec1.assign(output.begin(), output.end()); });
std::vector<uint64_t> result_vec2(1);
// Identical calls should give different seeds every time with 1/(2^64) chance of a repeat.
// We don't analyze for true randomness.
result = p.eval({}).back();
result.visit([&](auto output) { result_vec2.assign(output.begin(), output.end()); });
EXPECT(result_vec1[0] != result_vec2[0]);
}
/*
* 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/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <random>
#include <test.hpp>
/**
* Reference test for the random_uniform operation. Also invokes the random_seed operation.
*/
TEST_CASE(random_uniform_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
uint64_t seed(0);
size_t sample_size(200);
// Shape of the random data
migraphx::shape rs{migraphx::shape::float_type, {1, sample_size}};
// data tensor must be allocated at this point but does not need to be initialized.
std::vector<float> data(sample_size);
auto input = mm->add_literal(migraphx::literal(rs, data));
// Runtime randomization seed
migraphx::shape seed_shape{migraphx::shape::uint64_type, {1}};
std::vector<uint64_t> seed_data{seed};
auto seed_input = mm->add_literal(migraphx::literal(seed_shape, seed_data));
mm->add_instruction(migraphx::make_op("random_uniform"), seed_input, input);
p.compile(migraphx::make_target("ref"));
// no params_map needed
auto result = p.eval({}).back();
std::vector<float> result_vec(sample_size);
result.visit([&](auto output) { result_vec.assign(output.begin(), output.end()); });
// Compare result with the STL's mt19937 generator
std::mt19937 gen(seed);
std::uniform_real_distribution<> dis(0.0, 1.0);
std::vector<float> rand_samples(sample_size);
std::generate(rand_samples.begin(), rand_samples.end(), [&]() { return dis(gen); });
EXPECT(migraphx::verify::verify_range(result_vec, rand_samples, 100));
}
TEST_CASE(random_uniform_int_test)
{
// random uniform distribution with an integer type input shape
migraphx::program p;
auto* mm = p.get_main_module();
float seed(0.1);
size_t sample_size(200);
// Shape of the random data
migraphx::shape rs{migraphx::shape::uint16_type, {1, sample_size}};
// data tensor must be allocated at this point but does not need to be initialized.
std::vector<uint16_t> data(sample_size);
auto input = mm->add_literal(migraphx::literal(rs, data));
// Runtime randomization seed
migraphx::shape seed_shape{migraphx::shape::float_type, {1}};
std::vector<float> seed_data{seed};
auto seed_input = mm->add_literal(migraphx::literal(seed_shape, seed_data));
mm->add_instruction(migraphx::make_op("random_uniform"), seed_input, input);
p.compile(migraphx::make_target("ref"));
migraphx::parameter_map params0;
auto result = p.eval(params0).back();
std::vector<uint16_t> result_vec(sample_size);
result.visit([&](auto output) { result_vec.assign(output.begin(), output.end()); });
// Compare result with the STL's mt19937 generator
std::mt19937 gen(seed);
std::uniform_int_distribution<uint16_t> dis;
std::vector<uint16_t> rand_samples(sample_size);
std::generate(rand_samples.begin(), rand_samples.end(), [&]() { return dis(gen); });
EXPECT(migraphx::verify::verify_range(result_vec, rand_samples));
}
TEST_CASE(random_uniform_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
uint64_t seed(17);
size_t sample_size(200);
// Shape of the random data
migraphx::shape rs{migraphx::shape::float_type, {{1, 2}, {2, sample_size + 1}}};
auto input = mm->add_parameter("Input_1", rs);
// Runtime randomization seed
migraphx::shape seed_shape{migraphx::shape::uint64_type, {1}};
auto seed_input = mm->add_parameter("Seed", seed_shape);
mm->add_instruction(migraphx::make_op("random_uniform", {}), seed_input, input);
p.compile(migraphx::make_target("ref"));
// Create a dummy input to hold the random data
migraphx::shape input_fixed_shape1{migraphx::shape::float_type, {sample_size}};
migraphx::parameter_map params0;
params0["Input_1"] = migraphx::argument(input_fixed_shape1);
std::vector<uint64_t> seed_data = {seed};
params0["Seed"] = migraphx::argument(seed_shape, seed_data.data());
auto result = p.eval(params0).back();
std::vector<float> result_vec(sample_size);
result.visit([&](auto output) { result_vec.assign(output.begin(), output.end()); });
// Compare result with the STL's mt19937 generator
std::mt19937 gen(seed);
std::uniform_real_distribution<> dis(0.0, 1.0);
std::vector<float> rand_samples(sample_size);
std::generate(rand_samples.begin(), rand_samples.end(), [&]() { return dis(gen); });
EXPECT(migraphx::verify::verify_range(result_vec, rand_samples));
}
TEST_CASE(random_uniform_and_seed_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
size_t sample_size(20000);
// Shape of the random data
migraphx::shape rs{migraphx::shape::float_type, {{1, 2}, {2, sample_size + 1}}};
auto input = mm->add_parameter("Input_1", rs);
// Runtime randomization seed
auto seed_input = mm->add_instruction(migraphx::make_op("random_seed"));
mm->add_instruction(migraphx::make_op("random_uniform"), seed_input, input);
p.compile(migraphx::make_target("ref"));
// Create a dummy input to hold the random data
migraphx::shape input_fixed_shape1{migraphx::shape::float_type, {sample_size}};
migraphx::parameter_map params0;
params0["Input_1"] = migraphx::argument(input_fixed_shape1);
auto result = p.eval(params0).back();
result.visit([&](auto output) { EXPECT(output.size() == sample_size); });
// Do not check the content of the data since it's not repeatable
}
......@@ -99,4 +99,29 @@ TEST_CASE(interpolate_string_custom3)
EXPECT(s == "****b****");
}
TEST_CASE(slit_string_simple1)
{
std::string input = "one,two,three";
auto resuts = migraphx::split_string(input, ',');
EXPECT(resuts.size() == 3);
EXPECT(resuts.front() == "one");
EXPECT(resuts.back() == "three");
}
TEST_CASE(slit_string_simple2)
{
std::string input = "one";
auto resuts = migraphx::split_string(input, ',');
EXPECT(resuts.size() == 1);
EXPECT(resuts.front() == "one");
}
TEST_CASE(slit_string_simple3)
{
std::string input = "one two three";
auto resuts = migraphx::split_string(input, ',');
EXPECT(resuts.size() == 1);
EXPECT(resuts.front() == "one two three");
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
......@@ -39,6 +39,15 @@ def parse_args():
type=str,
default='gpu',
help='Specify where the tests execute (ref, gpu)')
parser.add_argument('--fp16', action='store_true', help='Quantize to fp16')
parser.add_argument('--atol',
type=float,
default=1e-3,
help='The absolute tolerance parameter')
parser.add_argument('--rtol',
type=float,
default=1e-3,
help='The relative tolerance parameter')
args = parser.parse_args()
return args
......@@ -257,6 +266,8 @@ def main():
# read and compile model
model = migraphx.parse_onnx(model_path_name, map_input_dims=param_shapes)
if args.fp16:
migraphx.quantize_fp16(model)
model.compile(migraphx.get_target(target))
# get test cases
......@@ -279,7 +290,10 @@ def main():
output_data = run_one_case(model, input_data)
# check output correctness
ret = check_correctness(gold_outputs, output_data)
ret = check_correctness(gold_outputs,
output_data,
atol=args.atol,
rtol=args.rtol)
if ret:
correct_num += 1
......
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