| 1 |
// RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - | FileCheck %s |
| 2 |
// RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -target-cpu sm_90 -DUSE_MAX_BLOCKS -fcuda-is-device -emit-llvm -o - | FileCheck -check-prefix=CHECK_MAX_BLOCKS %s |
| 3 |
|
| 4 |
#include "Inputs/cuda.h" |
| 5 |
|
| 6 |
#define MAX_THREADS_PER_BLOCK 256 |
| 7 |
#define MIN_BLOCKS_PER_MP 2 |
| 8 |
#ifdef USE_MAX_BLOCKS |
| 9 |
#define MAX_BLOCKS_PER_MP 4 |
| 10 |
#endif |
| 11 |
|
| 12 |
// CHECK: @Kernel1() #[[ATTR0:[0-9]+]] |
| 13 |
// CHECK: @Kernel2() #[[ATTR1:[0-9]+]] |
| 14 |
// CHECK: @{{.*}}Kernel3{{.*}}() #[[ATTR1]] |
| 15 |
// CHECK: @{{.*}}Kernel4{{.*}}() #[[ATTR0]] |
| 16 |
// CHECK: @{{.*}}Kernel5{{.*}}() #[[ATTR2:[0-9]+]] |
| 17 |
// CHECK: @{{.*}}Kernel6{{.*}}() #[[ATTR3:[0-9]+]] |
| 18 |
// CHECK: @{{.*}}Kernel7{{.*}}() #[[ATTR1]] |
| 19 |
// CHECK: @{{.*}}Kernel8{{.*}}() #[[ATTR4:[0-9]+]] |
| 20 |
|
| 21 |
// CHECK-DAG: attributes #[[ATTR0]] = {{{.*}} "nvvm.maxntid"="256" "nvvm.minctasm"="2" {{.*}}} |
| 22 |
// CHECK-DAG: attributes #[[ATTR1]] = {{{.*}} "nvvm.maxntid"="256" {{.*}}} |
| 23 |
// CHECK-DAG: attributes #[[ATTR2]] = {{{.*}} "nvvm.maxntid"="356" "nvvm.minctasm"="258" {{.*}}} |
| 24 |
// CHECK-DAG: attributes #[[ATTR3]] = {{{.*}} "nvvm.minctasm"="2" {{.*}}} |
| 25 |
// CHECK-DAG: attributes #[[ATTR4]] = {{{.*}} "nvvm.maxntid"="100" "nvvm.minctasm"="12" {{.*}}} |
| 26 |
|
| 27 |
// CHECK_MAX_BLOCKS: @Kernel1_sm_90() #[[ATTR0:[0-9]+]] |
| 28 |
// CHECK_MAX_BLOCKS: @{{.*}}Kernel4_sm_90{{.*}} #[[ATTR0]] |
| 29 |
// CHECK_MAX_BLOCKS: @{{.*}}Kernel5_sm_90{{.*}} #[[ATTR1:[0-9]+]] |
| 30 |
// CHECK_MAX_BLOCKS: @{{.*}}Kernel7_sm_90{{.*}} #[[ATTR2:[0-9]+]] |
| 31 |
// CHECK_MAX_BLOCKS: @{{.*}}Kernel8_sm_90{{.*}} #[[ATTR3:[0-9]+]] |
| 32 |
|
| 33 |
// CHECK_MAX_BLOCKS-DAG: attributes #[[ATTR0]] = {{{.*}} "nvvm.maxclusterrank"="4" "nvvm.maxntid"="256" "nvvm.minctasm"="2" {{.*}}} |
| 34 |
// CHECK_MAX_BLOCKS-DAG: attributes #[[ATTR1]] = {{{.*}} "nvvm.maxclusterrank"="260" "nvvm.maxntid"="356" "nvvm.minctasm"="258" {{.*}}} |
| 35 |
// CHECK_MAX_BLOCKS-DAG: attributes #[[ATTR2]] = {{{.*}} "nvvm.maxntid"="256" {{.*}}} |
| 36 |
// CHECK_MAX_BLOCKS-DAG: attributes #[[ATTR3]] = {{{.*}} "nvvm.maxclusterrank"="14" "nvvm.maxntid"="100" "nvvm.minctasm"="12" {{.*}}} |
| 37 |
|
| 38 |
// Test both max threads per block and Min cta per sm. |
| 39 |
extern "C" { |
| 40 |
__global__ void |
| 41 |
__launch_bounds__( MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP ) |
| 42 |
Kernel1() |
| 43 |
{ |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
#ifdef USE_MAX_BLOCKS |
| 48 |
// Test max threads per block and min/max cta per sm. |
| 49 |
extern "C" { |
| 50 |
__global__ void |
| 51 |
__launch_bounds__( MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP, MAX_BLOCKS_PER_MP ) |
| 52 |
Kernel1_sm_90() |
| 53 |
{ |
| 54 |
} |
| 55 |
} |
| 56 |
#endif // USE_MAX_BLOCKS |
| 57 |
|
| 58 |
// Test only max threads per block. Min cta per sm defaults to 0, and |
| 59 |
// CodeGen doesn't output a zero value for minctasm. |
| 60 |
extern "C" { |
| 61 |
__global__ void |
| 62 |
__launch_bounds__( MAX_THREADS_PER_BLOCK ) |
| 63 |
Kernel2() |
| 64 |
{ |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
template <int max_threads_per_block> |
| 69 |
__global__ void |
| 70 |
__launch_bounds__(max_threads_per_block) |
| 71 |
Kernel3() |
| 72 |
{ |
| 73 |
} |
| 74 |
|
| 75 |
template __global__ void Kernel3<MAX_THREADS_PER_BLOCK>(); |
| 76 |
|
| 77 |
template <int max_threads_per_block, int min_blocks_per_mp> |
| 78 |
__global__ void |
| 79 |
__launch_bounds__(max_threads_per_block, min_blocks_per_mp) |
| 80 |
Kernel4() |
| 81 |
{ |
| 82 |
} |
| 83 |
template __global__ void Kernel4<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP>(); |
| 84 |
|
| 85 |
|
| 86 |
#ifdef USE_MAX_BLOCKS |
| 87 |
template <int max_threads_per_block, int min_blocks_per_mp, int max_blocks_per_mp> |
| 88 |
__global__ void |
| 89 |
__launch_bounds__(max_threads_per_block, min_blocks_per_mp, max_blocks_per_mp) |
| 90 |
Kernel4_sm_90() |
| 91 |
{ |
| 92 |
} |
| 93 |
template __global__ void Kernel4_sm_90<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP, MAX_BLOCKS_PER_MP>(); |
| 94 |
|
| 95 |
#endif //USE_MAX_BLOCKS |
| 96 |
|
| 97 |
const int constint = 100; |
| 98 |
template <int max_threads_per_block, int min_blocks_per_mp> |
| 99 |
__global__ void |
| 100 |
__launch_bounds__(max_threads_per_block + constint, |
| 101 |
min_blocks_per_mp + max_threads_per_block) |
| 102 |
Kernel5() |
| 103 |
{ |
| 104 |
} |
| 105 |
template __global__ void Kernel5<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP>(); |
| 106 |
|
| 107 |
#ifdef USE_MAX_BLOCKS |
| 108 |
|
| 109 |
template <int max_threads_per_block, int min_blocks_per_mp, int max_blocks_per_mp> |
| 110 |
__global__ void |
| 111 |
__launch_bounds__(max_threads_per_block + constint, |
| 112 |
min_blocks_per_mp + max_threads_per_block, |
| 113 |
max_blocks_per_mp + max_threads_per_block) |
| 114 |
Kernel5_sm_90() |
| 115 |
{ |
| 116 |
} |
| 117 |
template __global__ void Kernel5_sm_90<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP, MAX_BLOCKS_PER_MP>(); |
| 118 |
|
| 119 |
#endif //USE_MAX_BLOCKS |
| 120 |
|
| 121 |
// Make sure we don't emit negative launch bounds values. |
| 122 |
__global__ void |
| 123 |
__launch_bounds__( -MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP ) |
| 124 |
Kernel6() |
| 125 |
{ |
| 126 |
} |
| 127 |
|
| 128 |
__global__ void |
| 129 |
__launch_bounds__( MAX_THREADS_PER_BLOCK, -MIN_BLOCKS_PER_MP ) |
| 130 |
Kernel7() |
| 131 |
{ |
| 132 |
} |
| 133 |
|
| 134 |
#ifdef USE_MAX_BLOCKS |
| 135 |
__global__ void |
| 136 |
__launch_bounds__( MAX_THREADS_PER_BLOCK, -MIN_BLOCKS_PER_MP, -MAX_BLOCKS_PER_MP ) |
| 137 |
Kernel7_sm_90() |
| 138 |
{ |
| 139 |
} |
| 140 |
#endif // USE_MAX_BLOCKS |
| 141 |
|
| 142 |
const char constchar = 12; |
| 143 |
__global__ void __launch_bounds__(constint, constchar) Kernel8() {} |
| 144 |
|
| 145 |
#ifdef USE_MAX_BLOCKS |
| 146 |
const char constchar_2 = 14; |
| 147 |
__global__ void __launch_bounds__(constint, constchar, constchar_2) Kernel8_sm_90() {} |
| 148 |
#endif // USE_MAX_BLOCKS |