Skip to content

Commit b994ff4

Browse files
whitneywhtsangetiotto
authored andcommitted
Conversion of 'sycl.constructor(%0, %1) {type = @Accessor}' (DefaultCtor) (#57)
Add conversion of `sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>:: accessor()`. Signed-off-by: Tsang, Whitney <whitney.tsang@intel.com>
1 parent 25e15dc commit b994ff4

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

mlir-sycl/include/mlir/Conversion/SYCLToLLVM/SYCLFuncRegistry.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ class SYCLFuncDescriptor {
4141
Unknown,
4242

4343
// Member functions for the sycl:accessor class.
44-
AccessorInt1ReadWriteGlobalBufferFalseInit, // sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>::
45-
// __init(int AS1*, sycl::range<1>, sycl::range<1>, sycl::id<1>)
44+
AccessorInt1ReadWriteGlobalBufferFalseCtorDefault, // sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>::
45+
// accessor()
46+
AccessorInt1ReadWriteGlobalBufferFalseInit, // sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>::
47+
// __init(int AS1*, sycl::range<1>, sycl::range<1>, sycl::id<1>)
4648

4749
// Member functions for the sycl:id<n> class.
4850
Id1CtorDefault, // sycl::id<1>::id()

mlir-sycl/lib/Conversion/SYCLToLLVM/SYCLFuncRegistry.cpp

+27-9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void SYCLFuncDescriptor::declareFunction(ModuleOp &module, OpBuilder &b) {
8080

8181
bool SYCLAccessorFuncDescriptor::isValid(FuncId funcId) const {
8282
switch (funcId) {
83+
case FuncId::AccessorInt1ReadWriteGlobalBufferFalseCtorDefault:
8384
case FuncId::AccessorInt1ReadWriteGlobalBufferFalseInit:
8485
return true;
8586
default:
@@ -180,11 +181,12 @@ SYCLFuncRegistry::getFuncId(SYCLFuncDescriptor::FuncKind funcKind, Type retType,
180181
continue;
181182
}
182183
if (desc.argTys.size() != argTypes.size()) {
183-
LLVM_DEBUG(llvm::dbgs() << "\tskip, number of arguments does not match\n");
184+
LLVM_DEBUG(llvm::dbgs()
185+
<< "\tskip, number of arguments does not match\n");
184186
continue;
185187
}
186188
if (!std::equal(argTypes.begin(), argTypes.end(), desc.argTys.begin())) {
187-
LLVM_DEBUG(llvm::dbgs() << "\tskip, arguments types do not match\n");
189+
LLVM_DEBUG(llvm::dbgs() << "\tskip, arguments types do not match\n");
188190
continue;
189191
}
190192

@@ -212,19 +214,35 @@ void SYCLFuncRegistry::declareAccessorFuncDescriptors(
212214
MLIRContext *context = module.getContext();
213215
auto voidTy = LLVM::LLVMVoidType::get(context);
214216
auto i32Ty = IntegerType::get(context, 32);
215-
auto i32PtrTy = LLVM::LLVMPointerType::get(i32Ty);
216-
Type accessorInt1ReadWriteGlobalBufferPtrTy =
217-
converter.convertType(MemRefType::get(
218-
-1, AccessorType::get(context, i32Ty, 1, MemoryAccessMode::ReadWrite,
219-
MemoryTargetMode::GlobalBuffer, {})));
220-
Type id1Ty = converter.convertType(IDType::get(context, 1));
221-
Type range1Ty = converter.convertType(RangeType::get(context, 1));
217+
auto i32PtrTy = converter.convertType(MemRefType::get(-1, i32Ty));
218+
219+
constexpr unsigned int dim = 1;
220+
Type id1SYCLTy = IDType::get(context, dim);
221+
Type range1SYCLTy = RangeType::get(context, dim);
222+
Type accessorImplDeviceSYCLTy = AccessorImplDeviceType::get(
223+
context, dim, {id1SYCLTy, range1SYCLTy, range1SYCLTy});
224+
Type accessorInt1ReadWriteGlobalBufferSYCLTy = AccessorType::get(
225+
context, i32Ty, dim, MemoryAccessMode::ReadWrite,
226+
MemoryTargetMode::GlobalBuffer, {accessorImplDeviceSYCLTy});
227+
Type accessorInt1ReadWriteGlobalBufferPtrTy = converter.convertType(
228+
MemRefType::get(-1, accessorInt1ReadWriteGlobalBufferSYCLTy));
229+
230+
Type id1Ty = converter.convertType(id1SYCLTy);
231+
Type range1Ty = converter.convertType(range1SYCLTy);
222232

223233
// Construct the SYCL functions descriptors for the sycl::accessor<n> type.
224234
// Descriptor format: (enum, function name, signature).
225235
// clang-format off
226236
std::vector<SYCLFuncDescriptor> descriptors = {
227237
// sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>::
238+
// accessor()
239+
SYCLAccessorFuncDescriptor(
240+
FuncId::AccessorInt1ReadWriteGlobalBufferFalseCtorDefault,
241+
"_ZN2cl4sycl8accessorIiLi1ELNS0_6access4modeE1026ELNS2_"
242+
"6targetE2014ELNS2_11placeholderE0ENS0_3ext6oneapi22accessor_"
243+
"property_listIJEEEEC2Ev",
244+
voidTy, {accessorInt1ReadWriteGlobalBufferPtrTy}),
245+
// sycl::accessor<int, 1, read_write, global_buffer, (placeholder)0>::
228246
// __init(int AS1*, sycl::range<1>, sycl::range<1>, sycl::id<1>)
229247
SYCLAccessorFuncDescriptor(
230248
FuncId::AccessorInt1ReadWriteGlobalBufferFalseInit,

mlir-sycl/lib/Conversion/SYCLToLLVM/SYCLToLLVM.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static Optional<Type> convertBodyType(StringRef name,
9797
static Optional<Type>
9898
convertAccessorImplDeviceType(sycl::AccessorImplDeviceType type,
9999
LLVMTypeConverter &converter) {
100-
return convertBodyType("class.cl::sycl::detail::AccessorImplDevice" +
100+
return convertBodyType("class.cl::sycl::detail::AccessorImplDevice." +
101101
std::to_string(type.getDimension()),
102102
type.getBody(), converter);
103103
}
@@ -107,7 +107,7 @@ static Optional<Type> convertAccessorType(sycl::AccessorType type,
107107
LLVMTypeConverter &converter) {
108108
auto convertedTy = LLVM::LLVMStructType::getIdentified(
109109
&converter.getContext(),
110-
"class.cl::sycl::accessor" + std::to_string(type.getDimension()));
110+
"class.cl::sycl::accessor." + std::to_string(type.getDimension()));
111111
if (!convertedTy.isInitialized()) {
112112
SmallVector<Type> convertedElemTypes;
113113
convertedElemTypes.reserve(type.getBody().size());

mlir-sycl/test/Conversion/SYCLToLLVM/func-ops-to-llvm.mlir

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
// RUN: sycl-mlir-opt -split-input-file -convert-sycl-to-llvm -verify-diagnostics %s | FileCheck %s
22

3+
//===-------------------------------------------------------------------------------------------------===//
4+
// Constructors for sycl::accessor<t, d, m, t, p>::accessor()
5+
//===-------------------------------------------------------------------------------------------------===//
6+
7+
// CHECK: llvm.func @_ZN2cl4sycl8accessorIiLi1ELNS0_6access4modeE1026ELNS2_6targetE2014ELNS2_11placeholderE0ENS0_3ext6oneapi22accessor_property_listIJEEEEC2Ev([[THIS_PTR_TYPE:!llvm.struct<\(ptr<struct<"class.cl::sycl::accessor.1",.*]])
8+
!sycl_accessor_1_i32_read_write_global_buffer = !sycl.accessor<[1, i32, read_write, global_buffer], (!sycl.accessor_impl_device<[1], (!sycl.id<1>, !sycl.range<1>, !sycl.range<1>)>, !llvm.struct<(ptr<i32, 1>)>)>
9+
func.func @accessorInt1ReadWriteGlobalBufferFalseCtor(%arg0: memref<?x!sycl_accessor_1_i32_read_write_global_buffer>) {
10+
// CHECK: llvm.call @_ZN2cl4sycl8accessorIiLi1ELNS0_6access4modeE1026ELNS2_6targetE2014ELNS2_11placeholderE0ENS0_3ext6oneapi22accessor_property_listIJEEEEC2Ev({{.*}}) : ([[THIS_PTR_TYPE]]) -> ()
11+
sycl.constructor(%arg0) {Type = @accessor} : (memref<?x!sycl_accessor_1_i32_read_write_global_buffer>) -> ()
12+
return
13+
}
14+
15+
// -----
16+
317
//===-------------------------------------------------------------------------------------------------===//
418
// Constructors for sycl::id<n>::id()
519
//===-------------------------------------------------------------------------------------------------===//

0 commit comments

Comments
 (0)