Skip to content

Commit 084d83a

Browse files
authored
[SYCL] Fix set_final_data(..) for std::vector<bool> iterator (#3099)
Fixed set_final_data() taking std::vector<bool> which was not compiling because such a vector has no data method. The patch adds a special case for bool type. Test: intel/llvm-test-suite#122 Signed-off-by: mdimakov [email protected]
1 parent 14437db commit 084d83a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <CL/sycl/stl.hpp>
2121

2222
#include <cstring>
23+
#include <memory>
2324
#include <type_traits>
2425

2526
__SYCL_INLINE_NAMESPACE(cl) {
@@ -51,7 +52,13 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
5152

5253
template <typename T>
5354
using EnableIfOutputIteratorT = enable_if_t<
54-
/*is_output_iterator<T>::value &&*/ !std::is_pointer<T>::value>;
55+
/*is_output_iterator<T>::value &&*/ !std::is_pointer<T>::value &&
56+
!std::is_same<typename T::value_type, bool>::value>;
57+
58+
template <typename T>
59+
using EnableIfOutputIteratorBool =
60+
enable_if_t<!std::is_pointer<T>::value &&
61+
std::is_same<typename T::value_type, bool>::value>;
5562

5663
template <typename T>
5764
using EnableIfDefaultAllocator =
@@ -184,6 +191,22 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
184191
};
185192
}
186193

194+
template <typename Destination>
195+
__SYCL_DLL_LOCAL EnableIfOutputIteratorBool<Destination>
196+
set_final_data(Destination FinalData) {
197+
MUploadDataFunctor = [this, FinalData]() {
198+
using DestinationValueT = iterator_value_type_t<Destination>;
199+
// TODO if Destination is ContiguousIterator then don't create
200+
// ContiguousStorage. updateHostMemory works only with pointer to
201+
// continuous data.
202+
const size_t Size = MSizeInBytes / sizeof(DestinationValueT);
203+
std::unique_ptr<bool[]> ContiguousStorage(new bool[Size]);
204+
updateHostMemory(ContiguousStorage.get());
205+
std::copy(ContiguousStorage.get(), ContiguousStorage.get() + Size,
206+
FinalData);
207+
};
208+
}
209+
187210
protected:
188211
void updateHostMemory(void *const Ptr);
189212

0 commit comments

Comments
 (0)