From 576664d2323ececbc754e98ecff3f95c736a1bf2 Mon Sep 17 00:00:00 2001 From: ling Date: Fri, 25 Dec 2020 09:47:56 +0800 Subject: [PATCH] [MSLITE] delete useless op gelu & matris diag --- mindspore/lite/src/ops/gelu.cc | 42 ------------ mindspore/lite/src/ops/gelu.h | 45 ------------- mindspore/lite/src/ops/matrix_diag.cc | 66 ------------------- mindspore/lite/src/ops/matrix_diag.h | 50 -------------- .../lite/src/ops/populate/gelu_populate.cc | 40 ----------- 5 files changed, 243 deletions(-) delete mode 100644 mindspore/lite/src/ops/gelu.cc delete mode 100644 mindspore/lite/src/ops/gelu.h delete mode 100644 mindspore/lite/src/ops/matrix_diag.cc delete mode 100644 mindspore/lite/src/ops/matrix_diag.h delete mode 100644 mindspore/lite/src/ops/populate/gelu_populate.cc diff --git a/mindspore/lite/src/ops/gelu.cc b/mindspore/lite/src/ops/gelu.cc deleted file mode 100644 index 14e9fdfc3d..0000000000 --- a/mindspore/lite/src/ops/gelu.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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/gelu.h" -#include -#include "include/errorcode.h" -#include "src/common/log_adapter.h" -#include "src/tensor.h" -#ifndef PRIMITIVE_WRITEABLE -#include "src/ops/ops_register.h" -#endif - -namespace mindspore { -namespace lite { -#ifdef PRIMITIVE_WRITEABLE -// int GeLU::GetApproximate() const { return this->primitive_->value.AsGeLU()->approximate; } - -// void GeLU::SetApproximate(bool approximate) { this->primitive_->value.AsGeLU()->approximate = approximate; } - -#else -// int GeLU::GetApproximate() const { return this->primitive_->value_as_GeLU()->approximate(); } - -// PrimitiveC *GeLUCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } -// Registry GeLURegistry(schema::PrimitiveType_GeLU, GeLUCreator); - -#endif - -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/src/ops/gelu.h b/mindspore/lite/src/ops/gelu.h deleted file mode 100644 index 27721fc744..0000000000 --- a/mindspore/lite/src/ops/gelu.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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_GELU_H_ -#define LITE_MINDSPORE_LITE_C_OPS_GELU_H_ - -#include -#include -#include -#include "src/ops/primitive_c.h" - -namespace mindspore { -namespace lite { -class GeLU : public PrimitiveC { - public: - GeLU() = default; - ~GeLU() = default; -#ifdef PRIMITIVE_WRITEABLE - MS_DECLARE_PARENT(GeLU, PrimitiveC); - explicit GeLU(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} -// int UnPackAttr(const Primitive &prim, const std::vector &inputs) override; -// void SetApproximate(bool approximate); -#else -// int UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) override; -#endif - int InferShape(std::vector inputs_, std::vector outputs_) override; - // bool GetApproximate() const; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_MINDSPORE_LITE_C_OPS_GELU_H_ diff --git a/mindspore/lite/src/ops/matrix_diag.cc b/mindspore/lite/src/ops/matrix_diag.cc deleted file mode 100644 index f078287452..0000000000 --- a/mindspore/lite/src/ops/matrix_diag.cc +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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/matrix_diag.h" - -#ifndef PRIMITIVE_WRITEABLE -#include "src/ops/ops_register.h" -#endif - -namespace mindspore { -namespace lite { -#ifdef PRIMITIVE_WRITEABLE -int MatrixDiag::GetK() const { return this->primitive_->value.AsMatrixDiag()->k; } -int MatrixDiag::GetNumRows() const { return this->primitive_->value.AsMatrixDiag()->numRows; } -int MatrixDiag::GetNumCols() const { return this->primitive_->value.AsMatrixDiag()->numCols; } -float MatrixDiag::GetPaddingValue() const { return this->primitive_->value.AsMatrixDiag()->paddingValue; } - -void MatrixDiag::SetK(int k) { this->primitive_->value.AsMatrixDiag()->k = k; } -void MatrixDiag::SetNumRows(int num_rows) { this->primitive_->value.AsMatrixDiag()->numRows = num_rows; } -void MatrixDiag::SetNumCols(int num_cols) { this->primitive_->value.AsMatrixDiag()->numCols = num_cols; } -void MatrixDiag::SetPaddingValue(float padding_value) { - this->primitive_->value.AsMatrixDiag()->paddingValue = padding_value; -} - -#else - -int MatrixDiag::GetK() const { return this->primitive_->value_as_MatrixDiag()->k(); } -int MatrixDiag::GetNumRows() const { return this->primitive_->value_as_MatrixDiag()->numRows(); } -int MatrixDiag::GetNumCols() const { return this->primitive_->value_as_MatrixDiag()->numCols(); } -float MatrixDiag::GetPaddingValue() const { return this->primitive_->value_as_MatrixDiag()->paddingValue(); } - -int MatrixDiag::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) { - MS_ASSERT(nullptr != primitive); - MS_ASSERT(nullptr != fbb); - auto attr = primitive->value_as_MatrixDiag(); - if (attr == nullptr) { - MS_LOG(ERROR) << "value_as_MatrixDiag return nullptr"; - return RET_ERROR; - } - auto val_offset = schema::CreateMatrixDiag(*fbb, attr->k(), attr->numRows(), attr->numCols(), attr->paddingValue()); - auto prim_offset = schema::CreatePrimitive(*fbb, schema::PrimitiveType_MatrixDiag, val_offset.o); - fbb->Finish(prim_offset); - return RET_OK; -} - -PrimitiveC *MatrixDiagCreator(const schema::Primitive *primitive) { - return PrimitiveC::NewPrimitiveC(primitive); -} -Registry MatrixDiagRegistry(schema::PrimitiveType_MatrixDiag, MatrixDiagCreator); - -#endif -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/src/ops/matrix_diag.h b/mindspore/lite/src/ops/matrix_diag.h deleted file mode 100644 index 7e5cd52ae0..0000000000 --- a/mindspore/lite/src/ops/matrix_diag.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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_MATRIX_DIAG_H_ -#define LITE_MINDSPORE_LITE_C_OPS_MATRIX_DIAG_H_ - -#include -#include -#include - -#include "src/ops/primitive_c.h" - -namespace mindspore { -namespace lite { -class MatrixDiag : public PrimitiveC { - public: - MatrixDiag() = default; - ~MatrixDiag() = default; -#ifdef PRIMITIVE_WRITEABLE - MS_DECLARE_PARENT(MatrixDiag, PrimitiveC); - explicit MatrixDiag(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} - void SetK(int k); - void SetNumRows(int num_rows); - void SetNumCols(int num_cols); - void SetPaddingValue(float padding_value); -#else - int UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) override; -#endif - int GetK() const; - int GetNumRows() const; - int GetNumCols() const; - float GetPaddingValue() const; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_MINDSPORE_LITE_C_OPS_MATRIX_DIAG_H_ diff --git a/mindspore/lite/src/ops/populate/gelu_populate.cc b/mindspore/lite/src/ops/populate/gelu_populate.cc deleted file mode 100644 index 320a231884..0000000000 --- a/mindspore/lite/src/ops/populate/gelu_populate.cc +++ /dev/null @@ -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. - */ - -#include "src/ops/primitive_c.h" -#include "src/ops/populate/populate_register.h" -#include "src/ops/gelu.h" -#include "nnacl/gelu_parameter.h" - -namespace mindspore { -namespace lite { -OpParameter *PopulateGeLUParameter(const mindspore::lite::PrimitiveC *primitive) { - // const auto param = reinterpret_cast(const_cast(primitive)); - GeLUParameter *gelu_param = reinterpret_cast(malloc(sizeof(GeLUParameter))); - if (gelu_param == nullptr) { - MS_LOG(ERROR) << "malloc GeLUParameter failed."; - return nullptr; - } - memset(gelu_param, 0, sizeof(GeLUParameter)); - gelu_param->op_parameter_.type_ = primitive->Type(); - // gelu_param->approximate_ = param->GetApproximate(); - return reinterpret_cast(gelu_param); -} - -// Registry GeLUParameterRegistry(schema::PrimitiveType_GeLU, PopulateGeLUParameter); -} // namespace lite -} // namespace mindspore