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

Expose create_buffer_gc in a header #680

Open
isuruf opened this issue Apr 7, 2023 · 4 comments
Open

Expose create_buffer_gc in a header #680

isuruf opened this issue Apr 7, 2023 · 4 comments

Comments

@isuruf
Copy link
Collaborator

isuruf commented Apr 7, 2023

Is your feature request related to a problem? Please describe.
When using pyvkfft, vkfft calls clCreateBuffer which fails sometimes because it doesn't run the garbage collector.

Describe the solution you'd like
If we could have a header like below, we can include that in pyvkfft.

#include <CL/cl.h>

static inline pyopenclCreateBuffer(cl_context ctx,
      cl_mem_flags flags,
      size_t size,
      void *host_ptr,
      cl_int *status_code) {
    PYOPENCL_RETRY_IF_MEM_ERROR(
       clCreateBuffer(ctx, flags, size, host_ptr, status_code);
       if (*status_code != CL_SUCCESS)
           throw pyopencl::error("pyopenclCreateBuffer", *status_code);
    );
}

#define clCreateBuffer pyopenclCreateBuffer

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@inducer
Copy link
Owner

inducer commented Apr 7, 2023

Not sure about this, specifically because I'm hesitant to have PyOpenCL pick up a C-level API (which is more complexity that needs managing).

I think you can do the same just from Python, and the extra overhead should not really matter given that memory allocation is high-cost anyhow.

@isuruf
Copy link
Collaborator Author

isuruf commented Apr 14, 2023

The issue is that allocation might happen in C side, for eg: in VkFFT where phase vectors are allocated and there's no way to plug in a custom allocator.

@inducer
Copy link
Owner

inducer commented Apr 14, 2023

But wouldn't a call to a presumptive PyOpenCL C API stick out like sore thumb in such a setting just as much as a bunch of Python C API "stuff" to call the Python side?

@isuruf
Copy link
Collaborator Author

isuruf commented Apr 14, 2023

Taking the example of pyvkfft, I was thinking of changing the line https://github.com/vincefn/pyvkfft/blob/5b51a7bcb0d93581c5ea8dcf7edbe77d1b191f2f/src/vkfft_opencl.cpp#L15
from

#include "vkFFT.h"

to

#include <pyopencl-allocate.h>
#include "vkFFT.h"

and that should work without any other changes.

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

No branches or pull requests

2 participants