!7708 [MSLITE][Develop] Refactor arithmetic populate and add eltwise int8 kernel
Merge pull request !7708 from sunsuodong/eltwise_int8pull/7708/MERGE
commit
ee1865605d
@ -1,46 +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/add.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/populate/populate_register.h"
|
||||
#include "nnacl/arithmetic_common.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
OpParameter *PopulateAddParameter(const mindspore::lite::PrimitiveC *primitive) {
|
||||
ArithmeticParameter *arithmetic_param = reinterpret_cast<ArithmeticParameter *>(malloc(sizeof(ArithmeticParameter)));
|
||||
if (arithmetic_param == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc ArithmeticParameter failed.";
|
||||
return nullptr;
|
||||
}
|
||||
memset(arithmetic_param, 0, sizeof(ArithmeticParameter));
|
||||
arithmetic_param->op_parameter_.type_ = primitive->Type();
|
||||
arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting();
|
||||
arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims();
|
||||
arithmetic_param->activation_type_ =
|
||||
reinterpret_cast<mindspore::lite::Add *>(const_cast<mindspore::lite::PrimitiveC *>(primitive))->GetActivationType();
|
||||
auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0();
|
||||
memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->InShape1();
|
||||
memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape();
|
||||
memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
return reinterpret_cast<OpParameter *>(arithmetic_param);
|
||||
}
|
||||
Registry AddParameterRegistry(schema::PrimitiveType_Add, PopulateAddParameter);
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -1,47 +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/div.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/populate/populate_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
||||
OpParameter *PopulateDivParameter(const mindspore::lite::PrimitiveC *primitive) {
|
||||
ArithmeticParameter *arithmetic_param = reinterpret_cast<ArithmeticParameter *>(malloc(sizeof(ArithmeticParameter)));
|
||||
if (arithmetic_param == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc ArithmeticParameter failed.";
|
||||
return nullptr;
|
||||
}
|
||||
memset(arithmetic_param, 0, sizeof(ArithmeticParameter));
|
||||
arithmetic_param->op_parameter_.type_ = primitive->Type();
|
||||
arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting();
|
||||
arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims();
|
||||
arithmetic_param->activation_type_ =
|
||||
reinterpret_cast<mindspore::lite::Div *>(const_cast<mindspore::lite::PrimitiveC *>(primitive))->GetActivationType();
|
||||
auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0();
|
||||
memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->InShape1();
|
||||
memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape();
|
||||
memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
return reinterpret_cast<OpParameter *>(arithmetic_param);
|
||||
}
|
||||
Registry DivParameterRegistry(schema::PrimitiveType_Div, PopulateDivParameter);
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -1,52 +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/eltwise.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/populate/populate_register.h"
|
||||
#include "nnacl/arithmetic_common.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
||||
OpParameter *PopulateEltwiseParameter(const mindspore::lite::PrimitiveC *primitive) {
|
||||
ArithmeticParameter *arithmetic_param = reinterpret_cast<ArithmeticParameter *>(malloc(sizeof(ArithmeticParameter)));
|
||||
if (arithmetic_param == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc ArithmeticParameter failed.";
|
||||
return nullptr;
|
||||
}
|
||||
memset(arithmetic_param, 0, sizeof(ArithmeticParameter));
|
||||
auto eltwise = reinterpret_cast<mindspore::lite::Eltwise *>(const_cast<mindspore::lite::PrimitiveC *>(primitive));
|
||||
switch (eltwise->GetMode()) {
|
||||
case schema::EltwiseMode_PROD:
|
||||
arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Mul;
|
||||
break;
|
||||
case schema::EltwiseMode_SUM:
|
||||
arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Add;
|
||||
break;
|
||||
case schema::EltwiseMode_MAXIMUM:
|
||||
arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Maximum;
|
||||
break;
|
||||
default:
|
||||
free(arithmetic_param);
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<OpParameter *>(arithmetic_param);
|
||||
}
|
||||
Registry EltwiseParameterRegistry(schema::PrimitiveType_Eltwise, PopulateEltwiseParameter);
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -1,48 +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/mul.h"
|
||||
#include "nnacl/arithmetic_common.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/populate/populate_register.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
||||
OpParameter *PopulateMulParameter(const mindspore::lite::PrimitiveC *primitive) {
|
||||
ArithmeticParameter *arithmetic_param = reinterpret_cast<ArithmeticParameter *>(malloc(sizeof(ArithmeticParameter)));
|
||||
if (arithmetic_param == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc ArithmeticParameter failed.";
|
||||
return nullptr;
|
||||
}
|
||||
memset(arithmetic_param, 0, sizeof(ArithmeticParameter));
|
||||
arithmetic_param->op_parameter_.type_ = primitive->Type();
|
||||
arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting();
|
||||
arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims();
|
||||
arithmetic_param->activation_type_ =
|
||||
reinterpret_cast<mindspore::lite::Mul *>(const_cast<mindspore::lite::PrimitiveC *>(primitive))->GetActivationType();
|
||||
auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0();
|
||||
memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->InShape1();
|
||||
memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape();
|
||||
memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
return reinterpret_cast<OpParameter *>(arithmetic_param);
|
||||
}
|
||||
Registry MulParameterRegistry(schema::PrimitiveType_Mul, PopulateMulParameter);
|
||||
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -1,47 +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/sub.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/populate/populate_register.h"
|
||||
#include "nnacl/arithmetic_common.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
||||
OpParameter *PopulateSubParameter(const mindspore::lite::PrimitiveC *primitive) {
|
||||
ArithmeticParameter *arithmetic_param = reinterpret_cast<ArithmeticParameter *>(malloc(sizeof(ArithmeticParameter)));
|
||||
if (arithmetic_param == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc ArithmeticParameter failed.";
|
||||
return nullptr;
|
||||
}
|
||||
memset(arithmetic_param, 0, sizeof(ArithmeticParameter));
|
||||
arithmetic_param->op_parameter_.type_ = primitive->Type();
|
||||
arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting();
|
||||
arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims();
|
||||
arithmetic_param->activation_type_ =
|
||||
reinterpret_cast<mindspore::lite::Sub *>(const_cast<mindspore::lite::PrimitiveC *>(primitive))->GetActivationType();
|
||||
auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0();
|
||||
memcpy(arithmetic_param->in_shape0_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->InShape1();
|
||||
memcpy(arithmetic_param->in_shape1_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape();
|
||||
memcpy(arithmetic_param->out_shape_, static_cast<void *>(tmp_shape.data()), tmp_shape.size() * sizeof(int));
|
||||
return reinterpret_cast<OpParameter *>(arithmetic_param);
|
||||
}
|
||||
Registry SubParameterRegistry(schema::PrimitiveType_Sub, PopulateSubParameter);
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
Loading…
Reference in new issue