Skip to content

Commit 6cc4701

Browse files
sergey-semenovromanovvlad
authored andcommitted
Revert "[SYCL] Reuse user ptr in buffer & fix default memory allocation (#243)"
This reverts commit 83bb79e. It introduced multiple Khronos CTS failures. Signed-off-by: Sergey Semenov <[email protected]>
1 parent f0491f0 commit 6cc4701

File tree

7 files changed

+27
-51
lines changed

7 files changed

+27
-51
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ class accessor :
336336
using reference = DataT &;
337337
using const_reference = const DataT &;
338338

339-
template <typename AllocatorT, int Dims = Dimensions>
339+
template <int Dims = Dimensions>
340340
accessor(
341341
enable_if_t<Dims == 0 && ((!IsPlaceH && IsHostBuf) ||
342342
(IsPlaceH && (IsGlobalBuf || IsConstantBuf))),
343-
buffer<DataT, 1, AllocatorT>> &BufferRef)
343+
buffer<DataT, 1>> &BufferRef)
344344
#ifdef __SYCL_DEVICE_ONLY__
345345
: impl(id<AdjustedDim>(), BufferRef.get_range(), BufferRef.MemRange) {
346346
#else
@@ -357,9 +357,9 @@ class accessor :
357357
#endif
358358
}
359359

360-
template <typename AllocatorT, int Dims = Dimensions>
360+
template <int Dims = Dimensions>
361361
accessor(
362-
buffer<DataT, 1, AllocatorT> &BufferRef,
362+
buffer<DataT, 1> &BufferRef,
363363
enable_if_t<Dims == 0 && (!IsPlaceH && (IsGlobalBuf || IsConstantBuf)),
364364
handler> &CommandGroupHandler)
365365
#ifdef __SYCL_DEVICE_ONLY__
@@ -376,11 +376,11 @@ class accessor :
376376
}
377377
#endif
378378

379-
template <typename AllocatorT, int Dims = Dimensions,
379+
template <int Dims = Dimensions,
380380
typename = enable_if_t<
381381
(Dims > 0) && ((!IsPlaceH && IsHostBuf) ||
382382
(IsPlaceH && (IsGlobalBuf || IsConstantBuf)))>>
383-
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef)
383+
accessor(buffer<DataT, Dimensions> &BufferRef)
384384
#ifdef __SYCL_DEVICE_ONLY__
385385
: impl(id<Dimensions>(), BufferRef.get_range(), BufferRef.MemRange) {
386386
}
@@ -398,11 +398,10 @@ class accessor :
398398
}
399399
#endif
400400

401-
template <typename AllocatorT, int Dims = Dimensions,
401+
template <int Dims = Dimensions,
402402
typename = enable_if_t<
403403
(Dims > 0) && (!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>>
404-
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
405-
handler &CommandGroupHandler)
404+
accessor(buffer<DataT, Dimensions> &BufferRef, handler &CommandGroupHandler)
406405
#ifdef __SYCL_DEVICE_ONLY__
407406
: impl(id<AdjustedDim>(), BufferRef.get_range(), BufferRef.MemRange) {
408407
}
@@ -417,12 +416,12 @@ class accessor :
417416
}
418417
#endif
419418

420-
template <typename AllocatorT, int Dims = Dimensions,
419+
template <int Dims = Dimensions,
421420
typename = enable_if_t<
422421
(Dims > 0) && ((!IsPlaceH && IsHostBuf) ||
423422
(IsPlaceH && (IsGlobalBuf || IsConstantBuf)))>>
424-
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
425-
range<Dimensions> AccessRange, id<Dimensions> AccessOffset = {})
423+
accessor(buffer<DataT, Dimensions> &BufferRef, range<Dimensions> AccessRange,
424+
id<Dimensions> AccessOffset = {})
426425
#ifdef __SYCL_DEVICE_ONLY__
427426
: impl(AccessOffset, AccessRange, BufferRef.MemRange) {
428427
}
@@ -439,12 +438,11 @@ class accessor :
439438
}
440439
#endif
441440

442-
template <typename AllocatorT, int Dims = Dimensions,
441+
template <int Dims = Dimensions,
443442
typename = enable_if_t<
444443
(Dims > 0) && (!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>>
445-
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
446-
handler &CommandGroupHandler, range<Dimensions> AccessRange,
447-
id<Dimensions> AccessOffset = {})
444+
accessor(buffer<DataT, Dimensions> &BufferRef, handler &CommandGroupHandler,
445+
range<Dimensions> AccessRange, id<Dimensions> AccessOffset = {})
448446
#ifdef __SYCL_DEVICE_ONLY__
449447
: impl(AccessOffset, AccessRange, BufferRef.MemRange) {
450448
}

sycl/include/CL/sycl/buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class queue;
2121
template <int dimensions> class range;
2222

2323
template <typename T, int dimensions = 1,
24-
typename AllocatorT = cl::sycl::detail::aligned_allocator<T>>
24+
typename AllocatorT = cl::sycl::buffer_allocator>
2525
class buffer {
2626
public:
2727
using value_type = T;

sycl/include/CL/sycl/detail/aligned_allocator.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010

1111
#include <CL/cl.h>
1212
#include <CL/sycl/detail/cnri.h>
13-
#include <CL/sycl/detail/common.hpp>
1413
#include <CL/sycl/detail/os_util.hpp>
1514
#include <CL/sycl/range.hpp>
1615

17-
#include <algorithm>
1816
#include <cstring>
1917
#include <cstdlib>
2018
#include <memory>
2119
#include <vector>
2220

2321
namespace cl {
2422
namespace sycl {
25-
namespace detail {
26-
template <typename T> class aligned_allocator {
23+
template <typename T, size_t Alignment>
24+
class aligned_allocator {
2725
public:
2826
using value_type = T;
2927
using pointer = T*;
@@ -32,7 +30,10 @@ template <typename T> class aligned_allocator {
3230
using const_reference = const T&;
3331

3432
public:
35-
template <typename U> struct rebind { typedef aligned_allocator<U> other; };
33+
template<typename U>
34+
struct rebind {
35+
typedef aligned_allocator<U, Alignment> other;
36+
};
3637

3738
// Construct an object
3839
void construct(pointer Ptr, const_reference Val) {
@@ -45,15 +46,11 @@ template <typename T> class aligned_allocator {
4546
pointer address(reference Val) const { return &Val; }
4647
const_pointer address(const_reference Val) { return &Val; }
4748

48-
// Allocate sufficiently aligned memory
49+
// Allocate aligned (to Alignment) memory
4950
pointer allocate(size_t Size) {
50-
size_t NumBytes = Size * sizeof(value_type);
51-
const size_t Alignment =
52-
std::max<size_t>(getNextPowerOfTwo(sizeof(value_type)), 64);
53-
NumBytes = ((NumBytes - 1) | (Alignment - 1)) + 1;
54-
51+
Size += Alignment - Size % Alignment;
5552
pointer Result = reinterpret_cast<pointer>(
56-
detail::OSUtil::alignedAlloc(Alignment, NumBytes));
53+
detail::OSUtil::alignedAlloc(Alignment, Size * sizeof(value_type)));
5754
if (!Result)
5855
throw std::bad_alloc();
5956
return Result;
@@ -68,6 +65,5 @@ template <typename T> class aligned_allocator {
6865
bool operator==(const aligned_allocator&) { return true; }
6966
bool operator!=(const aligned_allocator& rhs) { return false; }
7067
};
71-
} // namespace detail
7268
} // namespace sycl
7369
} // namespace cl

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

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

25-
#include <cstdint>
2625
#include <functional>
2726
#include <memory>
2827
#include <type_traits>
@@ -36,7 +35,7 @@ class accessor;
3635
template <typename T, int Dimensions, typename AllocatorT> class buffer;
3736
class handler;
3837

39-
using buffer_allocator = detail::aligned_allocator<char>;
38+
using buffer_allocator = aligned_allocator<char, /*Alignment*/64>;
4039

4140
namespace detail {
4241
using EventImplPtr = std::shared_ptr<detail::event_impl>;
@@ -60,10 +59,7 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
6059
return;
6160

6261
set_final_data(reinterpret_cast<char *>(HostData));
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>()) {
62+
if (MProps.has_property<property::buffer::use_host_ptr>()) {
6763
MUserPtr = HostData;
6864
return;
6965
}

sycl/include/CL/sycl/detail/common.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
103103
return T(ImplObj);
104104
}
105105

106-
// Returns the smallest power of two not less than Var
107-
size_t getNextPowerOfTwo(size_t Var);
108-
109106
} // namespace detail
110107
} // namespace sycl
111108
} // namespace cl

sycl/include/CL/sycl/detail/image_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum class image_channel_type : unsigned int;
2626
namespace detail {
2727

2828
// utility functions and typedefs for image_impl
29-
using image_allocator = aligned_allocator<byte>;
29+
using image_allocator = aligned_allocator<byte, /*alignment*/ 64>;
3030

3131
// utility function: Returns the Number of Channels for a given Order.
3232
uint8_t getImageNumberChannels(image_channel_order Order);

sycl/source/detail/common.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,6 @@ vector_class<string_class> split_string(const string_class &str,
237237
return result;
238238
}
239239

240-
size_t getNextPowerOfTwo(size_t Var) {
241-
--Var;
242-
Var |= Var >> 1;
243-
Var |= Var >> 2;
244-
Var |= Var >> 4;
245-
Var |= Var >> 8;
246-
Var |= Var >> 16;
247-
Var |= Var >> 32;
248-
return ++Var;
249-
}
250-
251240
} // namespace detail
252241
} // namespace sycl
253242
} // namespace cl

0 commit comments

Comments
 (0)