- 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
|
|
|
//
|
|
|
|
// GatherTest.cpp
|
|
|
|
// MNNTests
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/09/17.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
/*
|
|
|
|
Test Case From https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/gather-nd
|
|
|
|
*/
|
2020-11-05 16:41:56 +08:00
|
|
|
#include <math.h>
|
2019-12-27 22:16:57 +08:00
|
|
|
#include <MNN/expr/ExprCreator.hpp>
|
2021-11-30 10:10:53 +08:00
|
|
|
#include <MNN/expr/Module.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"
|
|
|
|
#include "MNN_generated.h"
|
2025-08-01 17:19:36 +08:00
|
|
|
#include "TestUtils.h"
|
2021-11-30 10:10:53 +08:00
|
|
|
using namespace MNN;
|
- 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;
|
|
|
|
|
2021-06-11 17:17:13 +08:00
|
|
|
class GatherExprTest : public MNNTestCase {
|
- 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
|
|
|
public:
|
2021-06-11 17:17:13 +08:00
|
|
|
virtual bool run(int precision) {
|
2025-08-01 17:19:36 +08:00
|
|
|
auto executor = cloneCurrentExecutor();
|
|
|
|
ExecutorScope scope(executor);
|
|
|
|
|
- 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
|
|
|
std::unique_ptr<MNN::OpT> gatherOp(new MNN::OpT);
|
|
|
|
gatherOp->type = MNN::OpType_GatherND;
|
|
|
|
auto parameter = _Input({2, 2}, NHWC, halide_type_of<int32_t>());
|
2021-11-30 10:10:53 +08:00
|
|
|
parameter->setName("param");
|
2020-11-05 16:41:56 +08:00
|
|
|
auto indice = _Input({2, 2}, NHWC, halide_type_of<int32_t>());
|
2021-11-30 10:10:53 +08:00
|
|
|
indice->setName("indice");
|
2020-11-05 16:41:56 +08:00
|
|
|
auto y = Variable::create(Expr::create(gatherOp.get(), {parameter, indice}));
|
2021-11-30 10:10:53 +08:00
|
|
|
y->setName("y");
|
- 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
|
|
|
{
|
|
|
|
parameter->resize({2, 2});
|
2020-11-05 16:41:56 +08:00
|
|
|
auto ptr = parameter->writeMap<float>();
|
|
|
|
ptr[0] = 7.0;
|
|
|
|
ptr[1] = 2.0;
|
|
|
|
ptr[2] = 4.0;
|
|
|
|
ptr[3] = 6.0;
|
- 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 indicePtr = indice->writeMap<int32_t>();
|
2020-11-05 16:41:56 +08:00
|
|
|
indicePtr[0] = 0;
|
|
|
|
indicePtr[1] = 0;
|
|
|
|
indicePtr[2] = 1;
|
|
|
|
indicePtr[3] = 1;
|
|
|
|
auto size = y->getInfo()->size;
|
- 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
|
|
|
if (size != 2) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-05 16:41:56 +08:00
|
|
|
auto yPtr = y->readMap<float>();
|
|
|
|
if (fabs(yPtr[0] - 7.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001) {
|
- 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 false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
indice->resize({2, 1});
|
|
|
|
auto indicePtr = indice->writeMap<int32_t>();
|
2020-11-05 16:41:56 +08:00
|
|
|
indicePtr[0] = 1;
|
|
|
|
indicePtr[1] = 0;
|
|
|
|
auto size = y->getInfo()->size;
|
- 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
|
|
|
if (4 != size) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-05 16:41:56 +08:00
|
|
|
auto yPtr = y->readMap<float>();
|
|
|
|
if (fabs(yPtr[0] - 4.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001 || fabs(yPtr[2] - 7.0) > 0.001 ||
|
|
|
|
fabs(yPtr[3] - 2.0) > 0.001) {
|
- 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 false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
indice->resize({1, 1});
|
|
|
|
auto indicePtr = indice->writeMap<int32_t>();
|
2020-11-05 16:41:56 +08:00
|
|
|
indicePtr[0] = 1;
|
- 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
|
|
|
parameter->resize({2, 2, 2});
|
2020-11-05 16:41:56 +08:00
|
|
|
auto parameterPtr = parameter->writeMap<float>();
|
|
|
|
for (int i = 0; i < parameter->getInfo()->size; ++i) {
|
|
|
|
parameterPtr[i] = 1.0 * i;
|
- 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 size = y->getInfo()->size;
|
|
|
|
if (4 != size) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-05 16:41:56 +08:00
|
|
|
auto yPtr = y->readMap<float>();
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
if (fabs(yPtr[i] - 4.0 - i) > 0.001) {
|
- 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 false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 10:10:53 +08:00
|
|
|
// Run as Module
|
|
|
|
flatbuffers::FlatBufferBuilder builderOutput(1024);
|
|
|
|
{
|
|
|
|
std::unique_ptr<MNN::NetT> net(new NetT);
|
|
|
|
Variable::save({y}, net.get());
|
|
|
|
y = nullptr;
|
|
|
|
auto len = MNN::Net::Pack(builderOutput, net.get());
|
|
|
|
builderOutput.Finish(len);
|
|
|
|
}
|
|
|
|
int sizeOutput = builderOutput.GetSize();
|
|
|
|
auto bufferOutput = builderOutput.GetBufferPointer();
|
|
|
|
std::shared_ptr<MNN::Express::Module> module(Module::load(std::vector<std::string>{"param", "indice"}, std::vector<std::string>{"y"}, bufferOutput, sizeOutput));
|
|
|
|
{
|
|
|
|
{
|
|
|
|
parameter->resize({2, 2});
|
|
|
|
auto ptr = parameter->writeMap<float>();
|
|
|
|
ptr[0] = 7.0;
|
|
|
|
ptr[1] = 2.0;
|
|
|
|
ptr[2] = 4.0;
|
|
|
|
ptr[3] = 6.0;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
indice->resize({2, 2});
|
|
|
|
auto indicePtr = indice->writeMap<int32_t>();
|
|
|
|
indicePtr[0] = 0;
|
|
|
|
indicePtr[1] = 0;
|
|
|
|
indicePtr[2] = 1;
|
|
|
|
indicePtr[3] = 1;
|
|
|
|
auto y2 = module->onForward({parameter, indice})[0];
|
|
|
|
auto size = y2->getInfo()->size;
|
|
|
|
if (size != 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto yPtr = y2->readMap<float>();
|
|
|
|
if (fabs(yPtr[0] - 7.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
indice->resize({2, 1});
|
|
|
|
auto indicePtr = indice->writeMap<int32_t>();
|
|
|
|
indicePtr[0] = 1;
|
|
|
|
indicePtr[1] = 0;
|
|
|
|
auto y2 = module->onForward({parameter, indice})[0];
|
|
|
|
auto size = y2->getInfo()->size;
|
|
|
|
if (4 != size) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto yPtr = y2->readMap<float>();
|
|
|
|
if (fabs(yPtr[0] - 4.0) > 0.001 || fabs(yPtr[1] - 6.0) > 0.001 || fabs(yPtr[2] - 7.0) > 0.001 ||
|
|
|
|
fabs(yPtr[3] - 2.0) > 0.001) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
indice->resize({1, 1});
|
|
|
|
auto indicePtr = indice->writeMap<int32_t>();
|
|
|
|
indicePtr[0] = 1;
|
|
|
|
parameter->resize({2, 2, 2});
|
|
|
|
auto parameterPtr = parameter->writeMap<float>();
|
|
|
|
for (int i = 0; i < parameter->getInfo()->size; ++i) {
|
|
|
|
parameterPtr[i] = 1.0 * i;
|
|
|
|
}
|
|
|
|
auto y2 = module->onForward({parameter, indice})[0];
|
|
|
|
auto yPtr = y2->readMap<float>();
|
|
|
|
auto size = y2->getInfo()->size;
|
|
|
|
if (4 != size) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
if (fabs(yPtr[i] - 4.0 - i) > 0.001) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-29 16:21:40 +08:00
|
|
|
{
|
|
|
|
const float inpudata[] = {-1.0, -2.0, 3.0, 4.0};
|
|
|
|
const int indices_data[] = {0, 0, 1, 1};
|
|
|
|
auto params = _Const(inpudata, {2, 2}, NHWC, halide_type_of<float>());
|
|
|
|
auto indices = _Const(indices_data, {2, 2}, NHWC, halide_type_of<int>());
|
|
|
|
auto x1 = _GatherND(params, indices);
|
|
|
|
x1->setName("input1");
|
|
|
|
auto shape = x1->getInfo()->dim;
|
|
|
|
auto x0 = _Input(shape, NHWC, halide_type_of<float>());
|
|
|
|
float x0data[] = {1.0f, 2.0f};
|
|
|
|
::memcpy(x0->writeMap<float>(), x0data, 2 * sizeof(float));
|
|
|
|
x0->setName("input0");
|
|
|
|
auto res = _Add(x0, x1);
|
|
|
|
res->setName("GatherNd_output_0");
|
|
|
|
|
|
|
|
flatbuffers::FlatBufferBuilder builderOutput(1024);
|
|
|
|
{
|
|
|
|
std::unique_ptr<MNN::NetT> net(new NetT);
|
|
|
|
Variable::save({res}, net.get());
|
|
|
|
y = nullptr;
|
|
|
|
auto len = MNN::Net::Pack(builderOutput, net.get());
|
|
|
|
builderOutput.Finish(len);
|
|
|
|
}
|
|
|
|
int sizeOutput = builderOutput.GetSize();
|
|
|
|
auto bufferOutput = builderOutput.GetBufferPointer();
|
|
|
|
const char* cacheFileName = ".tempcache";
|
|
|
|
MNN::ScheduleConfig config;
|
|
|
|
config.numThread = 1;
|
|
|
|
|
|
|
|
BackendConfig bnConfig;
|
|
|
|
bnConfig.precision = (MNN::BackendConfig::PrecisionMode)precision;
|
|
|
|
config.backendConfig = &bnConfig;
|
|
|
|
std::shared_ptr<Executor::RuntimeManager> rtmgr(Executor::RuntimeManager::createRuntimeManager(config));
|
|
|
|
rtmgr->setCache(cacheFileName);
|
|
|
|
MNN::Express::Module::Config mConfig;
|
|
|
|
/*
|
|
|
|
ScheduleConfig config;
|
|
|
|
BackendConfig bnConfig;
|
|
|
|
bnConfig.precision = (MNN::BackendConfig::PrecisionMode)precision;
|
|
|
|
config.numThread = 1;
|
|
|
|
config.type = ExecutorScope::Current()->getAttr()->firstType.first;
|
|
|
|
config.backendConfig = &bnConfig;
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::shared_ptr<MNN::Express::Module> module_2(Module::load(std::vector<std::string>{"input0"}, std::vector<std::string>{"GatherNd_output_0"}, bufferOutput, sizeOutput, rtmgr, &mConfig));
|
|
|
|
|
|
|
|
auto y2 = module_2->onForward({x0})[0];
|
|
|
|
|
|
|
|
const float inpudata1[] = {-5.0, -6.0, 7.0, 8.0};
|
|
|
|
x0->resize({2, 2});
|
|
|
|
auto parameterPtr = params->writeMap<float>();
|
|
|
|
::memcpy(parameterPtr, inpudata1, 4*sizeof(float));
|
|
|
|
|
|
|
|
y2 = module_2->onForward({x0})[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GatherNdReComputeTest : public MNNTestCase {
|
|
|
|
public:
|
|
|
|
virtual bool run(int precision) {
|
2025-08-01 17:19:36 +08:00
|
|
|
auto executor = cloneCurrentExecutor();
|
|
|
|
ExecutorScope scope(executor);
|
2024-02-29 16:21:40 +08:00
|
|
|
const float inpudata[] = {-1.0, -2.0, 3.0, 4.0};
|
|
|
|
const int indices_data[] = {0, 0, 1, 1};
|
|
|
|
auto params = _Const(inpudata, {2, 2}, NHWC, halide_type_of<float>());
|
|
|
|
auto indices = _Const(indices_data, {2, 2}, NHWC, halide_type_of<int>());
|
|
|
|
auto x1 = _GatherND(params, indices);
|
|
|
|
x1->setName("input1");
|
|
|
|
auto shape = x1->getInfo()->dim;
|
|
|
|
auto x0 = _Input(shape, NHWC, halide_type_of<float>());
|
|
|
|
x0->setName("input0");
|
|
|
|
auto res = _Add(x0, x1);
|
|
|
|
res->setName("GatherNd_output_0");
|
|
|
|
|
|
|
|
flatbuffers::FlatBufferBuilder builderOutput(1024);
|
|
|
|
{
|
|
|
|
std::unique_ptr<MNN::NetT> net(new NetT);
|
|
|
|
Variable::save({res}, net.get());
|
|
|
|
auto len = MNN::Net::Pack(builderOutput, net.get());
|
|
|
|
builderOutput.Finish(len);
|
2021-11-30 10:10:53 +08:00
|
|
|
}
|
2024-02-29 16:21:40 +08:00
|
|
|
int sizeOutput = builderOutput.GetSize();
|
|
|
|
auto bufferOutput = builderOutput.GetBufferPointer();
|
|
|
|
|
|
|
|
std::shared_ptr<MNN::Express::Module> module(Module::load(std::vector<std::string>{"input0"}, std::vector<std::string>{"GatherNd_output_0"}, bufferOutput, sizeOutput));
|
|
|
|
|
|
|
|
// first run, call GatherNd compute function when resize.
|
|
|
|
float data0[] = {1.0f, 2.0f};
|
|
|
|
::memcpy(x0->writeMap<float>(), data0, 2 * sizeof(float));
|
|
|
|
auto y = module->onForward({x0});
|
|
|
|
|
|
|
|
// resize input and test GatherNd recompute function when risize.
|
|
|
|
const float data1[] = {-5.0, -6.0, 7.0, 8.0};
|
|
|
|
x0->resize({2, 2});
|
|
|
|
::memcpy(x0->writeMap<float>(), data1, 4 * sizeof(float));
|
|
|
|
y = module->onForward({x0});
|
- 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;
|
|
|
|
}
|
2024-02-29 16:21:40 +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
|
|
|
};
|
2021-06-11 17:17:13 +08:00
|
|
|
MNNTestSuiteRegister(GatherExprTest, "expr/Gather");
|
2024-02-29 16:21:40 +08:00
|
|
|
MNNTestSuiteRegister(GatherNdReComputeTest, "expr/GatherNdRecomputeTest");
|