Skip to content

Commit b0f099f

Browse files
committed
[SYCL][CUDA] Add unit test for local arguments alignment
This issue was solved in intel/llvm#5113, local kernel arguments have to be aligned to the type size.
1 parent 74e49b3 commit b0f099f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

SYCL/Regression/local-arg-align.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
//
3+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
8+
//==-- local-arg-align.cpp - Test for local argument alignmnent ------------==//
9+
//
10+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
// See https://llvm.org/LICENSE.txt for license information.
12+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include <CL/sycl.hpp>
17+
#include <iostream>
18+
19+
using namespace sycl;
20+
21+
// This test is a simple unit test to ensure that local kernel arguments are
22+
// properly aligned.
23+
int main(int argc, char *argv[]) {
24+
queue q;
25+
buffer<size_t, 1> res(2);
26+
27+
q.submit([&](sycl::handler &h) {
28+
// Use two local buffers, one with an int and one with a double4
29+
accessor<cl_int, 1, access::mode::read_write, access::target::local> a(1, h);
30+
accessor<double4, 1, access::mode::read_write, access::target::local> b(1, h);
31+
32+
auto ares = res.get_access<access::mode::read_write>(h);
33+
34+
// Manually capture kernel arguments to ensure an order with the int
35+
// argument first and the double4 argument second. If the two arguments are
36+
// simply laid out consecutively, the double4 argument will not be
37+
// correctly aligned.
38+
h.parallel_for(1, [a, b, ares](sycl::id<1> i) {
39+
// Get the addresses of the two local buffers
40+
ares[0] = (size_t)&a[0];
41+
ares[1] = (size_t)&b[0];
42+
});
43+
}).wait_and_throw();
44+
45+
auto hres = res.get_access<access::mode::read_write>();
46+
47+
int ret = 0;
48+
// Check that the addresses are aligned as expected
49+
if (hres[0] % sizeof(cl_int) != 0) {
50+
std::cout
51+
<< "Error: incorrect alignment for argument a, required alignment: "
52+
<< sizeof(cl_int) << ", address: " << (void *)hres[0] << std::endl;
53+
ret = -1;
54+
}
55+
56+
if (hres[1] % sizeof(double4) != 0) {
57+
std::cout
58+
<< "Error: incorrect alignment for argument b, required alignment: "
59+
<< sizeof(double4) << ", address: " << (void *)hres[1] << std::endl;
60+
ret = -1;
61+
}
62+
63+
return ret;
64+
}

0 commit comments

Comments
 (0)