diff options
author | SiCong Li <sicong.li@arm.com> | 2021-01-08 15:16:02 +0000 |
---|---|---|
committer | Georgios Pinitas <georgios.pinitas@arm.com> | 2021-02-02 22:05:34 +0000 |
commit | 7061eb283969f9a020c08349454447564e4dd5b3 (patch) | |
tree | cf11604aaf57ee86ff6e4980a3ddf95bb49167e8 /src/runtime/CL/mlgo/MLGOHeuristics.h | |
parent | 74a142c11ec0b2f2b3fe1feb3fdfd98e9190762e (diff) | |
download | ComputeLibrary-7061eb283969f9a020c08349454447564e4dd5b3.tar.gz |
Implement MLGO module
* Implement MLGOHeuristics which provides a query and a loading
interface
* Implement a top-down parser MLGOParser for parsing dotmlgo
* Add validation tests for MLGOHeuristics
Resolves COMPMID-3840, COMPMID-3841
Signed-off-by: SiCong Li <sicong.li@arm.com>
Change-Id: Iae96d2779524b2dd83623d1a3a30ef57823ae084
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4941
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/runtime/CL/mlgo/MLGOHeuristics.h')
-rw-r--r-- | src/runtime/CL/mlgo/MLGOHeuristics.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/runtime/CL/mlgo/MLGOHeuristics.h b/src/runtime/CL/mlgo/MLGOHeuristics.h new file mode 100644 index 0000000000..02e8111b6e --- /dev/null +++ b/src/runtime/CL/mlgo/MLGOHeuristics.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef SRC_RUNTIME_MLGO_MLGOHEURISTICS_H +#define SRC_RUNTIME_MLGO_MLGOHEURISTICS_H + +#include "src/runtime/CL/mlgo/Common.h" +#include "src/runtime/CL/mlgo/HeuristicTree.h" + +#include <iostream> +#include <map> +#include <string> +#include <utility> +namespace arm_compute +{ +namespace mlgo +{ +/** Query interface */ +struct Query +{ + std::string ip_target; /**< The name of the IP target */ + DataType data_type; /**< Data type */ + unsigned int m; /**< Number of rows for the lhs matrix. Lhs matrix NOT transposed */ + unsigned int n; /**< Number of columns for the rhs matrix. Rhs matrix NOT transposed */ + unsigned int k; /**< Number of rows for the rhs matrix. Rhs matrix NOT transposed */ + unsigned int b; /**< Batch size */ +}; + +bool operator==(const GEMMConfigReshapedOnlyRHS &lhs, const GEMMConfigReshapedOnlyRHS &rhs); +bool operator==(const GEMMConfigReshaped &lhs, const GEMMConfigReshaped &rhs); + +/** MLGOHeuristics for configuring GEMM kernels */ +class MLGOHeuristics +{ +public: + /** Constructor */ + MLGOHeuristics(); + /** Query the gemm type + * + * @param[in] query Query + * + * @return std::pair<bool, GEMMType> signals if the query succeeded or failed + */ + std::pair<bool, GEMMType> query_gemm_type(Query) const; + /** Query the gemm configuration for native kernel + * + * @param[in] query Query + * + * @return std::pair<bool, GEMMConfigNative> bool signals if the query succeeded or failed + */ + std::pair<bool, GEMMConfigNative> query_gemm_config_native(Query query) const; + /** Query the gemm configuration for reshaped only rhs kernel + * + * @param[in] query Query + * + * @return std::pair<bool, GEMMConfigReshapedOnlyRHS> bool signals if the query succeeded or failed + */ + std::pair<bool, GEMMConfigReshapedOnlyRHS> query_gemm_config_reshaped_only_rhs(Query) const; + /** Query the gemm configuration for reshaped kernel + * + * @param[in] query Query + * + * @return std::pair<bool, GEMMConfigReshaped> bool signals if the query succeeded or failed + */ + std::pair<bool, GEMMConfigReshaped> query_gemm_config_reshaped(Query) const; + /** (Re)Load the heuristics from reading a dotmlgo file + * + * @param[in] filename Path to the dotmlgo file + * + * @return bool Signals if the reload succeeded or failed + */ + bool reload_from_file(const std::string &filename); + /** (Re)Load the heuristics from reading an input stream + * + * @param[in] istream Istream containing mlgo heuristics + * + * @return bool Signals if the reload succeeded or failed + */ + bool reload_from_stream(std::istream &istream); + + /** Get the heuristic tree from tree id + * + * @param[in] id Tree id. + * + * @return HeuristicTree& + */ + std::pair<bool, HeuristicTree *> get_heuristic_tree(HeuristicTree::TreeID id); + /** Add a heuristic tree + * @param t Heuristic tree to be added + */ + bool add_heuristic_tree(HeuristicTree &&t); + + /** Check the validity of the heuristic tree. + * + * @param id ID of the tree to be checked + * + * @return bool + */ + bool check_heuristic_tree(HeuristicTree::TreeID id); + + /** Check the overall validity of the heuristics. + * @return bool + */ + bool check_all() const; + +private: + static constexpr size_t _max_num_trees{ 100 }; /**< Max number of trees that can be added*/ + +private: + // There exists a one-to-one mappipng between TreeID and Index, either can be used to identify a @ref HeuristicTree + std::map<HeuristicTree::TreeID, HeuristicTree::Index> _indices; /**< A mapping from TreeID to Index */ + std::map<HeuristicTree::Index, HeuristicTree> _trees; /**< A mapping from Index to HeuristicTree */ + std::map<HeuristicTree::TreeID, bool> _tree_valid; /**< Result cache of the tree validity checks */ + bool _valid; /**< Overall validity */ +}; + +} // namespace mlgo +} // namespace arm_compute +#endif //SRC_MLGO_MLGOHEURISTICS_H
\ No newline at end of file |