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

[SYCL][ESIMD] Report an error when slm_init is called more than once in the kernel #12804

Merged
merged 17 commits into from
Mar 19, 2024

Conversation

fineg74
Copy link
Contributor

@fineg74 fineg74 commented Feb 22, 2024

No description provided.

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
unsigned Idx = 0;
for (const Argument &Arg : F.args()) {
if (Arg.getType()->isPointerTy()) {
auto *KernelArgAccPtrs = F.getMetadata("kernel_arg_accessor_ptr");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we send an email to the CFE/SYCL language team as a non-blocking follow-up to see if they have any ideas on improving this check by doing it somewhere else (Sema?). Relying on the metadata should work but it seems a bit indirect and possibly flaky, but I don't know how to do any better today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, although it looks like a standard way to mark passing accessors to the kernel from FE

Copy link
Contributor

@v-klochkov v-klochkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have couple of concerns in this patch: 1st - test is probably not valid (see other comment below),

2nd is related to a case with 1 kernel using slm_init and 2nd kernel using local_accessor.
Please add a test for this scenario.

sycl/test/esimd/slm_init_local_accessor_check.cpp Outdated Show resolved Hide resolved
Comment on lines 3 to 4
// This test verifies call to slm_init from a function not marked as
// always_inline triggers an error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the comment is not precise. It tests the case when a function is marked noinline, not not marked as always_inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
@v-klochkov
Copy link
Contributor

How about using such algorithm?

  1. for each spir_function F or spir_kernel F available in the module have a map: map_func_to_esimd_kernel[F] = esimd_kernel
    Additionally:
    • If F has slm_init, then map_kernel_to_slm_num[map_func_to_esimd_kernel[F]]++;
    • If F is a kernel and uses local_accessor then map_kernel_to_slm_num[map_func_to_esimd_kernel[F]]++;. This ++ can be done only once per kernel (i.e. if 2 local accessors, then it is still 1 ++ op).
  2. if F is not called by any esimd_kernel, then simply prohibit uses of slm_init for such F - report an error.
  3. After the initial loop by F do walk through each of esimd_kernels in the map map_kernel_to_slm_num. The int value mapped there must not exceed 1.

There may be some extra data needed here to emit a meaningful/helpful error. It is more the idea above.

@fineg74
Copy link
Contributor Author

fineg74 commented Mar 7, 2024

How about using such algorithm?

  1. for each spir_function F or spir_kernel F available in the module have a map: map_func_to_esimd_kernel[F] = esimd_kernel
    Additionally:

    • If F has slm_init, then map_kernel_to_slm_num[map_func_to_esimd_kernel[F]]++;
    • If F is a kernel and uses local_accessor then map_kernel_to_slm_num[map_func_to_esimd_kernel[F]]++;. This ++ can be done only once per kernel (i.e. if 2 local accessors, then it is still 1 ++ op).
  2. if F is not called by any esimd_kernel, then simply prohibit uses of slm_init for such F - report an error.

  3. After the initial loop by F do walk through each of esimd_kernels in the map map_kernel_to_slm_num. The int value mapped there must not exceed 1.

There may be some extra data needed here to emit a meaningful/helpful error. It is more the idea above.

  1. An ESIMD function can be called from multiple kernels
  2. Inside the kernel accessor is a pointer in some address space and currently the only way to identify it as an accessor is to examine the metadata when it is passed from host to the kernel. In other words, I do see a kernel using local accessors but I don't see a a particular function using a local accessor. (Technically it is possible to track whatever is passed to the kernel but I am not sure it worth the effort. I am also not sure if treating every pointer in the local address space as a local accessor (without using the kernel metadata) is a correct way to identify local accessors.

I believe the current implementation is using more or less the same algorithm but in slightly different way: It uses a set to see if a kernel called slm_init one way or another I probably need to tweak it for multiple kernels in a module

Copy link
Contributor

@v-klochkov v-klochkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you.

Just 1 minor comment - SPIRV_LOCAL_ACCESSOR_PREF is not needed after the recent logic simplification patch.

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Outdated Show resolved Hide resolved
Co-authored-by: Vyacheslav Klochkov <vyacheslav.n.klochkov@intel.com>
@v-klochkov v-klochkov merged commit 3f43d47 into intel:sycl Mar 19, 2024
12 checks passed
@fineg74 fineg74 deleted the slmInitCheck branch March 19, 2024 16:50
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

Successfully merging this pull request may close these issues.

3 participants