kernel-args-alignment.cu 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // New CUDA kernel launch sequence does not require explicit specification of
  2. // size/offset for each argument, so only the old way is tested.
  3. //
  4. // RUN: %clang_cc1 --std=c++11 -triple x86_64-unknown-linux-gnu -emit-llvm \
  5. // RUN: -target-sdk-version=8.0 -o - %s \
  6. // RUN: | FileCheck -check-prefixes=HOST-OLD,CHECK %s
  7. // RUN: %clang_cc1 --std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda \
  8. // RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=DEVICE,CHECK %s
  9. #include "Inputs/cuda.h"
  10. struct U {
  11. short x;
  12. } __attribute__((packed));
  13. struct S {
  14. int *ptr;
  15. char a;
  16. U u;
  17. };
  18. // Clang should generate a packed LLVM struct for S (denoted by the <>s),
  19. // otherwise this test isn't interesting.
  20. // CHECK: %struct.S = type <{ i32*, i8, %struct.U, [5 x i8] }>
  21. static_assert(alignof(S) == 8, "Unexpected alignment.");
  22. // HOST-LABEL: @_Z6kernelc1SPi
  23. // Marshalled kernel args should be:
  24. // 1. offset 0, width 1
  25. // 2. offset 8 (because alignof(S) == 8), width 16
  26. // 3. offset 24, width 8
  27. // HOST-OLD: call i32 @cudaSetupArgument({{[^,]*}}, i64 1, i64 0)
  28. // HOST-OLD: call i32 @cudaSetupArgument({{[^,]*}}, i64 16, i64 8)
  29. // HOST-OLD: call i32 @cudaSetupArgument({{[^,]*}}, i64 8, i64 24)
  30. // DEVICE-LABEL: @_Z6kernelc1SPi
  31. // DEVICE-SAME: i8{{[^,]*}}, %struct.S* byval(%struct.S) align 8{{[^,]*}}, i32*
  32. __global__ void kernel(char a, S s, int *b) {}