Skip to content

Commit c74c3f2

Browse files
authored
[SYCL][SCLA][NFC] Fix warning and potential test errors (#13937)
- `DecorateAddressIndex` is not used. Drop to avoid warnings. - Modify `test` function implementing tests so it does not read from stdin, but receive its parameter as an argument and read these arguments from stdin in `main`. - Manually inline `allocate` function as this usage of `[aligned_]private_alloca` is undefined behavior Signed-off-by: Victor Perez <[email protected]>
1 parent 9f44b8e commit c74c3f2

File tree

7 files changed

+45
-38
lines changed

7 files changed

+45
-38
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23922,7 +23922,6 @@ RValue CodeGenFunction::EmitIntelSYCLAllocaBuiltin(
2392223922
constexpr unsigned ElementTypeIndex = 0;
2392323923
const unsigned AlignmentIndex = IsAlignedAlloca ? 1 : InvalidIndex;
2392423924
const unsigned SpecNameIndex = IsAlignedAlloca ? 2 : 1;
23925-
const unsigned DecorateAddressIndex = IsAlignedAlloca ? 3 : 2;
2392623925

2392723926
const FunctionDecl *FD = E->getDirectCallee();
2392823927
assert(FD && "Expecting direct call to builtin");

sycl/test-e2e/PrivateAlloca/ValidUsage/Inputs/private_alloca_test.hpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,29 @@ template <typename ElementType, typename SizeType,
1111
sycl::access::decorated DecorateAddress, std::size_t Alignment>
1212
class Kernel;
1313

14-
template <typename ElementType, auto &Size,
15-
sycl::access::decorated DecorateAddress, std::size_t Alignment>
16-
static auto allocate(sycl::kernel_handler &kh) {
17-
if constexpr (Alignment > 0) {
18-
return sycl::ext::oneapi::experimental::aligned_private_alloca<
19-
ElementType, Alignment, Size, DecorateAddress>(kh);
20-
} else {
21-
return sycl::ext::oneapi::experimental::private_alloca<ElementType, Size,
22-
DecorateAddress>(kh);
23-
}
24-
}
25-
2614
template <typename ElementType, auto &Size,
2715
sycl::access::decorated DecorateAddress, std::size_t Alignment = 0>
28-
void test() {
29-
std::size_t N;
30-
31-
std::cin >> N;
32-
33-
std::vector<std::size_t> v(N);
16+
void test(std::size_t n) {
17+
std::vector<std::size_t> v(n);
3418
{
3519
sycl::queue q;
3620
sycl::buffer<std::size_t> b(v);
3721
q.submit([&](sycl::handler &cgh) {
3822
sycl::accessor acc(b, cgh, sycl::write_only, sycl::no_init);
39-
cgh.set_specialization_constant<Size>(N);
23+
cgh.set_specialization_constant<Size>(n);
4024
using spec_const_type = std::remove_reference_t<decltype(Size)>;
4125
using size_type = typename spec_const_type::value_type;
4226
cgh.single_task<
4327
Kernel<ElementType, size_type, DecorateAddress, Alignment>>(
4428
[=](sycl::kernel_handler h) {
45-
auto ptr =
46-
allocate<ElementType, Size, DecorateAddress, Alignment>(h);
29+
sycl::private_ptr<ElementType, DecorateAddress> ptr;
30+
if constexpr (Alignment > 0) {
31+
ptr = sycl::ext::oneapi::experimental::aligned_private_alloca<
32+
ElementType, Alignment, Size, DecorateAddress>(h);
33+
} else {
34+
ptr = sycl::ext::oneapi::experimental::private_alloca<
35+
ElementType, Size, DecorateAddress>(h);
36+
}
4737
const std::size_t M = h.get_specialization_constant<Size>();
4838
ptr[0] = static_cast<ElementType>(M);
4939
ElementType value{1};
@@ -60,9 +50,9 @@ void test() {
6050
});
6151
q.wait_and_throw();
6252
}
63-
assert(static_cast<std::size_t>(v.front()) == N &&
53+
assert(static_cast<std::size_t>(v.front()) == n &&
6454
"Wrong private alloca length reported");
65-
for (std::size_t i = 1; i < N; ++i) {
55+
for (std::size_t i = 1; i < n; ++i) {
6656
assert(static_cast<std::size_t>(v[i]) == i &&
6757
"Wrong value in copied-back sequence");
6858
}

sycl/test-e2e/PrivateAlloca/ValidUsage/private_alloca_bool_size.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
constexpr sycl::specialization_id<bool> size(true);
1010

1111
int main() {
12-
test<int, size, sycl::access::decorated::legacy>();
13-
test<int, size, sycl::access::decorated::legacy, alignof(int) * 2>();
12+
std::size_t n = 0;
13+
std::cin >> n;
14+
test<int, size, sycl::access::decorated::legacy>(n);
15+
test<int, size, sycl::access::decorated::legacy, alignof(int) * 2>(n);
1416
}

sycl/test-e2e/PrivateAlloca/ValidUsage/private_alloca_decorated.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
constexpr sycl::specialization_id<int> size(10);
1313

1414
int main() {
15-
test<float, size, sycl::access::decorated::yes>();
16-
test<float, size, sycl::access::decorated::yes, alignof(float) * 2>();
15+
std::size_t n = 0;
16+
std::cin >> n;
17+
test<float, size, sycl::access::decorated::yes>(n);
18+
test<float, size, sycl::access::decorated::yes, alignof(float) * 2>(n);
1719
}

sycl/test-e2e/PrivateAlloca/ValidUsage/private_alloca_legacy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
constexpr sycl::specialization_id<int16_t> size(10);
1313

1414
int main() {
15-
test<int, size, sycl::access::decorated::legacy>();
16-
test<int, size, sycl::access::decorated::legacy, alignof(int) * 4>();
15+
std::size_t n = 0;
16+
std::cin >> n;
17+
test<int, size, sycl::access::decorated::legacy>(n);
18+
test<int, size, sycl::access::decorated::legacy, alignof(int) * 4>(n);
1719
}

sycl/test-e2e/PrivateAlloca/ValidUsage/private_alloca_multiple.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ constexpr sycl::specialization_id<int> isize(10);
1111
constexpr sycl::specialization_id<int16_t> ssize(100);
1212

1313
int main() {
14-
test<float, size, sycl::access::decorated::yes>();
15-
test<int16_t, isize, sycl::access::decorated::legacy>();
16-
test<int, ssize, sycl::access::decorated::no>();
14+
constexpr std::size_t num_tests = 3;
15+
std::array<std::size_t, num_tests> ns;
16+
std::generate_n(ns.begin(), num_tests, []() {
17+
std::size_t i = 0;
18+
std::cin >> i;
19+
return i;
20+
});
1721

18-
test<float, size, sycl::access::decorated::yes, alignof(float) * 2>();
19-
test<int16_t, isize, sycl::access::decorated::legacy, alignof(int16_t) * 2>();
20-
test<int, ssize, sycl::access::decorated::no, alignof(int) * 2>();
22+
test<float, size, sycl::access::decorated::yes>(ns[0]);
23+
test<int16_t, isize, sycl::access::decorated::legacy>(ns[1]);
24+
test<int, ssize, sycl::access::decorated::no>(ns[2]);
25+
26+
test<float, size, sycl::access::decorated::yes, alignof(float) * 2>(ns[0]);
27+
test<int16_t, isize, sycl::access::decorated::legacy, alignof(int16_t) * 2>(
28+
ns[1]);
29+
test<int, ssize, sycl::access::decorated::no, alignof(int) * 2>(ns[2]);
2130
}

sycl/test-e2e/PrivateAlloca/ValidUsage/private_alloca_raw.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class value_and_sign {
5757
};
5858

5959
int main() {
60-
test<value_and_sign, size, sycl::access::decorated::no>();
60+
std::size_t n = 0;
61+
std::cin >> n;
62+
63+
test<value_and_sign, size, sycl::access::decorated::no>(n);
6164
test<value_and_sign, size, sycl::access::decorated::no,
62-
alignof(value_and_sign) * 2>();
65+
alignof(value_and_sign) * 2>(n);
6366
}

0 commit comments

Comments
 (0)