Compute Library
 21.11
arm_compute::cl_gemm::auto_heuristics Namespace Reference

Data Structures

struct  CommonQuery
 A collection of adaptor functions that enable the auto selection between mlgo-based heuristics and default heuristics. More...
 
struct  GEMMConfigResult
 Result of querying about GEMM config ( GEMMLHSMatrixInfo and GEMMRHSMatrixInfo) More...
 
struct  GEMMTypeResult
 Result of querying about GEMM type ( CLGEMMKernelType) More...
 

Functions

GEMMTypeResult select_mlgo_gemm_kernel (const CommonQuery &query, bool reshape_b_only_on_first_run)
 Select gemm type based on mlgo heuristics. More...
 
GEMMTypeResult select_default_gemm_kernel (const CommonQuery &query, bool reshape_b_only_on_first_run)
 Select gemm type based on default heuristics. More...
 
GEMMConfigResult select_default_gemm_config_reshaped_only_rhs (const CommonQuery &query)
 Select gemm config based on default heuristics. More...
 
GEMMConfigResult select_mlgo_gemm_config_reshaped_only_rhs (const CommonQuery &query)
 Select gemm config based on mlgo heuristics. More...
 
GEMMConfigResult select_default_gemm_config_reshaped (const CommonQuery &query)
 Select gemm config based on default heuristics. More...
 
GEMMConfigResult select_mlgo_gemm_config_reshaped (const CommonQuery &query)
 Select gemm config based on mlgo heuristics. More...
 
GEMMConfigResult select_default_gemm_config_native (const CommonQuery &query)
 Select gemm config based on default heuristics. More...
 
GEMMConfigResult select_mlgo_gemm_config_native (const CommonQuery &query)
 Select gemm config based on mlgo heuristics. More...
 

Function Documentation

◆ select_default_gemm_config_native()

GEMMConfigResult select_default_gemm_config_native ( const CommonQuery query)

Select gemm config based on default heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 155 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, CommonQuery::b, ClGemmNativeKernelConfigurationFactory::create(), CommonQuery::data_type, CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, and arm_compute::test::validation::rhs_info.

Referenced by ClGemmLowpMatrixMultiplyCore::validate().

156 {
157  GEMMLHSMatrixInfo lhs_info;
158  GEMMRHSMatrixInfo rhs_info;
159  std::unique_ptr<IClGemmKernelConfig> gemm_config = ClGemmNativeKernelConfigurationFactory::create(query.gpu_target);
160  ARM_COMPUTE_ERROR_ON_NULLPTR(gemm_config.get());
161  std::tie(lhs_info, rhs_info) = gemm_config->configure(query.m, query.n, query.k, query.b, query.data_type);
162  return GEMMConfigResult{ true, lhs_info, rhs_info };
163 }
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ select_default_gemm_config_reshaped()

GEMMConfigResult select_default_gemm_config_reshaped ( const CommonQuery query)

Select gemm config based on default heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 121 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, CommonQuery::b, ClGemmReshapedKernelConfigurationFactory::create(), CommonQuery::data_type, CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, and arm_compute::test::validation::rhs_info.

122 {
123  GEMMLHSMatrixInfo lhs_info;
124  GEMMRHSMatrixInfo rhs_info;
125  std::unique_ptr<IClGemmKernelConfig> gemm_config = ClGemmReshapedKernelConfigurationFactory::create(query.gpu_target);
126  ARM_COMPUTE_ERROR_ON_NULLPTR(gemm_config.get());
127  std::tie(lhs_info, rhs_info) = gemm_config->configure(query.m, query.n, query.k, query.b, query.data_type);
128  return GEMMConfigResult{ true, lhs_info, rhs_info };
129 }
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ select_default_gemm_config_reshaped_only_rhs()

GEMMConfigResult select_default_gemm_config_reshaped_only_rhs ( const CommonQuery query)

Select gemm config based on default heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 86 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, CommonQuery::b, ClGemmReshapedOnlyRhsKernelConfigurationFactory::create(), CommonQuery::data_type, CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, and arm_compute::test::validation::rhs_info.

Referenced by ClGemmLowpMatrixMultiplyCore::validate().

87 {
88  GEMMLHSMatrixInfo lhs_info;
89  GEMMRHSMatrixInfo rhs_info;
90  std::unique_ptr<IClGemmKernelConfig> gemm_config = ClGemmReshapedOnlyRhsKernelConfigurationFactory::create(query.gpu_target);
91  ARM_COMPUTE_ERROR_ON_NULLPTR(gemm_config.get());
92  std::tie(lhs_info, rhs_info) = gemm_config->configure(query.m, query.n, query.k, query.b, query.data_type);
93  return GEMMConfigResult{ true, lhs_info, rhs_info };
94 }
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ select_default_gemm_kernel()

GEMMTypeResult select_default_gemm_kernel ( const CommonQuery query,
bool  reshape_b_only_on_first_run 
)

Select gemm type based on default heuristics.

Parameters
queryQuery
reshape_b_only_on_first_runAdditional query parameter if reshape b only on first run
Returns
GEMMTypeResult. Result is valid if bool(GEMMTypeResult) == true and invalid otherwise

Definition at line 69 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, CommonQuery::b, CLGEMMKernelSelectionFactory::create(), CommonQuery::data_type, CommonQuery::gpu_target, CommonQuery::k, CLGEMMKernelSelectionParams::m, CommonQuery::m, and CommonQuery::n.

70 {
71  std::unique_ptr<ICLGEMMKernelSelection> default_heuristics = CLGEMMKernelSelectionFactory::create(query.gpu_target);
72  ARM_COMPUTE_ERROR_ON_NULLPTR(default_heuristics.get());
73 
74  CLGEMMKernelSelectionParams params;
75  params.m = query.m;
76  params.n = query.n;
77  params.k = query.k;
78  params.b = query.b;
79  params.is_rhs_constant = reshape_b_only_on_first_run;
80  params.data_type = query.data_type;
81 
82  const auto kernel_type = default_heuristics->select_kernel(params);
83  return GEMMTypeResult(true, kernel_type);
84 }
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ select_mlgo_gemm_config_native()

GEMMConfigResult select_mlgo_gemm_config_native ( const CommonQuery query)

Select gemm config based on mlgo heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 165 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_LOG_INFO_MSG_CORE, ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE, CommonQuery::b, arm_compute::opencl::kernels::gemm::configure_lhs_rhs_info(), CommonQuery::data_type, CLScheduler::gemm_heuristics(), CLScheduler::get(), CLGEMMHeuristicsHandle::get(), CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, MLGOHeuristics::query_gemm_config_native(), arm_compute::test::validation::rhs_info, arm_compute::string_from_target(), and arm_compute::to_string().

166 {
167  bool valid = false;
168  GEMMLHSMatrixInfo lhs_info;
169  GEMMRHSMatrixInfo rhs_info;
170  mlgo::GEMMConfigNative config{};
171  const auto mlgo_heuristics = CLScheduler::get().gemm_heuristics();
172  if(mlgo_heuristics != nullptr)
173  {
174  std::tie(valid, config) = mlgo_heuristics->get()->query_gemm_config_native(mlgo::Query{ string_from_target(query.gpu_target), query.data_type, query.m, query.n, query.k, query.b });
175  }
176  if(valid)
177  {
178  ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("MLGOHeuristics query returns gemm config: %s.", to_string(config).c_str());
179  // Setting irrelevant unsigned int parameters to 1 and bool parameters to false as they do no matter
180  std::tie(lhs_info, rhs_info) = opencl::kernels::gemm::configure_lhs_rhs_info(query.m, query.n, config.m0, config.n0, config.k0, 1, 1, false, false, false, false, false);
181  }
182  else
183  {
184  ARM_COMPUTE_LOG_INFO_MSG_CORE("MLGOHeuristics query failed");
185  }
186  return GEMMConfigResult{ valid, lhs_info, rhs_info };
187 }
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:119
#define ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE(fmt,...)
Log information level formatted message to the core system logger.
Definition: Log.h:99
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > configure_lhs_rhs_info(unsigned int m, unsigned int n, unsigned int m0, unsigned int n0, unsigned int k0, unsigned int v0, unsigned int h0, bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose, bool export_to_cl_image)
Configure GEMMLHSMatrixInfo and GEMMRHSMatrixInfo.
#define ARM_COMPUTE_LOG_INFO_MSG_CORE(msg)
Log information level message to the core system logger.
Definition: Log.h:87

◆ select_mlgo_gemm_config_reshaped()

GEMMConfigResult select_mlgo_gemm_config_reshaped ( const CommonQuery query)

Select gemm config based on mlgo heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 131 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_LOG_INFO_MSG_CORE, ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE, CommonQuery::b, arm_compute::opencl::kernels::gemm::configure_lhs_rhs_info(), CommonQuery::data_type, CLScheduler::gemm_heuristics(), CLScheduler::get(), CLGEMMHeuristicsHandle::get(), CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, MLGOHeuristics::query_gemm_config_reshaped(), arm_compute::test::validation::rhs_info, arm_compute::string_from_target(), and arm_compute::to_string().

132 {
133  bool valid = false;
134  GEMMLHSMatrixInfo lhs_info;
135  GEMMRHSMatrixInfo rhs_info;
136  mlgo::GEMMConfigReshaped config{};
137  const auto mlgo_heuristics = CLScheduler::get().gemm_heuristics();
138  if(mlgo_heuristics != nullptr)
139  {
140  std::tie(valid, config) = mlgo_heuristics->get()->query_gemm_config_reshaped(mlgo::Query{ string_from_target(query.gpu_target), query.data_type, query.m, query.n, query.k, query.b });
141  }
142  if(valid)
143  {
144  ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("MLGOHeuristics query returns gemm config: %s.", to_string(config).c_str());
145  std::tie(lhs_info, rhs_info) = configure_lhs_rhs_info(query.m, query.n, config.m0, config.n0, config.k0, config.v0, config.h0, config.interleave_lhs, config.interleave_rhs, !config.transpose_rhs,
146  config.transpose_rhs, config.export_cl_image);
147  }
148  else
149  {
150  ARM_COMPUTE_LOG_INFO_MSG_CORE("MLGOHeuristics query failed");
151  }
152  return GEMMConfigResult{ valid, lhs_info, rhs_info };
153 }
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:119
#define ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE(fmt,...)
Log information level formatted message to the core system logger.
Definition: Log.h:99
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > configure_lhs_rhs_info(unsigned int m, unsigned int n, unsigned int m0, unsigned int n0, unsigned int k0, unsigned int v0, unsigned int h0, bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose, bool export_to_cl_image)
Configure GEMMLHSMatrixInfo and GEMMRHSMatrixInfo.
#define ARM_COMPUTE_LOG_INFO_MSG_CORE(msg)
Log information level message to the core system logger.
Definition: Log.h:87

◆ select_mlgo_gemm_config_reshaped_only_rhs()

GEMMConfigResult select_mlgo_gemm_config_reshaped_only_rhs ( const CommonQuery query)

Select gemm config based on mlgo heuristics.

Parameters
queryQuery
Returns
GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise

Definition at line 96 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_LOG_INFO_MSG_CORE, ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE, CommonQuery::b, arm_compute::opencl::kernels::gemm::configure_lhs_rhs_info(), CommonQuery::data_type, CLScheduler::gemm_heuristics(), CLScheduler::get(), CLGEMMHeuristicsHandle::get(), CommonQuery::gpu_target, CommonQuery::k, arm_compute::test::validation::lhs_info, CommonQuery::m, CommonQuery::n, MLGOHeuristics::query_gemm_config_reshaped_only_rhs(), arm_compute::test::validation::rhs_info, arm_compute::string_from_target(), and arm_compute::to_string().

97 {
98  bool valid = false;
99  GEMMLHSMatrixInfo lhs_info;
100  GEMMRHSMatrixInfo rhs_info;
101  mlgo::GEMMConfigReshapedOnlyRHS config{};
102  const auto mlgo_heuristics = CLScheduler::get().gemm_heuristics();
103  if(mlgo_heuristics != nullptr)
104  {
105  std::tie(valid, config) = mlgo_heuristics->get()->query_gemm_config_reshaped_only_rhs(mlgo::Query{ string_from_target(query.gpu_target), query.data_type, query.m, query.n, query.k, query.b });
106  }
107  if(valid)
108  {
109  ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("MLGOHeuristics query returns gemm config: %s.", to_string(config).c_str());
110  // Setting irrelevant unsigned int parameters to 1 and bool parameters to false as they do no matter
111  std::tie(lhs_info, rhs_info) = configure_lhs_rhs_info(query.m, query.n, config.m0, config.n0, config.k0, 1, config.h0, false, config.interleave_rhs, !config.transpose_rhs, config.transpose_rhs,
112  config.export_cl_image);
113  }
114  else
115  {
116  ARM_COMPUTE_LOG_INFO_MSG_CORE("MLGOHeuristics query failed");
117  }
118  return GEMMConfigResult{ valid, lhs_info, rhs_info };
119 }
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:119
#define ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE(fmt,...)
Log information level formatted message to the core system logger.
Definition: Log.h:99
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > configure_lhs_rhs_info(unsigned int m, unsigned int n, unsigned int m0, unsigned int n0, unsigned int k0, unsigned int v0, unsigned int h0, bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose, bool export_to_cl_image)
Configure GEMMLHSMatrixInfo and GEMMRHSMatrixInfo.
#define ARM_COMPUTE_LOG_INFO_MSG_CORE(msg)
Log information level message to the core system logger.
Definition: Log.h:87

◆ select_mlgo_gemm_kernel()

GEMMTypeResult select_mlgo_gemm_kernel ( const CommonQuery query,
bool  reshape_b_only_on_first_run 
)

Select gemm type based on mlgo heuristics.

Parameters
queryQuery
reshape_b_only_on_first_runAdditional query parameter if reshape b only on first run
Returns
GEMMTypeResult. Result is valid if bool(GEMMTypeResult) == true and invalid otherwise

Definition at line 48 of file CLGEMMAutoHeuristics.cpp.

References ARM_COMPUTE_LOG_INFO_MSG_CORE, ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE, ARM_COMPUTE_UNUSED, CommonQuery::b, CommonQuery::data_type, CLScheduler::gemm_heuristics(), arm_compute::mlgo::parser::gemm_type(), CLScheduler::get(), CLGEMMHeuristicsHandle::get(), CommonQuery::gpu_target, CommonQuery::k, CommonQuery::m, CommonQuery::n, MLGOHeuristics::query_gemm_type(), arm_compute::string_from_target(), and arm_compute::to_string().

49 {
50  ARM_COMPUTE_UNUSED(reshape_b_only_on_first_run);
51  bool valid = false;
53  const auto mlgo_heuristics = CLScheduler::get().gemm_heuristics();
54  if(mlgo_heuristics != nullptr)
55  {
56  std::tie(valid, gemm_type) = mlgo_heuristics->get()->query_gemm_type(mlgo::Query{ string_from_target(query.gpu_target), query.data_type, query.m, query.n, query.k, query.b });
57  }
58  if(valid)
59  {
60  ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("MLGOHeuristics query returns gemm type: %s.", to_string(gemm_type).c_str());
61  }
62  else
63  {
64  ARM_COMPUTE_LOG_INFO_MSG_CORE("MLGOHeuristics query failed");
65  }
66  return GEMMTypeResult(valid, gemm_type);
67 }
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
GEMMType gemm_type(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:567
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:119
CLGEMMKernelType
OpenCL GEMM kernel types.
Definition: CLTypes.h:31
#define ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE(fmt,...)
Log information level formatted message to the core system logger.
Definition: Log.h:99
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
template std::pair< bool, GEMMType > query(GEMMShape shape) const
Explicit template instantiation.
#define ARM_COMPUTE_LOG_INFO_MSG_CORE(msg)
Log information level message to the core system logger.
Definition: Log.h:87