| | |
| | | return d; |
| | | } |
| | | |
| | | #ifdef CUDNN |
| | | cudnnHandle_t cudnn_handle() |
| | | { |
| | | static int init = 0; |
| | | static cudnnHandle_t handle; |
| | | if(!init) { |
| | | cudnnCreate(&handle); |
| | | init = 1; |
| | | } |
| | | return handle; |
| | | } |
| | | #endif |
| | | |
| | | cublasHandle_t blas_handle() |
| | | { |
| | | static int init = 0; |
| | |
| | | return handle; |
| | | } |
| | | |
| | | float *cuda_make_array(float *x, int n) |
| | | float *cuda_make_array(float *x, size_t n) |
| | | { |
| | | float *x_gpu; |
| | | size_t size = sizeof(float)*n; |
| | |
| | | status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); |
| | | check_error(status); |
| | | } |
| | | if(!x_gpu) error("Cuda malloc failed\n"); |
| | | return x_gpu; |
| | | } |
| | | |
| | | void cuda_random(float *x_gpu, int n) |
| | | void cuda_random(float *x_gpu, size_t n) |
| | | { |
| | | static curandGenerator_t gen; |
| | | static int init = 0; |
| | |
| | | check_error(cudaPeekAtLastError()); |
| | | } |
| | | |
| | | float cuda_compare(float *x_gpu, float *x, int n, char *s) |
| | | float cuda_compare(float *x_gpu, float *x, size_t n, char *s) |
| | | { |
| | | float *tmp = calloc(n, sizeof(float)); |
| | | cuda_pull_array(x_gpu, tmp, n); |
| | |
| | | return err; |
| | | } |
| | | |
| | | int *cuda_make_int_array(int n) |
| | | int *cuda_make_int_array(size_t n) |
| | | { |
| | | int *x_gpu; |
| | | size_t size = sizeof(int)*n; |
| | |
| | | check_error(status); |
| | | } |
| | | |
| | | void cuda_push_array(float *x_gpu, float *x, int n) |
| | | void cuda_push_array(float *x_gpu, float *x, size_t n) |
| | | { |
| | | size_t size = sizeof(float)*n; |
| | | cudaError_t status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); |
| | | check_error(status); |
| | | } |
| | | |
| | | void cuda_pull_array(float *x_gpu, float *x, int n) |
| | | void cuda_pull_array(float *x_gpu, float *x, size_t n) |
| | | { |
| | | size_t size = sizeof(float)*n; |
| | | cudaError_t status = cudaMemcpy(x, x_gpu, size, cudaMemcpyDeviceToHost); |