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

buffer::set_final_data accepts weak_ptr<T>, not <T[]> #1011

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 9 additions & 11 deletions tests/buffer/buffer_storage_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,20 @@ class buffer_storage_test {

// Case 3 - Weak pointer
std::shared_ptr<T[]> data_shared_ptr(new T[size]);
std::weak_ptr<T[]> data_final3 = data_shared_ptr;
// construct an aliasing shared_ptr to get rid of the []
std::shared_ptr<T> data_shared_ptr_alias(data_shared_ptr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doing this, since you initialize it also with the pointer from the shared pointer handling the ownership? 🤔
OK, after more thoughts you do this to have the same shared pointer but returning a pointer of the array decay.
You could add a comment. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment!

data_shared_ptr.get());
std::weak_ptr<T> data_final3 = data_shared_ptr_alias;

// Case 4 - Shared pointer
std::shared_ptr<T[]> data_final4(new T[size]);

// Case 5 - Vector data
// Case 4 - Vector iterator
std::vector<T> data_vector;
data_vector.resize(size);
auto data_final5 = data_vector.begin();
auto data_final4 = data_vector.begin();

check_write_back(log, r, data_final1.get());
check_write_back(log, r, data_final2, true /*is_nullptr*/);
check_write_back(log, r, data_final3);
check_write_back(log, r, data_final4);
check_write_back(log, r, data_final5);
}

private:
Expand All @@ -99,12 +98,11 @@ class buffer_storage_test {
}
}

template <template <typename T1> class C>
void check_write_back(util::logger &log, sycl::range<dims> r,
C<T[]> final_data) {
void check_write_back(util::logger& log, sycl::range<dims> r,
std::weak_ptr<T> final_data) {
use_buffer(final_data, r);

std::shared_ptr<T[]> ptr_shrd(final_data);
auto ptr_shrd = final_data.lock();
T *ptr = ptr_shrd.get();
for (size_t i = 0; i < size; ++i) {
check_equal_values(ptr[i], (T)0xFF);
Expand Down