Skip to content

[DeviceSanitizer] Fix device global type of KernelMetadata #16357

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 3 commits into from
Dec 23, 2024

Conversation

AllanZyne
Copy link
Contributor

@AllanZyne AllanZyne commented Dec 13, 2024

OpenCL CPU requires the type of device global wraps with structure type

@AllanZyne AllanZyne requested a review from a team as a code owner December 13, 2024 08:16
@AllanZyne AllanZyne changed the title [DeviceSanitier] Fix device global type of KernelMetadata [DeviceSanitizer] Fix device global type of KernelMetadata Dec 13, 2024
@AllanZyne
Copy link
Contributor Author

Hi @intel/dpcpp-tools-reviewers, please review, thanks!

Copy link
Contributor

@zhaomaosu zhaomaosu left a comment

Choose a reason for hiding this comment

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

lgtm

KernelMetadata->copyAttributesFrom(KernelMetadataOld);
KernelMetadata->copyMetadata(KernelMetadataOld, 0);

KernelMetadataOld->eraseFromParent();
Copy link
Contributor

Choose a reason for hiding this comment

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

why not generate KernelMetadataOld in struct type in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good question.

"KernelMetadata" is an array with appending linkage, so it can't be struct type at beginning.

I also considered to generate "KernelMetadata" at sycl-post-link step completely, but I use "KernelMetadata" to distinguish if the device image is a sanitized module at the same time. If we don't add "KernelMetadata" at sanitizer pass, it's possible that a sanitized module (but without any sanitized kernels) won't enable sanitizer layer at UR.

This is a design decision that if user uses "-fsanitize=" to compile program, we will always enable sanitizer layer in UR.

@AllanZyne
Copy link
Contributor Author

Kindly ping @intel/dpcpp-tools-reviewers. Thanks!

Comment on lines 45 to 47
auto Name = KernelMetadata->getName().str();
KernelMetadata->setName(Name + "_del");
auto *KernelMetadataOld = KernelMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is Value::takeName which will simplify name transfer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

M, StructTypeWithArray, false, GlobalValue::ExternalLinkage,
ConstantStruct::get(StructTypeWithArray,
KernelMetadataOld->getInitializer()),
Name, nullptr, GlobalValue::NotThreadLocal, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to have an inline comment explaining this magic 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@AllanZyne
Copy link
Contributor Author

@intel/llvm-gatekeepers, please merge. Thanks!

@yingcong-wu
Copy link
Contributor

Kindly ping @intel/llvm-gatekeepers , please help merge the PR, thanks.

@sarnex sarnex merged commit 2017256 into sycl Dec 23, 2024
14 checks passed
@AllanZyne AllanZyne deleted the review/yang/fix_medatata_struct branch December 24, 2024 01:49
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.

6 participants