我試圖分配浮點數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;
}
這是您的程序中的第一個VRAM分配?在使用cudaMalloc()之前,我肯定會分配更大的內存塊。也許你可以提供一個最小的repro? – Gabriel
是的。您希望最低限度複製什麼? – stanigator
最小的重現將是產生錯誤的最小的完整程序。沒有必要,理想情況下我可以複製/粘貼到C文件,編譯,鏈接和執行。根據你的描述,這應該不會超過C的幾行。 – Gabriel