1# RUN: %PYTHON %s | FileCheck %s 2 3from mlir.ir import * 4import mlir.dialects.gpu as gpu 5import mlir.dialects.gpu.passes 6from mlir.passmanager import * 7 8 9def run(f): 10 print("\nTEST:", f.__name__) 11 with Context(), Location.unknown(): 12 f() 13 return f 14 15 16# CHECK-LABEL: testGPUPass 17# CHECK: SUCCESS 18@run 19def testGPUPass(): 20 PassManager.parse("any(gpu-kernel-outlining)") 21 print("SUCCESS") 22 23 24# CHECK-LABEL: testMMAElementWiseAttr 25@run 26def testMMAElementWiseAttr(): 27 module = Module.create() 28 with InsertionPoint(module.body): 29 gpu.BlockDimOp(gpu.Dimension.y) 30 # CHECK: %block_dim_y = gpu.block_dim y 31 print(module) 32 pass 33 34 35# CHECK-LABEL: testObjectAttr 36@run 37def testObjectAttr(): 38 target = Attribute.parse("#nvvm.target") 39 format = gpu.CompilationTarget.Fatbin 40 object = b"BC\xc0\xde5\x14\x00\x00\x05\x00\x00\x00b\x0c0$MY\xbef" 41 properties = DictAttr.get({"O": IntegerAttr.get(IntegerType.get_signless(32), 2)}) 42 o = gpu.ObjectAttr.get(target, format, object, properties) 43 # CHECK: #gpu.object<#nvvm.target, properties = {O = 2 : i32}, "BC\C0\DE5\14\00\00\05\00\00\00b\0C0$MY\BEf"> 44 print(o) 45 assert o.object == object 46 47 o = gpu.ObjectAttr.get(target, format, object) 48 # CHECK: #gpu.object<#nvvm.target, "BC\C0\DE5\14\00\00\05\00\00\00b\0C0$MY\BEf"> 49 print(o) 50 51 object = ( 52 b"//\n// Generated by LLVM NVPTX Back-End\n//\n\n.version 6.0\n.target sm_50" 53 ) 54 o = gpu.ObjectAttr.get(target, format, object) 55 # CHECK: #gpu.object<#nvvm.target, "//\0A// Generated by LLVM NVPTX Back-End\0A//\0A\0A.version 6.0\0A.target sm_50"> 56 print(o) 57 assert o.object == object 58 59 object = b"BC\xc0\xde5\x14\x00\x00\x05\x00\x00\x00b\x0c0$MY\xbef" 60 kernelTable = Attribute.parse( 61 '#gpu.kernel_table<[#gpu.kernel_metadata<"kernel", () -> ()>]>' 62 ) 63 o = gpu.ObjectAttr.get(target, format, object, kernels=kernelTable) 64 # CHECK: #gpu.object<#nvvm.target, kernels = <[#gpu.kernel_metadata<"kernel", () -> ()>]>, "BC\C0\DE5\14\00\00\05\00\00\00b\0C0$MY\BEf"> 65 print(o) 66 assert o.kernels == kernelTable 67