!4527 [MS][LITE]optimize the interface of model and kernel registry
Merge pull request !4527 from zhaizhiqiang/masterpull/4527/MERGE
commit
857c0301a8
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mindspore/lite/src/kernel_factory.h"
|
||||
#include "utils/log_adapter.h"
|
||||
#include "src/populate_parameter.h"
|
||||
#include "schema/model_generated.h"
|
||||
|
||||
using mindspore::kernel::KERNEL_ARCH;
|
||||
using mindspore::kernel::KernelKey;
|
||||
using mindspore::kernel::LiteKernel;
|
||||
|
||||
namespace mindspore::lite {
|
||||
KernelFactory::KernelFactory() = default;
|
||||
|
||||
KernelFactory::~KernelFactory() = default;
|
||||
|
||||
KernelFactory *KernelFactory::GetInstance() {
|
||||
static KernelFactory instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
LiteKernel *KernelFactory::GetKernel(const std::vector<tensor::Tensor *> &in_tensors,
|
||||
const std::vector<tensor::Tensor *> &out_tensors, const lite::Primitive *primitive,
|
||||
const Context *ctx, const kernel::KernelKey &key) {
|
||||
MS_EXCEPTION_IF_NULL(primitive);
|
||||
MS_EXCEPTION_IF_NULL(ctx);
|
||||
auto parameter = kernel::PopulateParameter(primitive);
|
||||
if (parameter == nullptr) {
|
||||
MS_LOG(ERROR) << "PopulateParameter return nullptr, type: " << schema::EnumNamePrimitiveType(primitive->Type());
|
||||
return nullptr;
|
||||
}
|
||||
auto creator = KernelRegistry::GetInstance()->GetCreator(key);
|
||||
if (creator != nullptr) {
|
||||
auto kernel = creator(in_tensors, out_tensors, parameter, ctx, key, primitive);
|
||||
return kernel;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace mindspore::lite
|
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_SRC_KERNEL_FACTORY_H_
|
||||
#define MINDSPORE_LITE_SRC_KERNEL_FACTORY_H_
|
||||
|
||||
#include <vector>
|
||||
#include "mindspore/lite/src/lite_kernel.h"
|
||||
#include "mindspore/lite/src/kernel_registry.h"
|
||||
#include "mindspore/lite/include/context.h"
|
||||
#include "mindspore/lite/src/ir/tensor.h"
|
||||
#include "schema/model_generated.h"
|
||||
|
||||
namespace mindspore::lite {
|
||||
class KernelFactory {
|
||||
public:
|
||||
KernelFactory();
|
||||
virtual ~KernelFactory();
|
||||
|
||||
static KernelFactory *GetInstance();
|
||||
kernel::LiteKernel *GetKernel(const std::vector<tensor::Tensor *> &in_tensors,
|
||||
const std::vector<tensor::Tensor *> &out_tensors, const lite::Primitive *primitive,
|
||||
const Context *ctx, const kernel::KernelKey &key);
|
||||
};
|
||||
} // namespace mindspore::lite
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_KERNEL_FACTORY_H_
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_SRC_MODEL_IMPL_H_
|
||||
#define MINDSPORE_LITE_SRC_MODEL_IMPL_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "schema/model_generated.h"
|
||||
#include "src/ops/ops.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class ModelImpl {
|
||||
public:
|
||||
static ModelImpl *Import(const char *model_buf, size_t size);
|
||||
ModelImpl() = default;
|
||||
explicit ModelImpl(const char *model_buf, size_t size) : model_buf_(model_buf), buf_size_(size) {
|
||||
meta_graph_ = schema::GetMetaGraph(model_buf);
|
||||
}
|
||||
virtual ~ModelImpl();
|
||||
lite::Primitive *GetOp(const std::string &name) const;
|
||||
const schema::MetaGraph *meta_graph() const;
|
||||
void FreeMetaGraph();
|
||||
int BuildOps();
|
||||
|
||||
protected:
|
||||
lite::Primitive *CopyPrimitive(const schema::Primitive *src_prim);
|
||||
|
||||
protected:
|
||||
const char *model_buf_;
|
||||
size_t buf_size_;
|
||||
const schema::MetaGraph *meta_graph_ = nullptr;
|
||||
std::map<std::string, lite::Primitive *> ops_;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_LITE_INCLUDE_MODEL_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue