From d303aa2703f2b3a7e25cad9905e6379a00312f4f Mon Sep 17 00:00:00 2001 From: zouaoui Date: Mon, 13 Mar 2023 15:07:17 +0100 Subject: [PATCH 01/12] Creating files --- clic/include/tier1/cleCropKernel.hpp | 0 clic/src/tier1/cleCropKernel.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 clic/include/tier1/cleCropKernel.hpp create mode 100644 clic/src/tier1/cleCropKernel.cpp diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/clic/src/tier1/cleCropKernel.cpp b/clic/src/tier1/cleCropKernel.cpp new file mode 100644 index 000000000..e69de29bb From 8cd8778d01ad89a21c62dfc8e116addac8c88e03 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Mon, 13 Mar 2023 16:46:09 +0100 Subject: [PATCH 02/12] Implementing funtions for cleCropKernel.hpp --- clic/include/tier1/cleCropKernel.hpp | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index e69de29bb..388395546 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -0,0 +1,51 @@ + +#ifndef __TIER1_CLECROPKERNEL_HPP +#define __TIER1_CLECROPKERNEL_HPP + +#include "cleOperation.hpp" + +namespace cle +{ + +class CropKernel : public Operation +{ + public: + explicit CropKernel(const ProcessorPointer & device); + + auto + SetInput(const Image & object) -> void; + + auto + SetOutput(const Image & object) -> void; + + auto + SetIndex1(const Int & index) -> void; + + auto + SetIndex2(const Int & index) -> void; + + auto + SetIndex3(const Int & index) -> void; + +}; + +CropKernel_Call(const std::sharedptr & device, + const Image & src, + const Image & dst, + const Int & index0, + const Int & index1, + const Int & index2 + ) -> void +{ + CropKernel kernel(device); + kernel.SetInput(src); + kernel.SetOutput(dst); + kernel.SetIndex1(index0); + kernel.SetIndex2(index1); + kernel.SetIndex3(index2); + kernel.Execute(); +} + +} + +#endif \ No newline at end of file From 9988f7c6ec20372f8664569840efb090d339e6b2 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Mon, 13 Mar 2023 17:06:53 +0100 Subject: [PATCH 03/12] Implementing cleCropkernel.cpp --- clic/include/tier1/cleCropKernel.hpp | 6 ++-- clic/src/tier1/cleCropKernel.cpp | 43 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index 388395546..aa2092775 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -19,13 +19,13 @@ class CropKernel : public Operation SetOutput(const Image & object) -> void; auto - SetIndex1(const Int & index) -> void; + SetIndex1(const int & index) -> void; auto - SetIndex2(const Int & index) -> void; + SetIndex2(const int & index) -> void; auto - SetIndex3(const Int & index) -> void; + SetIndex3(const int & index) -> void; }; diff --git a/clic/src/tier1/cleCropKernel.cpp b/clic/src/tier1/cleCropKernel.cpp index e69de29bb..8f103d359 100644 --- a/clic/src/tier1/cleCropKernel.cpp +++ b/clic/src/tier1/cleCropKernel.cpp @@ -0,0 +1,43 @@ + +#include "cleCropKernel.hpp" +namespace cle +{ + CropKernel::CropKernel(const ProcessorPointer & device) : + Operation(device, 5) + { + std::string cl_header = { + #include "cle_crop.h" + }; + this->SetSource("crop", cl_header); + } + + auto + CropKernel::SetInput(const Image & object) -> void + { + this->AddParameter("src", object); + } + + auto + CropKernel::SetOutput(const Image & object) -> void + { + this->AddParameter("dst", object); + } + + auto + CropKernel::SetIndex1(const int & index) -> void + { + this->AddParameter("index0", index); + } + + auto + CropKernel::SetIndex2(const int & index) -> void + { + this->AddParameter("index1", index); + } + + auto + CropKernel::SetIndex3(const int & index) -> void + { + this->AddParameter("index2", index); + } +} From f4ca3dd7da3057523468d6235b25bb349b97cc93 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Mon, 13 Mar 2023 17:28:22 +0100 Subject: [PATCH 04/12] Implementing clesperanto (.hpp and .cpp) --- clic/include/core/clesperanto.hpp | 6 ++++++ clic/src/core/clesperanto.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/clic/include/core/clesperanto.hpp b/clic/include/core/clesperanto.hpp index fa604feb2..0b7383373 100644 --- a/clic/include/core/clesperanto.hpp +++ b/clic/include/core/clesperanto.hpp @@ -95,6 +95,12 @@ class Clesperanto auto ConnectedComponentLabelingBox(const Image & source, const Image & destination) -> void; + auto + Crop(const Image & source, const Image & destination, + const int & index0 = 0, + const int & index1 = 0, + const int & index2 = 0) -> void; + auto Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void; diff --git a/clic/src/core/clesperanto.cpp b/clic/src/core/clesperanto.cpp index 81e28d192..9f4f3012e 100644 --- a/clic/src/core/clesperanto.cpp +++ b/clic/src/core/clesperanto.cpp @@ -120,6 +120,15 @@ Clesperanto::BinaryXor(const Image & source1, const Image & source2, const Image kernel.Execute(); } +auto +Clesperanto::Crop(const Image & source, const Image & destination, + const int & index0, + const int & index1, + const int & index2) -> void +{ + CropKernel_Call(this->getDevice(), source, destination, index0, index1, index2) +} + auto Clesperanto::Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void { From 7019eee7eb958b1f97a3764f1dda1ee48ececc72 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Tue, 14 Mar 2023 12:25:04 +0100 Subject: [PATCH 05/12] Error correction --- clic/include/tier1/cleCropKernel.hpp | 9 +++++---- clic/src/core/clesperanto.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index aa2092775..173587376 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -29,12 +29,13 @@ class CropKernel : public Operation }; -CropKernel_Call(const std::sharedptr & device, +inline auto +CropKernel_Call(const std::shared_ptr & device, const Image & src, const Image & dst, - const Int & index0, - const Int & index1, - const Int & index2 + const int & index0, + const int & index1, + const int & index2 ) -> void { CropKernel kernel(device); diff --git a/clic/src/core/clesperanto.cpp b/clic/src/core/clesperanto.cpp index 9f4f3012e..b7310be8b 100644 --- a/clic/src/core/clesperanto.cpp +++ b/clic/src/core/clesperanto.cpp @@ -126,7 +126,7 @@ Clesperanto::Crop(const Image & source, const Image & destination, const int & index1, const int & index2) -> void { - CropKernel_Call(this->getDevice(), source, destination, index0, index1, index2) + CropKernel_Call(this->GetDevice(), source, destination, index0, index1, index2); } auto From 3ae575d8a6f34d8435ef9ae4b95e2f1d9f68a6cd Mon Sep 17 00:00:00 2001 From: zouaoui Date: Tue, 14 Mar 2023 16:11:35 +0100 Subject: [PATCH 06/12] Adding tests and fixing some errors --- clic/include/core/clesperanto.hpp | 12 ++++----- clic/src/core/clesperanto.cpp | 12 ++++----- clic/src/tier1/cleCropKernel.cpp | 3 ++- tests/CMakeLists.txt | 8 ++++++ tests/crop_test.cpp | 42 +++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 tests/crop_test.cpp diff --git a/clic/include/core/clesperanto.hpp b/clic/include/core/clesperanto.hpp index 0b7383373..71e20284a 100644 --- a/clic/include/core/clesperanto.hpp +++ b/clic/include/core/clesperanto.hpp @@ -94,12 +94,6 @@ class Clesperanto auto ConnectedComponentLabelingBox(const Image & source, const Image & destination) -> void; - - auto - Crop(const Image & source, const Image & destination, - const int & index0 = 0, - const int & index1 = 0, - const int & index2 = 0) -> void; auto Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void; @@ -107,6 +101,12 @@ class Clesperanto auto Copy(const Image & source, const Image & destination) -> void; + auto + Crop(const Image & source, const Image & destination, + const int & index0 = 0, + const int & index1 = 0, + const int & index2 = 0) -> void; + auto DetectMaximaBox(const Image & source, const Image & destination) -> void; diff --git a/clic/src/core/clesperanto.cpp b/clic/src/core/clesperanto.cpp index b7310be8b..2d051a3dc 100644 --- a/clic/src/core/clesperanto.cpp +++ b/clic/src/core/clesperanto.cpp @@ -120,6 +120,12 @@ Clesperanto::BinaryXor(const Image & source1, const Image & source2, const Image kernel.Execute(); } +auto +Clesperanto::Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void +{ + ConvolveKernel_Call(this->GetDevice(), source, convolve_kernel, destination); +} + auto Clesperanto::Crop(const Image & source, const Image & destination, const int & index0, @@ -129,12 +135,6 @@ Clesperanto::Crop(const Image & source, const Image & destination, CropKernel_Call(this->GetDevice(), source, destination, index0, index1, index2); } -auto -Clesperanto::Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void -{ - ConvolveKernel_Call(this->GetDevice(), source, convolve_kernel, destination); -} - auto Clesperanto::SubtractImages(const Image & source1, const Image & source2, const Image & destination) -> void { diff --git a/clic/src/tier1/cleCropKernel.cpp b/clic/src/tier1/cleCropKernel.cpp index 8f103d359..51a572bfe 100644 --- a/clic/src/tier1/cleCropKernel.cpp +++ b/clic/src/tier1/cleCropKernel.cpp @@ -1,5 +1,6 @@ -#include "cleCropKernel.hpp" +#include "cleCropKernel.hpp" + namespace cle { CropKernel::CropKernel(const ProcessorPointer & device) : diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 08dfcba37..894cbe2b7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -112,6 +112,12 @@ target_link_libraries(copy_test PRIVATE CLIc::CLIc) set_target_properties(copy_test PROPERTIES FOLDER "Tests") target_compile_features(copy_test PRIVATE cxx_std_17) +add_executable(crop_test crop_test.cpp) +add_dependencies(crop_test CLIc) +target_link_libraries(crop_test PRIVATE CLIc::CLIc) +set_target_properties(crop_test PROPERTIES FOLDER "Tests") +target_compile_features(crop_test PRIVATE cxx_std_17) + add_executable(detect_maxima_test detect_maxima_test.cpp) add_dependencies(detect_maxima_test CLIc) target_link_libraries(detect_maxima_test PRIVATE CLIc::CLIc) @@ -468,6 +474,7 @@ add_test(NAME close_indexgaps_in_labelmap_test WORKING_DIRECTORY ${CMAKE_CURRENT add_test(NAME connected_component_labeling_box_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND connected_component_labeling_box_test) add_test(NAME convolve_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND convolve_test) add_test(NAME copy_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND copy_test) +add_test(NAME crop_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND crop_test) add_test(NAME detect_maxima_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND detect_maxima_test) add_test(NAME difference_of_gaussian_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND difference_of_gaussian_test) add_test(NAME dilate_sphere_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND dilate_sphere_test) @@ -548,6 +555,7 @@ set_tests_properties(absolute_test connected_component_labeling_box_test convolve_test copy_test + crop_test detect_maxima_test difference_of_gaussian_test dilate_sphere_test diff --git a/tests/crop_test.cpp b/tests/crop_test.cpp new file mode 100644 index 000000000..1e1b5bd15 --- /dev/null +++ b/tests/crop_test.cpp @@ -0,0 +1,42 @@ + +#include + +#include "clesperanto.hpp" + +template +auto +run_test(const std::array & shape, const cle::MemoryType & mem_type) -> bool +{ + //std::vector input(shape[0] * shape[1] * shape[2]); + //std::vector valid(shape[0] * shape[1] * shape[2]); + + std::vector input{1, 0, 1, 0, 0, 0, 0, 1, 0}; + std::vector valid{2, 1, 2, 1, 1, 1, 1, 2, 1}; + + const int index0 = 1; + const int index1 = 1; + const int index2 = 1; + + //std::fill(input.begin(), input.end(), static_cast(value)); + //std::fill(valid.begin(), valid.end(), static_cast ); + + cle::Clesperanto cle; + cle.GetDevice()->WaitForKernelToFinish(); + auto gpu_input = cle.Push(input, shape, mem_type); + auto gpu_output = cle.Create(shape, mem_type); + cle.Crop(gpu_input, gpu_output, index0, index1, index2); + auto output = cle.Pull(gpu_output); + + return std::equal(output.begin(), output.end(), valid.begin()); + + +} + +auto +main(int argc, char ** argv) -> int +{ + if(!run_test({9, 1, 1}, cle::BUFFER)) + { + return EXIT_FAILURE; + } +} \ No newline at end of file From de524adc99d9a093562bfe44fcdcea8781d7674c Mon Sep 17 00:00:00 2001 From: zouaoui Date: Wed, 15 Mar 2023 09:59:20 +0100 Subject: [PATCH 07/12] New example in the crop_test --- tests/crop_test.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/crop_test.cpp b/tests/crop_test.cpp index 1e1b5bd15..17c6a6030 100644 --- a/tests/crop_test.cpp +++ b/tests/crop_test.cpp @@ -10,33 +10,34 @@ run_test(const std::array & shape, const cle::MemoryType & mem_type) //std::vector input(shape[0] * shape[1] * shape[2]); //std::vector valid(shape[0] * shape[1] * shape[2]); - std::vector input{1, 0, 1, 0, 0, 0, 0, 1, 0}; - std::vector valid{2, 1, 2, 1, 1, 1, 1, 2, 1}; + std::vector input{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + std::vector valid{6, 7, 10, 11}; const int index0 = 1; const int index1 = 1; - const int index2 = 1; + const int index2 = 0; //std::fill(input.begin(), input.end(), static_cast(value)); //std::fill(valid.begin(), valid.end(), static_cast ); cle::Clesperanto cle; cle.GetDevice()->WaitForKernelToFinish(); - auto gpu_input = cle.Push(input, shape, mem_type); - auto gpu_output = cle.Create(shape, mem_type); + auto gpu_input = cle.Push(input, shape, mem_type); + auto gpu_output = cle.Create({2, 2, 1}, mem_type); cle.Crop(gpu_input, gpu_output, index0, index1, index2); - auto output = cle.Pull(gpu_output); + auto output = cle.Pull(gpu_output); return std::equal(output.begin(), output.end(), valid.begin()); - - + } auto main(int argc, char ** argv) -> int { - if(!run_test({9, 1, 1}, cle::BUFFER)) + if(!run_test({4, 4, 1}, cle::BUFFER)) { return EXIT_FAILURE; } + + return EXIT_SUCCESS; } \ No newline at end of file From ddb0a0164aa797c34ab89096388cea22e2d044b9 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Wed, 15 Mar 2023 14:38:38 +0100 Subject: [PATCH 08/12] Format correction --- clic/include/core/clesperanto.hpp | 13 ++--- clic/include/tier1/cleCropKernel.hpp | 68 +++++++++++++------------ clic/src/core/clesperanto.cpp | 9 ++-- clic/src/tier1/cleCropKernel.cpp | 74 ++++++++++++++-------------- 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/clic/include/core/clesperanto.hpp b/clic/include/core/clesperanto.hpp index 71e20284a..d3e38f8fe 100644 --- a/clic/include/core/clesperanto.hpp +++ b/clic/include/core/clesperanto.hpp @@ -94,7 +94,7 @@ class Clesperanto auto ConnectedComponentLabelingBox(const Image & source, const Image & destination) -> void; - + auto Convolve(const Image & source, const Image & convolve_kernel, const Image & destination) -> void; @@ -102,11 +102,12 @@ class Clesperanto Copy(const Image & source, const Image & destination) -> void; auto - Crop(const Image & source, const Image & destination, - const int & index0 = 0, - const int & index1 = 0, - const int & index2 = 0) -> void; - + Crop(const Image & source, + const Image & destination, + const int & index0 = 0, + const int & index1 = 0, + const int & index2 = 0) -> void; + auto DetectMaximaBox(const Image & source, const Image & destination) -> void; diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index 173587376..e0f406f71 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -1,52 +1,50 @@ -#ifndef __TIER1_CLECROPKERNEL_HPP -#define __TIER1_CLECROPKERNEL_HPP +#ifndef __TIER1_CLECROPKERNEL_HPP +#define __TIER1_CLECROPKERNEL_HPP -#include "cleOperation.hpp" +#include "cleOperation.hpp" -namespace cle +namespace cle { -class CropKernel : public Operation -{ - public: - explicit CropKernel(const ProcessorPointer & device); +class CropKernel : public Operation +{ +public: + explicit CropKernel(const ProcessorPointer & device); - auto - SetInput(const Image & object) -> void; + auto + SetInput(const Image & object) -> void; - auto - SetOutput(const Image & object) -> void; + auto + SetOutput(const Image & object) -> void; - auto - SetIndex1(const int & index) -> void; + auto + SetIndex1(const int & index) -> void; - auto - SetIndex2(const int & index) -> void; + auto + SetIndex2(const int & index) -> void; - auto - SetIndex3(const int & index) -> void; - + auto + SetIndex3(const int & index) -> void; }; inline auto -CropKernel_Call(const std::shared_ptr & device, - const Image & src, - const Image & dst, - const int & index0, - const int & index1, - const int & index2 - ) -> void +CropKernel_Call(const std::shared_ptr & device, + const Image & src, + const Image & dst, + const int & index0, + const int & index1, + const int & index2) -> void { - CropKernel kernel(device); - kernel.SetInput(src); - kernel.SetOutput(dst); - kernel.SetIndex1(index0); - kernel.SetIndex2(index1); - kernel.SetIndex3(index2); - kernel.Execute(); + CropKernel kernel(device); + kernel.SetInput(src); + kernel.SetOutput(dst); + kernel.SetIndex1(index0); + kernel.SetIndex2(index1); + kernel.SetIndex3(index2); + kernel.Execute(); } -} +} // namespace cle -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/clic/src/core/clesperanto.cpp b/clic/src/core/clesperanto.cpp index 2d051a3dc..2bb42f3f0 100644 --- a/clic/src/core/clesperanto.cpp +++ b/clic/src/core/clesperanto.cpp @@ -127,10 +127,11 @@ Clesperanto::Convolve(const Image & source, const Image & convolve_kernel, const } auto -Clesperanto::Crop(const Image & source, const Image & destination, - const int & index0, - const int & index1, - const int & index2) -> void +Clesperanto::Crop(const Image & source, + const Image & destination, + const int & index0, + const int & index1, + const int & index2) -> void { CropKernel_Call(this->GetDevice(), source, destination, index0, index1, index2); } diff --git a/clic/src/tier1/cleCropKernel.cpp b/clic/src/tier1/cleCropKernel.cpp index 51a572bfe..f285c8bee 100644 --- a/clic/src/tier1/cleCropKernel.cpp +++ b/clic/src/tier1/cleCropKernel.cpp @@ -1,44 +1,44 @@ -#include "cleCropKernel.hpp" - -namespace cle +#include "cleCropKernel.hpp" + +namespace cle +{ +CropKernel::CropKernel(const ProcessorPointer & device) + : Operation(device, 5) { - CropKernel::CropKernel(const ProcessorPointer & device) : - Operation(device, 5) - { - std::string cl_header = { - #include "cle_crop.h" - }; - this->SetSource("crop", cl_header); - } + std::string cl_header = { +#include "cle_crop.h" + }; + this->SetSource("crop", cl_header); +} - auto - CropKernel::SetInput(const Image & object) -> void - { - this->AddParameter("src", object); - } +auto +CropKernel::SetInput(const Image & object) -> void +{ + this->AddParameter("src", object); +} - auto - CropKernel::SetOutput(const Image & object) -> void - { - this->AddParameter("dst", object); - } +auto +CropKernel::SetOutput(const Image & object) -> void +{ + this->AddParameter("dst", object); +} - auto - CropKernel::SetIndex1(const int & index) -> void - { - this->AddParameter("index0", index); - } +auto +CropKernel::SetIndex1(const int & index) -> void +{ + this->AddParameter("index0", index); +} - auto - CropKernel::SetIndex2(const int & index) -> void - { - this->AddParameter("index1", index); - } +auto +CropKernel::SetIndex2(const int & index) -> void +{ + this->AddParameter("index1", index); +} - auto - CropKernel::SetIndex3(const int & index) -> void - { - this->AddParameter("index2", index); - } -} +auto +CropKernel::SetIndex3(const int & index) -> void +{ + this->AddParameter("index2", index); +} +} // namespace cle From f392663bc893df2fe51583aaf741f3cd3e45f615 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Thu, 16 Mar 2023 13:55:01 +0100 Subject: [PATCH 09/12] Adding some tests and fixing the format --- clic/include/tier1/cleCropKernel.hpp | 2 +- tests/crop_test.cpp | 97 +++++++++++++++++++++------- 2 files changed, 73 insertions(+), 26 deletions(-) diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index e0f406f71..b0b177a46 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -47,4 +47,4 @@ CropKernel_Call(const std::shared_ptr & device, } // namespace cle -#endif \ No newline at end of file +#endif // __TIER1_CLECROPKERNEL_HPP \ No newline at end of file diff --git a/tests/crop_test.cpp b/tests/crop_test.cpp index 17c6a6030..e0e06052c 100644 --- a/tests/crop_test.cpp +++ b/tests/crop_test.cpp @@ -5,39 +5,86 @@ template auto -run_test(const std::array & shape, const cle::MemoryType & mem_type) -> bool +run_test(const std::array & shape, + const cle::MemoryType & mem_type, + const std::array & output_shape, + const std::array & crop_start) -> bool { - //std::vector input(shape[0] * shape[1] * shape[2]); - //std::vector valid(shape[0] * shape[1] * shape[2]); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 100); + std::vector input(shape[0] * shape[1] * shape[2]); + std::generate(input.begin(), input.end(), [&]() { return dis(gen); }); - std::vector input{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - std::vector valid{6, 7, 10, 11}; - - const int index0 = 1; - const int index1 = 1; - const int index2 = 0; - - //std::fill(input.begin(), input.end(), static_cast(value)); - //std::fill(valid.begin(), valid.end(), static_cast ); + std::vector valid; + for (size_t i = crop_start[2]; i < crop_start[2] + output_shape[2]; i++) + { + for (size_t j = crop_start[0]; j < crop_start[0] + output_shape[0]; j++) + { + for (size_t k = crop_start[1]; k < crop_start[1] + output_shape[1]; k++) + { + valid.push_back(input[i * shape[0] * shape[1] + j * shape[0] + k]); + } + } + } - cle::Clesperanto cle; - cle.GetDevice()->WaitForKernelToFinish(); - auto gpu_input = cle.Push(input, shape, mem_type); - auto gpu_output = cle.Create({2, 2, 1}, mem_type); - cle.Crop(gpu_input, gpu_output, index0, index1, index2); - auto output = cle.Pull(gpu_output); + cle::Clesperanto cle; + cle.GetDevice()->WaitForKernelToFinish(); + auto gpu_input = cle.Push(input, shape, mem_type); + auto gpu_output = cle.Create(output_shape, mem_type); + cle.Crop(gpu_input, gpu_output, crop_start[0], crop_start[1], crop_start[2]); + auto output = cle.Pull(gpu_output); - return std::equal(output.begin(), output.end(), valid.begin()); - + return std::equal(output.begin(), output.end(), valid.begin()); } auto main(int argc, char ** argv) -> int { - if(!run_test({4, 4, 1}, cle::BUFFER)) - { - return EXIT_FAILURE; - } + if (!run_test({ 3, 3, 1 }, cle::BUFFER, { 2, 2, 1 }, { 1, 1, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 5, 5, 2 }, cle::BUFFER, { 3, 3, 2 }, { 2, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 8, 8, 1 }, cle::BUFFER, { 6, 6, 1 }, { 2, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 2, 2, 3 }, { 0, 1, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 1, 2, 3 }, { 1, 0, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 10 }, cle::BUFFER, { 3, 5, 7 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 5, 4, 6 }, cle::BUFFER, { 3, 3, 4 }, { 1, 1, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 2, 2, 3 }, { 0, 1, 1 })) + { + return EXIT_FAILURE; + } - return EXIT_SUCCESS; + return EXIT_SUCCESS; } \ No newline at end of file From da763a8317c26c7175270c56a48ac6c4b1ded206 Mon Sep 17 00:00:00 2001 From: zouaoui Date: Fri, 17 Mar 2023 10:05:00 +0100 Subject: [PATCH 10/12] Adding tests and fixing datatype errors --- tests/crop_test.cpp | 85 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/tests/crop_test.cpp b/tests/crop_test.cpp index e0e06052c..df015b94b 100644 --- a/tests/crop_test.cpp +++ b/tests/crop_test.cpp @@ -10,11 +10,8 @@ run_test(const std::array & shape, const std::array & output_shape, const std::array & crop_start) -> bool { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 100); - std::vector input(shape[0] * shape[1] * shape[2]); - std::generate(input.begin(), input.end(), [&]() { return dis(gen); }); + std::vector input(shape[0] * shape[1] * shape[2]); + std::generate(input.begin(), input.end(), [&]() { return (static_cast((1 + (rand() % 9)))); }); std::vector valid; for (size_t i = crop_start[2]; i < crop_start[2] + output_shape[2]; i++) @@ -41,47 +38,107 @@ run_test(const std::array & shape, auto main(int argc, char ** argv) -> int { - if (!run_test({ 3, 3, 1 }, cle::BUFFER, { 2, 2, 1 }, { 1, 1, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 5, 5, 2 }, cle::BUFFER, { 3, 3, 2 }, { 2, 2, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 8, 8, 1 }, cle::BUFFER, { 6, 6, 1 }, { 2, 2, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 2, 2, 3 }, { 0, 1, 1 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 1, 2, 3 }, { 1, 0, 1 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 10 }, cle::BUFFER, { 3, 5, 7 }, { 2, 3, 1 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 5, 4, 6 }, cle::BUFFER, { 3, 3, 4 }, { 1, 1, 1 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 2, 3, 4 }, cle::BUFFER, { 2, 2, 3 }, { 0, 1, 1 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + { + return EXIT_FAILURE; + } + + if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) { return EXIT_FAILURE; } From 0c8b0a9795ca80296f5e3099faaa9bbb347a44cb Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Mar 2023 16:57:01 +0100 Subject: [PATCH 11/12] Updating tests --- tests/crop_test.cpp | 62 +++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/tests/crop_test.cpp b/tests/crop_test.cpp index df015b94b..5ef74bd3b 100644 --- a/tests/crop_test.cpp +++ b/tests/crop_test.cpp @@ -11,20 +11,28 @@ run_test(const std::array & shape, const std::array & crop_start) -> bool { std::vector input(shape[0] * shape[1] * shape[2]); - std::generate(input.begin(), input.end(), [&]() { return (static_cast((1 + (rand() % 9)))); }); + std::vector valid(output_shape[0] * output_shape[1] * output_shape[2]); + int index = 0; - std::vector valid; - for (size_t i = crop_start[2]; i < crop_start[2] + output_shape[2]; i++) + for (auto i = 0; i < input.size(); i++) { - for (size_t j = crop_start[0]; j < crop_start[0] + output_shape[0]; j++) + input[i] = static_cast(i + 1); + } + + for (auto i = crop_start[0]; i < crop_start[0] + output_shape[0]; i++) + { + for (auto j = crop_start[1]; j < crop_start[1] + output_shape[1]; j++) { - for (size_t k = crop_start[1]; k < crop_start[1] + output_shape[1]; k++) + for (auto k = crop_start[2]; k < crop_start[2] + output_shape[2]; k++) { - valid.push_back(input[i * shape[0] * shape[1] + j * shape[0] + k]); + valid[index] = input[i + j * shape[0] + k * shape[0] * shape[1]]; + index++; } } } + std::sort(valid.begin(), valid.end()); + cle::Clesperanto cle; cle.GetDevice()->WaitForKernelToFinish(); auto gpu_input = cle.Push(input, shape, mem_type); @@ -38,107 +46,107 @@ run_test(const std::array & shape, auto main(int argc, char ** argv) -> int { - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 2, 0, 0 })) + if (!run_test({ 10, 1, 1 }, cle::BUFFER, { 5, 1, 1 }, { 1, 0, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 4, 5, 1 }, { 1, 2, 0 })) + if (!run_test({ 6, 8, 1 }, cle::BUFFER, { 2, 4, 1 }, { 4, 2, 0 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } - if (!run_test({ 6, 8, 6 }, cle::BUFFER, { 3, 5, 3 }, { 2, 3, 1 })) + if (!run_test({ 3, 4, 5 }, cle::BUFFER, { 2, 2, 3 }, { 1, 2, 1 })) { return EXIT_FAILURE; } From b7bf5f7e06cbd8c7cb6452491c9a52f65137d3d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Mar 2023 18:27:36 +0100 Subject: [PATCH 12/12] Merge the three method into one --- clic/include/core/clesperanto.hpp | 7 ++----- clic/include/tier1/cleCropKernel.hpp | 12 ++---------- clic/src/tier1/cleCropKernel.cpp | 17 ++++------------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/clic/include/core/clesperanto.hpp b/clic/include/core/clesperanto.hpp index d3e38f8fe..4eefdaca3 100644 --- a/clic/include/core/clesperanto.hpp +++ b/clic/include/core/clesperanto.hpp @@ -102,11 +102,8 @@ class Clesperanto Copy(const Image & source, const Image & destination) -> void; auto - Crop(const Image & source, - const Image & destination, - const int & index0 = 0, - const int & index1 = 0, - const int & index2 = 0) -> void; + Crop(const Image & source, const Image & destination, const int & x = 0, const int & y = 0, const int & z = 0) + -> void; auto DetectMaximaBox(const Image & source, const Image & destination) -> void; diff --git a/clic/include/tier1/cleCropKernel.hpp b/clic/include/tier1/cleCropKernel.hpp index b0b177a46..d3511a00c 100644 --- a/clic/include/tier1/cleCropKernel.hpp +++ b/clic/include/tier1/cleCropKernel.hpp @@ -19,13 +19,7 @@ class CropKernel : public Operation SetOutput(const Image & object) -> void; auto - SetIndex1(const int & index) -> void; - - auto - SetIndex2(const int & index) -> void; - - auto - SetIndex3(const int & index) -> void; + SetIndex(const int & index0, const int & index1, const int & index2) -> void; }; inline auto @@ -39,9 +33,7 @@ CropKernel_Call(const std::shared_ptr & device, CropKernel kernel(device); kernel.SetInput(src); kernel.SetOutput(dst); - kernel.SetIndex1(index0); - kernel.SetIndex2(index1); - kernel.SetIndex3(index2); + kernel.SetIndex(index0, index1, index2); kernel.Execute(); } diff --git a/clic/src/tier1/cleCropKernel.cpp b/clic/src/tier1/cleCropKernel.cpp index f285c8bee..6d4bd0b05 100644 --- a/clic/src/tier1/cleCropKernel.cpp +++ b/clic/src/tier1/cleCropKernel.cpp @@ -25,20 +25,11 @@ CropKernel::SetOutput(const Image & object) -> void } auto -CropKernel::SetIndex1(const int & index) -> void +CropKernel::SetIndex(const int & index0, const int & index1, const int & index2) -> void { - this->AddParameter("index0", index); + this->AddParameter("index0", index0); + this->AddParameter("index1", index1); + this->AddParameter("index2", index2); } -auto -CropKernel::SetIndex2(const int & index) -> void -{ - this->AddParameter("index1", index); -} - -auto -CropKernel::SetIndex3(const int & index) -> void -{ - this->AddParameter("index2", index); -} } // namespace cle