Skip to content

[sycl-post-link] Fix a crash during spec-constant properties generation #5538

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

Merged
merged 7 commits into from Feb 18, 2022
Merged

[sycl-post-link] Fix a crash during spec-constant properties generation #5538

merged 7 commits into from Feb 18, 2022

Conversation

ghost
Copy link

@ghost ghost commented Feb 10, 2022

The sycl-post-link tool crashed during processing an IR where a
specialization constant with a padding is present, for example a
specialization constant of such type:

struct alignas(32) coeff_str_aligned_t {
  std::array<float, 3> coeffs;
  size_t number;
};

In the IR, the constant looks like the following:

@_ZL8coeff_id = internal addrspace(1) constant %"class.cl::sycl::specialization_id" { %struct.coeff_str_aligned_t { %"class.std::array" zeroinitializer, i64 0, [8 x i8] undef } }, align 32

That '[8 x i8] undef' led to the crash.

This patch fixes the issue and adds the following optimization: if the
default value of a specialization constant or a part of such default value
is undefined, the value (or its part) is passed into an invocation of the
'__spirv_SpecConstantComposite' function as is.

Co-authored-by: Steffen Larsen steffen.larsen@intel.com
Signed-off-by: Pavel Samolysov pavel.samolysov@intel.com

Pavel Samolysov and others added 3 commits February 10, 2022 17:15
The sycl-post-link tool crashed during processing an IR where a
specialization constant with a padding is present, for example a
specialization constant of such type:

struct alignas(32) coeff_str_aligned_t {
  std::array<float, 3> coeffs;
  size_t number;
};

In the IR, the constant looks like the following:

@_ZL8coeff_id = internal addrspace(1) constant %"class.cl::sycl::specialization_id" { %struct.coeff_str_aligned_t { %"class.std::array" zeroinitializer, i64 0, [8 x i8] undef } }, align 32

That '[8 x i8] undef' led to the crash.

This patch fixes the issue.

Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
Signed-off-by: Pavel Samolysov <pavel.samolysov@intel.com>
Instead of generating a '__spirv_SpecConstant' invocation for every
element of a composite data type with value 'undef' and then combining
thir results into a call to '__spirv_SpecConstantComposite', the
following optimization has been implemented. If the default value of a
specialization constant or a part of such default value is undefined,
the value (or its part) is passed into an invocation of the
'__spirv_SpecConstantComposite' function as is.
@ghost ghost requested a review from AlexeySachkov February 10, 2022 14:18
@ghost ghost self-requested a review as a code owner February 10, 2022 14:18
@ghost ghost requested a review from steffenlarsen February 10, 2022 14:18
@steffenlarsen
Copy link
Contributor

Would it make sense to add a SYCL test (probably in llvm-test-suite) to ensure that the default values and offsets given to the runtime are correct when encountering this kind of padding?

@ghost
Copy link
Author

ghost commented Feb 11, 2022

Good idea, @steffenlarsen I've extended the vector convolution demo test in llvm-test-suite to handle an aligned structure: intel/llvm-test-suite#830

@ghost
Copy link
Author

ghost commented Feb 11, 2022

/verify with intel/llvm-test-suite#830

AlexeySachkov
AlexeySachkov previously approved these changes Feb 11, 2022
@ghost
Copy link
Author

ghost commented Feb 11, 2022

/verify with intel/llvm-test-suite#830

@ghost
Copy link
Author

ghost commented Feb 11, 2022

Some problems with the test infrastructure.

@ghost
Copy link
Author

ghost commented Feb 11, 2022

/verify with intel/llvm-test-suite#830

@ghost ghost marked this pull request as draft February 11, 2022 14:39
@ghost
Copy link
Author

ghost commented Feb 11, 2022

I tried the solution locally with this test: https://github.com/intel/llvm-test-suite/pull/830/files#diff-ec64dcd370d47e70aa3c7dcb41f18fb8780a11422e6065b9866fce62e75f1973 and the application crushes in the runtime (at program_manager.cpp). It's the time to debug.

@ghost
Copy link
Author

ghost commented Feb 15, 2022

I've pushed a new commit with changes in the spec. constant metadata generation, this works along with the changes from @steffenlarsen applied in commit 12d7c1f The idea is to skip undefined values during metadata IDs generation to let the padding processing handle such values as padding that they actually are.

@ghost
Copy link
Author

ghost commented Feb 15, 2022

/verify with intel/llvm-test-suite#830

@ghost
Copy link
Author

ghost commented Feb 15, 2022

Some tests failed but they are unrelated to the changes. The SYCL :: SpecConstants/vector-convolution-demo.cpp test added in intel/llvm-test-suite#830 passed.

@ghost ghost marked this pull request as ready for review February 15, 2022 15:28
@ghost ghost requested review from AlexeySachkov, a team and mlychkov February 15, 2022 15:28
@mlychkov
Copy link
Contributor

Some tests failed but they are unrelated to the changes. The SYCL :: SpecConstants/vector-convolution-demo.cpp test added in intel/llvm-test-suite#830 passed.

Could you please check if failed tests have issues or create new ones for them?

@ghost
Copy link
Author

ghost commented Feb 16, 2022

@mlychkov I've created one and there already is one for another failure.

@ghost
Copy link
Author

ghost commented Feb 16, 2022

I would like to get a review from @steffenlarsen before merging. @steffenlarsen Could you have a look, please?

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

LGTM! It's a little confusing that ID has an ID member, but not enough that I worry about it.

@ghost
Copy link
Author

ghost commented Feb 16, 2022

I thought about it but didn't manage to make better naming.

@bader bader merged commit fbf6e21 into intel:sycl Feb 18, 2022
smaslov-intel pushed a commit to smaslov-intel/llvm that referenced this pull request Feb 19, 2022
…on (intel#5538)

The sycl-post-link tool crashed during processing an IR where a
specialization constant with a padding is present, for example a
specialization constant of such type:

struct alignas(32) coeff_str_aligned_t {
  std::array<float, 3> coeffs;
  size_t number;
};

In the IR, the constant looks like the following:

@_ZL8coeff_id = internal addrspace(1) constant %"class.cl::sycl::specialization_id" { %struct.coeff_str_aligned_t { %"class.std::array" zeroinitializer, i64 0, [8 x i8] undef } }, align 32

That '[8 x i8] undef' led to the crash.

This patch fixes the issue and adds the following optimization: if the
default value of a specialization constant or a part of such default value
is undefined, the value (or its part) is passed into an invocation of the
'__spirv_SpecConstantComposite' function as is.

Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
Signed-off-by: Pavel Samolysov <pavel.samolysov@intel.com>
AlexeySachkov pushed a commit to intel/llvm-test-suite that referenced this pull request Feb 22, 2022
The test is extended with a specialization constant built upon an aligned
structure. The CFE generates a padding represented as '[size x i8] undef' for
such structures and the sycl-post-link tool crashed during property set
generation for the specialization constant. The bug has been fixed in
intel/llvm#5538, this extension is the E2E test for the fix to ensure that
the default values and offsets given to the runtime are correct.

Signed-off-by: Pavel Samolysov <pavel.samolysov@intel.com>
alexbatashev added a commit to alexbatashev/llvm that referenced this pull request Feb 23, 2022
* upstream/sycl: (2757 commits)
  [SYCL][Doc] Fixing incorrect merge of community Readme.md with our version (intel#5636)
  [SYCL] Change USM pooling parameters. (intel#5457)
  [CI] Fix cache location on Windows (intel#5603)
  [SYCL][NFC] Fix a warning about uninitialized struct members (intel#5610)
  [Buildbot] Update Windows GPU version to 101.1340 (intel#5620)
  Fix SPIRV -> OCL barrier call argument attributes
  Move SPV_INTEL_memory_access_aliasing tokens from spirv_internal
  [SYCL][ESIMD] Add support for named barrier APIs (intel#5583)
  [SYCL][L0] Remove ZeModule when program build failed (intel#5541)
  [SYCL] Silence "unknown attribute" warning for `device_indirectly_callable` (intel#5591)
  [SYCL][DOC] Introductory material for extensions (intel#5605)
  [SYCL][DOC] Change extension names to lower case (intel#5607)
  [SYCL] Improve get_kernel_bundle performance (intel#5496)
  [SYCL] Do not build device code for sub-devices (intel#5240)
  [sycl-post-link] Fix a crash during spec-constant properties generation (intel#5538)
  [SYCL][DOC] Move SPIR-V and OpenCL extensions (intel#5578)
  [SYCL][ESIMD][EMU] Update memory intrinsics for ESIMD_EMU plugin (intel#4748)
  [CI] Allow stale issue bot to analyze more issues (intel#5602)
  [SYCL][L0] Honor property::queue::enable_profiling (intel#5543)
  [OpenMP] Properly save strings when doing LTO
  ...
aelovikov-intel pushed a commit to aelovikov-intel/llvm that referenced this pull request Mar 27, 2023
…el/llvm-test-suite#830)

The test is extended with a specialization constant built upon an aligned
structure. The CFE generates a padding represented as '[size x i8] undef' for
such structures and the sycl-post-link tool crashed during property set
generation for the specialization constant. The bug has been fixed in
intel#5538, this extension is the E2E test for the fix to ensure that
the default values and offsets given to the runtime are correct.

Signed-off-by: Pavel Samolysov <pavel.samolysov@intel.com>
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.

4 participants