From 5153fe4b989768907ed588ecdb859d6a81b72992 Mon Sep 17 00:00:00 2001 From: Gunes Bayir Date: Thu, 6 Jul 2023 15:51:12 +0100 Subject: Fix unsupported configuration in CLFullyConnected validation When the weights to CLFullyConnected layer are not constant and the weights need reshaping, we prefer MatMul kernels instead of Gemm-based ones. The bias addition is currently unsupported in MatMull, but the validate() function does not account for this properly. This patch fixes the validation of this function. Resolves: COMPMID-6338 Change-Id: I5c240191ae8e369753691c43ab4a30d4ae1776b0 Signed-off-by: Gunes Bayir Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9882 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Viet-Hoa Do Comments-Addressed: Arm Jenkins --- src/gpu/cl/operators/ClFullyConnected.cpp | 6 +++--- src/gpu/cl/operators/ClFullyConnected.h | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gpu/cl/operators/ClFullyConnected.cpp b/src/gpu/cl/operators/ClFullyConnected.cpp index c62e4b531f..b7ba8b89fa 100644 --- a/src/gpu/cl/operators/ClFullyConnected.cpp +++ b/src/gpu/cl/operators/ClFullyConnected.cpp @@ -115,7 +115,7 @@ Status validate_mm(const ITensorInfo &src, const ITensorInfo &weights, const ITe { // If weights are dynamic, data is not batched, and bias is nullptr validate using matmul. const bool weights_reshaped = fc_info.transpose_weights ? fc_info.are_weights_reshaped : true; - const bool use_matmul = !weights.are_values_constant() && !weights_reshaped && !(dst.dimension(1) > 1) && (bias != nullptr); + const bool use_matmul = !weights.are_values_constant() && !weights_reshaped && !(dst.dimension(1) > 1) && (bias == nullptr); if(use_matmul) { @@ -317,7 +317,7 @@ void ClFullyConnected::configure(const CLCompileContext &compile_context, ITenso // Note: No matmul with biases for the moment. const bool is_batched_fc_layer = dst->dimension(1) > 1; _dynamic_weights = !weights->are_values_constant() && !_are_weights_reshaped; - _use_matmul = _dynamic_weights && !is_batched_fc_layer && !(biases); + _use_matmul = _dynamic_weights && !is_batched_fc_layer && (biases == nullptr); // With the Fully Connected layer we can have 4 different cases: // 1) Convolution layer -> Fully Connected layer without batches @@ -442,7 +442,7 @@ Status ClFullyConnected::validate(const ITensorInfo *src, const ITensorInfo *wei // Note: Pre-Shaped RHS is a deprecated use case and is therefore not supported with matmul. const bool dynamic_weights = !weights->are_values_constant() && !weights_reshaped; const bool is_batched_fc_layer = dst->dimension(1) > 1; - const bool use_matmul = dynamic_weights && !is_batched_fc_layer && (biases != nullptr); + const bool use_matmul = dynamic_weights && !is_batched_fc_layer && (biases == nullptr); const ITensorInfo &flatten_src = TensorInfo(src->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(compute_flatten_shape(src)).set_data_layout(DataLayout::NCHW)); const ITensorInfo &reshaped_weights = TensorInfo(weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(compute_transposed_shape(*weights))); diff --git a/src/gpu/cl/operators/ClFullyConnected.h b/src/gpu/cl/operators/ClFullyConnected.h index 5dc68c1bbe..9a5ba40510 100644 --- a/src/gpu/cl/operators/ClFullyConnected.h +++ b/src/gpu/cl/operators/ClFullyConnected.h @@ -132,11 +132,7 @@ private: TensorInfo _flattened_src{}; TensorInfo _converted_weights{}; TensorInfo _reshaped_weights{}; - - // Saved tensor shapes for reshaping when using matmul - TensorShape _lhs_shape_original{}; TensorInfo _lhs_to_use{}; - TensorInfo _weights_to_use{}; int _weights_to_use_idx{ ACL_SRC_1 }; -- cgit v1.2.1