| 1 |
/* |
| 2 |
* Copyright (c) 2023 Arm Limited. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and associated documentation files (the "Software"), to |
| 8 |
* deal in the Software without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be included in all |
| 14 |
* copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 |
* SOFTWARE. |
| 23 |
*/ |
| 24 |
#ifndef ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUMATMUL_H |
| 25 |
#define ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUMATMUL_H |
| 26 |
|
| 27 |
#include "arm_compute/core/Error.h" |
| 28 |
#include "arm_compute/core/KernelDescriptors.h" |
| 29 |
#include "arm_compute/dynamic_fusion/sketch/attributes/MatMulAttributes.h" |
| 30 |
|
| 31 |
namespace arm_compute |
| 32 |
{ |
| 33 |
namespace experimental |
| 34 |
{ |
| 35 |
namespace dynamic_fusion |
| 36 |
{ |
| 37 |
/** Forward declaration */ |
| 38 |
class GpuWorkloadContext; |
| 39 |
class GpuWorkloadSketch; |
| 40 |
|
| 41 |
/** Operator backend specific settings |
| 42 |
*/ |
| 43 |
class GpuMatMulSettings |
| 44 |
{ |
| 45 |
public: |
| 46 |
/** Set N0: number of columns processed by each work-item */ |
| 47 |
GpuMatMulSettings &n0(int n0); |
| 48 |
/** Get N0: number of columns processed by each work-item */ |
| 49 |
int n0() const; |
| 50 |
|
| 51 |
/** Set M0: number of rows processed by each work-item */ |
| 52 |
GpuMatMulSettings &m0(int m0); |
| 53 |
/** Get M0: number of rows processed by each work-item */ |
| 54 |
int m0() const; |
| 55 |
|
| 56 |
/** Set K0: number of inner accumulations */ |
| 57 |
GpuMatMulSettings &k0(int k0); |
| 58 |
/** Get K0: number of inner accumulations */ |
| 59 |
int k0() const; |
| 60 |
|
| 61 |
private: |
| 62 |
int _n0{0}; /**< Number of columns processed by each work-item */ |
| 63 |
int _m0{0}; /**< Number of rows processed by each work-item */ |
| 64 |
int _k0{0}; /**< Number of inner accumulations */ |
| 65 |
}; |
| 66 |
|
| 67 |
/** Operator interface. */ |
| 68 |
class GpuMatMul final |
| 69 |
{ |
| 70 |
public: |
| 71 |
/* Attributes are a set of backend-agnostic parameters that define what an operator does */ |
| 72 |
using Attributes = MatMulAttributes; |
| 73 |
/* Settings are a set of backend-specific parameters that influence the implementation of a operator */ |
| 74 |
using Settings = GpuMatMulSettings; |
| 75 |
|
| 76 |
/* Create an operator and fuse it into the workload sketch. |
| 77 |
* @note If @ref validate_op() fails, the creation also fails and may throw an error. |
| 78 |
* @note If @ref validate_op() fails, @p sketch remains unchanged and valid. |
| 79 |
* |
| 80 |
* Valid data type configurations: |
| 81 |
* |LHS |RHS |dst | |
| 82 |
* |:--------------|:--------------|:--------------| |
| 83 |
* |F16 |F16 |F16 | |
| 84 |
* |F32 |F32 |F32 | |
| 85 |
* |
| 86 |
* |
| 87 |
* @param[in,out] sketch Workload sketch into which the operator will be fused |
| 88 |
* @param[in] lhs Input tensor info for the LHS matrix. Data type supported: F32/F16. Dimensions above 2 are collapsed onto dimension 2 and represent the batch. |
| 89 |
* @param[in] rhs Input tensor info for the RHS matrix. Data type supported: same as @p lhs. Dimensions above 2 are collapsed onto dimension 2 and represent the batch. |
| 90 |
* @param[in] attributes Operator attributes |
| 91 |
* @param[in] settings Operator settings |
| 92 |
* |
| 93 |
* @return Pointer for the destination tensor info |
| 94 |
*/ |
| 95 |
static ITensorInfo *create_op(GpuWorkloadSketch &sketch, |
| 96 |
ITensorInfo *lhs, |
| 97 |
ITensorInfo *rhs, |
| 98 |
const Attributes &attributes, |
| 99 |
const Settings &settings); |
| 100 |
|
| 101 |
/* Check if the operator configuration is supported, irrespective of fusion |
| 102 |
* |
| 103 |
* @param[in] context Workload context within which the operator is running |
| 104 |
* @param[in] lhs Input tensor info for the LHS matrix. |
| 105 |
* @param[in] rhs Input tensor info for the RHS matrix. |
| 106 |
* @param[in] attributes Operator attributes |
| 107 |
* @param[in] settings Operator settings |
| 108 |
* |
| 109 |
* @return Status |
| 110 |
*/ |
| 111 |
static Status is_supported_op(const GpuWorkloadContext &context, |
| 112 |
const ITensorInfo *lhs, |
| 113 |
const ITensorInfo *rhs, |
| 114 |
const Attributes &attributes, |
| 115 |
const Settings &settings); |
| 116 |
|
| 117 |
/* Check if the operator configuration is supported and if it can be fused into the workload sketch. |
| 118 |
* |
| 119 |
* Parameters are similar to @ref GpuMatMul::create_op() |
| 120 |
* |
| 121 |
* @return Status |
| 122 |
*/ |
| 123 |
static Status validate_op(const GpuWorkloadSketch &sketch, |
| 124 |
const ITensorInfo *lhs, |
| 125 |
const ITensorInfo *rhs, |
| 126 |
const Attributes &attributes, |
| 127 |
const Settings &settings); |
| 128 |
}; |
| 129 |
} // namespace dynamic_fusion |
| 130 |
} // namespace experimental |
| 131 |
} // namespace arm_compute |
| 132 |
#endif // ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUMATMUL_H |