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

OpenCL interoperability does not work on 64-bit OS #265

Open
villekf opened this issue Apr 9, 2024 · 2 comments
Open

OpenCL interoperability does not work on 64-bit OS #265

villekf opened this issue Apr 9, 2024 · 2 comments

Comments

@villekf
Copy link

villekf commented Apr 9, 2024

Currently the OpenCL interoperability does not work on 64-bit Windows machine. The reason for this is the use of c_int_t which defaults to long on Windows (which on the other hand is 32-bit). This can be problematic with things like device IDs as they can easily go over 2^32/2-1. For example https://github.com/arrayfire/arrayfire-python/blob/master/arrayfire/opencl.py#L88 uses c_int_t, as well as a few other functions in the same file. This can be fixed by replacing the c_int_t with, for example, c_void_ptr_t as it is used with the context. Is there by the way some specific reason why context is treated differently?

There is also another issue. When the context is created by PyOpenCL, the input device, context and queue values are input as python ints in order to use the same context and queue, but on Windows you get <class 'OverflowError'>: int too long to convert errors then. These can be avoided by casting them to, for example, c_int64-types. For example in https://github.com/arrayfire/arrayfire-python/blob/master/arrayfire/opencl.py#L156, replace safe_call(backend.get().afcl_add_device_context(dev, ctx, que)) with safe_call(backend.get().afcl_add_device_context(ct.c_int64(dev), ct.c_int64(ctx), ct.c_int64(que))) (using c_void_p seems to work too).

I haven't tested these changes extensively, but they do seem to get things working on 64-bit Windows. I can provide a PR if needed.

@villekf
Copy link
Author

villekf commented Apr 9, 2024

Note that the PyOpenCL parts have been commented in the tests: https://github.com/arrayfire/arrayfire-python/blob/master/tests/simple/interop.py#L78, although the issue that is mentioned there has been closed over six years ago.

@villekf villekf changed the title OpenCL interoperability does not work on 64-bit Windows OpenCL interoperability does not work on 64-bit OS Apr 22, 2024
@villekf
Copy link
Author

villekf commented Apr 22, 2024

Contrary to my earlier mention, this also affects Linux systems.

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