ericproffitt / TopicModelsVB.jl

A Julia package for variational Bayesian topic modeling.
Other
81 stars 8 forks source link

Release GPU memory. #39

Open ValeriiBaidin opened 3 years ago

ValeriiBaidin commented 3 years ago

I try to release memory by the next code. The memory is realized, by I can't create the next new model. There is an unknown error.

Do you know, how to realise memory right way?

Thank you in advance.


    cl.api.clFinish(model.queue.id)
    cl.api.clReleaseKernel(model.beta_kernel.id)
    cl.api.clReleaseKernel(model.beta_norm_kernel.id)
    cl.api.clReleaseKernel(model.Elogtheta_kernel.id)
    cl.api.clReleaseKernel(model.Elogtheta_sum_kernel.id)
    cl.api.clReleaseKernel(model.gamma_kernel.id)
    cl.api.clReleaseKernel(model.phi_kernel.id)
    cl.api.clReleaseKernel(model.phi_norm_kernel.id)

    cl.api.clReleaseMemObject(model.N_cumsum_buffer.id)
    cl.api.clReleaseMemObject(model.J_cumsum_buffer.id)
    cl.api.clReleaseMemObject(model.terms_buffer.id)
    cl.api.clReleaseMemObject(model.terms_sortperm_buffer.id)
    cl.api.clReleaseMemObject(model.counts_buffer.id)
    cl.api.clReleaseMemObject(model.alpha_buffer.id)
    cl.api.clReleaseMemObject(model.beta_buffer.id)
    cl.api.clReleaseMemObject(model.gamma_buffer.id)
    cl.api.clReleaseMemObject(model.Elogtheta_buffer.id)
    cl.api.clReleaseMemObject(model.Elogtheta_sum_buffer.id)
    cl.api.clReleaseMemObject(model.Elogtheta_dist_buffer.id)
    cl.api.clReleaseMemObject(model.phi_buffer.id)
    cl.api.clReleaseCommandQueue(model.queue.id)
    cl.api.clReleaseContext(model.context.id)
    cl.api.clReleaseDevice(model.device.id)
ericproffitt commented 3 years ago

Hi Valerii,

You shouldn't need to manually release buffer memory.

Could you provide a code example that is producing your error?

ValeriiBaidin commented 3 years ago
  1. I just run a big model.
  2. GPU memory is full after the finish.
  3. I tried to run another model, but memory isn't enough.

TopicModelsVB.update_buffer!(model) helps me!!!

ericproffitt commented 3 years ago

If your first model is using up all the buffer memory, then you will likely need to clear it before setting up your new model, however you shouldn't need to manually clear the buffers using the OpenCL API, you should just be able to do something like the following,

model = nothing

I'm not sure what other help I can provide, you may need to be more explicit in describing your steps and where the error is occurring.

ericproffitt commented 3 years ago

Frankly, I'm not exactly sure what happens when you load multiple models into buffer memory and there isn't enough memory for all of them. The machine may overwrite the buffer without notification.

However I'm unable to reproduce a set of circumstances where loading a model into buffer memory causes an error only after a previous model has been loaded.

ValeriiBaidin commented 3 years ago

If your first model is using up all the buffer memory, then you will likely need to clear it before setting up your new model, however you shouldn't need to manually clear the buffers using the OpenCL API, you should just be able to do something like the following,

model = nothing

I'm not sure what other help I can provide, you may need to be more explicit in describing your steps and where the error is occurring.

Thank you, I will try it.