Skip to content

Commit 3625a7b

Browse files
[SYCL] Use the user-provided host ptr if alignment is sufficient
Reuse the pointer provided by the user in the buffer constructor (even if use_host_ptr wasn't specified) if its alignment is sufficient. Signed-off-by: Sergey Semenov <sergey.semenov@intel.com>
1 parent 28c0cfa commit 3625a7b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sycl/include/CL/sycl/detail/buffer_impl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <CL/sycl/stl.hpp>
2323
#include <CL/sycl/types.hpp>
2424

25+
#include <cstdint>
2526
#include <functional>
2627
#include <memory>
2728
#include <type_traits>
@@ -59,7 +60,10 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
5960
return;
6061

6162
set_final_data(reinterpret_cast<char *>(HostData));
62-
if (MProps.has_property<property::buffer::use_host_ptr>()) {
63+
size_t RequiredAlignment =
64+
getNextPowerOfTwo(sizeof(typename AllocatorT::value_type));
65+
if (reinterpret_cast<std::uintptr_t>(HostData) % RequiredAlignment == 0 ||
66+
MProps.has_property<property::buffer::use_host_ptr>()) {
6367
MUserPtr = HostData;
6468
return;
6569
}

0 commit comments

Comments
 (0)