MNN/source/backend/cpu/CPUFill.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// CPUFill.cpp
// MNN
//
// Created by MNN on 2018/08/22.
// Copyright © 2018, Alibaba Group Holding Limited
//
2019-12-27 22:16:57 +08:00
#include "backend/cpu/CPUFill.hpp"
#include "backend/cpu/CPUBackend.hpp"
#include "core/Macro.h"
2019-04-17 10:49:11 +08:00
namespace MNN {
CPUFill::CPUFill(Backend *backend) : Execution(backend) {
2019-04-17 10:49:11 +08:00
// nothing to do
}
ErrorCode CPUFill::onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) {
int bytes = outputs[0]->getType().bytes();
int size = outputs[0]->elementSize();
uint8_t *value = inputs[1]->host<uint8_t>();
uint8_t *buffer = outputs[0]->host<uint8_t>();
for (int i = 0; i < size; ++i, buffer += bytes) {
memcpy(buffer, value, bytes);
2019-04-17 10:49:11 +08:00
}
2019-12-27 22:16:57 +08:00
2019-04-17 10:49:11 +08:00
return NO_ERROR;
}
class CPUFillCreator : public CPUBackend::Creator {
public:
virtual Execution *onCreate(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs,
const MNN::Op *op, Backend *backend) const {
return new CPUFill(backend);
2019-04-17 10:49:11 +08:00
}
};
REGISTER_CPU_OP_CREATOR(CPUFillCreator, OpType_Fill);
} // namespace MNN