2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// CPUScale.cpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2018/08/07.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "CPUScale.hpp"
|
|
|
|
#include "CPUBackend.hpp"
|
|
|
|
#include "CommonOptFunction.h"
|
|
|
|
#include "Macro.h"
|
|
|
|
#include "TensorUtils.hpp"
|
|
|
|
|
|
|
|
namespace MNN {
|
|
|
|
CPUScale::CPUScale(const Op* op, Backend* bn) : MNN::Execution(bn) {
|
|
|
|
auto scale = op->main_as_Scale();
|
|
|
|
int outputCount = scale->scaleData()->size();
|
|
|
|
mScale.reset(ALIGN_UP4(outputCount));
|
|
|
|
mScale.clear();
|
|
|
|
::memcpy(mScale.get(), scale->scaleData()->data(), outputCount * sizeof(float));
|
|
|
|
|
|
|
|
mBias.reset(ALIGN_UP4(outputCount));
|
|
|
|
mBias.clear();
|
|
|
|
if (nullptr != scale->biasData() && nullptr != scale->biasData()->data()) {
|
|
|
|
::memcpy(mBias.get(), scale->biasData()->data(), outputCount * sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ErrorCode CPUScale::onExecute(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs) {
|
|
|
|
auto input = inputs[0];
|
|
|
|
auto output = outputs[0];
|
|
|
|
if (TensorUtils::getDescribe(input)->dimensionFormat == MNN_DATA_FORMAT_NC4HW4) {
|
|
|
|
auto batchSize = input->buffer().dim[0].stride;
|
|
|
|
auto batch = input->buffer().dim[0].extent;
|
|
|
|
auto depthQuad = UP_DIV(input->channel(), 4);
|
- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
int planeNumber = 1;
|
|
|
|
for (int i = 2; i < input->buffer().dimensions; ++i) {
|
|
|
|
planeNumber *= input->length(i);
|
|
|
|
}
|
2019-04-17 10:49:11 +08:00
|
|
|
for (int i = 0; i < batch; ++i) {
|
|
|
|
MNNScaleAndAddBias(output->host<float>() + batchSize * i, input->host<float>() + batchSize * i, mBias.get(),
|
|
|
|
mScale.get(), planeNumber, depthQuad);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
MNN_ASSERT(TensorUtils::getDescribe(input)->dimensionFormat == MNN_DATA_FORMAT_NHWC);
|
|
|
|
|
2019-05-05 20:27:57 +08:00
|
|
|
auto channel = input->channel();
|
2019-04-17 10:49:11 +08:00
|
|
|
auto outside = input->elementSize() / channel;
|
|
|
|
MNNScaleAndAddBiasOutside(output->host<float>(), input->host<float>(), mBias.get(), mScale.get(), outside, channel);
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
class CPUScaleCreator : public CPUBackend::Creator {
|
|
|
|
public:
|
|
|
|
virtual Execution* onCreate(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
|
|
|
|
const MNN::Op* op, Backend* backend) const override {
|
|
|
|
return new CPUScale(op, backend);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_CPU_OP_CREATOR(CPUScaleCreator, OpType_Scale);
|
|
|
|
} // namespace MNN
|