diff options
author | cloudygoose <[email protected]> | 2015-05-31 11:32:45 +0800 |
---|---|---|
committer | cloudygoose <[email protected]> | 2015-05-31 11:32:45 +0800 |
commit | 36162328956177d554891f937a13616b5476b231 (patch) | |
tree | a28c7a6f29b37ce091b03534e85d5cb28b2e0f81 /matrix/cuda_helper.h | |
parent | cfd06bb974c7088837a107d721b1311a4f160572 (diff) | |
parent | ab12a9583bdd39884fde9bc2444e6fd1bc5f518e (diff) |
...
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'matrix/cuda_helper.h')
-rw-r--r-- | matrix/cuda_helper.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/matrix/cuda_helper.h b/matrix/cuda_helper.h new file mode 100644 index 0000000..c0fa618 --- /dev/null +++ b/matrix/cuda_helper.h @@ -0,0 +1,55 @@ +#ifndef NERV_CUDA_HELPER_H +#define NERV_CUDA_HELPER_H +#define CUBLAS_SAFE_CALL(call) \ + do { \ + cublasStatus_t err = (call); \ + if (err != CUBLAS_STATUS_SUCCESS) \ + nerv_error(L, "cumatrix cublas error: %s", cublasGetErrorString(err)); \ + } while (0) + +#define CUDA_SAFE_CALL(call) \ + do { \ + cudaError_t err = (call); \ + if (err != cudaSuccess) \ + nerv_error(L, "cumatrix CUDA error: %s", cudaGetErrorString(err)); \ + } while (0) + +#define CUDA_SAFE_SYNC_CALL(call) \ + do { \ + CUDA_SAFE_CALL(call); \ + cudaDeviceSynchronize(); \ + } while (0) + +#define CHECK_SAME_DIMENSION(a, b) \ + do { \ + if (!(a->nrow == b->nrow && a->ncol == b->ncol)) \ + nerv_error(L, "Matrices should be of the same dimension"); \ + } while (0) + +static const char *cublasGetErrorString(cublasStatus_t err) { + switch (err) + { + case CUBLAS_STATUS_SUCCESS: + return "CUBLAS_STATUS_SUCCESS"; + case CUBLAS_STATUS_NOT_INITIALIZED: + return "CUBLAS_STATUS_NOT_INITIALIZED"; + case CUBLAS_STATUS_ALLOC_FAILED: + return "CUBLAS_STATUS_ALLOC_FAILED"; + case CUBLAS_STATUS_INVALID_VALUE: + return "CUBLAS_STATUS_INVALID_VALUE"; + case CUBLAS_STATUS_ARCH_MISMATCH: + return "CUBLAS_STATUS_ARCH_MISMATCH"; + case CUBLAS_STATUS_MAPPING_ERROR: + return "CUBLAS_STATUS_MAPPING_ERROR"; + case CUBLAS_STATUS_EXECUTION_FAILED: + return "CUBLAS_STATUS_EXECUTION_FAILED"; + case CUBLAS_STATUS_INTERNAL_ERROR: + return "CUBLAS_STATUS_INTERNAL_ERROR"; + case CUBLAS_STATUS_NOT_SUPPORTED: + return "CUBLAS_STATUS_NOT_SUPPORTED"; + case CUBLAS_STATUS_LICENSE_ERROR: + return "CUBLAS_STATUS_LICENSE_ERROR"; + } + return "<unknown>"; +} +#endif |