Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel of Laplace Box #157

Merged
merged 9 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clic/include/core/clesperanto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class Clesperanto
const float & min_intensity = FloatLimits::infinity(),
const float & max_intensity = FloatLimits::infinity()) -> void;

auto
LaplaceBox(const Image & source, const Image & destination) -> void;

auto
Mask(const Image & source, const Image & t_mask, const Image & destination) -> void;

Expand Down
32 changes: 32 additions & 0 deletions clic/include/tier1/cleLaplaceBoxKernel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


#ifndef __TIER1_CLELAPLACEBOXKERNEL_HPP
#define __TIER1_CLELAPLACEBOXKERNEL_HPP

#include "cleOperation.hpp"

namespace cle
{

class LaplaceBoxKernel : public Operation
{
public:
explicit LaplaceBoxKernel(const ProcessorPointer & device);
auto
SetInput(const Image & object) -> void;
auto
SetOutput(const Image & object) -> void;
};

inline auto
LaplaceBoxKernel_Call(const std::shared_ptr<cle::Processor> & device, const Image & src, const Image & dst) -> void
{
LaplaceBoxKernel kernel(device);
kernel.SetInput(src);
kernel.SetOutput(dst);
kernel.Execute();
}

} // namespace cle

#endif // __TIER1_CLELAPLACEBOXKERNEL_HPP
6 changes: 6 additions & 0 deletions clic/src/core/clesperanto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ Clesperanto::GreaterOrEqualConstant(const Image & source, const Image & destinat
kernel.Execute();
}

auto
Clesperanto::LaplaceBox(const Image & source, const Image & destination) -> void
{
LaplaceBoxKernel_Call(this->GetDevice(), source, destination);
}

auto
Clesperanto::Mask(const Image & source, const Image & t_mask, const Image & destination) -> void
{
Expand Down
27 changes: 27 additions & 0 deletions clic/src/tier1/cleLaplaceBoxKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


#include "cleLaplaceBoxKernel.hpp"
#include "cle_laplace_box.h"

namespace cle
{

LaplaceBoxKernel::LaplaceBoxKernel(const ProcessorPointer & device)
: Operation(device, 2)
{
this->SetSource("laplace_box", oclKernel::laplace_box);
}

auto
LaplaceBoxKernel::SetInput(const Image & object) -> void
{
this->AddParameter("src", object);
}

auto
LaplaceBoxKernel::SetOutput(const Image & object) -> void
{
this->AddParameter("dst", object);
}

} // namespace cle
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ target_link_libraries(histogram_test PRIVATE CLIc::CLIc)
set_target_properties(histogram_test PROPERTIES FOLDER "Tests")
# target_compile_features(histogram_test PRIVATE cxx_std_17)

add_executable(laplace_box_test laplace_box_test.cpp)
add_dependencies(laplace_box_test CLIc)
target_link_libraries(laplace_box_test PRIVATE CLIc::CLIc)
set_target_properties(laplace_box_test PROPERTIES FOLDER "Tests")
# target_compile_features(laplace_box_test PRIVATE cxx_std_17)

add_executable(mask_test mask_test.cpp)
add_dependencies(mask_test CLIc)
target_link_libraries(mask_test PRIVATE CLIc::CLIc)
Expand Down Expand Up @@ -492,6 +498,7 @@ add_test(NAME greater_or_equal_constant_test WORKING_DIRECTORY ${CMAKE_CURRENT_B
add_test(NAME greater_or_equal_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND greater_or_equal_test)
add_test(NAME greater_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND greater_test)
add_test(NAME histogram_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND histogram_test)
add_test(NAME laplace_box_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND laplace_box_test)
add_test(NAME mask_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND mask_test)
add_test(NAME masked_voronoi_labeling_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND masked_voronoi_labeling_test)
add_test(NAME maximum_all_pixels_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND maximum_all_pixels_test)
Expand Down Expand Up @@ -571,6 +578,7 @@ set_tests_properties(absolute_test
greater_or_equal_test
greater_test
histogram_test
laplace_box_test
mask_test
masked_voronoi_labeling_test
maximum_all_pixels_test
Expand Down
102 changes: 102 additions & 0 deletions tests/laplace_box_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@


#include "clesperanto.hpp"

template <class type>
auto
run_test(const std::array<size_t, 3> & shape, const cle::MemoryType & mem_type) -> bool
{
std::vector<type> input(shape[0] * shape[1] * shape[2]);
std::vector<type> valid(shape[0] * shape[1] * shape[2]);

if (shape[2] > 1)
{
input = { 1, 0, 2, 1, 0, 1, 0, 3, 0, 2, 0, 1, 3, 0, 0, 1, 0, 1, 1, 0, 2, 0, 2, 1 };
valid = { 4, -22, 30, -6, -21, 6, -26, 50, -19, 34, -28, -2, 50, -23, -18, 3, -27, 3, 5, -26, 31, -25, 28, -1 };
}
else if (shape[1] > 1)
{
input = { 1, 0, 2, 1, 0, 1, 3, 1, 0, 2, 1, 1 };
valid = { 3, -8, 8, -2, -9, 2, 13, -1, -6, 1, -3, 2 };
}
else
{
input = { 1, 0, 0, 1, 1 };
valid = { 1, -1, -1, 1, 0 };
}

cle::Clesperanto cle;
cle.GetDevice()->WaitForKernelToFinish();
auto gpu_input = cle.Push<type>(input, shape, mem_type);
auto gpu_output = cle.Create<type>(shape, mem_type);
cle.LaplaceBox(gpu_input, gpu_output);
auto output = cle.Pull<type>(gpu_output);

return std::equal(output.begin(), output.end(), valid.begin());
}

auto
main(int argc, char ** argv) -> int
{
if (!run_test<float>({ 5, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int32_t>({ 5, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int16_t>({ 5, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int8_t>({ 5, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<float>({ 3, 4, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int32_t>({ 3, 4, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int16_t>({ 3, 4, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int8_t>({ 3, 4, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<float>({ 4, 3, 2 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int32_t>({ 4, 3, 2 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int16_t>({ 4, 3, 2 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

if (!run_test<int8_t>({ 4, 3, 2 }, cle::BUFFER))
{
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}