- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
//
|
|
|
|
// ReplaceTest.cpp
|
|
|
|
// MNNTests
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/09/10.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
2019-12-27 22:16:57 +08:00
|
|
|
#include <MNN/expr/ExprCreator.hpp>
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
#include "MNNTestSuite.h"
|
2020-02-26 09:57:17 +08:00
|
|
|
#include <math.h>
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
|
|
|
|
using namespace MNN::Express;
|
2020-02-26 09:57:17 +08:00
|
|
|
class PrecomputeTest : public MNNTestCase {
|
|
|
|
public:
|
|
|
|
virtual bool run() {
|
|
|
|
auto x = _Input({100}, NCHW);
|
|
|
|
auto xPtr = x->writeMap<float>();
|
|
|
|
for (int i=0; i<100; ++i) {
|
|
|
|
xPtr[i] = (float)i - 50.0f;
|
|
|
|
}
|
|
|
|
auto y = _Abs(x);
|
|
|
|
|
|
|
|
auto z = _Square(y);
|
|
|
|
auto u = _Sin(z);
|
2020-02-29 10:34:24 +08:00
|
|
|
auto v = _Cos(z);
|
|
|
|
Variable::prepareCompute({y, u, v});
|
|
|
|
auto check = [&](int number) {
|
|
|
|
{
|
|
|
|
auto yPtr = y->readMap<float>();
|
|
|
|
if (nullptr == yPtr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
if (yPtr[i] != fabs((float)i - 50.0f)) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n", yPtr[i], fabs((float)i - 50.0f));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto uPtr = u->readMap<float>();
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
auto target = sinf(yPtr[i] * yPtr[i]);
|
|
|
|
auto diff = fabsf(uPtr[i] - target);
|
|
|
|
if (diff > 0.00001f) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n",uPtr[i], target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto vPtr = v->readMap<float>();
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
auto target = cosf(yPtr[i] * yPtr[i]);
|
|
|
|
auto diff = fabsf(vPtr[i] - target);
|
|
|
|
if (diff > 0.00001f) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n",vPtr[i], target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (!check(100)) {
|
2020-02-26 09:57:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-29 10:34:24 +08:00
|
|
|
{
|
|
|
|
x->resize({1, 101});
|
|
|
|
auto xPtr = x->writeMap<float>();
|
|
|
|
for (int i=0; i<101; ++i) {
|
|
|
|
xPtr[i] = (float)i - 50.0f;
|
2020-02-26 09:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
2020-02-29 10:34:24 +08:00
|
|
|
if (!check(101)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Delete end var, check if the cache can work
|
|
|
|
u = nullptr;
|
|
|
|
{
|
|
|
|
x->writeMap<float>();
|
|
|
|
auto xPtr = x->writeMap<float>();
|
|
|
|
auto number = 101;
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
xPtr[i] = (float)i - 50.0f;
|
|
|
|
}
|
|
|
|
auto yPtr = y->readMap<float>();
|
|
|
|
if (nullptr == yPtr) {
|
2020-02-28 17:26:43 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-29 10:34:24 +08:00
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
if (yPtr[i] != fabs((float)i - 50.0f)) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n", yPtr[i], fabs((float)i - 50.0f));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto vPtr = v->readMap<float>();
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
auto target = cosf(yPtr[i] * yPtr[i]);
|
|
|
|
auto diff = fabsf(vPtr[i] - target);
|
|
|
|
if (diff > 0.00001f) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n",vPtr[i], target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
number = 102;
|
|
|
|
x->resize({number, 1});
|
|
|
|
xPtr = x->writeMap<float>();
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
xPtr[i] = (float)i - 50.0f;
|
|
|
|
}
|
|
|
|
yPtr = y->readMap<float>();
|
|
|
|
if (nullptr == yPtr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
if (yPtr[i] != fabs((float)i - 50.0f)) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n", yPtr[i], fabs((float)i - 50.0f));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vPtr = v->readMap<float>();
|
|
|
|
for (int i=0; i<number; ++i) {
|
|
|
|
auto target = cosf(yPtr[i] * yPtr[i]);
|
|
|
|
auto diff = fabsf(vPtr[i] - target);
|
|
|
|
if (diff > 0.00001f) {
|
|
|
|
MNN_PRINT("PrecomputeTest Error: %f, %f\n",vPtr[i], target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-02-28 17:26:43 +08:00
|
|
|
}
|
2020-02-26 09:57:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
|
|
|
|
class ReplaceTest : public MNNTestCase {
|
|
|
|
public:
|
|
|
|
virtual bool run() {
|
|
|
|
auto c1 = MNN::Express::_Const(1.f, {1, 1, 1, 1}, MNN::Express::NHWC);
|
|
|
|
auto c2 = MNN::Express::_Const(2.f, {1, 1, 1, 1}, MNN::Express::NHWC);
|
|
|
|
auto c3 = MNN::Express::_Const(3.f, {1, 1, 1, 1}, MNN::Express::NHWC);
|
|
|
|
auto c4 = MNN::Express::_Const(4.f, {1, 1, 1, 1}, MNN::Express::NHWC);
|
|
|
|
auto c5 = MNN::Express::_Const(5.f, {1, 1, 1, 1}, MNN::Express::NHWC);
|
|
|
|
auto b1 = MNN::Express::_Add(c1, c2);
|
2019-12-27 22:16:57 +08:00
|
|
|
auto b2 = MNN::Express::_Multiply(c3, c4);
|
|
|
|
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
auto r1 = b1->readMap<float>();
|
|
|
|
if (3.0f != r1[0]) {
|
|
|
|
MNN_PRINT("1 + 2 = %f\n", r1[0]);
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-27 22:16:57 +08:00
|
|
|
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
MNN::Express::Variable::replace(c2, b2);
|
|
|
|
auto r2 = b1->readMap<float>();
|
|
|
|
if (13.0f != r2[0]) {
|
|
|
|
MNN_PRINT("1 + 3 x 4 = %f\n", r2[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MNN::Express::Variable::replace(c3, c5);
|
|
|
|
auto r3 = b1->readMap<float>();
|
|
|
|
if (21.0f != r3[0]) {
|
|
|
|
MNN_PRINT("1 + 5 x 4 = %f\n", r3[0]);
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-15 13:33:47 +08:00
|
|
|
auto d0 = _Const(7.f, {1, 3, 1, 1}, NHWC);
|
|
|
|
auto d = _Split(d0, {1, 1, 1}, 1)[0];
|
|
|
|
Variable::replace(c3, d);
|
|
|
|
r3 = b1->readMap<float>();
|
|
|
|
if (29.0f != r3[0]) {
|
|
|
|
MNN_PRINT("1 + 7 x 4 = %f\n", r3[0]);
|
|
|
|
return false;
|
|
|
|
}
|
- build:
- unify schema building in core and converter;
- add more build script for android;
- add linux build script for python;
- ops impl:
- add floor mod support in binary;
- use eltwise impl in add/max/sub/mul binary for optimization;
- remove fake double support in cast;
- fix 5d support for concat;
- add adjX and adjY support for batch matmul;
- optimize conv2d back prop filter;
- add pad mode support for conv3d;
- fix bug in conv2d & conv depthwise with very small feature map;
- optimize binary without broacast;
- add data types support for gather;
- add gather ND support;
- use uint8 data type in gather v2;
- add transpose support for matmul;
- add matrix band part;
- add dim != 4 support for padding, reshape & tensor convert;
- add pad type support for pool3d;
- make ops based on TensorFlow Lite quantization optional;
- add all & any support for reduction;
- use type in parameter as output type in reduction;
- add int support for unary;
- add variable weight support for conv2d;
- fix conv2d depthwise weights initialization;
- fix type support for transpose;
- fix grad outputs count for reduce grad and reshape grad;
- fix priorbox & detection output;
- fix metal softmax error;
- python:
- add runSessionWithCallBackInfo interface;
- add max nodes limit (1400) for visualization tool;
- fix save error in python3;
- align default dim;
- convert:
- add extra design for optimization;
- add more post converting optimizers;
- add caffe v1 weights blob support;
- add cast, unary, conv transpose support for onnx model;
- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
- add cos/sin/atan/tan support for unary for tensorflow model;
- add any/all support for reduction for tensorflow model;
- add elu, conv3d, pool3d support for tensorflow model;
- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
- fix size computer lock;
- fix thread pool deadlock;
- add express & parameters in express;
- rewrite blitter chooser without static map;
- add tests for expr;
2019-10-29 13:37:26 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
MNNTestSuiteRegister(ReplaceTest, "expr/Replace");
|
2020-02-26 09:57:17 +08:00
|
|
|
MNNTestSuiteRegister(PrecomputeTest, "expr/Precompute");
|