| 246 | class RefTest : public MNNTestCase { |
| 247 | public: |
| 248 | virtual bool run(int precision) { |
| 249 | auto executor = cloneCurrentExecutor(); |
| 250 | ExecutorScope scope(executor); |
| 251 | std::vector<int8_t> buffer; |
| 252 | // construct |
| 253 | { |
| 254 | auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 255 | x->setName("data"); |
| 256 | auto x1 = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 257 | x1->setName("data1"); |
| 258 | auto x1Ptr = x1->writeMap<int>(); |
| 259 | for (int i=0; i<x1->getInfo()->size; ++i) { |
| 260 | x1Ptr[i] = 1; |
| 261 | } |
| 262 | x1.fix(VARP::CONSTANT); |
| 263 | auto y = x + x1; |
| 264 | y->setName("o0"); |
| 265 | auto y1 = x - x1; |
| 266 | y1->setName("o1"); |
| 267 | buffer = Variable::save({y, y1}); |
| 268 | } |
| 269 | // Execute |
| 270 | std::shared_ptr<Module> refModule(Module::load({"data"}, {"o0", "o1", "data1"}, (const uint8_t*)buffer.data(), buffer.size()), Module::destroy); |
| 271 | auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 272 | auto size = x->getInfo()->size; |
| 273 | std::vector<int> inputPtr(size); |
| 274 | for (int i=0; i<size; ++i) { |
| 275 | inputPtr[i] = i; |
| 276 | } |
| 277 | ::memcpy(x->writeMap<int>(), inputPtr.data(), size * sizeof(int)); |
| 278 | auto outputVars = refModule->onForward({x}); |
| 279 | refModule.reset(); |
| 280 | auto p0 = outputVars[0]->readMap<int>(); |
| 281 | for (int i=0; i<size; ++i) { |
| 282 | if (p0[i] != inputPtr[i] + 1) { |
| 283 | FUNC_PRINT(1); |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | auto p1 = outputVars[1]->readMap<int>(); |
| 288 | for (int i=0; i<size; ++i) { |
| 289 | if (p1[i] != inputPtr[i] - 1) { |
| 290 | FUNC_PRINT(1); |
| 291 | return false; |
| 292 | } |
| 293 | } |
| 294 | auto p2 = outputVars[2]->readMap<int>(); |
| 295 | for (int i=0; i<size; ++i) { |
| 296 | if (p2[i] != 1) { |
| 297 | FUNC_PRINT(1); |
| 298 | return false; |
| 299 | } |
| 300 | } |
| 301 | return true; |
| 302 | } |
| 303 | }; |
| 304 | MNNTestSuiteRegister(RefTest, "expr/RefTest"); |
| 305 |
nothing calls this directly
no test coverage detected