aboutsummaryrefslogtreecommitdiff
path: root/src/dynamic_fusion/sketch/gpu/operators/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/dynamic_fusion/sketch/gpu/operators/internal')
-rw-r--r--src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.cpp119
-rw-r--r--src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h23
2 files changed, 71 insertions, 71 deletions
diff --git a/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.cpp b/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.cpp
index aec22e100c..7c087c9a7b 100644
--- a/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.cpp
+++ b/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Arm Limited.
+ * Copyright (c) 2022-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,6 +22,7 @@
* SOFTWARE.
*/
#include "src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h"
+#include "src/common/utils/Log.h"
#include "src/core/helpers/AutoConfiguration.h"
#include "src/dynamic_fusion/sketch/ArgumentPack.h"
#include "src/dynamic_fusion/sketch/gpu/GpuWorkloadSketchImpl.h"
@@ -43,30 +44,23 @@ void calculate_and_init_dst_if_empty(ITensorInfo *dst, const ITensorInfo *lhs, c
auto_init_if_empty(*dst, lhs->clone()->set_tensor_shape(broadcast_pair.first));
}
}
-GpuOperatorType operator_type = GpuOperatorType::Simple;
-}
-ElementwiseBinaryCommonAttributes &ElementwiseBinaryCommonAttributes::operation(const ElementwiseBinaryCommonAttributes::ElementwiseOp &operation)
+Status is_supported_op_helper(const GpuWorkloadContext &context,
+ const ITensorInfo *lhs,
+ const ITensorInfo *rhs,
+ const ITensorInfo *dst,
+ const ElementwiseBinaryCommonAttributes &attributes)
{
- _operation = operation;
- return *this;
-}
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(lhs, rhs);
-ElementwiseBinaryCommonAttributes::ElementwiseOp ElementwiseBinaryCommonAttributes::operation() const
-{
- return _operation;
-}
+ TensorInfo dst_info_to_validate;
+ const ITensorInfo *dst_info_to_validate_ptr = &dst_info_to_validate;
-Status GpuElementwiseBinaryCommon::is_supported_op(const GpuWorkloadContext &context,
- const ITensorInfo *lhs,
- const ITensorInfo *rhs,
- const ITensorInfo *dst,
- const ElementwiseBinaryCommonAttributes &attributes)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(lhs, rhs, dst);
+ if(dst != nullptr)
+ {
+ dst_info_to_validate_ptr = dst;
+ }
- // Auto initialize dst tensor info
- TensorInfo dst_info_to_validate = *dst;
calculate_and_init_dst_if_empty(&dst_info_to_validate, lhs, rhs);
// Check components
@@ -80,16 +74,8 @@ Status GpuElementwiseBinaryCommon::is_supported_op(const GpuWorkloadContext
ArgumentPack<ITensorInfo> arguments;
arguments.add_const_tensor(ACL_SRC_0, lhs);
arguments.add_const_tensor(ACL_SRC_1, rhs);
+ arguments.add_const_tensor(ACL_DST_0, dst_info_to_validate_ptr);
- // We needed to pass the original dst pointer for in-place detection, in case its shape is not empty
- if(dst->tensor_shape().total_size() == 0)
- {
- arguments.add_const_tensor(ACL_DST_0, &dst_info_to_validate);
- }
- else
- {
- arguments.add_const_tensor(ACL_DST_0, dst);
- }
ARM_COMPUTE_RETURN_ON_ERROR(ClComponentElementwiseBinary::validate(arguments, attributes));
}
}
@@ -101,18 +87,40 @@ Status GpuElementwiseBinaryCommon::is_supported_op(const GpuWorkloadContext
return Status{};
}
+GpuOperatorType operator_type = GpuOperatorType::Simple;
+} // namespace
+
+ElementwiseBinaryCommonAttributes &ElementwiseBinaryCommonAttributes::operation(const ElementwiseBinaryCommonAttributes::ElementwiseOp &operation)
+{
+ _operation = operation;
+ return *this;
+}
+
+ElementwiseBinaryCommonAttributes::ElementwiseOp ElementwiseBinaryCommonAttributes::operation() const
+{
+ return _operation;
+}
+
+Status GpuElementwiseBinaryCommon::is_supported_op(const GpuWorkloadContext &context,
+ const ITensorInfo *lhs,
+ const ITensorInfo *rhs,
+ const ElementwiseBinaryCommonAttributes &attributes)
+{
+ return is_supported_op_helper(context, lhs, rhs, nullptr, attributes);
+}
+
Status GpuElementwiseBinaryCommon::validate_op(const GpuWorkloadSketch &sketch,
const ITensorInfo *lhs,
const ITensorInfo *rhs,
- const ITensorInfo *dst,
const ElementwiseBinaryCommonAttributes &attributes)
{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(lhs, rhs, dst);
- ARM_COMPUTE_RETURN_ERROR_ON(
- !lhs->has_valid_id() || !rhs->has_valid_id() || !dst->has_valid_id());
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(lhs, rhs);
+ ARM_COMPUTE_RETURN_ERROR_ON(!lhs->has_valid_id() || !rhs->has_valid_id());
+
+ // Refer to GpuConv2d::validate_op() for id-validness of this TensorInfo object
+ TensorInfo dst_info_to_validate;
// Auto initialize dst tensor info
- TensorInfo dst_info_to_validate = *dst;
calculate_and_init_dst_if_empty(&dst_info_to_validate, lhs, rhs);
// Perform fusion test
@@ -125,20 +133,21 @@ Status GpuElementwiseBinaryCommon::validate_op(const GpuWorkloadSketch
ARM_COMPUTE_RETURN_ERROR_ON_MSG(!sketch.implementation().operator_group().try_add_operator(op),
"Operator fusion test failed. This operator cannot be fused into the workload");
- // Check if configuration is supported, and passing the original dst for in-place detection
- return is_supported_op(*sketch.gpu_context(), lhs, rhs, dst, attributes);
+ // Check if configuration is supported
+ return is_supported_op_helper(*sketch.gpu_context(), lhs, rhs, &dst_info_to_validate, attributes);
}
-void GpuElementwiseBinaryCommon::create_op(GpuWorkloadSketch &sketch,
- ITensorInfo *lhs,
- ITensorInfo *rhs,
- ITensorInfo *dst,
- const ElementwiseBinaryCommonAttributes &attributes)
+ITensorInfo *GpuElementwiseBinaryCommon::create_op(GpuWorkloadSketch &sketch,
+ ITensorInfo *lhs,
+ ITensorInfo *rhs,
+ const ElementwiseBinaryCommonAttributes &attributes)
{
- ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, dst);
- const bool in_place = (lhs == dst) || (rhs == dst);
- static TensorInfo in_place_dst;
- in_place_dst = in_place ? sketch.create_tensor_info(*lhs) : TensorInfo{};
+ ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs);
+ ARM_COMPUTE_LOG_PARAMS(lhs, rhs);
+ ARM_COMPUTE_ERROR_THROW_ON(GpuElementwiseBinaryCommon::validate_op(sketch, lhs, rhs, attributes));
+
+ ITensorInfo *dst = sketch.implementation().create_virtual_tensor();
+ ARM_COMPUTE_ERROR_ON_NULLPTR(dst);
// Auto initialize dst tensor
calculate_and_init_dst_if_empty(dst, lhs, rhs);
@@ -160,14 +169,7 @@ void GpuElementwiseBinaryCommon::create_op(GpuWorkloadSketch
ArgumentPack<ITensorInfo> arguments;
arguments.add_const_tensor(ACL_SRC_0, lhs);
arguments.add_const_tensor(ACL_SRC_1, rhs);
- if(in_place)
- {
- arguments.add_const_tensor(ACL_DST_0, &in_place_dst);
- }
- else
- {
- arguments.add_const_tensor(ACL_DST_0, dst);
- }
+ arguments.add_const_tensor(ACL_DST_0, dst);
comp_graph.add_new_component<ClComponentElementwiseBinary>(properties, arguments, attributes);
}
}
@@ -183,16 +185,11 @@ void GpuElementwiseBinaryCommon::create_op(GpuWorkloadSketch
ArgumentPack<ITensorInfo> tensors;
tensors.add_const_tensor(ACL_SRC_0, lhs);
tensors.add_const_tensor(ACL_SRC_1, rhs);
- if(in_place)
- {
- tensors.add_const_tensor(ACL_DST_0, &in_place_dst);
- }
- else
- {
- tensors.add_tensor(ACL_DST_0, dst);
- }
+ tensors.add_tensor(ACL_DST_0, dst);
const auto op = sketch.implementation().operator_group().new_operator(operator_type, tensors);
sketch.implementation().operator_group().add_operator(op);
+
+ return dst;
}
} // namespace dynamic_fusion
diff --git a/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h b/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h
index b00d069389..cbefa379e6 100644
--- a/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h
+++ b/src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h
@@ -25,6 +25,7 @@
#define SRC_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_INTERNAL_GPUELEMENTWISEBINARYCOMMON
#include "arm_compute/core/Error.h"
+#include "arm_compute/core/ITensorInfo.h"
namespace arm_compute
{
@@ -76,34 +77,36 @@ public:
* @param[in,out] sketch Workload sketch into which the operator will be fused
* @param[in] lhs Left hand side tensor info. Data types supported: U8/S16/S32/F16/F32.
* @param[in] rhs Right hand side tensor info. Data types supported: U8/S16/S32/F16/F32.
- * @param[out] dst Destination tensor info. Data types supported: U8/S16/S32/F16/F32. If an uninitialized ITensorInfo is passed in, it will be auto-initialized
* @param[in] attributes ElementwiseBinaryCommonAttributes containing the operator type: ADD, SUB, DIV, ... etc.
+ *
+ * @return Pointer for the destination tensor info
*/
- static void create_op(GpuWorkloadSketch &sketch,
- ITensorInfo *lhs,
- ITensorInfo *rhs,
- ITensorInfo *dst,
- const ElementwiseBinaryCommonAttributes &attributes);
+ static ITensorInfo *create_op(GpuWorkloadSketch &sketch,
+ ITensorInfo *lhs,
+ ITensorInfo *rhs,
+ const ElementwiseBinaryCommonAttributes &attributes);
/** Check if the operator configuration is supported, irrespective of fusion
*
* @param[in] context Workload context within which the operator is running
* @param[in] lhs Left hand side tensor info. Data types supported: U8/S16/S32/F16/F32.
* @param[in] rhs Right hand side tensor info. Data types supported: U8/S16/S32/F16/F32.
- * @param[in] dst Destination tensor info. Data types supported: U8/S16/S32/F16/F32. If an uninitialized ITensorInfo is passed in, it will be auto-initialized
* @param[in] attributes ElementwiseBinaryCommonAttributes containing the operator type: ADD, SUB, DIV, ... etc.
+ *
+ * @return Status
*/
static Status is_supported_op(const GpuWorkloadContext &context,
const ITensorInfo *lhs,
const ITensorInfo *rhs,
- const ITensorInfo *dst,
const ElementwiseBinaryCommonAttributes &attributes);
/** Validate the operator and check if it can be fused into the workload sketch.
- * Similar to @ref GpuElementwiseBinaryCommon::create_op()
+ *
+ * Parameters are similar to @ref GpuElementwiseBinaryCommon::create_op()
+ *
+ * @return Status
*/
static Status validate_op(const GpuWorkloadSketch &sketch,
const ITensorInfo *rhs,
const ITensorInfo *lhs,
- const ITensorInfo *dst,
const ElementwiseBinaryCommonAttributes &attributes);
};
} // namespace dynamic_fusion