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

Commit 32fbf01

Browse files
authored
[SYCL][CUDA] Add unit test for local arguments alignment (#608)
This issue was solved in intel/llvm#5113, local kernel arguments have to be aligned to the type size.
1 parent 9f807d9 commit 32fbf01

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

SYCL/Regression/local-arg-align.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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,
30+
h);
31+
accessor<double4, 1, access::mode::read_write, access::target::local> b(1,
32+
h);
33+
34+
auto ares = res.get_access<access::mode::read_write>(h);
35+
36+
// Manually capture kernel arguments to ensure an order with the int
37+
// argument first and the double4 argument second. If the two arguments are
38+
// simply laid out consecutively, the double4 argument will not be
39+
// correctly aligned.
40+
h.parallel_for(1, [a, b, ares](sycl::id<1> i) {
41+
// Get the addresses of the two local buffers
42+
ares[0] = (size_t)&a[0];
43+
ares[1] = (size_t)&b[0];
44+
});
45+
}).wait_and_throw();
46+
47+
auto hres = res.get_access<access::mode::read_write>();
48+
49+
int ret = 0;
50+
// Check that the addresses are aligned as expected
51+
if (hres[0] % sizeof(cl_int) != 0) {
52+
std::cout
53+
<< "Error: incorrect alignment for argument a, required alignment: "
54+
<< sizeof(cl_int) << ", address: " << (void *)hres[0] << std::endl;
55+
ret = -1;
56+
}
57+
58+
if (hres[1] % sizeof(double4) != 0) {
59+
std::cout
60+
<< "Error: incorrect alignment for argument b, required alignment: "
61+
<< sizeof(double4) << ", address: " << (void *)hres[1] << std::endl;
62+
ret = -1;
63+
}
64+
65+
return ret;
66+
}

0 commit comments

Comments
 (0)