| 1 |
#include <cuda_runtime.h> |
| 2 |
#include <cublas_v2.h> |
| 3 |
#include <iostream> |
| 4 |
|
| 5 |
void do_cuda_stuff(void); |
| 6 |
|
| 7 |
int cuda_devices(void) { |
| 8 |
int result = 0; |
| 9 |
cudaGetDeviceCount(&result); |
| 10 |
return result; |
| 11 |
} |
| 12 |
|
| 13 |
int main(void) { |
| 14 |
int n = cuda_devices(); |
| 15 |
if (n == 0) { |
| 16 |
std::cout << "No CUDA hardware found. Exiting.\n"; |
| 17 |
return 0; |
| 18 |
} |
| 19 |
|
| 20 |
std::cout << "Found " << n << " CUDA devices.\n"; |
| 21 |
|
| 22 |
do_cuda_stuff(); |
| 23 |
|
| 24 |
cublasHandle_t handle; |
| 25 |
if (cublasCreate(&handle) != CUBLAS_STATUS_SUCCESS) { |
| 26 |
std::cout << "cuBLAS initialization failed. Exiting.\n"; |
| 27 |
return -1; |
| 28 |
} |
| 29 |
|
| 30 |
std::cout << "Initialized cuBLAS\n"; |
| 31 |
if (cublasDestroy(handle) != CUBLAS_STATUS_SUCCESS) { |
| 32 |
std::cout << "cuBLAS de-initialization failed. Exiting.\n"; |
| 33 |
return -1; |
| 34 |
} |
| 35 |
|
| 36 |
return 0; |
| 37 |
} |