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

Improve matrices translation with SPV_KHR_untyped_pointers #2857

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vmaksimo
Copy link
Contributor

Ensure that we do correct translation of matrices (SPV_KHR_cooperative_matrix and SPV_INTEL_joint_matrix extensions) when untyped pointers are enabled.
This mainly fixes mangling issues in reverse translation for the untyped pointer.
Also added handling for typed and untyped SPIR-V friendly access chain instructions in forward translation (a point to review and discuss).

@vmaksimo vmaksimo changed the title Fix matrices translation with SPV_KHR_untyped_pointers Improve matrices translation with SPV_KHR_untyped_pointers Nov 13, 2024
; CHECK-SPIRV: UntypedAccessChainKHR [[#TypePtr]] [[#Res:]] [[#TypeMatrix]] [[#VarMatrixPtr]] [[#Const1]]
; CHECK-SPIRV: Store [[#Res]] [[#Const42]]

; CHECK-LLVM: %0 = alloca target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
; CHECK-LLVM: %0 = alloca target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 0)
; CHECK-LLVM: %[[#Matrix:]] = alloca target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 0)

and so on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's basically just a copy of access_store.ll test :) do we need these checks there too?

Copy link
Contributor

Choose a reason for hiding this comment

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

May be in another PR, not here :)

else if (RetTy->isVectorTy())
Ty = cast<VectorType>(RetTy)->getElementType();
else
Ty = RetTy;
Copy link
Contributor

Choose a reason for hiding this comment

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

So for store pointer parameter would be considered as void *? If so it doesn't feel right, can we instead query type of the value operand of the store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't get this at all. Don't we already query the type from the llvm instructions? Or do you mean specific SPIR-V opcode in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

On the line 3437 RetTy is defined like this:

  Type *RetTy =
      BI->hasType() ? transType(BI->getType()) : Type::getVoidTy(*Context);

So if the instruction doesn't have a return type (aka ...Store...) RetTy will be void and the line 3473 && RetTy is always true.
When processing Ptr argument of ...Store... instruction isa<Argument>(Val) will also be true, if so, we assign Ty to RetTy which is void.
Is it correct or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got you, you're right - it won't be correct, i was just "lucky" that we didn't have test case for that. Will prepare a fix

auto *AI = static_cast<SPIRVAtomicInstBase *>(BI);
ArgTys[Ptr] = TypedPointerType::get(
transType(AI->getSemanticType()),
SPIRSPIRVAddrSpaceMap::rmap(
BI->getValueType(Ops[Ptr]->getId())->getPointerStorageClass()));
} else if (OC == spv::OpCooperativeMatrixStoreKHR ||
OC == spv::internal::OpJointMatrixStoreINTEL ||
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, we can stop modifying code related to JointMatrixINTEL instructions that have CooperativeMatrixKHR counterparts aka trivial MatrixLoad/Store, MulAdd etc as they will be depricated. Meanwhile OpCooperativeMatrixStoreCheckedINTEL and other unique for SPV_INTEL_joint_matrix extension instruction must still be handled properly.

else if (RetTy->isVectorTy())
Ty = cast<VectorType>(RetTy)->getElementType();
else
Ty = RetTy;
Copy link
Contributor

Choose a reason for hiding this comment

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

On the line 3437 RetTy is defined like this:

  Type *RetTy =
      BI->hasType() ? transType(BI->getType()) : Type::getVoidTy(*Context);

So if the instruction doesn't have a return type (aka ...Store...) RetTy will be void and the line 3473 && RetTy is always true.
When processing Ptr argument of ...Store... instruction isa<Argument>(Val) will also be true, if so, we assign Ty to RetTy which is void.
Is it correct or am I missing something?

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.

2 participants