builtins.cu 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. // Tests that host and target builtins can be used in the same TU,
  2. // have appropriate host/device attributes and that CUDA call
  3. // restrictions are enforced. Also verify that non-target builtins can
  4. // be used from both host and device functions.
  5. //
  6. // REQUIRES: x86-registered-target
  7. // REQUIRES: nvptx-registered-target
  8. // RUN: %clang_cc1 -triple x86_64-unknown-unknown \
  9. // RUN: -aux-triple nvptx64-unknown-cuda \
  10. // RUN: -fsyntax-only -verify %s
  11. // RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
  12. // RUN: -aux-triple x86_64-unknown-unknown \
  13. // RUN: -fsyntax-only -verify %s
  14. #if !(defined(__amd64__) && defined(__PTX__))
  15. #error "Expected to see preprocessor macros from both sides of compilation."
  16. #endif
  17. void hf() {
  18. int x = __builtin_ia32_rdtsc();
  19. int y = __nvvm_read_ptx_sreg_tid_x(); // expected-note {{'__nvvm_read_ptx_sreg_tid_x' declared here}}
  20. // expected-error@-1 {{reference to __device__ function '__nvvm_read_ptx_sreg_tid_x' in __host__ function}}
  21. x = __builtin_abs(1);
  22. }
  23. __attribute__((device)) void df() {
  24. int x = __nvvm_read_ptx_sreg_tid_x();
  25. int y = __builtin_ia32_rdtsc(); // expected-error {{reference to __host__ function '__builtin_ia32_rdtsc' in __device__ function}}
  26. // expected-note@20 {{'__builtin_ia32_rdtsc' declared here}}
  27. x = __builtin_abs(1);
  28. }