Skip to content

[SYCL][Clang] Permit virtual functions in SYCL #7255

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 22 commits into from
Nov 10, 2022

Conversation

KornevNikita
Copy link
Contributor

To enable virtual functions support in SYCL we need to change virtual table variables address space, so llvm-spirv translator is able to generate valid SPIR-V modules.

To enable virtual functions support in SYCL we need to change virtual
table variables address space, so llvm-spirv translator is able to
generate valid SPIR-V modules.
@KornevNikita
Copy link
Contributor Author

@intel/dpcpp-cfe-reviewers could you please take a look? It's a draft because there is no test and lot of lit-test failures. I will add a test and fix failures if this patch is valid.

Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

Quick review.

@KornevNikita KornevNikita marked this pull request as ready for review November 3, 2022 19:24
@KornevNikita KornevNikita requested review from a team as code owners November 3, 2022 19:24
@KornevNikita
Copy link
Contributor Author

E2E is in the progress

Copy link
Contributor

@mdtoguchi mdtoguchi left a comment

Choose a reason for hiding this comment

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

OK for driver

Copy link
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

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

Please add a test.

static_cast<unsigned>(LangAS::opencl_global))
: CGM.Int8PtrTy;
if (!VTable) {
if (VTableTy == CGM.Int8PtrTy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

VTableTy is Int8PtrTy for both SYCL and non-SYCL case above right? So what is the else for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe Int8PtrTy and Int8PtrTy(LangAS::opencl_global) are different, am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure but in any case, I think it is better to guard this using SYCLIsDevice.

I am not familiar with this code so I may be wrong but do we need the call back function? Won't global variable be constructed with modified VTableTy without the callback back? Or do default constructors not consider address space?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think all new changes need to be guarded with SYCLIsDevice if as well as SYCLAllowVirtualFunctions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Smth like

if (!VTable) {
  Type *VTableTy = CGM.Int8PtrTy;
  if (CGM.getLangOpts().SYCLIsDevice &&
      CGM.getLangOpts().SYCLAllowVirtualFunctions &&
      (VTableName == ClassTypeInfo || VTableName == SIClassTypeInfo)) {
    VTableTy =
        CGM.Int8Ty->getPointerTo(static_cast<unsigned>(LangAS::opencl_global))
            VTable =
            CGM.getModule().getOrInsertGlobal(VTableName, VTableTy, [&] {
              return new llvm::GlobalVariable(
                  CGM.getModule(), VTableTy, false,
                  llvm::GlobalVariable::ExternalLinkage, nullptr, VTableName,
                  nullptr, llvm::GlobalValue::ThreadLocalMode::NotThreadLocal,
                  llvm::Optional<unsigned>(
                      static_cast<unsigned>(LangAS::opencl_global)));
            });
  } else {
    VTable = CGM.getModule().getOrInsertGlobal(VTableName, VTableTy);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you ok with c810c23 or you don't want to see VTableTy with opencl_global outside of this guards?

static_cast<unsigned>(LangAS::opencl_global))
: CGM.Int8PtrTy;
if (!VTable) {
if (VTableTy == CGM.Int8PtrTy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all new changes need to be guarded with SYCLIsDevice if as well as SYCLAllowVirtualFunctions.

static_cast<unsigned>(LangAS::opencl_global))
: CGM.Int8PtrTy;
if (!VTable) {
if (VTableTy == CGM.Int8PtrTy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Smth like

if (!VTable) {
  Type *VTableTy = CGM.Int8PtrTy;
  if (CGM.getLangOpts().SYCLIsDevice &&
      CGM.getLangOpts().SYCLAllowVirtualFunctions &&
      (VTableName == ClassTypeInfo || VTableName == SIClassTypeInfo)) {
    VTableTy =
        CGM.Int8Ty->getPointerTo(static_cast<unsigned>(LangAS::opencl_global))
            VTable =
            CGM.getModule().getOrInsertGlobal(VTableName, VTableTy, [&] {
              return new llvm::GlobalVariable(
                  CGM.getModule(), VTableTy, false,
                  llvm::GlobalVariable::ExternalLinkage, nullptr, VTableName,
                  nullptr, llvm::GlobalValue::ThreadLocalMode::NotThreadLocal,
                  llvm::Optional<unsigned>(
                      static_cast<unsigned>(LangAS::opencl_global)));
            });
  } else {
    VTable = CGM.getModule().getOrInsertGlobal(VTableName, VTableTy);
  }
}

@Fznamznon
Copy link
Contributor

Also, I believe @elizabethandrews means clang LIT test. E2E test only won't be enough.

@AlexeySachkov AlexeySachkov requested a review from a team November 7, 2022 17:09
@KornevNikita KornevNikita requested a review from Naghasan November 8, 2022 14:58
@KornevNikita
Copy link
Contributor Author

@intel/llvm-gatekeepers

@steffenlarsen
Copy link
Contributor

Failures unrelated:

@steffenlarsen steffenlarsen merged commit b90391e into intel:sycl Nov 10, 2022
@KornevNikita KornevNikita deleted the virtual-function-crash branch December 9, 2022 14:45
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.

9 participants