Valgrind and CUDA: Are reported leaks real?

前端 未结 5 1034
庸人自扰
庸人自扰 2020-12-15 22:23

I have a very simple CUDA component in my application. Valgrind reports a lot of leaks and still-reachables, all related to the cudaMalloc calls.

Are these leaks rea

5条回答
  •  天命终不由人
    2020-12-15 23:08

    Since I don't have 50 reputation, I cannot leave a comment on @Vyas 's answer.

    I feel strange that cuda-memcheck cannot observe cuda memory leakage.

    I just write a very simple code with a cuda memory leakage, but when using cuda-memcheck --leak-check full it give no leakage. It is:

    #include 
    #include 
    
    using namespace std;
    
    int main(){
        float* cpu_data;
        float* gpu_data;
        int buf_size = 10 * sizeof(float);
    
        cpu_data = (float*)malloc(buf_size);
        for(int i=0; i<10; i++){
            cpu_data[i] = 1.0f * i;
        }
    
        cudaError_t cudaStatus = cudaMalloc(&gpu_data, buf_size);
    
        cudaMemcpy(gpu_data, cpu_data, buf_size, cudaMemcpyHostToDevice);
    
        free(cpu_data);
        //cudaFree(gpu_data);
    
        return 0;
    }
    

    Note the commented line of code, which make this program a cuda memory leakage, I think. However, when execuing cuda-memcheck ./a.out it gives:

    ========= CUDA-MEMCHECK
    ========= ERROR SUMMARY: 0 errors
    

提交回复
热议问题