Domanda

Ho cercato di allocare 17338896 elementi di numeri in virgola mobile come segue (che è di circa 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;
    }

Tuttavia, sto ricevendo un messaggio di errore CUBLAS_STATUS_ALLOC_FAILED per lo stato variabile. Questo avrebbe qualcosa a che fare con la quantità di memoria della scheda video disponibile sulla macchina (128 mb al mio) o questo sarebbe un limite della quantità di memoria che posso allocare usando la funzione cublasAlloc () (cioè non pertinente alla quantità di memoria disponibile sulla macchina)? Ho provato a usare la funzione cudaMalloc () e sto riscontrando lo stesso problema. Grazie in anticipo per aver esaminato questo.

-------------- Aggiunta della riproduzione degli errori ----------------------------- --------

#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;
}
È stato utile?

Soluzione

La memoria può frammentarsi, il che significa che è ancora possibile allocare più blocchi più piccoli ma non un singolo blocco grande. La tua videocard avrà ovviamente bisogno di memoria per il suo normale compito 2D. Se ciò dovesse causare la rottura dei 128 MB in 2 blocchi di quasi 64 MB, vedresti questo tipo di errore.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top