Repository navigation
MULTIPLY enable broadcasting #655
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6887fb3
MULTIPLY enable broadcasting
densmirn b66a4e8
Add gtests for broadcast iterator
densmirn 052a307
Expand memory free before broadcasting
densmirn 6f6f9ed
Disable broadcasting in element-wise operations
densmirn bc0c1f7
Change docs for 2 DPNPC_id methods
densmirn 257700d
Merge branch 'master' of https://github.com/IntelPython/dpnp into fea…
densmirn 7f2e8e2
Change memory free call before broadcasting
densmirn 0731675
Enable gtests on broadcasting on GPU
densmirn da181e2
Enable broadcasting in element-wise operations
densmirn 3b30fb6
Merge branch 'master' of https://github.com/IntelPython/dpnp into fea…
densmirn 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
Enable gtests on broadcasting on GPU
- Loading branch information
commit 0731675949c1ee7552619a5f30d595c96c84e84f
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,30 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| #include "dpnp_iterator.hpp" | ||
|
|
||
| using namespace std; | ||
| using dpnpc_it_t = DPNPC_id<size_t>::iterator; | ||
| using dpnpc_value_t = dpnpc_it_t::value_type; | ||
| using dpnpc_index_t = dpnpc_it_t::size_type; | ||
|
|
||
| template <typename _DataType> | ||
| vector<_DataType> get_input_data(const vector<dpnpc_index_t>& shape) | ||
| { | ||
| const dpnpc_index_t size = accumulate(shape.begin(), shape.end(), dpnpc_index_t(1), multiplies<dpnpc_index_t>()); | ||
|
|
||
| vector<_DataType> input_data(size); | ||
| iota(input_data.begin(), input_data.end(), 1); // let's start from 1 to avoid cleaned memory comparison | ||
|
|
||
| return input_data; | ||
| } | ||
|
|
||
| template <typename _DataType> | ||
| _DataType* get_shared_data(const vector<_DataType>& input_data) | ||
| { | ||
| const size_t data_size_in_bytes = input_data.size() * sizeof(_DataType); | ||
| _DataType* shared_data = reinterpret_cast<_DataType*>(dpnp_memory_alloc_c(data_size_in_bytes)); | ||
| copy(input_data.begin(), input_data.end(), shared_data); | ||
|
|
||
| return shared_data; | ||
| } |
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 |
|---|---|---|
|
|
@@ -28,64 +28,11 @@ | |
| #include <vector> | ||
|
|
||
| #include "dpnp_iterator.hpp" | ||
| #include "dpnp_test_utils.hpp" | ||
|
|
||
| #define DPNP_LOCAL_QUEUE 1 // TODO need to fix build procedure and remove this workaround. Issue #551 | ||
| #include "queue_sycl.hpp" | ||
|
|
||
| using namespace std; | ||
| using dpnpc_it_t = DPNPC_id<size_t>::iterator; | ||
| using dpnpc_value_t = dpnpc_it_t::value_type; | ||
| using dpnpc_index_t = dpnpc_it_t::size_type; | ||
|
|
||
| template <typename _DataType> | ||
| vector<_DataType> get_input_data(const vector<dpnpc_index_t>& shape) | ||
| { | ||
| const dpnpc_index_t size = accumulate(shape.begin(), shape.end(), dpnpc_index_t(1), multiplies<dpnpc_index_t>()); | ||
|
|
||
| vector<_DataType> input_data(size); | ||
| iota(input_data.begin(), input_data.end(), 1); // let's start from 1 to avoid cleaned memory comparison | ||
|
|
||
| return input_data; | ||
| } | ||
|
|
||
| TEST(TestBroadcastIterator, take_value_broadcast_loop_2D) | ||
| { | ||
| vector<dpnpc_value_t> expected_data{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}; | ||
| // expected input data 1, 2, 3 | ||
| vector<dpnpc_value_t> input_data = get_input_data<dpnpc_value_t>({3, 1}); | ||
| DPNPC_id<dpnpc_value_t> result_obj(input_data.data(), {3, 1}); | ||
| result_obj.broadcast_to_shape({3, 4}); | ||
|
|
||
| for (dpnpc_index_t output_id = 0; output_id < result_obj.get_output_size(); ++output_id) | ||
| { | ||
| EXPECT_EQ(result_obj[output_id], expected_data[output_id]); | ||
| } | ||
| } | ||
|
|
||
| TEST(TestBroadcastIterator, take_value_broadcast_loop_3D) | ||
| { | ||
| vector<dpnpc_value_t> expected_data{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6}; | ||
| // expected input data 1, 2, 3, 4, 5, 6 | ||
| vector<dpnpc_value_t> input_data = get_input_data<dpnpc_value_t>({2, 3}); | ||
| DPNPC_id<dpnpc_value_t> result_obj(input_data.data(), {2, 3}); | ||
| result_obj.broadcast_to_shape({2, 2, 3}); | ||
|
|
||
| for (dpnpc_index_t output_id = 0; output_id < result_obj.get_output_size(); ++output_id) | ||
| { | ||
| EXPECT_EQ(result_obj[output_id], expected_data[output_id]); | ||
| } | ||
| } | ||
|
|
||
| TEST(TestBroadcastIterator, output_size_broadcast) | ||
| { | ||
| vector<dpnpc_value_t> input_data = get_input_data<dpnpc_value_t>({3, 4}); | ||
| DPNPC_id<dpnpc_value_t> result_obj(input_data.data(), {3, 4}); | ||
| result_obj.broadcast_to_shape({2, 3, 4}); | ||
|
|
||
| const dpnpc_index_t output_size = result_obj.get_output_size(); | ||
| EXPECT_EQ(output_size, 24); | ||
| } | ||
|
|
||
| struct IteratorParameters | ||
| { | ||
| vector<dpnpc_it_t::size_type> input_shape; | ||
|
|
@@ -108,22 +55,19 @@ class IteratorBroadcasting : public ::testing::TestWithParam<IteratorParameters> | |
|
|
||
| TEST_P(IteratorBroadcasting, loop_broadcast) | ||
| { | ||
| using data_type = double; | ||
|
|
||
| const IteratorParameters& param = GetParam(); | ||
| const dpnpc_index_t result_size = param.result.size(); | ||
| std::vector<data_type> input_data = get_input_data<data_type>(param.input_shape); | ||
|
|
||
| vector<dpnpc_value_t> input_data = get_input_data<dpnpc_value_t>(param.input_shape); | ||
| DPNPC_id<dpnpc_value_t> input(input_data.data(), param.input_shape); | ||
| DPNPC_id<data_type> input(input_data.data(), param.input_shape); | ||
| input.broadcast_to_shape(param.output_shape); | ||
|
|
||
| ASSERT_EQ(input.get_output_size(), result_size); | ||
| ASSERT_EQ(input.get_output_size(), param.result.size()); | ||
|
|
||
| vector<dpnpc_value_t> test_result(result_size, 42); | ||
| for (dpnpc_index_t output_id = 0; output_id < result_size; ++output_id) | ||
| for (dpnpc_index_t output_id = 0; output_id < input.get_output_size(); ++output_id) | ||
| { | ||
| test_result[output_id] = input[output_id]; | ||
| std::cout << "test_result[" << output_id << "] = " << test_result[output_id] << std::endl; | ||
| std::cout << "param.result.at(" << output_id << ") = " << param.result.at(output_id) << std::endl; | ||
| EXPECT_EQ(test_result[output_id], param.result.at(output_id)); | ||
| EXPECT_EQ(input[output_id], param.result.at(output_id)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -133,20 +77,23 @@ TEST_P(IteratorBroadcasting, sycl_broadcast) | |
|
|
||
| const IteratorParameters& param = GetParam(); | ||
| const dpnpc_index_t result_size = param.result.size(); | ||
| vector<data_type> result(result_size, 42); | ||
| data_type* result_ptr = result.data(); | ||
| data_type* result = reinterpret_cast<data_type*>(dpnp_memory_alloc_c(result_size * sizeof(data_type))); | ||
|
|
||
| vector<data_type> input_data = get_input_data<data_type>(param.input_shape); | ||
| DPNPC_id<data_type> input(input_data.data(), param.input_shape); | ||
| input.broadcast_to_shape(param.output_shape); | ||
| std::vector<data_type> input_data = get_input_data<data_type>(param.input_shape); | ||
| data_type* shared_data = get_shared_data<data_type>(input_data); | ||
|
|
||
| ASSERT_EQ(input.get_output_size(), result_size); | ||
| DPNPC_id<data_type>* input_it; | ||
| input_it = reinterpret_cast<DPNPC_id<data_type>*>(dpnp_memory_alloc_c(sizeof(DPNPC_id<data_type>))); | ||
| new (input_it) DPNPC_id<data_type>(shared_data, param.input_shape); | ||
|
|
||
| input_it->broadcast_to_shape(param.output_shape); | ||
|
|
||
| ASSERT_EQ(input_it->get_output_size(), result_size); | ||
|
|
||
| cl::sycl::range<1> gws(result_size); | ||
| const DPNPC_id<data_type>* input_it = &input; | ||
| auto kernel_parallel_for_func = [=](cl::sycl::id<1> global_id) { | ||
| const size_t idx = global_id[0]; | ||
| result_ptr[idx] = (*input_it)[idx]; | ||
| result[idx] = (*input_it)[idx]; | ||
| }; | ||
|
|
||
| auto kernel_func = [&](cl::sycl::handler& cgh) { | ||
|
|
@@ -158,8 +105,12 @@ TEST_P(IteratorBroadcasting, sycl_broadcast) | |
|
|
||
| for (dpnpc_index_t i = 0; i < result_size; ++i) | ||
| { | ||
| EXPECT_EQ(result.at(i), param.result.at(i)); | ||
| EXPECT_EQ(result[i], param.result.at(i)); | ||
| } | ||
|
|
||
| input_it->~DPNPC_id(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to explicitly call the destructor.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed for |
||
| dpnp_memory_free_c(shared_data); | ||
| dpnp_memory_free_c(result); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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
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.
@samir-nasibli it looks like it requires your attention