16995183eSJungwook Park# REQUIRES: host-supports-nvptx 26995183eSJungwook Park# RUN: %PYTHON %s | FileCheck %s 36995183eSJungwook Park 46995183eSJungwook Parkfrom mlir.ir import * 56995183eSJungwook Parkimport mlir.dialects.gpu as gpu 66995183eSJungwook Parkimport mlir.dialects.gpu.passes 76995183eSJungwook Parkfrom mlir.passmanager import * 86995183eSJungwook Park 96995183eSJungwook Park 106995183eSJungwook Parkdef run(f): 116995183eSJungwook Park print("\nTEST:", f.__name__) 126995183eSJungwook Park with Context(), Location.unknown(): 136995183eSJungwook Park f() 146995183eSJungwook Park return f 156995183eSJungwook Park 166995183eSJungwook Park 176995183eSJungwook Park# CHECK-LABEL: testGPUToLLVMBin 186995183eSJungwook Park@run 196995183eSJungwook Parkdef testGPUToLLVMBin(): 206995183eSJungwook Park with Context(): 216995183eSJungwook Park module = Module.parse( 226995183eSJungwook Park r""" 236995183eSJungwook Parkmodule attributes {gpu.container_module} { 246995183eSJungwook Park gpu.module @kernel_module1 [#nvvm.target<chip = "sm_70">] { 257ed96b1cSChristian Ulmann llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr, 267ed96b1cSChristian Ulmann %arg2: !llvm.ptr, %arg3: i64, %arg4: i64, 276995183eSJungwook Park %arg5: i64) attributes {gpu.kernel} { 286995183eSJungwook Park llvm.return 296995183eSJungwook Park } 306995183eSJungwook Park } 316995183eSJungwook Park} 326995183eSJungwook Park """ 336995183eSJungwook Park ) 346995183eSJungwook Park pm = PassManager("any") 356995183eSJungwook Park pm.add("gpu-module-to-binary{format=llvm}") 366995183eSJungwook Park pm.run(module.operation) 376995183eSJungwook Park # CHECK-LABEL: gpu.binary @kernel_module1 38*6e6da74cSMaksim Levental print(module) 39*6e6da74cSMaksim Levental 40*6e6da74cSMaksim Levental o = gpu.ObjectAttr(module.body.operations[0].objects[0]) 41*6e6da74cSMaksim Levental # CHECK: #gpu.object<#nvvm.target<chip = "sm_70">, offload = "{{.*}}"> 42*6e6da74cSMaksim Levental print(o) 43*6e6da74cSMaksim Levental # CHECK: #nvvm.target<chip = "sm_70"> 44*6e6da74cSMaksim Levental print(o.target) 45*6e6da74cSMaksim Levental # CHECK: offload 46*6e6da74cSMaksim Levental print(gpu.CompilationTarget(o.format)) 47*6e6da74cSMaksim Levental # CHECK: b'{{.*}}' 48*6e6da74cSMaksim Levental print(o.object) 49*6e6da74cSMaksim Levental # CHECK: None 50*6e6da74cSMaksim Levental print(o.properties) 516995183eSJungwook Park 526995183eSJungwook Park 536995183eSJungwook Park# CHECK-LABEL: testGPUToASMBin 546995183eSJungwook Park@run 556995183eSJungwook Parkdef testGPUToASMBin(): 566995183eSJungwook Park with Context(): 576995183eSJungwook Park module = Module.parse( 586995183eSJungwook Park r""" 596995183eSJungwook Parkmodule attributes {gpu.container_module} { 606995183eSJungwook Park gpu.module @kernel_module2 [#nvvm.target<flags = {fast}>, #nvvm.target] { 617ed96b1cSChristian Ulmann llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr, 627ed96b1cSChristian Ulmann %arg2: !llvm.ptr, %arg3: i64, %arg4: i64, 636995183eSJungwook Park %arg5: i64) attributes {gpu.kernel} { 646995183eSJungwook Park llvm.return 656995183eSJungwook Park } 666995183eSJungwook Park } 676995183eSJungwook Park} 686995183eSJungwook Park """ 696995183eSJungwook Park ) 706995183eSJungwook Park pm = PassManager("any") 716995183eSJungwook Park pm.add("gpu-module-to-binary{format=isa}") 726995183eSJungwook Park pm.run(module.operation) 736995183eSJungwook Park # CHECK-LABEL:gpu.binary @kernel_module2 74*6e6da74cSMaksim Levental print(module) 75*6e6da74cSMaksim Levental 76*6e6da74cSMaksim Levental o = gpu.ObjectAttr(module.body.operations[0].objects[0]) 77*6e6da74cSMaksim Levental # CHECK: #gpu.object<#nvvm.target<flags = {fast}> 78*6e6da74cSMaksim Levental print(o) 79*6e6da74cSMaksim Levental # CHECK: #nvvm.target<flags = {fast}> 80*6e6da74cSMaksim Levental print(o.target) 81*6e6da74cSMaksim Levental # CHECK: assembly 82*6e6da74cSMaksim Levental print(gpu.CompilationTarget(o.format)) 83*6e6da74cSMaksim Levental # CHECK: b'//\n// Generated by LLVM NVPTX Back-End{{.*}}' 84*6e6da74cSMaksim Levental print(o.object) 85*6e6da74cSMaksim Levental # CHECK: {O = 2 : i32} 86*6e6da74cSMaksim Levental print(o.properties) 87