Skip to content

Commit 4350cf4

Browse files
committed
[SYCL][FPGA] Change address space for USM pointers as kernel args
Query for address space of USM pointer before adding the appropriate pointer argument of OpenCL kernel. If this address space is global_device or global_host - leave it as is. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 363ad5f commit 4350cf4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,11 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
12441244
// space, because OpenCL requires it.
12451245
QualType PointeeTy = FieldTy->getPointeeType();
12461246
Qualifiers Quals = PointeeTy.getQualifiers();
1247-
Quals.setAddressSpace(LangAS::opencl_global);
1247+
auto AS = Quals.getAddressSpace();
1248+
// Leave global_device and global_host address spaces as is to help FPGA
1249+
// device in memory allocations
1250+
if (AS != LangAS::opencl_global_device && AS != LangAS::opencl_global_host)
1251+
Quals.setAddressSpace(LangAS::opencl_global);
12481252
PointeeTy = SemaRef.getASTContext().getQualifiedType(
12491253
PointeeTy.getUnqualifiedType(), Quals);
12501254
QualType ModTy = SemaRef.getASTContext().getPointerType(PointeeTy);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
2+
3+
// CHECK: define {{.*}}spir_kernel void @_ZTSZ4mainE15kernel_function(i32 addrspace(5)* {{.*}} i32 addrspace(6)* {{.*}}
4+
5+
#include "sycl.hpp"
6+
7+
int main() {
8+
__attribute__((opencl_global_device)) int *GLOBDEV = nullptr;
9+
__attribute__((opencl_global_host)) int *GLOBHOST = nullptr;
10+
cl::sycl::kernel_single_task<class kernel_function>(
11+
[=]() {
12+
__attribute__((opencl_global_device)) int *DevPtr = GLOBDEV;
13+
__attribute__((opencl_global_host)) int *HostPtr = GLOBHOST;
14+
});
15+
return 0;
16+
}

0 commit comments

Comments
 (0)