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

ICD JLL does not include USM functions #257

Open
VarLad opened this issue Oct 14, 2024 · 3 comments
Open

ICD JLL does not include USM functions #257

VarLad opened this issue Oct 14, 2024 · 3 comments

Comments

@VarLad
Copy link

VarLad commented Oct 14, 2024

could not load symbol "clHostMemAllocINTEL":

~/.julia/artifacts/c99d19d2f6dd75af3e997c4ecc4ac85e410cb7a7/lib/libOpenCL.so: undefined symbol: clHostMemAllocINTEL

To reproduce:

using OpenCL
error = Ref{Int32}()
al = cl.clHostMemAllocINTEL(cl.context(), C_NULL, 10000, 1, error)

Could this be an issue in using the function itself (wrong parameters or something)? 🤔

@maleadt maleadt changed the title Packaged JLL might not include USM functions ICD JLL does not include USM functions Oct 14, 2024
@maleadt
Copy link
Member

maleadt commented Oct 14, 2024

I think this is intended. The ICD we use only provides entry-points for functions from the spec, and for extensions one needs to use clGetExtensionFunctionAddressForPlatform to fetch the entrypoint address:

julia> using OpenCL, pocl_jll

julia> ptr = cl.clGetExtensionFunctionAddressForPlatform(cl.platform(), "clHostMemAllocINTEL")
Ptr{Nothing} @0x000000013131f000

julia> error = Ref{Int32}()
Base.RefValue{Int32}(219365504)

julia> ccall(ptr, Ptr{Cvoid}, (cl.cl_context, Ptr{cl.cl_mem_properties_intel}, Csize_t, cl.cl_uint, Ptr{cl.cl_int}), cl.context(), C_NULL, 1000, 1, error)
Ptr{Nothing} @0x0000000121016e00

julia> error[]
0

It's a bit annoying that we can't re-use the existing Clang.jl-generated headers for this, although for the handful of USM functions you need it's probably fine duplicating those ccalls.

@VarLad
Copy link
Author

VarLad commented Nov 19, 2024

@maleadt Would you have an example of how to pass the properties flags properly? I'm not sure how this works...
It seems to work differently from the svm flags in the current implementation
Unable to figure out how to use these from the docs:
Image
Image

@maleadt
Copy link
Member

maleadt commented Nov 19, 2024

AFAIU it behaves like context properties, so you pass a list of properties starting with CL_MEM_ALLOC_FLAGS_INTEL, then a flags bitmask, and terminate with NULL.

julia> using OpenCL, pocl_jll

julia> fun = cl.clGetExtensionFunctionAddressForPlatform(cl.platform(), "clHostMemAllocINTEL")
Ptr{Nothing} @0x0000000135a78178

julia> error = Ref{Int32}();

julia> flags = cl.CL_MEM_ALLOC_WRITE_COMBINED_INTEL;

julia> properties = cl.cl_mem_properties_intel[cl.CL_MEM_ALLOC_FLAGS_INTEL, flags, 0];

julia> buf = ccall(fun, Ptr{Cvoid},
                   (cl.cl_context, Ptr{cl.cl_mem_properties_intel}, Csize_t, cl.cl_uint, Ptr{cl.cl_int}),
                   cl.context(), properties, 1000, 1, error)
Ptr{Nothing} @0x00000001322cee00

julia> @assert error[] == cl.CL_SUCCESS

You can also look at how PoCL implements this:

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

2 participants