forked from mindspore-Ecosystem/mindspore
code review
This commit is contained in:
parent
1f3a5cb2ea
commit
42b08f2fb7
|
@ -9,7 +9,7 @@ if(BUILD_LITE)
|
|||
else()
|
||||
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter \
|
||||
-fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
|
||||
if(ENABLE_ACL)
|
||||
if(NOT ENABLE_GLIBCXX)
|
||||
set(protobuf_CXXFLAGS "${protobuf_CXXFLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
|
||||
endif()
|
||||
set(protobuf_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
|
||||
|
|
|
@ -1491,8 +1491,8 @@ std::vector<int64_t> DfGraphConvertor::CastToInt(const ValuePtr &value) {
|
|||
cur_value = GetValue<std::vector<int64_t>>(value);
|
||||
} else {
|
||||
auto origin_value = GetValue<std::vector<int>>(value);
|
||||
std::transform(origin_value.begin(), origin_value.end(), std::back_inserter(cur_value),
|
||||
[](int index) { return static_cast<int64_t>(index); });
|
||||
(void)std::transform(origin_value.begin(), origin_value.end(), std::back_inserter(cur_value),
|
||||
[](int index) { return static_cast<int64_t>(index); });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1529,7 +1529,7 @@ void DfGraphConvertor::ConvertReshape(const CNodePtr node) {
|
|||
std::vector<int64_t> list;
|
||||
list = CastToInt(value);
|
||||
|
||||
op->SetAttr("shape", list);
|
||||
(void)op->SetAttr("shape", list);
|
||||
op_cache_[node.get()] = op;
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ void FuncGraph::DropNode(const AnfNodePtr &node) {
|
|||
}
|
||||
auto graph = node->func_graph();
|
||||
if (node->isa<Parameter>()) {
|
||||
parameters_.erase(std::remove(parameters_.begin(), parameters_.end(), node), parameters_.end());
|
||||
(void)parameters_.erase(std::remove(parameters_.begin(), parameters_.end(), node), parameters_.end());
|
||||
}
|
||||
// Remove the node from order list.
|
||||
if (graph) {
|
||||
|
|
|
@ -250,11 +250,8 @@ if(ENABLE_ASAN)
|
|||
endif()
|
||||
|
||||
if(MSLITE_ENABLE_ACL)
|
||||
set(ENABLE_ACL on)
|
||||
add_definitions(-D ENABLE_LITE_ACL)
|
||||
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-shlib-undefined")
|
||||
|
||||
if(DEFINED ENV{ASCEND_CUSTOM_PATH})
|
||||
set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
|
||||
else()
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "common/log_adapter.h"
|
||||
#include "acl/acl.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
std::shared_ptr<AclEnvGuard> AclEnvGuard::global_acl_env_ = nullptr;
|
||||
std::mutex AclEnvGuard::global_acl_env_mutex_;
|
||||
|
@ -63,4 +63,4 @@ std::shared_ptr<AclEnvGuard> AclEnvGuard::GetAclEnv(std::string_view cfg_file) {
|
|||
return acl_env;
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
#include <mutex>
|
||||
#include "acl/acl_base.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
class __attribute__((visibility("default"))) AclEnvGuard {
|
||||
class AclEnvGuard {
|
||||
public:
|
||||
explicit AclEnvGuard(std::string_view cfg_file);
|
||||
~AclEnvGuard();
|
||||
|
@ -37,6 +37,6 @@ class __attribute__((visibility("default"))) AclEnvGuard {
|
|||
aclError errno_;
|
||||
};
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
|
||||
#endif // LITE_ACL_ENV_GUARD_H
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* 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_LITE_SRC_RUNTIME_AGENT_ACL_MODEL_OPTIONS_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_AGENT_ACL_MODEL_OPTIONS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
typedef struct AclModelOptions {
|
||||
int32_t device_id_;
|
||||
std::string dump_cfg_path_;
|
||||
} AclModelOptions;
|
||||
|
||||
} // namespace acl
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_AGENT_ACL_MODEL_OPTIONS_H_
|
|
@ -20,7 +20,7 @@
|
|||
#include "include/registry/register_kernel_interface.h"
|
||||
#include "common/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
Status CustomInterface::Infer(std::vector<mindspore::MSTensor> *inputs, std::vector<mindspore::MSTensor> *outputs,
|
||||
const mindspore::schema::Primitive *primitive) {
|
||||
|
@ -44,15 +44,15 @@ Status CustomInterface::Infer(std::vector<mindspore::MSTensor> *inputs, std::vec
|
|||
}
|
||||
|
||||
std::shared_ptr<mindspore::kernel::KernelInterface> CustomInferCreater() {
|
||||
auto infer = new (std::nothrow) CustomInterface();
|
||||
auto infer = std::make_shared<CustomInterface>();
|
||||
if (infer == nullptr) {
|
||||
MS_LOG(ERROR) << "New custom infer is nullptr";
|
||||
return nullptr;
|
||||
}
|
||||
return std::shared_ptr<mindspore::kernel::KernelInterface>(infer);
|
||||
return infer;
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
REGISTER_CUSTOM_KERNEL_INTERFACE(ACL, ACL, acl::CustomInferCreater);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <vector>
|
||||
#include "include/kernel_interface.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
class CustomInterface : public mindspore::kernel::KernelInterface {
|
||||
public:
|
||||
|
@ -30,5 +30,5 @@ class CustomInterface : public mindspore::kernel::KernelInterface {
|
|||
const mindspore::schema::Primitive *primitive) override;
|
||||
};
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_ACL_CUSTOM_INTERFACE_H_
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
#include "include/api/types.h"
|
||||
#include "include/api/data_type.h"
|
||||
#include "src/runtime/kernel/ascend310/src/model_infer.h"
|
||||
#include "src/common/log_util.h"
|
||||
#include "common/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
CustomAscend310Kernel::CustomAscend310Kernel(const std::vector<mindspore::MSTensor> &inputs,
|
||||
const std::vector<mindspore::MSTensor> &outputs,
|
||||
|
@ -37,6 +38,34 @@ CustomAscend310Kernel::~CustomAscend310Kernel() {
|
|||
}
|
||||
}
|
||||
|
||||
AclModelOptions CustomAscend310Kernel::GetAclModelOptions(const mindspore::Context *ctx) const {
|
||||
AclModelOptions options;
|
||||
options.device_id_ = 0;
|
||||
if (ctx == nullptr) {
|
||||
MS_LOG(WARNING) << "Context is nullptr.";
|
||||
return options;
|
||||
}
|
||||
auto context = const_cast<mindspore::Context *>(ctx);
|
||||
auto device_infos = context->MutableDeviceInfo();
|
||||
if (device_infos.size() != 1) {
|
||||
MS_LOG(WARNING) << "Size of device infos is not one.";
|
||||
return options;
|
||||
}
|
||||
if (device_infos[0] == nullptr) {
|
||||
MS_LOG(WARNING) << "Device info is nullptr.";
|
||||
return options;
|
||||
}
|
||||
auto ascend31o_info = device_infos[0]->Cast<Ascend310DeviceInfo>();
|
||||
if (ascend31o_info == nullptr) {
|
||||
MS_LOG(WARNING) << "Ascend310 info is nullptr.";
|
||||
return options;
|
||||
}
|
||||
|
||||
options.device_id_ = static_cast<int32_t>(ascend31o_info->GetDeviceID());
|
||||
options.dump_cfg_path_ = ascend31o_info->GetDumpConfigPath();
|
||||
return options;
|
||||
}
|
||||
|
||||
STATUS CustomAscend310Kernel::PrepareModelInfer() {
|
||||
if (inputs_.size() < 1) {
|
||||
MS_LOG(ERROR) << "Inputs size should not less than 1.";
|
||||
|
@ -46,7 +75,9 @@ STATUS CustomAscend310Kernel::PrepareModelInfer() {
|
|||
int idx = inputs_.size() - 1;
|
||||
Buffer om_data(inputs_[idx].Data().get(), inputs_[idx].DataSize());
|
||||
if (model_infer_ == nullptr) {
|
||||
model_infer_.reset(new ModelInfer(om_data, 0));
|
||||
auto options = GetAclModelOptions(context_);
|
||||
model_infer_ = std::make_shared<ModelInfer>(om_data, options);
|
||||
CHECK_NULL_RETURN(model_infer_);
|
||||
}
|
||||
int ret = model_infer_->Init();
|
||||
if (ret != lite::RET_OK) {
|
||||
|
@ -119,7 +150,7 @@ std::shared_ptr<kernel::Kernel> CustomCreateKernel(const std::vector<mindspore::
|
|||
return kernel;
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
namespace mindspore {
|
||||
namespace registry {
|
||||
namespace {
|
||||
|
@ -127,8 +158,8 @@ const auto kFloat32 = DataType::kNumberTypeFloat32;
|
|||
const auto kInt8 = DataType::kNumberTypeInt8;
|
||||
const auto kUInt8 = DataType::kNumberTypeUInt8;
|
||||
} // namespace
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kFloat32, ACL, acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kInt8, ACL, acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kUInt8, ACL, acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kFloat32, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kInt8, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND310, ACL, kUInt8, ACL, kernel::acl::CustomCreateKernel)
|
||||
} // namespace registry
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -19,16 +19,17 @@
|
|||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "src/runtime/kernel/ascend310/src/acl_model_options.h"
|
||||
#include "src/runtime/kernel/ascend310/src/model_infer.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/api/context.h"
|
||||
#include "include/api/kernel.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "src/runtime/kernel/ascend310/src/model_infer.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
using mindspore::lite::STATUS;
|
||||
|
||||
namespace mindspore {
|
||||
namespace acl {
|
||||
class CustomAscend310Kernel : public kernel::Kernel {
|
||||
public:
|
||||
CustomAscend310Kernel(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs,
|
||||
|
@ -41,11 +42,12 @@ class CustomAscend310Kernel : public kernel::Kernel {
|
|||
|
||||
private:
|
||||
STATUS PrepareModelInfer();
|
||||
AclModelOptions GetAclModelOptions(const mindspore::Context *ctx) const;
|
||||
|
||||
bool load_model_;
|
||||
std::shared_ptr<ModelInfer> model_infer_;
|
||||
};
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ASCEND310_FP32_CUSTOM_H_
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ASCEND310_KERNEL_CUSTOM_H_
|
||||
|
|
|
@ -18,15 +18,15 @@
|
|||
#include "common/log_adapter.h"
|
||||
#include "acl/acl.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
ModelInfer::ModelInfer(const Buffer &om_data, int32_t device_id)
|
||||
ModelInfer::ModelInfer(const Buffer &om_data, const AclModelOptions &options)
|
||||
: init_flag_(false),
|
||||
load_flag_(false),
|
||||
device_type_("AscendCL"),
|
||||
device_id_(device_id),
|
||||
context_(nullptr),
|
||||
om_data_(om_data),
|
||||
options_(options),
|
||||
model_process_(),
|
||||
acl_env_(nullptr) {}
|
||||
|
||||
|
@ -36,20 +36,20 @@ STATUS ModelInfer::Init() {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
acl_env_ = AclEnvGuard::GetAclEnv("");
|
||||
acl_env_ = AclEnvGuard::GetAclEnv(options_.dump_cfg_path_);
|
||||
if (acl_env_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Acl init failed.";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
|
||||
aclError ret = aclrtSetDevice(device_id_);
|
||||
int32_t device_id = options_.device_id_;
|
||||
aclError ret = aclrtSetDevice(device_id);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
MS_LOG(ERROR) << "Acl open device " << device_id_ << " failed.";
|
||||
MS_LOG(ERROR) << "Acl open device " << device_id << " failed.";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
MS_LOG(INFO) << "Open device " << device_id_ << " success.";
|
||||
MS_LOG(INFO) << "Open device " << device_id << " success.";
|
||||
|
||||
ret = aclrtCreateContext(&context_, device_id_);
|
||||
ret = aclrtCreateContext(&context_, device_id);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
MS_LOG(ERROR) << "Acl create context failed.";
|
||||
return lite::RET_ERROR;
|
||||
|
@ -66,7 +66,7 @@ STATUS ModelInfer::Init() {
|
|||
model_process_.SetIsDevice(is_device);
|
||||
MS_LOG(INFO) << "Get run mode success is device input/output " << is_device;
|
||||
|
||||
MS_LOG(INFO) << "Init acl success, device id " << device_id_;
|
||||
MS_LOG(INFO) << "Init acl success, device id " << device_id;
|
||||
init_flag_ = true;
|
||||
return lite::RET_OK;
|
||||
}
|
||||
|
@ -98,12 +98,13 @@ STATUS ModelInfer::Finalize() {
|
|||
}
|
||||
MS_LOG(INFO) << "End to destroy context.";
|
||||
|
||||
rt_ret = aclrtResetDevice(device_id_);
|
||||
rt_ret = aclrtResetDevice(options_.device_id_);
|
||||
if (rt_ret != ACL_ERROR_NONE) {
|
||||
MS_LOG(ERROR) << "Reset device " << device_id_ << " failed.";
|
||||
MS_LOG(ERROR) << "Reset device " << options_.device_id_ << " failed.";
|
||||
}
|
||||
MS_LOG(INFO) << "End to reset device " << device_id_;
|
||||
MS_LOG(INFO) << "End to reset device " << options_.device_id_;
|
||||
init_flag_ = false;
|
||||
load_flag_ = false;
|
||||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
|
@ -159,4 +160,4 @@ STATUS ModelInfer::Inference(const std::vector<mindspore::MSTensor> &inputs,
|
|||
return model_process_.PredictFromHost(inputs, outputs);
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -22,16 +22,17 @@
|
|||
#include <string>
|
||||
#include "src/runtime/kernel/ascend310/src/model_process.h"
|
||||
#include "src/runtime/kernel/ascend310/src/acl_env_guard.h"
|
||||
#include "src/runtime/kernel/ascend310/src/acl_model_options.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/errorcode.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
using mindspore::lite::STATUS;
|
||||
|
||||
namespace mindspore {
|
||||
namespace acl {
|
||||
class ModelInfer {
|
||||
public:
|
||||
ModelInfer(const Buffer &om_data, int32_t device_id);
|
||||
ModelInfer(const Buffer &om_data, const AclModelOptions &options);
|
||||
~ModelInfer() = default;
|
||||
|
||||
STATUS Init();
|
||||
|
@ -45,12 +46,12 @@ class ModelInfer {
|
|||
bool init_flag_;
|
||||
bool load_flag_;
|
||||
std::string device_type_;
|
||||
int32_t device_id_;
|
||||
aclrtContext context_;
|
||||
Buffer om_data_;
|
||||
AclModelOptions options_;
|
||||
ModelProcess model_process_;
|
||||
std::shared_ptr<AclEnvGuard> acl_env_;
|
||||
};
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_AGENT_ACL_MODEL_INFER_H_
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <map>
|
||||
#include "common/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
namespace {
|
||||
constexpr size_t kDynamicBatchSize = 1;
|
||||
|
@ -226,7 +226,7 @@ STATUS ModelProcess::InitOutputsBuffer() {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
aclFormat format = aclmdlGetOutputFormat(model_desc_, i);
|
||||
if (format != aclFormat::ACL_FORMAT_NCHW) {
|
||||
if (format != aclFormat::ACL_FORMAT_NCHW && format != aclFormat::ACL_FORMAT_ND) {
|
||||
MS_LOG(WARNING) << "The output format of om should be nchw, but now is " << format;
|
||||
}
|
||||
aclDataType data_type = aclmdlGetOutputDataType(model_desc_, i);
|
||||
|
@ -573,4 +573,4 @@ STATUS ModelProcess::ConstructTensor(std::vector<mindspore::MSTensor> *outputs)
|
|||
return lite::RET_OK;
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -26,10 +26,9 @@
|
|||
#include "include/api/types.h"
|
||||
#include "include/errorcode.h"
|
||||
|
||||
using mindspore::lite::STATUS;
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindspore::kernel {
|
||||
namespace acl {
|
||||
using mindspore::lite::STATUS;
|
||||
struct AclTensorInfo {
|
||||
void *cur_device_data;
|
||||
void *device_data;
|
||||
|
@ -91,5 +90,5 @@ class ModelProcess {
|
|||
std::vector<AclTensorInfo> output_infos_;
|
||||
};
|
||||
} // namespace acl
|
||||
} // namespace mindspore
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_AGENT_ACL_MODEL_PROCESS_H_
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
add_definitions(-DPRIMITIVE_WRITEABLE)
|
||||
add_definitions(-DUSE_GLOG)
|
||||
|
||||
if(MSLITE_ENABLE_ACL)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-shlib-undefined")
|
||||
endif()
|
||||
|
||||
set(CCSRC_SRC
|
||||
${CCSRC_DIR}/backend/optimizer/common/pattern_engine.cc
|
||||
${CCSRC_DIR}/backend/optimizer/common/visit.cc
|
||||
|
@ -138,7 +142,6 @@ add_subdirectory(${CORE_DIR} mindspore_core)
|
|||
if(MSLITE_ENABLE_ACL)
|
||||
set(MODE_ASCEND_ACL ON)
|
||||
include(${TOP_DIR}/cmake/dependency_graphengine.cmake)
|
||||
|
||||
add_subdirectory(acl)
|
||||
link_directories(${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
endif()
|
||||
|
|
|
@ -11,10 +11,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|||
file(GLOB ACL_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/deparser/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mapper/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/infer/*.cc
|
||||
)
|
||||
|
||||
set(ENABLE_ACL on)
|
||||
|
||||
add_subdirectory(${TOP_DIR}/mindspore/ccsrc/transform/graph_ir _mindspore_transform_graph_ir_obj)
|
||||
add_subdirectory(${TOP_DIR}/mindspore/ccsrc/cxx_api mindspore_shared_lib)
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include "tools/converter/ops/ops_def.h"
|
||||
#include "tools/common/graph_util.h"
|
||||
#include "tools/common/tensor_util.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/spatial_node_adapter.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/spatial_node_adapter.h"
|
||||
#include "tools/converter/parser/parser_utils.h"
|
||||
#include "tools/converter/optimizer_manager.h"
|
||||
#include "include/registry/pass_registry.h"
|
||||
|
@ -29,6 +29,7 @@
|
|||
#include "base/core_ops.h"
|
||||
#include "cxx_api/model/acl/model_converter.h"
|
||||
#include "backend/kernel_compiler/cpu/nnacl/op_base.h"
|
||||
#include "src/common/log_util.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt {
|
||||
|
@ -36,7 +37,7 @@ namespace {
|
|||
constexpr auto kMakeTuple = "MakeTuple";
|
||||
constexpr auto kOutputNames = "outputs_names";
|
||||
constexpr auto kCustomPrimTypeACL = "ACL";
|
||||
constexpr auto kCustomNodeName = "Custom";
|
||||
constexpr auto kCustomNodeName = "Custom_0";
|
||||
} // namespace
|
||||
|
||||
ParameterPtr AclPass::CreateOmParameter(const FuncGraphPtr &func_graph, const Buffer &om_data) {
|
||||
|
@ -83,7 +84,7 @@ STATUS AclPass::BuildGraph(const FuncGraphPtr &func_graph) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
STATUS AclPass::RunPrimitiveDeparser(const FuncGraphPtr &func_graph) {
|
||||
STATUS AclPass::RunPrimitiveMapper(const FuncGraphPtr &func_graph) {
|
||||
MS_LOG(INFO) << "Deparser graph start.";
|
||||
MS_ASSERT(func_graph != nullptr);
|
||||
std::set<FuncGraphPtr> all_func_graphs = {};
|
||||
|
@ -101,13 +102,13 @@ STATUS AclPass::RunPrimitiveDeparser(const FuncGraphPtr &func_graph) {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
auto name = prim->name();
|
||||
auto deparser = lite::PrimitiveDeparserRegister::GetInstance().GetPrimitiveDeparser(name);
|
||||
if (deparser == nullptr) {
|
||||
MS_LOG(DEBUG) << "Name: " << name << " not need to deparser.";
|
||||
auto mapper = lite::PrimitiveMapperRegister::GetInstance().GetPrimitiveMapper(name);
|
||||
if (mapper == nullptr) {
|
||||
MS_LOG(DEBUG) << "Name: " << name << " not need to mapper.";
|
||||
continue;
|
||||
}
|
||||
MS_LOG(INFO) << "Deparser cnode: " << name;
|
||||
auto status = deparser->Deparser(cnode);
|
||||
auto status = mapper->Mapper(cnode);
|
||||
if (status != lite::RET_OK) {
|
||||
MS_LOG(ERROR) << "Deparser primitive failed.";
|
||||
return lite::RET_ERROR;
|
||||
|
@ -119,11 +120,11 @@ STATUS AclPass::RunPrimitiveDeparser(const FuncGraphPtr &func_graph) {
|
|||
|
||||
STATUS AclPass::DeparseGraph(const FuncGraphPtr &func_graph, const FuncGraphManagerPtr &manager) {
|
||||
if (fmk_type_ == converter::kFmkTypeMs) {
|
||||
MS_LOG(INFO) << "MindIr no need to deparser graph";
|
||||
MS_LOG(INFO) << "MindIr no need to mapper graph";
|
||||
return lite::RET_OK;
|
||||
}
|
||||
if (RunPrimitiveDeparser(func_graph) != lite::RET_OK) {
|
||||
MS_LOG(ERROR) << "Run deparser primitive failed.";
|
||||
if (RunPrimitiveMapper(func_graph) != lite::RET_OK) {
|
||||
MS_LOG(ERROR) << "Run mapper primitive failed.";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
#include "include/registry/parser_context.h"
|
||||
#include "cxx_api/model/acl/acl_model_options.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt {
|
||||
using mindspore::converter::FmkType;
|
||||
using mindspore::lite::STATUS;
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt {
|
||||
class AclPass : public Pass {
|
||||
public:
|
||||
explicit AclPass(FmkType fmk_type) : Pass("Acl"), fmk_type_(fmk_type) {}
|
||||
|
@ -42,7 +42,7 @@ class AclPass : public Pass {
|
|||
STATUS PreProcGraph(const FuncGraphPtr &func_graph);
|
||||
STATUS PostProcGraph(const FuncGraphPtr &func_graph);
|
||||
STATUS DeparseGraph(const FuncGraphPtr &func_graph, const FuncGraphManagerPtr &manager);
|
||||
STATUS RunPrimitiveDeparser(const FuncGraphPtr &func_graph);
|
||||
STATUS RunPrimitiveMapper(const FuncGraphPtr &func_graph);
|
||||
STATUS BuildGraph(const FuncGraphPtr &func_graph);
|
||||
STATUS ConvertGraphToOm(const FuncGraphPtr &func_graph, Buffer *om_data);
|
||||
ParameterPtr CreateOmParameter(const FuncGraphPtr &func_graph, const Buffer &om);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "tools/converter/acl/common/utils.h"
|
||||
#include <functional>
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "base/base_ref.h"
|
||||
#include "base/core_ops.h"
|
||||
|
@ -120,6 +121,41 @@ TypeId GetTypeFromNode(const AnfNodePtr &node) {
|
|||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
std::vector<int> GetIntParameterData(const ParameterPtr ¶m_ptr) {
|
||||
std::vector<int> result;
|
||||
if (param_ptr == nullptr) {
|
||||
MS_LOG(DEBUG) << "Param is nullptr.";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!param_ptr->has_default()) {
|
||||
MS_LOG(DEBUG) << "Param has not default.";
|
||||
return result;
|
||||
}
|
||||
auto default_param = param_ptr->default_param();
|
||||
if (!utils::isa<tensor::TensorPtr>(default_param)) {
|
||||
MS_LOG(DEBUG) << "Tensor info is not tensor::TensorPtr.";
|
||||
return result;
|
||||
}
|
||||
auto default_param_ptr = utils::cast<tensor::TensorPtr>(default_param);
|
||||
if (default_param_ptr == nullptr) {
|
||||
MS_LOG(DEBUG) << "Default param ptr is nullptr.";
|
||||
return result;
|
||||
}
|
||||
if (default_param_ptr->data_type() != kNumberTypeInt32 && default_param_ptr->data_type() != kNumberTypeInt) {
|
||||
MS_LOG(DEBUG) << "Default param is not int.";
|
||||
return result;
|
||||
}
|
||||
|
||||
auto ptr = reinterpret_cast<int *>(default_param_ptr->data_c());
|
||||
int64_t shape_size =
|
||||
std::accumulate(default_param_ptr->shape().begin(), default_param_ptr->shape().end(), 1, std::multiplies<int>());
|
||||
for (int i = 0; i < shape_size; i++) {
|
||||
result.emplace_back(ptr[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace acl
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace acl {
|
|||
STATUS GetShapeVectorFromCNode(const mindspore::CNodePtr &cnode, std::vector<int64_t> *shape_vector);
|
||||
|
||||
TypeId GetTypeFromNode(const AnfNodePtr &node);
|
||||
|
||||
std::vector<int> GetIntParameterData(const ParameterPtr ¶m_ptr);
|
||||
} // namespace acl
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* 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 ACL_DEPARSER_PRIMITIVE_DEPARSER_REGISTER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_DEPARSER_REGISTER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "ir/anf.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class PrimitiveDeparserRegister {
|
||||
public:
|
||||
static PrimitiveDeparserRegister &GetInstance();
|
||||
|
||||
void InsertPrimitiveDeparser(const std::string &name, const PrimitiveDeparserPtr &deparser);
|
||||
|
||||
PrimitiveDeparserPtr GetPrimitiveDeparser(const std::string &name);
|
||||
|
||||
private:
|
||||
PrimitiveDeparserRegister() = default;
|
||||
~PrimitiveDeparserRegister() = default;
|
||||
|
||||
std::map<std::string, PrimitiveDeparserPtr> deparser_;
|
||||
};
|
||||
|
||||
class RegisterPrimitiveDeparser {
|
||||
public:
|
||||
RegisterPrimitiveDeparser(const std::string &name, const PrimitiveDeparserPtr &deparser);
|
||||
|
||||
~RegisterPrimitiveDeparser() = default;
|
||||
};
|
||||
|
||||
#define REGISTER_PRIMITIVE_DEPARSER(name, deparser) \
|
||||
static RegisterPrimitiveDeparser g_##name##PrimDeparser(name, std::make_shared<deparser>());
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_DEPARSER_REGISTER_H
|
|
@ -14,10 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/activation_deparser.h"
|
||||
#include "tools/converter/acl/mapper/activation_mapper.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "ops/elu.h"
|
||||
#include "ops/gelu.h"
|
||||
#include "ops/leaky_relu.h"
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS ActivationDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS ActivationMapper::Mapper(const CNodePtr &cnode) {
|
||||
static std::map<ActivationType, PrimitivePtr> activation_type_map = {
|
||||
{mindspore::ELU, std::make_shared<ops::Elu>()},
|
||||
{mindspore::GELU, std::make_shared<ops::GeLU>()},
|
||||
|
@ -62,6 +62,6 @@ STATUS ActivationDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameActivation, ActivationDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameActivation, ActivationMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_ACTIVATION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_ACTIVATION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_ACTIVATION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_ACTIVATION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/activation.h"
|
||||
|
||||
using mindspore::ops::kNameActivation;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class ActivationDeparser : public PrimitiveDeparser {
|
||||
class ActivationMapper : public PrimitiveMapper {
|
||||
public:
|
||||
ActivationDeparser() : PrimitiveDeparser(kNameActivation) {}
|
||||
ActivationMapper() : PrimitiveMapper(kNameActivation) {}
|
||||
|
||||
~ActivationDeparser() override = default;
|
||||
~ActivationMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_ACTIVATION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_ACTIVATION_MAPPER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/add_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/add_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS AddFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS AddFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
auto dst_prim = std::make_shared<ops::Add>();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "AddFusion deparser failed.";
|
||||
MS_LOG(ERROR) << "AddFusion mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameAddFusion, AddFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameAddFusion, AddFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_ADDFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_ADDFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_ADDFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_ADDFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/add_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameAddFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class AddFusionDeparser : public PrimitiveDeparser {
|
||||
class AddFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
AddFusionDeparser() : PrimitiveDeparser(kNameAddFusion) {}
|
||||
AddFusionMapper() : PrimitiveMapper(kNameAddFusion) {}
|
||||
|
||||
~AddFusionDeparser() override = default;
|
||||
~AddFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_ADDFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_ADDFUSION_MAPPER_H
|
|
@ -14,15 +14,15 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/avgpool_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/avgpool_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS AvgPoolFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS AvgPoolFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -58,6 +58,6 @@ STATUS AvgPoolFusionDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameAvgPoolFusion, AvgPoolFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameAvgPoolFusion, AvgPoolFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_AVGPOOLFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_AVGPOOLFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_AVGPOOLFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_AVGPOOLFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/avg_pool_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameAvgPoolFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class AvgPoolFusionDeparser : public PrimitiveDeparser {
|
||||
class AvgPoolFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
AvgPoolFusionDeparser() : PrimitiveDeparser(kNameAvgPoolFusion) {}
|
||||
~AvgPoolFusionDeparser() override = default;
|
||||
AvgPoolFusionMapper() : PrimitiveMapper(kNameAvgPoolFusion) {}
|
||||
~AvgPoolFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_AVGPOOLFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_AVGPOOLFUSION_MAPPER_H
|
|
@ -14,15 +14,15 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/batchnorm_deparser.h"
|
||||
#include "tools/converter/acl/mapper/batchnorm_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS BatchNormDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS BatchNormMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -35,13 +35,13 @@ STATUS BatchNormDeparser::Deparser(const CNodePtr &cnode) {
|
|||
if (fmk_type == converter::kFmkTypeCaffe) {
|
||||
auto dst_prim = std::make_shared<acl::BNInference>();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "BatchNorm deparser failed.";
|
||||
MS_LOG(ERROR) << "BatchNorm mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameBatchNorm, BatchNormDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameBatchNorm, BatchNormMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_BATCHNORM_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_BATCHNORM_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_BATCHNORM_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_BATCHNORM_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/batch_norm.h"
|
||||
|
||||
using mindspore::ops::kNameBatchNorm;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class BatchNormDeparser : public PrimitiveDeparser {
|
||||
class BatchNormMapper : public PrimitiveMapper {
|
||||
public:
|
||||
BatchNormDeparser() : PrimitiveDeparser(kNameBatchNorm) {}
|
||||
BatchNormMapper() : PrimitiveMapper(kNameBatchNorm) {}
|
||||
|
||||
~BatchNormDeparser() override = default;
|
||||
~BatchNormMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_BATCHNORM_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_BATCHNORM_MAPPER_H
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/cast_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "tools/converter/acl/mapper/cast_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/common/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -24,7 +24,7 @@ namespace {
|
|||
constexpr size_t kNameCastInputNum = 3;
|
||||
} // namespace
|
||||
|
||||
STATUS CastDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS CastMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (cnode == nullptr) {
|
||||
MS_LOG(ERROR) << "Cnode is nullptr.";
|
||||
return lite::RET_ERROR;
|
||||
|
@ -40,7 +40,7 @@ STATUS CastDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
ParameterPtr to_param = to_input->cast<ParameterPtr>();
|
||||
auto data = opt::GetIntParameterData(to_param);
|
||||
auto data = acl::GetIntParameterData(to_param);
|
||||
int dst_type = data.empty() ? kNumberTypeInt32 : data.front();
|
||||
TypePtr type_ptr = TypeIdToType(TypeId(dst_type));
|
||||
if (type_ptr == nullptr) {
|
||||
|
@ -56,6 +56,6 @@ STATUS CastDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameCast, CastDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameCast, CastMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_CAST_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_CAST_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_CAST_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_CAST_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/cast.h"
|
||||
|
||||
using mindspore::ops::kNameCast;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class CastDeparser : public PrimitiveDeparser {
|
||||
class CastMapper : public PrimitiveMapper {
|
||||
public:
|
||||
CastDeparser() : PrimitiveDeparser(kNameCast) {}
|
||||
CastMapper() : PrimitiveMapper(kNameCast) {}
|
||||
|
||||
~CastDeparser() override = default;
|
||||
~CastMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_CAST_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_CAST_MAPPER_H
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/concat_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/concat_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -23,15 +23,15 @@ namespace {
|
|||
constexpr auto kNameInputNums = "inputNums";
|
||||
}
|
||||
|
||||
STATUS ConcatDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS ConcatMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (AddAttrForDynInputPrimitive(cnode) != RET_OK) {
|
||||
MS_LOG(ERROR) << "Concat deparser failed.";
|
||||
MS_LOG(ERROR) << "Concat mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
STATUS ConcatDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
STATUS ConcatMapper::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
MS_ASSERT(cnode != nullptr);
|
||||
auto value_node = cnode->input(0)->cast<ValueNodePtr>();
|
||||
MS_ASSERT(value_node != nullptr);
|
||||
|
@ -48,6 +48,6 @@ STATUS ConcatDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameConcat, ConcatDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameConcat, ConcatMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,27 +14,27 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_CONCAT_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_CONCAT_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_CONCAT_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_CONCAT_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/concat.h"
|
||||
|
||||
using mindspore::ops::kNameConcat;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class ConcatDeparser : public PrimitiveDeparser {
|
||||
class ConcatMapper : public PrimitiveMapper {
|
||||
public:
|
||||
ConcatDeparser() : PrimitiveDeparser(kNameConcat) {}
|
||||
ConcatMapper() : PrimitiveMapper(kNameConcat) {}
|
||||
|
||||
~ConcatDeparser() override = default;
|
||||
~ConcatMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
|
||||
private:
|
||||
STATUS AddAttrForDynInputPrimitive(const CNodePtr &cnode);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_CONCAT_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_CONCAT_MAPPER_H
|
|
@ -14,13 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/conv2d_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/conv2d_fusion_mapper.h"
|
||||
#include "memory"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS Conv2DFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS Conv2DFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -45,6 +45,6 @@ STATUS Conv2DFusionDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameConv2DFusion, Conv2DFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameConv2DFusion, Conv2DFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_CONV2DFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_CONV2DFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_CONV2DFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_CONV2DFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/conv2d_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameConv2DFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class Conv2DFusionDeparser : public PrimitiveDeparser {
|
||||
class Conv2DFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
Conv2DFusionDeparser() : PrimitiveDeparser(kNameConv2DFusion) {}
|
||||
~Conv2DFusionDeparser() override = default;
|
||||
Conv2DFusionMapper() : PrimitiveMapper(kNameConv2DFusion) {}
|
||||
~Conv2DFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_CONV2DFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_CONV2DFUSION_MAPPER_H
|
|
@ -14,15 +14,15 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/conv2d_transpose_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/conv2d_transpose_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS Conv2dTransposeFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS Conv2dTransposeMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -49,6 +49,6 @@ STATUS Conv2dTransposeFusionDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameConv2dTransposeFusion, Conv2dTransposeFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameConv2dTransposeFusion, Conv2dTransposeMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_CONV2DTRANSPOSEFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_CONV2DTRANSPOSEFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_CONV2DTRANSPOSEFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_CONV2DTRANSPOSEFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/conv2d_transpose_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameConv2dTransposeFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class Conv2dTransposeFusionDeparser : public PrimitiveDeparser {
|
||||
class Conv2dTransposeMapper : public PrimitiveMapper {
|
||||
public:
|
||||
Conv2dTransposeFusionDeparser() : PrimitiveDeparser(kNameConv2dTransposeFusion) {}
|
||||
~Conv2dTransposeFusionDeparser() override = default;
|
||||
Conv2dTransposeMapper() : PrimitiveMapper(kNameConv2dTransposeFusion) {}
|
||||
~Conv2dTransposeMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_CONV2DTRANSPOSEFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_CONV2DTRANSPOSEFUSION_MAPPER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/eltwise_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/eltwise_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "ops/op_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS EltWiseDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS EltWiseMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (AddAttrForDynInputPrimitive(cnode) != RET_OK) {
|
||||
MS_LOG(ERROR) << "EltWise deparser failed.";
|
||||
MS_LOG(ERROR) << "EltWise mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
STATUS EltWiseDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
STATUS EltWiseMapper::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
MS_ASSERT(cnode != nullptr);
|
||||
auto value_node = cnode->input(0)->cast<ValueNodePtr>();
|
||||
MS_ASSERT(value_node != nullptr);
|
||||
|
@ -45,6 +45,6 @@ STATUS EltWiseDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameEltwise, EltWiseDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameEltwise, EltWiseMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,27 +14,27 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_ELTWISE_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_ELTWISE_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_ELTWISE_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_ELTWISE_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/eltwise.h"
|
||||
|
||||
using mindspore::ops::kNameEltwise;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class EltWiseDeparser : public PrimitiveDeparser {
|
||||
class EltWiseMapper : public PrimitiveMapper {
|
||||
public:
|
||||
EltWiseDeparser() : PrimitiveDeparser(kNameEltwise) {}
|
||||
EltWiseMapper() : PrimitiveMapper(kNameEltwise) {}
|
||||
|
||||
~EltWiseDeparser() override = default;
|
||||
~EltWiseMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
|
||||
private:
|
||||
STATUS AddAttrForDynInputPrimitive(const CNodePtr &cnode);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_ELTWISE_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_ELTWISE_MAPPER_H
|
|
@ -14,13 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/fused_batchnorm_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/fused_batchnorm_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "ops/op_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS FusedBatchNormDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS FusedBatchNormMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -31,6 +31,6 @@ STATUS FusedBatchNormDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameFusedBatchNorm, FusedBatchNormDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameFusedBatchNorm, FusedBatchNormMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_FUSEDBATCHNORM_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_FUSEDBATCHNORM_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_FUSEDBATCHNORM_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_FUSEDBATCHNORM_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fused_batch_norm.h"
|
||||
|
||||
using mindspore::ops::kNameFusedBatchNorm;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class FusedBatchNormDeparser : public PrimitiveDeparser {
|
||||
class FusedBatchNormMapper : public PrimitiveMapper {
|
||||
public:
|
||||
FusedBatchNormDeparser() : PrimitiveDeparser(kNameFusedBatchNorm) {}
|
||||
~FusedBatchNormDeparser() override = default;
|
||||
FusedBatchNormMapper() : PrimitiveMapper(kNameFusedBatchNorm) {}
|
||||
~FusedBatchNormMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_FUSEDBATCHNORM_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_FUSEDBATCHNORM_MAPPER_H
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/gather_fusion_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "tools/converter/acl/mapper/gather_fusion_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/common/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -24,7 +24,7 @@ namespace {
|
|||
constexpr size_t kNameGatherInputNum = 4;
|
||||
}
|
||||
|
||||
STATUS GatherDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS GatherMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (cnode == nullptr) {
|
||||
MS_LOG(ERROR) << "Cnode is nullptr.";
|
||||
return lite::RET_ERROR;
|
||||
|
@ -40,7 +40,7 @@ STATUS GatherDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
ParameterPtr axis_param = axis_input->cast<ParameterPtr>();
|
||||
auto data = opt::GetIntParameterData(axis_param);
|
||||
auto data = acl::GetIntParameterData(axis_param);
|
||||
int64_t axis = data.empty() ? 0 : static_cast<int64_t>(data.front());
|
||||
ValueNodePtr value_node = NewValueNode<int64_t>(axis);
|
||||
if (value_node == nullptr) {
|
||||
|
@ -51,6 +51,6 @@ STATUS GatherDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameGather, GatherDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameGather, GatherMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_GATHER_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_GATHER_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_GATHER_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_GATHER_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/gather.h"
|
||||
|
||||
using mindspore::ops::kNameGather;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class GatherDeparser : public PrimitiveDeparser {
|
||||
class GatherMapper : public PrimitiveMapper {
|
||||
public:
|
||||
GatherDeparser() : PrimitiveDeparser(kNameGather) {}
|
||||
~GatherDeparser() override = default;
|
||||
GatherMapper() : PrimitiveMapper(kNameGather) {}
|
||||
~GatherMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_GATHER_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_GATHER_MAPPER_H
|
|
@ -14,15 +14,15 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/maxpool_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/maxpool_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS MaxPoolFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS MaxPoolFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -53,6 +53,6 @@ STATUS MaxPoolFusionDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameMaxPoolFusion, MaxPoolFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameMaxPoolFusion, MaxPoolFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_MAXPOOLFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_MAXPOOLFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_MAXPOOLFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_MAXPOOLFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/max_pool_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameMaxPoolFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class MaxPoolFusionDeparser : public PrimitiveDeparser {
|
||||
class MaxPoolFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
MaxPoolFusionDeparser() : PrimitiveDeparser(kNameMaxPoolFusion) {}
|
||||
~MaxPoolFusionDeparser() override = default;
|
||||
MaxPoolFusionMapper() : PrimitiveMapper(kNameMaxPoolFusion) {}
|
||||
~MaxPoolFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_MAXPOOLFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_MAXPOOLFUSION_MAPPER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/mul_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/mul_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS MulFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS MulFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
auto dst_prim = std::make_shared<ops::Mul>();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "MulFusion deparser failed.";
|
||||
MS_LOG(ERROR) << "MulFusion mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameMulFusion, MulFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameMulFusion, MulFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_MULFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_MULFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_MULFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_MULFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/mul_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameMulFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class MulFusionDeparser : public PrimitiveDeparser {
|
||||
class MulFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
MulFusionDeparser() : PrimitiveDeparser(kNameMulFusion) {}
|
||||
MulFusionMapper() : PrimitiveMapper(kNameMulFusion) {}
|
||||
|
||||
~MulFusionDeparser() override = default;
|
||||
~MulFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_MULFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_MULFUSION_MAPPER_H
|
|
@ -14,12 +14,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/pad_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/pad_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
#include "ops/op_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
@ -29,7 +29,7 @@ constexpr size_t kNamePadInputNum = 3;
|
|||
constexpr auto kNamePadContiguous = "pad_contiguous";
|
||||
} // namespace
|
||||
|
||||
STATUS PadFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS PadFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -60,7 +60,7 @@ STATUS PadFusionDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
void PadFusionDeparser::AdjustPadAttr(const PrimitivePtr &dst_prim) {
|
||||
void PadFusionMapper::AdjustPadAttr(const PrimitivePtr &dst_prim) {
|
||||
static std::map<int64_t, std::string> kPadModeToStrMap = {
|
||||
{PaddingMode::CONSTANT, "constant"},
|
||||
{PaddingMode::REFLECT, "reflect"},
|
||||
|
@ -78,6 +78,6 @@ void PadFusionDeparser::AdjustPadAttr(const PrimitivePtr &dst_prim) {
|
|||
dst_prim->AddAttr(kNamePadContiguous, MakeValue(true));
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNamePadFusion, PadFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNamePadFusion, PadFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,26 +14,26 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_PADFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_PADFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_PADFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_PADFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/pad_fusion.h"
|
||||
|
||||
using mindspore::ops::kNamePadFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class PadFusionDeparser : public PrimitiveDeparser {
|
||||
class PadFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
PadFusionDeparser() : PrimitiveDeparser(kNamePadFusion) {}
|
||||
~PadFusionDeparser() override = default;
|
||||
PadFusionMapper() : PrimitiveMapper(kNamePadFusion) {}
|
||||
~PadFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
|
||||
private:
|
||||
void AdjustPadAttr(const PrimitivePtr &dst_prim);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_PADFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_PADFUSION_MAPPER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/prelu_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/prelu_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS PReluFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS PReluFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
auto dst_prim = std::make_shared<ops::PReLU>();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "PReluFusion deparser failed.";
|
||||
MS_LOG(ERROR) << "PReluFusion mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNamePReLUFusion, PReluFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNamePReLUFusion, PReluFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_PRELUFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_PRELUFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_PRELUFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_PRELUFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/prelu_fusion.h"
|
||||
|
||||
using mindspore::ops::kNamePReLUFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class PReluFusionDeparser : public PrimitiveDeparser {
|
||||
class PReluFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
PReluFusionDeparser() : PrimitiveDeparser(kNamePReLUFusion) {}
|
||||
~PReluFusionDeparser() override = default;
|
||||
PReluFusionMapper() : PrimitiveMapper(kNamePReLUFusion) {}
|
||||
~PReluFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_PRELUFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_PRELUFUSION_MAPPER_H
|
|
@ -14,18 +14,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "tools/converter/acl/common/utils.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "ir/graph_utils.h"
|
||||
#include "utils/log_adapter.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
#include "ops/op_utils.h"
|
||||
#include "ops/fusion/avg_pool_fusion.h"
|
||||
#include "backend/kernel_compiler/cpu/nnacl/op_base.h"
|
||||
#include "src/common/log_util.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -35,10 +35,10 @@ constexpr auto kNamePaddingMode = "padding_mode";
|
|||
constexpr auto kNameCeilMode = "ceil_mode";
|
||||
} // namespace
|
||||
|
||||
STATUS PrimitiveDeparser::Deparser(const CNodePtr &cnode) { return lite::RET_OK; }
|
||||
STATUS PrimitiveMapper::Mapper(const CNodePtr &cnode) { return lite::RET_OK; }
|
||||
|
||||
STATUS PrimitiveDeparser::GetValueNodeAndPrimFromCnode(const CNodePtr &cnode, ValueNodePtr *value_node,
|
||||
PrimitivePtr *prim_ptr) {
|
||||
STATUS PrimitiveMapper::GetValueNodeAndPrimFromCnode(const CNodePtr &cnode, ValueNodePtr *value_node,
|
||||
PrimitivePtr *prim_ptr) {
|
||||
CHECK_NULL_RETURN(cnode);
|
||||
CHECK_NULL_RETURN(value_node);
|
||||
CHECK_NULL_RETURN(prim_ptr);
|
||||
|
@ -56,7 +56,7 @@ STATUS PrimitiveDeparser::GetValueNodeAndPrimFromCnode(const CNodePtr &cnode, Va
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
STATUS PrimitiveDeparser::AttrAdjust(const PrimitivePtr &prim, const std::string &name) {
|
||||
STATUS PrimitiveMapper::AttrAdjust(const PrimitivePtr &prim, const std::string &name) {
|
||||
auto value_ptr = prim->GetAttr(name);
|
||||
if (value_ptr == nullptr) {
|
||||
MS_LOG(WARNING) << prim->name() << " has no attr " << name;
|
||||
|
@ -96,7 +96,7 @@ STATUS PrimitiveDeparser::AttrAdjust(const PrimitivePtr &prim, const std::string
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
void PrimitiveDeparser::AdjustCaffePoolAttr(const std::string &src_prim_name, const PrimitivePtr &dst_prim) {
|
||||
void PrimitiveMapper::AdjustCaffePoolAttr(const std::string &src_prim_name, const PrimitivePtr &dst_prim) {
|
||||
int64_t mode = src_prim_name == ops::kNameAvgPoolFusion ? 1 : 0;
|
||||
dst_prim->AddAttr(ops::kMode, MakeValue(mode));
|
||||
|
||||
|
@ -106,7 +106,7 @@ void PrimitiveDeparser::AdjustCaffePoolAttr(const std::string &src_prim_name, co
|
|||
dst_prim->set_attr(ops::kRoundMode, MakeValue(run_mode_ge));
|
||||
}
|
||||
|
||||
void PrimitiveDeparser::AdjustOnnxPoolAttr(const PrimitivePtr &dst_prim) {
|
||||
void PrimitiveMapper::AdjustOnnxPoolAttr(const PrimitivePtr &dst_prim) {
|
||||
static std::map<int64_t, std::string> kPadModToStrMap = {
|
||||
{PadMode::PAD, "CALCULATED"},
|
||||
{PadMode::SAME, "SAME"},
|
||||
|
@ -126,7 +126,7 @@ void PrimitiveDeparser::AdjustOnnxPoolAttr(const PrimitivePtr &dst_prim) {
|
|||
dst_prim->AddAttr(kNameCeilMode, MakeValue(ceil_mode));
|
||||
}
|
||||
|
||||
STATUS PrimitiveDeparser::AdjustPoolAttr(int fmk_type, const std::string &src_prim_name, const PrimitivePtr &dst_prim) {
|
||||
STATUS PrimitiveMapper::AdjustPoolAttr(int fmk_type, const std::string &src_prim_name, const PrimitivePtr &dst_prim) {
|
||||
if (fmk_type == converter::kFmkTypeCaffe) {
|
||||
AdjustCaffePoolAttr(src_prim_name, dst_prim);
|
||||
return lite::RET_OK;
|
||||
|
@ -147,7 +147,7 @@ STATUS PrimitiveDeparser::AdjustPoolAttr(int fmk_type, const std::string &src_pr
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
STATUS PrimitiveDeparser::MoveAttrMap(const CNodePtr &cnode, const PrimitivePtr &dst_prim) {
|
||||
STATUS PrimitiveMapper::MoveAttrMap(const CNodePtr &cnode, const PrimitivePtr &dst_prim) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -163,8 +163,8 @@ STATUS PrimitiveDeparser::MoveAttrMap(const CNodePtr &cnode, const PrimitivePtr
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
STATUS PrimitiveDeparser::AddAttrToInput(const FuncGraphPtr &func_graph, const CNodePtr &cnode,
|
||||
const PrimitivePtr &dst_prim, const std::string &attr_name, int flag) {
|
||||
STATUS PrimitiveMapper::AddAttrToInput(const FuncGraphPtr &func_graph, const CNodePtr &cnode,
|
||||
const PrimitivePtr &dst_prim, const std::string &attr_name, int flag) {
|
||||
auto attr_val = dst_prim->GetAttr(attr_name);
|
||||
if (attr_val == nullptr) {
|
||||
MS_LOG(INFO) << "There is no attr: " << attr_name;
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_MAPPER_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
@ -25,13 +25,13 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class PrimitiveDeparser {
|
||||
class PrimitiveMapper {
|
||||
public:
|
||||
explicit PrimitiveDeparser(const std::string &name) : name_(name) {}
|
||||
explicit PrimitiveMapper(const std::string &name) : name_(name) {}
|
||||
|
||||
virtual ~PrimitiveDeparser() = default;
|
||||
virtual ~PrimitiveMapper() = default;
|
||||
|
||||
virtual STATUS Deparser(const CNodePtr &cnode);
|
||||
virtual STATUS Mapper(const CNodePtr &cnode);
|
||||
|
||||
protected:
|
||||
STATUS AttrAdjust(const PrimitivePtr &prim, const std::string &name);
|
||||
|
@ -53,7 +53,7 @@ class PrimitiveDeparser {
|
|||
std::string name_;
|
||||
};
|
||||
|
||||
using PrimitiveDeparserPtr = std::shared_ptr<PrimitiveDeparser>;
|
||||
using PrimitiveMapperPtr = std::shared_ptr<PrimitiveMapper>;
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_MAPPER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
PrimitiveDeparserRegister &PrimitiveDeparserRegister::GetInstance() {
|
||||
static PrimitiveDeparserRegister instance;
|
||||
PrimitiveMapperRegister &PrimitiveMapperRegister::GetInstance() {
|
||||
static PrimitiveMapperRegister instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void PrimitiveDeparserRegister::InsertPrimitiveDeparser(const std::string &name, const PrimitiveDeparserPtr &deparser) {
|
||||
void PrimitiveMapperRegister::InsertPrimitiveMapper(const std::string &name, const PrimitiveMapperPtr &deparser) {
|
||||
deparser_[name] = deparser;
|
||||
}
|
||||
|
||||
PrimitiveDeparserPtr PrimitiveDeparserRegister::GetPrimitiveDeparser(const std::string &name) {
|
||||
PrimitiveMapperPtr PrimitiveMapperRegister::GetPrimitiveMapper(const std::string &name) {
|
||||
if (deparser_.find(name) != deparser_.end()) {
|
||||
return deparser_[name];
|
||||
} else {
|
||||
|
@ -37,8 +37,8 @@ PrimitiveDeparserPtr PrimitiveDeparserRegister::GetPrimitiveDeparser(const std::
|
|||
}
|
||||
}
|
||||
|
||||
RegisterPrimitiveDeparser::RegisterPrimitiveDeparser(const std::string &name, const PrimitiveDeparserPtr &deparser) {
|
||||
PrimitiveDeparserRegister::GetInstance().InsertPrimitiveDeparser(name, deparser);
|
||||
RegisterPrimitiveMapper::RegisterPrimitiveMapper(const std::string &name, const PrimitiveMapperPtr &deparser) {
|
||||
PrimitiveMapperRegister::GetInstance().InsertPrimitiveMapper(name, deparser);
|
||||
}
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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 ACL_MAPPER_PRIMITIVE_MAPPER_REGISTER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_MAPPER_REGISTER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "ir/anf.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class PrimitiveMapperRegister {
|
||||
public:
|
||||
static PrimitiveMapperRegister &GetInstance();
|
||||
|
||||
void InsertPrimitiveMapper(const std::string &name, const PrimitiveMapperPtr &deparser);
|
||||
|
||||
PrimitiveMapperPtr GetPrimitiveMapper(const std::string &name);
|
||||
|
||||
private:
|
||||
PrimitiveMapperRegister() = default;
|
||||
~PrimitiveMapperRegister() = default;
|
||||
|
||||
std::map<std::string, PrimitiveMapperPtr> deparser_;
|
||||
};
|
||||
|
||||
class RegisterPrimitiveMapper {
|
||||
public:
|
||||
RegisterPrimitiveMapper(const std::string &name, const PrimitiveMapperPtr &deparser);
|
||||
|
||||
~RegisterPrimitiveMapper() = default;
|
||||
};
|
||||
|
||||
#define REGISTER_PRIMITIVE_MAPPER(name, mapper) \
|
||||
static RegisterPrimitiveMapper g_##name##PrimMapper(name, std::make_shared<mapper>());
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_MAPPER_PRIMITIVE_MAPPER_REGISTER_H
|
|
@ -14,21 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/scale_fusion_deparser.h"
|
||||
#include "tools/converter/acl/mapper/scale_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS ScaleFusionDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS ScaleFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
auto dst_prim = std::make_shared<ops::Scale>();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "ScaleFusion deparser failed.";
|
||||
MS_LOG(ERROR) << "ScaleFusion mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameScaleFusion, ScaleFusionDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameScaleFusion, ScaleFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_SCALEFUSION_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_SCALEFUSION_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_SCALEFUSION_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_SCALEFUSION_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/scale_fusion.h"
|
||||
|
||||
using mindspore::ops::kNameScaleFusion;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class ScaleFusionDeparser : public PrimitiveDeparser {
|
||||
class ScaleFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
ScaleFusionDeparser() : PrimitiveDeparser(kNameScaleFusion) {}
|
||||
~ScaleFusionDeparser() override = default;
|
||||
ScaleFusionMapper() : PrimitiveMapper(kNameScaleFusion) {}
|
||||
~ScaleFusionMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_SCALEFUSION_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_SCALEFUSION_MAPPER_H
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/spatial_node_adapter.h"
|
||||
#include "tools/converter/acl/mapper/spatial_node_adapter.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
@ -25,7 +25,6 @@
|
|||
#include "include/errorcode.h"
|
||||
#include "base/base.h"
|
||||
#include "base/core_ops.h"
|
||||
#include "utils/log_adapter.h"
|
||||
#include "ops/concat.h"
|
||||
#include "ops/batch_norm.h"
|
||||
#include "ops/fused_batch_norm.h"
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_SPATIAL_NODE_ADAPTER_PASS_H
|
||||
#define ACL_DEPARSER_SPATIAL_NODE_ADAPTER_PASS_H
|
||||
#ifndef ACL_MAPPER_SPATIAL_NODE_ADAPTER_PASS_H
|
||||
#define ACL_MAPPER_SPATIAL_NODE_ADAPTER_PASS_H
|
||||
|
||||
#include "ir/func_graph.h"
|
||||
#include "include/errorcode.h"
|
||||
|
@ -26,4 +26,4 @@ STATUS AdapteSpatialNode(const FuncGraphPtr &func_graph, const FuncGraphManagerP
|
|||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // ACL_DEPARSER_SPATIAL_NODE_ADAPTER_PASS_H
|
||||
#endif // ACL_MAPPER_SPATIAL_NODE_ADAPTER_PASS_H
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/stack_deparser.h"
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/mapper/stack_mapper.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -23,15 +23,15 @@ namespace {
|
|||
constexpr auto kNameNum = "num";
|
||||
}
|
||||
|
||||
STATUS StackDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS StackMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (AddAttrForDynInputPrimitive(cnode) != RET_OK) {
|
||||
MS_LOG(ERROR) << "Stack deparser failed.";
|
||||
MS_LOG(ERROR) << "Stack mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
STATUS StackDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
STATUS StackMapper::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
||||
MS_ASSERT(cnode != nullptr);
|
||||
auto value_node = cnode->input(0)->cast<ValueNodePtr>();
|
||||
MS_ASSERT(value_node != nullptr);
|
||||
|
@ -48,6 +48,6 @@ STATUS StackDeparser::AddAttrForDynInputPrimitive(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameStack, StackDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameStack, StackMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,27 +14,27 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_STACK_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_STACK_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_STACK_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_STACK_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/stack.h"
|
||||
|
||||
using mindspore::ops::kNameStack;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class StackDeparser : public PrimitiveDeparser {
|
||||
class StackMapper : public PrimitiveMapper {
|
||||
public:
|
||||
StackDeparser() : PrimitiveDeparser(kNameStack) {}
|
||||
StackMapper() : PrimitiveMapper(kNameStack) {}
|
||||
|
||||
~StackDeparser() override = default;
|
||||
~StackMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
|
||||
private:
|
||||
STATUS AddAttrForDynInputPrimitive(const CNodePtr &cnode);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_STACK_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_STACK_MAPPER_H
|
|
@ -14,16 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/stridedslice_deparser.h"
|
||||
#include "tools/converter/acl/mapper/stridedslice_mapper.h"
|
||||
#include <memory>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/converter/acl/deparser/tbe_op_def.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/mapper/tbe_op_def.h"
|
||||
#include "include/registry/parser_context.h"
|
||||
#include "ops/op_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
STATUS StridedSliceDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS StridedSliceMapper::Mapper(const CNodePtr &cnode) {
|
||||
ValueNodePtr value_node = nullptr;
|
||||
PrimitivePtr src_prim = nullptr;
|
||||
if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) {
|
||||
|
@ -42,6 +42,6 @@ STATUS StridedSliceDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameStridedSlice, StridedSliceDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameStridedSlice, StridedSliceMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,23 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_STRIDEDSLICE_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_STRIDEDSLICE_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_STRIDEDSLICE_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_STRIDEDSLICE_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/strided_slice.h"
|
||||
|
||||
using mindspore::ops::kNameStridedSlice;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class StridedSliceDeparser : public PrimitiveDeparser {
|
||||
class StridedSliceMapper : public PrimitiveMapper {
|
||||
public:
|
||||
StridedSliceDeparser() : PrimitiveDeparser(kNameStridedSlice) {}
|
||||
~StridedSliceDeparser() override = default;
|
||||
StridedSliceMapper() : PrimitiveMapper(kNameStridedSlice) {}
|
||||
~StridedSliceMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_STRIDEDSLICE_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_STRIDEDSLICE_MAPPER_H
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_TBE_OP_DEF_H
|
||||
#define ACL_DEPARSER_TBE_OP_DEF_H
|
||||
#ifndef ACL_MAPPER_TBE_OP_DEF_H
|
||||
#define ACL_MAPPER_TBE_OP_DEF_H
|
||||
|
||||
#include "ops/primitive_c.h"
|
||||
|
||||
|
@ -49,4 +49,4 @@ ADD_CONVERTER_TBE_OP(Deconvolution)
|
|||
} // namespace acl
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_TBE_OP_DEF_H
|
||||
#endif // ACL_MAPPER_TBE_OP_DEF_H
|
|
@ -14,11 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/acl/deparser/transpose_deparser.h"
|
||||
#include "tools/converter/acl/mapper/transpose_mapper.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "tools/converter/acl/deparser/primitive_deparser_register.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/acl/common/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
@ -26,7 +26,7 @@ namespace {
|
|||
constexpr size_t kCommonInputNum = 3;
|
||||
}
|
||||
|
||||
STATUS TransposeDeparser::Deparser(const CNodePtr &cnode) {
|
||||
STATUS TransposeMapper::Mapper(const CNodePtr &cnode) {
|
||||
if (cnode == nullptr) {
|
||||
MS_LOG(ERROR) << "Cnode is nullptr.";
|
||||
return lite::RET_ERROR;
|
||||
|
@ -42,7 +42,7 @@ STATUS TransposeDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
ParameterPtr perm_param = perm_input->cast<ParameterPtr>();
|
||||
auto data = opt::GetIntParameterData(perm_param);
|
||||
auto data = acl::GetIntParameterData(perm_param);
|
||||
std::vector<int64_t> perm;
|
||||
std::transform(data.begin(), data.end(), std::back_inserter(perm),
|
||||
[](int32_t n) -> int64_t { return static_cast<int64_t>(n); });
|
||||
|
@ -55,6 +55,6 @@ STATUS TransposeDeparser::Deparser(const CNodePtr &cnode) {
|
|||
return lite::RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_DEPARSER(kNameTranspose, TransposeDeparser)
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameTranspose, TransposeMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -14,24 +14,24 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACL_DEPARSER_PRIMITIVE_TRANSPOSE_DEPARSER_H
|
||||
#define ACL_DEPARSER_PRIMITIVE_TRANSPOSE_DEPARSER_H
|
||||
#ifndef ACL_MAPPER_PRIMITIVE_TRANSPOSE_MAPPER_H
|
||||
#define ACL_MAPPER_PRIMITIVE_TRANSPOSE_MAPPER_H
|
||||
|
||||
#include "tools/converter/acl/deparser/primitive_deparser.h"
|
||||
#include "tools/converter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/transpose.h"
|
||||
|
||||
using mindspore::ops::kNameTranspose;
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class TransposeDeparser : public PrimitiveDeparser {
|
||||
class TransposeMapper : public PrimitiveMapper {
|
||||
public:
|
||||
TransposeDeparser() : PrimitiveDeparser(kNameTranspose) {}
|
||||
TransposeMapper() : PrimitiveMapper(kNameTranspose) {}
|
||||
|
||||
~TransposeDeparser() override = default;
|
||||
~TransposeMapper() override = default;
|
||||
|
||||
STATUS Deparser(const CNodePtr &cnode) override;
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // ACL_DEPARSER_PRIMITIVE_TRANSPOSE_DEPARSER_H
|
||||
#endif // ACL_MAPPER_PRIMITIVE_TRANSPOSE_MAPPER_H
|
Loading…
Reference in New Issue