@@ -29,10 +29,10 @@ namespace
29
29
30
30
using namespace onert ::ir;
31
31
32
- class CompiledMockUpModel
32
+ class MockUpModel
33
33
{
34
34
public:
35
- CompiledMockUpModel ()
35
+ MockUpModel ()
36
36
{
37
37
// Model: two elementwise add operation
38
38
// model input: lhs, rhs1
@@ -76,12 +76,17 @@ class CompiledMockUpModel
76
76
graph->addOutput (operand_result2);
77
77
graph->verify ();
78
78
79
- // Compile
79
+ // Initialize compile option
80
+ coptions = onert::compiler::CompilerOptions::fromGlobalConfig ();
81
+ }
82
+
83
+ void compile ()
84
+ {
80
85
auto model = std::make_shared<onert::ir::Model>();
81
86
model->push (onert::ir::SubgraphIndex{0 }, graph);
82
- coptions = onert::compiler::CompilerOptions::fromGlobalConfig ();
83
- auto compiler = onert::compiler::CompilerFactory::get ().create (std::make_unique<NNPkg>(model),
84
- coptions.get ());
87
+ // Compile copied nnpkg to handle multiple compilation
88
+ auto compiler = onert::compiler::CompilerFactory::get ().create (
89
+ std::make_unique<onert::ir::NNPkg>(model), coptions.get ());
85
90
artifact = compiler->compile ();
86
91
}
87
92
@@ -301,8 +306,8 @@ class CompiledMockUpQuantModelToFloat
301
306
302
307
TEST (ExecInstance, simple)
303
308
{
304
- auto mockup = CompiledMockUpModel ();
305
- auto graph = mockup.graph ;
309
+ auto mockup = MockUpModel ();
310
+ mockup.compile () ;
306
311
auto executors = mockup.artifact ->_executors ;
307
312
308
313
auto input1 = IOIndex{0 };
@@ -327,10 +332,74 @@ TEST(ExecInstance, simple)
327
332
}
328
333
}
329
334
335
+ TEST (ExecInstance, shapeinf)
336
+ {
337
+ auto mockup = MockUpModel ();
338
+ mockup.compile ();
339
+ auto executors = mockup.artifact ->_executors ;
340
+
341
+ auto input1 = IOIndex{0 };
342
+ auto input2 = IOIndex{1 };
343
+ auto output = IOIndex{0 };
344
+
345
+ const onert::ir::Shape new_shape{2 , 2 , 2 , 1 };
346
+ const float input1_buffer[8 ] = {1 , 0 , -1 , -2 , 1 , 2 , 0 , -1 };
347
+ const float input2_buffer[8 ] = {1 , -3 , 2 , -4 , 4 , -2 , 3 , 1 };
348
+ float output_buffer[8 ] = {};
349
+ const float output_expected[8 ] = {5 , -2 , 0 , -1 , 8 , 1 , 2 , 5 };
350
+
351
+ onert::exec::Execution execution{executors};
352
+
353
+ execution.changeInputShape (input1, new_shape);
354
+ execution.changeInputShape (input2, new_shape);
355
+ execution.setInput (input1, reinterpret_cast <const void *>(input1_buffer), 32 );
356
+ execution.setInput (input2, reinterpret_cast <const void *>(input2_buffer), 32 );
357
+ execution.setOutput (output, reinterpret_cast <void *>(output_buffer), 32 );
358
+ execution.execute ();
359
+
360
+ EXPECT_EQ (execution.outputInfo (0 ).shape (), new_shape);
361
+ for (auto i = 0 ; i < 8 ; i++)
362
+ {
363
+ EXPECT_EQ (output_buffer[i], output_expected[i]);
364
+ }
365
+ }
366
+
367
+ TEST (ExecInstance, internaloutput_shapeinf)
368
+ {
369
+ auto mockup = MockUpModel ();
370
+ mockup.coptions ->internal_output_alloc = true ;
371
+ mockup.compile ();
372
+ auto executors = mockup.artifact ->_executors ;
373
+
374
+ auto input1 = IOIndex{0 };
375
+ auto input2 = IOIndex{1 };
376
+ auto output = IOIndex{0 };
377
+
378
+ const onert::ir::Shape new_shape{2 , 2 , 2 , 1 };
379
+ const float input1_buffer[8 ] = {1 , 0 , -1 , -2 , 1 , 2 , 0 , -1 };
380
+ const float input2_buffer[8 ] = {1 , -3 , 2 , -4 , 4 , -2 , 3 , 1 };
381
+ const float output_expected[8 ] = {5 , -2 , 0 , -1 , 8 , 1 , 2 , 5 };
382
+
383
+ onert::exec::Execution execution{executors};
384
+
385
+ execution.changeInputShape (input1, new_shape);
386
+ execution.changeInputShape (input2, new_shape);
387
+ execution.setInput (input1, reinterpret_cast <const void *>(input1_buffer), 32 );
388
+ execution.setInput (input2, reinterpret_cast <const void *>(input2_buffer), 32 );
389
+ execution.execute ();
390
+
391
+ const float *output_buffer = reinterpret_cast <const float *>(executors->outputBuffer (output));
392
+ EXPECT_EQ (execution.outputInfo (0 ).shape (), new_shape);
393
+ for (auto i = 0 ; i < 8 ; i++)
394
+ {
395
+ EXPECT_EQ (output_buffer[i], output_expected[i]);
396
+ }
397
+ }
398
+
330
399
TEST (ExecInstance, neg_small_outputbuffer)
331
400
{
332
- auto mockup = CompiledMockUpModel ();
333
- auto graph = mockup.graph ;
401
+ auto mockup = MockUpModel ();
402
+ mockup.compile () ;
334
403
auto executors = mockup.artifact ->_executors ;
335
404
336
405
auto input1 = IOIndex{0 };
@@ -351,8 +420,8 @@ TEST(ExecInstance, neg_small_outputbuffer)
351
420
352
421
TEST (ExecInstance, neg_small_inoutsize)
353
422
{
354
- auto mockup = CompiledMockUpModel ();
355
- auto graph = mockup.graph ;
423
+ auto mockup = MockUpModel ();
424
+ mockup.compile () ;
356
425
auto executors = mockup.artifact ->_executors ;
357
426
358
427
auto input1 = IOIndex{0 };
@@ -385,7 +454,8 @@ TEST(ExecInstance, neg_small_inoutsize)
385
454
386
455
TEST (ExecInstance, twoCompile)
387
456
{
388
- auto mockup = CompiledMockUpModel ();
457
+ auto mockup = MockUpModel ();
458
+ mockup.compile ();
389
459
auto graph = mockup.graph ;
390
460
auto executors1 = mockup.artifact ->_executors ;
391
461
onert::exec::Execution execution1{executors1};
@@ -434,7 +504,8 @@ TEST(ExecInstance, twoCompile)
434
504
// Support two initialized execution instance then ordered execution
435
505
TEST (ExecInstance, twoExecution)
436
506
{
437
- auto mockup = CompiledMockUpModel ();
507
+ auto mockup = MockUpModel ();
508
+ mockup.compile ();
438
509
auto executors = mockup.artifact ->_executors ;
439
510
auto input1 = IOIndex{0 };
440
511
auto input2 = IOIndex{1 };
@@ -533,7 +604,8 @@ class Inference
533
604
// Support multi-thread execution
534
605
TEST (ExecInstance, twoThreads)
535
606
{
536
- auto mockup = CompiledMockUpModel ();
607
+ auto mockup = MockUpModel ();
608
+ mockup.compile ();
537
609
auto executors = mockup.artifact ->_executors ;
538
610
539
611
const float exe1_input1_buffer[4 ] = {1 , 0 , -1 , -2 };
@@ -566,8 +638,8 @@ TEST(ExecInstance, twoThreads)
566
638
// Support asynchronous execution
567
639
TEST (ExecInstance, async)
568
640
{
569
- auto mockup = CompiledMockUpModel ();
570
- auto graph = mockup.graph ;
641
+ auto mockup = MockUpModel ();
642
+ mockup.compile () ;
571
643
auto executors = mockup.artifact ->_executors ;
572
644
573
645
auto input1 = IOIndex{0 };
0 commit comments