Skip to content
Draft
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
19 changes: 19 additions & 0 deletions examples/cuda_tile/tile_example.spy
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ def exported() -> None:
store_view_tko(added, pviewA, unpack_blockIdx_x(blockidxs), token)


I1 = MLIR_Type("i1")
TileI1 = MLIR_Type("!cuda_tile.tile<{}>", I1)
# equal = MLIR_asm("cuda_tile.cmpi {comparison_predicate=#cuda_tile.comparison_predicate<equal>, signedness=#cuda_tile.signedness<signed>}", Tile128xI1, (Tile128xI32, Tile128xI32))
# "cuda_tile.constant"() <{value = dense<[1, 2, 3, 4]> : !cuda_tile.tile<4xi32>}> : () -> !cuda_tile.tile<4xi32>
const_one = MLIR_asm("cuda_tile.constant {value = dense<true> : !cuda_tile.tile<i1>}", bool, ())

if_op = MLIR_op("cuda_tile.if", bool, (TileI1,))

def export_ifelse(a: TilePtrF64) -> None:
tid = iota()
ptrs = offset(broadcast(reshape(a)), tid)
tko = load_ptr_tko(ptrs) # load pointers
v = unpack_0(tko) # MLIR details to get the tile data

if const_one():
printfn(v) # print the tile data

return

_ = exported()


Expand Down
31 changes: 17 additions & 14 deletions nbcc/cutile_backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

from cuda_tile._mlir.extras import types as _tile_types
import cuda_tile._mlir.ir as ir # Context, Location, Module, Type

from nbcc.developer import TODO
from nbcc.mlir_lowering import LowerStates


def entry(
sym_name,
function_type,
Expand Down Expand Up @@ -87,7 +85,8 @@ def __init__(self, tu: TranslationUnit):
self._i32 = ir.IntegerType.get_signless(32)
self._i64 = ir.IntegerType.get_signless(64)
self._boolean = ir.IntegerType.get_signless(1)
self._io_type = ir.IntegerType.get_signless(1)
self._io_bitype = ir.IntegerType.get_signless(1)
self._io_type = ir.Type.parse("!cuda_tile.tile<i1>")
self._none_type = ir.IntegerType.get_signless(1)

@classmethod
Expand Down Expand Up @@ -165,7 +164,7 @@ def create_constant(self, value, type):
return op

def initialize_io(self):
return self.create_constant(0, self.io_type)
return self.create_constant(0, self._io_bitype)

def create_none(self):
return self.create_constant(0, self.none_type)
Expand Down Expand Up @@ -275,13 +274,15 @@ def wrap(self, fqn, args):
def _handle_builtins_i32(self, fqn: FQN, args: tuple):
return (self.i32,)

@disp.case(by_typename("builtins::bool"))
def _handle_builtins_bool(self, fqn: FQN, args: tuple):
boolty = ir.Type.parse("!cuda_tile.tile<i1>")
return (boolty,)

@disp.case(by_typename("types::NoneType"))
def _handle_none(self, fqn: FQN, args: tuple):
return ()

def get_ll_type(self, expr, mdmap) -> ir.Type | None:
"""Get backend type for expression with metadata."""
raise NotImplementedError

def handle_builtin_op(
self, op_name: str, args, state, lowering_instance=None
Expand Down Expand Up @@ -312,17 +313,19 @@ def create_constant_boolean(self, value: bool):
return self.create_constant(int(value), "i1")

# Control flow methods
def create_if_op(self, condition, result_types, has_else=True):
def create_if_op(self, condition, result_types, operands, has_else=True, ):
"""Create if-else control flow operation - may not be supported in CuTile."""
raise UnsupportedError(
"SCF if operations not supported in CuTile backend"
)
from types import SimpleNamespace
ifop = _cuda_tile.IfOp(results_=result_types, condition=condition)
ns = SimpleNamespace()
ns.then_block = ifop.thenRegion.blocks.append()
ns.else_block = ifop.elseRegion.blocks.append()
ns.results = ifop.results_
return ns

def create_yield_op(self, operands):
"""Create yield operation - may not be supported in CuTile."""
raise UnsupportedError(
"SCF yield operations not supported in CuTile backend"
)
return _cuda_tile.yield_(operands)

def create_while_op(self, result_types, init_args):
"""Create while loop operation - may not be supported in CuTile."""
Expand Down
Loading
Loading