|
| 1 | +//@ compile-flags: -Zoffload=Enable -C opt-level=3 -Clto=fat |
| 2 | +//@ no-prefer-dynamic |
| 3 | +//@ needs-enzyme |
| 4 | + |
| 5 | +// This test is verifying that we generate __tgt_target_data_*_mapper before and after a call to the |
| 6 | +// kernel_1. Better documentation to what each global or variable means is available in the gpu |
| 7 | +// offlaod code, or the LLVM offload documentation. This code does not launch any GPU kernels yet, |
| 8 | +// and will be rewritten once a proper offload frontend has landed. |
| 9 | +// |
| 10 | +// We currently only handle memory transfer for specific calls to functions named `kernel_{num}`, |
| 11 | +// when inside of a function called main. This, too, is a temporary workaround for not having a |
| 12 | +// frontend. |
| 13 | + |
| 14 | +#![no_main] |
| 15 | + |
| 16 | +#[unsafe(no_mangle)] |
| 17 | +fn main() { |
| 18 | + let mut x = [3.0; 256]; |
| 19 | + kernel_1(&mut x); |
| 20 | + core::hint::black_box(&x); |
| 21 | +} |
| 22 | + |
| 23 | +// CHECK: %struct.ident_t = type { i32, i32, i32, i32, ptr } |
| 24 | +// CHECK: %struct.__tgt_kernel_arguments = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, [3 x i32], [3 x i32], i32 } |
| 25 | +// CHECK: %struct.__tgt_offload_entry = type { i64, i16, i16, i32, ptr, ptr, i64, i64, ptr } |
| 26 | +// CHECK: %struct.__tgt_bin_desc = type { i32, ptr, ptr, ptr } |
| 27 | + |
| 28 | +// CHECK: @0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1 |
| 29 | +// CHECK: @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8 |
| 30 | +// CHECK: @my_struct_global2 = external global %struct.__tgt_kernel_arguments |
| 31 | +// CHECK: @.offload_sizes.1 = private unnamed_addr constant [1 x i64] [i64 1024] |
| 32 | +// CHECK: @.offload_maptypes.1 = private unnamed_addr constant [1 x i64] [i64 3] |
| 33 | +// CHECK: @.kernel_1.region_id = weak unnamed_addr constant i8 0 |
| 34 | +// CHECK: @.offloading.entry_name.1 = internal unnamed_addr constant [9 x i8] c"kernel_1\00", section ".llvm.rodata.offloading", align 1 |
| 35 | +// CHECK: @.offloading.entry.kernel_1 = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 0, ptr @.kernel_1.region_id, ptr @.offloading.entry_name.1, i64 0, i64 0, ptr null }, section ".omp_offloading_entries", align 1 |
| 36 | + |
| 37 | +// CHECK: Function Attrs: |
| 38 | +// CHECK-NEXT: define{{( dso_local)?}} void @main() |
| 39 | +// CHECK-NEXT: start: |
| 40 | +// CHECK-NEXT: %0 = alloca [8 x i8], align 8 |
| 41 | +// CHECK-NEXT: %x = alloca [1024 x i8], align 16 |
| 42 | +// CHECK-NEXT: %EmptyDesc = alloca %struct.__tgt_bin_desc, align 8 |
| 43 | +// CHECK-NEXT: %.offload_baseptrs = alloca [1 x ptr], align 8 |
| 44 | +// CHECK-NEXT: %.offload_ptrs = alloca [1 x ptr], align 8 |
| 45 | +// CHECK-NEXT: %.offload_sizes = alloca [1 x i64], align 8 |
| 46 | +// CHECK-NEXT: %x.addr = alloca ptr, align 8 |
| 47 | +// CHECK-NEXT: store ptr %x, ptr %x.addr, align 8 |
| 48 | +// CHECK-NEXT: %1 = load ptr, ptr %x.addr, align 8 |
| 49 | +// CHECK-NEXT: %2 = getelementptr inbounds float, ptr %1, i32 0 |
| 50 | +// CHECK: call void @llvm.memset.p0.i64(ptr align 8 %EmptyDesc, i8 0, i64 32, i1 false) |
| 51 | +// CHECK-NEXT: call void @__tgt_register_lib(ptr %EmptyDesc) |
| 52 | +// CHECK-NEXT: call void @__tgt_init_all_rtls() |
| 53 | +// CHECK-NEXT: %3 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 |
| 54 | +// CHECK-NEXT: store ptr %1, ptr %3, align 8 |
| 55 | +// CHECK-NEXT: %4 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0 |
| 56 | +// CHECK-NEXT: store ptr %2, ptr %4, align 8 |
| 57 | +// CHECK-NEXT: %5 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0 |
| 58 | +// CHECK-NEXT: store i64 1024, ptr %5, align 8 |
| 59 | +// CHECK-NEXT: %6 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 |
| 60 | +// CHECK-NEXT: %7 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0 |
| 61 | +// CHECK-NEXT: %8 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0 |
| 62 | +// CHECK-NEXT: call void @__tgt_target_data_begin_mapper(ptr @1, i64 -1, i32 1, ptr %6, ptr %7, ptr %8, ptr @.offload_maptypes.1, ptr null, ptr null) |
| 63 | +// CHECK-NEXT: call void @kernel_1(ptr noalias noundef nonnull align 4 dereferenceable(1024) %x) |
| 64 | +// CHECK-NEXT: %9 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0 |
| 65 | +// CHECK-NEXT: %10 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0 |
| 66 | +// CHECK-NEXT: %11 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0 |
| 67 | +// CHECK-NEXT: call void @__tgt_target_data_end_mapper(ptr @1, i64 -1, i32 1, ptr %9, ptr %10, ptr %11, ptr @.offload_maptypes.1, ptr null, ptr null) |
| 68 | +// CHECK-NEXT: call void @__tgt_unregister_lib(ptr %EmptyDesc) |
| 69 | +// CHECK: store ptr %x, ptr %0, align 8 |
| 70 | +// CHECK-NEXT: call void asm sideeffect "", "r,~{memory}"(ptr nonnull %0) |
| 71 | +// CHECK: ret void |
| 72 | +// CHECK-NEXT: } |
| 73 | + |
| 74 | +#[unsafe(no_mangle)] |
| 75 | +#[inline(never)] |
| 76 | +pub fn kernel_1(x: &mut [f32; 256]) { |
| 77 | + for i in 0..256 { |
| 78 | + x[i] = 21.0; |
| 79 | + } |
| 80 | +} |
0 commit comments