ArmNN
 25.11
Loading...
Searching...
No Matches
ClBatchMatMulWorkload.cpp
Go to the documentation of this file.
1//
2// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
7
8#include "ClWorkloadUtils.hpp"
9
12
14
16
17#include <cl/ClTensorHandle.hpp>
18
19#include <arm_compute/function_info/MatMulInfo.h>
20
21namespace armnn
22{
23
24arm_compute::Status ClBatchMatMulValidate(const TensorInfo& inputInfoX,
25 const TensorInfo& inputInfoY,
26 const TensorInfo& outputInfo,
27 const BatchMatMulDescriptor& descriptor,
28 const ActivationDescriptor* activationDescriptor)
29{
30 if (descriptor.m_AdjointX || descriptor.m_AdjointY )
31 {
32 throw Exception("Support for adjoint not implemented.");
33 }
35 {
36 throw Exception("Only supported the MatMul in the last 2 dimensions");
37 }
38
39 arm_compute::TensorInfo aclInputInfoX = armcomputetensorutils::BuildArmComputeTensorInfo(inputInfoX);
40 arm_compute::TensorInfo aclInputInfoY = armcomputetensorutils::BuildArmComputeTensorInfo(inputInfoY);
41 const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(outputInfo);
42
43 // GeMM dispatches kernel handles dynamic inputs differently to static so this flag needs to be set
44 aclInputInfoX.set_are_values_constant(false);
45 aclInputInfoY.set_are_values_constant(false);
46
47 const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
48 activationDescriptor);
49
50 arm_compute::MatMulInfo matMulInfo;
51 matMulInfo.adj_lhs(descriptor.m_TransposeX);
52 matMulInfo.adj_rhs(descriptor.m_TransposeY);
53
54 return arm_compute::CLMatMul::validate(&aclInputInfoX, &aclInputInfoY, &aclOutputInfo, matMulInfo, activationInfo);
55}
56
58 const WorkloadInfo& info,
59 const arm_compute::CLCompileContext& clCompileContext)
61{
62 // Report Profiling Details
63 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClBatchMatMulWorkload_Construct",
64 descriptor.m_Parameters,
65 info,
66 this->GetGuid());
67
68 if (descriptor.m_Parameters.m_AdjointX || descriptor.m_Parameters.m_AdjointY )
69 {
70 throw Exception("Support for adjoint not implemented.");
71 }
74 {
75 throw Exception("Only supported the MatMul in the last 2 dimensions");
76 }
77
78 m_Data.ValidateInputsOutputs("ClBatchMatMulWorkload", 2, 1);
79
80 arm_compute::ICLTensor& inputX = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
81 arm_compute::ICLTensor& inputY = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
82 auto outputHandle = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Outputs[0]);
83 arm_compute::ICLTensor& output = outputHandle->GetTensor();
84
85 // GeMM dispatches kernel handles dynamic inputs differently to static so this flag needs to be set
86 inputX.info()->set_are_values_constant(false);
87 inputY.info()->set_are_values_constant(false);
88
89 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
90
91 arm_compute::MatMulInfo matMulInfo;
92 matMulInfo.adj_lhs(descriptor.m_Parameters.m_TransposeX);
93 matMulInfo.adj_rhs(descriptor.m_Parameters.m_TransposeY);
94
95 arm_compute::GpuMatMulSettings settings;
96
97 m_MatMulLayer.configure(clCompileContext, &inputX, &inputY, &output, matMulInfo, settings, activationInfo);
98
99 // Report Profiling Details
100 WorkloadInfo detailsInfo;
101 detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
102 detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
103 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClBatchMatMulWorkload_Construct",
104 descriptor.m_Parameters,
105 detailsInfo,
106 GetGuid());
107}
108
110{
111 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClBatchMatMulWorkload_Execute");
112 RunClFunction(m_MatMulLayer, CHECK_LOCATION());
113}
114} //namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
#define CHECK_LOCATION()
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
arm::pipe::ProfilingGuid GetGuid() const final
Definition Workload.hpp:52
ClBaseWorkload(const BatchMatMulQueueDescriptor &descriptor, const WorkloadInfo &info)
ClBatchMatMulWorkload(const BatchMatMulQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
virtual void Execute() const override
Base class for all ArmNN exceptions so that users can filter to just those.
Copyright (c) 2021 ARM Limited and Contributors.
arm_compute::Status ClBatchMatMulValidate(const TensorInfo &inputInfoX, const TensorInfo &inputInfoY, const TensorInfo &outputInfo, const BatchMatMulDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.
arm_compute::ActivationLayerInfo ConvertActivationDescriptorToAclActivationLayerInfo(const ActivationDescriptor &actDesc)
An ActivationDescriptor for the ActivationLayer.
A BatchMatMulDescriptor for the BatchMatMul operator.
bool m_AdjointX
Adjoint the slices of each input tensor Transpose and Adjoint can not both be set to true for the sam...
bool m_TransposeX
Transpose the slices of each input tensor Transpose and Adjoint can not both be set to true for the s...
DataLayout m_DataLayoutX
Data layout of each input tensor, such as NHWC/NDHWC (leave as default for arbitrary layout)
Contains information about TensorInfos of a layer.
std::vector< TensorInfo > m_OutputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos