Skip to content
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
4 changes: 4 additions & 0 deletions projects/eudsl-python-extras/mlir/extras/dialects/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ def func(
ip=ip,
)
func_.__name__ = f.__name__
if func_._is_decl():
raise ValueError(
"gpu.func does not support external declarations (body must not be empty)"
)
if emit:
func_.emit()
if emit_grid:
Expand Down
48 changes: 38 additions & 10 deletions projects/eudsl-python-extras/tests/dialect/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,27 +1583,20 @@ def main():
ctx.module.operation.verify()


@pytest.mark.xfail(
reason="gpu.func emit inside gpu.module via region_op fails verification; "
"existing test_grid_qualname_and_call works but only with int sizes"
)
def test_gpu_func_call_with_value_sizes(ctx: MLIRContext):
"""Branch 391->390: GPUFunc.__call__ with Value grid/block sizes"""
from mlir.extras.dialects.arith import constant
from mlir.extras.dialects.gpu import set_container_module

set_container_module(ctx.module)

@gpu.func(emit_grid=True)
@canonicalize(using=scf.canonicalizer)
@gpu.func
def kernel(a: T.memref(4, 4, T.f32())):
return

kernel.qualname = "MyModule"
x = a[0, 0]

@module("MyModule", ["#nvvm.target"])
def gpu_mod():
kernel.func.emit()
kernel.emit()

mem = memref.alloc([4, 4], T.f32())
gx = constant(1, T.index())
Expand All @@ -1617,6 +1610,41 @@ def gpu_mod():
ctx.module.operation.verify()


def test_gpu_func_external_decl_raises(ctx: MLIRContext):
"""gpu.func does not support external declarations"""
with pytest.raises(
ValueError, match="gpu.func does not support external declarations"
):

@gpu.func
def kernel(a: T.memref(4, 4, T.f32())): ...


def test_gpu_func_external_decl_in_gpu_module_raises():
"""gpu.func external decl inside gpu.module also raises"""
from mlir.ir import Context, Location, Module, InsertionPoint

with Context():
with Location.unknown():
module = Module.create()
with InsertionPoint(module.body):
with pytest.raises(
ValueError,
match="gpu.func does not support external declarations",
):

class MyModule(
metaclass=GPUModuleMeta, targets=["#nvvm.target"]
):

@gpu.func
def kernel(a: T.memref(4, 4, T.f32())): ...

# GPUModuleMeta.__prepare__ enters an InsertionPoint that
# never exits when the class body raises; pop it manually.
InsertionPoint.current.__exit__(None, None, None)


def test_launch_with_async_dependencies(ctx: MLIRContext):
"""Branch 301->303: LaunchOp with explicit async_dependencies"""
from mlir.extras.dialects.gpu import launch
Expand Down
Loading