CUDA error: CUBLAS_STATUS_NOT_INITIALIZED when calling `cublasCreate(handle)`
时间: 2023-09-21 10:11:38 浏览: 128
并行编程接口-电子产品结构设计规则大全
This error occurs when the CUBLAS library has not been initialized properly before calling the `cublasCreate()` function.
To fix this error, make sure that you have included the necessary header files and linked the CUBLAS library to your project. Additionally, you should call the `cudaSetDevice()` function to select the GPU device before initializing CUBLAS.
Here is an example code snippet that demonstrates how to properly initialize CUBLAS:
```
#include <cuda.h>
#include <cublas_v2.h>
int main() {
// Select the GPU device
cudaSetDevice(0);
// Initialize CUBLAS
cublasHandle_t handle;
cublasStatus_t status = cublasCreate(&handle);
if (status != CUBLAS_STATUS_SUCCESS) {
printf("CUBLAS initialization failed\n");
return 1;
}
// Use CUBLAS functions here...
// Destroy the CUBLAS handle
cublasDestroy(handle);
return 0;
}
```
阅读全文