Skip to content

[mlir][spirv] Handle all zero-element memref types #73351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ static Type convertBoolMemrefType(const spirv::TargetEnv &targetEnv,
return wrapInStructAndGetPointer(arrayType, storageClass);
}

if (type.getNumElements() == 0) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: zero-element memrefs are not supported\n");
return nullptr;
}

int64_t memrefSize = llvm::divideCeil(type.getNumElements() * numBoolBits, 8);
int64_t arrayElemCount = llvm::divideCeil(memrefSize, *arrayElemSize);
int64_t stride = needsExplicitLayout(storageClass) ? *arrayElemSize : 0;
Expand Down Expand Up @@ -500,6 +506,12 @@ static Type convertSubByteMemrefType(const spirv::TargetEnv &targetEnv,
return wrapInStructAndGetPointer(arrayType, storageClass);
}

if (type.getNumElements() == 0) {
LLVM_DEBUG(llvm::dbgs()
<< type << " illegal: zero-element memrefs are not supported\n");
return nullptr;
}

int64_t memrefSize =
llvm::divideCeil(type.getNumElements() * elementType.getWidth(), 8);
int64_t arrayElemCount = llvm::divideCeil(memrefSize, arrayElemSize);
Expand Down
2 changes: 2 additions & 0 deletions mlir/test/Conversion/MemRefToSPIRV/alloc.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ module attributes {
{
func.func @zero_size() {
%0 = memref.alloc() : memref<0xf32, #spirv.storage_class<Workgroup>>
%1 = memref.alloc() : memref<0xi1, #spirv.storage_class<Workgroup>>
%2 = memref.alloc() : memref<0xi4, #spirv.storage_class<Workgroup>>
return
}
}
Expand Down