Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit e04affa

Browse files
Print failing line, remove template type paramter by using decltype
1 parent a23691e commit e04affa

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

SYCL/USM/allocator_rebind.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <sycl.hpp>
1616

17+
#include <iostream>
18+
1719
using namespace sycl;
1820

1921
// Allocator has a minimum internal alignment of 64, so use higher values for
@@ -25,17 +27,20 @@ struct alignas(128) Aligned128 {
2527
int x;
2628
};
2729

28-
template <class T, class Allocator>
29-
void test_align(Allocator alloc, size_t Align) {
30-
std::vector<T *> Ptrs;
31-
for (int i = 0; i < 10; ++i)
32-
Ptrs.push_back(alloc.allocate(1));
30+
template <class Allocator>
31+
void test_align(Allocator alloc, size_t Align, int Line = __builtin_LINE()) {
32+
decltype(alloc.allocate(1)) Ptrs[10];
33+
for (auto *&Elem : Ptrs)
34+
Elem = alloc.allocate(1);
3335

3436
int NumExactlyAligned = 0;
3537

36-
for (T *Ptr : Ptrs) {
38+
for (auto *Ptr : Ptrs) {
3739
auto Val = reinterpret_cast<uintptr_t>(Ptr);
38-
assert((Val & (Align - 1)) == 0 && "Not properly aligned!");
40+
if ((Val & (Align - 1)) != 0) {
41+
std::cout << "Failed at line " << Line << std::endl;
42+
assert(false && "Not properly aligned!");
43+
}
3944
if ((Val & (Align * 2 - 1)) != 0)
4045
++NumExactlyAligned;
4146
}
@@ -50,9 +55,12 @@ void test_align(Allocator alloc, size_t Align) {
5055
// needs to be updated to find configuration where we still test our runtime
5156
// by ensuring that underlying allocations' alignment differs between
5257
// Aligned128/Aligned256.
53-
assert(NumExactlyAligned != 0 && "All allocations are over-aligned!");
58+
if (NumExactlyAligned == 0) {
59+
std::cout << "Failed at line " << Line << std::endl;
60+
assert(false && "All allocations are over-aligned!");
61+
}
5462

55-
for (T *Ptr : Ptrs)
63+
for (auto *Ptr : Ptrs)
5664
alloc.deallocate(Ptr, 1);
5765
}
5866

@@ -67,24 +75,24 @@ int main() {
6775
{
6876
// Test default value of Alignment template parameter.
6977
usm_allocator<Aligned256, usm::alloc::host> alloc(ctx, dev);
70-
test_align<Aligned256>(alloc, 256);
78+
test_align(alloc, 256);
7179

7280
using traits_t = std::allocator_traits<decltype(alloc)>;
7381
using rebind_t = typename traits_t::template rebind_alloc<Aligned128>;
7482
rebind_t alloc_rebound = alloc;
75-
test_align<Aligned128>(alloc_rebound, 128);
83+
test_align(alloc_rebound, 128);
7684
}
7785

7886
{
7987
// Test explicit value of Alignment template parameter.
8088
usm_allocator<Aligned256, usm::alloc::host, 256> alloc(ctx, dev);
81-
test_align<Aligned256>(alloc, 256);
89+
test_align(alloc, 256);
8290
using traits_t = std::allocator_traits<decltype(alloc)>;
8391
using rebind_t = typename traits_t::template rebind_alloc<Aligned128>;
8492
rebind_t alloc_rebound = alloc;
8593
// Rebound allocator must use the higher alignment from the explicit
8694
// template parameter, not the type's alignment.
87-
test_align<Aligned128>(alloc_rebound, 256);
95+
test_align(alloc_rebound, 256);
8896
}
8997

9098
return 0;

0 commit comments

Comments
 (0)