ThomasKroes / exposure-render

Automatically exported from code.google.com/p/exposure-render
106 stars 37 forks source link

memory leak in core.cu::Render #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 
I was wondering if you free pDevScene etc. in your rendering call or if it is 
already reimplemented otherwise.

Regardless,
my code looks something like this:

And I found that no dev pointer gets freed, which after several thousand 
iteration fills up the gpu memory to the brim.

best regards
Christoph

void Render(const int& Type, CScene& Scene, CTiming& RenderImageTimer, CTiming& 
BlurImageTimer, CTiming& PostProcessImageTimer, CTiming& DenoiseImageTimer)
{
    CScene* pDevScene = NULL;

    HandleCudaError(cudaMalloc(&pDevScene, sizeof(CScene)), "alloc dev scene failed");
    HandleCudaError(cudaMemcpy(pDevScene, &Scene, sizeof(CScene), cudaMemcpyHostToDevice));

    if (Scene.m_Camera.m_Focus.m_Type == 0)
        Scene.m_Camera.m_Focus.m_FocalDistance = NearestIntersection(pDevScene);

    HandleCudaError(cudaMemcpy(pDevScene, &Scene, sizeof(CScene), cudaMemcpyHostToDevice));

    CCudaView* pDevView = NULL;

    HandleCudaError(cudaMalloc(&pDevView, sizeof(CCudaView)));
    HandleCudaError(cudaMemcpy(pDevView, &gRenderCanvasView, sizeof(CCudaView), cudaMemcpyHostToDevice));

    CCudaInstantRadiosity* pDevIR= NULL;

    HandleCudaError(cudaMalloc(&pDevIR, sizeof(CCudaInstantRadiosity)));
    HandleCudaError(cudaMemcpy(pDevIR, &gInstantRadiosity, sizeof(CCudaInstantRadiosity), cudaMemcpyHostToDevice));

    CCudaTimer TmrRender;

    bool VPLRender = true;  
    switch (VPLRender)
    {
        case false:
        {
            SingleScattering(&Scene, pDevScene, pDevView);
            break;
        }

        case true:
        {
            RenderVPL(&Scene, pDevScene, pDevIR, gpVPLArray, gpAVSMArray, pDevView);        
            break;
        }
    }

    HandleCudaError(cudaFree(pDevIR),"Error freeing pDevIR");

    RenderImageTimer.AddDuration(TmrRender.ElapsedTime());

    CCudaTimer TmrBlur;
    Blur(&Scene, pDevScene, pDevView);
    BlurImageTimer.AddDuration(TmrBlur.ElapsedTime());

    CCudaTimer TmrPostProcess;
    Estimate(&Scene, pDevScene, pDevView);
    PostProcessImageTimer.AddDuration(TmrPostProcess.ElapsedTime());

    ToneMap(&Scene, pDevScene, pDevView);

    CCudaTimer TmrDenoise;
    Denoise(&Scene, pDevScene, pDevView);
    DenoiseImageTimer.AddDuration(TmrDenoise.ElapsedTime());

    HandleCudaError(cudaFree(pDevView),"Error freeing pDevView");
    HandleCudaError(cudaFree(pDevScene),"Error freeing pDevScene");

}

Original issue reported on code.google.com by c.web...@yahoo.de on 10 Aug 2012 at 1:07