Skip to content

Commit

Permalink
Re-write dynamically quantized Conv2D as FC
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 727589025
  • Loading branch information
alankelly authored and xnnpack-bot committed Feb 16, 2025
1 parent dd5f821 commit 846c1af
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/subgraph/convolution-2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ enum xnn_status xnn_define_convolution_2d(
return status;
}

const struct xnn_value* input_value = &subgraph->values[input_id];
struct xnn_value* input_value = &subgraph->values[input_id];
status = xnn_subgraph_check_input_type_dense(xnn_node_type_convolution_2d, input_id, input_value);
if (status != xnn_status_success) {
return status;
Expand Down Expand Up @@ -1299,15 +1299,19 @@ enum xnn_status xnn_define_convolution_2d(
}
}
}
if (input_value->datatype == output_value->datatype) {
const bool unit_subsampling = (subsampling_width | subsampling_height) == 1;
const size_t kernel_size = kernel_height * kernel_width;
if (groups == 1 && kernel_size == 1 && unit_subsampling && !any_padding) {
// Check if the convolution can take the vmulcaddc path.
if (group_input_channels + group_output_channels > 2) {
return xnn_define_fully_connected(subgraph, output_min, output_max,
input_id, filter_id, bias_id, output_id, /*flags=*/0);
const bool unit_subsampling = (subsampling_width | subsampling_height) == 1;
const size_t kernel_size = kernel_height * kernel_width;
if (groups == 1 && kernel_size == 1 && unit_subsampling && !any_padding) {
// Check if the convolution can take the vmulcaddc path.
if (group_input_channels + group_output_channels > 2) {
if (input_value->datatype == xnn_datatype_qdint8) {
// Dynammically quantized tensors for fully connected ops are quantized
// per-channel, not per-batch.
input_value->quantization.num_nonbatch_dims = 1;
input_value->quantization.dynamic_params_size = xnn_tensor_get_dynamic_quant_param_size(input_value);
}
return xnn_define_fully_connected(subgraph, output_min, output_max,
input_id, filter_id, bias_id, output_id, /*flags=*/0);
}
}
struct xnn_node* node = xnn_subgraph_new_node(subgraph);
Expand Down

0 comments on commit 846c1af

Please sign in to comment.