intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.
Other
1.25k stars 738 forks source link

[L0] Follow up zeModuleGetFunctionPointer not returning kernel pointer #5420

Open AidanBeltonS opened 2 years ago

AidanBeltonS commented 2 years ago

This issue is a follow up from #4599 and https://github.com/intel/compute-runtime/issues/460. The current method for querying if a kernel exists is to check if a nullptr is given by piextGetDeviceFunctionPointer.

The OpenCL and level zero implementations use clGetDeviceFunctionPointerINTEL and zeModuleGetFunctionPointer respectively to get the function pointers. The OpenCL and level zero implementations were not finding pointers to the kernels. A fallback method that searched through the kernel names was implemented, and an issue was filed with the level_zero runtime.

The response was that kernels and functions are not the same and that this is expected behaviour. Therefore, one should not expect a kernel pointer to be returned with zeModuleGetFunctionPointer. The prior usage of piextGetDeviceFunctionPointer seems to agree with this. It appears like it was being used to pass functions as arguments to kernels. For example SYCL/DeprecatedFeatures/FunctionPointers/fp-as-kernel-arg.cpp within the llvm-test-suite. It may be a similar case with OpenCL.

The response would indicate that using piextGetDeviceFunctionPointer to check if a program has a kernel does not fit level_zero and OpenCL backends well.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be automatically closed in 30 days.

AlexeySachkov commented 1 month ago

Hi @AidanBeltonS, our main use-case for clGetDeviceFunctionPointerINTEL was to query an address of a device function and not of a kernel. There had been a specific use case for function pointers support in SYCL which we later disregarded, but may re-introduce once again to achieve parity with CUDA.

However, I don't think that we are interested in getting addresses of kernel functions, simply because they are of no use: SYCL does not guarantee that lambda captures (or functor members) map 1:1 to kernel arguments. For example, in our implementation we decompose certain structs and pass them as several arguments - accessor is an example here. Therefore user won't be able to use that pointer to perform a call, because they don't know which arguments to pass there.

The response would indicate that using piextGetDeviceFunctionPointer to check if a program has a kernel

Right, when we worked on defining that API, we never expected it to be used for such checks.