2009-10-21 95 views
1

我試圖分配浮點數17338896種元素如下所示(這大概是70 MB):CUBLAS內存分配錯誤

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; 
} 
+0

這是您的程序中的第一個VRAM分配?在使用cudaMalloc()之前,我肯定會分配更大的內存塊。也許你可以提供一個最小的repro? – Gabriel

+0

是的。您希望最低限度複製什麼? – stanigator

+0

最小的重現將是產生錯誤的最小的完整程序。沒有必要,理想情況下我可以複製/粘貼到C文件,編譯,鏈接和執行。根據你的描述,這應該不會超過C的幾行。 – Gabriel

回答

5

內存可以分段,這意味着你仍然可以分配多個較小的塊但不是一個大的塊。您的視頻卡顯然需要一些內存用於正常的2D任務。如果發生這種情況將128 MB分成幾乎64MB的2個塊,那麼你會看到這種失敗。

+0

你的解釋很有道理。我分配了較小的內存量,並沒有遇到這個問題。我將在另一臺具有更多視頻卡內存的計算機上進行測試,以確認是否屬於這種情況。 – stanigator