我尝试按如下方式分配17338896个浮点数元素(大约为70MB):
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错误消息。这是否与机器上可用显卡的内存量(我的是128MB)有关,或者这是不是我可以使用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;
}发布于 2009-10-22 17:30:20
内存可以分段,这意味着您仍然可以分配多个较小的块,但不能分配单个较大的块。你的显卡显然需要一些内存来完成正常的2D任务。如果这恰好将128MB拆分成两个几乎64MB的块,那么您将看到这种故障。
https://stackoverflow.com/questions/1603401
复制相似问题