-
Notifications
You must be signed in to change notification settings - Fork 16
Kernel detect minima #151
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
Open
CherifMZ
wants to merge
10
commits into
clEsperanto:master
Choose a base branch
from
CherifMZ:kernel_detect_minima
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kernel detect minima #151
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52d6751
Creating files & implementing funtions
77a4688
Implementing cleDetectMinimaKernel.cpp
4dc1e15
Implementing clesperanto (.hpp and .cpp)
2cd96b7
Adding tests
e690274
Format fixing
e320882
error checking
c6b43dd
Added a forgotten -1 and some comments
063ccc7
Merge branch 'clEsperanto:master' into kernel_detect_minima
CherifMZ 4524d14
Merge branch 'clEsperanto:master' into kernel_detect_minima
CherifMZ 976f97f
Updating detectMinima and correcting an error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
|
|
||
| #ifndef __TIER1_CLEDETECTMINIMAKERNEL_HPP | ||
| #define __TIER1_CLEDETECTMINIMAKERNEL_HPP | ||
|
|
||
| #include "cleOperation.hpp" | ||
|
|
||
| namespace cle | ||
| { | ||
|
|
||
| class DetectMinimaKernel : public Operation | ||
| { | ||
| public: | ||
| explicit DetectMinimaKernel(const ProcessorPointer & device); | ||
| auto | ||
| SetInput(const Image & object) -> void; | ||
| auto | ||
| SetOutput(const Image & object) -> void; | ||
| }; | ||
|
|
||
| inline auto | ||
| DetectMinimaKernel_Call(const std::shared_ptr<cle::Processor> & device, const Image & src, const Image & dst) -> void | ||
| { | ||
| DetectMinimaKernel kernel(device); | ||
| kernel.SetInput(src); | ||
| kernel.SetOutput(dst); | ||
| kernel.Execute(); | ||
| } | ||
|
|
||
| } // namespace cle | ||
|
|
||
| #endif // __TIER1_CLEDETECTMINIMAKERNEL_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| #include "cleDetectMinimaKernel.hpp" | ||
|
|
||
| namespace cle | ||
|
|
||
| { | ||
| DetectMinimaKernel::DetectMinimaKernel(const ProcessorPointer & device) | ||
| : Operation(device, 2) | ||
|
|
||
| { | ||
| std::string cl_header = { | ||
| #include "cle_detect_minima.h" | ||
| }; | ||
| this->SetSource("detect_minima", cl_header); | ||
| } | ||
|
|
||
| auto | ||
| DetectMinimaKernel::SetInput(const Image & object) -> void | ||
| { | ||
| this->AddParameter("src", object); | ||
| } | ||
|
|
||
| auto | ||
| DetectMinimaKernel::SetOutput(const Image & object) -> void | ||
| { | ||
| this->AddParameter("dst", object); | ||
| } | ||
| } // namespace cle | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
|
|
||
|
|
||
| #include <random> | ||
|
|
||
| #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]); | ||
| std::fill(input.begin(), input.end(), static_cast<type>(100)); | ||
| std::fill(valid.begin(), valid.end(), static_cast<type>(0)); | ||
|
|
||
| // An example of a case where the maximal value is located in the center | ||
| // int center = (shape[0] / 2) + (shape[1] / 2) * shape[0] + (shape[2] / 2) * shape[0] * shape[1]; | ||
| // input[center] = static_cast<type>(0); | ||
| // valid[center] = static_cast<type>(1); | ||
|
|
||
| // An example of a case where the maximal value is located at the bottom right | ||
| input[input.size() - 1] = static_cast<type>(0); | ||
| valid[valid.size() - 1] = static_cast<type>(1); | ||
|
|
||
| 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.DetectMinima(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>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int32_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint32_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int16_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint16_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int8_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint8_t>({ 10, 1, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<float>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int32_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint32_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int16_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint16_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int8_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint8_t>({ 4, 3, 1 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<float>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int32_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint32_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int16_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint16_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<int8_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| if (!run_test<uint8_t>({ 5, 6, 3 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| /* Although it works for the above tests, here is an example in which detecting the minimal value when it is located | ||
| in the center of a 3D array of shape (3, 3, 2) does not work. | ||
|
|
||
| if (!run_test<float>({ 3, 3, 2 }, cle::BUFFER)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } */ | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Library was updated, this need to be changed as followed:
cl_headerbyoclKernel::detect_minimasee: absolute kernel for example