From 0d5f1fba6029a449089f8b3d5312eb31dca5ecb6 Mon Sep 17 00:00:00 2001 From: jjfeing Date: Tue, 21 Jul 2020 21:38:24 +0800 Subject: [PATCH] check tbe kernel property in kernel select process --- .../tbe_kernel_select/tbe_kernel_select.cc | 5 ++ .../tbe_kernel_select/tbe_property_checker.cc | 53 +++++++++++++++++++ .../tbe_kernel_select/tbe_property_checker.h | 33 ++++++++++++ .../frontend/parallel/ops_info/ops_utils.h | 1 + 4 files changed, 92 insertions(+) create mode 100644 mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc create mode 100644 mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc index 21f2347629a..e83502a7c6f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc @@ -31,6 +31,7 @@ #include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.h" #include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h" #include "backend/kernel_compiler/tbe/tbe_kernel_select/common_utils.h" +#include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h" namespace mindspore { namespace kernel { @@ -59,6 +60,10 @@ void TbeKernelSelect::TbeMetadataInfoEx() { MS_LOG(INFO) << "Warning: Cann't find tbe core opinfo, node type: " << node_name_; return; } + if (!TbePropertyChecker::CheckTbeProperties(cnode_ptr_)) { + MS_LOG(INFO) << "Warning: node(" << cnode_ptr_->fullname_with_scope() << ") not support tbe aicore."; + return; + } MS_LOG(INFO) << "Start to tbe metadata info. node type: " << node_name_ << ", node name: " << cnode_ptr_->fullname_with_scope(); OpPattern pattern = op_info_ptr->op_pattern(); diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc new file mode 100644 index 00000000000..0ce5e778801 --- /dev/null +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc @@ -0,0 +1,53 @@ +/** + * Copyright 2020 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. + */ +#include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h" +#include +#include +#include +#include "backend/session/anf_runtime_algorithm.h" +#include "frontend/parallel/ops_info/ops_utils.h" + +namespace mindspore { +namespace kernel { +using CheckSupportFun = bool (*)(const CNodePtr &cnode); + +constexpr char kAttrStrides[] = "strides"; + +static bool CheckStridedSlice(const CNodePtr &cnode) { + // check stride[-1] != 1 TODO + if (AnfAlgo::HasNodeAttr(kAttrStrides, cnode)) { + auto strides = AnfAlgo::GetNodeAttr>(cnode, kAttrStrides); + if (!strides.empty() && strides[strides.size() - 1] == 1) { + return true; + } + } + // last tensor TODO + return true; +} + +bool TbePropertyChecker::CheckTbeProperties(const mindspore::CNodePtr &cnode) { + MS_EXCEPTION_IF_NULL(cnode); + static std::map tbe_property_checker = {{parallel::KStridedSlice, CheckStridedSlice}}; + auto cnode_type = AnfAlgo::GetCNodeName(cnode); + auto find_iter = tbe_property_checker.find(cnode_type); + if (find_iter != tbe_property_checker.end()) { + return find_iter->second(cnode); + } + return true; +} + +} // namespace kernel +} // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h new file mode 100644 index 00000000000..f3fb6b60c32 --- /dev/null +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.h @@ -0,0 +1,33 @@ +/** + * Copyright 2020 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_BACKEND_KERNEL_COMPILER_TBE_TBE_KERNEL_SELECT_TBE_PROPERTY_CHECKER_H +#define MINDSPORE_BACKEND_KERNEL_COMPILER_TBE_TBE_KERNEL_SELECT_TBE_PROPERTY_CHECKER_H +#include "mindspore/core/ir/anf.h" + +namespace mindspore { +namespace kernel { +class TbePropertyChecker { + public: + TbePropertyChecker() = default; + ~TbePropertyChecker() = default; + static bool CheckTbeProperties(const mindspore::CNodePtr &cnode); +}; + +} // namespace kernel +} // namespace mindspore + +#endif // MINDSPORE_BACKEND_KERNEL_COMPILER_TBE_TBE_KERNEL_SELECT_TBE_PROPERTY_CHECKER_H diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h b/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h index 434ddce6f13..aacbe2e7149 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h @@ -232,6 +232,7 @@ constexpr char UNSORTEF_SEGMENT_PRODD[] = "UnsortedSegmentProdD"; constexpr char DEPTHWISE_CONV2D_NATIVE[] = "DepthwiseConv2dNative"; constexpr char DEPTHWISE_CONV2D[] = "DepthwiseConv2D"; constexpr char ADD[] = "Add"; +constexpr char KStridedSlice[] = "StridedSlice"; // Parallel don't care constexpr char TUPLE_GETITEM[] = "tuple_getitem";