由于“无效参数”,Cublas编程程序命中了cudaErrorInvalidValue

问题描述 投票:0回答:1

最近,我尝试用Cublas库编写GPU编程。我所做的只是在设备上分配内存并进行矩阵计算。但是,当我尝试按如下方式分配内存时,我得到了类似的错误。

enter image description here我的代码如下。 C等于21,N等于53940.SNIPs等于550482 / 30.奇怪的是,我发现无论我在设备上分配内存的顺序如何,我都会因此而得到错误。 cudaStat = cudaMalloc((void**)&d_WTW, C * C * sizeof(float));完整代码如下。

// Set cuda context
cudaError_t cudaStat;
cublasStatus_t stat;

// Initialize device pointer
float* d_data;
float* d_W;
float* d_v;
float* d_result;
float* d_result2;
float* d_temp;
float* d_one;
float* d_mean;
float prod;
float* d_cby1;
float* d_cby2;
float* d_cby3;
float* d_R;
float* d_data_final;
float* d_temp_final;
float* d_WTW;
cudaStat = cudaMalloc((void**)&d_data, SNIPs * N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 1" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_W, N * C * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 2" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_v, N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 4" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_result2, N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 5" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_result, N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 6" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_temp, SNIPs * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 7" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_cby1, C * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 9" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_cby2, C * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 10" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_cby3, N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 11" << endl;
    return EXIT_FAILURE;
}
cudaStat = cudaMalloc((void**)&d_v, N * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 13" << endl;
    return EXIT_FAILURE;
}
// stat = cublasSetVector((int)N, sizeof(*vector_ones), vector_ones, 1, d_one, 1);
stat = cublasSetMatrix((int)N, C, sizeof(*W), W, (int)N, d_W, (int)N);
stat = cublasSetMatrix(C, C, sizeof(*WTWInv), WTWInv, C, d_WTW, C);
// allocate memeory for temp result
float* d_R_temp;
cudaStat = cudaMalloc((void**)&d_R, N * B * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 14" << endl;
    return EXIT_FAILURE;
}

cudaStat = cudaMalloc((void**)&d_WTW, C * C * sizeof(float));
if (cudaStat != cudaSuccess) {
    cout << "device memory allocation failed 12" << endl;
    return EXIT_FAILURE;
}                     
memory-management gpu-programming cublas
1个回答
0
投票

最后,我发现我的内存分配大小有问题,导致溢出。

© www.soinside.com 2019 - 2024. All rights reserved.