from mlir.ir import *
from mlir.dialects import nvgpu, arith, memref
def constructAndPrintInModule(f):
print("\nTEST:", f.__name__)
with Context(), Location.unknown():
module = Module.create()
with InsertionPoint(module.body):
f()
print(module)
return f
@constructAndPrintInModule
def testTypes():
tensorMemrefType = MemRefType.get(
(128, 64), F16Type.get(), memory_space=Attribute.parse("3")
)
tma_desc = nvgpu.TensorMapDescriptorType.get(
tensorMemrefType,
nvgpu.TensorMapSwizzleKind.SWIZZLE_128B,
nvgpu.TensorMapL2PromoKind.L2PROMO_256B,
nvgpu.TensorMapOOBKind.OOB_NAN,
nvgpu.TensorMapInterleaveKind.INTERLEAVE_NONE,
)
print(tma_desc)
@constructAndPrintInModule
def testSmoke():
cst = arith.ConstantOp(value=42, result=IndexType.get())
mem_t = MemRefType.get((10, 10), F32Type.get(), memory_space=Attribute.parse("3"))
vec_t = VectorType.get((4, 1), F32Type.get())
mem = memref.AllocOp(mem_t, [], [])
nvgpu.LdMatrixOp(vec_t, mem, [cst, cst], False, 4)