|
17 | 17 | #ifdef PA_AutoDispatch_arm64_20_M1
|
18 | 18 | #include "Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_64x8_arm64_NEON.h"
|
19 | 19 | #include "Kernels/PartialWordAccess/Kernels_PartialWordAccess_arm64_NEON.h"
|
| 20 | + #include "Kernels/Waterfill/Kernels_Waterfill_Core_64x8_arm64_NEON.h" |
20 | 21 | #endif
|
| 22 | +#include "Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64xH_Default.h" |
| 23 | +#include "Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_64x4_Default.h" |
21 | 24 | #include "Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_64xH_Default.h"
|
22 | 25 | #include "Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters.h"
|
23 | 26 | #include "Kernels/ImageFilters/Kernels_ImageFilter_Basic.h"
|
24 | 27 | #include "Kernels/ImageScaleBrightness/Kernels_ImageScaleBrightness.h"
|
| 28 | +#include "Kernels/Waterfill/Kernels_Waterfill.h" |
| 29 | +#include "Kernels/Waterfill/Kernels_Waterfill_Session.h" |
| 30 | +#include "Kernels/Waterfill/Kernels_Waterfill_Core_64xH_Default.h" |
| 31 | +#include "Kernels/Waterfill/Kernels_Waterfill_Routines.h" |
25 | 32 | #include "Kernels_Tests.h"
|
26 | 33 | #include "TestUtils.h"
|
27 | 34 |
|
@@ -593,20 +600,74 @@ int test_kernels_CompressRGB32ToBinaryEuclidean(const ImageViewRGB32& image){
|
593 | 600 |
|
594 | 601 |
|
595 | 602 | int test_kernels_Waterfill(const ImageViewRGB32& image){
|
| 603 | + const size_t width = image.width(); |
| 604 | + const size_t height = image.height(); |
| 605 | + cout << "Testing test_kernels_Waterfill(), image size " << width << " x " << height << endl; |
596 | 606 |
|
597 |
| - ImagePixelBox box(0, 0, image.width(), image.height()); |
598 |
| - ImageViewRGB32 sub_image = extract_box_reference(image, box); |
599 |
| - |
600 |
| - PackedBinaryMatrix matrix(sub_image.width(), sub_image.height()); |
| 607 | + PackedBinaryMatrix matrix(width, height); |
601 | 608 | uint32_t mins = combine_rgb(0, 0, 0);
|
602 | 609 | // uint32_t maxs = combine_rgb(255, 255, 255);
|
603 | 610 | uint32_t maxs = combine_rgb(63, 63, 63);
|
604 | 611 | Kernels::compress_rgb32_to_binary_range(
|
605 |
| - sub_image.data(), sub_image.bytes_per_row(), |
| 612 | + image.data(), image.bytes_per_row(), |
606 | 613 | matrix, mins, maxs
|
607 | 614 | );
|
608 | 615 |
|
609 |
| - cout << matrix.dump() << flush; |
| 616 | + PackedBinaryMatrix source_matrix = matrix.copy(); |
| 617 | + |
| 618 | + PackedBinaryMatrix gt_matrix = matrix.copy(); |
| 619 | + Kernels::PackedBinaryMatrix_IB& gt_matrix_ib = gt_matrix; |
| 620 | + |
| 621 | + size_t min_area = 10; |
| 622 | + std::vector<Kernels::Waterfill::WaterfillObject> gt_objects; |
| 623 | + bool gt_computed = false; |
| 624 | + |
| 625 | +#ifdef PA_AutoDispatch_arm64_20_M1 |
| 626 | + if (CPU_CAPABILITY_CURRENT.OK_M1){ |
| 627 | + using Waterfill_64x8_Default = Kernels::Waterfill::Waterfill_64xH_Default<Kernels::BinaryTile_64x8_arm64_NEON>; |
| 628 | + gt_objects = Kernels::Waterfill::find_objects_inplace<Kernels::BinaryTile_64x8_arm64_NEON, Waterfill_64x8_Default>( |
| 629 | + static_cast<Kernels::PackedBinaryMatrix_64x8_arm64_NEON&>(gt_matrix_ib).get(), |
| 630 | + min_area |
| 631 | + ); |
| 632 | + gt_computed = true; |
| 633 | + } |
| 634 | +#endif |
| 635 | + if (gt_computed == false){ |
| 636 | + using Waterfill_64x4_Default = Kernels::Waterfill::Waterfill_64xH_Default<Kernels::BinaryTile_64x4_Default>; |
| 637 | + gt_objects = Kernels::Waterfill::find_objects_inplace<Kernels::BinaryTile_64x4_Default, Waterfill_64x4_Default>( |
| 638 | + static_cast<Kernels::PackedBinaryMatrix_64x4_Default&>(gt_matrix_ib).get(), |
| 639 | + min_area |
| 640 | + ); |
| 641 | + } |
| 642 | + cout << "num objects: " << gt_objects.size() << endl; |
| 643 | + |
| 644 | + auto time_start = current_time(); |
| 645 | + std::vector<Kernels::Waterfill::WaterfillObject> objects = Kernels::Waterfill::find_objects_inplace(matrix, min_area); |
| 646 | + auto time_end = current_time(); |
| 647 | + auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(time_end - time_start).count(); |
| 648 | + auto ms = ns / 1000000.; |
| 649 | + cout << "One waterfill time: " << ms << " ms" << endl; |
| 650 | + |
| 651 | + for(size_t i = 0; i < objects.size(); ++i){ |
| 652 | + TEST_RESULT_COMPONENT_EQUAL(objects[i].area, gt_objects[i].area, "object " + std::to_string(i) + " area"); |
| 653 | + TEST_RESULT_COMPONENT_EQUAL(objects[i].min_x, gt_objects[i].min_x, "object " + std::to_string(i) + " min_x"); |
| 654 | + TEST_RESULT_COMPONENT_EQUAL(objects[i].min_y, gt_objects[i].min_y, "object " + std::to_string(i) + " min_y"); |
| 655 | + TEST_RESULT_COMPONENT_EQUAL(objects[i].max_x, gt_objects[i].max_x, "object " + std::to_string(i) + " max_x"); |
| 656 | + TEST_RESULT_COMPONENT_EQUAL(objects[i].max_y, gt_objects[i].max_y, "object " + std::to_string(i) + " max_y"); |
| 657 | + } |
| 658 | + |
| 659 | + // We try to wait for three seconds: |
| 660 | + const size_t num_iters = size_t(3000 / ms); |
| 661 | + time_start = current_time(); |
| 662 | + for(size_t i = 0; i < num_iters; i++){ |
| 663 | + matrix = source_matrix.copy(); |
| 664 | + objects = Kernels::Waterfill::find_objects_inplace(matrix, min_area); |
| 665 | + } |
| 666 | + time_end = current_time(); |
| 667 | + ms = (double)std::chrono::duration_cast<Milliseconds>(time_end - time_start).count(); |
| 668 | + cout << "Running " << num_iters << " iters, avg filter time: " << ms / num_iters << " ms" << endl; |
| 669 | + |
| 670 | + |
610 | 671 |
|
611 | 672 | return 0;
|
612 | 673 | }
|
|
0 commit comments