Skip to content

Commit c4d48f9

Browse files
Pass value pointer but not the values to kernelLaunch()
1 parent 576969e commit c4d48f9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/gc/Transforms/GPU/GpuToGpuOcl.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,17 @@ struct ConvertLaunch final : ConvertOpPattern<gpu::LaunchFuncOp> {
256256

257257
int i = 0;
258258
for (auto arg : kernelArgs) {
259-
if (isa<MemRefType>(gpuLaunch.getKernelOperand(i++).getType())) {
259+
if (auto type = gpuLaunch.getKernelOperand(i++).getType();
260+
isa<MemRefType>(type)) {
260261
MemRefDescriptor desc(arg);
261262
args.emplace_back(desc.alignedPtr(rewriter, loc));
262263
} else {
263-
args.emplace_back(arg);
264+
// Store the arg on the stack and pass the pointer
265+
auto ptr = rewriter.create<LLVM::AllocaOp>(
266+
loc, helper.ptrType, typeConverter->convertType(type),
267+
helper.idxConstant(rewriter, loc, 1));
268+
rewriter.create<LLVM::StoreOp>(loc, arg, ptr);
269+
args.emplace_back(ptr);
264270
}
265271
}
266272

@@ -352,7 +358,7 @@ struct ConvertLaunch final : ConvertOpPattern<gpu::LaunchFuncOp> {
352358
// ...name_Ptr.
353359
bool createKernel(
354360
gpu::LaunchFuncOp &gpuLaunch, OpAdaptor &adaptor,
355-
ConversionPatternRewriter &rewriter, Location &loc, ModuleOp &mod,
361+
ConversionPatternRewriter &rewriter, const Location &loc, ModuleOp &mod,
356362
StringRef funcName,
357363
const std::function<SmallString<128> &(const char *chars)> &str) const {
358364
auto kernelModName = gpuLaunch.getKernelModuleName();
@@ -410,6 +416,8 @@ struct ConvertLaunch final : ConvertOpPattern<gpu::LaunchFuncOp> {
410416

411417
for (auto arg : adaptor.getKernelOperands()) {
412418
auto type = arg.getType();
419+
// Assuming, that the value is either an integer or a float or a pointer.
420+
// In the latter case, the size is 0 bytes.
413421
auto size = type.isIntOrFloat() ? type.getIntOrFloatBitWidth() / 8 : 0;
414422
argSize.emplace_back(helper.idxConstant(rewriter, loc, size));
415423
}

0 commit comments

Comments
 (0)