launch-bounds.cu 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - | FileCheck %s
  2. #include "Inputs/cuda.h"
  3. #define MAX_THREADS_PER_BLOCK 256
  4. #define MIN_BLOCKS_PER_MP 2
  5. // Test both max threads per block and Min cta per sm.
  6. extern "C" {
  7. __global__ void
  8. __launch_bounds__( MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP )
  9. Kernel1()
  10. {
  11. }
  12. }
  13. // CHECK: !{{[0-9]+}} = !{void ()* @Kernel1, !"maxntidx", i32 256}
  14. // CHECK: !{{[0-9]+}} = !{void ()* @Kernel1, !"minctasm", i32 2}
  15. // Test only max threads per block. Min cta per sm defaults to 0, and
  16. // CodeGen doesn't output a zero value for minctasm.
  17. extern "C" {
  18. __global__ void
  19. __launch_bounds__( MAX_THREADS_PER_BLOCK )
  20. Kernel2()
  21. {
  22. }
  23. }
  24. // CHECK: !{{[0-9]+}} = !{void ()* @Kernel2, !"maxntidx", i32 256}
  25. template <int max_threads_per_block>
  26. __global__ void
  27. __launch_bounds__(max_threads_per_block)
  28. Kernel3()
  29. {
  30. }
  31. template __global__ void Kernel3<MAX_THREADS_PER_BLOCK>();
  32. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel3{{.*}}, !"maxntidx", i32 256}
  33. template <int max_threads_per_block, int min_blocks_per_mp>
  34. __global__ void
  35. __launch_bounds__(max_threads_per_block, min_blocks_per_mp)
  36. Kernel4()
  37. {
  38. }
  39. template __global__ void Kernel4<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP>();
  40. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel4{{.*}}, !"maxntidx", i32 256}
  41. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel4{{.*}}, !"minctasm", i32 2}
  42. const int constint = 100;
  43. template <int max_threads_per_block, int min_blocks_per_mp>
  44. __global__ void
  45. __launch_bounds__(max_threads_per_block + constint,
  46. min_blocks_per_mp + max_threads_per_block)
  47. Kernel5()
  48. {
  49. }
  50. template __global__ void Kernel5<MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP>();
  51. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel5{{.*}}, !"maxntidx", i32 356}
  52. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel5{{.*}}, !"minctasm", i32 258}
  53. // Make sure we don't emit negative launch bounds values.
  54. __global__ void
  55. __launch_bounds__( -MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP )
  56. Kernel6()
  57. {
  58. }
  59. // CHECK-NOT: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel6{{.*}}, !"maxntidx",
  60. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel6{{.*}}, !"minctasm",
  61. __global__ void
  62. __launch_bounds__( MAX_THREADS_PER_BLOCK, -MIN_BLOCKS_PER_MP )
  63. Kernel7()
  64. {
  65. }
  66. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel7{{.*}}, !"maxntidx",
  67. // CHECK-NOT: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel7{{.*}}, !"minctasm",
  68. const char constchar = 12;
  69. __global__ void __launch_bounds__(constint, constchar) Kernel8() {}
  70. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel8{{.*}}, !"maxntidx", i32 100
  71. // CHECK: !{{[0-9]+}} = !{void ()* @{{.*}}Kernel8{{.*}}, !"minctasm", i32 12