Skip to content

Conversation

@skc7
Copy link
Collaborator

@skc7 skc7 commented Jan 8, 2026

This PR adds support to emit AMDGPU-specific module flags amdhsa_code_object_version and amdgpu_printf_kind to match OGCG behavior.

In CIRGenModule, the flags are stored as CIR module attributes:

  • cir.amdhsa_code_object_version (integer)
  • cir.amdgpu_printf_kind (string: "hostcall" or "buffered")

During lowering to LLVM IR (in LowerToLLVMIR.cpp), these attributes are converted to LLVM module flags.

@skc7 skc7 marked this pull request as ready for review January 8, 2026 10:24
@skc7
Copy link
Collaborator Author

skc7 commented Jan 8, 2026

amdhsa_code_object_version and amdgpu_printf_kind are llvm ir level module flags. Not sure if at CIR level does targets need a specific attribute for them implemented. So, went ahead with integer and string attribute representation.

CC: @bcardosolopes, @xlauko

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Overall makes sense, some nits

}

if (getTriple().isAMDGPU()) {
if (target.getTargetOpts().CodeObjectVersion !=
Copy link
Member

Choose a reason for hiding this comment

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

Create a emitAMDGPUMetadata (similar to emitOpenCLMetadata) and add this code over there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for feedback. Have updated PR to use emitAMDGPUMetadata() instead.

if (target.getTargetOpts().CodeObjectVersion !=
llvm::CodeObjectVersionKind::COV_None) {
theModule->setAttr(
"cir.amdhsa_code_object_version",
Copy link
Member

Choose a reason for hiding this comment

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

The name of these attributes shouldn't be hardcoded, please use something akin to getOpenCLVersionAttrName here and in the one below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getAMDGPUCodeObjectVersionAttrName()
getAMDGPUPrintfKindAttrName()

above methods have been added for querying the attr names.

@skc7 skc7 force-pushed the skc7/amdgpu_module_attrs branch from 22f67af to 83c22c0 Compare January 13, 2026 07:27
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