CUBLAS内存分配错误

发布于 2024-08-09 02:04:37 字数 2017 浏览 3 评论 0原文

我尝试分配 17338896 个浮点数元素,如下所示(大约 70 mb):

    state = cublasAlloc(theSim->Ndim*theSim->Ndim, 
                       sizeof(*(theSim->K0)), 
                       (void**)&K0cuda);
    if(state != CUBLAS_STATUS_SUCCESS) {
        printf("Error allocation video memory.\n");
        return -1;
    }

但是,我收到变量状态的 CUBLAS_STATUS_ALLOC_FAILED 错误消息。这是否与机器上可用的显卡内存量(我的为 128 mb)有关,或者这是否是我可以使用 cublasAlloc() 函数分配的内存量的限制(即与内存量无关)机器上的可用内存)?我尝试使用 cudaMalloc() 函数,但遇到了同样的问题。预先感谢您对此进行调查。

--------------添加错误再现-------------------------------- -----

#include <cuda.h>
#include <stdio.h>
int main (int argc, char *argv[]) {

    // CUDA setup
    cublasStatus state;

    if(cublasInit() == CUBLAS_STATUS_NOT_INITIALIZED) {
        printf("CUBLAS init error.\n");
        return -1;
    }

    // Instantiate video memory pointers
    float *K0cuda;

    // Allocate video memory needed
    state = cublasAlloc(20000000, 
                        sizeof(float), 
                        (void**)&K0cuda);
    if(state != CUBLAS_STATUS_SUCCESS) {
        printf("Error allocation video memory.\n");
        return -1;
    }

    // Copy K0 from CPU memory to GPU memory
    // Note: before so, decide whether to integrate as a part of InsertionSim or
    //      CUDA content as a separate class
    //state = cublasSetMatrix(theSim->Ndim, theSim->Ndim, sizeof(*theSim->K0),
    //                      theSim->K0, theSim->Ndim, K0cuda, theSim->Ndim);
    //if(state != CUBLAS_STATUS_SUCCESS) {
    //  printf("Error copy to video memory.\n");
    //  return -1;
    //}

    // Free memory
    if(cublasFree(K0cuda) != CUBLAS_STATUS_SUCCESS) {
        printf("Error freeing video memory.\n");
        return -1;
    }

    // CUDA shutdown
    if(cublasShutdown() != CUBLAS_STATUS_SUCCESS) {
        printf("CUBLAS shutdown error.\n");
        return -1;
    }

    if(theSim != NULL) delete theSim;

    return 0;
}

I tried to allocate 17338896 elements of floating point numbers as follows (which is roughly 70 mb):

    state = cublasAlloc(theSim->Ndim*theSim->Ndim, 
                       sizeof(*(theSim->K0)), 
                       (void**)&K0cuda);
    if(state != CUBLAS_STATUS_SUCCESS) {
        printf("Error allocation video memory.\n");
        return -1;
    }

However, I'm receiving error message of CUBLAS_STATUS_ALLOC_FAILED for the variable state. Would this have anything to do with the amount of video card memory available on the machine (128 mb on mine) or would this be a limit of the amount of memory that I can allocate using cublasAlloc() function (i.e. not relevant to the amount of memory available on the machine)? I tried using cudaMalloc() function and I am running into the same problem. Thanks in advance for looking into this.

--------------Addition of Error Reproduction-------------------------------------

#include <cuda.h>
#include <stdio.h>
int main (int argc, char *argv[]) {

    // CUDA setup
    cublasStatus state;

    if(cublasInit() == CUBLAS_STATUS_NOT_INITIALIZED) {
        printf("CUBLAS init error.\n");
        return -1;
    }

    // Instantiate video memory pointers
    float *K0cuda;

    // Allocate video memory needed
    state = cublasAlloc(20000000, 
                        sizeof(float), 
                        (void**)&K0cuda);
    if(state != CUBLAS_STATUS_SUCCESS) {
        printf("Error allocation video memory.\n");
        return -1;
    }

    // Copy K0 from CPU memory to GPU memory
    // Note: before so, decide whether to integrate as a part of InsertionSim or
    //      CUDA content as a separate class
    //state = cublasSetMatrix(theSim->Ndim, theSim->Ndim, sizeof(*theSim->K0),
    //                      theSim->K0, theSim->Ndim, K0cuda, theSim->Ndim);
    //if(state != CUBLAS_STATUS_SUCCESS) {
    //  printf("Error copy to video memory.\n");
    //  return -1;
    //}

    // Free memory
    if(cublasFree(K0cuda) != CUBLAS_STATUS_SUCCESS) {
        printf("Error freeing video memory.\n");
        return -1;
    }

    // CUDA shutdown
    if(cublasShutdown() != CUBLAS_STATUS_SUCCESS) {
        printf("CUBLAS shutdown error.\n");
        return -1;
    }

    if(theSim != NULL) delete theSim;

    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2024-08-16 02:04:37

内存可能会产生碎片,这意味着您仍然可以分配多个较小的块,但不能分配单个大块。您的显卡显然需要一些内存来执行正常的 2D 任务。如果这恰好将 128 MB 分成 2 个几乎 64 MB 的块,那么您就会看到这种失败。

Memory can fragment, which means that you can still allocate multiple smaller blocks but not a single large block. Your videocard will obviously need some memory for its normal 2D task. If that happens to break the 128 MB into 2 blocks of almost 64MB, then you'd see this kind of failure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文