Skip to content

Commit 1815d78

Browse files
Check optionals before getting KnownGrid/BlockSize
1 parent 9ac4a93 commit 1815d78

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/gc/Transforms/GPU/GpuToGpuOcl.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,24 @@ struct ConvertLaunch final : ConvertOpPattern<gpu::LaunchFuncOp> {
403403
SmallVector<int32_t> argSize;
404404
kernelMod->walk([&](gpu::GPUFuncOp func) {
405405
if (func.getName() == gpuLaunch.getKernelName()) {
406-
for (auto s : func.getKnownGridSize().value()) {
407-
globalSize.emplace_back(s);
406+
if (auto size = func.getKnownGridSize()) {
407+
for (auto s : size.value()) {
408+
globalSize.emplace_back(s);
409+
}
408410
}
409-
for (auto s : func.getKnownBlockSize().value()) {
410-
localSize.emplace_back(s);
411+
if (auto size = func.getKnownBlockSize()) {
412+
for (auto s : size.value()) {
413+
localSize.emplace_back(s);
414+
}
411415
}
412416
}
413417
});
414-
assert(globalSize.size() == 3 && localSize.size() == 3);
418+
while (globalSize.size() < 3) {
419+
globalSize.emplace_back(1);
420+
}
421+
while (localSize.size() < 3) {
422+
localSize.emplace_back(1);
423+
}
415424
globalSize = {globalSize[0] * localSize[0], globalSize[1] * localSize[1],
416425
globalSize[2] * localSize[2]};
417426
for (auto arg : adaptor.getKernelOperands()) {

0 commit comments

Comments
 (0)