main.notcu 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <cuda.h>
  2. #include <cuda_runtime.h>
  3. #include <iostream>
  4. #include <inc_cuda.h>
  5. #ifndef INC_CUDA
  6. #error "INC_CUDA not defined!"
  7. #endif
  8. #ifndef HOST_DEFINE
  9. #error "HOST_DEFINE not defined!"
  10. #endif
  11. #ifndef PACKED_DEFINE
  12. #error "PACKED_DEFINE not defined!"
  13. #endif
  14. #ifndef FLAG_COMPILE_LANG_CUDA
  15. #error "FLAG_COMPILE_LANG_CUDA not defined!"
  16. #endif
  17. #ifndef FLAG_LANG_IS_CUDA
  18. #error "FLAG_LANG_IS_CUDA not defined!"
  19. #endif
  20. #if !FLAG_LANG_IS_CUDA
  21. #error "Expected FLAG_LANG_IS_CUDA"
  22. #endif
  23. #ifndef DEF_COMPILE_LANG_CUDA
  24. #error "DEF_COMPILE_LANG_CUDA not defined!"
  25. #endif
  26. #ifndef DEF_LANG_IS_CUDA
  27. #error "DEF_LANG_IS_CUDA not defined!"
  28. #endif
  29. #if !DEF_LANG_IS_CUDA
  30. #error "Expected DEF_LANG_IS_CUDA"
  31. #endif
  32. static __global__ void DetermineIfValidCudaDevice()
  33. {
  34. }
  35. #ifdef _MSC_VER
  36. #pragma pack(push, 1)
  37. #undef PACKED_DEFINE
  38. #define PACKED_DEFINE
  39. #endif
  40. struct PACKED_DEFINE result_type
  41. {
  42. bool valid;
  43. int value;
  44. #if defined(NDEBUG) && !defined(DEFREL)
  45. #error missing DEFREL flag
  46. #endif
  47. };
  48. #ifdef _MSC_VER
  49. #pragma pack(pop)
  50. #endif
  51. result_type can_launch_kernel()
  52. {
  53. result_type r;
  54. DetermineIfValidCudaDevice<<<1, 1>>>();
  55. r.valid = (cudaSuccess == cudaGetLastError());
  56. if (r.valid) {
  57. r.value = 1;
  58. } else {
  59. r.value = -1;
  60. }
  61. return r;
  62. }
  63. int main(int argc, char** argv)
  64. {
  65. cudaError_t err;
  66. int nDevices = 0;
  67. err = cudaGetDeviceCount(&nDevices);
  68. if (err != cudaSuccess) {
  69. std::cerr << cudaGetErrorString(err) << std::endl;
  70. return 1;
  71. }
  72. return 0;
  73. }