111 lines · plain
1// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s2 3// Checking the translation of the `gpu.binary` & `gpu.launch_fun` ops.4module attributes {gpu.container_module} {5 // CHECK: [[ARGS_TY:%.*]] = type { i32, i32 }6 // CHECK-DAG: @kernel_module_binary = internal constant [4 x i8] c"BLOB", align 87 // CHECK-DAG: kernel_module_module = internal global ptr null8 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @kernel_module_load9 // CHECK-DAG: @llvm.global_dtors = appending global {{.*}} @kernel_module_unload10 // CHECK-DAG: @kernel_module_kernel_name = private unnamed_addr constant [7 x i8] c"kernel\00", align 111 gpu.binary @kernel_module [#gpu.object<#nvvm.target, "BLOB">]12 llvm.func @foo() {13 // CHECK: [[ARGS:%.*]] = alloca %{{.*}}, align 814 // CHECK: [[ARGS_ARRAY:%.*]] = alloca ptr, i64 2, align 815 // CHECK: [[ARG0:%.*]] = getelementptr inbounds nuw [[ARGS_TY]], ptr [[ARGS]], i32 0, i32 016 // CHECK: store i32 32, ptr [[ARG0]], align 417 // CHECK: %{{.*}} = getelementptr ptr, ptr [[ARGS_ARRAY]], i32 018 // CHECK: store ptr [[ARG0]], ptr %{{.*}}, align 819 // CHECK: [[ARG1:%.*]] = getelementptr inbounds nuw [[ARGS_TY]], ptr [[ARGS]], i32 0, i32 120 // CHECK: store i32 32, ptr [[ARG1]], align 421 // CHECK: %{{.*}} = getelementptr ptr, ptr [[ARGS_ARRAY]], i32 122 // CHECK: store ptr [[ARG1]], ptr %{{.*}}, align 823 // CHECK: [[MODULE:%.*]] = load ptr, ptr @kernel_module_module24 // CHECK: [[FUNC:%.*]] = call ptr @mgpuModuleGetFunction(ptr [[MODULE]], ptr @kernel_module_kernel_name)25 // CHECK: [[STREAM:%.*]] = call ptr @mgpuStreamCreate()26 // CHECK: call void @mgpuLaunchKernel(ptr [[FUNC]], i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i32 256, ptr [[STREAM]], ptr [[ARGS_ARRAY]], ptr null, i64 2)27 // CHECK: call void @mgpuStreamSynchronize(ptr [[STREAM]])28 // CHECK: call void @mgpuStreamDestroy(ptr [[STREAM]])29 %0 = llvm.mlir.constant(8 : index) : i6430 %1 = llvm.mlir.constant(32 : i32) : i3231 %2 = llvm.mlir.constant(256 : i32) : i3232 gpu.launch_func @kernel_module::@kernel blocks in (%0, %0, %0) threads in (%0, %0, %0) : i64 dynamic_shared_memory_size %2 args(%1 : i32, %1 : i32)33 llvm.return34 }35 // CHECK: @kernel_module_load() section ".text.startup"36 // CHECK: [[MODULE:%.*]] = call ptr @mgpuModuleLoad37 // CHECK: store ptr [[MODULE]], ptr @kernel_module_module38 //39 // CHECK: @kernel_module_unload() section ".text.startup"40 // CHECK: [[MODULE:%.*]] = load ptr, ptr @kernel_module_module41 // CHECK: call void @mgpuModuleUnload(ptr [[MODULE]])42}43 44// -----45 46// Checking the correct selection of the second object using an index as a selector.47module {48 // CHECK: @kernel_module_binary = internal constant [1 x i8] c"1", align 849 gpu.binary @kernel_module <#gpu.select_object<1>> [#gpu.object<#nvvm.target, "0">, #gpu.object<#nvvm.target, "1">]50}51 52// -----53 54// Checking the correct selection of the second object using a target as a selector.55module {56 // CHECK: @kernel_module_binary = internal constant [6 x i8] c"AMDGPU", align 857 gpu.binary @kernel_module <#gpu.select_object<#rocdl.target>> [#gpu.object<#nvvm.target, "NVPTX">, #gpu.object<#rocdl.target, "AMDGPU">]58}59 60// -----61 62// Checking the correct selection of the second object using a target as a selector.63module {64 // CHECK: @kernel_module_binary = internal constant [4 x i8] c"BLOB", align 865 gpu.binary @kernel_module <#gpu.select_object<#spirv.target_env<#spirv.vce<v1.0, [Addresses, Int64, Kernel], []>, api=OpenCL, #spirv.resource_limits<>>>> [#gpu.object<#nvvm.target, "NVPTX">, #gpu.object<#spirv.target_env<#spirv.vce<v1.0, [Addresses, Int64, Kernel], []>, api=OpenCL, #spirv.resource_limits<>>, "BLOB">]66}67 68// -----69// Checking the translation of `gpu.launch_fun` with an async dependency.70module attributes {gpu.container_module} {71 gpu.binary @kernel_module [#gpu.object<#rocdl.target, "BLOB">]72 llvm.func @foo(%stream : !llvm.ptr) {73 %0 = llvm.mlir.constant(8 : index) : i6474 // CHECK-NOT: @mgpuStreamCreate75 // CHECK: call void @mgpuLaunchKernel76 gpu.launch_func <%stream : !llvm.ptr> @kernel_module::@kernel blocks in (%0, %0, %0) threads in (%0, %0, %0) : i6477 // CHECK-NOT: @mgpuStreamSynchronize78 // CHECK-NOT: @mgpuStreamDestroy79 llvm.return80 }81}82 83// -----84 85// Test cluster/block/thread syntax.86module attributes {gpu.container_module} {87 gpu.binary @kernel_module [#gpu.object<#nvvm.target, "BLOB">]88 llvm.func @foo() {89 // CHECK: call void @mgpuLaunchClusterKernel(90 // CHECK-SAME: i64 1, i64 1, i64 1,91 // CHECK-SAME: i64 2, i64 2, i64 2,92 // CHECK-SAME: i64 3, i64 3, i64 3, i32 0, ptr93 %c1 = llvm.mlir.constant(1 : index) : i6494 %c2 = llvm.mlir.constant(2 : index) : i6495 %c3 = llvm.mlir.constant(3 : index) : i6496 gpu.launch_func @kernel_module::@kernel 97 clusters in (%c1, %c1, %c1)98 blocks in (%c2, %c2, %c2)99 threads in (%c3, %c3, %c3) : i64100 llvm.return101 }102}103 104// -----105 106// Checking that ELF section is populated107module attributes {gpu.container_module} {108 // CHECK: @cuda_device_mod_binary = internal constant [4 x i8] c"BLOB", section "__nv_rel_fatbin", align 8109 gpu.binary @cuda_device_mod [#gpu.object<#nvvm.target, properties = {section = "__nv_rel_fatbin"}, "BLOB">]110}111