"example/vscode:/vscode.git/clone" did not exist on "9b7093aac0d93b37691454d5ff632b208e6b953f"
Commit 1d3527d1 authored by Shucai Xiao's avatar Shucai Xiao
Browse files

add an unit test to cover the code change

parent 9b9869c4
......@@ -896,7 +896,7 @@ TEST_CASE(target_copy)
}
}
TEST_CASE(int8_quantization)
TEST_CASE(int8_quantization_dot)
{
auto run_prog = [](migraphx::program p,
const migraphx::target& t,
......@@ -958,4 +958,60 @@ TEST_CASE(int8_quantization)
}
}
TEST_CASE(int8_quantization_conv)
{
auto run_prog = [](migraphx::program p,
const migraphx::target& t,
std::vector<float>& res,
bool b_quantize = false) {
if(b_quantize)
{
std::vector<migraphx::program::parameter_map> cali_data;
migraphx::quantize_int8(p, t, cali_data);
}
p.compile(t);
migraphx::program::parameter_map m;
auto result = t.copy_from(p.eval(m));
result.visit([&](auto v) { res.assign(v.begin(), v.end()); });
};
auto create_program = [] {
migraphx::program p;
migraphx::shape sx{migraphx::shape::float_type, {4, 2, 2, 2}};
migraphx::shape sw{migraphx::shape::float_type, {4, 2, 2, 2}};
std::vector<float> v(sx.elements(), 0.5f);
auto input =
p.add_literal(migraphx::literal(sx, v));
auto weights =
p.add_literal(migraphx::literal(sw, v));
p.add_instruction(migraphx::op::convolution{}, input, weights);
return p;
};
{
auto p = create_program();
std::vector<float> quant_result;
migraphx::target cpu_t = migraphx::cpu::target{};
run_prog(p, cpu_t, quant_result, true);
std::vector<float> no_quant_result;
run_prog(p, cpu_t, no_quant_result);
for (auto v : no_quant_result)
{
std::cout << v << "\t";
}
std::cout << std::endl;
for (auto v : quant_result)
{
std::cout << v << "\t";
}
std::cout << std::endl;
EXPECT(migraphx::verify_range(quant_result, no_quant_result));
}
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
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