Skip to content

Commit

Permalink
Merge pull request #118 from pr4deepr/master
Browse files Browse the repository at this point in the history
gradient_z support

Congrats @pr4deepr
  • Loading branch information
StRigaud authored Nov 24, 2022
2 parents eeddb71 + f0a75cc commit 7d82883
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clic/include/core/clesperanto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class Clesperanto
auto
GradientY(const Image & source, const Image & destination) -> void;

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

auto
Greater(const Image & source1, const Image & source2, const Image & destination) -> void;

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

#include "cleOperation.hpp"

namespace cle
{

class GradientZKernel : public Operation
{
public:
explicit GradientZKernel(const ProcessorPointer & device);

auto
SetInput(const Image & object) -> void;

auto
SetOutput(const Image & object) -> void;
};

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

} // namespace cle

#endif // __TIER1_CLEGradientZKERNEL_HPP
6 changes: 6 additions & 0 deletions clic/src/core/clesperanto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ Clesperanto::GradientY(const Image & source, const Image & destination) -> void
GradientYKernel_Call(this->GetDevice(), source, destination);
}

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

auto
Clesperanto::Greater(const Image & source1, const Image & source2, const Image & destination) -> void
{
Expand Down
27 changes: 27 additions & 0 deletions clic/src/tier1/cleGradientZKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "cleGradientZKernel.hpp"

namespace cle
{

GradientZKernel::GradientZKernel(const ProcessorPointer & device)
: Operation(device, 2)
{
std::string cl_header_ = {
#include "cle_gradient_z.h"
};
this->SetSource("gradient_z", cl_header_);
}

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

auto
GradientZKernel::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 @@ -202,6 +202,12 @@ target_link_libraries(gradient_x_test PRIVATE CLIc::CLIc)
set_target_properties(gradient_x_test PROPERTIES FOLDER "Tests")
target_compile_features(gradient_x_test PRIVATE cxx_std_17)

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

add_executable(masked_voronoi_labeling_test masked_voronoi_labeling_test.cpp)
add_dependencies(masked_voronoi_labeling_test CLIc)
target_link_libraries(masked_voronoi_labeling_test PRIVATE CLIc::CLIc)
Expand Down Expand Up @@ -434,6 +440,7 @@ add_test(NAME detect_maxima_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} C
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)
add_test(NAME gradient_x_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND gradient_x_test)
add_test(NAME gradient_z_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND gradient_z_test)
add_test(NAME equal_constant_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND equal_constant_test)
add_test(NAME equal_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND equal_test)
add_test(NAME erode_sphere_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND erode_sphere_test)
Expand Down Expand Up @@ -556,4 +563,5 @@ set_tests_properties(absolute_test
sum_z_projection_test
threshold_otsu_test
gradient_x_test
gradient_z_test
voronoi_otsu_labeling_test PROPERTIES LABELS "KERNELS" WILL_FAIL FALSE)
237 changes: 237 additions & 0 deletions tests/gradient_z_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@


#include "clesperanto.hpp"

#include <random>

template <class type>
auto
run_test(const std::array<size_t, 3> & shape, const cle::MemoryType & mem_type) -> bool
{
std::vector<type> input = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
std::vector<type> valid = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 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.GradientZ(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>({ 3, 3, 3 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
/*
if (!run_test<signed int>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned int>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed short>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned short>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed char>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned char>({ 10, 1, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<float>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed int>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned int>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed short>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned short>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed char>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned char>({ 10, 7, 1 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<float>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed int>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned int>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed short>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned short>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<signed char>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
if (!run_test<unsigned char>({ 10, 7, 5 }, cle::BUFFER))
{
return EXIT_FAILURE;
}
// if (!run_test<float>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed int>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned int>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed short>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned short>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed char>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned char>({ 10, 1, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<float>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed int>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned int>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed short>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned short>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed char>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned char>({ 10, 7, 1 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<float>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed int>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned int>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed short>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned short>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<signed char>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
// if (!run_test<unsigned char>({ 10, 7, 5 }, cle::IMAGE))
// {
// return EXIT_FAILURE;
// }
*/
return EXIT_SUCCESS;
}

0 comments on commit 7d82883

Please sign in to comment.