Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernels keep Buffers alive #450

Closed
inducer opened this issue Mar 25, 2021 · 1 comment
Closed

Kernels keep Buffers alive #450

inducer opened this issue Mar 25, 2021 · 1 comment

Comments

@inducer
Copy link
Owner

inducer commented Mar 25, 2021

In various projects, some memory allocation "oddities" have popped up:

I realized that one contribution to this could be that clSetKernelArg is stateful, i.e. when you pass a buffer to a kernel, what you do is set the argument of the kernel to that buffer, and then enqueue the kernel. And from that point onward (until the argument is set to something else, or until the kernel object is freed) the kernel keeps the buffer alive.

We could try out two approaches:

  • Kernel.clone() (CL2.1+ only, unfortunately) right before setting arguments
  • Resetting arguments to None after passing them.

Both are relatively cheap to try out, just by modifying the invoker generation. To be clear, I don't know that this will have a measurable impact, but it is one possible theory of how memory could survive longer than necessary. (In a way, the issue is a mirror image of #449.) An actually efficient version of option 2 would probably involve some C++, to efficiently call clSetKernelArg(..., nullptr) on a big batch of arguments.

cc @matthiasdiener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant