forked from mindspore-Ecosystem/mindspore
!19940 [MSLITE][DEVELOP] modify lite for new api
Merge pull request !19940 from yangruoqi713/master
This commit is contained in:
commit
90f37a98c4
|
@ -216,8 +216,6 @@ if(PLATFORM_ARM64)
|
||||||
endif()
|
endif()
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/format.h DESTINATION ${RUNTIME_INC_DIR}/ir
|
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
|
||||||
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
__install_micro_wrapper()
|
__install_micro_wrapper()
|
||||||
|
@ -269,8 +267,6 @@ elseif(PLATFORM_ARM32)
|
||||||
endif()
|
endif()
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/format.h DESTINATION ${RUNTIME_INC_DIR}/ir
|
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
|
||||||
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
__install_micro_wrapper()
|
__install_micro_wrapper()
|
||||||
|
@ -306,6 +302,8 @@ elseif(WIN32)
|
||||||
DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME})
|
DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${glog_LIBPATH}/../bin/libglog.dll DESTINATION ${CONVERTER_ROOT_DIR}/lib
|
install(FILES ${glog_LIBPATH}/../bin/libglog.dll DESTINATION ${CONVERTER_ROOT_DIR}/lib
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${CONVERTER_ROOT_DIR}/include/api
|
||||||
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
install(DIRECTORY ${TOP_DIR}/mindspore/core/abstract/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract
|
install(DIRECTORY ${TOP_DIR}/mindspore/core/abstract/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
|
||||||
install(DIRECTORY ${TOP_DIR}/mindspore/core/base/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base
|
install(DIRECTORY ${TOP_DIR}/mindspore/core/base/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base
|
||||||
|
@ -372,8 +370,6 @@ elseif(WIN32)
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/format.h DESTINATION ${RUNTIME_INC_DIR}/ir
|
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
|
||||||
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR}
|
install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR}
|
||||||
|
@ -404,8 +400,6 @@ else()
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${RUNTIME_INC_DIR}/ir/dtype
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||||
install(FILES ${TOP_DIR}/mindspore/core/ir/format.h DESTINATION ${RUNTIME_INC_DIR}/ir
|
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
|
||||||
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/${MINDSPORE_LITE_LIB_NAME}.so DESTINATION ${RUNTIME_LIB_DIR}
|
install(FILES ${TOP_DIR}/mindspore/lite/build/src/${MINDSPORE_LITE_LIB_NAME}.so DESTINATION ${RUNTIME_LIB_DIR}
|
||||||
|
@ -423,6 +417,8 @@ else()
|
||||||
install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${CONVERTER_ROOT_DIR}/include
|
install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${CONVERTER_ROOT_DIR}/include
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h"
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h"
|
||||||
PATTERN "train*" EXCLUDE PATTERN "delegate.h" EXCLUDE PATTERN "lite_session.h" EXCLUDE)
|
PATTERN "train*" EXCLUDE PATTERN "delegate.h" EXCLUDE PATTERN "lite_session.h" EXCLUDE)
|
||||||
|
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${CONVERTER_ROOT_DIR}/include/api
|
||||||
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
|
||||||
install(DIRECTORY ${TOP_DIR}/mindspore/core/abstract/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract
|
install(DIRECTORY ${TOP_DIR}/mindspore/core/abstract/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract
|
||||||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
|
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
|
||||||
install(DIRECTORY ${TOP_DIR}/mindspore/core/base/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base
|
install(DIRECTORY ${TOP_DIR}/mindspore/core/base/ DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MINDSPORE_LITE_INCLUDE_ALLOCATOR_H_
|
#ifndef MINDSPORE_INCLUDE_API_ALLOCATOR_H
|
||||||
#define MINDSPORE_LITE_INCLUDE_ALLOCATOR_H_
|
#define MINDSPORE_INCLUDE_API_ALLOCATOR_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/lite_utils.h"
|
#include "include/api/types.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
/// \brief Allocator defined a memory pool for malloc memory and free memory dynamically.
|
/// \brief Allocator defined a memory pool for malloc memory and free memory dynamically.
|
||||||
|
@ -85,4 +85,4 @@ class MS_API Allocator {
|
||||||
size_t aligned_size_ = 32;
|
size_t aligned_size_ = 32;
|
||||||
};
|
};
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
#endif // MINDSPORE_LITE_INCLUDE_ALLOCATOR_H_
|
#endif // MINDSPORE_INCLUDE_API_ALLOCATOR_H
|
|
@ -36,6 +36,7 @@ enum DeviceType {
|
||||||
};
|
};
|
||||||
|
|
||||||
class Allocator;
|
class Allocator;
|
||||||
|
class Delegate;
|
||||||
class DeviceInfoContext;
|
class DeviceInfoContext;
|
||||||
|
|
||||||
class MS_API Context {
|
class MS_API Context {
|
||||||
|
@ -57,6 +58,9 @@ class MS_API Context {
|
||||||
void SetEnableParallel(bool is_parallel);
|
void SetEnableParallel(bool is_parallel);
|
||||||
bool GetEnableParallel() const;
|
bool GetEnableParallel() const;
|
||||||
|
|
||||||
|
void SetDelegate(const std::shared_ptr<Delegate> &delegate);
|
||||||
|
std::shared_ptr<Delegate> GetDelegate() const;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<DeviceInfoContext>> &MutableDeviceInfo();
|
std::vector<std::shared_ptr<DeviceInfoContext>> &MutableDeviceInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -23,6 +23,7 @@ enum class DataType : int {
|
||||||
kObjectTypeList = 13,
|
kObjectTypeList = 13,
|
||||||
kObjectTypeTuple = 14,
|
kObjectTypeTuple = 14,
|
||||||
kObjectTypeTensorType = 17,
|
kObjectTypeTensorType = 17,
|
||||||
|
kNumberTypeBegin = 29,
|
||||||
kNumberTypeBool = 30,
|
kNumberTypeBool = 30,
|
||||||
kNumberTypeInt8 = 32,
|
kNumberTypeInt8 = 32,
|
||||||
kNumberTypeInt16 = 33,
|
kNumberTypeInt16 = 33,
|
||||||
|
|
|
@ -14,15 +14,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
#ifndef MINDSPORE_INCLUDE_API_DELEGATE_H
|
||||||
#define MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
#define MINDSPORE_INCLUDE_API_DELEGATE_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/ms_tensor.h"
|
#include "schema/model_generated.h"
|
||||||
#include "include/context.h"
|
#include "include/api/kernel.h"
|
||||||
#include "include/kernel.h"
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -35,8 +34,8 @@ using KernelIter = std::vector<kernel::Kernel *>::iterator;
|
||||||
class MS_API DelegateModel {
|
class MS_API DelegateModel {
|
||||||
public:
|
public:
|
||||||
/// \brief Constructor of MindSpore Lite DelegateModel.
|
/// \brief Constructor of MindSpore Lite DelegateModel.
|
||||||
DelegateModel(std::vector<kernel::Kernel *> *kernels, const std::vector<tensor::MSTensor *> &inputs,
|
DelegateModel(std::vector<kernel::Kernel *> *kernels, const std::vector<MSTensor> &inputs,
|
||||||
const std::vector<tensor::MSTensor *> &outputs,
|
const std::vector<MSTensor> &outputs,
|
||||||
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives, SchemaVersion version)
|
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives, SchemaVersion version)
|
||||||
: kernels_(kernels), inputs_(inputs), outputs_(outputs), primitives_(primitives), version_(version) {}
|
: kernels_(kernels), inputs_(inputs), outputs_(outputs), primitives_(primitives), version_(version) {}
|
||||||
|
|
||||||
|
@ -71,12 +70,12 @@ class MS_API DelegateModel {
|
||||||
/// \brief Get the input tensors of DelegateModel.
|
/// \brief Get the input tensors of DelegateModel.
|
||||||
///
|
///
|
||||||
/// \return The input tensor vector of DelegateModel.
|
/// \return The input tensor vector of DelegateModel.
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &inputs() { return this->inputs_; }
|
const std::vector<mindspore::MSTensor> &inputs() { return this->inputs_; }
|
||||||
|
|
||||||
/// \brief Get the output tensors of DelegateModel.
|
/// \brief Get the output tensors of DelegateModel.
|
||||||
///
|
///
|
||||||
/// \return The ioutput tensor vector of DelegateModel.
|
/// \return The ioutput tensor vector of DelegateModel.
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &outputs() { return this->outputs_; }
|
const std::vector<mindspore::MSTensor> &outputs() { return this->outputs_; }
|
||||||
|
|
||||||
/// \brief Get the ms model version.
|
/// \brief Get the ms model version.
|
||||||
///
|
///
|
||||||
|
@ -85,14 +84,12 @@ class MS_API DelegateModel {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<kernel::Kernel *> *kernels_;
|
std::vector<kernel::Kernel *> *kernels_;
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &inputs_;
|
const std::vector<mindspore::MSTensor> &inputs_;
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &outputs_;
|
const std::vector<mindspore::MSTensor> &outputs_;
|
||||||
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives_;
|
const std::map<kernel::Kernel *, const schema::Primitive *> &primitives_;
|
||||||
SchemaVersion version_;
|
SchemaVersion version_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*DelegateHook)(std::shared_ptr<Delegate> delegate);
|
|
||||||
static void HookNullFuc(std::shared_ptr<Delegate> delegate) {}
|
|
||||||
class MS_API Delegate {
|
class MS_API Delegate {
|
||||||
public:
|
public:
|
||||||
/// \brief Constructor of MindSpore Lite Delegate.
|
/// \brief Constructor of MindSpore Lite Delegate.
|
||||||
|
@ -112,10 +109,6 @@ class MS_API Delegate {
|
||||||
///
|
///
|
||||||
/// \param[in] model Define the delegate model to be built.
|
/// \param[in] model Define the delegate model to be built.
|
||||||
virtual int Build(DelegateModel *model) = 0;
|
virtual int Build(DelegateModel *model) = 0;
|
||||||
|
|
||||||
DelegateHook init_hook_ = HookNullFuc;
|
|
||||||
DelegateHook build_hook_ = HookNullFuc;
|
|
||||||
DelegateHook run_hook_ = HookNullFuc;
|
|
||||||
};
|
};
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
#endif // MINDSPORE_LITE_DELEGATE_DELEGATE_H_
|
#endif // MINDSPORE_INCLUDE_API_DELEGATE_H
|
|
@ -16,8 +16,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MINDSPORE_CORE_IR_FORMAT_H_
|
#ifndef MINDSPORE_INCLUDE_API_FORMAT_H
|
||||||
#define MINDSPORE_CORE_IR_FORMAT_H_
|
#define MINDSPORE_INCLUDE_API_FORMAT_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -43,4 +43,4 @@ enum Format : int64_t {
|
||||||
NCW = 17
|
NCW = 17
|
||||||
};
|
};
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
#endif // MINDSPORE_CORE_IR_FORMAT_H_
|
#endif // MINDSPORE_INCLUDE_API_FORMAT_H
|
|
@ -14,22 +14,22 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MINDSPORE_LITE_SRC_KERNEL_H_
|
#ifndef MINDSPORE_INCLUDE_API_KERNEL_H
|
||||||
#define MINDSPORE_LITE_SRC_KERNEL_H_
|
#define MINDSPORE_INCLUDE_API_KERNEL_H
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "schema/model_generated.h"
|
#include "schema/model_generated.h"
|
||||||
#include "include/lite_utils.h"
|
#include "include/api/types.h"
|
||||||
#include "include/context.h"
|
#include "include/api/context.h"
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
namespace mindspore::kernel {
|
||||||
class Kernel {
|
class Kernel {
|
||||||
public:
|
public:
|
||||||
Kernel() = default;
|
Kernel() = default;
|
||||||
|
|
||||||
Kernel(const std::vector<tensor::MSTensor *> &inputs, const std::vector<tensor::MSTensor *> &outputs,
|
Kernel(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs,
|
||||||
const schema::Primitive *primitive, const lite::Context *ctx)
|
const schema::Primitive *primitive, const mindspore::Context *ctx)
|
||||||
: inputs_(std::move(inputs)), outputs_(std::move(outputs)), primitive_(primitive), context_(ctx) {
|
: inputs_(std::move(inputs)), outputs_(std::move(outputs)), primitive_(primitive), context_(ctx) {
|
||||||
if (primitive != nullptr) {
|
if (primitive != nullptr) {
|
||||||
type_ = primitive->value_type();
|
type_ = primitive->value_type();
|
||||||
|
@ -46,33 +46,34 @@ class Kernel {
|
||||||
|
|
||||||
virtual schema::PrimitiveType type() const { return type_; }
|
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_inputs(const std::vector<mindspore::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_outputs(const std::vector<mindspore::tensor::MSTensor *> &out_tensors) {
|
virtual void set_input(mindspore::MSTensor in_tensor, int index) { this->inputs_[index] = in_tensor; }
|
||||||
this->outputs_ = out_tensors;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_; }
|
std::string name() const { return this->name_; }
|
||||||
|
|
||||||
void set_name(const std::string &name) { this->name_ = 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_; }
|
const schema::Primitive *primitive() const { return this->primitive_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<mindspore::tensor::MSTensor *> inputs_;
|
std::vector<mindspore::MSTensor> inputs_;
|
||||||
std::vector<mindspore::tensor::MSTensor *> outputs_;
|
std::vector<mindspore::MSTensor> outputs_;
|
||||||
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
const schema::Primitive *primitive_ = nullptr;
|
const schema::Primitive *primitive_ = nullptr;
|
||||||
const lite::Context *context_ = nullptr;
|
const mindspore::Context *context_ = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace mindspore::kernel
|
} // namespace mindspore::kernel
|
||||||
|
|
||||||
#endif // MINDSPORE_LITE_SRC_KERNEL_H_
|
#endif // MINDSPORE_INCLUDE_API_KERNEL_H
|
|
@ -23,6 +23,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "include/api/data_type.h"
|
#include "include/api/data_type.h"
|
||||||
#include "include/api/dual_abi_helper.h"
|
#include "include/api/dual_abi_helper.h"
|
||||||
|
#include "include/api/format.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define MS_API __declspec(dllexport)
|
#define MS_API __declspec(dllexport)
|
||||||
|
@ -56,6 +57,7 @@ enum OptimizationLevel : uint32_t {
|
||||||
kOptimizationType = 0xFFFFFFFF
|
kOptimizationType = 0xFFFFFFFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Allocator;
|
||||||
class MS_API MSTensor {
|
class MS_API MSTensor {
|
||||||
public:
|
public:
|
||||||
class Impl;
|
class Impl;
|
||||||
|
@ -91,6 +93,17 @@ class MS_API MSTensor {
|
||||||
MSTensor *Clone() const;
|
MSTensor *Clone() const;
|
||||||
bool operator==(std::nullptr_t) const;
|
bool operator==(std::nullptr_t) const;
|
||||||
bool operator!=(std::nullptr_t) const;
|
bool operator!=(std::nullptr_t) const;
|
||||||
|
bool operator==(const MSTensor &tensor) const;
|
||||||
|
|
||||||
|
void SetShape(const std::vector<int64_t> &shape);
|
||||||
|
void SetDataType(enum DataType data_type);
|
||||||
|
void SetTensorName(const std::string &name);
|
||||||
|
void SetAllocator(std::shared_ptr<Allocator> allocator);
|
||||||
|
std::shared_ptr<Allocator> allocator() const;
|
||||||
|
void SetFormat(mindspore::Format format);
|
||||||
|
mindspore::Format format() const;
|
||||||
|
void SetData(void *data);
|
||||||
|
const std::shared_ptr<Impl> impl() const { return impl_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// api without std::string
|
// api without std::string
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "base/base.h"
|
#include "base/base.h"
|
||||||
#include "ir/anf.h"
|
#include "ir/anf.h"
|
||||||
#include "ir/dtype/type_id.h"
|
#include "ir/dtype/type_id.h"
|
||||||
#include "ir/format.h"
|
#include "include/api/format.h"
|
||||||
#include "utils/log_adapter.h"
|
#include "utils/log_adapter.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
typedef std::pair<std::map<std::string, int64_t>, std::map<int64_t, std::string>> AttrConverterPair;
|
typedef std::pair<std::map<std::string, int64_t>, std::map<int64_t, std::string>> AttrConverterPair;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/model.h"
|
#include "include/model.h"
|
||||||
#include "include/ms_tensor.h"
|
#include "include/api/types.h"
|
||||||
#include "schema/model_generated.h"
|
#include "schema/model_generated.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
@ -46,7 +46,7 @@ class MS_API KernelInterface {
|
||||||
/// \param[in] primitive Define the attributes of op.
|
/// \param[in] primitive Define the attributes of op.
|
||||||
///
|
///
|
||||||
/// \return STATUS as an error code of inferring, STATUS is defined in errorcode.h..
|
/// \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) {
|
const schema::Primitive *primitive) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class MS_API KernelInterface {
|
||||||
/// \param[in] param Define the contr of performance.
|
/// \param[in] param Define the contr of performance.
|
||||||
///
|
///
|
||||||
/// \return STATUS as an error code of inferring, STATUS is defined in errorcode.h.
|
/// \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) {
|
CapabilityParam *param) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "schema/model_generated.h"
|
#include "schema/model_generated.h"
|
||||||
#include "include/context.h"
|
#include "include/api/context.h"
|
||||||
#include "include/ms_tensor.h"
|
#include "include/api/types.h"
|
||||||
#include "include/kernel.h"
|
#include "include/api/kernel.h"
|
||||||
|
#include "ir/dtype/type_id.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
|
@ -57,8 +58,8 @@ struct MS_API KernelDesc {
|
||||||
///
|
///
|
||||||
/// \return Smart Pointer of kernel.
|
/// \return Smart Pointer of kernel.
|
||||||
using CreateKernel = std::function<std::shared_ptr<kernel::Kernel>(
|
using CreateKernel = std::function<std::shared_ptr<kernel::Kernel>(
|
||||||
const std::vector<tensor::MSTensor *> &inputs, const std::vector<tensor::MSTensor *> &outputs,
|
const std::vector<MSTensor> &inputs, const std::vector<MSTensor> &outputs, const schema::Primitive *primitive,
|
||||||
const schema::Primitive *primitive, const lite::Context *ctx)>;
|
const mindspore::Context *ctx)>;
|
||||||
|
|
||||||
/// \brief RegisterKernel Defined registration of kernel.
|
/// \brief RegisterKernel Defined registration of kernel.
|
||||||
class MS_API RegisterKernel {
|
class MS_API RegisterKernel {
|
||||||
|
|
|
@ -127,9 +127,13 @@ set(CODER_OPCODERS_SRC
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LITE_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/file_utils.cc
|
||||||
${LITE_DIR}/src/common/graph_util.cc
|
${LITE_DIR}/src/common/graph_util.cc
|
||||||
${LITE_DIR}/src/common/prim_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/common/tensor_util.cc
|
||||||
${LITE_DIR}/src/runtime/infer_manager.cc
|
${LITE_DIR}/src/runtime/infer_manager.cc
|
||||||
${LITE_DIR}/src/registry/kernel_interface.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.cc
|
||||||
${LITE_DIR}/src/registry/register_kernel_impl.cc
|
${LITE_DIR}/src/registry/register_kernel_impl.cc
|
||||||
${LITE_DIR}/src/lite_model.cc
|
${LITE_DIR}/src/lite_model.cc
|
||||||
|
${LITE_DIR}/src/ms_tensor.cc
|
||||||
${LITE_DIR}/src/tensorlist.cc
|
${LITE_DIR}/src/tensorlist.cc
|
||||||
${LITE_DIR}/src/tensor.cc
|
${LITE_DIR}/src/tensor.cc
|
||||||
${LITE_DIR}/src/weight_decoder.cc
|
${LITE_DIR}/src/weight_decoder.cc
|
||||||
${LITE_DIR}/src/huffman_decode.cc
|
${LITE_DIR}/src/huffman_decode.cc
|
||||||
${LITE_DIR}/src/common/log_adapter.cc
|
${LITE_DIR}/src/common/log_adapter.cc
|
||||||
${LITE_DIR}/src/common/utils.cc
|
${LITE_DIR}/src/common/utils.cc
|
||||||
|
${LITE_DIR}/../core/utils/status.cc
|
||||||
### tools
|
### tools
|
||||||
${LITE_DIR}/tools/common/flag_parser.cc
|
${LITE_DIR}/tools/common/flag_parser.cc
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,7 +38,7 @@ const char tensor_header[] = R"RAW(
|
||||||
#define MINDSPORE_LITE_MICRO_LIBRARY_SOURCE_TENSOR_H_
|
#define MINDSPORE_LITE_MICRO_LIBRARY_SOURCE_TENSOR_H_
|
||||||
|
|
||||||
#include "include/ms_tensor.h"
|
#include "include/ms_tensor.h"
|
||||||
#include "include/ir/format.h"
|
#include "include/api/format.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
|
|
|
@ -62,6 +62,7 @@ endif()
|
||||||
|
|
||||||
set(LITE_SRC
|
set(LITE_SRC
|
||||||
${API_SRC}
|
${API_SRC}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/common/context_util.cc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/common/file_utils.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/common/file_utils.cc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/common/utils.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/common/utils.cc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/common/graph_util.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 <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "mindspore/lite/src/tensor.h"
|
#include "src/tensor.h"
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
#include "tools/common/option.h"
|
#include "tools/common/option.h"
|
||||||
#include "include/errorcode.h"
|
#include "include/errorcode.h"
|
||||||
|
|
|
@ -270,5 +270,15 @@ int CheckTensorsInvalid(const std::vector<Tensor *> &tensors) {
|
||||||
}
|
}
|
||||||
return RET_OK;
|
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 lite
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -17,10 +17,13 @@
|
||||||
#ifndef MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
#ifndef MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
||||||
#define MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
#define MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "src/tensor.h"
|
#include "src/tensor.h"
|
||||||
#include "src/tensorlist.h"
|
#include "src/tensorlist.h"
|
||||||
#include "nnacl/tensor_c.h"
|
#include "nnacl/tensor_c.h"
|
||||||
#include "nnacl/infer/common_infer.h"
|
#include "nnacl/infer/common_infer.h"
|
||||||
|
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
|
@ -40,6 +43,9 @@ int GenerateOutTensorC(const OpParameter *const parameter, const std::vector<lit
|
||||||
const std::vector<lite::Tensor *> &outputs, std::vector<TensorC *> *out_tensor_c);
|
const std::vector<lite::Tensor *> &outputs, std::vector<TensorC *> *out_tensor_c);
|
||||||
|
|
||||||
int CheckTensorsInvalid(const std::vector<Tensor *> &tensors);
|
int CheckTensorsInvalid(const std::vector<Tensor *> &tensors);
|
||||||
|
|
||||||
|
std::vector<mindspore::MSTensor> LiteTensorsToMSTensors(const std::vector<lite::Tensor *> &lite_tensors);
|
||||||
|
|
||||||
} // namespace lite
|
} // namespace lite
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ struct Context::Data {
|
||||||
bool enable_parallel_ = false;
|
bool enable_parallel_ = false;
|
||||||
std::vector<int32_t> affinity_core_list_;
|
std::vector<int32_t> affinity_core_list_;
|
||||||
int affinity_mode_ = 2;
|
int affinity_mode_ = 2;
|
||||||
|
std::shared_ptr<Delegate> delegate = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeviceInfoContext::Data {
|
struct DeviceInfoContext::Data {
|
||||||
|
@ -100,6 +101,7 @@ bool Context::GetEnableParallel() const {
|
||||||
MS_LOG(ERROR) << "Invalid context.";
|
MS_LOG(ERROR) << "Invalid context.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_->enable_parallel_;
|
return data_->enable_parallel_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +139,22 @@ std::vector<int32_t> Context::GetThreadAffinityCoreList() const {
|
||||||
return data_->affinity_core_list_;
|
return data_->affinity_core_list_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Context::SetDelegate(const std::shared_ptr<Delegate> &delegate) {
|
||||||
|
if (data_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid context.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data_->delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Delegate> Context::GetDelegate() const {
|
||||||
|
if (data_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid context.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return data_->delegate;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<DeviceInfoContext>> &Context::MutableDeviceInfo() {
|
std::vector<std::shared_ptr<DeviceInfoContext>> &Context::MutableDeviceInfo() {
|
||||||
static std::vector<std::shared_ptr<DeviceInfoContext>> empty;
|
static std::vector<std::shared_ptr<DeviceInfoContext>> empty;
|
||||||
if (data_ == nullptr) {
|
if (data_ == nullptr) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ Status A2L_ConvertContext(Context *a_context, lite::Context *l_context) {
|
||||||
return kLiteInputParamInvalid;
|
return kLiteInputParamInvalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
l_context->delegate = a_context->GetDelegate();
|
||||||
return kSuccess;
|
return kSuccess;
|
||||||
}
|
}
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -132,6 +132,7 @@ Status ModelImpl::RunGraph(const MSKernelCallBack &before, const MSKernelCallBac
|
||||||
mscall_param.node_type_ = call_param.node_type;
|
mscall_param.node_type_ = call_param.node_type;
|
||||||
return before(inputs, outputs, mscall_param);
|
return before(inputs, outputs, mscall_param);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto after_call_back = [&](const std::vector<mindspore::tensor::MSTensor *> &before_inputs,
|
auto after_call_back = [&](const std::vector<mindspore::tensor::MSTensor *> &before_inputs,
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &before_outputs,
|
const std::vector<mindspore::tensor::MSTensor *> &before_outputs,
|
||||||
const CallBackParam &call_param) {
|
const CallBackParam &call_param) {
|
||||||
|
|
|
@ -100,7 +100,6 @@ class ModelImpl {
|
||||||
void SetGraph(const std::shared_ptr<Graph> &graph) { graph_ = graph; }
|
void SetGraph(const std::shared_ptr<Graph> &graph) { graph_ = graph; }
|
||||||
void SetContext(const std::shared_ptr<Context> &context) { context_ = context; }
|
void SetContext(const std::shared_ptr<Context> &context) { context_ = context; }
|
||||||
void SetConfig(const std::shared_ptr<TrainCfg> cfg) { cfg_ = cfg; }
|
void SetConfig(const std::shared_ptr<TrainCfg> cfg) { cfg_ = cfg; }
|
||||||
lite::CpuBindMode GetCpuBindMode();
|
|
||||||
Status RunGraph(const MSKernelCallBack &before, const MSKernelCallBack &after);
|
Status RunGraph(const MSKernelCallBack &before, const MSKernelCallBack &after);
|
||||||
};
|
};
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -21,15 +22,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "src/cxx_api/tensor/tensor_impl.h"
|
|
||||||
#include "src/cxx_api/tensor_utils.h"
|
#include "src/cxx_api/tensor_utils.h"
|
||||||
#include "include/api/types.h"
|
|
||||||
#include "include/api/status.h"
|
|
||||||
#include "include/ms_tensor.h"
|
|
||||||
#include "src/common/string_util.h"
|
|
||||||
#include "src/tensor.h"
|
#include "src/tensor.h"
|
||||||
#include "src/common/log_adapter.h"
|
|
||||||
#include "ir/dtype/type_id.h"
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
using mindspore::lite::RET_OK;
|
using mindspore::lite::RET_OK;
|
||||||
|
@ -37,7 +31,12 @@ using mindspore::lite::RET_OK;
|
||||||
std::shared_ptr<MSTensor::Impl> MSTensor::Impl::CreateTensorImpl(const std::string &name, enum DataType type,
|
std::shared_ptr<MSTensor::Impl> MSTensor::Impl::CreateTensorImpl(const std::string &name, enum DataType type,
|
||||||
const std::vector<int64_t> &shape, const void *data,
|
const std::vector<int64_t> &shape, const void *data,
|
||||||
size_t data_len) {
|
size_t data_len) {
|
||||||
std::vector<int32_t> truncated_shape = TruncateShape(shape, static_cast<enum TypeId>(type), data_len, true);
|
std::vector<int32_t> truncated_shape;
|
||||||
|
if (data_len == 0) {
|
||||||
|
truncated_shape = TruncateShape(shape, static_cast<enum TypeId>(type), data_len, false);
|
||||||
|
} else {
|
||||||
|
truncated_shape = TruncateShape(shape, static_cast<enum TypeId>(type), data_len, true);
|
||||||
|
}
|
||||||
if (truncated_shape.empty() && !(shape.empty())) {
|
if (truncated_shape.empty() && !(shape.empty())) {
|
||||||
MS_LOG(ERROR) << "Invalid shape for creating tensor.";
|
MS_LOG(ERROR) << "Invalid shape for creating tensor.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -80,4 +79,14 @@ std::shared_ptr<MSTensor::Impl> MSTensor::Impl::StringsToTensorImpl(const std::s
|
||||||
impl->set_from_session(false);
|
impl->set_from_session(false);
|
||||||
return impl;
|
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
|
} // namespace mindspore
|
||||||
|
|
|
@ -26,9 +26,9 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "include/api/types.h"
|
#include "include/api/types.h"
|
||||||
#include "include/api/status.h"
|
#include "include/api/status.h"
|
||||||
|
#include "include/errorcode.h"
|
||||||
#include "include/lite_utils.h"
|
#include "include/lite_utils.h"
|
||||||
#include "include/ms_tensor.h"
|
#include "include/ms_tensor.h"
|
||||||
#include "src/tensor.h"
|
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
@ -38,7 +38,7 @@ class MSTensor::Impl {
|
||||||
public:
|
public:
|
||||||
Impl() {}
|
Impl() {}
|
||||||
|
|
||||||
virtual ~Impl() {
|
~Impl() {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -57,22 +57,15 @@ class MSTensor::Impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<Impl> CreateTensorImpl(const std::string &name, enum DataType type,
|
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);
|
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) {
|
static std::vector<std::string> MS_API 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const std::string &Name() const {
|
const std::string &Name() const {
|
||||||
static std::string empty = "";
|
static std::string empty = "";
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
@ -81,7 +74,15 @@ class MSTensor::Impl {
|
||||||
return tensor_name_;
|
return tensor_name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual enum DataType DataType() const {
|
void SetName(const std::string &name) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lite_tensor_->set_tensor_name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DataType DataType() const {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
return DataType::kTypeUnknown;
|
return DataType::kTypeUnknown;
|
||||||
|
@ -89,6 +90,14 @@ class MSTensor::Impl {
|
||||||
return static_cast<enum DataType>(lite_tensor_->data_type());
|
return static_cast<enum DataType>(lite_tensor_->data_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetDataType(enum DataType data_type) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lite_tensor_->set_data_type(static_cast<enum TypeId>(data_type));
|
||||||
|
}
|
||||||
|
|
||||||
int64_t ElementNum() const {
|
int64_t ElementNum() const {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
@ -97,7 +106,7 @@ class MSTensor::Impl {
|
||||||
return static_cast<int64_t>(lite_tensor_->ElementsNum());
|
return static_cast<int64_t>(lite_tensor_->ElementsNum());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const std::vector<int64_t> &Shape() {
|
const std::vector<int64_t> &Shape() {
|
||||||
static std::vector<int64_t> empty;
|
static std::vector<int64_t> empty;
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
@ -109,7 +118,50 @@ class MSTensor::Impl {
|
||||||
return shape_;
|
return shape_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::shared_ptr<const void> Data() const {
|
void SetShape(const std::vector<int64_t> &shape) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<int> tensor_shape;
|
||||||
|
tensor_shape.resize(shape.size());
|
||||||
|
std::transform(shape.begin(), shape.end(), tensor_shape.begin(), [](int64_t c) { return static_cast<int>(c); });
|
||||||
|
lite_tensor_->set_shape(tensor_shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Allocator> allocator() const {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return lite_tensor_->allocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetAllocator(std::shared_ptr<Allocator> allocator) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lite_tensor_->set_allocator(allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
mindspore::Format format() {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return mindspore::Format::NHWC;
|
||||||
|
}
|
||||||
|
return lite_tensor_->format();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetFormat(mindspore::Format format) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lite_tensor_->set_format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const void> Data() const {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -123,14 +175,15 @@ class MSTensor::Impl {
|
||||||
return std::shared_ptr<const void>(lite_tensor_->data(), [](const void *) {});
|
return std::shared_ptr<const void>(lite_tensor_->data(), [](const void *) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void *MutableData() {
|
void *MutableData() {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return lite_tensor_->MutableData();
|
return lite_tensor_->MutableData();
|
||||||
}
|
}
|
||||||
virtual size_t DataSize() const {
|
|
||||||
|
size_t DataSize() const {
|
||||||
if (lite_tensor_ == nullptr) {
|
if (lite_tensor_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor.";
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -138,7 +191,15 @@ class MSTensor::Impl {
|
||||||
return lite_tensor_->Size();
|
return lite_tensor_->Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsDevice() const { return false; }
|
void SetData(void *data) {
|
||||||
|
if (lite_tensor_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lite_tensor_->set_data(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDevice() const { return false; }
|
||||||
|
|
||||||
tensor::MSTensor *lite_tensor() const { return lite_tensor_; }
|
tensor::MSTensor *lite_tensor() const { return lite_tensor_; }
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "src/cxx_api/tensor_utils.h"
|
#include "src/cxx_api/tensor_utils.h"
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
|
#include "src/tensor.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
std::vector<int32_t> TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
std::vector<int32_t> TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
||||||
|
|
|
@ -26,11 +26,12 @@
|
||||||
#include "src/cxx_api/tensor/tensor_impl.h"
|
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
std::vector<int32_t> TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
std::vector<int32_t> MS_API TruncateShape(const std::vector<int64_t> &shape, enum TypeId type, size_t data_len,
|
||||||
bool verify_size);
|
bool verify_size);
|
||||||
Status LiteTensorToMSTensor(tensor::MSTensor *srcTensor, MSTensor *dstTensor);
|
|
||||||
|
|
||||||
std::vector<MSTensor> LiteTensorsToMSTensors(const std::vector<mindspore::tensor::MSTensor *> &srcTensors);
|
Status MS_API LiteTensorToMSTensor(tensor::MSTensor *srcTensor, MSTensor *dstTensor);
|
||||||
|
|
||||||
|
std::vector<MSTensor> MS_API LiteTensorsToMSTensors(const std::vector<mindspore::tensor::MSTensor *> &srcTensors);
|
||||||
|
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,12 @@
|
||||||
#include "include/api/status.h"
|
#include "include/api/status.h"
|
||||||
#include "include/api/dual_abi_helper.h"
|
#include "include/api/dual_abi_helper.h"
|
||||||
#include "src/cxx_api/tensor/tensor_impl.h"
|
#include "src/cxx_api/tensor/tensor_impl.h"
|
||||||
#include "src/common/string_util.h"
|
|
||||||
#include "src/tensor.h"
|
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
namespace {
|
||||||
|
constexpr int64_t MAX_MALLOC_SIZE = static_cast<size_t>(2000) * 1024 * 1024;
|
||||||
|
}
|
||||||
class Buffer::Impl {
|
class Buffer::Impl {
|
||||||
public:
|
public:
|
||||||
Impl() : data_() { MS_LOG(ERROR) << "Unsupported feature."; }
|
Impl() : data_() { MS_LOG(ERROR) << "Unsupported feature."; }
|
||||||
|
@ -71,28 +72,37 @@ bool MSTensor::operator==(std::nullptr_t) const { return impl_ == nullptr; }
|
||||||
|
|
||||||
bool MSTensor::operator!=(std::nullptr_t) const { return impl_ != nullptr; }
|
bool MSTensor::operator!=(std::nullptr_t) const { return impl_ != nullptr; }
|
||||||
|
|
||||||
|
bool MSTensor::operator==(const MSTensor &tensor) const { return impl_->lite_tensor() == tensor.impl_->lite_tensor(); }
|
||||||
|
|
||||||
MSTensor *MSTensor::CreateTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape,
|
MSTensor *MSTensor::CreateTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape,
|
||||||
const void *data, size_t data_len) noexcept {
|
const void *data, size_t data_len) noexcept {
|
||||||
if (data_len < 0 || data_len > MAX_MALLOC_SIZE) {
|
if (data_len < 0 || data_len > MAX_MALLOC_SIZE) {
|
||||||
MS_LOG(ERROR) << "data_len is error.";
|
MS_LOG(ERROR) << "data_len is error.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto new_data = malloc(data_len);
|
void *new_data = nullptr;
|
||||||
|
if (data != nullptr) {
|
||||||
|
new_data = malloc(data_len);
|
||||||
if (new_data == nullptr) {
|
if (new_data == nullptr) {
|
||||||
MS_LOG(ERROR) << "Allocate data failed.";
|
MS_LOG(ERROR) << "Allocate data failed.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
::memcpy(new_data, data, data_len);
|
::memcpy(new_data, data, data_len);
|
||||||
|
}
|
||||||
auto impl = Impl::CreateTensorImpl(CharToString(name), type, shape, new_data, data_len);
|
auto impl = Impl::CreateTensorImpl(CharToString(name), type, shape, new_data, data_len);
|
||||||
if (impl == nullptr) {
|
if (impl == nullptr) {
|
||||||
MS_LOG(ERROR) << "Allocate tensor impl failed.";
|
MS_LOG(ERROR) << "Allocate tensor impl failed.";
|
||||||
|
if (new_data != nullptr) {
|
||||||
free(new_data);
|
free(new_data);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto ms_tensor = new (std::nothrow) MSTensor(impl);
|
auto ms_tensor = new (std::nothrow) MSTensor(impl);
|
||||||
if (ms_tensor == nullptr) {
|
if (ms_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Allocate tensor impl failed.";
|
MS_LOG(ERROR) << "Allocate tensor impl failed.";
|
||||||
|
if (new_data != nullptr) {
|
||||||
free(new_data);
|
free(new_data);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
impl->set_own_data(true);
|
impl->set_own_data(true);
|
||||||
|
@ -172,7 +182,7 @@ MSTensor *MSTensor::Clone() const {
|
||||||
|
|
||||||
std::vector<char> MSTensor::CharName() const {
|
std::vector<char> MSTensor::CharName() const {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return std::vector<char>();
|
return std::vector<char>();
|
||||||
}
|
}
|
||||||
return StringToChar(impl_->Name());
|
return StringToChar(impl_->Name());
|
||||||
|
@ -180,7 +190,7 @@ std::vector<char> MSTensor::CharName() const {
|
||||||
|
|
||||||
int64_t MSTensor::ElementNum() const {
|
int64_t MSTensor::ElementNum() const {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return impl_->ElementNum();
|
return impl_->ElementNum();
|
||||||
|
@ -188,7 +198,7 @@ int64_t MSTensor::ElementNum() const {
|
||||||
|
|
||||||
enum DataType MSTensor::DataType() const {
|
enum DataType MSTensor::DataType() const {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return DataType::kTypeUnknown;
|
return DataType::kTypeUnknown;
|
||||||
}
|
}
|
||||||
return impl_->DataType();
|
return impl_->DataType();
|
||||||
|
@ -197,7 +207,7 @@ enum DataType MSTensor::DataType() const {
|
||||||
const std::vector<int64_t> &MSTensor::Shape() const {
|
const std::vector<int64_t> &MSTensor::Shape() const {
|
||||||
static std::vector<int64_t> empty;
|
static std::vector<int64_t> empty;
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
return impl_->Shape();
|
return impl_->Shape();
|
||||||
|
@ -205,7 +215,7 @@ const std::vector<int64_t> &MSTensor::Shape() const {
|
||||||
|
|
||||||
std::shared_ptr<const void> MSTensor::Data() const {
|
std::shared_ptr<const void> MSTensor::Data() const {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return impl_->Data();
|
return impl_->Data();
|
||||||
|
@ -213,7 +223,7 @@ std::shared_ptr<const void> MSTensor::Data() const {
|
||||||
|
|
||||||
void *MSTensor::MutableData() {
|
void *MSTensor::MutableData() {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return impl_->MutableData();
|
return impl_->MutableData();
|
||||||
|
@ -221,7 +231,7 @@ void *MSTensor::MutableData() {
|
||||||
|
|
||||||
size_t MSTensor::DataSize() const {
|
size_t MSTensor::DataSize() const {
|
||||||
if (impl_ == nullptr) {
|
if (impl_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Invalid tensor inpmlement.";
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return impl_->DataSize();
|
return impl_->DataSize();
|
||||||
|
@ -238,6 +248,70 @@ void MSTensor::DestroyTensorPtr(MSTensor *tensor) noexcept {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetShape(const std::vector<int64_t> &shape) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
impl_->SetShape(shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetDataType(enum DataType data_type) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
impl_->SetDataType(data_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetTensorName(const std::string &name) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
impl_->SetName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetAllocator(std::shared_ptr<Allocator> allocator) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return impl_->SetAllocator(allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Allocator> MSTensor::allocator() const {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return impl_->allocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetFormat(mindspore::Format format) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return impl_->SetFormat(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
mindspore::Format MSTensor::format() const {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return mindspore::Format::NHWC;
|
||||||
|
}
|
||||||
|
return impl_->format();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSTensor::SetData(void *data) {
|
||||||
|
if (impl_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Invalid tensor implement.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return impl_->SetData(data);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer::Buffer() : impl_(nullptr) { MS_LOG(ERROR) << "Unsupported feature."; }
|
Buffer::Buffer() : impl_(nullptr) { MS_LOG(ERROR) << "Unsupported feature."; }
|
||||||
Buffer::Buffer(const void *data, size_t data_len) : impl_(nullptr) { MS_LOG(ERROR) << "Unsupported feature."; }
|
Buffer::Buffer(const void *data, size_t data_len) : impl_(nullptr) { MS_LOG(ERROR) << "Unsupported feature."; }
|
||||||
Buffer::~Buffer() = default;
|
Buffer::~Buffer() = default;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "include/delegate.h"
|
#include "include/api/delegate.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
const schema::Primitive *DelegateModel::GetPrimitive(kernel::Kernel *kernel) const {
|
const schema::Primitive *DelegateModel::GetPrimitive(kernel::Kernel *kernel) const {
|
||||||
if (primitives_.find(kernel) != primitives_.end()) {
|
if (primitives_.find(kernel) != primitives_.end()) {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "src/delegate/delegate_utils.h"
|
#include "src/delegate/delegate_utils.h"
|
||||||
namespace mindspore::lite {
|
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()) {
|
if (find(inputs.begin(), inputs.end(), input) != inputs.end()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,17 @@
|
||||||
#define MINDSPORE_LITE_SRC_DELEGATE_DELEGATE_UTILS
|
#define MINDSPORE_LITE_SRC_DELEGATE_DELEGATE_UTILS
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "include/ms_tensor.h"
|
#include "include/ms_tensor.h"
|
||||||
#include "include/delegate.h"
|
#include "include/api/delegate.h"
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
#include "src/delegate/tensorrt/op/tensorrt_op.h"
|
#include "src/delegate/tensorrt/op/tensorrt_op.h"
|
||||||
|
|
||||||
namespace mindspore::lite {
|
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>
|
template <typename T>
|
||||||
std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<T *> ops) {
|
std::vector<mindspore::MSTensor> GetGraphInTensors(std::vector<T *> ops) {
|
||||||
std::vector<mindspore::tensor::MSTensor *> inputs;
|
std::vector<mindspore::MSTensor> inputs;
|
||||||
auto is_op_output = [&](tensor::MSTensor *tensor) -> bool {
|
auto is_op_output = [&](mindspore::MSTensor tensor) -> bool {
|
||||||
for (auto op : ops) {
|
for (auto op : ops) {
|
||||||
auto out_tensors = op->outputs();
|
auto out_tensors = op->outputs();
|
||||||
if (find(out_tensors.begin(), out_tensors.end(), tensor) != out_tensors.end()) {
|
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 op : ops) {
|
||||||
for (auto in_tensor : op->inputs()) {
|
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);
|
inputs.push_back(in_tensor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,9 @@ std::vector<mindspore::tensor::MSTensor *> GetGraphInTensors(std::vector<T *> op
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::vector<mindspore::tensor::MSTensor *> GetGraphOutTensors(const std::vector<T *> &ops) {
|
std::vector<mindspore::MSTensor> GetGraphOutTensors(const std::vector<T *> &ops) {
|
||||||
std::vector<mindspore::tensor::MSTensor *> outputs;
|
std::vector<mindspore::MSTensor> outputs;
|
||||||
auto is_op_input = [&](const tensor::MSTensor *tensor) -> bool {
|
auto is_op_input = [&](const mindspore::MSTensor tensor) -> bool {
|
||||||
for (auto op : ops) {
|
for (auto op : ops) {
|
||||||
auto in_tensors = op->inputs();
|
auto in_tensors = op->inputs();
|
||||||
if (find(in_tensors.begin(), in_tensors.end(), tensor) != in_tensors.end()) {
|
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>
|
template <typename T>
|
||||||
std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
std::vector<mindspore::MSTensor> GraphInTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||||
KernelIter end) {
|
KernelIter end) {
|
||||||
auto in_tensors = GetGraphInTensors(ops);
|
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 op : ops) {
|
||||||
for (auto in_tensor : op->inputs()) {
|
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);
|
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>
|
template <typename T>
|
||||||
std::vector<tensor::MSTensor *> GraphOutTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
std::vector<mindspore::MSTensor> GraphOutTensors(const std::vector<T *> &ops, DelegateModel *model, KernelIter from,
|
||||||
KernelIter end) {
|
KernelIter end) {
|
||||||
auto out_tensors = GetGraphOutTensors(ops);
|
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 op : ops) {
|
||||||
for (auto out_tensor : op->outputs()) {
|
for (auto out_tensor : op->outputs()) {
|
||||||
if (find(out_tensors.begin(), out_tensors.end(), out_tensor) == out_tensors.end()) {
|
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>
|
template <typename T>
|
||||||
int GetGraphInOutOps(const std::vector<mindspore::tensor::MSTensor *> &inputs,
|
int GetGraphInOutOps(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs,
|
||||||
const std::vector<mindspore::tensor::MSTensor *> &outputs, std::vector<T *> *in_ops,
|
std::vector<T *> *in_ops, std::vector<T *> *out_ops, const std::vector<T *> &all_ops) {
|
||||||
std::vector<T *> *out_ops, const std::vector<T *> &all_ops) {
|
|
||||||
for (auto in_tensor : inputs) {
|
for (auto in_tensor : inputs) {
|
||||||
for (auto op : all_ops) {
|
for (auto op : all_ops) {
|
||||||
if (find(op->inputs().begin(), op->inputs().end(), in_tensor) != op->inputs().end() &&
|
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 "src/delegate/npu/npu_converter_utils.h"
|
||||||
#include <arm_neon.h>
|
|
||||||
#include "src/common/log_adapter.h"
|
#include "src/common/log_adapter.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
#define C8NUM 8
|
#define C8NUM 8
|
||||||
|
@ -54,7 +53,7 @@ void Float16ToFloat32(const float16_t *__restrict input, float *__restrict outpu
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ge::Shape ConverterToNPUShape(const std::vector<int> &src_shape) {
|
ge::Shape ConverterToNPUShape(const std::vector<int64_t> &src_shape) {
|
||||||
vector<int64_t> shapes;
|
vector<int64_t> shapes;
|
||||||
shapes.reserve(src_shape.size());
|
shapes.reserve(src_shape.size());
|
||||||
for (int i = 0; i < src_shape.size(); i++) {
|
for (int i = 0; i < src_shape.size(); i++) {
|
||||||
|
@ -82,27 +81,26 @@ ge::Format ConverterToNPUFormat(schema::Format format) {
|
||||||
return ge_format;
|
return ge_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
ge::DataType ConverterToNPUDataType(TypeId type_id) {
|
ge::DataType ConverterToNPUDataType(DataType type_id) {
|
||||||
ge::DataType data_type;
|
ge::DataType data_type;
|
||||||
switch (type_id) {
|
switch (type_id) {
|
||||||
case kNumberTypeFloat:
|
case DataType::kNumberTypeFloat32:
|
||||||
case kNumberTypeFloat32:
|
case DataType::kNumberTypeFloat16:
|
||||||
case kNumberTypeFloat16:
|
|
||||||
data_type = ge::DT_FLOAT;
|
data_type = ge::DT_FLOAT;
|
||||||
break;
|
break;
|
||||||
case kNumberTypeInt8:
|
case DataType::kNumberTypeInt8:
|
||||||
data_type = ge::DT_INT8;
|
data_type = ge::DT_INT8;
|
||||||
break;
|
break;
|
||||||
case kNumberTypeUInt8:
|
case DataType::kNumberTypeUInt8:
|
||||||
data_type = ge::DT_UINT8;
|
data_type = ge::DT_UINT8;
|
||||||
break;
|
break;
|
||||||
case kNumberTypeInt16:
|
case DataType::kNumberTypeInt16:
|
||||||
data_type = ge::DT_INT16;
|
data_type = ge::DT_INT16;
|
||||||
break;
|
break;
|
||||||
case kNumberTypeInt32:
|
case DataType::kNumberTypeInt32:
|
||||||
data_type = ge::DT_INT32;
|
data_type = ge::DT_INT32;
|
||||||
break;
|
break;
|
||||||
case kNumberTypeUInt32:
|
case DataType::kNumberTypeUInt32:
|
||||||
data_type = ge::DT_UINT32;
|
data_type = ge::DT_UINT32;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -112,43 +110,41 @@ ge::DataType ConverterToNPUDataType(TypeId type_id) {
|
||||||
return data_type;
|
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);
|
auto data = new (std::nothrow) hiai::op::Data(name);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
MS_LOG(ERROR) << "new data failed.";
|
MS_LOG(ERROR) << "new data failed.";
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src->shape()), ge::FORMAT_NCHW,
|
ge::TensorDesc tensor_desc(ConverterToNPUShape(src.Shape()), ge::FORMAT_NCHW, ConverterToNPUDataType(src.DataType()));
|
||||||
ConverterToNPUDataType(src->data_type()));
|
|
||||||
data->update_input_desc_x(tensor_desc);
|
data->update_input_desc_x(tensor_desc);
|
||||||
return data;
|
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());
|
std::shared_ptr<ge::Tensor> ge_tensor = std::shared_ptr<ge::Tensor>(new (std::nothrow) ge::Tensor());
|
||||||
if (ge_tensor == nullptr) {
|
if (ge_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "new ge_tensor failed.";
|
MS_LOG(ERROR) << "new ge_tensor failed.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
ge::TensorDesc tensor_desc(ConverterToNPUShape(src->shape()), ge::FORMAT_NCHW,
|
ge::TensorDesc tensor_desc(ConverterToNPUShape(src.Shape()), ge::FORMAT_NCHW, ConverterToNPUDataType(src.DataType()));
|
||||||
ConverterToNPUDataType(src->data_type()));
|
|
||||||
|
|
||||||
ge_tensor->SetTensorDesc(tensor_desc);
|
ge_tensor->SetTensorDesc(tensor_desc);
|
||||||
|
|
||||||
if (src->data() != nullptr) {
|
if (src.Data() != nullptr) {
|
||||||
if (src->data_type() == kNumberTypeFloat16) {
|
if (src.DataType() == DataType::kNumberTypeFloat16) {
|
||||||
#ifdef ENABLE_ARM64
|
#ifdef ENABLE_ARM64
|
||||||
auto fp32_data = malloc(src->ElementsNum() * sizeof(float));
|
auto fp32_data = malloc(src.ElementNum() * sizeof(float));
|
||||||
Float16ToFloat32(reinterpret_cast<float16_t *>(src->data()), reinterpret_cast<float *>(fp32_data),
|
Float16ToFloat32(reinterpret_cast<float16_t *>(src.MutableData()), reinterpret_cast<float *>(fp32_data),
|
||||||
src->ElementsNum());
|
src.ElementNum());
|
||||||
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(fp32_data), src->ElementsNum() * sizeof(float));
|
ge_tensor->SetData(reinterpret_cast<const uint8_t *>(fp32_data), src.ElementNum() * sizeof(float));
|
||||||
free(fp32_data);
|
free(fp32_data);
|
||||||
#else
|
#else
|
||||||
MS_LOG(ERROR) << "This platform does not support fp16.";
|
MS_LOG(ERROR) << "This platform does not support fp16.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} 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;
|
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();
|
return find(tensor_vec.begin(), tensor_vec.end(), tensor) != tensor_vec.end();
|
||||||
}
|
}
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -19,29 +19,36 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#ifdef ENABLE_ARM64
|
||||||
|
#include <arm_neon.h>
|
||||||
|
#endif
|
||||||
#include "schema/ops_generated.h"
|
#include "schema/ops_generated.h"
|
||||||
#include "include/graph/tensor.h"
|
#include "include/graph/tensor.h"
|
||||||
#include "include/graph/op/array_defs.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 {
|
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::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);
|
ge::Shape ConverterToNPUShape(const std::vector<int64_t> &src_shape);
|
||||||
|
|
||||||
int ConverterToNPUActMode(schema::ActivationType type);
|
|
||||||
|
|
||||||
int ConverterToNPUEltwiseMode(schema::EltwiseMode mode);
|
int ConverterToNPUEltwiseMode(schema::EltwiseMode mode);
|
||||||
|
|
||||||
int TransFormAxis(int axis);
|
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
|
} // namespace mindspore
|
||||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_CONVERTER_UITLS_H_
|
#endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_CONVERTER_UITLS_H_
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/npu_delegate.h"
|
#include "src/delegate/npu/npu_delegate.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include "include/errorcode.h"
|
||||||
#include "src/delegate/npu/op/npu_op.h"
|
#include "src/delegate/npu/op/npu_op.h"
|
||||||
#include "src/delegate/npu/op/activation_npu.h"
|
#include "src/delegate/npu/op/activation_npu.h"
|
||||||
#include "src/delegate/npu/op/argmax_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_insert_transform_pass.h"
|
||||||
#include "src/delegate/npu/pass/npu_fusion_pass.h"
|
#include "src/delegate/npu/pass/npu_fusion_pass.h"
|
||||||
|
|
||||||
|
using mindspore::lite::RET_ERROR;
|
||||||
|
using mindspore::lite::RET_OK;
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
NPUDelegate::~NPUDelegate() {
|
NPUDelegate::~NPUDelegate() {
|
||||||
if (npu_manager_ != nullptr) {
|
if (npu_manager_ != nullptr) {
|
||||||
|
@ -202,42 +206,42 @@ int NPUDelegate::Build(DelegateModel *model) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NPUOp *NPUDelegate::GetOP(kernel::Kernel *kernel, const schema::Primitive *primitive) {
|
NPUOp *NPUDelegate::GetOP(kernel::Kernel *kernel, const schema::Primitive *primitive) {
|
||||||
auto in_tensors = kernel->inputs();
|
|
||||||
auto out_tensors = kernel->outputs();
|
|
||||||
auto name = kernel->name();
|
auto name = kernel->name();
|
||||||
NPUOp *npu_op = nullptr;
|
NPUOp *npu_op = nullptr;
|
||||||
auto node_type = primitive->value_type();
|
auto node_type = primitive->value_type();
|
||||||
if (node_type == schema::PrimitiveType_Conv2DFusion) {
|
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 {
|
} else {
|
||||||
if (op_func_lists_.find(node_type) != op_func_lists_.end()) {
|
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 {
|
} else {
|
||||||
MS_LOG(DEBUG) << "Unsupported op type for NPU.";
|
MS_LOG(DEBUG) << "Unsupported op type for NPU.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto tensor : in_tensors) {
|
for (int i = 0; i < kernel->inputs().size(); i++) {
|
||||||
if (tensor->data_type() == kNumberTypeFloat16 && tensor->data() == nullptr) {
|
mindspore::MSTensor tensor = kernel->inputs()[i];
|
||||||
tensor->set_data_type(kNumberTypeFloat32);
|
if (tensor.DataType() == DataType::kNumberTypeFloat16 && tensor.Data() == nullptr) {
|
||||||
|
tensor.SetDataType(DataType::kNumberTypeFloat32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto tensor : out_tensors) {
|
for (int i = 0; i < kernel->outputs().size(); i++) {
|
||||||
if (tensor->data_type() == kNumberTypeFloat16) {
|
mindspore::MSTensor tensor = kernel->outputs()[i];
|
||||||
tensor->set_data_type(kNumberTypeFloat32);
|
if (tensor.DataType() == DataType::kNumberTypeFloat16) {
|
||||||
|
tensor.SetDataType(DataType::kNumberTypeFloat32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return npu_op;
|
return npu_op;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
std::vector<mindspore::MSTensor> GraphInTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||||
KernelIter end) {
|
KernelIter end) {
|
||||||
auto in_tensors = NPUGraphUtils::GetGraphInTensors(ops);
|
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 op : ops) {
|
||||||
for (auto in_tensor : op->inputs()) {
|
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);
|
all_in_tensors.push_back(in_tensor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,10 +261,10 @@ std::vector<tensor::MSTensor *> GraphInTensors(const std::vector<NPUOp *> &ops,
|
||||||
return in_tensors;
|
return in_tensors;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<tensor::MSTensor *> GraphOutTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
std::vector<mindspore::MSTensor> GraphOutTensors(const std::vector<NPUOp *> &ops, DelegateModel *model, KernelIter from,
|
||||||
KernelIter end) {
|
KernelIter end) {
|
||||||
auto out_tensors = NPUGraphUtils::GetGraphOutTensors(ops);
|
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 op : ops) {
|
||||||
for (auto out_tensor : op->outputs()) {
|
for (auto out_tensor : op->outputs()) {
|
||||||
if (find(out_tensors.begin(), out_tensors.end(), out_tensor) == out_tensors.end()) {
|
if (find(out_tensors.begin(), out_tensors.end(), out_tensor) == out_tensors.end()) {
|
||||||
|
|
|
@ -19,16 +19,11 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "include/delegate.h"
|
#include "include/api/delegate.h"
|
||||||
|
#include "include/context.h"
|
||||||
#include "src/delegate/npu/npu_manager.h"
|
#include "src/delegate/npu/npu_manager.h"
|
||||||
#include "src/delegate/npu/pass/npu_pass_manager.h"
|
#include "src/delegate/npu/pass/npu_pass_manager.h"
|
||||||
#include "src/delegate/npu/op//npu_op.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;
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class NPUDelegate : public Delegate {
|
class NPUDelegate : public Delegate {
|
||||||
|
|
|
@ -47,8 +47,8 @@ int NPUExecutor::Prepare() {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> GetNpuTensorShape(int dim, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
std::vector<int64_t> GetNpuTensorShape(int dim, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||||
std::vector<int> npu_shape;
|
std::vector<int64_t> npu_shape;
|
||||||
if (dim > 0) {
|
if (dim > 0) {
|
||||||
npu_shape.push_back(npu_tensor->GetTensorDimension().GetNumber());
|
npu_shape.push_back(npu_tensor->GetTensorDimension().GetNumber());
|
||||||
}
|
}
|
||||||
|
@ -75,40 +75,40 @@ std::vector<int> ExpandShapeTo4d(const std::vector<int> &shape) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSameShapeTensor(tensor::MSTensor *tensor, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
bool IsSameShapeTensor(mindspore::MSTensor tensor, std::shared_ptr<hiai::AiTensor> npu_tensor) {
|
||||||
if (tensor->shape().size() > 4) {
|
if (tensor.Shape().size() > 4) {
|
||||||
MS_LOG(ERROR) << "Npu does not support output tensor dims greater than 4";
|
MS_LOG(ERROR) << "Npu does not support output tensor dims greater than 4";
|
||||||
return false;
|
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,
|
int NPUExecutor::Run(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, const std::vector<NPUOp *> &in_ops) {
|
const std::vector<mindspore::MSTensor> &out_tensors, const std::vector<NPUOp *> &in_ops) {
|
||||||
hiai::AiContext context;
|
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 : in_ops) {
|
||||||
for (const auto op_input : op->inputs()) {
|
for (const auto op_input : op->inputs()) {
|
||||||
if (tensor_uses.find(op_input) == tensor_uses.end()) {
|
if (tensor_uses.find(op_input.Name()) == tensor_uses.end()) {
|
||||||
tensor_uses.insert({op_input, 1});
|
tensor_uses.insert({op_input.Name(), 1});
|
||||||
} else {
|
} else {
|
||||||
tensor_uses[op_input]++;
|
tensor_uses[op_input.Name()]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < npu_input_tensors_.size(); ++i) {
|
for (int i = 0; i < npu_input_tensors_.size(); ++i) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; index < in_tensors.size(); index++) {
|
for (; index < in_tensors.size(); index++) {
|
||||||
if (tensor_uses[in_tensors[index]] > 0 && IsSameShapeTensor(in_tensors[index], npu_input_tensors_[i])) {
|
if (tensor_uses[in_tensors[index].Name()] > 0 && IsSameShapeTensor(in_tensors[index], npu_input_tensors_[i])) {
|
||||||
void *data = in_tensors[index]->data();
|
auto data = in_tensors[index].Data();
|
||||||
if (data == nullptr) {
|
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";
|
<< " data is nullptr";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(npu_input_tensors_[i]->GetBuffer(), data, in_tensors[index]->Size());
|
memcpy(npu_input_tensors_[i]->GetBuffer(), data.get(), in_tensors[index].DataSize());
|
||||||
tensor_uses[in_tensors[index]]--;
|
tensor_uses[in_tensors[index].Name()]--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,9 +135,10 @@ int NPUExecutor::Run(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; index < out_tensors.size(); index++) {
|
for (; index < out_tensors.size(); index++) {
|
||||||
if (!outputs_visited[index] && IsSameShapeTensor(out_tensors[index], npu_output_tensors_[i])) {
|
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) {
|
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";
|
<< " data is nullptr";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class NPUExecutor {
|
||||||
~NPUExecutor();
|
~NPUExecutor();
|
||||||
int Prepare();
|
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);
|
const std::vector<NPUOp *> &in_ops);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,12 +28,12 @@ NPUGraph::~NPUGraph() {
|
||||||
for (auto *op : npu_ops_) {
|
for (auto *op : npu_ops_) {
|
||||||
delete op;
|
delete op;
|
||||||
}
|
}
|
||||||
for (auto *tensor : insert_tensors_) {
|
for (auto tensor : insert_tensors_) {
|
||||||
delete tensor;
|
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());
|
MS_ASSERT(index < inputs_.size());
|
||||||
auto origin_tensor = this->inputs_[index];
|
auto origin_tensor = this->inputs_[index];
|
||||||
for (auto kernel : all_kernels_) {
|
for (auto kernel : all_kernels_) {
|
||||||
|
@ -46,7 +46,7 @@ void NPUGraph::set_input(tensor::MSTensor *in_tensor, int index) {
|
||||||
this->inputs_[index] = in_tensor;
|
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());
|
MS_ASSERT(index < outputs_.size());
|
||||||
auto origin_tensor = this->outputs_[index];
|
auto origin_tensor = this->outputs_[index];
|
||||||
for (auto kernel : all_kernels_) {
|
for (auto kernel : all_kernels_) {
|
||||||
|
@ -199,7 +199,7 @@ int NPUGraph::Prepare() {
|
||||||
}
|
}
|
||||||
for (auto output : all_kernels_[i]->outputs()) {
|
for (auto output : all_kernels_[i]->outputs()) {
|
||||||
if (find(outputs_.begin(), outputs_.end(), output) == outputs_.end()) {
|
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
|
// 1. malloc graph output data
|
||||||
for (auto output : all_kernels_[i]->outputs()) {
|
for (auto output : all_kernels_[i]->outputs()) {
|
||||||
if (find(outputs_.begin(), outputs_.end(), output) != outputs_.end()) {
|
if (find(outputs_.begin(), outputs_.end(), output) != outputs_.end()) {
|
||||||
output->MutableData();
|
output.MutableData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 2. execute
|
// 2. execute
|
||||||
|
|
|
@ -20,15 +20,15 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "include/kernel.h"
|
#include "include/api/kernel.h"
|
||||||
#include "src/delegate/npu/op/npu_op.h"
|
#include "src/delegate/npu/op/npu_op.h"
|
||||||
#include "src/delegate/npu/npu_executor.h"
|
#include "src/delegate/npu/npu_executor.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class NPUGraph : public kernel::Kernel {
|
class NPUGraph : public kernel::Kernel {
|
||||||
public:
|
public:
|
||||||
NPUGraph(std::vector<NPUOp *> npu_ops, NPUManager *npu_manager, const std::vector<tensor::MSTensor *> &inputs,
|
NPUGraph(std::vector<NPUOp *> npu_ops, NPUManager *npu_manager, const std::vector<mindspore::MSTensor> &inputs,
|
||||||
const std::vector<tensor::MSTensor *> &outputs)
|
const std::vector<mindspore::MSTensor> &outputs)
|
||||||
: kernel::Kernel(inputs, outputs, nullptr, nullptr), npu_ops_(std::move(npu_ops)), npu_manager_(npu_manager) {}
|
: kernel::Kernel(inputs, outputs, nullptr, nullptr), npu_ops_(std::move(npu_ops)), npu_manager_(npu_manager) {}
|
||||||
|
|
||||||
~NPUGraph() override;
|
~NPUGraph() override;
|
||||||
|
@ -44,15 +44,15 @@ class NPUGraph : public kernel::Kernel {
|
||||||
return lite::RET_ERROR;
|
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();
|
int FindPreNextOps();
|
||||||
|
|
||||||
std::vector<NPUOp *> *GetOps() { return &npu_ops_; }
|
std::vector<NPUOp *> *GetOps() { return &npu_ops_; }
|
||||||
|
|
||||||
std::vector<tensor::MSTensor *> *GetInsertTensors() { return &insert_tensors_; }
|
std::vector<mindspore::MSTensor *> *GetInsertTensors() { return &insert_tensors_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<NPUOp *> FindPreOps(NPUOp *cur_op);
|
std::vector<NPUOp *> FindPreOps(NPUOp *cur_op);
|
||||||
|
@ -69,7 +69,7 @@ class NPUGraph : public kernel::Kernel {
|
||||||
|
|
||||||
std::vector<kernel::Kernel *> all_kernels_{};
|
std::vector<kernel::Kernel *> all_kernels_{};
|
||||||
|
|
||||||
std::vector<tensor::MSTensor *> insert_tensors_;
|
std::vector<mindspore::MSTensor *> insert_tensors_;
|
||||||
|
|
||||||
NPUManager *npu_manager_ = nullptr;
|
NPUManager *npu_manager_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/npu_graph_utils.h"
|
#include "src/delegate/npu/npu_graph_utils.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphInTensors(std::vector<NPUOp *> ops) {
|
std::vector<mindspore::MSTensor> NPUGraphUtils::GetGraphInTensors(std::vector<NPUOp *> ops) {
|
||||||
std::vector<mindspore::tensor::MSTensor *> inputs;
|
std::vector<mindspore::MSTensor> inputs;
|
||||||
auto is_op_output = [&](tensor::MSTensor *tensor) -> bool {
|
auto is_op_output = [&](mindspore::MSTensor tensor) -> bool {
|
||||||
for (auto op : ops) {
|
for (auto op : ops) {
|
||||||
auto out_tensors = op->outputs();
|
auto out_tensors = op->outputs();
|
||||||
if (find(out_tensors.begin(), out_tensors.end(), tensor) != out_tensors.end()) {
|
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 op : ops) {
|
||||||
for (auto in_tensor : op->inputs()) {
|
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);
|
inputs.push_back(in_tensor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphInTensors(std:
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<mindspore::tensor::MSTensor *> NPUGraphUtils::GetGraphOutTensors(std::vector<NPUOp *> ops) {
|
std::vector<mindspore::MSTensor> NPUGraphUtils::GetGraphOutTensors(std::vector<NPUOp *> ops) {
|
||||||
std::vector<mindspore::tensor::MSTensor *> outputs;
|
std::vector<mindspore::MSTensor> outputs;
|
||||||
auto is_op_input = [&](const tensor::MSTensor *tensor) -> bool {
|
auto is_op_input = [&](const mindspore::MSTensor tensor) -> bool {
|
||||||
for (auto op : ops) {
|
for (auto op : ops) {
|
||||||
auto in_tensors = op->inputs();
|
auto in_tensors = op->inputs();
|
||||||
if (find(in_tensors.begin(), in_tensors.end(), tensor) != in_tensors.end()) {
|
if (find(in_tensors.begin(), in_tensors.end(), tensor) != in_tensors.end()) {
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class NPUGraphUtils {
|
class NPUGraphUtils {
|
||||||
public:
|
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
|
} // namespace mindspore
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ NPUSubGraph::~NPUSubGraph() {
|
||||||
op_buffer_.clear();
|
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());
|
MS_ASSERT(index < inputs_.size());
|
||||||
auto origin_tensor = inputs_[index];
|
auto origin_tensor = inputs_[index];
|
||||||
// only in_ops_ input tensors list used in execute function
|
// 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;
|
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());
|
MS_ASSERT(index < out_tensor_sorted_.size());
|
||||||
auto origin_tensor = outputs_[index];
|
auto origin_tensor = outputs_[index];
|
||||||
for (size_t i = 0; i < out_tensor_sorted_.size(); i++) {
|
for (size_t i = 0; i < out_tensor_sorted_.size(); i++) {
|
||||||
|
@ -217,7 +217,7 @@ int NPUSubGraph::BuildNPUInputOp() {
|
||||||
return RET_OK;
|
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()) {
|
if (find(this->inputs().begin(), this->inputs().end(), input) != this->inputs().end()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/kernel.h"
|
#include "include/api/kernel.h"
|
||||||
#include "src/delegate/npu/npu_executor.h"
|
#include "src/delegate/npu/npu_executor.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
@ -42,9 +42,9 @@ class NPUSubGraph : public kernel::Kernel {
|
||||||
return lite::RET_ERROR;
|
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();
|
int GetGraphInOutOps();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class NPUSubGraph : public kernel::Kernel {
|
||||||
|
|
||||||
int GetNPUOperators(const std::vector<NPUOp *> &ops);
|
int GetNPUOperators(const std::vector<NPUOp *> &ops);
|
||||||
|
|
||||||
bool IsSubGraphInputTensor(tensor::MSTensor *input);
|
bool IsSubGraphInputTensor(mindspore::MSTensor input);
|
||||||
|
|
||||||
std::string GetOMModelName();
|
std::string GetOMModelName();
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class NPUSubGraph : public kernel::Kernel {
|
||||||
|
|
||||||
std::vector<ge::Operator> subgraph_output_ops_;
|
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_;
|
std::vector<ge::Operator *> op_buffer_;
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/activation_npu.h"
|
#include "src/delegate/npu/op/activation_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ActivationNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ActivationNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto act_prim = primitive->value_as_Activation();
|
auto act_prim = primitive->value_as_Activation();
|
||||||
if (act_prim == nullptr) {
|
if (act_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ActivationNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ActivationNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
act_ = new (std::nothrow) hiai::op::Activation(name_);
|
act_ = new (std::nothrow) hiai::op::Activation(name_);
|
||||||
if (act_ == nullptr) {
|
if (act_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New activation npu operator for activation op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ActivationNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ActivationNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
act_->set_input_x(*npu_inputs[0]);
|
act_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -18,26 +18,25 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
#include "include/graph/compatible/all_ops.h"
|
#include "include/graph/compatible/all_ops.h"
|
||||||
#include "src/delegate/npu/op/npu_op.h"
|
#include "src/delegate/npu/op/npu_op.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ActivationNPUOp : public NPUOp {
|
class ActivationNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ActivationNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ActivationNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ActivationNPUOp() override;
|
~ActivationNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/argmax_npu.h"
|
#include "src/delegate/npu/op/argmax_npu.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ArgmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArgmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
argmax_ = new (std::nothrow) hiai::op::ArgMaxExt2(name_);
|
argmax_ = new (std::nothrow) hiai::op::ArgMaxExt2(name_);
|
||||||
if (argmax_ == nullptr) {
|
if (argmax_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New argmax npu operator for " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArgmaxNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArgmaxNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
argmax_->set_input_x(*npu_inputs[0]);
|
argmax_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -27,22 +27,22 @@ namespace mindspore {
|
||||||
|
|
||||||
class ArgmaxNPUOp : public NPUOp {
|
class ArgmaxNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ArgmaxNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ArgmaxNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ArgmaxNPUOp() override;
|
~ArgmaxNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,23 +15,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/arithmetic_npu.h"
|
#include "src/delegate/npu/op/arithmetic_npu.h"
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
constexpr int RELU_MODE = 1;
|
constexpr int RELU_MODE = 1;
|
||||||
constexpr int RELU6_MODE = 14;
|
constexpr int RELU6_MODE = 14;
|
||||||
int ArithmeticNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArithmeticNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors[0]->shape() != in_tensors[1]->shape()) {
|
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."
|
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;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
auto type = primitive->value_type();
|
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";
|
MS_LOG(WARNING) << name_ << " not support input 1d";
|
||||||
return RET_NOT_SUPPORT;
|
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";
|
MS_LOG(WARNING) << name_ << " not support input 2d";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +47,8 @@ ge::Operator *CreateOperator(const std::string &name) {
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArithmeticNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArithmeticNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case schema::PrimitiveType_MulFusion:
|
case schema::PrimitiveType_MulFusion:
|
||||||
op_ = CreateOperator<hiai::op::Mul>(name_);
|
op_ = CreateOperator<hiai::op::Mul>(name_);
|
||||||
|
@ -143,8 +142,8 @@ void SetInputs(const std::vector<ge::Operator *> &npu_inputs, ge::Operator *op)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArithmeticNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArithmeticNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case schema::PrimitiveType_MulFusion:
|
case schema::PrimitiveType_MulFusion:
|
||||||
|
@ -203,7 +202,7 @@ int ArithmeticNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tens
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArithmeticNPUOp::SetNPUInputs(
|
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::vector<ge::Operator *> &npu_inputs,
|
||||||
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
||||||
auto ret = SetNPUInputs(in_tensors, out_tensors, npu_inputs);
|
auto ret = SetNPUInputs(in_tensors, out_tensors, npu_inputs);
|
||||||
|
|
|
@ -25,24 +25,24 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ArithmeticNPUOp : public NPUOp {
|
class ArithmeticNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ArithmeticNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ArithmeticNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ArithmeticNPUOp() override;
|
~ArithmeticNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, const std::vector<ge::Operator *> &npu_inputs,
|
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;
|
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/arithmetic_self_npu.h"
|
#include "src/delegate/npu/op/arithmetic_self_npu.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -29,8 +28,8 @@ ge::Operator *CreateOperator(const std::string &name) {
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArithmeticSelfNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArithmeticSelfNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case schema::PrimitiveType_Cos:
|
case schema::PrimitiveType_Cos:
|
||||||
op_ = CreateOperator<hiai::op::Cos>(name_);
|
op_ = CreateOperator<hiai::op::Cos>(name_);
|
||||||
|
@ -86,8 +85,8 @@ void SetInputs(const std::vector<ge::Operator *> &npu_inputs, ge::Operator *op)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArithmeticSelfNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ArithmeticSelfNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case schema::PrimitiveType_Cos:
|
case schema::PrimitiveType_Cos:
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ArithmeticSelfNPUOp : public NPUOp {
|
class ArithmeticSelfNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ArithmeticSelfNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ArithmeticSelfNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ArithmeticSelfNPUOp() override;
|
~ArithmeticSelfNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/avg_pooling_npu.h"
|
#include "src/delegate/npu/op/avg_pooling_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int AvgPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int AvgPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto pooling_prim = primitive->value_as_AvgPoolFusion();
|
auto pooling_prim = primitive->value_as_AvgPoolFusion();
|
||||||
if (pooling_prim == nullptr) {
|
if (pooling_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AvgPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int AvgPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
||||||
if (pooling_ == nullptr) {
|
if (pooling_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New pooling npu operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AvgPoolingNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int AvgPoolingNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
pooling_->set_input_x(*npu_inputs[0]);
|
pooling_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -23,20 +23,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class AvgPoolingNPUOp : public ConvolutionBaseNPUOp {
|
class AvgPoolingNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
AvgPoolingNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
AvgPoolingNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~AvgPoolingNPUOp() override;
|
~AvgPoolingNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/batchnorm_npu.h"
|
#include "src/delegate/npu/op/batchnorm_npu.h"
|
||||||
|
#include "include/graph/op/all_ops.h"
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int BatchnormNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int BatchnormNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
batchnorm_ = new (std::nothrow) ge::op::BatchNormExt2(name_);
|
batchnorm_ = new (std::nothrow) ge::op::BatchNormExt2(name_);
|
||||||
if (batchnorm_ == nullptr) {
|
if (batchnorm_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New batchnorm npu operator for batchnorm op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BatchnormNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int BatchnormNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
batchnorm_->set_input_x(*npu_inputs[0]);
|
batchnorm_->set_input_x(*npu_inputs[0]);
|
||||||
auto scale = new (std::nothrow) hiai::op::Const(name_ + "_scale");
|
auto scale = new (std::nothrow) hiai::op::Const(name_ + "_scale");
|
||||||
|
|
|
@ -18,29 +18,28 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
#include "include/graph/compatible/all_ops.h"
|
#include "include/graph/compatible/all_ops.h"
|
||||||
#include "src/delegate/npu/op/npu_op.h"
|
#include "src/delegate/npu/op/npu_op.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class BatchnormNPUOp : public NPUOp {
|
class BatchnormNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
BatchnormNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
BatchnormNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~BatchnormNPUOp() override;
|
~BatchnormNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors.size() >= 2 && in_tensors[1]->ElementsNum() == 1) {
|
if (in_tensors.size() >= 2 && in_tensors[1].ElementNum() == 1) {
|
||||||
dst_type_ = static_cast<int *>(in_tensors[1]->data())[0];
|
dst_type_ = reinterpret_cast<const int *>(in_tensors[1].Data().get())[0];
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(WARNING) << "NPU dst dtype is attribute.";
|
MS_LOG(WARNING) << "NPU dst dtype is attribute.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
|
@ -29,20 +29,20 @@ int CastNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<t
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CastNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int CastNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
cast_ = new (std::nothrow) hiai::op::CastT(name_);
|
cast_ = new (std::nothrow) hiai::op::CastT(name_);
|
||||||
if (cast_ == nullptr) {
|
if (cast_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is nullptr";
|
MS_LOG(ERROR) << name_ << " op is nullptr";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
cast_->set_attr_dst_dtype(ConverterToNPUDataType(static_cast<TypeId>(dst_type_)));
|
cast_->set_attr_dst_dtype(ConverterToNPUDataType(static_cast<DataType>(dst_type_)));
|
||||||
cast_->set_attr_src_dtype(ConverterToNPUDataType(static_cast<TypeId>(in_tensors[0]->data_type())));
|
cast_->set_attr_src_dtype(ConverterToNPUDataType(static_cast<DataType>(in_tensors[0].DataType())));
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CastNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int CastNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
cast_->set_input_x(*npu_inputs[0]);
|
cast_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class CastNPUOp : public NPUOp {
|
class CastNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
CastNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
CastNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~CastNPUOp() override;
|
~CastNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ConcatNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConcatNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
concat_ = new (std::nothrow) hiai::op::ConcatD(name_);
|
concat_ = new (std::nothrow) hiai::op::ConcatD(name_);
|
||||||
if (concat_ == nullptr) {
|
if (concat_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConcatNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConcatNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
concat_->set_attr_concat_dim(axis_);
|
concat_->set_attr_concat_dim(axis_);
|
||||||
concat_->set_attr_N(npu_inputs.size());
|
concat_->set_attr_N(npu_inputs.size());
|
||||||
|
|
|
@ -23,22 +23,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ConcatNPUOp : public NPUOp {
|
class ConcatNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ConcatNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ConcatNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ConcatNPUOp() override;
|
~ConcatNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
#include "src/delegate/npu/transpose_kernel.h"
|
#include "src/delegate/npu/transpose_kernel.h"
|
||||||
#include "nnacl/fp16/cast_fp16.h"
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
ConvolutionBaseNPUOp::~ConvolutionBaseNPUOp() {
|
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");
|
weight_ = new (std::nothrow) hiai::op::Const(name_ + "_w");
|
||||||
if (weight_ == nullptr) {
|
if (weight_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New weight const failed.";
|
MS_LOG(ERROR) << "New weight const failed.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
auto w_shape = inputs[1]->shape();
|
auto w_shape = inputs[1].Shape();
|
||||||
auto origin_data = inputs[1]->data();
|
auto origin_data = inputs[1].Data().get();
|
||||||
auto fp32_data = origin_data;
|
float *fp32_data = nullptr;
|
||||||
if (inputs[1]->data_type() == kNumberTypeFloat16) {
|
if (inputs[1].DataType() == DataType::kNumberTypeFloat16) {
|
||||||
fp32_data = reinterpret_cast<float *>(malloc(inputs[1]->ElementsNum() * sizeof(float)));
|
#ifdef ENABLE_ARM64
|
||||||
|
fp32_data = reinterpret_cast<float *>(malloc(inputs[1].ElementNum() * sizeof(float)));
|
||||||
// fp16->fp32
|
// fp16->fp32
|
||||||
Float16ToFloat32(reinterpret_cast<float16_t *>(origin_data), reinterpret_cast<float *>(fp32_data),
|
Float16ToFloat32(reinterpret_cast<const float16_t *>(origin_data), reinterpret_cast<float *>(fp32_data),
|
||||||
inputs[1]->ElementsNum());
|
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) {
|
if (nchw_data == nullptr) {
|
||||||
MS_LOG(ERROR) << "Malloc buffer failed.";
|
MS_LOG(ERROR) << "Malloc buffer failed.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
if (inputs[1].DataType() == DataType::kNumberTypeFloat16) {
|
||||||
PackNHWCToNCHWFp32(fp32_data, nchw_data, w_shape[0], w_shape[1] * w_shape[2], w_shape[3]);
|
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());
|
std::shared_ptr<ge::Tensor> weight_tensor = std::shared_ptr<ge::Tensor>(new (std::nothrow) ge::Tensor());
|
||||||
if (weight_tensor == nullptr) {
|
if (weight_tensor == nullptr) {
|
||||||
|
@ -63,16 +74,16 @@ int ConvolutionBaseNPUOp::InitWeightConst(const std::vector<tensor::MSTensor *>
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
ge::TensorDesc tensor_desc(ConverterToNPUShape({w_shape[0], w_shape[3], w_shape[1], w_shape[2]}), ge::FORMAT_NCHW,
|
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->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);
|
weight_->set_attr_value(weight_tensor);
|
||||||
free(nchw_data);
|
free(nchw_data);
|
||||||
return RET_OK;
|
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) {
|
if (inputs.size() >= 3) {
|
||||||
bias_ = new (std::nothrow) hiai::op::Const(name_ + "_b");
|
bias_ = new (std::nothrow) hiai::op::Const(name_ + "_b");
|
||||||
if (bias_ == nullptr) {
|
if (bias_ == nullptr) {
|
||||||
|
|
|
@ -24,15 +24,15 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ConvolutionBaseNPUOp : public NPUOp {
|
class ConvolutionBaseNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ConvolutionBaseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ConvolutionBaseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ConvolutionBaseNPUOp() override;
|
~ConvolutionBaseNPUOp() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int InitWeightConst(const std::vector<tensor::MSTensor *> &inputs);
|
int InitWeightConst(const std::vector<mindspore::MSTensor> &inputs);
|
||||||
int InitBiasConst(const std::vector<tensor::MSTensor *> &inputs);
|
int InitBiasConst(const std::vector<mindspore::MSTensor> &inputs);
|
||||||
int SetActivation(const ge::Operator *input, schema::ActivationType act_type);
|
int SetActivation(const ge::Operator *input, schema::ActivationType act_type);
|
||||||
hiai::op::Activation *act_ = nullptr;
|
hiai::op::Activation *act_ = nullptr;
|
||||||
hiai::op::Const *weight_ = 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,
|
int ConvolutionDepthwiseNPUOp::Init(const schema::Primitive *primitive,
|
||||||
const std::vector<tensor::MSTensor *> &in_tensors,
|
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
conv_dw_ = new (std::nothrow) hiai::op::ConvolutionDepthwise(name_ + "_conv_depthwise");
|
conv_dw_ = new (std::nothrow) hiai::op::ConvolutionDepthwise(name_ + "_conv_depthwise");
|
||||||
if (conv_dw_ == nullptr) {
|
if (conv_dw_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New convolution depthwise operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvolutionDepthwiseNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConvolutionDepthwiseNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
auto ret = InitWeightConst(in_tensors);
|
auto ret = InitWeightConst(in_tensors);
|
||||||
if (ret != RET_OK) {
|
if (ret != RET_OK) {
|
||||||
|
|
|
@ -18,28 +18,27 @@
|
||||||
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_DEPTHWISE_NPU_H_
|
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_DEPTHWISE_NPU_H_
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
#include "include/graph/compatible/all_ops.h"
|
#include "include/graph/compatible/all_ops.h"
|
||||||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ConvolutionDepthwiseNPUOp : public ConvolutionBaseNPUOp {
|
class ConvolutionDepthwiseNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
ConvolutionDepthwiseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ConvolutionDepthwiseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ConvolutionDepthwiseNPUOp() override;
|
~ConvolutionDepthwiseNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "src/delegate/npu/op/convolution_npu.h"
|
#include "src/delegate/npu/op/convolution_npu.h"
|
||||||
#include "src/delegate/npu/op/convolution_depthwise_npu.h"
|
#include "src/delegate/npu/op/convolution_depthwise_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ConvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto conv_prim = primitive->value_as_Conv2DFusion();
|
auto conv_prim = primitive->value_as_Conv2DFusion();
|
||||||
if (conv_prim == nullptr) {
|
if (conv_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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_h = static_cast<int>(*(conv_prim->stride()->begin()));
|
||||||
auto stride_w = static_cast<int>(*(conv_prim->stride()->begin() + 1));
|
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]) {
|
if (stride_h > in_shape[1] || stride_w > in_shape[2]) {
|
||||||
MS_LOG(WARNING) << "Npu convolution does not support stride greater than input size.";
|
MS_LOG(WARNING) << "Npu convolution does not support stride greater than input size.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
|
@ -61,8 +61,8 @@ int ConvolutionNPUOp::SetConvParam(const schema::Conv2DFusion *conv_prim) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
// set conv attr param
|
// set conv attr param
|
||||||
conv_ = new (std::nothrow) hiai::op::Convolution(name_ + "_conv");
|
conv_ = new (std::nothrow) hiai::op::Convolution(name_ + "_conv");
|
||||||
if (conv_ == nullptr) {
|
if (conv_ == nullptr) {
|
||||||
|
@ -90,8 +90,8 @@ int ConvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvolutionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ConvolutionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
auto ret = InitWeightConst(in_tensors);
|
auto ret = InitWeightConst(in_tensors);
|
||||||
if (ret != RET_OK) {
|
if (ret != RET_OK) {
|
||||||
|
@ -125,30 +125,30 @@ ConvolutionNPUOp::~ConvolutionNPUOp() {
|
||||||
conv_ = nullptr;
|
conv_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name) {
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name) {
|
auto shape = out_tensors.front().Shape();
|
||||||
auto shape = out_tensors.front()->shape();
|
|
||||||
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
||||||
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
||||||
return nullptr;
|
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";
|
MS_LOG(ERROR) << "Npu does not support input tensor dims greater than 4";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_tensors[0]->data_type() != kNumberTypeFloat32 && in_tensors[0]->data_type() != kNumberTypeFloat16) {
|
if (in_tensors[0].DataType() != DataType::kNumberTypeFloat32 &&
|
||||||
MS_LOG(ERROR) << "Npu does not support datatype " << in_tensors[0]->data_type();
|
in_tensors[0].DataType() != DataType::kNumberTypeFloat16) {
|
||||||
|
MS_LOG(ERROR) << "Npu does not support datatype " << static_cast<int>(in_tensors[0].DataType());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NPUOp *op = nullptr;
|
NPUOp *op = nullptr;
|
||||||
auto conv_prim = primitive->value_as_Conv2DFusion();
|
auto conv_prim = primitive->value_as_Conv2DFusion();
|
||||||
auto group = static_cast<int>(conv_prim->group());
|
auto group = static_cast<int>(conv_prim->group());
|
||||||
auto input_channel = in_tensors.front()->shape()[3];
|
auto input_channel = in_tensors.front().Shape()[3];
|
||||||
auto output_channel = out_tensors.front()->shape()[3];
|
auto output_channel = out_tensors.front().Shape()[3];
|
||||||
if (group == input_channel && group == output_channel) {
|
if (group == input_channel && group == output_channel) {
|
||||||
op = new (std::nothrow) ConvolutionDepthwiseNPUOp(primitive, in_tensors, out_tensors, name);
|
op = new (std::nothrow) ConvolutionDepthwiseNPUOp(primitive, in_tensors, out_tensors, name);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,20 +23,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ConvolutionNPUOp : public ConvolutionBaseNPUOp {
|
class ConvolutionNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
ConvolutionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ConvolutionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ConvolutionNPUOp() override;
|
~ConvolutionNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
@ -47,7 +47,7 @@ class ConvolutionNPUOp : public ConvolutionBaseNPUOp {
|
||||||
hiai::op::Convolution *conv_ = nullptr;
|
hiai::op::Convolution *conv_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
NPUOp *GetNPUConvOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name);
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name);
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_NPU_H_
|
#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"
|
#include "src/delegate/npu/op/crop_and_resize_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors.size() < 4) {
|
if (in_tensors.size() < 4) {
|
||||||
MS_LOG(WARNING) << "NPU CropAndResize got nput inputs size < 4";
|
MS_LOG(WARNING) << "NPU CropAndResize got nput inputs size < 4";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
|
@ -37,8 +38,8 @@ int CropAndResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std:
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CropAndResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int CropAndResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
crop_and_resize_ = new (std::nothrow) hiai::op::CropAndResize(name_);
|
crop_and_resize_ = new (std::nothrow) hiai::op::CropAndResize(name_);
|
||||||
if (crop_and_resize_ == nullptr) {
|
if (crop_and_resize_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CropAndResizeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int CropAndResizeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
crop_and_resize_->set_input_x(*npu_inputs[0]);
|
crop_and_resize_->set_input_x(*npu_inputs[0]);
|
||||||
crop_and_resize_->set_input_boxes(*npu_inputs[1]);
|
crop_and_resize_->set_input_boxes(*npu_inputs[1]);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class CropAndResizeNPUOp : public NPUOp {
|
class CropAndResizeNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
CropAndResizeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
CropAndResizeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~CropAndResizeNPUOp() override;
|
~CropAndResizeNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int DeconvolutionNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int DeconvolutionNPUOp::IsSupport(const schema::Primitive *primitive,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto deconv_prim = primitive->value_as_Conv2dTransposeFusion();
|
auto deconv_prim = primitive->value_as_Conv2dTransposeFusion();
|
||||||
if (deconv_prim == nullptr) {
|
if (deconv_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||||
|
@ -59,8 +60,8 @@ int DeconvolutionNPUOp::SetDeconvParam(const schema::Conv2dTransposeFusion *conv
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
// set deconv attr param
|
// set deconv attr param
|
||||||
deconv_ = new (std::nothrow) hiai::op::ConvTranspose(name_ + "_deconv");
|
deconv_ = new (std::nothrow) hiai::op::ConvTranspose(name_ + "_deconv");
|
||||||
if (deconv_ == nullptr) {
|
if (deconv_ == nullptr) {
|
||||||
|
@ -89,8 +90,8 @@ int DeconvolutionNPUOp::Init(const schema::Primitive *primitive, const std::vect
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeconvolutionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int DeconvolutionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
auto ret = InitWeightConst(in_tensors);
|
auto ret = InitWeightConst(in_tensors);
|
||||||
if (ret != RET_OK) {
|
if (ret != RET_OK) {
|
||||||
|
|
|
@ -24,19 +24,19 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class DeconvolutionNPUOp : public ConvolutionBaseNPUOp {
|
class DeconvolutionNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
DeconvolutionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
DeconvolutionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
~DeconvolutionNPUOp() override;
|
~DeconvolutionNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int EltwiseNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int EltwiseNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
eltwise_ = new (std::nothrow) hiai::op::Eltwise(name_);
|
eltwise_ = new (std::nothrow) hiai::op::Eltwise(name_);
|
||||||
if (eltwise_ == nullptr) {
|
if (eltwise_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EltwiseNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int EltwiseNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
for (int i = 0; i < npu_inputs.size(); ++i) {
|
for (int i = 0; i < npu_inputs.size(); ++i) {
|
||||||
eltwise_->set_dynamic_input_x(i + 1, *npu_inputs[i]);
|
eltwise_->set_dynamic_input_x(i + 1, *npu_inputs[i]);
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class EltwiseNPUOp : public NPUOp {
|
class EltwiseNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
EltwiseNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
EltwiseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~EltwiseNPUOp() override;
|
~EltwiseNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ExpandDimsNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ExpandDimsNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
expand_dims_ = new (std::nothrow) hiai::op::ExpandDims(name_);
|
expand_dims_ = new (std::nothrow) hiai::op::ExpandDims(name_);
|
||||||
if (expand_dims_ == nullptr) {
|
if (expand_dims_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExpandDimsNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ExpandDimsNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
expand_dims_->set_input_x(*npu_inputs[0]);
|
expand_dims_->set_input_x(*npu_inputs[0]);
|
||||||
expand_dims_->set_input_axis(*npu_inputs[1]);
|
expand_dims_->set_input_axis(*npu_inputs[1]);
|
||||||
|
|
|
@ -24,21 +24,21 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ExpandDimsNPUOp : public NPUOp {
|
class ExpandDimsNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ExpandDimsNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ExpandDimsNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
~ExpandDimsNPUOp() override;
|
~ExpandDimsNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -19,15 +19,15 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int FullconnectionNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto fc_prim = primitive->value_as_FullConnection();
|
auto fc_prim = primitive->value_as_FullConnection();
|
||||||
if (fc_prim == nullptr) {
|
if (fc_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
act_type_ = fc_prim->activation_type();
|
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");
|
reshape_ = new (std::nothrow) hiai::op::Reshape(name_ + "_reshape");
|
||||||
if (reshape_ == nullptr) {
|
if (reshape_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New reshape operator for fullconnection op " << name_ << " failed.";
|
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];
|
col *= input_shape[i];
|
||||||
}
|
}
|
||||||
reshape_op_ = new (std::nothrow) hiai::op::Const(name_ + "_reshape_data");
|
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::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);
|
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));
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FullconnectionNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int FullconnectionNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
reshape_->set_input_x(*npu_inputs[0]);
|
reshape_->set_input_x(*npu_inputs[0]);
|
||||||
fc_->set_input_x1(*reshape_);
|
fc_->set_input_x1(*reshape_);
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class FullconnectionNPUOp : public ConvolutionBaseNPUOp {
|
class FullconnectionNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
FullconnectionNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
FullconnectionNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~FullconnectionNPUOp() override;
|
~FullconnectionNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
#include "src/delegate/npu/op/gather_npu.h"
|
#include "src/delegate/npu/op/gather_npu.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors[1]->data_type() != kNumberTypeInt32) {
|
if (in_tensors[1].DataType() != DataType::kNumberTypeInt32) {
|
||||||
MS_LOG(WARNING) << "Gather indices only support Int32";
|
MS_LOG(WARNING) << "Gather indices only support Int32";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
if (in_tensors.size() >= 3 && in_tensors[2]->ElementsNum() == 1) {
|
if (in_tensors.size() >= 3 && in_tensors[2].ElementNum() == 1) {
|
||||||
axis_ = static_cast<int *>(in_tensors[2]->data())[0];
|
axis_ = static_cast<const int *>(in_tensors[2].Data().get())[0];
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(WARNING) << "NPU axis is attribute.";
|
MS_LOG(WARNING) << "NPU axis is attribute.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
|
@ -32,8 +32,8 @@ int GatherNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GatherNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int GatherNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
gather_ = new (std::nothrow) hiai::op::GatherV2D(name_);
|
gather_ = new (std::nothrow) hiai::op::GatherV2D(name_);
|
||||||
if (gather_ == nullptr) {
|
if (gather_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GatherNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int GatherNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
gather_->set_input_x(*npu_inputs[0]);
|
gather_->set_input_x(*npu_inputs[0]);
|
||||||
gather_->set_input_indices(*npu_inputs[1]);
|
gather_->set_input_indices(*npu_inputs[1]);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class GatherNPUOp : public NPUOp {
|
class GatherNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
GatherNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
GatherNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~GatherNPUOp() override;
|
~GatherNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/instance_norm_npu.h"
|
#include "src/delegate/npu/op/instance_norm_npu.h"
|
||||||
#include <memory>
|
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int InstanceNormNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int InstanceNormNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
instance_norm_ = new (std::nothrow) hiai::op::InstanceNorm(name_);
|
instance_norm_ = new (std::nothrow) hiai::op::InstanceNorm(name_);
|
||||||
if (instance_norm_ == nullptr) {
|
if (instance_norm_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New instance norm npu operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InstanceNormNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int InstanceNormNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
instance_norm_->set_input_x(*npu_inputs[0]);
|
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]);
|
auto gamma_tensor = ConverterToNPUTensor(in_tensors[1]);
|
||||||
if (gamma_tensor == nullptr) {
|
if (gamma_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get gamma_tensor failed.";
|
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);
|
gamma_->set_attr_value(gamma_tensor);
|
||||||
instance_norm_->set_input_gamma(*gamma_);
|
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]);
|
auto beta_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||||
if (beta_tensor == nullptr) {
|
if (beta_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get beta_tensor failed.";
|
MS_LOG(ERROR) << "Get beta_tensor failed.";
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class InstanceNormNPUOp : public NPUOp {
|
class InstanceNormNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
InstanceNormNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
InstanceNormNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~InstanceNormNPUOp() override;
|
~InstanceNormNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,21 +15,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/matmul_npu.h"
|
#include "src/delegate/npu/op/matmul_npu.h"
|
||||||
#include <memory>
|
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int MatMulNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int MatMulNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors.size() == 3) {
|
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_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MatMulNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int MatMulNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
matmul_ = new (std::nothrow) hiai::op::MatMul(name_);
|
matmul_ = new (std::nothrow) hiai::op::MatMul(name_);
|
||||||
if (matmul_ == nullptr) {
|
if (matmul_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New matmul npu operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MatMulNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int MatMulNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
matmul_->set_input_x1(*npu_inputs[0]);
|
matmul_->set_input_x1(*npu_inputs[0]);
|
||||||
matmul_->set_input_x2(*npu_inputs[1]);
|
matmul_->set_input_x2(*npu_inputs[1]);
|
||||||
|
@ -60,7 +59,7 @@ int MatMulNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
add_op_->set_input_x1(*matmul_);
|
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]);
|
auto bias_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||||
if (bias_tensor == nullptr) {
|
if (bias_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get bias_tensor failed.";
|
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}));
|
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_desc.SetShape(ConverterToNPUShape({1, bias_shape[0]}));
|
||||||
}
|
}
|
||||||
bias_tensor->SetTensorDesc(bias_tensor_desc);
|
bias_tensor->SetTensorDesc(bias_tensor_desc);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class MatMulNPUOp : public NPUOp {
|
class MatMulNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
MatMulNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
MatMulNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~MatMulNPUOp() override;
|
~MatMulNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/max_pooling_npu.h"
|
#include "src/delegate/npu/op/max_pooling_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int MaxPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int MaxPoolingNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto pooling_prim = primitive->value_as_MaxPoolFusion();
|
auto pooling_prim = primitive->value_as_MaxPoolFusion();
|
||||||
if (pooling_prim == nullptr) {
|
if (pooling_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MaxPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int MaxPoolingNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
pooling_ = new (std::nothrow) hiai::op::PoolingD(name_ + "_pooling");
|
||||||
if (pooling_ == nullptr) {
|
if (pooling_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New pooling npu operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MaxPoolingNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int MaxPoolingNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
pooling_->set_input_x(*npu_inputs[0]);
|
pooling_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -18,25 +18,24 @@
|
||||||
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_MAX_POOLING_NPU_H_
|
#define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_MAX_POOLING_NPU_H_
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "include/graph/op/all_ops.h"
|
|
||||||
#include "src/delegate/npu/op/convolution_base_npu.h"
|
#include "src/delegate/npu/op/convolution_base_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class MaxPoolingNPUOp : public ConvolutionBaseNPUOp {
|
class MaxPoolingNPUOp : public ConvolutionBaseNPUOp {
|
||||||
public:
|
public:
|
||||||
MaxPoolingNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
MaxPoolingNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
: ConvolutionBaseNPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~MaxPoolingNPUOp() override;
|
~MaxPoolingNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -21,19 +21,20 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#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 "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_ERROR;
|
||||||
using mindspore::lite::RET_NOT_SUPPORT;
|
using mindspore::lite::RET_NOT_SUPPORT;
|
||||||
using mindspore::lite::RET_OK;
|
using mindspore::lite::RET_OK;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class NPUOp {
|
class NPUOp {
|
||||||
public:
|
public:
|
||||||
NPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
NPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: inputs_(std::move(in_tensors)), outputs_(std::move(out_tensors)), name_(name) {
|
: inputs_(std::move(in_tensors)), outputs_(std::move(out_tensors)), name_(name) {
|
||||||
if (primitive != nullptr) {
|
if (primitive != nullptr) {
|
||||||
type_ = primitive->value_type();
|
type_ = primitive->value_type();
|
||||||
|
@ -42,24 +43,24 @@ class NPUOp {
|
||||||
|
|
||||||
virtual ~NPUOp() = default;
|
virtual ~NPUOp() = default;
|
||||||
|
|
||||||
virtual int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
virtual int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
virtual int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
virtual int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
virtual int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs,
|
const std::vector<ge::Operator *> &npu_inputs,
|
||||||
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
const std::unordered_map<int, std::pair<ge::Operator *, int>> &index2_multi_out_index) {
|
||||||
if (index2_multi_out_index.empty()) {
|
if (index2_multi_out_index.empty()) {
|
||||||
|
@ -70,18 +71,18 @@ class NPUOp {
|
||||||
|
|
||||||
virtual ge::Operator *GetNPUOp() { return nullptr; }
|
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());
|
MS_ASSERT(index < inputs_.size());
|
||||||
this->inputs_[index] = in_tensor;
|
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; }
|
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; }
|
void set_name(const std::string &name) { this->name_ = name; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<mindspore::tensor::MSTensor *> inputs_;
|
std::vector<mindspore::MSTensor> inputs_;
|
||||||
std::vector<mindspore::tensor::MSTensor *> outputs_;
|
std::vector<mindspore::MSTensor> outputs_;
|
||||||
std::vector<NPUOp *> in_ops_;
|
std::vector<NPUOp *> in_ops_;
|
||||||
std::vector<NPUOp *> out_ops_;
|
std::vector<NPUOp *> out_ops_;
|
||||||
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
schema::PrimitiveType type_ = schema::PrimitiveType_NONE;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef NPUOp *(*NPUGetOp)(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
typedef NPUOp *(*NPUGetOp)(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name);
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
NPUOp *GetNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
NPUOp *GetNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name) {
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name) {
|
||||||
auto shape = out_tensors.front()->shape();
|
auto shape = out_tensors.front().Shape();
|
||||||
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
if (std::find(shape.begin(), shape.end(), -1) != shape.end()) {
|
||||||
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
MS_LOG(ERROR) << "NPU does not support runtime inference shape.";
|
||||||
return nullptr;
|
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";
|
MS_LOG(ERROR) << "Npu does not support input tensor dims greater than 4";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<schema::PrimitiveType> int32_lists = {schema::PrimitiveType_Cast, schema::PrimitiveType_StridedSlice};
|
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();
|
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 &&
|
if (in_tensors[0].DataType() != DataType::kNumberTypeFloat32 &&
|
||||||
!support_int32) {
|
in_tensors[0].DataType() != DataType::kNumberTypeFloat16 && !support_int32) {
|
||||||
MS_LOG(ERROR) << "Npu does not support datatype " << in_tensors[0]->data_type() << " for op type "
|
MS_LOG(ERROR) << "Npu does not support datatype " << static_cast<int>(in_tensors[0].DataType()) << " for op type "
|
||||||
<< primitive->value_type();
|
<< primitive->value_type();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int PadNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int PadNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto pad_prim = primitive->value_as_PadFusion();
|
auto pad_prim = primitive->value_as_PadFusion();
|
||||||
if (pad_prim == nullptr) {
|
if (pad_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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) {
|
if (pad_prim->paddings() != nullptr) {
|
||||||
return RET_OK;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
MS_LOG(WARNING) << "NPU pad only support constant pad size.";
|
MS_LOG(WARNING) << "NPU pad only support constant pad size.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int PadNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
pad_ = new (std::nothrow) hiai::op::PadV2(name_);
|
pad_ = new (std::nothrow) hiai::op::PadV2(name_);
|
||||||
if (pad_ == nullptr) {
|
if (pad_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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());
|
auto paddings = std::vector<int64_t>(paddings_data->begin(), paddings_data->end());
|
||||||
paddings_vec_.insert(paddings_vec_.end(), paddings.begin(), paddings.end());
|
paddings_vec_.insert(paddings_vec_.end(), paddings.begin(), paddings.end());
|
||||||
}
|
}
|
||||||
} else if (in_tensors.size() >= 2 && in_tensors[1]->data() != nullptr) {
|
} else if (in_tensors.size() >= 2 && in_tensors[1].Data() != nullptr) {
|
||||||
for (int i = 0; i < in_tensors[1]->ElementsNum(); i++) {
|
for (int i = 0; i < in_tensors[1].ElementNum(); i++) {
|
||||||
paddings_vec_.push_back(static_cast<int *>(in_tensors[1]->data())[i]);
|
paddings_vec_.push_back(static_cast<const int *>(in_tensors[1].Data().get())[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(ERROR) << "NPU pad only support constant pad size.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PadNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int PadNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
int size = static_cast<int>(paddings_vec_.size() / 2);
|
int size = static_cast<int>(paddings_vec_.size() / 2);
|
||||||
ge::TensorDesc padding_tensor_desc(ge::Shape({size, 2}), ge::FORMAT_NCHW, ge::DT_INT32);
|
ge::TensorDesc padding_tensor_desc(ge::Shape({size, 2}), ge::FORMAT_NCHW, ge::DT_INT32);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class PadNPUOp : public NPUOp {
|
class PadNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
PadNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
PadNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~PadNPUOp() override;
|
~PadNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,11 +15,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/reduce_npu.h"
|
#include "src/delegate/npu/op/reduce_npu.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ReduceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReduceNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto reduce_prim = primitive->value_as_ReduceFusion();
|
auto reduce_prim = primitive->value_as_ReduceFusion();
|
||||||
if (reduce_prim == nullptr) {
|
if (reduce_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReduceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReduceNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto reduce_prim = primitive->value_as_ReduceFusion();
|
auto reduce_prim = primitive->value_as_ReduceFusion();
|
||||||
if (reduce_prim == nullptr) {
|
if (reduce_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReduceNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReduceNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
if (reduce_mode_ == schema::ReduceMode_ReduceMean) {
|
if (reduce_mode_ == schema::ReduceMode_ReduceMean) {
|
||||||
auto reduce_mean = reinterpret_cast<hiai::op::ReduceMean *>(reduce_);
|
auto reduce_mean = reinterpret_cast<hiai::op::ReduceMean *>(reduce_);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ReduceNPUOp : public NPUOp {
|
class ReduceNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ReduceNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ReduceNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ReduceNPUOp() override;
|
~ReduceNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,26 +15,25 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/reshape_npu.h"
|
#include "src/delegate/npu/op/reshape_npu.h"
|
||||||
#include <memory>
|
|
||||||
#include "include/graph/op/all_ops.h"
|
#include "include/graph/op/all_ops.h"
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ReshapeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReshapeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
if (in_tensors.size() != 2) {
|
if (in_tensors.size() != 2) {
|
||||||
MS_LOG(WARNING) << "Npu op should have w2 input tensors.";
|
MS_LOG(WARNING) << "Npu op should have w2 input tensors.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
auto shape_tensor = in_tensors.at(1);
|
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.";
|
MS_LOG(WARNING) << "Npu reshape op only supports const shape.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReshapeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReshapeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
reshape_ = new (std::nothrow) hiai::op::Reshape(name_);
|
reshape_ = new (std::nothrow) hiai::op::Reshape(name_);
|
||||||
if (reshape_ == nullptr) {
|
if (reshape_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReshapeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ReshapeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
reshape_->set_input_x(*npu_inputs[0]);
|
reshape_->set_input_x(*npu_inputs[0]);
|
||||||
reshape_->set_input_shape(*npu_inputs[1]);
|
reshape_->set_input_shape(*npu_inputs[1]);
|
||||||
|
|
|
@ -23,20 +23,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ReshapeNPUOp : public NPUOp {
|
class ReshapeNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ReshapeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ReshapeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ReshapeNPUOp() override;
|
~ReshapeNPUOp() override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ResizeNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto resize_prim = primitive->value_as_Resize();
|
auto resize_prim = primitive->value_as_Resize();
|
||||||
if (resize_prim == nullptr) {
|
if (resize_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_tensors[0]->shape()[1] > out_tensors[0]->shape()[1] ||
|
if (in_tensors[0].Shape()[1] > out_tensors[0].Shape()[1] || in_tensors[0].Shape()[2] > out_tensors[0].Shape()[2]) {
|
||||||
in_tensors[0]->shape()[2] > out_tensors[0]->shape()[2]) {
|
|
||||||
MS_LOG(WARNING) << "Npu resize does not support reduction.";
|
MS_LOG(WARNING) << "Npu resize does not support reduction.";
|
||||||
return RET_NOT_SUPPORT;
|
return RET_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto resize_prim = primitive->value_as_Resize();
|
auto resize_prim = primitive->value_as_Resize();
|
||||||
if (resize_prim == nullptr) {
|
if (resize_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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_height_ = resize_prim->new_height();
|
||||||
new_width_ = resize_prim->new_width();
|
new_width_ = resize_prim->new_width();
|
||||||
} else if (in_tensors.size() == 2) {
|
} 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) {
|
if (out_size == nullptr) {
|
||||||
MS_LOG(ERROR) << "Out size is not assigned";
|
MS_LOG(ERROR) << "Out size is not assigned";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
new_height_ = out_tensors.at(0)->shape().at(1);
|
new_height_ = out_tensors.at(0).Shape().at(1);
|
||||||
new_width_ = out_tensors.at(0)->shape().at(2);
|
new_width_ = out_tensors.at(0).Shape().at(2);
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(ERROR) << "Get resize op new_height and new_width error.";
|
MS_LOG(ERROR) << "Get resize op new_height and new_width error.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
|
@ -97,8 +96,8 @@ int ResizeNPUOp::Init(const schema::Primitive *primitive, const std::vector<tens
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResizeNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ResizeNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
if (resize_method_ == schema::ResizeMethod_LINEAR) {
|
if (resize_method_ == schema::ResizeMethod_LINEAR) {
|
||||||
auto resize_bilinear = reinterpret_cast<hiai::op::ResizeBilinearV2 *>(resize_);
|
auto resize_bilinear = reinterpret_cast<hiai::op::ResizeBilinearV2 *>(resize_);
|
||||||
|
|
|
@ -24,20 +24,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ResizeNPUOp : public NPUOp {
|
class ResizeNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ResizeNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ResizeNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ResizeNPUOp() override;
|
~ResizeNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/delegate/npu/op/scale_npu.h"
|
#include "src/delegate/npu/op/scale_npu.h"
|
||||||
#include <memory>
|
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ScaleNPUOp::IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
auto scale_prim = primitive->value_as_ScaleFusion();
|
auto scale_prim = primitive->value_as_ScaleFusion();
|
||||||
if (scale_prim == nullptr) {
|
if (scale_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get null primitive value for op ." << name_;
|
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();
|
axis_ = scale_prim->axis();
|
||||||
if (axis_ < 0) {
|
if (axis_ < 0) {
|
||||||
axis_ = axis_ + in_tensors[0]->shape().size();
|
axis_ = axis_ + in_tensors[0].Shape().size();
|
||||||
}
|
}
|
||||||
if (axis_ != 1 && axis_ != 3) {
|
if (axis_ != 1 && axis_ != 3) {
|
||||||
MS_LOG(WARNING) << "Npu scale axis attr only support 1 or channel, now is " << axis_;
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScaleNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int ScaleNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
op_ = new (std::nothrow) hiai::op::Scale(name_);
|
op_ = new (std::nothrow) hiai::op::Scale(name_);
|
||||||
if (op_ == nullptr) {
|
if (op_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScaleNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int ScaleNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
op_->set_input_x(*npu_inputs.at(0));
|
op_->set_input_x(*npu_inputs.at(0));
|
||||||
MS_ASSERT(in_tensors.size() > 1);
|
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]);
|
auto scale_tensor = ConverterToNPUTensor(in_tensors[1]);
|
||||||
if (scale_tensor == nullptr) {
|
if (scale_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get scale_tensor failed.";
|
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_);
|
op_->set_input_scale(*scale_);
|
||||||
|
|
||||||
if (in_tensors.size() > 2 && in_tensors[2] != nullptr) {
|
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]);
|
auto bias_tensor = ConverterToNPUTensor(in_tensors[2]);
|
||||||
if (bias_tensor == nullptr) {
|
if (bias_tensor == nullptr) {
|
||||||
MS_LOG(ERROR) << "Get bias_tensor failed.";
|
MS_LOG(ERROR) << "Get bias_tensor failed.";
|
||||||
|
|
|
@ -25,20 +25,20 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class ScaleNPUOp : public NPUOp {
|
class ScaleNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
ScaleNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
ScaleNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~ScaleNPUOp() override;
|
~ScaleNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int SliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int SliceNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
slice_ = new (std::nothrow) hiai::op::Slice(name_);
|
slice_ = new (std::nothrow) hiai::op::Slice(name_);
|
||||||
if (slice_ == nullptr) {
|
if (slice_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SliceNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SliceNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
slice_->set_input_x(*npu_inputs[0]);
|
slice_->set_input_x(*npu_inputs[0]);
|
||||||
slice_->set_input_offsets(*npu_inputs[1]);
|
slice_->set_input_offsets(*npu_inputs[1]);
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class SliceNPUOp : public NPUOp {
|
class SliceNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
SliceNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
SliceNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~SliceNPUOp() override;
|
~SliceNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
#include "src/delegate/npu/op/softmax_npu.h"
|
#include "src/delegate/npu/op/softmax_npu.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int SoftmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int SoftmaxNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
softmax_ = new (std::nothrow) hiai::op::Softmax(name_);
|
softmax_ = new (std::nothrow) hiai::op::Softmax(name_);
|
||||||
if (softmax_ == nullptr) {
|
if (softmax_ == nullptr) {
|
||||||
MS_LOG(ERROR) << name_ << " op is 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()));
|
auto axis = static_cast<int>(*(softmax_prim->axis()->begin()));
|
||||||
if (axis == -1) {
|
if (axis == -1) {
|
||||||
softmax_->set_attr_axis(in_tensors[0]->shape().size() + axis);
|
softmax_->set_attr_axis(in_tensors[0].Shape().size() + axis);
|
||||||
} else {
|
} else {
|
||||||
softmax_->set_attr_axis(axis);
|
softmax_->set_attr_axis(axis);
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SoftmaxNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SoftmaxNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
softmax_->set_input_x(*npu_inputs[0]);
|
softmax_->set_input_x(*npu_inputs[0]);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class SoftmaxNPUOp : public NPUOp {
|
class SoftmaxNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
SoftmaxNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
SoftmaxNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~SoftmaxNPUOp() override;
|
~SoftmaxNPUOp() override;
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
ge::Operator *GetNPUOp() override;
|
ge::Operator *GetNPUOp() override;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "src/delegate/npu/npu_converter_utils.h"
|
#include "src/delegate/npu/npu_converter_utils.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
int SplitNPUOp::Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int SplitNPUOp::Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) {
|
const std::vector<mindspore::MSTensor> &out_tensors) {
|
||||||
split_ = new (std::nothrow) hiai::op::SplitV(name_);
|
split_ = new (std::nothrow) hiai::op::SplitV(name_);
|
||||||
if (split_ == nullptr) {
|
if (split_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "New split npu operator for op " << name_ << " failed.";
|
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;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SplitNPUOp::SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SplitNPUOp::SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) {
|
const std::vector<ge::Operator *> &npu_inputs) {
|
||||||
ge::TensorDesc split_dim_tensor_desc(ge::Shape({1}), ge::FORMAT_NCHW, ge::DT_INT32);
|
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);
|
ge::TensorPtr split_dim_tensor = std::make_shared<hiai::Tensor>(split_dim_tensor_desc);
|
||||||
|
|
|
@ -24,22 +24,22 @@
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
class SplitNPUOp : public NPUOp {
|
class SplitNPUOp : public NPUOp {
|
||||||
public:
|
public:
|
||||||
SplitNPUOp(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
SplitNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors, std::string name)
|
const std::vector<mindspore::MSTensor> &out_tensors, std::string name)
|
||||||
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
: NPUOp(primitive, in_tensors, out_tensors, name) {}
|
||||||
|
|
||||||
~SplitNPUOp();
|
~SplitNPUOp();
|
||||||
|
|
||||||
int IsSupport(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int IsSupport(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override {
|
const std::vector<mindspore::MSTensor> &out_tensors) override {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const schema::Primitive *primitive, const std::vector<tensor::MSTensor *> &in_tensors,
|
int Init(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors) override;
|
const std::vector<mindspore::MSTensor> &out_tensors) override;
|
||||||
|
|
||||||
int SetNPUInputs(const std::vector<tensor::MSTensor *> &in_tensors,
|
int SetNPUInputs(const std::vector<mindspore::MSTensor> &in_tensors,
|
||||||
const std::vector<tensor::MSTensor *> &out_tensors,
|
const std::vector<mindspore::MSTensor> &out_tensors,
|
||||||
const std::vector<ge::Operator *> &npu_inputs) override;
|
const std::vector<ge::Operator *> &npu_inputs) override;
|
||||||
|
|
||||||
int HandleAxis();
|
int HandleAxis();
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue