Skip to content
25 changes: 24 additions & 1 deletion sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <CL/sycl/stl.hpp>

#include <cstring>
#include <memory>
#include <type_traits>

__SYCL_INLINE_NAMESPACE(cl) {
Expand Down Expand Up @@ -51,7 +52,13 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {

template <typename T>
using EnableIfOutputIteratorT = enable_if_t<
/*is_output_iterator<T>::value &&*/ !std::is_pointer<T>::value>;
/*is_output_iterator<T>::value &&*/ !std::is_pointer<T>::value &&
!std::is_same<typename T::value_type, bool>::value>;
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexbatashev, @sergey-semenov, could you, please, help reviewing this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid this is going to break some use cases: https://godbolt.org/z/nznfq1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is the test SYCL/buffer/buffer.cpp . There are a lot of checks, including pointer (for ex int*, void*). The only compilation error was the error with void*, because there was an iterator_value_type_t and void type was trying to convert to void&. With typename T::value_type all the checks were passed

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, sounds good to me


template <typename T>
using EnableIfOutputIteratorBool =
enable_if_t<!std::is_pointer<T>::value &&
std::is_same<typename T::value_type, bool>::value>;

template <typename T>
using EnableIfDefaultAllocator =
Expand Down Expand Up @@ -184,6 +191,22 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
};
}

template <typename Destination>
__SYCL_DLL_LOCAL EnableIfOutputIteratorBool<Destination>
set_final_data(Destination FinalData) {
MUploadDataFunctor = [this, FinalData]() {
using DestinationValueT = iterator_value_type_t<Destination>;
// TODO if Destination is ContiguousIterator then don't create
// ContiguousStorage. updateHostMemory works only with pointer to
// continuous data.
const size_t Size = MSizeInBytes / sizeof(DestinationValueT);
std::unique_ptr<bool[]> ContiguousStorage(new bool[Size]);
updateHostMemory(ContiguousStorage.get());
std::copy(ContiguousStorage.get(), ContiguousStorage.get() + Size,
FinalData);
};
}

protected:
void updateHostMemory(void *const Ptr);

Expand Down