Skip to content

Commit

Permalink
[SYCL] Set address space to accessors-related kernel arguments
Browse files Browse the repository at this point in the history
in accordance with accessors targets.

Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent 94c1d56 commit 9e3fcc9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
31 changes: 29 additions & 2 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ using namespace clang;

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

enum target {
global_buffer = 2014,
constant_buffer,
local,
image,
host_buffer,
host_image,
image_array
};

class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
public:
KernelBodyTransform(llvm::DenseMap<DeclaratorDecl *, DeclaratorDecl *> &Map,
Expand Down Expand Up @@ -161,7 +171,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
ParamStmts.push_back(Res);

// lambda.accessor.__set_pointer(kernel_parameter)
CXXMemberCallExpr *Call = new (S.Context) CXXMemberCallExpr(
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create(
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
BodyStmts.push_back(Call);
}
Expand Down Expand Up @@ -208,10 +218,27 @@ void BuildArgTys(ASTContext &Context,
const auto *TemplateDecl =
dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
if (TemplateDecl) {
// First parameter - data type
QualType PointeeType = TemplateDecl->getTemplateArgs()[0].getAsType();
// Fourth parameter - access target
auto AccessQualifier = TemplateDecl->getTemplateArgs()[3].getAsIntegral();
int64_t AccessTarget = AccessQualifier.getExtValue();
Qualifiers Quals = PointeeType.getQualifiers();
// TODO: Support all access targets
switch (AccessTarget) {
case target::global_buffer:
Quals.setAddressSpace(LangAS::opencl_global);
break;
case target::constant_buffer:
Quals.setAddressSpace(LangAS::opencl_constant);
break;
case target::local:
Quals.setAddressSpace(LangAS::opencl_local);
break;
default:
llvm_unreachable("Unsupported access target");
}
// TODO: get address space from accessor template parameter.
Quals.setAddressSpace(LangAS::opencl_global);
PointeeType =
Context.getQualifiedType(PointeeType.getUnqualifiedType(), Quals);
QualType PointerType = Context.getPointerType(PointeeType);
Expand Down
28 changes: 28 additions & 0 deletions clang/test/SemaSYCL/accessors-targets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clang -S --sycl -Xclang -ast-dump %s | FileCheck %s
// XFAIL: *
#include <CL/sycl.hpp>

using namespace cl::sycl;

int main() {

queue myQueue;
const int size = 64;
int data[size];
buffer<int, 1> buf(data, range<1>(size));

myQueue.submit([&](handler &cgh) {
auto ptr = buf.get_access<access::mode::read_write>(cgh);

accessor<int, 1, access::mode::read_write,
access::target::local>
tile(range<1>(2), cgh);
cgh.single_task<class kernel_function>([=]() {
tile[0] = 0;
ptr[0] = 0;
});
});

myQueue.wait();
}
// CHECK: kernel_function 'void (__local int *__local, __global int *__global)'

0 comments on commit 9e3fcc9

Please sign in to comment.