Commit 5f38fd1a authored by Adam Straw's avatar Adam Straw Committed by Scott Cyphers

Adding serializer support for experimental quant ops (#2384)

* Fix inconsistent ifdefs that broke macos build
Add quant ops to op table
Define serialize/deserialize for Quant con, avg pool, max pool
Add empty cases to interpreter

* iGPU cases.

* Include quant ops

* Define ngpu emitters
parent afff7c9b
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
// //
// It's that easy. You can use this for fun and profit. // It's that easy. You can use this for fun and profit.
#ifndef NGRAPH_OP
#error "NGRAPH_OP not defined"
#define NGRAPH_OP(x, y)
#endif
NGRAPH_OP(Abs, ngraph::op) NGRAPH_OP(Abs, ngraph::op)
NGRAPH_OP(Acos, ngraph::op) NGRAPH_OP(Acos, ngraph::op)
NGRAPH_OP(Add, ngraph::op) NGRAPH_OP(Add, ngraph::op)
...@@ -103,6 +108,13 @@ NGRAPH_OP(Parameter, ngraph::op) ...@@ -103,6 +108,13 @@ NGRAPH_OP(Parameter, ngraph::op)
NGRAPH_OP(Power, ngraph::op) NGRAPH_OP(Power, ngraph::op)
NGRAPH_OP(Product, ngraph::op) NGRAPH_OP(Product, ngraph::op)
NGRAPH_OP(Quantize, ngraph::op) NGRAPH_OP(Quantize, ngraph::op)
NGRAPH_OP(QuantizedAvgPool, ngraph::op)
NGRAPH_OP(QuantizedConvolutionBias, ngraph::op)
NGRAPH_OP(QuantizedConvolutionBiasAdd, ngraph::op)
NGRAPH_OP(QuantizedConvolutionBiasSignedAdd, ngraph::op)
NGRAPH_OP(QuantizedConvolutionRelu, ngraph::op)
NGRAPH_OP(QuantizedConvolution, ngraph::op)
NGRAPH_OP(QuantizedMaxPool, ngraph::op)
NGRAPH_OP(Relu, ngraph::op) NGRAPH_OP(Relu, ngraph::op)
NGRAPH_OP(ReluBackprop, ngraph::op) NGRAPH_OP(ReluBackprop, ngraph::op)
NGRAPH_OP(ReplaceSlice, ngraph::op) NGRAPH_OP(ReplaceSlice, ngraph::op)
......
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
#include "ngraph/op/equal.hpp" #include "ngraph/op/equal.hpp"
#include "ngraph/op/exp.hpp" #include "ngraph/op/exp.hpp"
#include "ngraph/op/experimental/generate_mask.hpp" #include "ngraph/op/experimental/generate_mask.hpp"
#include "ngraph/op/experimental/quantized_avg_pool.hpp"
#include "ngraph/op/experimental/quantized_conv.hpp"
#include "ngraph/op/experimental/quantized_conv_bias.hpp"
#include "ngraph/op/experimental/quantized_conv_relu.hpp"
#include "ngraph/op/experimental/quantized_max_pool.hpp"
#include "ngraph/op/experimental/shape_of.hpp" #include "ngraph/op/experimental/shape_of.hpp"
#include "ngraph/op/floor.hpp" #include "ngraph/op/floor.hpp"
#include "ngraph/op/get_output_element.hpp" #include "ngraph/op/get_output_element.hpp"
...@@ -880,6 +885,41 @@ std::string runtime::gpu::GPU_Emitter::emit_Quantize(EMIT_ARGS) ...@@ -880,6 +885,41 @@ std::string runtime::gpu::GPU_Emitter::emit_Quantize(EMIT_ARGS)
throw unsupported_op("Unsupported op '" + node->description() + "'"); throw unsupported_op("Unsupported op '" + node->description() + "'");
} }
std::string runtime::gpu::GPU_Emitter::emit_QuantizedAvgPool(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedConvolution(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedConvolutionBias(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedConvolutionBiasAdd(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedConvolutionBiasSignedAdd(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedConvolutionRelu(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_QuantizedMaxPool(EMIT_ARGS)
{
throw unsupported_op("Unsupported op '" + node->description() + "'");
}
std::string runtime::gpu::GPU_Emitter::emit_Relu(EMIT_ARGS) std::string runtime::gpu::GPU_Emitter::emit_Relu(EMIT_ARGS)
{ {
return emit_elementwise<ngraph::op::Relu>(compiled_function, function_name, node, args, out); return emit_elementwise<ngraph::op::Relu>(compiled_function, function_name, node, args, out);
......
...@@ -1763,6 +1763,13 @@ runtime::Handle runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> ...@@ -1763,6 +1763,13 @@ runtime::Handle runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function>
case OP_TYPEID::BroadcastLike: case OP_TYPEID::BroadcastLike:
case OP_TYPEID::Dequantize: case OP_TYPEID::Dequantize:
case OP_TYPEID::Quantize: case OP_TYPEID::Quantize:
case OP_TYPEID::QuantizedAvgPool:
case OP_TYPEID::QuantizedConvolutionBias:
case OP_TYPEID::QuantizedConvolutionBiasAdd:
case OP_TYPEID::QuantizedConvolutionBiasSignedAdd:
case OP_TYPEID::QuantizedConvolutionRelu:
case OP_TYPEID::QuantizedConvolution:
case OP_TYPEID::QuantizedMaxPool:
case OP_TYPEID::ReplaceSlice: case OP_TYPEID::ReplaceSlice:
case OP_TYPEID::GenerateMask: case OP_TYPEID::GenerateMask:
case OP_TYPEID::ReverseSequence: case OP_TYPEID::ReverseSequence:
......
...@@ -144,8 +144,8 @@ namespace ngraph ...@@ -144,8 +144,8 @@ namespace ngraph
{ {
class INTBackend; class INTBackend;
} }
} } // namespace runtime
} } // namespace ngraph
class ngraph::runtime::interpreter::INTBackend : public Backend class ngraph::runtime::interpreter::INTBackend : public Backend
{ {
...@@ -1016,6 +1016,17 @@ private: ...@@ -1016,6 +1016,17 @@ private:
break; break;
} }
case OP_TYPEID::QuantizedAvgPool:
case OP_TYPEID::QuantizedConvolutionBias:
case OP_TYPEID::QuantizedConvolutionBiasAdd:
case OP_TYPEID::QuantizedConvolutionBiasSignedAdd:
case OP_TYPEID::QuantizedConvolutionRelu:
case OP_TYPEID::QuantizedConvolution:
case OP_TYPEID::QuantizedMaxPool:
{
throw unsupported_op("Unsupported op '" + node.description() +
"' in Interpreter back end.");
}
case OP_TYPEID::Relu: case OP_TYPEID::Relu:
{ {
size_t element_count = shape_size(node.get_output_shape(0)); size_t element_count = shape_size(node.get_output_shape(0));
......
...@@ -48,6 +48,11 @@ ...@@ -48,6 +48,11 @@
#include "ngraph/op/equal.hpp" #include "ngraph/op/equal.hpp"
#include "ngraph/op/exp.hpp" #include "ngraph/op/exp.hpp"
#include "ngraph/op/experimental/generate_mask.hpp" #include "ngraph/op/experimental/generate_mask.hpp"
#include "ngraph/op/experimental/quantized_avg_pool.hpp"
#include "ngraph/op/experimental/quantized_conv.hpp"
#include "ngraph/op/experimental/quantized_conv_bias.hpp"
#include "ngraph/op/experimental/quantized_conv_relu.hpp"
#include "ngraph/op/experimental/quantized_max_pool.hpp"
#include "ngraph/op/experimental/shape_of.hpp" #include "ngraph/op/experimental/shape_of.hpp"
#include "ngraph/op/floor.hpp" #include "ngraph/op/floor.hpp"
#include "ngraph/op/get_output_element.hpp" #include "ngraph/op/get_output_element.hpp"
...@@ -957,6 +962,66 @@ static shared_ptr<ngraph::Function> ...@@ -957,6 +962,66 @@ static shared_ptr<ngraph::Function>
node = make_shared<op::Quantize>(args[0], args[1], args[2], type, axes, round_mode); node = make_shared<op::Quantize>(args[0], args[1], args[2], type, axes, round_mode);
break; break;
} }
case OP_TYPEID::QuantizedAvgPool:
{
auto window_shape = node_js.at("window_shape").get<vector<size_t>>();
auto window_movement_strides =
node_js.at("window_movement_strides").get<vector<size_t>>();
auto padding_below = node_js.at("padding_below").get<vector<size_t>>();
auto padding_above = node_js.at("padding_above").get<vector<size_t>>();
auto include_padding_in_avg_computation =
node_js.at("include_padding_in_avg_computation").get<bool>();
node = make_shared<op::QuantizedAvgPool>(args[0],
window_shape,
window_movement_strides,
padding_below,
padding_above,
include_padding_in_avg_computation);
break;
}
case OP_TYPEID::QuantizedConvolutionBias: { break;
}
case OP_TYPEID::QuantizedConvolutionBiasAdd: { break;
}
case OP_TYPEID::QuantizedConvolutionBiasSignedAdd: { break;
}
case OP_TYPEID::QuantizedConvolutionRelu: { break;
}
case OP_TYPEID::QuantizedConvolution:
{
auto window_movement_strides =
node_js.at("window_movement_strides").get<vector<size_t>>();
auto window_dilation_strides =
node_js.at("window_dilation_strides").get<vector<size_t>>();
auto padding_below = node_js.at("padding_below").get<vector<std::ptrdiff_t>>();
auto padding_above = node_js.at("padding_above").get<vector<std::ptrdiff_t>>();
auto data_dilation_strides = node_js["data_dilation_strides"];
node =
make_shared<op::Convolution>(args[0],
args[1],
window_movement_strides,
window_dilation_strides,
padding_below,
padding_above,
data_dilation_strides.get<std::vector<size_t>>());
break;
}
case OP_TYPEID::QuantizedMaxPool:
{
auto window_shape = node_js.at("window_shape").get<vector<size_t>>();
auto window_movement_strides =
node_js.at("window_movement_strides").get<vector<size_t>>();
// For backwards compatibility, both (but not just one) of the padding_ fields may be
// omitted.
auto padding_below_maybe = node_js["padding_below"];
auto padding_above_maybe = node_js["padding_above"];
auto padding_below = padding_below_maybe.get<vector<size_t>>();
auto padding_above = padding_above_maybe.get<vector<size_t>>();
node = make_shared<op::QuantizedMaxPool>(
args[0], window_shape, window_movement_strides, padding_below, padding_above);
break;
}
case OP_TYPEID::Relu: case OP_TYPEID::Relu:
{ {
node = make_shared<op::Relu>(args[0]); node = make_shared<op::Relu>(args[0]);
...@@ -1507,6 +1572,43 @@ static json write(const Node& n, bool binary_constant_data) ...@@ -1507,6 +1572,43 @@ static json write(const Node& n, bool binary_constant_data)
node["round_mode"] = tmp->get_round_mode(); node["round_mode"] = tmp->get_round_mode();
break; break;
} }
case OP_TYPEID::QuantizedAvgPool:
{
auto tmp = dynamic_cast<const op::QuantizedAvgPool*>(&n);
node["window_shape"] = tmp->get_window_shape();
node["window_movement_strides"] = tmp->get_window_movement_strides();
node["padding_below"] = tmp->get_padding_below();
node["padding_above"] = tmp->get_padding_above();
node["include_padding_in_avg_computation"] = tmp->get_include_padding_in_avg_computation();
break;
}
case OP_TYPEID::QuantizedConvolutionBias: { break;
}
case OP_TYPEID::QuantizedConvolutionBiasAdd: { break;
}
case OP_TYPEID::QuantizedConvolutionBiasSignedAdd: { break;
}
case OP_TYPEID::QuantizedConvolutionRelu: { break;
}
case OP_TYPEID::QuantizedConvolution:
{
auto tmp = dynamic_cast<const op::QuantizedConvolution*>(&n);
node["window_movement_strides"] = tmp->get_window_movement_strides();
node["window_dilation_strides"] = tmp->get_window_dilation_strides();
node["padding_below"] = tmp->get_padding_below();
node["padding_above"] = tmp->get_padding_above();
node["data_dilation_strides"] = tmp->get_data_dilation_strides();
break;
}
case OP_TYPEID::QuantizedMaxPool:
{
auto tmp = dynamic_cast<const op::QuantizedMaxPool*>(&n);
node["window_shape"] = tmp->get_window_shape();
node["window_movement_strides"] = tmp->get_window_movement_strides();
node["padding_below"] = tmp->get_padding_below();
node["padding_above"] = tmp->get_padding_above();
break;
}
case OP_TYPEID::Relu: { break; case OP_TYPEID::Relu: { break;
} }
case OP_TYPEID::ReluBackprop: { break; case OP_TYPEID::ReluBackprop: { break;
......
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