我尝试如下分配浮点数的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;
}
最佳答案
内存可能会碎片化,这意味着您仍然可以分配多个较小的块,但不能分配一个较大的块。您的视频卡显然将需要一些内存才能完成其常规2D任务。如果碰巧将128 MB分成了将近64 MB的2个块,那么您将看到这种故障。