@@ -182,30 +182,37 @@ class CheckTest : public ::testing::Test {
182182 /* outputs=*/ nullptr , iree_allocator_system ());
183183 }
184184
185- iree_status_t InvokeValue (const char * function_name,
186- std::vector<iree_vm_value_t > args) {
185+ iree_status_t Invoke (const char * function_name,
186+ std::vector<vm::ref<iree_hal_buffer_view_t >> buffer_args,
187+ std::vector<iree_vm_value_t > value_args) {
187188 IREE_RETURN_IF_ERROR (
188- iree_vm_list_create (iree_vm_make_undefined_type_def (), args.size (),
189+ iree_vm_list_create (iree_vm_make_undefined_type_def (),
190+ buffer_args.size () + value_args.size (),
189191 iree_allocator_system (), &inputs_));
190- for (auto & arg : args) {
192+ if (!buffer_args.empty ()) {
193+ iree_vm_ref_t device_ref = iree_hal_device_retain_ref (device_);
194+ IREE_RETURN_IF_ERROR (
195+ iree_vm_list_push_ref_move (inputs_.get (), &device_ref));
196+ for (auto & arg : buffer_args) {
197+ iree_vm_ref_t arg_ref = iree_hal_buffer_view_retain_ref (arg.get ());
198+ IREE_RETURN_IF_ERROR (
199+ iree_vm_list_push_ref_move (inputs_.get (), &arg_ref));
200+ }
201+ }
202+ for (auto & arg : value_args) {
191203 IREE_RETURN_IF_ERROR (iree_vm_list_push_value (inputs_.get (), &arg));
192204 }
193205 return Invoke (function_name);
194206 }
195207
208+ iree_status_t InvokeValue (const char * function_name,
209+ std::vector<iree_vm_value_t > args) {
210+ return Invoke (function_name, /* buffer_args=*/ {}, args);
211+ }
212+
196213 iree_status_t Invoke (const char * function_name,
197214 std::vector<vm::ref<iree_hal_buffer_view_t >> args) {
198- IREE_RETURN_IF_ERROR (
199- iree_vm_list_create (iree_vm_make_undefined_type_def (), args.size (),
200- iree_allocator_system (), &inputs_));
201- iree_vm_ref_t device_ref = iree_hal_device_retain_ref (device_);
202- IREE_RETURN_IF_ERROR (
203- iree_vm_list_push_ref_move (inputs_.get (), &device_ref));
204- for (auto & arg : args) {
205- iree_vm_ref_t arg_ref = iree_hal_buffer_view_retain_ref (arg.get ());
206- IREE_RETURN_IF_ERROR (iree_vm_list_push_ref_move (inputs_.get (), &arg_ref));
207- }
208- return Invoke (function_name);
215+ return Invoke (function_name, args, /* value_args=*/ {});
209216 }
210217
211218 static iree_hal_device_t *& device () { return CheckTest::device_; }
@@ -432,8 +439,9 @@ TEST_F(CheckTest, ExpectAlmostEqSameBufferSuccess) {
432439 iree_hal_dim_t shape[] = {1 };
433440 ASSERT_NO_FATAL_FAILURE (
434441 CreateFloat32BufferView (contents, shape, &input_buffer_view));
435- IREE_ASSERT_OK (
436- Invoke (" expect_almost_eq" , {input_buffer_view, input_buffer_view}));
442+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" ,
443+ {input_buffer_view, input_buffer_view},
444+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )}));
437445}
438446
439447TEST_F (CheckTest, ExpectAlmostEqIdenticalBufferSuccess) {
@@ -443,7 +451,8 @@ TEST_F(CheckTest, ExpectAlmostEqIdenticalBufferSuccess) {
443451 iree_hal_dim_t shape[] = {1 };
444452 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, shape, &lhs));
445453 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, shape, &rhs));
446- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs}));
454+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
455+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )}));
447456}
448457
449458TEST_F (CheckTest, ExpectAlmostEqNearIdenticalBufferSuccess) {
@@ -454,7 +463,8 @@ TEST_F(CheckTest, ExpectAlmostEqNearIdenticalBufferSuccess) {
454463 iree_hal_dim_t shape[] = {4 };
455464 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (lhs_contents, shape, &lhs));
456465 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (rhs_contents, shape, &rhs));
457- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs}));
466+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
467+ {/* tolerance=*/ iree_vm_value_make_f32 (1 .e -4f )}));
458468}
459469
460470TEST_F (CheckTest, ExpectAlmostEqIdentical3DBufferSuccess) {
@@ -464,7 +474,8 @@ TEST_F(CheckTest, ExpectAlmostEqIdentical3DBufferSuccess) {
464474 iree_hal_dim_t shape[] = {2 , 2 , 2 };
465475 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, shape, &lhs));
466476 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, shape, &rhs));
467- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs}));
477+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
478+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )}));
468479}
469480
470481TEST_F (CheckTest, ExpectAlmostEqDifferentShapeFailure) {
@@ -476,7 +487,8 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentShapeFailure) {
476487 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, lhs_shape, &lhs));
477488 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (contents, rhs_shape, &rhs));
478489 EXPECT_NONFATAL_FAILURE (
479- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
490+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
491+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )})),
480492 " Shapes do not match" );
481493}
482494
@@ -492,7 +504,8 @@ TEST_F(CheckTest, ExpectAlmostEqSmallerLhsElementCountFailure) {
492504 ASSERT_NO_FATAL_FAILURE (
493505 CreateFloat32BufferView (bigger_contents, bigger_shape, &bigger));
494506 EXPECT_NONFATAL_FAILURE (
495- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {smaller, bigger})),
507+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {smaller, bigger},
508+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )})),
496509 " Shapes do not match" );
497510}
498511
@@ -508,7 +521,8 @@ TEST_F(CheckTest, ExpectAlmostEqSmallerRhsElementCountFailure) {
508521 ASSERT_NO_FATAL_FAILURE (
509522 CreateFloat32BufferView (bigger_contents, bigger_shape, &bigger));
510523 EXPECT_NONFATAL_FAILURE (
511- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {bigger, smaller})),
524+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {bigger, smaller},
525+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )})),
512526 " Shapes do not match" );
513527}
514528
@@ -521,7 +535,8 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentElementTypeFailure) {
521535 ASSERT_NO_FATAL_FAILURE (CreateFloat64BufferView (lhs_contents, shape, &lhs));
522536 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (rhs_contents, shape, &rhs));
523537 EXPECT_NONFATAL_FAILURE (
524- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
538+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
539+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )})),
525540 " Element types do not match" );
526541}
527542
@@ -534,7 +549,8 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentContentsFailure) {
534549 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (lhs_contents, shape, &lhs));
535550 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (rhs_contents, shape, &rhs));
536551 EXPECT_NONFATAL_FAILURE (
537- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
552+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
553+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .1f )})),
538554 " Contents does not match" );
539555}
540556
@@ -552,7 +568,8 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentEverythingFullMessageFailure) {
552568 // Note no comment on contents. Cannot compare different shapes and element
553569 // types.
554570 EXPECT_NONFATAL_FAILURE (
555- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
571+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
572+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )})),
556573 " Expected near equality of these values. Element types do not match."
557574 " Shapes do not match.\n "
558575 " lhs:\n "
@@ -570,8 +587,10 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentContents3DFullMessageFailure) {
570587 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (lhs_contents, shape, &lhs));
571588 ASSERT_NO_FATAL_FAILURE (CreateFloat32BufferView (rhs_contents, shape, &rhs));
572589 EXPECT_NONFATAL_FAILURE (
573- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
574- " Expected near equality of these values. Contents does not match.\n "
590+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
591+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .1f )})),
592+ " Expected near equality of these values. Contents does not match to "
593+ " tolerance=0.1.\n "
575594 " lhs:\n "
576595 " 2x2x2xf32=[[1 2][3 4]][[5 6][7 8]]\n "
577596 " rhs:\n "
@@ -585,22 +604,24 @@ TEST_F(CheckTest, ExpectAlmostEqIdenticalBufferF16Success) {
585604 iree_hal_dim_t shape[] = {1 };
586605 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (contents, shape, &lhs));
587606 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (contents, shape, &rhs));
588- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs}));
607+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
608+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .f )}));
589609}
590610
591611TEST_F (CheckTest, ExpectAlmostEqNearIdenticalBufferF16Success) {
592612 vm::ref<iree_hal_buffer_view_t > lhs;
593613 vm::ref<iree_hal_buffer_view_t > rhs;
594614 uint16_t lhs_contents[] = {
595- iree_math_f32_to_f16 (1 .0f ), iree_math_f32_to_f16 (1 .99999f ),
596- iree_math_f32_to_f16 (0 .00001f ), iree_math_f32_to_f16 (4 .0f )};
615+ iree_math_f32_to_f16 (1 .0f ), iree_math_f32_to_f16 (1 .999f ),
616+ iree_math_f32_to_f16 (0 .001f ), iree_math_f32_to_f16 (4 .0f )};
597617 uint16_t rhs_contents[] = {
598- iree_math_f32_to_f16 (1 .00001f ), iree_math_f32_to_f16 (2 .0f ),
618+ iree_math_f32_to_f16 (1 .001f ), iree_math_f32_to_f16 (2 .0f ),
599619 iree_math_f32_to_f16 (0 .0f ), iree_math_f32_to_f16 (4 .0f )};
600620 iree_hal_dim_t shape[] = {4 };
601621 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (lhs_contents, shape, &lhs));
602622 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (rhs_contents, shape, &rhs));
603- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs}));
623+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
624+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .01f )}));
604625}
605626
606627TEST_F (CheckTest, ExpectAlmostEqDifferentContentsF16Failure) {
@@ -612,7 +633,8 @@ TEST_F(CheckTest, ExpectAlmostEqDifferentContentsF16Failure) {
612633 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (lhs_contents, shape, &lhs));
613634 ASSERT_NO_FATAL_FAILURE (CreateFloat16BufferView (rhs_contents, shape, &rhs));
614635 EXPECT_NONFATAL_FAILURE (
615- IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs})),
636+ IREE_ASSERT_OK (Invoke (" expect_almost_eq" , {lhs, rhs},
637+ {/* tolerance=*/ iree_vm_value_make_f32 (0 .1f )})),
616638 " Contents does not match" );
617639}
618640} // namespace
0 commit comments