CUBLAS 메모리 할당 오류
-
05-07-2019 - |
문제
다음과 같이 부동 소수점 숫자의 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;
}
해결책
메모리는 조각화될 수 있습니다. 즉, 여러 개의 작은 블록을 할당할 수 있지만 하나의 큰 블록은 할당할 수 없습니다.귀하의 비디오 카드는 일반적인 2D 작업을 위해 분명히 약간의 메모리가 필요합니다.만약 128MB가 거의 64MB의 2개 블록으로 나누어진다면 이런 종류의 실패를 보게 될 것입니다.
제휴하지 않습니다 StackOverflow