Skip to content

Commit 9e3fcc9

Browse files
committed
[SYCL] Set address space to accessors-related kernel arguments
in accordance with accessors targets. Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 94c1d56 commit 9e3fcc9

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ using namespace clang;
1818

1919
typedef llvm::DenseMap<DeclaratorDecl *, DeclaratorDecl *> DeclMap;
2020

21+
enum target {
22+
global_buffer = 2014,
23+
constant_buffer,
24+
local,
25+
image,
26+
host_buffer,
27+
host_image,
28+
image_array
29+
};
30+
2131
class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
2232
public:
2333
KernelBodyTransform(llvm::DenseMap<DeclaratorDecl *, DeclaratorDecl *> &Map,
@@ -161,7 +171,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
161171
ParamStmts.push_back(Res);
162172

163173
// lambda.accessor.__set_pointer(kernel_parameter)
164-
CXXMemberCallExpr *Call = new (S.Context) CXXMemberCallExpr(
174+
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create(
165175
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
166176
BodyStmts.push_back(Call);
167177
}
@@ -208,10 +218,27 @@ void BuildArgTys(ASTContext &Context,
208218
const auto *TemplateDecl =
209219
dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
210220
if (TemplateDecl) {
221+
// First parameter - data type
211222
QualType PointeeType = TemplateDecl->getTemplateArgs()[0].getAsType();
223+
// Fourth parameter - access target
224+
auto AccessQualifier = TemplateDecl->getTemplateArgs()[3].getAsIntegral();
225+
int64_t AccessTarget = AccessQualifier.getExtValue();
212226
Qualifiers Quals = PointeeType.getQualifiers();
227+
// TODO: Support all access targets
228+
switch (AccessTarget) {
229+
case target::global_buffer:
230+
Quals.setAddressSpace(LangAS::opencl_global);
231+
break;
232+
case target::constant_buffer:
233+
Quals.setAddressSpace(LangAS::opencl_constant);
234+
break;
235+
case target::local:
236+
Quals.setAddressSpace(LangAS::opencl_local);
237+
break;
238+
default:
239+
llvm_unreachable("Unsupported access target");
240+
}
213241
// TODO: get address space from accessor template parameter.
214-
Quals.setAddressSpace(LangAS::opencl_global);
215242
PointeeType =
216243
Context.getQualifiedType(PointeeType.getUnqualifiedType(), Quals);
217244
QualType PointerType = Context.getPointerType(PointeeType);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang -S --sycl -Xclang -ast-dump %s | FileCheck %s
2+
// XFAIL: *
3+
#include <CL/sycl.hpp>
4+
5+
using namespace cl::sycl;
6+
7+
int main() {
8+
9+
queue myQueue;
10+
const int size = 64;
11+
int data[size];
12+
buffer<int, 1> buf(data, range<1>(size));
13+
14+
myQueue.submit([&](handler &cgh) {
15+
auto ptr = buf.get_access<access::mode::read_write>(cgh);
16+
17+
accessor<int, 1, access::mode::read_write,
18+
access::target::local>
19+
tile(range<1>(2), cgh);
20+
cgh.single_task<class kernel_function>([=]() {
21+
tile[0] = 0;
22+
ptr[0] = 0;
23+
});
24+
});
25+
26+
myQueue.wait();
27+
}
28+
// CHECK: kernel_function 'void (__local int *__local, __global int *__global)'

0 commit comments

Comments
 (0)