// // RasterOutputTest.cpp // MNNTests // // Created by MNN on 2020/12/29. // Copyright © 2018, Alibaba Group Holding Limited // #include #include "MNNTestSuite.h" #include "MNN_generated.h" #include #include "TestUtils.h" using namespace MNN::Express; using namespace MNN; static std::shared_ptr _createModel() { auto x = _Input({1, 3, 224, 224}, NCHW, halide_type_of()); x->setName("Input"); auto y = _Transpose(x, {0, 1, 3, 2}); auto z = _Add(y, _Scalar(1)); z->setName("Add"); auto q = _Negative(y); auto p = _Transpose(q, {0, 3, 1, 2}); p->setName("Transpose"); std::unique_ptr net(new NetT); Variable::save({z, p}, net.get()); flatbuffers::FlatBufferBuilder builder; auto len = MNN::Net::Pack(builder, net.get()); builder.Finish(len); return std::shared_ptr(Module::load({"Input"}, {"Add", "Transpose"}, builder.GetBufferPointer(), builder.GetSize())); } class RasterOutputTest : public MNNTestCase { public: virtual bool run(int precision) { auto executor = cloneCurrentExecutor(); ExecutorScope scope(executor); auto net = _createModel(); auto x = _Input({1, 3, 224, 224}, NCHW, halide_type_of()); auto y = _Transpose(x, {0, 1, 3, 2}); auto z = _Add(y, _Scalar(1)); auto q = _Negative(y); auto p = _Transpose(q, {0, 3, 1, 2}); { auto xPtr = x->writeMap(); for (int v = 0; v < 1 * 3 * 224 * 224; ++ v) { xPtr[v] = v; } x->unMap(); } auto outputs = net->onForward({x}); { auto dPtr = outputs[0]->readMap(); auto zPtr = z->readMap(); auto size = z->getInfo()->size; for (int v = 0; v < size; ++v) { if (zPtr[v] != dPtr[v]) { return false; } } } { auto dPtr = outputs[1]->readMap(); auto zPtr = p->readMap(); auto size = p->getInfo()->size; for (int v = 0; v < size; ++v) { if (zPtr[v] != dPtr[v]) { return false; } } } return true; } }; MNNTestSuiteRegister(RasterOutputTest, "expr/RasterOutput");