!3824 Changing folders for several operators
Merge pull request !3824 from zhangzheng/masterpull/3824/MERGE
commit
0082c0e5df
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 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/runtime/kernel/arm/base/caffeprelu_base.h"
|
||||
#include <vector>
|
||||
#include "schema/model_generated.h"
|
||||
#include "src/kernel_factory.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "include/context.h"
|
||||
|
||||
using mindspore::lite::KernelRegistrar;
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
using mindspore::schema::PrimitiveType_CaffePReLU;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
int CaffePreluBaseCPUKernel::Init() { return RET_OK; }
|
||||
|
||||
kernel::LiteKernel *CpuCaffePreluFp32KernelCreator(const std::vector<lite::tensor::Tensor *> &inputs,
|
||||
const std::vector<lite::tensor::Tensor *> &outputs,
|
||||
OpParameter *opParameter, const Context *ctx,
|
||||
const kernel::KernelKey &desc, const lite::Primitive *primitive) {
|
||||
if (opParameter == nullptr) {
|
||||
MS_LOG(ERROR) << "Input opParameter is nullptr!";
|
||||
return nullptr;
|
||||
}
|
||||
MS_ASSERT(desc.type == schema::PrimitiveType_CaffePrelu);
|
||||
auto *kernel = new (std::nothrow) CaffePreluBaseCPUKernel(opParameter, inputs, outputs, ctx, primitive);
|
||||
if (kernel == nullptr) {
|
||||
MS_LOG(ERROR) << "new PreluCPUKernel fail!";
|
||||
return nullptr;
|
||||
}
|
||||
auto ret = kernel->Init();
|
||||
if (ret != RET_OK) {
|
||||
delete kernel;
|
||||
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
|
||||
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
|
||||
return nullptr;
|
||||
}
|
||||
return kernel;
|
||||
}
|
||||
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_CaffePReLU, CpuCaffePreluFp32KernelCreator)
|
||||
} // namespace mindspore::kernel
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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_RUNTIME_KERNEL_ARM_BASE_CAFFEPRELU_BASE_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CAFFEPRELU_BASE_H_
|
||||
|
||||
#include <vector>
|
||||
#include "src/lite_kernel.h"
|
||||
#include "src/runtime/kernel/arm/nnacl/caffeprelu_parameter.h"
|
||||
#include "src/runtime/kernel/arm/base/layout_transform.h"
|
||||
|
||||
using mindspore::lite::Context;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
class CaffePreluBaseCPUKernel : public LiteKernel {
|
||||
public:
|
||||
CaffePreluBaseCPUKernel(OpParameter *parameter, const std::vector<lite::tensor::Tensor *> &inputs,
|
||||
const std::vector<lite::tensor::Tensor *> &outputs, const Context *ctx,
|
||||
const lite::Primitive *primitive)
|
||||
: LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {
|
||||
prelu_param_ = reinterpret_cast<CaffePreluParameter *>(parameter);
|
||||
}
|
||||
|
||||
~CaffePreluBaseCPUKernel() = default;
|
||||
|
||||
int Init() override;
|
||||
|
||||
int ReSize() override { return 0; }
|
||||
|
||||
int Run() override { return 0; }
|
||||
|
||||
protected:
|
||||
int thread_count_;
|
||||
const Context *ctx_;
|
||||
CaffePreluParameter *prelu_param_;
|
||||
};
|
||||
} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CAFFEPRELU_BASE_H_
|
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 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/runtime/kernel/arm/fp32/caffeprelu.h"
|
||||
#include <vector>
|
||||
#include "schema/model_generated.h"
|
||||
#include "src/runtime/kernel/arm/nnacl/caffeprelu.h"
|
||||
#include "src/kernel_registry.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "src/runtime/runtime_api.h"
|
||||
|
||||
using mindspore::kernel::KERNEL_ARCH::kCPU;
|
||||
using mindspore::lite::KernelRegistrar;
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
using mindspore::schema::PrimitiveType_CaffePReLU;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
int CaffePReluCPUKernel::Init() { return RET_OK; }
|
||||
|
||||
int CaffePReluCPUKernel::DoExcute(int task_id) {
|
||||
PRelu(input_data, output_data, prelu_param_, task_id);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CaffePReluRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) {
|
||||
auto PReludata = reinterpret_cast<CaffePReluCPUKernel *>(cdata);
|
||||
auto ret = PReludata->DoExcute(task_id);
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "PReluRun error task_id[" << task_id << "] error_code[" << ret << "]";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CaffePReluCPUKernel::Run() {
|
||||
auto prepare_ret = Prepare();
|
||||
if (prepare_ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret;
|
||||
return prepare_ret;
|
||||
}
|
||||
auto input = inputs_.at(0);
|
||||
auto input1 = inputs_.at(1);
|
||||
|
||||
prelu_param_->input_num_ = input->ElementsNum();
|
||||
input_data = reinterpret_cast<float *>(input->Data());
|
||||
output_data = reinterpret_cast<float *>(outputs_.at(0)->Data());
|
||||
auto channels = input->shape();
|
||||
prelu_param_->negtive_slope_ = reinterpret_cast<float *>(input1->Data());
|
||||
prelu_param_->channel_num_ = channels.at(channels.size() - 1);
|
||||
|
||||
auto ret = LiteBackendParallelLaunch(CaffePReluRun, this, prelu_param_->op_parameter_.thread_num_);
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "PReluDwRun error: error_code[" << ret << "]";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
kernel::LiteKernel *CpuCaffePReluFp32KernelCreator(const std::vector<lite::tensor::Tensor *> &inputs,
|
||||
const std::vector<lite::tensor::Tensor *> &outputs,
|
||||
OpParameter *opParameter, const lite::Context *ctx,
|
||||
const kernel::KernelKey &desc, const lite::Primitive *primitive) {
|
||||
if (opParameter == nullptr) {
|
||||
MS_LOG(ERROR) << "input opParameter is nullptr!";
|
||||
return nullptr;
|
||||
}
|
||||
MS_ASSERT(desc.type == schema::PrimitiveType_Prelu);
|
||||
auto *kernel = new (std::nothrow) CaffePReluCPUKernel(opParameter, inputs, outputs, ctx, primitive);
|
||||
if (kernel == nullptr) {
|
||||
MS_LOG(ERROR) << "new PReluCPUKernel fail!";
|
||||
return nullptr;
|
||||
}
|
||||
auto ret = kernel->Init();
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
|
||||
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
|
||||
delete kernel;
|
||||
return nullptr;
|
||||
}
|
||||
return kernel;
|
||||
}
|
||||
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_CaffePReLU, CpuCaffePReluFp32KernelCreator)
|
||||
} // namespace mindspore::kernel
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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_RUNTIME_KERNEL_ARM_FP32_CAFFEPRELU_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CAFFEPRELU_H_
|
||||
|
||||
#include <vector>
|
||||
#include "src/lite_kernel.h"
|
||||
|
||||
#include "include/context.h"
|
||||
#include "src/runtime/kernel/arm/nnacl/caffeprelu.h"
|
||||
#include "src/runtime/kernel/arm/base/layout_transform.h"
|
||||
|
||||
using mindspore::lite::Context;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
class CaffePReluCPUKernel : public LiteKernel {
|
||||
public:
|
||||
CaffePReluCPUKernel(OpParameter *parameter, const std::vector<lite::tensor::Tensor *> &inputs,
|
||||
const std::vector<lite::tensor::Tensor *> &outputs, const lite::Context *ctx,
|
||||
const lite::Primitive *primitive)
|
||||
: LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {
|
||||
prelu_param_ = (reinterpret_cast<CaffePReluParameter *>(opParameter));
|
||||
primitive_ = primitive;
|
||||
}
|
||||
~CaffePReluCPUKernel() = default;
|
||||
|
||||
int Init() override;
|
||||
int ReSize() override { return 0; }
|
||||
int Run() override;
|
||||
int DoExcute(int task_id);
|
||||
|
||||
protected:
|
||||
int thread_count_;
|
||||
const Context *ctx_;
|
||||
CaffePReluParameter *prelu_param_;
|
||||
|
||||
private:
|
||||
float *input_data;
|
||||
float *output_data;
|
||||
};
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CAFFEPRELU_H_
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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/runtime/kernel/arm/nnacl/caffeprelu.h"
|
||||
|
||||
void PRelu(float *input, float *output, CaffePReluParameter *prelu_param_, int task_id) {
|
||||
int block = int(prelu_param_->input_num_ / prelu_param_->op_parameter_.thread_num_);
|
||||
int start = task_id * block;
|
||||
int end = start + block;
|
||||
if (task_id == prelu_param_->op_parameter_.thread_num_ - 1) {
|
||||
end = prelu_param_->input_num_;
|
||||
}
|
||||
for (int i = start; i < end; i++) {
|
||||
if (input[i] > 0) {
|
||||
output[i] = input[i];
|
||||
} else {
|
||||
if (prelu_param_->channeShared) {
|
||||
int temp = i % prelu_param_->channel_num_;
|
||||
output[i] = input[i] * prelu_param_->negtive_slope_[temp];
|
||||
} else {
|
||||
output[i] = input[i] * prelu_param_->negtive_slope_[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_H_
|
||||
|
||||
#include "src/runtime/kernel/arm/nnacl/op_base.h"
|
||||
|
||||
struct CaffePReluParameter {
|
||||
OpParameter op_parameter_;
|
||||
float *negtive_slope_;
|
||||
bool channeShared;
|
||||
int channel_num_;
|
||||
int input_num_;
|
||||
int thread_num_;
|
||||
};
|
||||
|
||||
void PRelu(float *input, float *output, CaffePReluParameter *prelu_param_, int task_id);
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_H_
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_PARAMETER_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_PARAMETER_H_
|
||||
|
||||
#include "src/runtime/kernel/arm/nnacl/op_base.h"
|
||||
#define CAFFEPRELU_OFFSET_MAX_SIZE 4
|
||||
|
||||
struct CaffePreluParameter {
|
||||
OpParameter op_parameter_;
|
||||
bool channelShared;
|
||||
double alpha_;
|
||||
int64_t offset_[CAFFEPRELU_OFFSET_MAX_SIZE];
|
||||
int64_t in_offset_[CAFFEPRELU_OFFSET_MAX_SIZE];
|
||||
int64_t axis_;
|
||||
const int *in_shape_;
|
||||
const int *out_shape_;
|
||||
int input_dim_;
|
||||
};
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CAFFEPRELU_PARAMETER_H_
|
Loading…
Reference in new issue