forked from huawei/mindspore2022
[MSLITE][Develop] new api to r1.3
This commit is contained in:
parent
b06c924ee3
commit
0a7bc34f7e
|
|
@ -1,88 +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 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_INCLUDE_ALLOCATOR_H_
|
||||
#define MINDSPORE_LITE_INCLUDE_ALLOCATOR_H_
|
||||
|
||||
#include <memory>
|
||||
#include "include/lite_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
/// \brief Allocator defined a memory pool for malloc memory and free memory dynamically.
|
||||
class MS_API Allocator {
|
||||
public:
|
||||
/// \brief Destructor of MindSpore Allocator.
|
||||
virtual ~Allocator() = default;
|
||||
|
||||
/// \brief Method to request memory.
|
||||
///
|
||||
/// \param[in] size Define the memory size to request.
|
||||
virtual void *Malloc(size_t size) = 0;
|
||||
|
||||
/// \brief Method to free memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory.
|
||||
virtual void Free(void *ptr) = 0;
|
||||
|
||||
/// \brief Reference count of a certain memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory.
|
||||
///
|
||||
/// \return Reference count of a certain memory currently.
|
||||
virtual int RefCount(void *ptr) = 0;
|
||||
|
||||
/// \brief Set reference count of a certain memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory.
|
||||
/// \param[in] ref_count Define the reference count to set.
|
||||
///
|
||||
/// \return Reference count of a certain memory after setting.
|
||||
virtual int SetRefCount(void *ptr, int ref_count) = 0;
|
||||
|
||||
/// \brief Decrease the reference count of a certain memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory.
|
||||
/// \param[in] ref_count Define the reference count to reduce.
|
||||
///
|
||||
/// \return Reference count of a certain memory after decreating.
|
||||
virtual int DecRefCount(void *ptr, int ref_count) = 0;
|
||||
|
||||
/// \brief Increase the reference count of a certain memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory.
|
||||
/// \param[in] ref_count Define the reference count to increase.
|
||||
///
|
||||
/// \return Reference count of a certain memory after increasing.
|
||||
virtual int IncRefCount(void *ptr, int ref_count) = 0;
|
||||
|
||||
/// \brief Static method to create an allocator.
|
||||
///
|
||||
/// \return Smart pointer of an allocator.
|
||||
static std::shared_ptr<Allocator> Create();
|
||||
|
||||
/// \brief Prepare a certain memory.
|
||||
///
|
||||
/// \param[in] ptr Define the pointer of a certain memory to prepare.
|
||||
///
|
||||
/// \return Pointer of ready memory.
|
||||
virtual void *Prepare(void *ptr) { return ptr; }
|
||||
|
||||
protected:
|
||||
// memory aligned bytes
|
||||
size_t aligned_size_ = 32;
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_INCLUDE_ALLOCATOR_H_
|
||||
|
|
@ -14,24 +14,30 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
||||
#define MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
||||
#ifndef MINDSPORE_INCLUDE_API_DELEGATE_H
|
||||
#define MINDSPORE_INCLUDE_API_DELEGATE_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "include/ms_tensor.h"
|
||||
#include "include/context.h"
|
||||
#include "schema/model_generated.h"
|
||||
#include "include/kernel.h"
|
||||
|
||||
namespace mindspore {
|
||||
typedef enum {
|
||||
SCHEMA_INVALID = -1, /**< invalid version */
|
||||
SCHEMA_CUR, /**< current version for ms model defined in model.fbs*/
|
||||
SCHEMA_V0, /**< previous version for ms model defined in model_v0.fbs*/
|
||||
} SchemaVersion;
|
||||
|
||||
using KernelIter = std::vector<kernel::Kernel *>::iterator;
|
||||
class DelegateModel {
|
||||
class MS_API DelegateModel {
|
||||
public:
|
||||
/// \brief Constructor of MindSpore Lite DelegateModel.
|
||||
DelegateModel(std::vector<kernel::Kernel *> *kernels,
|
||||
const std::map<kernel::Kernel *, const schema::Primitive *> primitives)
|
||||
: kernels_(kernels), primitives_(primitives) {}
|
||||
DelegateModel(std::vector<kernel::Kernel *> *kernels, const std::vector<MSTensor> &inputs,
|
||||
const std::vector<MSTensor> &outputs,
|
||||
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives, SchemaVersion version)
|
||||
: kernels_(kernels), inputs_(inputs), outputs_(outputs), primitives_(primitives), version_(version) {}
|
||||
|
||||
/// \brief Destructor of MindSpore Lite DelegateModel.
|
||||
~DelegateModel() = default;
|
||||
|
|
@ -61,14 +67,30 @@ class DelegateModel {
|
|||
/// \return The next iterator after graph_kernel, point to the next kernel that is not visited.
|
||||
KernelIter Replace(KernelIter from, KernelIter end, kernel::Kernel *graph_kernel);
|
||||
|
||||
/// \brief Get the input tensors of DelegateModel.
|
||||
///
|
||||
/// \return The input tensor vector of DelegateModel.
|
||||
const std::vector<mindspore::MSTensor> &inputs() { return this->inputs_; }
|
||||
|
||||
/// \brief Get the output tensors of DelegateModel.
|
||||
///
|
||||
/// \return The ioutput tensor vector of DelegateModel.
|
||||
const std::vector<mindspore::MSTensor> &outputs() { return this->outputs_; }
|
||||
|
||||
/// \brief Get the ms model version.
|
||||
///
|
||||
/// \return The schema version for the primitives map.
|
||||
const SchemaVersion GetVersion() { return version_; }
|
||||
|
||||
protected:
|
||||
std::vector<kernel::Kernel *> *kernels_;
|
||||
const std::map<kernel::Kernel *, const schema::Primitive *> primitives_;
|
||||
const std::vector<mindspore::MSTensor> &inputs_;
|
||||
const std::vector<mindspore::MSTensor> &outputs_;
|
||||
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives_;
|
||||
SchemaVersion version_;
|
||||
};
|
||||
|
||||
typedef void (*DelegateHook)(std::shared_ptr<Delegate> delegate);
|
||||
static void HookNullFuc(std::shared_ptr<Delegate> delegate) {}
|
||||
class Delegate {
|
||||
class MS_API Delegate {
|
||||
public:
|
||||
/// \brief Constructor of MindSpore Lite Delegate.
|
||||
Delegate() = default;
|
||||
|
|
@ -87,10 +109,6 @@ class Delegate {
|
|||
///
|
||||
/// \param[in] model Define the delegate model to be built.
|
||||
virtual int Build(DelegateModel *model) = 0;
|
||||
|
||||
DelegateHook init_hook_ = HookNullFuc;
|
||||
DelegateHook build_hook_ = HookNullFuc;
|
||||
DelegateHook run_hook_ = HookNullFuc;
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
||||
#endif // MINDSPORE_INCLUDE_API_DELEGATE_H
|
||||
|
|
|
|||
|
|
@ -14,22 +14,22 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_SRC_KERNEL_H_
|
||||
#define MINDSPORE_LITE_SRC_KERNEL_H_
|
||||
#ifndef MINDSPORE_INCLUDE_API_KERNEL_H
|
||||
#define MINDSPORE_INCLUDE_API_KERNEL_H
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "schema/model_generated.h"
|
||||
#include "include/lite_utils.h"
|
||||
#include "include/context.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/api/context.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
class Kernel {
|
||||
public:
|
||||
Kernel() = default;
|
||||
|
||||
Kernel(const std::vector<tensor::MSTensor *> &inputs, const std::vector<tensor::MSTensor *> &outputs,
|
||||
const schema::Primitive *primitive, const lite::Context *ctx)
|
||||
Kernel(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs,
|
||||
const schema::Primitive *primitive, const mindspore::Context *ctx)
|
||||
: inputs_(std::move(inputs)), outputs_(std::move(outputs)), primitive_(primitive), context_(ctx) {
|
||||
if (primitive != nullptr) {
|
||||
type_ = primitive->value_type();
|
||||
|
|
@ -46,33 +46,34 @@ class Kernel {
|
|||
|
||||
virtual schema::PrimitiveType type() const { return type_; }
|
||||
|
||||
virtual void set_inputs(const std::vector<mindspore::tensor::MSTensor *> &in_tensors) { this->inputs_ = in_tensors; }
|
||||
virtual void set_input(mindspore::tensor::MSTensor *in_tensor, int index) { this->inputs_[index] = in_tensor; }
|
||||
virtual void set_inputs(const std::vector<mindspore::MSTensor> &in_tensors) { this->inputs_ = in_tensors; }
|
||||
|
||||
virtual void set_outputs(const std::vector<mindspore::tensor::MSTensor *> &out_tensors) {
|
||||
this->outputs_ = out_tensors;
|
||||
}
|
||||
virtual void set_input(mindspore::MSTensor in_tensor, int index) { this->inputs_[index] = in_tensor; }
|
||||
|
||||
virtual void set_output(mindspore::tensor::MSTensor *out_tensor, int index) { this->outputs_[index] = out_tensor; }
|
||||
virtual void set_outputs(const std::vector<mindspore::MSTensor> &out_tensors) { this->outputs_ = out_tensors; }
|
||||
|
||||
virtual const std::vector<mindspore::tensor::MSTensor *> &inputs() { return this->inputs_; }
|
||||
virtual void set_output(mindspore::MSTensor out_tensor, int index) { this->outputs_[index] = out_tensor; }
|
||||
|
||||
virtual const std::vector<mindspore::tensor::MSTensor *> &outputs() { return this->outputs_; }
|
||||
virtual const std::vector<mindspore::MSTensor> &inputs() { return this->inputs_; }
|
||||
|
||||
virtual const std::vector<mindspore::MSTensor> &outputs() { return this->outputs_; }
|
||||
|
||||
std::string name() const { return this->name_; }
|
||||
|
||||
void set_name(const std::string &name) { this->name_ = name; }
|
||||
const lite::Context *context() const { return this->context_; }
|
||||
|
||||
const mindspore::Context *context() const { return this->context_; }
|
||||
|
||||
const schema::Primitive *primitive() const { return this->primitive_; }
|
||||
|
||||
protected:
|
||||
std::vector<mindspore::tensor::MSTensor *> inputs_;
|
||||
std::vector<mindspore::tensor::MSTensor *> outputs_;
|
||||
std::vector<mindspore::MSTensor> inputs_;
|
||||
std::vector<mindspore::MSTensor> outputs_;
|
||||
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
||||
std::string name_;
|
||||
const schema::Primitive *primitive_ = nullptr;
|
||||
const lite::Context *context_ = nullptr;
|
||||
const mindspore::Context *context_ = nullptr;
|
||||
};
|
||||
} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_KERNEL_H_
|
||||
#endif // MINDSPORE_INCLUDE_API_KERNEL_H
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
#include "include/model.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "include/api/types.h"
|
||||
#include "schema/model_generated.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
|
@ -46,7 +46,7 @@ class MS_API KernelInterface {
|
|||
/// \param[in] primitive Define the attributes of op.
|
||||
///
|
||||
/// \return STATUS as an error code of inferring, STATUS is defined in errorcode.h..
|
||||
virtual int Infer(const std::vector<tensor::MSTensor *> &inputs, const std::vector<tensor::MSTensor *> &outputs,
|
||||
virtual int Infer(std::vector<mindspore::MSTensor> *inputs, std::vector<mindspore::MSTensor> *outputs,
|
||||
const schema::Primitive *primitive) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ class MS_API KernelInterface {
|
|||
/// \param[in] param Define the contr of performance.
|
||||
///
|
||||
/// \return STATUS as an error code of inferring, STATUS is defined in errorcode.h.
|
||||
virtual int GetCapability(const std::vector<tensor::MSTensor *> &tensor_in, const schema::Primitive *primitive,
|
||||
virtual int GetCapability(const std::vector<mindspore::MSTensor> &tensor_in, const schema::Primitive *primitive,
|
||||
CapabilityParam *param) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
#include "schema/model_generated.h"
|
||||
#include "include/context.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "include/api/context.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/kernel.h"
|
||||
#include "ir/dtype/type_id.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
|
|
@ -57,8 +58,8 @@ struct MS_API KernelDesc {
|
|||
///
|
||||
/// \return Smart Pointer of kernel.
|
||||
using CreateKernel = std::function<std::shared_ptr<kernel::Kernel>(
|
||||
const std::vector<tensor::MSTensor *> &inputs, const std::vector<tensor::MSTensor *> &outputs,
|
||||
const schema::Primitive *primitive, const lite::Context *ctx)>;
|
||||
const std::vector<MSTensor> &inputs, const std::vector<MSTensor> &outputs, const schema::Primitive *primitive,
|
||||
const mindspore::Context *ctx)>;
|
||||
|
||||
/// \brief RegisterKernel Defined registration of kernel.
|
||||
class MS_API RegisterKernel {
|
||||
|
|
|
|||
|
|
@ -127,9 +127,13 @@ set(CODER_OPCODERS_SRC
|
|||
)
|
||||
|
||||
set(LITE_SRC
|
||||
${LITE_DIR}/src/cxx_api/tensor_utils.cc
|
||||
${LITE_DIR}/src/cxx_api/types.cc
|
||||
${LITE_DIR}/src/cxx_api/tensor/tensor_impl.cc
|
||||
${LITE_DIR}/src/common/file_utils.cc
|
||||
${LITE_DIR}/src/common/graph_util.cc
|
||||
${LITE_DIR}/src/common/prim_util.cc
|
||||
${LITE_DIR}/src/common/string_util.cc
|
||||
${LITE_DIR}/src/common/tensor_util.cc
|
||||
${LITE_DIR}/src/runtime/infer_manager.cc
|
||||
${LITE_DIR}/src/registry/kernel_interface.cc
|
||||
|
|
@ -137,12 +141,14 @@ set(LITE_SRC
|
|||
${LITE_DIR}/src/registry/register_kernel.cc
|
||||
${LITE_DIR}/src/registry/register_kernel_impl.cc
|
||||
${LITE_DIR}/src/lite_model.cc
|
||||
${LITE_DIR}/src/ms_tensor.cc
|
||||
${LITE_DIR}/src/tensorlist.cc
|
||||
${LITE_DIR}/src/tensor.cc
|
||||
${LITE_DIR}/src/weight_decoder.cc
|
||||
${LITE_DIR}/src/huffman_decode.cc
|
||||
${LITE_DIR}/src/common/log_adapter.cc
|
||||
${LITE_DIR}/src/common/utils.cc
|
||||
${LITE_DIR}/../core/utils/status.cc
|
||||
### tools
|
||||
${LITE_DIR}/tools/common/flag_parser.cc
|
||||
)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ endif()
|
|||
|
||||
set(LITE_SRC
|
||||
${API_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/context_util.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/file_utils.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/utils.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/graph_util.cc
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "src/common/context_util.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "src/common/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
namespace {
|
||||
template <class T>
|
||||
void PassBasicProperties(std::shared_ptr<T> device_info, const lite::DeviceContext &device_context) {
|
||||
device_info->SetProvider(device_context.provider_);
|
||||
device_info->SetProviderDevice(device_context.provider_device_);
|
||||
device_info->SetAllocator(device_context.allocator_);
|
||||
}
|
||||
|
||||
std::shared_ptr<mindspore::CPUDeviceInfo> CPUDeviceInfoFromCPUDeviceContext(const lite::DeviceContext &cpu_context) {
|
||||
if (cpu_context.device_type_ != DT_CPU) {
|
||||
MS_LOG(ERROR) << "function input parameter is not cpu context.";
|
||||
return nullptr;
|
||||
}
|
||||
auto cpu_info = std::make_shared<mindspore::CPUDeviceInfo>();
|
||||
cpu_info->SetEnableFP16(cpu_context.device_info_.cpu_device_info_.enable_float16_);
|
||||
PassBasicProperties(cpu_info, cpu_context);
|
||||
return cpu_info;
|
||||
}
|
||||
|
||||
std::shared_ptr<mindspore::MaliGPUDeviceInfo> GPUDeviceInfoFromGPUDeviceContext(
|
||||
const lite::DeviceContext &gpu_context) {
|
||||
if (gpu_context.device_type_ != DT_GPU) {
|
||||
MS_LOG(ERROR) << "function input parameter is not gpu context.";
|
||||
return nullptr;
|
||||
}
|
||||
auto gpu_info = std::make_shared<mindspore::MaliGPUDeviceInfo>();
|
||||
gpu_info->SetEnableFP16(gpu_context.device_info_.gpu_device_info_.enable_float16_);
|
||||
PassBasicProperties(gpu_info, gpu_context);
|
||||
return gpu_info;
|
||||
}
|
||||
|
||||
std::shared_ptr<mindspore::KirinNPUDeviceInfo> NPUDeviceInfoFromNPUDeviceContext(
|
||||
const lite::DeviceContext &npu_context) {
|
||||
if (npu_context.device_type_ != DT_NPU) {
|
||||
MS_LOG(ERROR) << "function input parameter is not npu context.";
|
||||
return nullptr;
|
||||
}
|
||||
auto npu_info = std::make_shared<mindspore::KirinNPUDeviceInfo>();
|
||||
npu_info->SetFrequency(npu_context.device_info_.npu_device_info_.frequency_);
|
||||
PassBasicProperties(npu_info, npu_context);
|
||||
return npu_info;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
mindspore::Context *MSContextFromContext(const lite::Context *context) {
|
||||
if (context == nullptr) {
|
||||
MS_LOG(ERROR) << "context is nullptr";
|
||||
return nullptr;
|
||||
}
|
||||
auto ms_context = new (std::nothrow) mindspore::Context();
|
||||
if (ms_context == nullptr) {
|
||||
MS_LOG(ERROR) << "New Context failed";
|
||||
return nullptr;
|
||||
}
|
||||
ms_context->SetThreadNum(context->thread_num_);
|
||||
ms_context->SetThreadAffinity(context->affinity_core_list_);
|
||||
ms_context->SetEnableParallel(context->enable_parallel_);
|
||||
ms_context->SetDelegate(context->delegate);
|
||||
auto &device_infos = ms_context->MutableDeviceInfo();
|
||||
std::map<DeviceType, std::function<std::shared_ptr<mindspore::DeviceInfoContext>(const lite::DeviceContext &)>>
|
||||
transfer_funcs = {{DT_CPU, CPUDeviceInfoFromCPUDeviceContext},
|
||||
{DT_GPU, GPUDeviceInfoFromGPUDeviceContext},
|
||||
{DT_NPU, NPUDeviceInfoFromNPUDeviceContext}};
|
||||
for (auto &device_context : context->device_list_) {
|
||||
auto device_type = device_context.device_type_;
|
||||
if (transfer_funcs.find(device_type) == transfer_funcs.end()) {
|
||||
MS_LOG(ERROR) << "device type is invalid.";
|
||||
return nullptr;
|
||||
}
|
||||
auto device_info = transfer_funcs[device_type](device_context);
|
||||
if (device_info == nullptr) {
|
||||
MS_LOG(ERROR) << "transfer device context to device info failed.";
|
||||
return nullptr;
|
||||
}
|
||||
if (device_type == DT_CPU) {
|
||||
ms_context->SetThreadAffinity(device_context.device_info_.cpu_device_info_.cpu_bind_mode_);
|
||||
}
|
||||
device_infos.push_back(device_info);
|
||||
}
|
||||
return ms_context;
|
||||
}
|
||||
|
||||
std::set<std::string> ProvidersFromMSContext(const mindspore::Context *context) {
|
||||
std::set<std::string> providers;
|
||||
if (context == nullptr) {
|
||||
return providers;
|
||||
}
|
||||
auto &device_infos = const_cast<mindspore::Context *>(context)->MutableDeviceInfo();
|
||||
for (auto &device_info : device_infos) {
|
||||
providers.emplace(device_info->GetProvider());
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
@ -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_COMMON_CONTEXT_UTIL_H_
|
||||
#define MINDSPORE_LITE_SRC_COMMON_CONTEXT_UTIL_H_
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "include/context.h"
|
||||
#include "include/api/context.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
mindspore::Context *MSContextFromContext(const lite::Context *context);
|
||||
std::set<std::string> ProvidersFromMSContext(const mindspore::Context *context);
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_SRC_COMMON_CONTEXT_UTIL_H_
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "mindspore/lite/src/tensor.h"
|
||||
#include "src/tensor.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "tools/common/option.h"
|
||||
#include "include/errorcode.h"
|
||||
|
|
|
|||
|
|
@ -270,5 +270,15 @@ int CheckTensorsInvalid(const std::vector<Tensor *> &tensors) {
|
|||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
std::vector<mindspore::MSTensor> LiteTensorsToMSTensors(const std::vector<lite::Tensor *> &lite_tensors) {
|
||||
std::vector<mindspore::MSTensor> tensors;
|
||||
std::transform(lite_tensors.begin(), lite_tensors.end(), std::back_inserter(tensors), [](lite::Tensor *tensor) {
|
||||
return mindspore::MSTensor(std::make_shared<mindspore::MSTensor::Impl>(tensor));
|
||||
});
|
||||
|
||||
return tensors;
|
||||
}
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@
|
|||
#ifndef MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
||||
#define MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "src/tensor.h"
|
||||
#include "src/tensorlist.h"
|
||||
#include "nnacl/tensor_c.h"
|
||||
#include "nnacl/infer/common_infer.h"
|
||||
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
|
@ -40,6 +42,9 @@ int GenerateOutTensorC(const OpParameter *const parameter, const std::vector<lit
|
|||
const std::vector<lite::Tensor *> &outputs, std::vector<TensorC *> *out_tensor_c);
|
||||
|
||||
int CheckTensorsInvalid(const std::vector<Tensor *> &tensors);
|
||||
|
||||
std::vector<mindspore::MSTensor> LiteTensorsToMSTensors(const std::vector<lite::Tensor *> &lite_tensors);
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ bool Context::GetEnableParallel() const {
|
|||
MS_LOG(ERROR) << "Invalid context.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return data_->enable_parallel_;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ Status A2L_ConvertContext(Context *a_context, lite::Context *l_context) {
|
|||
return kLiteInputParamInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
l_context->delegate = a_context->GetDelegate();
|
||||
return kSuccess;
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -41,6 +41,77 @@ CreateTrainSessionProto *CreateTrainSessionCallbackHolder(CreateTrainSessionProt
|
|||
return proto_;
|
||||
}
|
||||
|
||||
lite::CpuBindMode ModelImpl::GetCpuBindMode() {
|
||||
auto affinity_mode = context_->GetThreadAffinityMode();
|
||||
switch (affinity_mode) {
|
||||
case 0:
|
||||
return lite::NO_BIND;
|
||||
case 1:
|
||||
return lite::HIGHER_CPU;
|
||||
case 2:
|
||||
return lite::MID_CPU;
|
||||
default:
|
||||
return lite::NO_BIND;
|
||||
}
|
||||
}
|
||||
|
||||
Status ModelImpl::ConverterContext(const std::shared_ptr<Context> &context, lite::Context *model_context) {
|
||||
auto device_list = context->MutableDeviceInfo();
|
||||
if (device_list.size() == 0) {
|
||||
MS_LOG(ERROR) << "Invalid device list.";
|
||||
return kLiteInputParamInvalid;
|
||||
}
|
||||
if (device_list.size() > 2) {
|
||||
MS_LOG(ERROR) << "Only CPU/CPU & GPU/CPU & NPU mode is supported.";
|
||||
return kLiteInputParamInvalid;
|
||||
}
|
||||
|
||||
model_context->thread_num_ = context->GetThreadNum();
|
||||
model_context->enable_parallel_ = context->GetEnableParallel();
|
||||
model_context->affinity_core_list_ = context->GetThreadAffinityCoreList();
|
||||
model_context->device_list_.clear();
|
||||
if (device_list[0]->GetDeviceType() != kCPU) {
|
||||
MS_LOG(ERROR) << "CPU context must be enabled and in the first place of device list.";
|
||||
return kLiteInputParamInvalid;
|
||||
}
|
||||
|
||||
auto cpu_context = device_list[0]->Cast<CPUDeviceInfo>();
|
||||
model_context->allocator = cpu_context->GetAllocator();
|
||||
if (model_context->allocator == nullptr) {
|
||||
model_context->allocator = Allocator::Create();
|
||||
if (model_context->allocator == nullptr) {
|
||||
MS_LOG(ERROR) << "Create Allocator failed.";
|
||||
return kLiteNullptr;
|
||||
}
|
||||
MS_LOG(DEBUG) << "Set new allocator.";
|
||||
cpu_context->SetAllocator(model_context->allocator);
|
||||
}
|
||||
|
||||
lite::CpuBindMode mode = GetCpuBindMode();
|
||||
lite::DeviceInfo cpu_info = {0};
|
||||
cpu_info.cpu_device_info_ = {cpu_context->GetEnableFP16(), mode};
|
||||
model_context->device_list_.push_back({lite::DT_CPU, cpu_info, cpu_context->GetProvider(),
|
||||
cpu_context->GetProviderDevice(), cpu_context->GetAllocator()});
|
||||
if (device_list.size() == 2) {
|
||||
lite::DeviceInfo device_info = {0};
|
||||
if (device_list[1]->GetDeviceType() == kMaliGPU) {
|
||||
auto gpu_context = device_list[1]->Cast<MaliGPUDeviceInfo>();
|
||||
device_info.gpu_device_info_ = {gpu_context->GetEnableFP16()};
|
||||
model_context->device_list_.push_back({lite::DT_GPU, device_info, gpu_context->GetProvider(),
|
||||
gpu_context->GetProviderDevice(), gpu_context->GetAllocator()});
|
||||
} else if (device_list[1]->GetDeviceType() == kKirinNPU) {
|
||||
auto npu_context = device_list[1]->Cast<KirinNPUDeviceInfo>();
|
||||
device_info.npu_device_info_ = {npu_context->GetFrequency()};
|
||||
model_context->device_list_.push_back({lite::DT_NPU, device_info});
|
||||
} else {
|
||||
MS_LOG(ERROR) << "Invalid device.";
|
||||
return kLiteInputParamInvalid;
|
||||
}
|
||||
}
|
||||
model_context->delegate = context->GetDelegate();
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
Status ModelImpl::Build(const void *model_data, size_t data_size, ModelType model_type,
|
||||
const std::shared_ptr<Context> &ms_context) {
|
||||
lite::Context lite_context;
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ class ModelImpl {
|
|||
void SetContext(const std::shared_ptr<Context> &context) { context_ = context; }
|
||||
void SetConfig(const std::shared_ptr<TrainCfg> cfg) { cfg_ = cfg; }
|
||||
lite::CpuBindMode GetCpuBindMode();
|
||||
Status ConverterContext(const std::shared_ptr<Context> &context, lite::Context *model_context);
|
||||
Status RunGraph(const MSKernelCallBack &before, const MSKernelCallBack &after);
|
||||
};
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@
|
|||
#include "include/api/status.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "src/tensor.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "ir/dtype/type_id.h"
|
||||
|
||||
namespace mindspore {
|
||||
using mindspore::lite::RET_OK;
|
||||
|
|
@ -84,4 +82,14 @@ std::shared_ptr<MSTensor::Impl> MSTensor::Impl::StringsToTensorImpl(const std::s
|
|||
impl->set_from_session(false);
|
||||
return impl;
|
||||
}
|
||||
|
||||
std::vector<std::string> MSTensor::Impl::TensorImplToStrings(const std::shared_ptr<Impl> &impl) {
|
||||
std::vector<std::string> empty;
|
||||
auto lite_tensor = impl->lite_tensor();
|
||||
if (lite_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Invalid tensor impl.";
|
||||
return empty;
|
||||
}
|
||||
return lite::MSTensorToStrings(lite_tensor);
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -57,20 +57,13 @@ class MSTensor::Impl {
|
|||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<Impl> CreateTensorImpl(const std::string &name, enum DataType type,
|
||||
const std::vector<int64_t> &shape, const void *data, size_t data_len);
|
||||
static std::shared_ptr<Impl> MS_API CreateTensorImpl(const std::string &name, enum DataType type,
|
||||
const std::vector<int64_t> &shape, const void *data,
|
||||
size_t data_len);
|
||||
|
||||
static std::shared_ptr<Impl> StringsToTensorImpl(const std::string &name, const std::vector<std::string> &str);
|
||||
static std::shared_ptr<Impl> MS_API StringsToTensorImpl(const std::string &name, const std::vector<std::string> &str);
|
||||
|
||||
static std::vector<std::string> TensorImplToStrings(const std::shared_ptr<Impl> &impl) {
|
||||
std::vector<std::string> empty;
|
||||
auto lite_tensor = impl->lite_tensor();
|
||||
if (lite_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Invalid tensor impl.";
|
||||
return empty;
|
||||
}
|
||||
return lite::MSTensorToStrings(lite_tensor);
|
||||
}
|
||||
static std::vector<std::string> MS_API TensorImplToStrings(const std::shared_ptr<Impl> &impl);
|
||||
|
||||
const std::string &Name() const {
|
||||
static std::string empty = "";
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@
|
|||
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||
|
||||
namespace mindspore {
|
||||
std::vector<int32_t> TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
||||
bool verify_size);
|
||||
std::vector<int32_t> MS_API TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
||||
bool verify_size);
|
||||
|
||||
Status LiteTensorToMSTensor(tensor::MSTensor *srcTensor, MSTensor *dstTensor);
|
||||
Status MS_API LiteTensorToMSTensor(tensor::MSTensor *srcTensor, MSTensor *dstTensor);
|
||||
|
||||
std::vector<MSTensor> LiteTensorsToMSTensors(const std::vector<mindspore::tensor::MSTensor *> &srcTensors);
|
||||
std::vector<MSTensor> MS_API LiteTensorsToMSTensors(const std::vector<mindspore::tensor::MSTensor *> &srcTensors);
|
||||
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "src/delegate/delegate_utils.h"
|
||||
namespace mindspore::lite {
|
||||
bool IsSubGraphInputTensor(const std::vector<mindspore::tensor::MSTensor *> &inputs, tensor::MSTensor *input) {
|
||||
bool IsSubGraphInputTensor(const std::vector<mindspore::MSTensor> &inputs, mindspore::MSTensor input) {
|
||||
if (find(inputs.begin(), inputs.end(), input) != inputs.end()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@
|
|||
#include "src/delegate/tensorrt/op/tensorrt_op.h"
|
||||
|
||||
namespace mindspore::lite {
|
||||
bool IsSubGraphInputTensor(const std::vector<mindspore::tensor::MSTensor *> &inputs, tensor::MSTensor *input);
|
||||
bool IsSubGraphInputTensor(const std::vector<mindspore::MSTensor> &inputs, mindspore::MSTensor input);
|
||||
|
||||
template <typename T>
|
||||
std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<T *> ops) {
|
||||
std::vector<mindspore::tensor::MSTensor *> inputs;
|
||||
auto is_op_output = [&](tensor::MSTensor *tensor) -> bool {
|
||||
std::vector<mindspore::MSTensor> GetGraphInTensors(std::vector<T *> ops) {
|
||||
std::vector<mindspore::MSTensor> inputs;
|
||||
auto is_op_output = [&](mindspore::MSTensor tensor) -> bool {
|
||||
for (auto op : ops) {
|
||||
auto out_tensors = op->outputs();
|
||||
if (find(out_tensors.begin(), out_tensors.end(), tensor) != out_tensors.end()) {
|
||||
|
|
@ -39,7 +39,7 @@ std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<T *> op
|
|||
|
||||
for (auto op : ops) {
|
||||
for (auto in_tensor : op->inputs()) {
|
||||
if (in_tensor->data() == nullptr && !is_op_output(in_tensor)) {
|
||||
if (in_tensor.Data() == nullptr && !is_op_output(in_tensor)) {
|
||||
inputs.push_back(in_tensor);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,9 +48,9 @@ std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<T *> op
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<mindspore::tensor::MSTensor *> GetGraphOutTensors(const std::vector<T *> &ops) {
|
||||
std::vector<mindspore::tensor::MSTensor *> outputs;
|
||||
auto is_op_input = [&](const tensor::MSTensor *tensor) -> bool {
|
||||
std::vector<mindspore::MSTensor> GetGraphOutTensors(const std::vector<T *> &ops) {
|
||||
std::vector<mindspore::MSTensor> outputs;
|
||||
auto is_op_input = [&](const mindspore::MSTensor tensor) -> bool {
|
||||
for (auto op : ops) {
|
||||
auto in_tensors = op->inputs();
|
||||
if (find(in_tensors.begin(), in_tensors.end(), tensor) != in_tensors.end()) {
|
||||
|
|
@ -86,13 +86,13 @@ std::vector<mindspore::tensor::MSTensor *> GetGraphOutTensors(const std::vector<
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
std::vector<mindspore::MSTensor> GraphInTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
auto in_tensors = GetGraphInTensors(ops);
|
||||
std::vector<tensor::MSTensor *> all_in_tensors;
|
||||
std::vector<mindspore::MSTensor> all_in_tensors;
|
||||
for (auto op : ops) {
|
||||
for (auto in_tensor : op->inputs()) {
|
||||
if (in_tensor->data() != nullptr && find(in_tensors.begin(), in_tensors.end(), in_tensor) == in_tensors.end()) {
|
||||
if (in_tensor.Data() != nullptr && find(in_tensors.begin(), in_tensors.end(), in_tensor) == in_tensors.end()) {
|
||||
all_in_tensors.push_back(in_tensor);
|
||||
}
|
||||
}
|
||||
|
|
@ -113,10 +113,10 @@ std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<T *> &ops, Dele
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<tensor::MSTensor *> GraphOutTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
std::vector<mindspore::MSTensor> GraphOutTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
auto out_tensors = GetGraphOutTensors(ops);
|
||||
std::vector<tensor::MSTensor *> all_out_tensors;
|
||||
std::vector<mindspore::MSTensor> all_out_tensors;
|
||||
for (auto op : ops) {
|
||||
for (auto out_tensor : op->outputs()) {
|
||||
if (find(out_tensors.begin(), out_tensors.end(), out_tensor) == out_tensors.end()) {
|
||||
|
|
@ -176,9 +176,8 @@ void FindPreNextOps(std::vector<T *> all_ops) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
int GetGraphInOutOps(const std::vector<mindspore::tensor::MSTensor *> &inputs,
|
||||
const std::vector<mindspore::tensor::MSTensor *> &outputs, std::vector<T *> *in_ops,
|
||||
std::vector<T *> *out_ops, const std::vector<T *> &all_ops) {
|
||||
int GetGraphInOutOps(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs,
|
||||
std::vector<T *> *in_ops, std::vector<T *> *out_ops, const std::vector<T *> &all_ops) {
|
||||
for (auto in_tensor : inputs) {
|
||||
for (auto op : all_ops) {
|
||||
if (find(op->inputs().begin(), op->inputs().end(), in_tensor) != op->inputs().end() &&
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
#include <arm_neon.h>
|
||||
#include "src/common/log_adapter.h"
|
||||
namespace mindspore {
|
||||
#define C8NUM 8
|
||||
|
|
@ -54,7 +53,7 @@ void Float16ToFloat32(const float16_t *__restrict input, float *__restrict outpu
|
|||
}
|
||||
#endif
|
||||
|
||||
ge::Shape ConverterToNPUShape(const std::vector<int> &src_shape) {
|
||||
ge::Shape ConverterToNPUShape(const std::vector<int64_t> &src_shape) {
|
||||
vector<int64_t> shapes;
|
||||
shapes.reserve(src_shape.size());
|
||||
for (int i = 0; i < src_shape.size(); i++) {
|
||||
|
|
@ -82,27 +81,26 @@ ge::Format ConverterToNPUFormat(schema::Format format) {
|
|||
return ge_format;
|
||||
}
|
||||
|
||||
ge::DataType ConverterToNPUDataType(TypeId type_id) {
|
||||
ge::DataType ConverterToNPUDataType(DataType type_id) {
|
||||
ge::DataType data_type;
|
||||
switch (type_id) {
|
||||
case kNumberTypeFloat:
|
||||
case kNumberTypeFloat32:
|
||||
case kNumberTypeFloat16:
|
||||
case DataType::kNumberTypeFloat32:
|
||||
case DataType::kNumberTypeFloat16:
|
||||
data_type = ge::DT_FLOAT;
|
||||
break;
|
||||
case kNumberTypeInt8:
|
||||
case DataType::kNumberTypeInt8:
|
||||
data_type = ge::DT_INT8;
|
||||
break;
|
||||
case kNumberTypeUInt8:
|
||||
case DataType::kNumberTypeUInt8:
|
||||
data_type = ge::DT_UINT8;
|
||||
break;
|
||||
case kNumberTypeInt16:
|
||||
case DataType::kNumberTypeInt16:
|
||||
data_type = ge::DT_INT16;
|
||||
break;
|
||||
case kNumberTypeInt32:
|
||||
case DataType::kNumberTypeInt32:
|
||||
data_type = ge::DT_INT32;
|
||||
break;
|
||||
case kNumberTypeUInt32:
|
||||
case DataType::kNumberTypeUInt32:
|
||||
data_type = ge::DT_UINT32;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -112,43 +110,41 @@ ge::DataType ConverterToNPUDataType(TypeId type_id) {
|
|||
return data_type;
|
||||
}
|
||||
|
||||
hiai::op::Data *ConverterToNPUData(tensor::MSTensor *src, const std::string &name) {
|
||||
hiai::op::Data *ConverterToNPUData(mindspore::MSTensor src, const std::string &name) {
|
||||
auto data = new (std::nothrow) hiai::op::Data(name);
|
||||
if (data == nullptr) {
|
||||
MS_LOG(ERROR) << "new data failed.";
|
||||
return data;
|
||||
}
|
||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src->shape()), ge::FORMAT_NCHW,
|
||||
ConverterToNPUDataType(src->data_type()));
|
||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src.Shape()), ge::FORMAT_NCHW, ConverterToNPUDataType(src.DataType()));
|
||||
data->update_input_desc_x(tensor_desc);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::shared_ptr<ge::Tensor> ConverterToNPUTensor(tensor::MSTensor *src) {
|
||||
std::shared_ptr<ge::Tensor> ConverterToNPUTensor(mindspore::MSTensor src) {
|
||||
std::shared_ptr<ge::Tensor> ge_tensor = std::shared_ptr<ge::Tensor>(new (std::nothrow) ge::Tensor());
|
||||
if (ge_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "new ge_tensor failed.";
|
||||
return nullptr;
|
||||
}
|
||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src->shape()), ge::FORMAT_NCHW,
|
||||
ConverterToNPUDataType(src->data_type()));
|
||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src.Shape()), ge::FORMAT_NCHW, ConverterToNPUDataType(src.DataType()));
|
||||
|
||||
ge_tensor->SetTensorDesc(tensor_desc);
|
||||
|
||||
if (src->data() != nullptr) {
|
||||
if (src->data_type() == kNumberTypeFloat16) {
|
||||
if (src.Data() != nullptr) {
|
||||
if (src.DataType() == DataType::kNumberTypeFloat16) {
|
||||
#ifdef ENABLE_ARM64
|
||||
auto fp32_data = malloc(src->ElementsNum() * sizeof(float));
|
||||
Float16ToFloat32(reinterpret_cast<float16_t *>(src->data()), reinterpret_cast<float *>(fp32_data),
|
||||
src->ElementsNum());
|
||||
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(fp32_data), src->ElementsNum() * sizeof(float));
|
||||
auto fp32_data = malloc(src.ElementNum() * sizeof(float));
|
||||
Float16ToFloat32(reinterpret_cast<float16_t *>(src.MutableData()), reinterpret_cast<float *>(fp32_data),
|
||||
src.ElementNum());
|
||||
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(fp32_data), src.ElementNum() * sizeof(float));
|
||||
free(fp32_data);
|
||||
#else
|
||||
MS_LOG(ERROR) << "This platform does not support fp16.";
|
||||
return nullptr;
|
||||
#endif
|
||||
} else {
|
||||
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(src->data()), src->Size());
|
||||
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(src.MutableData()), src.DataSize());
|
||||
}
|
||||
}
|
||||
return ge_tensor;
|
||||
|
|
@ -189,7 +185,7 @@ int TransFormAxis(int axis) {
|
|||
}
|
||||
}
|
||||
|
||||
bool IsContainMSTensor(const std::vector<tensor::MSTensor *> &tensor_vec, const tensor::MSTensor *tensor) {
|
||||
bool IsContainMSTensor(const std::vector<mindspore::MSTensor> &tensor_vec, const mindspore::MSTensor tensor) {
|
||||
return find(tensor_vec.begin(), tensor_vec.end(), tensor) != tensor_vec.end();
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -19,29 +19,36 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#ifdef ENABLE_ARM64
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
#include "schema/ops_generated.h"
|
||||
#include "include/graph/tensor.h"
|
||||
#include "include/graph/op/array_defs.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/api/data_type.h"
|
||||
|
||||
namespace mindspore {
|
||||
#ifdef ENABLE_ARM64
|
||||
void Float32ToFloat16(const float *__restrict input, float16_t *__restrict output, int number);
|
||||
|
||||
std::shared_ptr<ge::Tensor> ConverterToNPUTensor(tensor::MSTensor *src);
|
||||
void Float16ToFloat32(const float16_t *__restrict input, float *__restrict output, int number);
|
||||
#endif
|
||||
|
||||
hiai::op::Data *ConverterToNPUData(tensor::MSTensor *src, const std::string &name);
|
||||
std::shared_ptr<ge::Tensor> ConverterToNPUTensor(mindspore::MSTensor src);
|
||||
|
||||
hiai::op::Data *ConverterToNPUData(mindspore::MSTensor src, const std::string &name);
|
||||
|
||||
ge::Format ConverterToNPUFormat(schema::Format format);
|
||||
|
||||
ge::DataType ConverterToNPUDataType(TypeId type_id);
|
||||
ge::DataType ConverterToNPUDataType(DataType type_id);
|
||||
|
||||
ge::Shape ConverterToNPUShape(const std::vector<int> &src_shape);
|
||||
|
||||
int ConverterToNPUActMode(schema::ActivationType type);
|
||||
ge::Shape ConverterToNPUShape(const std::vector<int64_t> &src_shape);
|
||||
|
||||
int ConverterToNPUEltwiseMode(schema::EltwiseMode mode);
|
||||
|
||||
int TransFormAxis(int axis);
|
||||
|
||||
bool IsContainMSTensor(const std::vector<tensor::MSTensor *> &tensor_vec, const tensor::MSTensor *tensor);
|
||||
bool IsContainMSTensor(const std::vector<mindspore::MSTensor> &tensor_vec, const mindspore::MSTensor tensor);
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_CONVERTER_UITLS_H_
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "src/delegate/npu/npu_delegate.h"
|
||||
#include <queue>
|
||||
#include "include/errorcode.h"
|
||||
#include "src/delegate/npu/op/npu_op.h"
|
||||
#include "src/delegate/npu/op/activation_npu.h"
|
||||
#include "src/delegate/npu/op/argmax_npu.h"
|
||||
|
|
@ -54,6 +55,9 @@
|
|||
#include "src/delegate/npu/pass/npu_insert_transform_pass.h"
|
||||
#include "src/delegate/npu/pass/npu_fusion_pass.h"
|
||||
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
|
||||
namespace mindspore {
|
||||
NPUDelegate::~NPUDelegate() {
|
||||
if (npu_manager_ != nullptr) {
|
||||
|
|
@ -202,42 +206,42 @@ int NPUDelegate::Build(DelegateModel *model) {
|
|||
}
|
||||
|
||||
NPUOp *NPUDelegate::GetOP(kernel::Kernel *kernel, const schema::Primitive *primitive) {
|
||||
auto in_tensors = kernel->inputs();
|
||||
auto out_tensors = kernel->outputs();
|
||||
auto name = kernel->name();
|
||||
NPUOp *npu_op = nullptr;
|
||||
auto node_type = primitive->value_type();
|
||||
if (node_type == schema::PrimitiveType_Conv2DFusion) {
|
||||
npu_op = GetNPUConvOp(primitive, in_tensors, out_tensors, name);
|
||||
npu_op = GetNPUConvOp(primitive, kernel->inputs(), kernel->outputs(), name);
|
||||
} else {
|
||||
if (op_func_lists_.find(node_type) != op_func_lists_.end()) {
|
||||
npu_op = op_func_lists_[node_type](primitive, in_tensors, out_tensors, name);
|
||||
npu_op = op_func_lists_[node_type](primitive, kernel->inputs(), kernel->outputs(), name);
|
||||
} else {
|
||||
MS_LOG(DEBUG) << "Unsupported op type for NPU.";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto tensor : in_tensors) {
|
||||
if (tensor->data_type() == kNumberTypeFloat16 && tensor->data() == nullptr) {
|
||||
tensor->set_data_type(kNumberTypeFloat32);
|
||||
for (int i = 0; i < kernel->inputs().size(); i++) {
|
||||
mindspore::MSTensor tensor = kernel->inputs()[i];
|
||||
if (tensor.DataType() == DataType::kNumberTypeFloat16 && tensor.Data() == nullptr) {
|
||||
tensor.SetDataType(DataType::kNumberTypeFloat32);
|
||||
}
|
||||
}
|
||||
for (auto tensor : out_tensors) {
|
||||
if (tensor->data_type() == kNumberTypeFloat16) {
|
||||
tensor->set_data_type(kNumberTypeFloat32);
|
||||
for (int i = 0; i < kernel->outputs().size(); i++) {
|
||||
mindspore::MSTensor tensor = kernel->outputs()[i];
|
||||
if (tensor.DataType() == DataType::kNumberTypeFloat16) {
|
||||
tensor.SetDataType(DataType::kNumberTypeFloat32);
|
||||
}
|
||||
}
|
||||
return npu_op;
|
||||
}
|
||||
|
||||
std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
std::vector<mindspore::MSTensor> GraphInTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
auto in_tensors = NPUGraphUtils::GetGraphInTensors(ops);
|
||||
std::vector<tensor::MSTensor *> all_in_tensors;
|
||||
std::vector<mindspore::MSTensor> all_in_tensors;
|
||||
for (auto op : ops) {
|
||||
for (auto in_tensor : op->inputs()) {
|
||||
if (in_tensor->data() != nullptr && find(in_tensors.begin(), in_tensors.end(), in_tensor) == in_tensors.end()) {
|
||||
if (in_tensor.Data() != nullptr && find(in_tensors.begin(), in_tensors.end(), in_tensor) == in_tensors.end()) {
|
||||
all_in_tensors.push_back(in_tensor);
|
||||
}
|
||||
}
|
||||
|
|
@ -257,10 +261,10 @@ std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<NPUOp *> &ops,
|
|||
return in_tensors;
|
||||
}
|
||||
|
||||
std::vector<tensor::MSTensor *> GraphOutTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
std::vector<mindspore::MSTensor> GraphOutTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||
KernelIter end) {
|
||||
auto out_tensors = NPUGraphUtils::GetGraphOutTensors(ops);
|
||||
std::vector<tensor::MSTensor *> all_out_tensors;
|
||||
std::vector<mindspore::MSTensor> all_out_tensors;
|
||||
for (auto op : ops) {
|
||||
for (auto out_tensor : op->outputs()) {
|
||||
if (find(out_tensors.begin(), out_tensors.end(), out_tensor) == out_tensors.end()) {
|
||||
|
|
|
|||
|
|
@ -20,15 +20,10 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include "include/delegate.h"
|
||||
#include "include/context.h"
|
||||
#include "src/delegate/npu/npu_manager.h"
|
||||
#include "src/delegate/npu/pass/npu_pass_manager.h"
|
||||
#include "src/delegate/npu/op//npu_op.h"
|
||||
#include "include/context.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
#include "src/delegate/npu/op/npu_op.h"
|
||||
|
||||
namespace mindspore {
|
||||
class NPUDelegate : public Delegate {
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ int NPUExecutor::Prepare() {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
std::vector<int> GetNpuTensorShape(int dim, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||
std::vector<int> npu_shape;
|
||||
std::vector<int64_t> GetNpuTensorShape(int dim, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||
std::vector<int64_t> npu_shape;
|
||||
if (dim > 0) {
|
||||
npu_shape.push_back(npu_tensor->GetTensorDimension().GetNumber());
|
||||
}
|
||||
|
|
@ -75,40 +75,40 @@ std::vector<int> ExpandShapeTo4d(const std::vector<int> &shape) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool IsSameShapeTensor(tensor::MSTensor *tensor, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||
if (tensor->shape().size() > 4) {
|
||||
bool IsSameShapeTensor(mindspore::MSTensor tensor, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||
if (tensor.Shape().size() > 4) {
|
||||
MS_LOG(ERROR) << "Npu does not support output tensor dims greater than 4";
|
||||
return false;
|
||||
}
|
||||
return GetNpuTensorShape(tensor->shape().size(), npu_tensor) == tensor->shape();
|
||||
return GetNpuTensorShape(tensor.Shape().size(), npu_tensor) == tensor.Shape();
|
||||
}
|
||||
|
||||
int NPUExecutor::Run(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, const std::vector<NPUOp *> &in_ops) {
|
||||
int NPUExecutor::Run(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, const std::vector<NPUOp *> &in_ops) {
|
||||
hiai::AiContext context;
|
||||
std::unordered_map<tensor::MSTensor *, int> tensor_uses;
|
||||
std::unordered_map<std::string, int> tensor_uses;
|
||||
for (const auto op : in_ops) {
|
||||
for (const auto op_input : op->inputs()) {
|
||||
if (tensor_uses.find(op_input) == tensor_uses.end()) {
|
||||
tensor_uses.insert({op_input, 1});
|
||||
if (tensor_uses.find(op_input.Name()) == tensor_uses.end()) {
|
||||
tensor_uses.insert({op_input.Name(), 1});
|
||||
} else {
|
||||
tensor_uses[op_input]++;
|
||||
tensor_uses[op_input.Name()]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < npu_input_tensors_.size(); ++i) {
|
||||
int index = 0;
|
||||
for (; index < in_tensors.size(); index++) {
|
||||
if (tensor_uses[in_tensors[index]] > 0 && IsSameShapeTensor(in_tensors[index], npu_input_tensors_[i])) {
|
||||
void *data = in_tensors[index]->data();
|
||||
if (tensor_uses[in_tensors[index].Name()] > 0 && IsSameShapeTensor(in_tensors[index], npu_input_tensors_[i])) {
|
||||
auto data = in_tensors[index].Data();
|
||||
if (data == nullptr) {
|
||||
MS_LOG(ERROR) << "For " << model_name_ << ", the input tensor " << in_tensors[index]->tensor_name()
|
||||
MS_LOG(ERROR) << "For " << model_name_ << ", the input tensor " << in_tensors[index].Name()
|
||||
<< " data is nullptr";
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
memcpy(npu_input_tensors_[i]->GetBuffer(), data, in_tensors[index]->Size());
|
||||
tensor_uses[in_tensors[index]]--;
|
||||
memcpy(npu_input_tensors_[i]->GetBuffer(), data.get(), in_tensors[index].DataSize());
|
||||
tensor_uses[in_tensors[index].Name()]--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,9 +135,10 @@ int NPUExecutor::Run(const std::vector<tensor::MSTensor *> &in_tensors,
|
|||
int index = 0;
|
||||
for (; index < out_tensors.size(); index++) {
|
||||
if (!outputs_visited[index] && IsSameShapeTensor(out_tensors[index], npu_output_tensors_[i])) {
|
||||
void *data = out_tensors[index]->data();
|
||||
mindspore::MSTensor out_tensor = out_tensors[index];
|
||||
auto data = out_tensor.MutableData();
|
||||
if (data == nullptr) {
|
||||
MS_LOG(ERROR) << "For " << model_name_ << ", the output tensor " << in_tensors[index]->tensor_name()
|
||||
MS_LOG(ERROR) << "For " << model_name_ << ", the output tensor " << out_tensors[index].Name()
|
||||
<< " data is nullptr";
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class NPUExecutor {
|
|||
~NPUExecutor();
|
||||
int Prepare();
|
||||
|
||||
int Run(const std::vector<tensor::MSTensor *> &in_tensors, const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int Run(const std::vector<mindspore::MSTensor> &in_tensors, const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<NPUOp *> &in_ops);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ NPUGraph::~NPUGraph() {
|
|||
for (auto *op : npu_ops_) {
|
||||
delete op;
|
||||
}
|
||||
for (auto *tensor : insert_tensors_) {
|
||||
for (auto tensor : insert_tensors_) {
|
||||
delete tensor;
|
||||
}
|
||||
}
|
||||
|
||||
void NPUGraph::set_input(tensor::MSTensor *in_tensor, int index) {
|
||||
void NPUGraph::set_input(mindspore::MSTensor in_tensor, int index) {
|
||||
MS_ASSERT(index < inputs_.size());
|
||||
auto origin_tensor = this->inputs_[index];
|
||||
for (auto kernel : all_kernels_) {
|
||||
|
|
@ -46,7 +46,7 @@ void NPUGraph::set_input(tensor::MSTensor *in_tensor, int index) {
|
|||
this->inputs_[index] = in_tensor;
|
||||
}
|
||||
|
||||
void NPUGraph::set_output(tensor::MSTensor *out_tensor, int index) {
|
||||
void NPUGraph::set_output(mindspore::MSTensor out_tensor, int index) {
|
||||
MS_ASSERT(index < outputs_.size());
|
||||
auto origin_tensor = this->outputs_[index];
|
||||
for (auto kernel : all_kernels_) {
|
||||
|
|
@ -199,7 +199,7 @@ int NPUGraph::Prepare() {
|
|||
}
|
||||
for (auto output : all_kernels_[i]->outputs()) {
|
||||
if (find(outputs_.begin(), outputs_.end(), output) == outputs_.end()) {
|
||||
output->MutableData();
|
||||
output.MutableData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ int NPUGraph::Execute() {
|
|||
// 1. malloc graph output data
|
||||
for (auto output : all_kernels_[i]->outputs()) {
|
||||
if (find(outputs_.begin(), outputs_.end(), output) != outputs_.end()) {
|
||||
output->MutableData();
|
||||
output.MutableData();
|
||||
}
|
||||
}
|
||||
// 2. execute
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
namespace mindspore {
|
||||
class NPUGraph : public kernel::Kernel {
|
||||
public:
|
||||
NPUGraph(std::vector<NPUOp *> npu_ops, NPUManager *npu_manager, const std::vector<tensor::MSTensor *> &inputs,
|
||||
const std::vector<tensor::MSTensor *> &outputs)
|
||||
NPUGraph(std::vector<NPUOp *> npu_ops, NPUManager *npu_manager, const std::vector<mindspore::MSTensor> &inputs,
|
||||
const std::vector<mindspore::MSTensor> &outputs)
|
||||
: kernel::Kernel(inputs, outputs, nullptr, nullptr), npu_ops_(std::move(npu_ops)), npu_manager_(npu_manager) {}
|
||||
|
||||
~NPUGraph() override;
|
||||
|
|
@ -44,15 +44,15 @@ class NPUGraph : public kernel::Kernel {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
|
||||
void set_input(tensor::MSTensor *in_tensor, int index) override;
|
||||
void set_input(mindspore::MSTensor in_tensor, int index) override;
|
||||
|
||||
void set_output(tensor::MSTensor *out_tensor, int index) override;
|
||||
void set_output(mindspore::MSTensor out_tensor, int index) override;
|
||||
|
||||
int FindPreNextOps();
|
||||
|
||||
std::vector<NPUOp *> *GetOps() { return &npu_ops_; }
|
||||
|
||||
std::vector<tensor::MSTensor *> *GetInsertTensors() { return &insert_tensors_; }
|
||||
std::vector<mindspore::MSTensor *> *GetInsertTensors() { return &insert_tensors_; }
|
||||
|
||||
protected:
|
||||
std::vector<NPUOp *> FindPreOps(NPUOp *cur_op);
|
||||
|
|
@ -69,7 +69,7 @@ class NPUGraph : public kernel::Kernel {
|
|||
|
||||
std::vector<kernel::Kernel *> all_kernels_{};
|
||||
|
||||
std::vector<tensor::MSTensor *> insert_tensors_;
|
||||
std::vector<mindspore::MSTensor *> insert_tensors_;
|
||||
|
||||
NPUManager *npu_manager_ = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
#include "src/delegate/npu/npu_graph_utils.h"
|
||||
namespace mindspore {
|
||||
std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphInTensors(std::vector<NPUOp *> ops) {
|
||||
std::vector<mindspore::tensor::MSTensor *> inputs;
|
||||
auto is_op_output = [&](tensor::MSTensor *tensor) -> bool {
|
||||
std::vector<mindspore::MSTensor> NPUGraphUtils::GetGraphInTensors(std::vector<NPUOp *> ops) {
|
||||
std::vector<mindspore::MSTensor> inputs;
|
||||
auto is_op_output = [&](mindspore::MSTensor tensor) -> bool {
|
||||
for (auto op : ops) {
|
||||
auto out_tensors = op->outputs();
|
||||
if (find(out_tensors.begin(), out_tensors.end(), tensor) != out_tensors.end()) {
|
||||
|
|
@ -30,7 +30,7 @@ std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphInTensors(std:
|
|||
|
||||
for (auto op : ops) {
|
||||
for (auto in_tensor : op->inputs()) {
|
||||
if (in_tensor->data() == nullptr && !is_op_output(in_tensor)) {
|
||||
if (in_tensor.Data() == nullptr && !is_op_output(in_tensor)) {
|
||||
inputs.push_back(in_tensor);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,9 +38,9 @@ std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphInTensors(std:
|
|||
return inputs;
|
||||
}
|
||||
|
||||
std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphOutTensors(std::vector<NPUOp *> ops) {
|
||||
std::vector<mindspore::tensor::MSTensor *> outputs;
|
||||
auto is_op_input = [&](const tensor::MSTensor *tensor) -> bool {
|
||||
std::vector<mindspore::MSTensor> NPUGraphUtils::GetGraphOutTensors(std::vector<NPUOp *> ops) {
|
||||
std::vector<mindspore::MSTensor> outputs;
|
||||
auto is_op_input = [&](const mindspore::MSTensor tensor) -> bool {
|
||||
for (auto op : ops) {
|
||||
auto in_tensors = op->inputs();
|
||||
if (find(in_tensors.begin(), in_tensors.end(), tensor) != in_tensors.end()) {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@
|
|||
namespace mindspore {
|
||||
class NPUGraphUtils {
|
||||
public:
|
||||
static std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<NPUOp *> ops);
|
||||
static std::vector<mindspore::MSTensor> GetGraphInTensors(std::vector<NPUOp *> ops);
|
||||
|
||||
static std::vector<mindspore::tensor::MSTensor *> GetGraphOutTensors(std::vector<NPUOp *> ops);
|
||||
static std::vector<mindspore::MSTensor> GetGraphOutTensors(std::vector<NPUOp *> ops);
|
||||
};
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ NPUSubGraph::~NPUSubGraph() {
|
|||
op_buffer_.clear();
|
||||
}
|
||||
|
||||
void NPUSubGraph::set_input(tensor::MSTensor *in_tensor, int index) {
|
||||
void NPUSubGraph::set_input(mindspore::MSTensor in_tensor, int index) {
|
||||
MS_ASSERT(index < inputs_.size());
|
||||
auto origin_tensor = inputs_[index];
|
||||
// only in_ops_ input tensors list used in execute function
|
||||
|
|
@ -62,7 +62,7 @@ void NPUSubGraph::set_input(tensor::MSTensor *in_tensor, int index) {
|
|||
this->inputs_[index] = in_tensor;
|
||||
}
|
||||
|
||||
void NPUSubGraph::set_output(tensor::MSTensor *out_tensor, int index) {
|
||||
void NPUSubGraph::set_output(mindspore::MSTensor out_tensor, int index) {
|
||||
MS_ASSERT(index < out_tensor_sorted_.size());
|
||||
auto origin_tensor = outputs_[index];
|
||||
for (size_t i = 0; i < out_tensor_sorted_.size(); i++) {
|
||||
|
|
@ -217,7 +217,7 @@ int NPUSubGraph::BuildNPUInputOp() {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
bool NPUSubGraph::IsSubGraphInputTensor(tensor::MSTensor *input) {
|
||||
bool NPUSubGraph::IsSubGraphInputTensor(mindspore::MSTensor input) {
|
||||
if (find(this->inputs().begin(), this->inputs().end(), input) != this->inputs().end()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ class NPUSubGraph : public kernel::Kernel {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
|
||||
void set_input(tensor::MSTensor *in_tensor, int index) override;
|
||||
void set_input(mindspore::MSTensor in_tensor, int index) override;
|
||||
|
||||
void set_output(tensor::MSTensor *out_tensor, int index) override;
|
||||
void set_output(mindspore::MSTensor out_tensor, int index) override;
|
||||
|
||||
int GetGraphInOutOps();
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class NPUSubGraph : public kernel::Kernel {
|
|||
|
||||
int GetNPUOperators(const std::vector<NPUOp *> &ops);
|
||||
|
||||
bool IsSubGraphInputTensor(tensor::MSTensor *input);
|
||||
bool IsSubGraphInputTensor(mindspore::MSTensor input);
|
||||
|
||||
std::string GetOMModelName();
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class NPUSubGraph : public kernel::Kernel {
|
|||
|
||||
std::vector<ge::Operator> subgraph_output_ops_;
|
||||
|
||||
std::vector<tensor::MSTensor *> out_tensor_sorted_;
|
||||
std::vector<mindspore::MSTensor> out_tensor_sorted_;
|
||||
|
||||
std::vector<ge::Operator *> op_buffer_;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "src/delegate/npu/op/activation_npu.h"
|
||||
namespace mindspore {
|
||||
int ActivationNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ActivationNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto act_prim = primitive->value_as_Activation();
|
||||
if (act_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -33,8 +33,8 @@ int ActivationNPUOp::IsSupport(const schema::Primitive *primitive, const std::ve
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ActivationNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ActivationNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
act_ = new (std::nothrow) hiai::op::Activation(name_);
|
||||
if (act_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New activation npu operator for activation op " << name_ << " failed.";
|
||||
|
|
@ -72,8 +72,8 @@ int ActivationNPUOp::Init(const schema::Primitive *primitive, const std::vector<
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ActivationNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ActivationNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
act_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -18,26 +18,25 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "include/graph/compatible/all_ops.h"
|
||||
#include "src/delegate/npu/op/npu_op.h"
|
||||
namespace mindspore {
|
||||
class ActivationNPUOp : public NPUOp {
|
||||
public:
|
||||
ActivationNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ActivationNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ActivationNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,11 +16,10 @@
|
|||
|
||||
#include "src/delegate/npu/op/argmax_npu.h"
|
||||
#include <memory>
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int ArgmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ArgmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
argmax_ = new (std::nothrow) hiai::op::ArgMaxExt2(name_);
|
||||
if (argmax_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New argmax npu operator for " << name_ << " failed.";
|
||||
|
|
@ -54,8 +53,8 @@ int ArgmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ArgmaxNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ArgmaxNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
argmax_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -27,22 +27,22 @@ namespace mindspore {
|
|||
|
||||
class ArgmaxNPUOp : public NPUOp {
|
||||
public:
|
||||
ArgmaxNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ArgmaxNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ArgmaxNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,23 +15,22 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/arithmetic_npu.h"
|
||||
#include "include/graph/op/all_ops.h"
|
||||
namespace mindspore {
|
||||
constexpr int RELU_MODE = 1;
|
||||
constexpr int RELU6_MODE = 14;
|
||||
int ArithmeticNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
if (in_tensors[0]->shape() != in_tensors[1]->shape()) {
|
||||
int ArithmeticNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors[0].Shape() != in_tensors[1].Shape()) {
|
||||
MS_LOG(WARNING) << name_ << " for the two inputs, the corresponding dimensions must have the same value."
|
||||
<< " shape 1 is:" << in_tensors[0]->shape() << " shape 2 is:" << in_tensors[1]->shape();
|
||||
<< " shape 1 is:" << in_tensors[0].Shape() << " shape 2 is:" << in_tensors[1].Shape();
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
auto type = primitive->value_type();
|
||||
if (type == mindspore::schema::PrimitiveType_Less && in_tensors[0]->shape().size() == 1) {
|
||||
if (type == mindspore::schema::PrimitiveType_Less && in_tensors[0].Shape().size() == 1) {
|
||||
MS_LOG(WARNING) << name_ << " not support input 1d";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
if (type == mindspore::schema::PrimitiveType_Equal && in_tensors[0]->shape().size() == 2) {
|
||||
if (type == mindspore::schema::PrimitiveType_Equal && in_tensors[0].Shape().size() == 2) {
|
||||
MS_LOG(WARNING) << name_ << " not support input 2d";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
|
|
@ -48,8 +47,8 @@ ge::Operator *CreateOperator(const std::string &name) {
|
|||
return op;
|
||||
}
|
||||
|
||||
int ArithmeticNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ArithmeticNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
switch (type_) {
|
||||
case schema::PrimitiveType_MulFusion:
|
||||
op_ = CreateOperator<hiai::op::Mul>(name_);
|
||||
|
|
@ -143,8 +142,8 @@ void SetInputs(const std::vector<ge::Operator *> &npu_inputs, ge::Operator *op)
|
|||
return;
|
||||
}
|
||||
|
||||
int ArithmeticNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ArithmeticNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
switch (type_) {
|
||||
case schema::PrimitiveType_MulFusion:
|
||||
|
|
@ -203,7 +202,7 @@ int ArithmeticNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tens
|
|||
}
|
||||
|
||||
int ArithmeticNPUOp::SetNPUInputs(
|
||||
const std::vector<tensor::MSTensor *> &in_tensors, const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
const std::vector<mindspore::MSTensor> &in_tensors, const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs,
|
||||
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
||||
auto ret = SetNPUInputs(in_tensors, out_tensors, npu_inputs);
|
||||
|
|
|
|||
|
|
@ -25,24 +25,24 @@
|
|||
namespace mindspore {
|
||||
class ArithmeticNPUOp : public NPUOp {
|
||||
public:
|
||||
ArithmeticNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ArithmeticNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ArithmeticNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, const std::vector<ge::Operator *> &npu_inputs,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, const std::vector<ge::Operator *> &npu_inputs,
|
||||
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "src/delegate/npu/op/arithmetic_self_npu.h"
|
||||
#include <string>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
|
||||
namespace mindspore {
|
||||
template <typename T>
|
||||
|
|
@ -29,8 +28,8 @@ ge::Operator *CreateOperator(const std::string &name) {
|
|||
return op;
|
||||
}
|
||||
|
||||
int ArithmeticSelfNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ArithmeticSelfNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
switch (type_) {
|
||||
case schema::PrimitiveType_Cos:
|
||||
op_ = CreateOperator<hiai::op::Cos>(name_);
|
||||
|
|
@ -86,8 +85,8 @@ void SetInputs(const std::vector<ge::Operator *> &npu_inputs, ge::Operator *op)
|
|||
return;
|
||||
}
|
||||
|
||||
int ArithmeticSelfNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ArithmeticSelfNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
switch (type_) {
|
||||
case schema::PrimitiveType_Cos:
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class ArithmeticSelfNPUOp : public NPUOp {
|
||||
public:
|
||||
ArithmeticSelfNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ArithmeticSelfNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ArithmeticSelfNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "src/delegate/npu/op/avg_pooling_npu.h"
|
||||
namespace mindspore {
|
||||
int AvgPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int AvgPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto pooling_prim = primitive->value_as_AvgPoolFusion();
|
||||
if (pooling_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -71,8 +71,8 @@ int AvgPoolingNPUOp::SetPoolingParam(const schema::AvgPoolFusion *pooling_prim)
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int AvgPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int AvgPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
||||
if (pooling_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New pooling npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -99,8 +99,8 @@ int AvgPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int AvgPoolingNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int AvgPoolingNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
pooling_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@
|
|||
namespace mindspore {
|
||||
class AvgPoolingNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
AvgPoolingNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
AvgPoolingNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~AvgPoolingNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/batchnorm_npu.h"
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int BatchnormNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int BatchnormNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
batchnorm_ = new (std::nothrow) ge::op::BatchNormExt2(name_);
|
||||
if (batchnorm_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New batchnorm npu operator for batchnorm op " << name_ << " failed.";
|
||||
|
|
@ -36,8 +37,8 @@ int BatchnormNPUOp::Init(const schema::Primitive *primitive, const std::vector<t
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int BatchnormNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int BatchnormNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
batchnorm_->set_input_x(*npu_inputs[0]);
|
||||
auto scale = new (std::nothrow) hiai::op::Const(name_ + "_scale");
|
||||
|
|
|
|||
|
|
@ -18,29 +18,28 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "include/graph/compatible/all_ops.h"
|
||||
#include "src/delegate/npu/op/npu_op.h"
|
||||
|
||||
namespace mindspore {
|
||||
class BatchnormNPUOp : public NPUOp {
|
||||
public:
|
||||
BatchnormNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
BatchnormNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~BatchnormNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
if (in_tensors.size() >= 2 && in_tensors[1]->ElementsNum() == 1) {
|
||||
dst_type_ = static_cast<int *>(in_tensors[1]->data())[0];
|
||||
int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() >= 2 && in_tensors[1].ElementNum() == 1) {
|
||||
dst_type_ = reinterpret_cast<const int *>(in_tensors[1].Data().get())[0];
|
||||
} else {
|
||||
MS_LOG(WARNING) << "NPU dst dtype is attribute.";
|
||||
return RET_NOT_SUPPORT;
|
||||
|
|
@ -29,20 +29,20 @@ int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<t
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int CastNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int CastNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
cast_ = new (std::nothrow) hiai::op::CastT(name_);
|
||||
if (cast_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
return RET_ERROR;
|
||||
}
|
||||
cast_->set_attr_dst_dtype(ConverterToNPUDataType(static_cast<TypeId>(dst_type_)));
|
||||
cast_->set_attr_src_dtype(ConverterToNPUDataType(static_cast<TypeId>(in_tensors[0]->data_type())));
|
||||
cast_->set_attr_dst_dtype(ConverterToNPUDataType(static_cast<DataType>(dst_type_)));
|
||||
cast_->set_attr_src_dtype(ConverterToNPUDataType(static_cast<DataType>(in_tensors[0].DataType())));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CastNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int CastNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
cast_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class CastNPUOp : public NPUOp {
|
||||
public:
|
||||
CastNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
CastNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~CastNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int ConcatNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ConcatNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
concat_ = new (std::nothrow) hiai::op::ConcatD(name_);
|
||||
if (concat_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -34,8 +34,8 @@ int ConcatNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ConcatNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ConcatNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
concat_->set_attr_concat_dim(axis_);
|
||||
concat_->set_attr_N(npu_inputs.size());
|
||||
|
|
|
|||
|
|
@ -23,22 +23,22 @@
|
|||
namespace mindspore {
|
||||
class ConcatNPUOp : public NPUOp {
|
||||
public:
|
||||
ConcatNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ConcatNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ConcatNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
#include "src/delegate/npu/transpose_kernel.h"
|
||||
#include "nnacl/fp16/cast_fp16.h"
|
||||
|
||||
namespace mindspore {
|
||||
ConvolutionBaseNPUOp::~ConvolutionBaseNPUOp() {
|
||||
|
|
@ -35,27 +34,39 @@ ConvolutionBaseNPUOp::~ConvolutionBaseNPUOp() {
|
|||
}
|
||||
}
|
||||
|
||||
int ConvolutionBaseNPUOp::InitWeightConst(const std::vector<tensor::MSTensor *> &inputs) {
|
||||
int ConvolutionBaseNPUOp::InitWeightConst(const std::vector<mindspore::MSTensor> &inputs) {
|
||||
weight_ = new (std::nothrow) hiai::op::Const(name_ + "_w");
|
||||
if (weight_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New weight const failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
auto w_shape = inputs[1]->shape();
|
||||
auto origin_data = inputs[1]->data();
|
||||
auto fp32_data = origin_data;
|
||||
if (inputs[1]->data_type() == kNumberTypeFloat16) {
|
||||
fp32_data = reinterpret_cast<float *>(malloc(inputs[1]->ElementsNum() * sizeof(float)));
|
||||
auto w_shape = inputs[1].Shape();
|
||||
auto origin_data = inputs[1].Data().get();
|
||||
float *fp32_data = nullptr;
|
||||
if (inputs[1].DataType() == DataType::kNumberTypeFloat16) {
|
||||
#ifdef ENABLE_ARM64
|
||||
fp32_data = reinterpret_cast<float *>(malloc(inputs[1].ElementNum() * sizeof(float)));
|
||||
// fp16->fp32
|
||||
Float16ToFloat32(reinterpret_cast<float16_t *>(origin_data), reinterpret_cast<float *>(fp32_data),
|
||||
inputs[1]->ElementsNum());
|
||||
Float16ToFloat32(reinterpret_cast<const float16_t *>(origin_data), reinterpret_cast<float *>(fp32_data),
|
||||
inputs[1].ElementNum());
|
||||
#else
|
||||
MS_LOG(ERROR) << "This platform does not support fp16.";
|
||||
return RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
auto nchw_data = reinterpret_cast<float *>(malloc(inputs[1]->ElementsNum() * sizeof(float)));
|
||||
auto nchw_data = reinterpret_cast<float *>(malloc(inputs[1].ElementNum() * sizeof(float)));
|
||||
if (nchw_data == nullptr) {
|
||||
MS_LOG(ERROR) << "Malloc buffer failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
PackNHWCToNCHWFp32(fp32_data, nchw_data, w_shape[0], w_shape[1] * w_shape[2], w_shape[3]);
|
||||
if (inputs[1].DataType() == DataType::kNumberTypeFloat16) {
|
||||
PackNHWCToNCHWFp32(fp32_data, nchw_data, w_shape[0], w_shape[1] * w_shape[2], w_shape[3]);
|
||||
} else if (inputs[1].DataType() == DataType::kNumberTypeFloat32) {
|
||||
PackNHWCToNCHWFp32(origin_data, nchw_data, w_shape[0], w_shape[1] * w_shape[2], w_shape[3]);
|
||||
} else {
|
||||
MS_LOG(ERROR) << "Unsupported data type of weight tensor for npu convolution.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
std::shared_ptr<ge::Tensor> weight_tensor = std::shared_ptr<ge::Tensor>(new (std::nothrow) ge::Tensor());
|
||||
if (weight_tensor == nullptr) {
|
||||
|
|
@ -63,16 +74,16 @@ int ConvolutionBaseNPUOp::InitWeightConst(const std::vector<tensor::MSTensor *>
|
|||
return RET_ERROR;
|
||||
}
|
||||
ge::TensorDesc tensor_desc(ConverterToNPUShape({w_shape[0], w_shape[3], w_shape[1], w_shape[2]}), ge::FORMAT_NCHW,
|
||||
ConverterToNPUDataType(inputs[1]->data_type()));
|
||||
ConverterToNPUDataType(inputs[1].DataType()));
|
||||
weight_tensor->SetTensorDesc(tensor_desc);
|
||||
weight_tensor->SetData(reinterpret_cast<const uint8_t *>(nchw_data), inputs[1]->ElementsNum() * sizeof(float));
|
||||
weight_tensor->SetData(reinterpret_cast<const uint8_t *>(nchw_data), inputs[1].ElementNum() * sizeof(float));
|
||||
|
||||
weight_->set_attr_value(weight_tensor);
|
||||
free(nchw_data);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int ConvolutionBaseNPUOp::InitBiasConst(const std::vector<tensor::MSTensor *> &inputs) {
|
||||
int ConvolutionBaseNPUOp::InitBiasConst(const std::vector<mindspore::MSTensor> &inputs) {
|
||||
if (inputs.size() >= 3) {
|
||||
bias_ = new (std::nothrow) hiai::op::Const(name_ + "_b");
|
||||
if (bias_ == nullptr) {
|
||||
|
|
|
|||
|
|
@ -24,15 +24,15 @@
|
|||
namespace mindspore {
|
||||
class ConvolutionBaseNPUOp : public NPUOp {
|
||||
public:
|
||||
ConvolutionBaseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ConvolutionBaseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ConvolutionBaseNPUOp() override;
|
||||
|
||||
protected:
|
||||
int InitWeightConst(const std::vector<tensor::MSTensor *> &inputs);
|
||||
int InitBiasConst(const std::vector<tensor::MSTensor *> &inputs);
|
||||
int InitWeightConst(const std::vector<mindspore::MSTensor> &inputs);
|
||||
int InitBiasConst(const std::vector<mindspore::MSTensor> &inputs);
|
||||
int SetActivation(const ge::Operator *input, schema::ActivationType act_type);
|
||||
hiai::op::Activation *act_ = nullptr;
|
||||
hiai::op::Const *weight_ = nullptr;
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ int ConvolutionDepthwiseNPUOp::SetConvDwParam(const schema::Conv2DFusion *conv_p
|
|||
}
|
||||
|
||||
int ConvolutionDepthwiseNPUOp::Init(const schema::Primitive *primitive,
|
||||
const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
conv_dw_ = new (std::nothrow) hiai::op::ConvolutionDepthwise(name_ + "_conv_depthwise");
|
||||
if (conv_dw_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New convolution depthwise operator for op " << name_ << " failed.";
|
||||
|
|
@ -70,8 +70,8 @@ int ConvolutionDepthwiseNPUOp::Init(const schema::Primitive *primitive,
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ConvolutionDepthwiseNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ConvolutionDepthwiseNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
auto ret = InitWeightConst(in_tensors);
|
||||
if (ret != RET_OK) {
|
||||
|
|
|
|||
|
|
@ -18,28 +18,27 @@
|
|||
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_DEPTHWISE_NPU_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "include/graph/compatible/all_ops.h"
|
||||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||
namespace mindspore {
|
||||
class ConvolutionDepthwiseNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
ConvolutionDepthwiseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ConvolutionDepthwiseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ConvolutionDepthwiseNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
#include "src/delegate/npu/op/convolution_npu.h"
|
||||
#include "src/delegate/npu/op/convolution_depthwise_npu.h"
|
||||
namespace mindspore {
|
||||
int ConvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ConvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto conv_prim = primitive->value_as_Conv2DFusion();
|
||||
if (conv_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -26,7 +26,7 @@ int ConvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::v
|
|||
}
|
||||
auto stride_h = static_cast<int>(*(conv_prim->stride()->begin()));
|
||||
auto stride_w = static_cast<int>(*(conv_prim->stride()->begin() + 1));
|
||||
auto in_shape = in_tensors[0]->shape(); // default format: nhwc, RunPass not called
|
||||
auto in_shape = in_tensors[0].Shape(); // default format: nhwc, RunPass not called
|
||||
if (stride_h > in_shape[1] || stride_w > in_shape[2]) {
|
||||
MS_LOG(WARNING) << "Npu convolution does not support stride greater than input size.";
|
||||
return RET_NOT_SUPPORT;
|
||||
|
|
@ -61,8 +61,8 @@ int ConvolutionNPUOp::SetConvParam(const schema::Conv2DFusion *conv_prim) {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
// set conv attr param
|
||||
conv_ = new (std::nothrow) hiai::op::Convolution(name_ + "_conv");
|
||||
if (conv_ == nullptr) {
|
||||
|
|
@ -90,8 +90,8 @@ int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ConvolutionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ConvolutionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
auto ret = InitWeightConst(in_tensors);
|
||||
if (ret != RET_OK) {
|
||||
|
|
@ -125,30 +125,30 @@ ConvolutionNPUOp::~ConvolutionNPUOp() {
|
|||
conv_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name) {
|
||||
auto shape = out_tensors.front()->shape();
|
||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name) {
|
||||
auto shape = out_tensors.front().Shape();
|
||||
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
||||
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (in_tensors[0]->shape().size() > 4) {
|
||||
if (in_tensors[0].Shape().size() > 4) {
|
||||
MS_LOG(ERROR) << "Npu does not support input tensor dims greater than 4";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (in_tensors[0]->data_type() != kNumberTypeFloat32 && in_tensors[0]->data_type() != kNumberTypeFloat16) {
|
||||
MS_LOG(ERROR) << "Npu does not support datatype " << in_tensors[0]->data_type();
|
||||
if (in_tensors[0].DataType() != DataType::kNumberTypeFloat32 &&
|
||||
in_tensors[0].DataType() != DataType::kNumberTypeFloat16) {
|
||||
MS_LOG(ERROR) << "Npu does not support datatype " << static_cast<int>(in_tensors[0].DataType());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NPUOp *op = nullptr;
|
||||
auto conv_prim = primitive->value_as_Conv2DFusion();
|
||||
auto group = static_cast<int>(conv_prim->group());
|
||||
auto input_channel = in_tensors.front()->shape()[3];
|
||||
auto output_channel = out_tensors.front()->shape()[3];
|
||||
auto input_channel = in_tensors.front().Shape()[3];
|
||||
auto output_channel = out_tensors.front().Shape()[3];
|
||||
if (group == input_channel && group == output_channel) {
|
||||
op = new (std::nothrow) ConvolutionDepthwiseNPUOp(primitive, in_tensors, out_tensors, name);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@
|
|||
namespace mindspore {
|
||||
class ConvolutionNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
ConvolutionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ConvolutionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ConvolutionNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
@ -47,7 +47,7 @@ class ConvolutionNPUOp : public ConvolutionBaseNPUOp {
|
|||
hiai::op::Convolution *conv_ = nullptr;
|
||||
};
|
||||
|
||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name);
|
||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name);
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_NPU_H_
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@
|
|||
|
||||
#include "src/delegate/npu/op/crop_and_resize_npu.h"
|
||||
namespace mindspore {
|
||||
int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive,
|
||||
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() < 4) {
|
||||
MS_LOG(WARNING) << "NPU CropAndResize got nput inputs size < 4";
|
||||
return RET_NOT_SUPPORT;
|
||||
|
|
@ -37,8 +38,8 @@ int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std:
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int CropAndResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int CropAndResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
crop_and_resize_ = new (std::nothrow) hiai::op::CropAndResize(name_);
|
||||
if (crop_and_resize_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -62,8 +63,8 @@ int CropAndResizeNPUOp::Init(const schema::Primitive *primitive, const std::vect
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int CropAndResizeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int CropAndResizeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
crop_and_resize_->set_input_x(*npu_inputs[0]);
|
||||
crop_and_resize_->set_input_boxes(*npu_inputs[1]);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class CropAndResizeNPUOp : public NPUOp {
|
||||
public:
|
||||
CropAndResizeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
CropAndResizeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~CropAndResizeNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int DeconvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int DeconvolutionNPUOp::IsSupport(const schema::Primitive *primitive,
|
||||
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto deconv_prim = primitive->value_as_Conv2dTransposeFusion();
|
||||
if (deconv_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -59,8 +60,8 @@ int DeconvolutionNPUOp::SetDeconvParam(const schema::Conv2dTransposeFusion *conv
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
// set deconv attr param
|
||||
deconv_ = new (std::nothrow) hiai::op::ConvTranspose(name_ + "_deconv");
|
||||
if (deconv_ == nullptr) {
|
||||
|
|
@ -89,8 +90,8 @@ int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vect
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int DeconvolutionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int DeconvolutionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
auto ret = InitWeightConst(in_tensors);
|
||||
if (ret != RET_OK) {
|
||||
|
|
|
|||
|
|
@ -24,19 +24,19 @@
|
|||
namespace mindspore {
|
||||
class DeconvolutionNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
DeconvolutionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
DeconvolutionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
~DeconvolutionNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int EltwiseNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int EltwiseNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
eltwise_ = new (std::nothrow) hiai::op::Eltwise(name_);
|
||||
if (eltwise_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -39,8 +39,8 @@ int EltwiseNPUOp::Init(const schema::Primitive *primitive, const std::vector<ten
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int EltwiseNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int EltwiseNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
for (int i = 0; i < npu_inputs.size(); ++i) {
|
||||
eltwise_->set_dynamic_input_x(i + 1, *npu_inputs[i]);
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class EltwiseNPUOp : public NPUOp {
|
||||
public:
|
||||
EltwiseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
EltwiseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~EltwiseNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int ExpandDimsNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ExpandDimsNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
expand_dims_ = new (std::nothrow) hiai::op::ExpandDims(name_);
|
||||
if (expand_dims_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -29,8 +29,8 @@ int ExpandDimsNPUOp::Init(const schema::Primitive *primitive, const std::vector<
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ExpandDimsNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ExpandDimsNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
expand_dims_->set_input_x(*npu_inputs[0]);
|
||||
expand_dims_->set_input_axis(*npu_inputs[1]);
|
||||
|
|
|
|||
|
|
@ -24,21 +24,21 @@
|
|||
namespace mindspore {
|
||||
class ExpandDimsNPUOp : public NPUOp {
|
||||
public:
|
||||
ExpandDimsNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ExpandDimsNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
~ExpandDimsNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto fc_prim = primitive->value_as_FullConnection();
|
||||
if (fc_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
return RET_ERROR;
|
||||
}
|
||||
act_type_ = fc_prim->activation_type();
|
||||
auto input_shape = in_tensors[0]->shape();
|
||||
auto input_shape = in_tensors[0].Shape();
|
||||
reshape_ = new (std::nothrow) hiai::op::Reshape(name_ + "_reshape");
|
||||
if (reshape_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New reshape operator for fullconnection op " << name_ << " failed.";
|
||||
|
|
@ -39,7 +39,7 @@ int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vec
|
|||
col *= input_shape[i];
|
||||
}
|
||||
reshape_op_ = new (std::nothrow) hiai::op::Const(name_ + "_reshape_data");
|
||||
vector<int> reshape_data = {input_shape[0], col};
|
||||
vector<int> reshape_data = {static_cast<int>(input_shape[0]), col};
|
||||
ge::TensorDesc reshape_tensor_desc(ge::Shape({2}), ge::FORMAT_NCHW, ge::DT_FLOAT);
|
||||
ge::TensorPtr reshape_tensor = std::make_shared<hiai::Tensor>(reshape_tensor_desc);
|
||||
reshape_tensor->SetData(reinterpret_cast<uint8_t *>(reshape_data.data()), 2 * sizeof(float));
|
||||
|
|
@ -54,8 +54,8 @@ int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vec
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int FullconnectionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int FullconnectionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
reshape_->set_input_x(*npu_inputs[0]);
|
||||
fc_->set_input_x1(*reshape_);
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class FullconnectionNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
FullconnectionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
FullconnectionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~FullconnectionNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@
|
|||
#include "src/delegate/npu/op/gather_npu.h"
|
||||
|
||||
namespace mindspore {
|
||||
int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
if (in_tensors[1]->data_type() != kNumberTypeInt32) {
|
||||
int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors[1].DataType() != DataType::kNumberTypeInt32) {
|
||||
MS_LOG(WARNING) << "Gather indices only support Int32";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
if (in_tensors.size() >= 3 && in_tensors[2]->ElementsNum() == 1) {
|
||||
axis_ = static_cast<int *>(in_tensors[2]->data())[0];
|
||||
if (in_tensors.size() >= 3 && in_tensors[2].ElementNum() == 1) {
|
||||
axis_ = static_cast<const int *>(in_tensors[2].Data().get())[0];
|
||||
} else {
|
||||
MS_LOG(WARNING) << "NPU axis is attribute.";
|
||||
return RET_NOT_SUPPORT;
|
||||
|
|
@ -32,8 +32,8 @@ int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int GatherNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int GatherNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
gather_ = new (std::nothrow) hiai::op::GatherV2D(name_);
|
||||
if (gather_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -43,8 +43,8 @@ int GatherNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int GatherNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int GatherNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
gather_->set_input_x(*npu_inputs[0]);
|
||||
gather_->set_input_indices(*npu_inputs[1]);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class GatherNPUOp : public NPUOp {
|
||||
public:
|
||||
GatherNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
GatherNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~GatherNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/instance_norm_npu.h"
|
||||
#include <memory>
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int InstanceNormNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int InstanceNormNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
instance_norm_ = new (std::nothrow) hiai::op::InstanceNorm(name_);
|
||||
if (instance_norm_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New instance norm npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -35,12 +34,12 @@ int InstanceNormNPUOp::Init(const schema::Primitive *primitive, const std::vecto
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int InstanceNormNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int InstanceNormNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
instance_norm_->set_input_x(*npu_inputs[0]);
|
||||
|
||||
auto gamma_shape = in_tensors[1]->shape();
|
||||
auto gamma_shape = in_tensors[1].Shape();
|
||||
auto gamma_tensor = ConverterToNPUTensor(in_tensors[1]);
|
||||
if (gamma_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Get gamma_tensor failed.";
|
||||
|
|
@ -56,7 +55,7 @@ int InstanceNormNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_te
|
|||
gamma_->set_attr_value(gamma_tensor);
|
||||
instance_norm_->set_input_gamma(*gamma_);
|
||||
|
||||
auto beta_shape = in_tensors[2]->shape();
|
||||
auto beta_shape = in_tensors[2].Shape();
|
||||
auto beta_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||
if (beta_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Get beta_tensor failed.";
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class InstanceNormNPUOp : public NPUOp {
|
||||
public:
|
||||
InstanceNormNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
InstanceNormNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~InstanceNormNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,21 +15,20 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/matmul_npu.h"
|
||||
#include <memory>
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
namespace mindspore {
|
||||
int MatMulNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int MatMulNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() == 3) {
|
||||
if (in_tensors[2]->shape().size() != 1) {
|
||||
if (in_tensors[2].Shape().size() != 1) {
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int MatMulNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int MatMulNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
matmul_ = new (std::nothrow) hiai::op::MatMul(name_);
|
||||
if (matmul_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New matmul npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -48,8 +47,8 @@ int MatMulNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int MatMulNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int MatMulNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
matmul_->set_input_x1(*npu_inputs[0]);
|
||||
matmul_->set_input_x2(*npu_inputs[1]);
|
||||
|
|
@ -60,7 +59,7 @@ int MatMulNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
|||
return RET_ERROR;
|
||||
}
|
||||
add_op_->set_input_x1(*matmul_);
|
||||
auto bias_shape = in_tensors[2]->shape();
|
||||
auto bias_shape = in_tensors[2].Shape();
|
||||
auto bias_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||
if (bias_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Get bias_tensor failed.";
|
||||
|
|
@ -68,7 +67,7 @@ int MatMulNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
|||
}
|
||||
|
||||
ge::TensorDesc bias_tensor_desc(ConverterToNPUShape({1, bias_shape[0], 1, 1}));
|
||||
if (out_tensors[0]->shape().size() == 2) {
|
||||
if (out_tensors[0].Shape().size() == 2) {
|
||||
bias_tensor_desc.SetShape(ConverterToNPUShape({1, bias_shape[0]}));
|
||||
}
|
||||
bias_tensor->SetTensorDesc(bias_tensor_desc);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class MatMulNPUOp : public NPUOp {
|
||||
public:
|
||||
MatMulNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
MatMulNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~MatMulNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "src/delegate/npu/op/max_pooling_npu.h"
|
||||
namespace mindspore {
|
||||
int MaxPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int MaxPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto pooling_prim = primitive->value_as_MaxPoolFusion();
|
||||
if (pooling_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -71,8 +71,8 @@ int MaxPoolingNPUOp::SetPoolingParam(const schema::MaxPoolFusion *pooling_prim)
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int MaxPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int MaxPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
||||
if (pooling_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New pooling npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -99,8 +99,8 @@ int MaxPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int MaxPoolingNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int MaxPoolingNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
pooling_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -18,25 +18,24 @@
|
|||
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_MAX_POOLING_NPU_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||
namespace mindspore {
|
||||
class MaxPoolingNPUOp : public ConvolutionBaseNPUOp {
|
||||
public:
|
||||
MaxPoolingNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
MaxPoolingNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~MaxPoolingNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -21,19 +21,20 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include "include/errorcode.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "schema/model_generated.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "include/graph/graph.h"
|
||||
#include "schema/model_generated.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "include/api/types.h"
|
||||
#include "include/api/data_type.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_NOT_SUPPORT;
|
||||
using mindspore::lite::RET_OK;
|
||||
namespace mindspore {
|
||||
class NPUOp {
|
||||
public:
|
||||
NPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
NPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: inputs_(std::move(in_tensors)), outputs_(std::move(out_tensors)), name_(name) {
|
||||
if (primitive != nullptr) {
|
||||
type_ = primitive->value_type();
|
||||
|
|
@ -42,24 +43,24 @@ class NPUOp {
|
|||
|
||||
virtual ~NPUOp() = default;
|
||||
|
||||
virtual int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
virtual int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
virtual int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
virtual int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
virtual int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
virtual int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
virtual int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
virtual int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs,
|
||||
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
||||
if (index2_multi_out_index.empty()) {
|
||||
|
|
@ -70,18 +71,18 @@ class NPUOp {
|
|||
|
||||
virtual ge::Operator *GetNPUOp() { return nullptr; }
|
||||
|
||||
void set_inputs(const std::vector<mindspore::tensor::MSTensor *> &in_tensors) { this->inputs_ = in_tensors; }
|
||||
void set_inputs(const std::vector<mindspore::MSTensor> &in_tensors) { this->inputs_ = in_tensors; }
|
||||
|
||||
void set_input(mindspore::tensor::MSTensor *in_tensor, int index) {
|
||||
void set_input(mindspore::MSTensor in_tensor, int index) {
|
||||
MS_ASSERT(index < inputs_.size());
|
||||
this->inputs_[index] = in_tensor;
|
||||
}
|
||||
|
||||
void set_outputs(const std::vector<mindspore::tensor::MSTensor *> &out_tensors) { this->outputs_ = out_tensors; }
|
||||
void set_outputs(const std::vector<mindspore::MSTensor> &out_tensors) { this->outputs_ = out_tensors; }
|
||||
|
||||
const std::vector<mindspore::tensor::MSTensor *> &inputs() { return this->inputs_; }
|
||||
const std::vector<mindspore::MSTensor> &inputs() { return this->inputs_; }
|
||||
|
||||
const std::vector<mindspore::tensor::MSTensor *> &outputs() { return this->outputs_; }
|
||||
const std::vector<mindspore::MSTensor> &outputs() { return this->outputs_; }
|
||||
|
||||
void set_in_ops(const std::vector<NPUOp *> &in_ops) { this->in_ops_ = in_ops; }
|
||||
|
||||
|
|
@ -98,37 +99,37 @@ class NPUOp {
|
|||
void set_name(const std::string &name) { this->name_ = name; }
|
||||
|
||||
protected:
|
||||
std::vector<mindspore::tensor::MSTensor *> inputs_;
|
||||
std::vector<mindspore::tensor::MSTensor *> outputs_;
|
||||
std::vector<mindspore::MSTensor> inputs_;
|
||||
std::vector<mindspore::MSTensor> outputs_;
|
||||
std::vector<NPUOp *> in_ops_;
|
||||
std::vector<NPUOp *> out_ops_;
|
||||
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
typedef NPUOp *(*NPUGetOp)(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name);
|
||||
typedef NPUOp *(*NPUGetOp)(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name);
|
||||
|
||||
template <class T>
|
||||
NPUOp *GetNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name) {
|
||||
auto shape = out_tensors.front()->shape();
|
||||
NPUOp *GetNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name) {
|
||||
auto shape = out_tensors.front().Shape();
|
||||
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
||||
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (in_tensors[0]->shape().size() > 4) {
|
||||
if (in_tensors[0].Shape().size() > 4) {
|
||||
MS_LOG(ERROR) << "Npu does not support input tensor dims greater than 4";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::set<schema::PrimitiveType> int32_lists = {schema::PrimitiveType_Cast, schema::PrimitiveType_StridedSlice};
|
||||
auto support_int32 = in_tensors[0]->data_type() == kNumberTypeInt32 &&
|
||||
auto support_int32 = in_tensors[0].DataType() == DataType::kNumberTypeInt32 &&
|
||||
find(int32_lists.begin(), int32_lists.end(), primitive->value_type()) != int32_lists.end();
|
||||
if (in_tensors[0]->data_type() != kNumberTypeFloat32 && in_tensors[0]->data_type() != kNumberTypeFloat16 &&
|
||||
!support_int32) {
|
||||
MS_LOG(ERROR) << "Npu does not support datatype " << in_tensors[0]->data_type() << " for op type "
|
||||
if (in_tensors[0].DataType() != DataType::kNumberTypeFloat32 &&
|
||||
in_tensors[0].DataType() != DataType::kNumberTypeFloat16 && !support_int32) {
|
||||
MS_LOG(ERROR) << "Npu does not support datatype " << static_cast<int>(in_tensors[0].DataType()) << " for op type "
|
||||
<< primitive->value_type();
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int PadNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int PadNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto pad_prim = primitive->value_as_PadFusion();
|
||||
if (pad_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -33,15 +33,15 @@ int PadNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<te
|
|||
if (pad_prim->paddings() != nullptr) {
|
||||
return RET_OK;
|
||||
}
|
||||
if (in_tensors.size() >= 2 && in_tensors[1]->data() != nullptr) {
|
||||
if (in_tensors.size() >= 2 && in_tensors[1].Data() != nullptr) {
|
||||
return RET_OK;
|
||||
}
|
||||
MS_LOG(WARNING) << "NPU pad only support constant pad size.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
|
||||
int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
pad_ = new (std::nothrow) hiai::op::PadV2(name_);
|
||||
if (pad_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -67,9 +67,9 @@ int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor:
|
|||
auto paddings = std::vector<int64_t>(paddings_data->begin(), paddings_data->end());
|
||||
paddings_vec_.insert(paddings_vec_.end(), paddings.begin(), paddings.end());
|
||||
}
|
||||
} else if (in_tensors.size() >= 2 && in_tensors[1]->data() != nullptr) {
|
||||
for (int i = 0; i < in_tensors[1]->ElementsNum(); i++) {
|
||||
paddings_vec_.push_back(static_cast<int *>(in_tensors[1]->data())[i]);
|
||||
} else if (in_tensors.size() >= 2 && in_tensors[1].Data() != nullptr) {
|
||||
for (int i = 0; i < in_tensors[1].ElementNum(); i++) {
|
||||
paddings_vec_.push_back(static_cast<const int *>(in_tensors[1].Data().get())[i]);
|
||||
}
|
||||
} else {
|
||||
MS_LOG(ERROR) << "NPU pad only support constant pad size.";
|
||||
|
|
@ -86,8 +86,8 @@ int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor:
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int PadNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int PadNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
int size = static_cast<int>(paddings_vec_.size() / 2);
|
||||
ge::TensorDesc padding_tensor_desc(ge::Shape({size, 2}), ge::FORMAT_NCHW, ge::DT_INT32);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class PadNPUOp : public NPUOp {
|
||||
public:
|
||||
PadNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
PadNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~PadNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,11 +15,10 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/reduce_npu.h"
|
||||
#include <memory>
|
||||
|
||||
namespace mindspore {
|
||||
int ReduceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ReduceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto reduce_prim = primitive->value_as_ReduceFusion();
|
||||
if (reduce_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -37,8 +36,8 @@ int ReduceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ReduceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ReduceNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto reduce_prim = primitive->value_as_ReduceFusion();
|
||||
if (reduce_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -59,8 +58,8 @@ int ReduceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ReduceNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ReduceNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
if (reduce_mode_ == schema::ReduceMode_ReduceMean) {
|
||||
auto reduce_mean = reinterpret_cast<hiai::op::ReduceMean *>(reduce_);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class ReduceNPUOp : public NPUOp {
|
||||
public:
|
||||
ReduceNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ReduceNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ReduceNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,26 +15,25 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/reshape_npu.h"
|
||||
#include <memory>
|
||||
#include "include/graph/op/all_ops.h"
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
namespace mindspore {
|
||||
int ReshapeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ReshapeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() != 2) {
|
||||
MS_LOG(WARNING) << "Npu op should have w2 input tensors.";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
auto shape_tensor = in_tensors.at(1);
|
||||
if (shape_tensor->data() == nullptr) {
|
||||
if (shape_tensor.Data() == nullptr) {
|
||||
MS_LOG(WARNING) << "Npu reshape op only supports const shape.";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int ReshapeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ReshapeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
reshape_ = new (std::nothrow) hiai::op::Reshape(name_);
|
||||
if (reshape_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -43,8 +42,8 @@ int ReshapeNPUOp::Init(const schema::Primitive *primitive, const std::vector<ten
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ReshapeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ReshapeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
reshape_->set_input_x(*npu_inputs[0]);
|
||||
reshape_->set_input_shape(*npu_inputs[1]);
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@
|
|||
namespace mindspore {
|
||||
class ReshapeNPUOp : public NPUOp {
|
||||
public:
|
||||
ReshapeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ReshapeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ReshapeNPUOp() override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int ResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto resize_prim = primitive->value_as_Resize();
|
||||
if (resize_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -32,16 +32,15 @@ int ResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector
|
|||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
if (in_tensors[0]->shape()[1] > out_tensors[0]->shape()[1] ||
|
||||
in_tensors[0]->shape()[2] > out_tensors[0]->shape()[2]) {
|
||||
if (in_tensors[0].Shape()[1] > out_tensors[0].Shape()[1] || in_tensors[0].Shape()[2] > out_tensors[0].Shape()[2]) {
|
||||
MS_LOG(WARNING) << "Npu resize does not support reduction.";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto resize_prim = primitive->value_as_Resize();
|
||||
if (resize_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -51,13 +50,13 @@ int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
new_height_ = resize_prim->new_height();
|
||||
new_width_ = resize_prim->new_width();
|
||||
} else if (in_tensors.size() == 2) {
|
||||
auto out_size = in_tensors.at(1)->data();
|
||||
auto out_size = in_tensors.at(1).Data();
|
||||
if (out_size == nullptr) {
|
||||
MS_LOG(ERROR) << "Out size is not assigned";
|
||||
return RET_ERROR;
|
||||
}
|
||||
new_height_ = out_tensors.at(0)->shape().at(1);
|
||||
new_width_ = out_tensors.at(0)->shape().at(2);
|
||||
new_height_ = out_tensors.at(0).Shape().at(1);
|
||||
new_width_ = out_tensors.at(0).Shape().at(2);
|
||||
} else {
|
||||
MS_LOG(ERROR) << "Get resize op new_height and new_width error.";
|
||||
return RET_ERROR;
|
||||
|
|
@ -97,8 +96,8 @@ int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ResizeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ResizeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
if (resize_method_ == schema::ResizeMethod_LINEAR) {
|
||||
auto resize_bilinear = reinterpret_cast<hiai::op::ResizeBilinearV2 *>(resize_);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class ResizeNPUOp : public NPUOp {
|
||||
public:
|
||||
ResizeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ResizeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ResizeNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@
|
|||
*/
|
||||
|
||||
#include "src/delegate/npu/op/scale_npu.h"
|
||||
#include <memory>
|
||||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
auto scale_prim = primitive->value_as_ScaleFusion();
|
||||
if (scale_prim == nullptr) {
|
||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||
|
|
@ -28,7 +27,7 @@ int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<
|
|||
}
|
||||
axis_ = scale_prim->axis();
|
||||
if (axis_ < 0) {
|
||||
axis_ = axis_ + in_tensors[0]->shape().size();
|
||||
axis_ = axis_ + in_tensors[0].Shape().size();
|
||||
}
|
||||
if (axis_ != 1 && axis_ != 3) {
|
||||
MS_LOG(WARNING) << "Npu scale axis attr only support 1 or channel, now is " << axis_;
|
||||
|
|
@ -37,8 +36,8 @@ int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ScaleNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int ScaleNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
op_ = new (std::nothrow) hiai::op::Scale(name_);
|
||||
if (op_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -62,12 +61,12 @@ int ScaleNPUOp::Init(const schema::Primitive *primitive, const std::vector<tenso
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int ScaleNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int ScaleNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
op_->set_input_x(*npu_inputs.at(0));
|
||||
MS_ASSERT(in_tensors.size() > 1);
|
||||
auto scale_shape = in_tensors[1]->shape();
|
||||
auto scale_shape = in_tensors[1].Shape();
|
||||
auto scale_tensor = ConverterToNPUTensor(in_tensors[1]);
|
||||
if (scale_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Get scale_tensor failed.";
|
||||
|
|
@ -84,7 +83,7 @@ int ScaleNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
|||
op_->set_input_scale(*scale_);
|
||||
|
||||
if (in_tensors.size() > 2 && in_tensors[2] != nullptr) {
|
||||
auto bias_shape = in_tensors[2]->shape();
|
||||
auto bias_shape = in_tensors[2].Shape();
|
||||
auto bias_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||
if (bias_tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Get bias_tensor failed.";
|
||||
|
|
|
|||
|
|
@ -25,20 +25,20 @@
|
|||
namespace mindspore {
|
||||
class ScaleNPUOp : public NPUOp {
|
||||
public:
|
||||
ScaleNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
ScaleNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~ScaleNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int SliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int SliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
slice_ = new (std::nothrow) hiai::op::Slice(name_);
|
||||
if (slice_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -28,8 +28,8 @@ int SliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tenso
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int SliceNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SliceNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
slice_->set_input_x(*npu_inputs[0]);
|
||||
slice_->set_input_offsets(*npu_inputs[1]);
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class SliceNPUOp : public NPUOp {
|
||||
public:
|
||||
SliceNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
SliceNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~SliceNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "src/delegate/npu/op/softmax_npu.h"
|
||||
namespace mindspore {
|
||||
int SoftmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int SoftmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
softmax_ = new (std::nothrow) hiai::op::Softmax(name_);
|
||||
if (softmax_ == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||
|
|
@ -30,15 +30,15 @@ int SoftmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<ten
|
|||
}
|
||||
auto axis = static_cast<int>(*(softmax_prim->axis()->begin()));
|
||||
if (axis == -1) {
|
||||
softmax_->set_attr_axis(in_tensors[0]->shape().size() + axis);
|
||||
softmax_->set_attr_axis(in_tensors[0].Shape().size() + axis);
|
||||
} else {
|
||||
softmax_->set_attr_axis(axis);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int SoftmaxNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SoftmaxNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
softmax_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class SoftmaxNPUOp : public NPUOp {
|
||||
public:
|
||||
SoftmaxNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
SoftmaxNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~SoftmaxNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int SplitNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int SplitNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
split_ = new (std::nothrow) hiai::op::SplitV(name_);
|
||||
if (split_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New split npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -53,8 +53,8 @@ int SplitNPUOp::Init(const schema::Primitive *primitive, const std::vector<tenso
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int SplitNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SplitNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
ge::TensorDesc split_dim_tensor_desc(ge::Shape({1}), ge::FORMAT_NCHW, ge::DT_INT32);
|
||||
ge::TensorPtr split_dim_tensor = std::make_shared<hiai::Tensor>(split_dim_tensor_desc);
|
||||
|
|
|
|||
|
|
@ -24,22 +24,22 @@
|
|||
namespace mindspore {
|
||||
class SplitNPUOp : public NPUOp {
|
||||
public:
|
||||
SplitNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
SplitNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~SplitNPUOp();
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
int HandleAxis();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "src/delegate/npu/op/squeeze_npu.h"
|
||||
namespace mindspore {
|
||||
int SqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int SqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
squeeze_ = new (std::nothrow) hiai::op::Squeeze(name_);
|
||||
if (squeeze_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New squeeze npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -35,8 +35,8 @@ int SqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<ten
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int SqueezeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SqueezeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
squeeze_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -23,22 +23,22 @@
|
|||
namespace mindspore {
|
||||
class SqueezeNPUOp : public NPUOp {
|
||||
public:
|
||||
SqueezeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
SqueezeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~SqueezeNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@
|
|||
#include "src/delegate/npu/pass/npu_pass_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int StridedSliceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int StridedSliceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
// Only onnx StridedSlice has 5 in_tensors, of which the 4th input is axes and the 5th input is strides.
|
||||
if (in_tensors.size() == 5) {
|
||||
vector<int> axes;
|
||||
size_t size = in_tensors[3]->shape()[0];
|
||||
size_t size = in_tensors[3].Shape()[0];
|
||||
axes.resize(size);
|
||||
memcpy(axes.data(), in_tensors[3]->data(), sizeof(int) * size);
|
||||
memcpy(axes.data(), in_tensors[3].Data().get(), sizeof(int) * size);
|
||||
for (int i = 0; i < axes.size(); ++i) {
|
||||
if (i != axes[i]) {
|
||||
MS_LOG(WARNING) << "Does not support setting axis, so the axis must be continuous.";
|
||||
|
|
@ -37,8 +37,8 @@ int StridedSliceNPUOp::IsSupport(const schema::Primitive *primitive, const std::
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int StridedSliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int StridedSliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
strided_slice_ = new (std::nothrow) hiai::op::StridedSlice(name_);
|
||||
if (strided_slice_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New stridedSlice npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -57,8 +57,8 @@ int StridedSliceNPUOp::Init(const schema::Primitive *primitive, const std::vecto
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int StridedSliceNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int StridedSliceNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
strided_slice_->set_attr_begin_mask(begins_mask_);
|
||||
strided_slice_->set_attr_ellipsis_mask(ellipsis_mask_);
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class StridedSliceNPUOp : public NPUOp {
|
||||
public:
|
||||
StridedSliceNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
StridedSliceNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~StridedSliceNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -19,20 +19,20 @@
|
|||
#include "src/delegate/npu/npu_converter_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
int TileNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int TileNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() != 2) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
auto multiple_tensor = in_tensors[1];
|
||||
if (multiple_tensor->ElementsNum() > 4 || multiple_tensor->data() == nullptr) {
|
||||
if (multiple_tensor.ElementNum() > 4 || multiple_tensor.Data() == nullptr) {
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int TileNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int TileNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
tile_ = new (std::nothrow) hiai::op::Tile(name_);
|
||||
if (tile_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New tile npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -41,17 +41,17 @@ int TileNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int TileNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int TileNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
tile_->set_input_x(*npu_inputs[0]);
|
||||
|
||||
std::vector<int> multiples;
|
||||
auto multiple_data = reinterpret_cast<int *>(in_tensors[1]->data());
|
||||
if (multiple_data == nullptr) {
|
||||
if (in_tensors[1].Data() == nullptr) {
|
||||
return RET_ERROR;
|
||||
}
|
||||
for (int i = 0; i < in_tensors[1]->ElementsNum(); ++i) {
|
||||
auto multiple_data = reinterpret_cast<const int *>(in_tensors[1].Data().get());
|
||||
for (int i = 0; i < in_tensors[1].ElementNum(); ++i) {
|
||||
multiples.push_back(multiple_data[i]);
|
||||
}
|
||||
ge::TensorDesc multiple_tensor_desc(ge::Shape({static_cast<int64_t>(multiples.size())}), ge::FORMAT_NCHW,
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@
|
|||
namespace mindspore {
|
||||
class TileNPUOp : public NPUOp {
|
||||
public:
|
||||
TileNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
TileNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~TileNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
|
|
@ -16,18 +16,18 @@
|
|||
|
||||
#include "src/delegate/npu/op/transpose_npu.h"
|
||||
namespace mindspore {
|
||||
int TransposeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int TransposeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors.size() < 2) {
|
||||
MS_LOG(ERROR) << "Npu transpose must get fixed values of transpose axis.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
auto perm_num = in_tensors.at(1)->ElementsNum();
|
||||
auto perm_data = reinterpret_cast<int *>(in_tensors.at(1)->data());
|
||||
if (perm_data == nullptr) {
|
||||
auto perm_num = in_tensors.at(1).ElementNum();
|
||||
if (in_tensors.at(1).Data() == nullptr) {
|
||||
MS_LOG(ERROR) << "Npu transpose must get fixed values of transpose axis.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
auto perm_data = reinterpret_cast<const int *>(in_tensors.at(1).Data().get());
|
||||
for (int i = 0; i < perm_num; i++) {
|
||||
perm_.push_back(perm_data[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,24 +23,24 @@
|
|||
namespace mindspore {
|
||||
class TransposeNPUOp : public NPUOp {
|
||||
public:
|
||||
TransposeNPUOp(const std::vector<tensor::MSTensor *> &in_tensors, const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
std::vector<int> perm, std::string name)
|
||||
TransposeNPUOp(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::vector<int> perm, std::string name)
|
||||
: NPUOp(nullptr, in_tensors, out_tensors, name) {
|
||||
perm_ = perm;
|
||||
type_ = schema::PrimitiveType_Transpose;
|
||||
}
|
||||
|
||||
TransposeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
TransposeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~TransposeNPUOp() override = default;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,17 +18,17 @@
|
|||
#include <memory>
|
||||
|
||||
namespace mindspore {
|
||||
int UnsqueezeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
if (in_tensors[0]->shape().size() > 3) {
|
||||
int UnsqueezeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
if (in_tensors[0].Shape().size() > 3) {
|
||||
MS_LOG(WARNING) << "The dimension of output not support bigger than 4.";
|
||||
return RET_NOT_SUPPORT;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int UnsqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
||||
int UnsqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||
unsqueeze_ = new (std::nothrow) hiai::op::ExpandDims(name_);
|
||||
if (unsqueeze_ == nullptr) {
|
||||
MS_LOG(ERROR) << "New unsqueeze npu operator for op " << name_ << " failed.";
|
||||
|
|
@ -51,8 +51,8 @@ int UnsqueezeNPUOp::Init(const schema::Primitive *primitive, const std::vector<t
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int UnsqueezeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int UnsqueezeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) {
|
||||
unsqueeze_->set_input_x(*npu_inputs[0]);
|
||||
return RET_OK;
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@
|
|||
namespace mindspore {
|
||||
class UnsqueezeNPUOp : public NPUOp {
|
||||
public:
|
||||
UnsqueezeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
||||
UnsqueezeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||
|
||||
~UnsqueezeNPUOp() override;
|
||||
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
||||
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||
|
||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
||||
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||
|
||||
ge::Operator *GetNPUOp() override;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue