!13343 fix mobilenetv2 compile issue
From: @zhujingxuan Reviewed-by: @wangchengyuan,@hangangqiang Signed-off-by: @wangchengyuanpull/13343/MERGE
commit
e71b601e65
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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 "coder/opcoders/base/reshape_base_coder.h"
|
||||
#include <vector>
|
||||
#include "coder/opcoders/op_coder.h"
|
||||
#include "coder/opcoders/serializers/serializer.h"
|
||||
#include "include/errorcode.h"
|
||||
|
||||
using mindspore::schema::PrimitiveType_ExpandDims;
|
||||
using mindspore::schema::PrimitiveType_Flatten;
|
||||
using mindspore::schema::PrimitiveType_FlattenGrad;
|
||||
using mindspore::schema::PrimitiveType_Reshape;
|
||||
using mindspore::schema::PrimitiveType_Squeeze;
|
||||
using mindspore::schema::PrimitiveType_Unsqueeze;
|
||||
|
||||
namespace mindspore::lite::micro {
|
||||
|
||||
int ReshapeBaseCoder::Prepare(CoderContext *const context) {
|
||||
bool is_next_conv = std::any_of(output_ops().begin(), output_ops().end(), [](OperatorCoder *next_op) {
|
||||
return next_op->type() == schema::PrimitiveType_Conv2DFusion;
|
||||
});
|
||||
if (is_next_conv && output_tensor_->shape().size() == 4 && output_tensor_->format() == schema::Format::Format_NCHW) {
|
||||
output_tensor_->set_format(schema::Format::Format_NHWC);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int ReshapeBaseCoder::DoCode(CoderContext *const context) {
|
||||
Serializer coder;
|
||||
|
||||
size_t size = input_tensor_->Size();
|
||||
coder.CodeFunction("memcpy", output_tensor_, input_tensor_, size);
|
||||
|
||||
context->AppendCode(coder.str());
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Reshape, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_Reshape, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Flatten, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_Flatten, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_ExpandDims, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_ExpandDims, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Squeeze, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_Squeeze, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Unsqueeze, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_Unsqueeze, CPUOpCoderCreator<ReshapeBaseCoder>)
|
||||
|
||||
} // namespace mindspore::lite::micro
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* 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 "coder/opcoders/nnacl/fp32/expand_dims_fp32_coder.h"
|
||||
#include <string>
|
||||
#include "coder/opcoders/file_collector.h"
|
||||
#include "coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h"
|
||||
|
||||
using mindspore::schema::PrimitiveType_ExpandDims;
|
||||
|
||||
namespace mindspore::lite::micro::nnacl {
|
||||
int ExpandDimsFP32Coder::Prepare(CoderContext *const context) { return ReSize(); }
|
||||
|
||||
int ExpandDimsFP32Coder::ReSize() {
|
||||
data_size_ = input_tensor_->ElementsNum();
|
||||
thread_sz_count_ = MSMIN(thread_num_, static_cast<int>(data_size_));
|
||||
MS_CHECK_TRUE(thread_sz_count_ > 0, "thread_sz_count_ is less or equal to 0");
|
||||
thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int ExpandDimsFP32Coder::DoCode(CoderContext *const context) {
|
||||
// generate code .h .c
|
||||
Collect(context, {"nnacl/fp32/expandDims.h"}, {"nnacl/fp32/expandDims.c"});
|
||||
NNaclFp32Serializer code;
|
||||
int task_id = 0;
|
||||
size_t size = MSMIN(thread_sz_stride_, static_cast<int>(data_size_ - task_id * thread_sz_stride_));
|
||||
if (!size) {
|
||||
return RET_OK;
|
||||
}
|
||||
code.CodeFunction("ExpandDims", input_tensor_, output_tensor_, size * sizeof(float));
|
||||
context->AppendCode(code.str());
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_ExpandDims, CPUOpCoderCreator<ExpandDimsFP32Coder>)
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_ExpandDims, CPUOpCoderCreator<ExpandDimsFP32Coder>)
|
||||
} // namespace mindspore::lite::micro::nnacl
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* 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_MICRO_CODER_OPCODERS_NNACL_EXPANDDIMS_FP32_CODER_H_
|
||||
#define MINDSPORE_LITE_MICRO_CODER_OPCODERS_NNACL_EXPANDDIMS_FP32_CODER_H_
|
||||
|
||||
#include <vector>
|
||||
#include "coder/opcoders/op_coder.h"
|
||||
|
||||
namespace mindspore::lite::micro::nnacl {
|
||||
class ExpandDimsFP32Coder final : public OperatorCoder {
|
||||
public:
|
||||
ExpandDimsFP32Coder(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
|
||||
const Model::Node *node, size_t node_index, Target target)
|
||||
: OperatorCoder(in_tensors, out_tensors, node, node_index, target) {}
|
||||
|
||||
~ExpandDimsFP32Coder() override = default;
|
||||
int Prepare(CoderContext *const context) override;
|
||||
|
||||
int DoCode(CoderContext *const context) override;
|
||||
|
||||
private:
|
||||
int ReSize();
|
||||
int thread_sz_count_{0};
|
||||
int thread_sz_stride_{0};
|
||||
size_t data_size_{0};
|
||||
};
|
||||
} // namespace mindspore::lite::micro::nnacl
|
||||
#endif // MINDSPORE_LITE_MICRO_CODER_OPCODERS_NNACL_EXPANDDIMS_FP32_CODER_H_
|
@ -1,39 +0,0 @@
|
||||
/**
|
||||
* 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 "coder/opcoders/nnacl/fp32/reshape_fp32_coder.h"
|
||||
#include <string>
|
||||
#include "coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h"
|
||||
#include "coder/opcoders/file_collector.h"
|
||||
|
||||
using mindspore::schema::PrimitiveType_Reshape;
|
||||
namespace mindspore::lite::micro::nnacl {
|
||||
|
||||
int ReshapeFP32Coder::DoCode(CoderContext *const context) {
|
||||
size_t data_size = input_tensor_->Size();
|
||||
|
||||
Collect(context, {"nnacl/reshape.h"}, {"reshape.c"});
|
||||
|
||||
NNaclFp32Serializer code;
|
||||
code.CodeFunction("Reshape", input_tensor_, output_tensor_, data_size);
|
||||
context->AppendCode(code.str());
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Reshape, CPUOpCoderCreator<ReshapeFP32Coder>)
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeInt32, PrimitiveType_Reshape, CPUOpCoderCreator<ReshapeFP32Coder>)
|
||||
} // namespace mindspore::lite::micro::nnacl
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* 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_MICRO_CODER_OPCODERS_NNACL_RESHAPE_FP32_CODER_H_
|
||||
#define MINDSPORE_LITE_MICRO_CODER_OPCODERS_NNACL_RESHAPE_FP32_CODER_H_
|
||||
|
||||
#include <vector>
|
||||
#include "coder/opcoders/op_coder.h"
|
||||
|
||||
namespace mindspore::lite::micro::nnacl {
|
||||
class ReshapeFP32Coder final : public OperatorCoder {
|
||||
public:
|
||||
ReshapeFP32Coder(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
|
||||
const Model::Node *node, size_t node_index, Target target)
|
||||
: OperatorCoder(in_tensors, out_tensors, node, node_index, target) {}
|
||||
~ReshapeFP32Coder() override = default;
|
||||
int Prepare(CoderContext *const context) override { return RET_OK; }
|
||||
|
||||
int DoCode(CoderContext *const context) override;
|
||||
};
|
||||
} // namespace mindspore::lite::micro::nnacl
|
||||
#endif // MINDSPORE_LITE_MICRO_CODER_OPCODERS_NNACL_RESHAPE_FP32_CODER_H_
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* 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 "coder/opcoders/nnacl/fp32/squeeze_dims_fp32_coder.h"
|
||||
#include <string>
|
||||
#include "coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h"
|
||||
#include "coder/opcoders/file_collector.h"
|
||||
|
||||
using mindspore::schema::PrimitiveType_Squeeze;
|
||||
|
||||
namespace mindspore::lite::micro::nnacl {
|
||||
|
||||
int SqueezeFP32Coder::DoCode(CoderContext *const context) {
|
||||
size_t data_size = input_tensor_->Size();
|
||||
// generate code .h .c
|
||||
Collect(context, {"nnacl/squeeze.h"}, {"nnacl/squeeze.c"});
|
||||
|
||||
NNaclFp32Serializer code;
|
||||
|
||||
// call the op function
|
||||
if (input_tensor_->data_type() == kNumberTypeInt32) {
|
||||
code.CodeFunction("DoSqueezeInt32", input_tensor_, output_tensor_, data_size);
|
||||
} else {
|
||||
code.CodeFunction("DoSqueeze", input_tensor_, output_tensor_, data_size);
|
||||
}
|
||||
context->AppendCode(code.str());
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REG_OPERATOR_CODER(kAllTargets, kNumberTypeFloat32, PrimitiveType_Squeeze, CPUOpCoderCreator<SqueezeFP32Coder>)
|
||||
|
||||
} // namespace mindspore::lite::micro::nnacl
|
Loading…
Reference in new issue