提交 6392835f 编写于 作者: Y yejianwu

format code, fix fill input type, update op list docs

上级 e2e0a7f3
...@@ -12,7 +12,7 @@ Operator lists ...@@ -12,7 +12,7 @@ Operator lists
"BIAS_ADD","Y","" "BIAS_ADD","Y",""
"CAST","Y","Only CPU and TensorFlow model is supported." "CAST","Y","Only CPU and TensorFlow model is supported."
"CHANNEL_SHUFFLE","Y","" "CHANNEL_SHUFFLE","Y",""
"CONCATENATION","Y","Only support channel axis concatenation." "CONCATENATION","Y","For GPU only support channel axis concatenation."
"CONV_2D","Y","Fusion with BN and activation layer is supported." "CONV_2D","Y","Fusion with BN and activation layer is supported."
"CROP","Y","Only Caffe's crop layer is supported (in GPU, offset on channel-dim should be dividable by 4)." "CROP","Y","Only Caffe's crop layer is supported (in GPU, offset on channel-dim should be dividable by 4)."
"DECONV_2D","Y","Supports Caffe's Deconvolution and TensorFlow's tf.layers.conv2d_transpose." "DECONV_2D","Y","Supports Caffe's Deconvolution and TensorFlow's tf.layers.conv2d_transpose."
...@@ -20,7 +20,7 @@ Operator lists ...@@ -20,7 +20,7 @@ Operator lists
"DEPTH_TO_SPACE","Y","" "DEPTH_TO_SPACE","Y",""
"DEQUANTIZE","Y","Model quantization will be supported later." "DEQUANTIZE","Y","Model quantization will be supported later."
"ELEMENT_WISE","Y","ADD/MUL/DIV/MIN/MAX/NEG/ABS/SQR_DIFF/POW/RSQRT/EQUAL" "ELEMENT_WISE","Y","ADD/MUL/DIV/MIN/MAX/NEG/ABS/SQR_DIFF/POW/RSQRT/EQUAL"
"EMBEDDING_LOOKUP","Y","Only support channel axis concatenation." "EMBEDDING_LOOKUP","Y",""
"FULLY_CONNECTED","Y","" "FULLY_CONNECTED","Y",""
"GROUP_CONV_2D","","Caffe model with group count = channel count is supported." "GROUP_CONV_2D","","Caffe model with group count = channel count is supported."
"IDENTITY","Y","Only TensorFlow model is supported." "IDENTITY","Y","Only TensorFlow model is supported."
...@@ -44,7 +44,7 @@ Operator lists ...@@ -44,7 +44,7 @@ Operator lists
"SHAPE","Y","Only CPU and TensorFlow is supported." "SHAPE","Y","Only CPU and TensorFlow is supported."
"STACK","Y","Only CPU and TensorFlow is supported." "STACK","Y","Only CPU and TensorFlow is supported."
"STRIDEDSLICE","Y","Only CPU and TensorFlow is supported." "STRIDEDSLICE","Y","Only CPU and TensorFlow is supported."
"SLICE","Y","In TensorFlow, this op is equivalent to SPLIT; Only support channel axis slice." "SPLIT","Y","In Caffe, this op is equivalent to SLICE; For GPU only support channel axis slice."
"SOFTMAX","Y","" "SOFTMAX","Y",""
"SPACE_TO_BATCH_ND", "Y","" "SPACE_TO_BATCH_ND", "Y",""
"SPACE_TO_DEPTH","Y","" "SPACE_TO_DEPTH","Y",""
......
...@@ -70,7 +70,7 @@ MaceStatus OpenCLAllocator::New(size_t nbytes, void **result) const { ...@@ -70,7 +70,7 @@ MaceStatus OpenCLAllocator::New(size_t nbytes, void **result) const {
MaceStatus OpenCLAllocator::NewImage(const std::vector<size_t> &image_shape, MaceStatus OpenCLAllocator::NewImage(const std::vector<size_t> &image_shape,
const DataType dt, const DataType dt,
void **result) const { void **result) const {
MACE_CHECK(image_shape.size() == 2) << "Image shape's size must equal 2"; MACE_CHECK(image_shape.size() == 2, "Image shape's size must equal 2");
VLOG(3) << "Allocate OpenCL image: " << image_shape[0] << ", " VLOG(3) << "Allocate OpenCL image: " << image_shape[0] << ", "
<< image_shape[1]; << image_shape[1];
...@@ -134,7 +134,7 @@ void *OpenCLAllocator::Map(void *buffer, size_t offset, size_t nbytes) const { ...@@ -134,7 +134,7 @@ void *OpenCLAllocator::Map(void *buffer, size_t offset, size_t nbytes) const {
void *OpenCLAllocator::MapImage(void *buffer, void *OpenCLAllocator::MapImage(void *buffer,
const std::vector<size_t> &image_shape, const std::vector<size_t> &image_shape,
std::vector<size_t> *mapped_image_pitch) const { std::vector<size_t> *mapped_image_pitch) const {
MACE_CHECK(image_shape.size() == 2) << "Just support map 2d image"; MACE_CHECK(image_shape.size() == 2, "Just support map 2d image");
auto cl_image = static_cast<cl::Image2D *>(buffer); auto cl_image = static_cast<cl::Image2D *>(buffer);
std::array<size_t, 3> origin = {0, 0, 0}; std::array<size_t, 3> origin = {0, 0, 0};
std::array<size_t, 3> region = {image_shape[0], image_shape[1], 1}; std::array<size_t, 3> region = {image_shape[0], image_shape[1], 1};
......
...@@ -39,7 +39,7 @@ std::string DataTypeToString(const DataType dt) { ...@@ -39,7 +39,7 @@ std::string DataTypeToString(const DataType dt) {
#endif #endif
{DT_UINT8, "DT_UINT8"}, {DT_UINT8, "DT_UINT8"},
{DT_INT32, "DT_UINT32"}}; {DT_INT32, "DT_UINT32"}};
MACE_CHECK(dt != DT_INVALID) << "Not support Invalid data type"; MACE_CHECK(dt != DT_INVALID, "Not support Invalid data type");
return dtype_string_map[dt]; return dtype_string_map[dt];
} }
......
...@@ -26,41 +26,39 @@ ...@@ -26,41 +26,39 @@
namespace mace { namespace mace {
namespace kernels { namespace kernels {
struct FillBase {
explicit FillBase(float value) : value_(value) {}
int value_;
};
template <DeviceType D, class T> template <DeviceType D, class T>
struct FillFunctor; struct FillFunctor;
template <> template <>
struct FillFunctor<DeviceType::CPU, float> : FillBase { struct FillFunctor<DeviceType::CPU, float> {
explicit FillFunctor(float value) : FillBase(value) {} FillFunctor() {}
MaceStatus operator()(const Tensor *shape, MaceStatus operator()(const Tensor *shape,
const Tensor *value,
Tensor *output, Tensor *output,
StatsFuture *future) { StatsFuture *future) {
MACE_UNUSED(future); MACE_UNUSED(future);
MACE_CHECK(shape->dim_size() == 1) << "Shape must be 1-D"; MACE_CHECK(shape->dim_size() == 1, "Shape must be 1-D");
const index_t num_dims = shape->dim(0); const index_t num_dims = shape->dim(0);
Tensor::MappingGuard shape_guard(shape); Tensor::MappingGuard shape_guard(shape);
const int32_t *shape_data = shape->data<int32_t>(); const int32_t *shape_data = shape->data<int32_t>();
std::vector<index_t> output_shape; std::vector<index_t> output_shape;
for (index_t i = 0; i < num_dims; ++i) { for (index_t i = 0; i < num_dims; ++i) {
MACE_CHECK(shape_data[i] > 0) << "Shape must be non-negative: " MACE_CHECK(shape_data[i] > 0, "Shape must be non-negative: ",
<< shape_data[i]; shape_data[i]);
output_shape.push_back(shape_data[i]); output_shape.push_back(shape_data[i]);
} }
Tensor::MappingGuard value_guard(value);
const float *value_data = value->data<float>();
MACE_RETURN_IF_ERROR(output->Resize(output_shape)); MACE_RETURN_IF_ERROR(output->Resize(output_shape));
Tensor::MappingGuard output_guard(output); Tensor::MappingGuard output_guard(output);
float *output_data = output->mutable_data<float>(); float *output_data = output->mutable_data<float>();
std::fill(output_data, output_data + output->size(), value_); std::fill(output_data, output_data + output->size(), *value_data);
return MACE_SUCCESS; return MACE_SUCCESS;
} }
......
...@@ -58,7 +58,7 @@ namespace kernels { ...@@ -58,7 +58,7 @@ namespace kernels {
if (runtime->IsOutOfRangeCheckEnabled()) { \ if (runtime->IsOutOfRangeCheckEnabled()) { \
(kernel_error)->Map(nullptr); \ (kernel_error)->Map(nullptr); \
char *kerror_code = (kernel_error)->mutable_data<char>(); \ char *kerror_code = (kernel_error)->mutable_data<char>(); \
MACE_CHECK(*kerror_code == 0) << "Kernel error code: " << *kerror_code;\ MACE_CHECK(*kerror_code == 0, "Kernel error code: ", *kerror_code);\
(kernel_error)->UnMap(); \ (kernel_error)->UnMap(); \
} }
......
...@@ -55,10 +55,10 @@ TEST_F(ConcatOpTest, CPUSimpleHorizon) { ...@@ -55,10 +55,10 @@ TEST_F(ConcatOpTest, CPUSimpleHorizon) {
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
for (auto f : input0) { for (auto f : input0) {
ASSERT_EQ(f, *output_ptr++); EXPECT_EQ(f, *output_ptr++);
} }
for (auto f : input1) { for (auto f : input1) {
ASSERT_EQ(f, *output_ptr++); EXPECT_EQ(f, *output_ptr++);
} }
} }
...@@ -93,10 +93,10 @@ TEST_F(ConcatOpTest, CPUSimpleVertical) { ...@@ -93,10 +93,10 @@ TEST_F(ConcatOpTest, CPUSimpleVertical) {
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
ASSERT_EQ(input0[i * 4 + j], *output_ptr++); EXPECT_EQ(input0[i * 4 + j], *output_ptr++);
} }
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
ASSERT_EQ(input1[i * 4 + j], *output_ptr++); EXPECT_EQ(input1[i * 4 + j], *output_ptr++);
} }
} }
} }
......
...@@ -28,18 +28,19 @@ class FillOp : public Operator<D, T> { ...@@ -28,18 +28,19 @@ class FillOp : public Operator<D, T> {
public: public:
FillOp(const OperatorDef &operator_def, Workspace *ws) FillOp(const OperatorDef &operator_def, Workspace *ws)
: Operator<D, T>(operator_def, ws), : Operator<D, T>(operator_def, ws),
functor_(OperatorBase::GetOptionalArg<float>("value", 0.0f)) {} functor_() {}
MaceStatus Run(StatsFuture *future) override { MaceStatus Run(StatsFuture *future) override {
const Tensor *shape = this->Input(SHAPE); const Tensor *shape = this->Input(SHAPE);
const Tensor *value = this->Input(VALUE);
Tensor *output = this->Output(OUTPUT); Tensor *output = this->Output(OUTPUT);
return functor_(shape, output, future); return functor_(shape, value, output, future);
} }
private: private:
kernels::FillFunctor<D, T> functor_; kernels::FillFunctor<D, T> functor_;
MACE_OP_INPUT_TAGS(SHAPE); MACE_OP_INPUT_TAGS(SHAPE, VALUE);
MACE_OP_OUTPUT_TAGS(OUTPUT); MACE_OP_OUTPUT_TAGS(OUTPUT);
}; };
......
...@@ -28,7 +28,7 @@ void TestFill(const std::vector<int32_t> &shape, ...@@ -28,7 +28,7 @@ void TestFill(const std::vector<int32_t> &shape,
OpsTestNet net; OpsTestNet net;
OpDefBuilder("Fill", "FillTest") OpDefBuilder("Fill", "FillTest")
.Input("Shape") .Input("Shape")
.AddFloatArg("value", static_cast<float>(value)) .Input("Value")
.Output("Output") .Output("Output")
.Finalize(net.NewOperatorDef()); .Finalize(net.NewOperatorDef());
...@@ -38,19 +38,21 @@ void TestFill(const std::vector<int32_t> &shape, ...@@ -38,19 +38,21 @@ void TestFill(const std::vector<int32_t> &shape,
{static_cast<index_t>(shape.size())}, {static_cast<index_t>(shape.size())},
shape); shape);
net.AddInputFromArray<DeviceType::CPU, float>("Value", {}, {value});
// Run // Run
net.RunOp(); net.RunOp();
auto output = net.GetTensor("Output"); auto output = net.GetTensor("Output");
for (index_t i = 0; i < output->dim_size(); ++i) { for (index_t i = 0; i < output->dim_size(); ++i) {
ASSERT_EQ(output->dim(i), shape[i]); EXPECT_EQ(output->dim(i), shape[i]);
} }
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
const index_t size = output->size(); const index_t size = output->size();
for (index_t i = 0; i < size; ++i) { for (index_t i = 0; i < size; ++i) {
ASSERT_EQ(output_ptr[i], value); EXPECT_EQ(output_ptr[i], value);
} }
} }
} // namespace } // namespace
......
...@@ -46,7 +46,7 @@ void TestIdentity(const std::vector<index_t> &shape) { ...@@ -46,7 +46,7 @@ void TestIdentity(const std::vector<index_t> &shape) {
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
const int size = output->size(); const int size = output->size();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
ASSERT_EQ(input_ptr[i], output_ptr[i]); EXPECT_EQ(input_ptr[i], output_ptr[i]);
} }
} }
} // namespace } // namespace
......
...@@ -42,12 +42,12 @@ class ReshapeOp : public Operator<D, T> { ...@@ -42,12 +42,12 @@ class ReshapeOp : public Operator<D, T> {
for (int i = 0; i < num_dims; ++i) { for (int i = 0; i < num_dims; ++i) {
if (shape_data[i] == -1) { if (shape_data[i] == -1) {
MACE_CHECK(unknown_idx == -1) << "Only one input size may be -1"; MACE_CHECK(unknown_idx == -1, "Only one input size may be -1");
unknown_idx = i; unknown_idx = i;
out_shape.push_back(1); out_shape.push_back(1);
} else { } else {
MACE_CHECK(shape_data[i] >= 0) << "Shape must be non-negative: " MACE_CHECK(shape_data[i] >= 0, "Shape must be non-negative: ",
<< shape_data[i]; shape_data[i]);
out_shape.push_back(shape_data[i]); out_shape.push_back(shape_data[i]);
product *= shape_data[i]; product *= shape_data[i];
} }
......
...@@ -53,7 +53,7 @@ void TestReshape(const std::vector<index_t> &org_shape, ...@@ -53,7 +53,7 @@ void TestReshape(const std::vector<index_t> &org_shape,
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
const int size = output->size(); const int size = output->size();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
ASSERT_EQ(input_ptr[i], output_ptr[i]); EXPECT_EQ(input_ptr[i], output_ptr[i]);
} }
} }
} // namespace } // namespace
......
...@@ -49,7 +49,7 @@ void TestSqueeze(const std::vector<index_t> &org_shape, ...@@ -49,7 +49,7 @@ void TestSqueeze(const std::vector<index_t> &org_shape,
const float *output_ptr = output->data<float>(); const float *output_ptr = output->data<float>();
const int size = output->size(); const int size = output->size();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
ASSERT_EQ(input_ptr[i], output_ptr[i]); EXPECT_EQ(input_ptr[i], output_ptr[i]);
} }
} }
} // namespace } // namespace
......
...@@ -464,10 +464,6 @@ class TensorflowConverter(base_converter.ConverterInterface): ...@@ -464,10 +464,6 @@ class TensorflowConverter(base_converter.ConverterInterface):
op = self.convert_general_op(tf_op) op = self.convert_general_op(tf_op)
op.type = MaceOp.Fill.name op.type = MaceOp.Fill.name
value_arg = op.arg.add()
value_arg.name = MaceKeyword.mace_value_str
value_arg.f = tf_op.inputs[1].eval()
def convert_fused_batchnorm(self, tf_op): def convert_fused_batchnorm(self, tf_op):
op = self.convert_general_op(tf_op) op = self.convert_general_op(tf_op)
op.type = MaceOp.FoldedBatchNorm.name op.type = MaceOp.FoldedBatchNorm.name
......
...@@ -342,7 +342,7 @@ void MaceRunFunc(const int in_out_size) { ...@@ -342,7 +342,7 @@ void MaceRunFunc(const int in_out_size) {
MaceEngine engine(device); MaceEngine engine(device);
MaceStatus status = engine.Init(net_def.get(), input_names, output_names, MaceStatus status = engine.Init(net_def.get(), input_names, output_names,
reinterpret_cast<unsigned char *>(data.data())); reinterpret_cast<unsigned char *>(data.data()));
ASSERT_EQ(status, MaceStatus::MACE_SUCCESS); EXPECT_EQ(status, MaceStatus::MACE_SUCCESS);
std::map<std::string, mace::MaceTensor> inputs; std::map<std::string, mace::MaceTensor> inputs;
std::map<std::string, mace::MaceTensor> outputs; std::map<std::string, mace::MaceTensor> outputs;
......
...@@ -336,7 +336,7 @@ void MaceRun(const int in_out_size, ...@@ -336,7 +336,7 @@ void MaceRun(const int in_out_size,
MaceEngine engine(device); MaceEngine engine(device);
MaceStatus status = engine.Init(net_def.get(), input_names, output_names, MaceStatus status = engine.Init(net_def.get(), input_names, output_names,
reinterpret_cast<unsigned char *>(data.data())); reinterpret_cast<unsigned char *>(data.data()));
ASSERT_EQ(status, MaceStatus::MACE_SUCCESS); EXPECT_EQ(status, MaceStatus::MACE_SUCCESS);
std::map<std::string, mace::MaceTensor> inputs; std::map<std::string, mace::MaceTensor> inputs;
std::map<std::string, mace::MaceTensor> outputs; std::map<std::string, mace::MaceTensor> outputs;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册