|
1 | | -// Tests that we can run multiple kernels concurrently. Runs two kernels, which |
2 | | -// increment a global atomic counter, then wait for the counter to reach 2. |
| 1 | +// Tests multiple kernels running concurrently. Runs two kernels, which |
| 2 | +// increment a global atomic counter and wait for the counter to reach 2. |
3 | 3 | // |
4 | 4 | // RUN: mlir-opt %s \ |
5 | 5 | // RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format" \ |
6 | | -// RUN: | mlir-runner \ |
| 6 | +// RUN: | CUDA_MODULE_LOADING=EAGER mlir-runner \ |
7 | 7 | // RUN: --shared-libs=%mlir_cuda_runtime \ |
8 | 8 | // RUN: --shared-libs=%mlir_runner_utils \ |
9 | 9 | // RUN: --entry-point-result=void |
10 | 10 |
|
| 11 | +// CUDA_MODULE_LOADING=EAGER avoids an implicit context synchronization on first |
| 12 | +// use of each kernel. It is technically not needed for this test, because |
| 13 | +// there is only one kernel. |
| 14 | + |
11 | 15 | module attributes {gpu.container_module} { |
12 | | - gpu.module @kernels { |
13 | | - gpu.func @kernel(%memref: memref<i32>) kernel { |
14 | | - %c0 = arith.constant 0 : i32 |
15 | | - %c1 = arith.constant 1 : i32 |
16 | | - %c2 = arith.constant 2 : i32 |
17 | | - %block = memref.atomic_rmw addi %c1, %memref[] : (i32, memref<i32>) -> i32 |
18 | | - scf.while: () -> () { |
19 | | - %value = memref.atomic_rmw addi %c0, %memref[] : (i32, memref<i32>) -> i32 |
20 | | - %cond = arith.cmpi slt, %value, %c2 : i32 |
21 | | - scf.condition(%cond) |
22 | | - } do { |
23 | | - scf.yield |
24 | | - } |
25 | | - gpu.return |
26 | | - } |
| 16 | + |
| 17 | +gpu.module @kernels { |
| 18 | + gpu.func @kernel(%memref: memref<i32>) kernel { |
| 19 | + %c0 = arith.constant 0 : i32 |
| 20 | + %c1 = arith.constant 1 : i32 |
| 21 | + %c2 = arith.constant 2 : i32 |
| 22 | + %block = memref.atomic_rmw addi %c1, %memref[] : (i32, memref<i32>) -> i32 |
| 23 | + scf.while: () -> () { |
| 24 | + %value = memref.atomic_rmw addi %c0, %memref[] : (i32, memref<i32>) -> i32 |
| 25 | + %cond = arith.cmpi slt, %value, %c2 : i32 |
| 26 | + scf.condition(%cond) |
| 27 | + } do { |
| 28 | + scf.yield |
27 | 29 | } |
| 30 | + gpu.return |
| 31 | + } |
| 32 | +} |
28 | 33 |
|
29 | | - func.func @main() { |
30 | | - %memref = gpu.alloc host_shared () : memref<i32> |
31 | | - %c0 = arith.constant 0 : i32 |
32 | | - memref.store %c0, %memref[] : memref<i32> |
| 34 | +func.func @main() { |
| 35 | + %c0 = arith.constant 0 : i32 |
| 36 | + %c1 = arith.constant 1 : index |
| 37 | + %memref = gpu.alloc host_shared () : memref<i32> |
| 38 | + memref.store %c0, %memref[] : memref<i32> |
| 39 | + %0 = gpu.wait async |
| 40 | + %1 = gpu.wait async |
| 41 | + %2 = gpu.launch_func async [%0] @kernels::@kernel |
| 42 | + blocks in (%c1, %c1, %c1) |
| 43 | + threads in (%c1, %c1, %c1) |
| 44 | + args(%memref: memref<i32>) |
| 45 | + %3 = gpu.launch_func async [%1] @kernels::@kernel |
| 46 | + blocks in (%c1, %c1, %c1) |
| 47 | + threads in (%c1, %c1, %c1) |
| 48 | + args(%memref: memref<i32>) |
| 49 | + gpu.wait [%2, %3] |
| 50 | + return |
| 51 | +} |
33 | 52 |
|
34 | | - %0 = gpu.wait async |
35 | | - %1 = gpu.wait async |
36 | | - %c1 = arith.constant 1 : index |
37 | | - %2 = gpu.launch_func async [%0] @kernels::@kernel |
38 | | - blocks in (%c1, %c1, %c1) |
39 | | - threads in (%c1, %c1, %c1) |
40 | | - args(%memref: memref<i32>) |
41 | | - %3 = gpu.launch_func async [%1] @kernels::@kernel |
42 | | - blocks in (%c1, %c1, %c1) |
43 | | - threads in (%c1, %c1, %c1) |
44 | | - args(%memref: memref<i32>) |
45 | | - gpu.wait [%2, %3] |
46 | | - return |
47 | | - } |
48 | 53 | } |
0 commit comments