views:

327

answers:

1

I tried to allocate 17338896 elements of floating point numbers as follows (which is roughly 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;
    }

However, I'm receiving error message of CUBLAS_STATUS_ALLOC_FAILED for the variable state. Would this have anything to do with the amount of video card memory available on the machine (128 mb on mine) or would this be a limit of the amount of memory that I can allocate using cublasAlloc() function (i.e. not relevant to the amount of memory available on the machine)? I tried using cudaMalloc() function and I am running into the same problem. Thanks in advance for looking into this.

--------------Addition of Error Reproduction-------------------------------------

#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;
}
+3  A: 

Memory can fragment, which means that you can still allocate multiple smaller blocks but not a single large block. Your videocard will obviously need some memory for its normal 2D task. If that happens to break the 128 MB into 2 blocks of almost 64MB, then you'd see this kind of failure.

MSalters
Your explanation makes sense. I allocated smaller amount of memory and didn't encounter this problem. I will be testing this on another machine with a lot more video card memory to confirm whether this is the case.
stanigator