Skip to content

Commit

Permalink
[SYCL] Add check that accessor class declared in cl::sycl namespace.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent 124a88a commit 2ad1d20
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
25 changes: 12 additions & 13 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,33 +240,32 @@ void BuildArgTys(ASTContext &Context,
for (auto V : ArgDecls) {
QualType ArgTy = V->getType();
QualType ActualArgType = ArgTy;
StringRef Name = ArgTy.getBaseTypeIdentifier()->getName();
// TODO: harden this check with additional validation that this class is
// declared in cl::sycl namespace
if (std::string(Name) == "accessor") {
std::string Name = ArgTy.getCanonicalType().getAsString();
if (Name.find("class cl::sycl::accessor") != std::string::npos) {
if (const auto *RecordDecl = ArgTy->getAsCXXRecordDecl()) {
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();
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:
case target::global_buffer:
Quals.setAddressSpace(LangAS::opencl_global);
break;
case target::constant_buffer:
break;
case target::constant_buffer:
Quals.setAddressSpace(LangAS::opencl_constant);
break;
case target::local:
break;
case target::local:
Quals.setAddressSpace(LangAS::opencl_local);
break;
default:
llvm_unreachable("Unsupported access target");
break;
default:
llvm_unreachable("Unsupported access target");
}
// TODO: get address space from accessor template parameter.
PointeeType =
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaSYCL/built-in-type-kernel-arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang -S --sycl -Xclang -ast-dump %s | FileCheck %s
// XFAIL: *
#include <CL/sycl.hpp>

int main() {
int data = 5;
cl::sycl::queue deviceQueue;
cl::sycl::buffer<int, 1> bufferA(&data, cl::sycl::range<1>(1));

deviceQueue.submit([&](cl::sycl::handler &cgh) {
auto accessorA = bufferA.template get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.single_task<class kernel_function>(
[=]() {
accessorA[0] += data;
});
});
return 0;
}
// CHECK: kernel_function 'void (__global int *__global, int)
56 changes: 56 additions & 0 deletions clang/test/SemaSYCL/fake-accessors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// RUN: %clang -S --sycl -Xclang -ast-dump %s | FileCheck %s
// XFAIL: *
#include <CL/sycl.hpp>

namespace foo {
namespace cl {
namespace sycl {
class accessor {
public:
int field;
};
} // namespace sycl
} // namespace cl
} // namespace foo

class accessor {
public:
int field;
};

typedef cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write,
cl::sycl::access::target::global_buffer>
MyAccessorTD;

using MyAccessorA = cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write,
cl::sycl::access::target::global_buffer>;

int main() {
int data = 5;
cl::sycl::queue deviceQueue;
cl::sycl::buffer<int, 1> bufferA(&data, cl::sycl::range<1>(1));
foo::cl::sycl::accessor acc = {1};
accessor acc1 = {1};

deviceQueue.submit([&](cl::sycl::handler &cgh) {
auto accessorA = bufferA.template get_access<cl::sycl::access::mode::read_write>(cgh);
MyAccessorTD accessorB = bufferA.template get_access<cl::sycl::access::mode::read_write>(cgh);
MyAccessorA accessorC = bufferA.template get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.single_task<class fake_accessors>(
[=]() {
accessorA[0] = acc.field + acc1.field;
});
cgh.single_task<class accessor_typedef>(
[=]() {
accessorB[0] = acc.field + acc1.field;
});
cgh.single_task<class accessor_alias>(
[=]() {
accessorC[0] = acc.field + acc1.field;
});
});
return 0;
}
// CHECK: fake_accessors 'void (__global int *__global, foo::cl::sycl::accessor, accessor)
// CHECK: accessor_typedef 'void (__global int *__global, foo::cl::sycl::accessor, accessor)
// CHECK: accessor_alias 'void (__global int *__global, foo::cl::sycl::accessor, accessor)

0 comments on commit 2ad1d20

Please sign in to comment.