Skip to content

Commit 44901c9

Browse files
author
Artem Kroviakov
committed
[Func][GPU] Create func::ConstantOp using parents with SymbolTable trait
1 parent bc59b63 commit 44901c9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

mlir/lib/Dialect/Func/IR/FuncOps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ LogicalResult ConstantOp::verify() {
128128
Type type = getType();
129129

130130
// Try to find the referenced function.
131-
auto fn = (*this)->getParentOfType<ModuleOp>().lookupSymbol<FuncOp>(fnName);
131+
SymbolTable symbolTable(
132+
(*this)->getParentWithTrait<mlir::OpTrait::SymbolTable>());
133+
auto fn = symbolTable.lookup<FuncOp>(fnName);
132134
if (!fn)
133135
return emitOpError() << "reference to undefined function '" << fnName
134136
<< "'";
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: mlir-opt %s \
2+
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format" \
3+
// RUN: | mlir-cpu-runner \
4+
// RUN: --shared-libs=%mlir_cuda_runtime \
5+
// RUN: --shared-libs=%mlir_runner_utils \
6+
// RUN: --entry-point-result=void \
7+
// RUN: | FileCheck %s
8+
9+
// CHECK: Hello from 0, 1, 3.000000
10+
module attributes {gpu.container_module} {
11+
gpu.module @kernels {
12+
func.func @hello(%arg0 : f32) {
13+
%0 = gpu.thread_id x
14+
%csti8 = arith.constant 2 : i8
15+
gpu.printf "Hello from %lld, %d, %f\n" %0, %csti8, %arg0 : index, i8, f32
16+
return
17+
}
18+
19+
gpu.func @hello_indirect() kernel {
20+
%cstf32 = arith.constant 3.0 : f32
21+
%func_ref = func.constant @hello : (f32) -> ()
22+
func.call_indirect %func_ref(%cstf32) : (f32) -> ()
23+
gpu.return
24+
}
25+
}
26+
27+
func.func @main() {
28+
%c1 = arith.constant 1 : index
29+
gpu.launch_func @kernels::@hello_indirect
30+
blocks in (%c1, %c1, %c1)
31+
threads in (%c1, %c1, %c1)
32+
return
33+
}
34+
}

0 commit comments

Comments
 (0)