parent
9ab4f1237b
commit
2809ee63bd
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019-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 "src/ops/return.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace lite {
|
||||||
|
#ifdef PRIMITIVE_WRITEABLE
|
||||||
|
int Return::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inputs) {
|
||||||
|
if (this->primitive_ == nullptr) {
|
||||||
|
this->primitive_ = new (std::nothrow) schema::PrimitiveT;
|
||||||
|
if (this->primitive_ == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "new primitiveT failed";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
this->primitive_->value.type = schema::PrimitiveType_Return;
|
||||||
|
}
|
||||||
|
if (this->primitive_->value.type != schema::PrimitiveType_Return) {
|
||||||
|
MS_LOG(ERROR) << "Primitive type is error :" << this->primitive_->value.type;
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
if (this->primitive_->value.value == nullptr) {
|
||||||
|
auto attr = new (std::nothrow) schema::ReturnT();
|
||||||
|
if (attr == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "new primitiveT value failed";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
this->primitive_->value.value = attr;
|
||||||
|
if (this->primitive_->value.value == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "primitive value is nullptr";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr size_t kInputSize = 1;
|
||||||
|
constexpr size_t kOutputSize = 1;
|
||||||
|
} // namespace
|
||||||
|
int Return::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor::Tensor *> outputs_) {
|
||||||
|
if (inputs_.size() != kInputSize || outputs_.size() != kOutputSize) {
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
auto input = inputs_.front();
|
||||||
|
auto output = outputs_.front();
|
||||||
|
if (input == nullptr || output == nullptr) {
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
output->set_data_type(input->data_type());
|
||||||
|
output->SetFormat(input->GetFormat());
|
||||||
|
if (!GetInferFlag()) {
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
if (this->primitive_ == nullptr) {
|
||||||
|
return RET_NULL_PTR;
|
||||||
|
}
|
||||||
|
output->set_data_type(input->data_type());
|
||||||
|
output->set_shape(input->shape());
|
||||||
|
output->SetFormat(input->GetFormat());
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
} // namespace lite
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019-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 LITE_MINDSPORE_LITE_C_OPS_RETURN_H_
|
||||||
|
#define LITE_MINDSPORE_LITE_C_OPS_RETURN_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <cmath>
|
||||||
|
#include "ir/dtype/type_id.h"
|
||||||
|
#include "src/ops/primitive_c.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace lite {
|
||||||
|
class Return : public PrimitiveC {
|
||||||
|
public:
|
||||||
|
#ifdef PRIMITIVE_WRITEABLE
|
||||||
|
MS_DECLARE_PARENT(Return, PrimitiveC);
|
||||||
|
Return() = default;
|
||||||
|
explicit Return(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {}
|
||||||
|
int UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inputs);
|
||||||
|
#else
|
||||||
|
explicit Return(schema::Primitive *primitive) : PrimitiveC(primitive) {}
|
||||||
|
#endif
|
||||||
|
int InferShape(std::vector<lite::tensor::Tensor *> inputs_, std::vector<lite::tensor::Tensor *> outputs_) override;
|
||||||
|
};
|
||||||
|
} // namespace lite
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // LITE_MINDSPORE_LITE_C_OPS_RETURN_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue