Skip to content

Conversation

@haonanya1
Copy link
Contributor

@haonanya1 haonanya1 commented Mar 26, 2025

According to https://github.com/intel/llvm/blob/sycl/sycl/doc/design/DeviceGlobal.md#changes-to-the-dpc-front-end, LLVM IR attribute sycl-unique-id is the definition of each device_global variable, which provides a unique string identifier for each device global variable.

@haonanya1 haonanya1 requested a review from a team as a code owner March 26, 2025 05:51
// Create a memory buffer to hold the serialized module
std::string Buffer;
llvm::raw_string_ostream Stream(Buffer);
llvm::WriteBitcodeToFile(M, Stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the entire bitcode to do the hash seems quite heavy. Could we use others to do that? @wenju-he what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think WriteBitcodeToFile should be used here just for computing hash.
llvm::StructuralHash can be used to compute hash from module.
Does the hash needs to be different for different modules?

Copy link
Contributor Author

@haonanya1 haonanya1 Mar 26, 2025

Choose a reason for hiding this comment

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

Does the hash needs to be different for different modules?

@wenju-he, I think yes, https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/DeviceLib/bfloat16_conversion_test.cpp has 2 modules, one is BUILD_LIB code for dynamic link, another is BUILD_EXE code. If the 2 modules have same sycl-unique-id, test will assert fail in DeviceGlobalMapEntry::initialize https://github.com/intel/llvm/blob/sycl/sycl/source/detail/device_global_map_entry.hpp#L92.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/DeviceLib/bfloat16_conversion_test.cpp has 2 modules

When sanitizer isn't enabled, how is sycl-unique-id handled for the case if there is a device globals in the test?

Copy link
Contributor

@AllanZyne AllanZyne Mar 26, 2025

Choose a reason for hiding this comment

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

I think this is because we haven't handled "dynamic link" properly.
This is a new feature for device sanitizer, not a quick bug fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to issue a JIRA to track this.

Copy link
Contributor Author

@haonanya1 haonanya1 Mar 26, 2025

Choose a reason for hiding this comment

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

https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/DeviceLib/bfloat16_conversion_test.cpp has 2 modules

When sanitizer isn't enabled, how is sycl-unique-id handled for the case if there is a device globals in the test?

@wenju-he , sycl-unique-id is generated by dpcpp FE, The rules for creating this string are the same as __builtin_sycl_unique_stable_id https://github.com/intel/llvm/blob/sycl/sycl/doc/design/DeviceGlobal.md#changes-to-the-dpc-front-end. We generate fixed sycl-unique-id in DeviceSanitizer.
Do you mean we want same implementation for DeviceSanitizer attributes? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

When sanitizer isn't enabled, how is sycl-unique-id handled for the case if there is a device globals in the test?

For the above case, is it right that there is only one device global when sanitizer is disabled. However, if sanitizer is enabled, there are two distinct device globals which are supposed to be the same one?

Copy link
Contributor Author

@haonanya1 haonanya1 Mar 26, 2025

Choose a reason for hiding this comment

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

When sanitizer isn't enabled, how is sycl-unique-id handled for the case if there is a device globals in the test?

For the above case, is it right that there is only one device global when sanitizer is disabled. However, if sanitizer is enabled, there are two distinct device globals which are supposed to be the same one?

@wenju-he, when sanitizer is disabled, there is no device global. The device global is added by device sanitizer, for BUILD_LIB module, it's 2xi64 array which is ptrtoint for foo and main.

@__AsanKernelMetadata = dso_local local_unnamed_addr addrspace(1) global %0 { [2 x { i64, i64 }] [{ i64, i64 } { i64 ptrtoint (ptr addrspace(2) @__asan_kernel to i64), i64 61 }, { i64, i64 } { i64 ptrtoint (ptr addrspace(2) @__asan_kernel.1 to i64), i64 50 }] }, !spirv.Decorations !0 #0

for BUILD_EXE, it is ptrtoint for main.

@__AsanKernelMetadata = dso_local local_unnamed_addr addrspace(1) global %0 { [1 x { i64, i64 }] [{ i64, i64 } { i64 ptrtoint (ptr addrspace(2) @__asan_kernel to i64), i64 50 }] }, !spirv.Decorations !0 #0

Yes, the 2 @__AsanKernelMetadata has same main since main is compiled on both BUILD_EXE and BUILD_EXE.

Copy link
Contributor

Choose a reason for hiding this comment

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

when sanitizer is disabled, there is no device global.

Yeah, in the question there is a condition that if there is a device globals in the test
I understand that sanitizer adds new device global.

@haonanya1
Copy link
Contributor Author

haonanya1 commented Mar 26, 2025

All device Sanitizer such as Address Sanitizer, Memory Sanitizer and thread Sanitizer need similar change, the rename can be added to common utilts SPIRVSanitizerCommonUtils #17597.

@haonanya1 haonanya1 marked this pull request as draft April 23, 2025 07:05
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.

4 participants