 Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago  Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago  Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago  Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago  Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago  Add GraphKernelPassManager to manage the passes of GraphKernel
Refactor the original "PassManager" class, and derive the "GraphKernelPassManager"
GraphKernel's ir files are dumped into a new sub-directory "graph_kernel" in the original "verbose_ir_files"
All GraphKernel's passes are divided into 3 levels, and controlled by the flag "opt_level" by default.
when the opt_level is greaterequal to the pass's level, this pass will run.
The default "opt_level" is 2 when GraphKernel is enabled.
Levels:
1. Basic features, like cluster, splitter, and some preprocess, postprocess.
2. All stable features, mainly includes the optimization passes.
3. Experimental features, like stitch-fusion, parallel-fusion.
The two flags "enable_pass" and "disable_pass" are available in this commit.
User can manually enable some passes when it's disabled by "opt_level", or disable the enabled passes,
by specifying that pass in this format: "stage_id.pass_id" or "stage_name.pass_name", multiple passes are separated by comma(",")
the stage/pass index and stage/pass name can be found from the ir filename.
e.g. "--enable_pass=cluster.graph_kernel_expander,1.1,1.2"
Others:
1. the pass "tensor_promotion" is not useful, remove it.
2. put the pass "InsertPadOps" before "ArithmeticSimplify".
4 years ago |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- /**
- * Copyright 2021 Huawei Technologies Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- #ifndef MINDSPORE_CCSRC_UTILS_GRAPH_KERNEL_FLAGS_H
- #define MINDSPORE_CCSRC_UTILS_GRAPH_KERNEL_FLAGS_H
-
- #include <map>
- #include <memory>
- #include <string>
- #include <vector>
- #include <utility>
- #include "utils/ms_context.h"
-
- namespace mindspore {
- namespace context {
- constexpr unsigned int OptLevel_0 = 0; // Disabled
- constexpr unsigned int OptLevel_1 = 1; // Basic functions
- constexpr unsigned int OptLevel_2 = 2; // Default functions
- constexpr unsigned int OptLevel_3 = 3; // Experimental functions
- constexpr unsigned int OptLevel_MAX = 4;
-
- class GraphKernelFlags {
- public:
- static const GraphKernelFlags &GetInstance() {
- static std::unique_ptr<GraphKernelFlags> flags(nullptr);
- auto contexts = GetGraphKernelContext();
- if (flags == nullptr || contexts.first != flags->flags_cache_ || contexts.second != flags->enable_graph_kernel_) {
- flags.reset(new GraphKernelFlags(contexts.first, contexts.second));
- flags->Refresh();
- }
- return *flags;
- }
-
- // Dump all flags to json-format string
- std::string DumpAllFlags() const;
-
- // Check whether graph_kernel is enabled
- bool IsEnableGraphKernel() const { return opt_level > OptLevel_0; }
-
- GraphKernelFlags(const GraphKernelFlags &flags) = delete;
- ~GraphKernelFlags() = default;
-
- public:
- /**
- * Dump info as human-readable text.
- * A directory "graph_kernel_dump" will be created, and all information will be dumped in this directory.
- */
- bool dump_as_text{false};
-
- /**
- * Enable stitch fusion in graph kernel fusion strategy.
- *
- * Experimental feature, enabled by default when opt_level=3
- */
- bool enable_stitch_fusion;
-
- /**
- * Enable recompute fusion in graph kernel fusion strategy, enabled when op_level>=2.
- */
- bool enable_recompute_fusion;
-
- /**
- * Enable parallel fusion in graph kernel fusion strategy.
- *
- * Experimental feature, enabled by default when opt_level=3
- */
- bool enable_parallel_fusion;
-
- /**
- * Enable low precision in data transferring between graph kernel and computing in graph kernel
- * in graph kernel.
- * Experimental feature, enabled by the enable_low_precision flag
- */
- bool enable_low_precision;
-
- /**
- * Optimization level, value from 0 to 3.
- * 0: Disable GraphKernel
- * 1: Enable GraphKernel with basic features only.
- * 2: Enable GraphKernel with all stable features.
- * 3: Enable GraphKernel with all experimental features.
- * The default value is OptLevel_2 when the context "enable_graph_kernel" is set,
- * but if it's also changed in "graph_kernel_flags", then the "graph_kernel_flags" will prevail.
- */
- unsigned int opt_level; // defaults 0 or 2
-
- /**
- * Online tuning level, value from 0 to 3.
- * 0: Disable online tuning
- * 1-3: The higher level, the larger tuning space, and the more time it takes.
- */
- unsigned int online_tuning{0};
-
- /**
- * AKG's operator repository file path.
- */
- std::string repository_path;
-
- /**
- * Additional expanding operators (case sensitive).
- * The operators to be added into the default expanding operator list.
- */
- std::vector<std::string> enable_expand_ops;
-
- /**
- * Expanding operators to be enabled (case sensitive).
- * Unlike the "enable_expand_ops", the default list will be overwritten by this list.
- * Note that the "enable_expand_ops" and "disable_expand_ops" will be ignored if this flag is set.
- */
- std::vector<std::string> enable_expand_ops_only;
-
- /**
- * Expanding operators to be disabled (case sensitive).
- * The behavior is undefined when this list overlaps with "enable_expand_ops".
- */
- std::vector<std::string> disable_expand_ops;
-
- /**
- * Additional clustering operators (case sensitive).
- * The operators to be added into the default clustering operator list.
- */
- std::vector<std::string> enable_cluster_ops;
-
- /**
- * Clustering operators to be enabled (case sensitive).
- * Unlike the "enable_cluster_ops", the default list will be overwritten by this list.
- * Note that the "enable_cluster_ops" and "disable_cluster_ops" will be ignored if this flag is set.
- */
- std::vector<std::string> enable_cluster_ops_only;
-
- /**
- * Clustering operators to be disabled (case sensitive).
- * The behavior is undefined when this list overlaps with "enable_cluster_ops".
- */
- std::vector<std::string> disable_cluster_ops;
-
- /**
- * Arithmetic simplify expressions to be enabled (case sensitive).
- * The default list will be overwritten by this list.
- * Note that "disable_simplify_exprs" will be ignored if this flag is set.
- */
- std::vector<std::string> enable_simplify_exprs_only;
-
- /**
- * Arithmetic simplify expressions to be disabled (case sensitive).
- */
- std::vector<std::string> disable_simplify_exprs;
-
- /**
- * Passes to be enabled.
- * By default, the passes is controlled by "opt_level" and target device,
- * user can manually enable some passes by setting this flag.
- * The format is "stage_id.pass_id" or "stage_name.pass_name", which corresponds to the ir filename.
- */
- std::vector<std::string> enable_pass;
-
- /**
- * Passes to be disabled.
- * By default, the passes is controlled by "opt_level" and target device,
- * user can manually disable some passes by setting this flag.
- * The format is "stage_id.pass_id" or "stage_name.pass_name", which corresponds to the ir filename.
- */
- std::vector<std::string> disable_pass;
-
- private:
- GraphKernelFlags(const std::string &graph_kernel_flags, bool enable_graph_kernel)
- : flags_cache_(graph_kernel_flags), enable_graph_kernel_(enable_graph_kernel) {}
-
- // get the `graph_kernel_flags` and `enable_graph_kernel`
- static std::pair<std::string, bool> GetGraphKernelContext() {
- auto context = MsContext::GetInstance();
- MS_EXCEPTION_IF_NULL(context);
- // Use the environment variable in priority
- auto env_flags = std::getenv("MS_GRAPH_KERNEL_FLAGS");
- std::string flags = env_flags ? std::string(env_flags) : context->get_param<std::string>(MS_CTX_GRAPH_KERNEL_FLAGS);
- return std::make_pair(flags, context->get_param<bool>(MS_CTX_ENABLE_GRAPH_KERNEL));
- }
-
- // parse and refresh the flags
- void Refresh();
- // register the flags defined above
- void RegisterFlags(std::map<std::string, std::string> *flag_map);
-
- // cache the flag string to check whether the flags is changed.
- std::string flags_cache_;
- // cache the enable_graph_kernel value to check whether the context is changed.
- bool enable_graph_kernel_;
- };
- } // namespace context
- } // namespace mindspore
- #endif // MINDSPORE_CCSRC_UTILS_GRAPH_KERNEL_FLAGS_H
|