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] Represent JointMatrixINTEL type as extension type #8343

Merged
merged 8 commits into from
Apr 13, 2023

Conversation

MrSidims
Copy link
Contributor

@MrSidims MrSidims commented Feb 14, 2023

This patch is build on top of https://reviews.llvm.org/D141008

It adds:
ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type
which is represented as a pointer to a structure to LLVM extension type
with the parameters that follow SPIR-V JointMatrixINTEL type.
The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

Better approach is to introduce joint matrix type to clang, but it's off the table now, since we are lacking OpenCL
spec.

The SPIR-V spec

@MrSidims MrSidims changed the title Try matrix opaque [SYCL] Represent JointMatrixINTEL type as extension type Feb 14, 2023
@MrSidims
Copy link
Contributor Author

@jcranmer-intel please take a look if implementation like this makes sense

@MrSidims MrSidims requested a review from dkhaldi February 14, 2023 15:51
OpTypeReserveId ``spirv.ReserveId`` (none)
OpTypeQueue ``spirv.Queue`` (none)
OpTypePipe ``spirv.Pipe`` access qualifier
OpTypePipeStorage ``spirv.PipeStorage`` (none)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, JointMatrixINTEL should also be mentioned here at least in intel/llvm repo

// 'tf32' interpretation is mapped to '0'
return getJointMatrixINTELExtType<true>(CompTy, TemplateArgs, 0);
} else if (LlvmTyName == "bfloat16") {
CompTy = llvm::Type::getInt16Ty(getLLVMContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

LLVM has a bfloat type, so surely it would make more sense to use that instead of i16? Or is there something about the JointMatrixINTEL spec that I'm missing?

Copy link
Contributor Author

@MrSidims MrSidims Feb 20, 2023

Choose a reason for hiding this comment

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

The thing is that in SPIR-V we don't have bfloat type (yet?). Instead we have conversion instructions and using short value as bfloat16 storage. Same for SYCL - here bfloat16 class is a wrapper around int16 storage. So for the consistency int16 is used here as well, though there is no other reason not to reuse LLVM's bf16 (just because we still will replace it with int16 in SPIR-V). So I lean towards appying this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, lets keep i16 to be aligned with SPIR-V spec. Once we have proper SPIR-V bf16 type we can start generating in by DPC++ compiler either here or elsewhere.

MrSidims added a commit to KhronosGroup/SPIRV-LLVM-Translator that referenced this pull request Mar 16, 2023
)

The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

TODO: figure out, how to deal with the switch from old API (Matrix has Layout) to new API (Layout was removed)

Depends on:
#1799
intel/llvm#8343
FreddyLeaf pushed a commit to FreddyLeaf/llvm that referenced this pull request Mar 22, 2023
The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

TODO: figure out, how to deal with the switch from old API (Matrix has Layout) to new API (Layout was removed)

Depends on:
intel#1799
intel#8343

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@ee03f5f
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@MrSidims MrSidims force-pushed the try-matrix-opaque branch from 7707bb0 to b9529a6 Compare March 31, 2023 12:37
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@MrSidims MrSidims marked this pull request as ready for review March 31, 2023 12:46
@MrSidims MrSidims requested a review from a team as a code owner March 31, 2023 12:46
@MrSidims MrSidims temporarily deployed to aws March 31, 2023 13:05 — with GitHub Actions Inactive
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@MrSidims MrSidims requested a review from a team as a code owner March 31, 2023 15:40
@MrSidims MrSidims requested a review from bso-intel March 31, 2023 15:40
@MrSidims MrSidims temporarily deployed to aws March 31, 2023 15:59 — with GitHub Actions Inactive
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@MrSidims MrSidims temporarily deployed to aws April 3, 2023 13:49 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 3, 2023 14:22 — with GitHub Actions Inactive
@MrSidims
Copy link
Contributor Author

MrSidims commented Apr 3, 2023

@intel/dpcpp-cfe-reviewers please take a look

@Fznamznon
Copy link
Contributor

So, why don't we use built-in type instead of parsing the Matrix type from headers?

@MrSidims
Copy link
Contributor Author

MrSidims commented Apr 4, 2023

So, why don't we use built-in type instead of parsing the Matrix type from headers?

Which one? I don't see the conversation resolved. Until then we need to unblock switch to opaque pointers.

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

Well, that is just a switch from one fragile solution to another. A couple of nits to comments, otherwise lgtm.

clang/lib/CodeGen/CodeGenTypes.cpp Outdated Show resolved Hide resolved
clang/lib/CodeGen/CodeGenTypes.cpp Outdated Show resolved Hide resolved
clang/lib/CodeGen/CodeGenTypes.cpp Outdated Show resolved Hide resolved
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@MrSidims MrSidims temporarily deployed to aws April 6, 2023 16:02 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 6, 2023 16:33 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 8, 2023 11:07 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 9, 2023 12:24 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 10, 2023 22:23 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 11, 2023 00:05 — with GitHub Actions Inactive
@MrSidims
Copy link
Contributor Author

@intel/llvm-reviewers-runtime please take a look at test changes in sycl directory

Copy link
Contributor

@dm-vodopyanov dm-vodopyanov left a comment

Choose a reason for hiding this comment

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

sycl/test/matrix changes LGTM

// CHECK: @_Z2f2{{.*}}(%spirv.JointMatrixINTEL._long_10_2_0_0
void f2(__spv::__spirv_JointMatrixINTEL<uint64_t, 10, 2, 0, 0> *matrix) {}
// CHECK: @_Z2f2{{.*}}(target("spirv.JointMatrixINTEL", i64, 10, 2, 0, 0, 0)
void f2(__spv::__spirv_JointMatrixINTEL<uint64_t, 10, 2, 0, 0, 0> *matrix) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aelovikov-intel here is the test for unsigned. Would you mind if I won't duplicate it in sycl headers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure what's the purpose of the SYCL RT tests then, but yes, no need for unsigned there.

Copy link
Contributor Author

@MrSidims MrSidims Apr 12, 2023

Choose a reason for hiding this comment

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

Well, matrix API is changing overtime, so having several compilation tests using real headers is good to have. One the extension is stable we will remove them (note, the E2E tests were in different repo and require specific hardware)

@MrSidims MrSidims requested a review from a team April 12, 2023 17:35
@MrSidims
Copy link
Contributor Author

@intel/llvm-gatekeepers please help with merge. From what I see
Failed Tests (1):
SYCL :: Basic/memory-consumption.cpp

and ESIMD tests

are known issues reported elsewhere

@steffenlarsen
Copy link
Contributor

@MrSidims - Could you please push a merge commit? Most of these failures should have been fixed on tip, so hopefully we should see fewer CI failures now.

@MrSidims
Copy link
Contributor Author

@MrSidims - Could you please push a merge commit? Most of these failures should have been fixed on tip, so hopefully we should see fewer CI failures now.

sure, done!

@MrSidims MrSidims temporarily deployed to aws April 12, 2023 22:44 — with GitHub Actions Inactive
@MrSidims MrSidims temporarily deployed to aws April 12, 2023 23:52 — with GitHub Actions Inactive
@bader bader merged commit 6f8e456 into intel:sycl Apr 13, 2023
MrSidims added a commit to MrSidims/llvm that referenced this pull request Apr 14, 2023
…el#8343)"

It appears to be, that mem2reg and SROA passes can't handle
target extension type properly. It means, that with turned on
optimizations alloca/load/store sequences of joint matrix types won't be
eliminated. It results in a crash in IGC since it can't handle such case
yet. Note, it means that matrix samples compiled with -O0 also don't
work now.

So we have to (temporary?) revert this patch.

This reverts commit 6f8e456.
bader added a commit that referenced this pull request Jun 14, 2023
…9841)

This reverts commit 4447a50. Previous
attempt: #8343

What changed: One extra patch is being added to the headers:
ca0595b
with this patch clang won't generate llvm.memcpy for trivial c'tor. So
later on inst combine won't
replace it with a cast to i64 followed by load + store which SROA +
mem2reg won't be able to handle
for target extension types.

It adds:
ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type which
is represented as a pointer to a structure to LLVM extension type with
the parameters that follow SPIR-V JointMatrixINTEL type. The expected
representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

Better approach is to introduce joint matrix type to clang, but it's off
the table now, since we are lacking OpenCL
spec.

Co-authored-by: Joshua Cranmer <joshua.cranmer@intel.com>

---------

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
Co-authored-by: Alexey Bader <alexey.bader@intel.com>
fineg74 pushed a commit to fineg74/llvm that referenced this pull request Jun 15, 2023
…ntel#9841)

This reverts commit 4447a50. Previous
attempt: intel#8343

What changed: One extra patch is being added to the headers:
intel@ca0595b
with this patch clang won't generate llvm.memcpy for trivial c'tor. So
later on inst combine won't
replace it with a cast to i64 followed by load + store which SROA +
mem2reg won't be able to handle
for target extension types.

It adds:
ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type which
is represented as a pointer to a structure to LLVM extension type with
the parameters that follow SPIR-V JointMatrixINTEL type. The expected
representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

Better approach is to introduce joint matrix type to clang, but it's off
the table now, since we are lacking OpenCL
spec.

Co-authored-by: Joshua Cranmer <joshua.cranmer@intel.com>

---------

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
Co-authored-by: Alexey Bader <alexey.bader@intel.com>
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Dec 5, 2024
…get ext type

The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

TODO: figure out, how to deal with the switch from old API (Matrix has Layout) to new API (Layout was removed)

Depends on:
intel/llvm#8343
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Dec 9, 2024
…get ext type

The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

TODO: figure out, how to deal with the switch from old API (Matrix has Layout) to new API (Layout was removed)

Depends on:
intel/llvm#8343
MrSidims added a commit to KhronosGroup/SPIRV-LLVM-Translator that referenced this pull request Dec 9, 2024
…get ext type

The expected representation is:
target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
%use%, (optional) %element_type_interpretation%)

TODO: figure out, how to deal with the switch from old API (Matrix has Layout) to new API (Layout was removed)

Depends on:
intel/llvm#8343
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.

7 participants