main.hip.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <iostream>
  2. #include <hip/hip_runtime_api.h>
  3. #include <inc_hip.h>
  4. #ifndef INC_HIP
  5. # error "INC_HIP not defined!"
  6. #endif
  7. #ifndef PACKED_DEFINE
  8. # error "PACKED_DEFINE not defined!"
  9. #endif
  10. #ifndef FLAG_COMPILE_LANG_HIP
  11. # error "FLAG_COMPILE_LANG_HIP not defined!"
  12. #endif
  13. #ifndef FLAG_LANG_IS_HIP
  14. # error "FLAG_LANG_IS_HIP not defined!"
  15. #endif
  16. #if !FLAG_LANG_IS_HIP
  17. # error "Expected FLAG_LANG_IS_HIP"
  18. #endif
  19. #ifndef DEF_COMPILE_LANG_HIP
  20. # error "DEF_COMPILE_LANG_HIP not defined!"
  21. #endif
  22. #ifndef DEF_LANG_IS_HIP
  23. # error "DEF_LANG_IS_HIP not defined!"
  24. #endif
  25. #if !DEF_LANG_IS_HIP
  26. # error "Expected DEF_LANG_IS_HIP"
  27. #endif
  28. #ifndef DEF_HIP_COMPILER
  29. # error "DEF_HIP_COMPILER not defined!"
  30. #endif
  31. #ifndef DEF_HIP_COMPILER_VERSION
  32. # error "DEF_HIP_COMPILER_VERSION not defined!"
  33. #endif
  34. static __global__ void DetermineIfValidHIPDevice()
  35. {
  36. }
  37. #ifdef _MSC_VER
  38. # pragma pack(push, 1)
  39. # undef PACKED_DEFINE
  40. # define PACKED_DEFINE
  41. #endif
  42. #ifdef __NVCC__
  43. # undef PACKED_DEFINE
  44. # define PACKED_DEFINE
  45. #endif
  46. struct PACKED_DEFINE result_type
  47. {
  48. bool valid;
  49. int value;
  50. #if defined(NDEBUG) && !defined(DEFREL)
  51. # error missing DEFREL flag
  52. #endif
  53. };
  54. #ifdef _MSC_VER
  55. # pragma pack(pop)
  56. #endif
  57. result_type can_launch_kernel()
  58. {
  59. result_type r;
  60. DetermineIfValidHIPDevice<<<1, 1>>>();
  61. r.valid = (hipSuccess == hipGetLastError());
  62. if (r.valid) {
  63. r.value = 1;
  64. } else {
  65. r.value = -1;
  66. }
  67. return r;
  68. }
  69. int main(int argc, char** argv)
  70. {
  71. hipError_t err;
  72. int nDevices = 0;
  73. err = hipGetDeviceCount(&nDevices);
  74. if (err != hipSuccess) {
  75. std::cerr << hipGetErrorString(err) << std::endl;
  76. return 1;
  77. }
  78. return 0;
  79. }