-
Notifications
You must be signed in to change notification settings - Fork 791
[SYCL] Implement coverage instrumentation for device code #20206
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
base: sycl
Are you sure you want to change the base?
Changes from 3 commits
a1e71e8
4f9041b
43ff03a
9408601
8201ffc
259e666
c30c098
094c73d
fca194f
607e2c1
e2ea6ed
d4459f9
1bbdc76
5d16d4e
bd4e454
5c42c6c
b3fbe61
7d5f8b1
4c3d87b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,13 +389,16 @@ add_custom_target(sycl-compiler | |
clang-offload-extract | ||
clang-offload-packager | ||
clang-linker-wrapper | ||
compiler-rt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do other projects enable profiling unconditionally in the build too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only remaining question from me, the rest is 🔥 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know of any projects that enable profiling unconditionally. This change enables support for coverage instrumentation in our build but does not enable the instrumentation itself. I think it makes sense to do this unconditionally so that the related functionality in the SYCL runtime can be tested as part of our regular end-to-end testing process. I'd like to add a build flag for building the SYCL runtime with instrumentation enabled. This flag would allow us to produce coverage reports and identify areas in the runtime that are not covered by tests. I plan to do this in a separate PR and make the instrumentation disabled by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd argue that that would be a reason to enable it in That said, if others are ok, I'm not going to block PR on this. |
||
file-table-tform | ||
llc | ||
llvm-ar | ||
llvm-foreach | ||
llvm-spirv | ||
llvm-link | ||
llvm-objcopy | ||
llvm-profdata | ||
llvm-cov | ||
spirv-to-ir-wrapper | ||
sycl-post-link | ||
opencl-aot | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,62 @@ OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(adapter_impl &Adapter) { | |
} | ||
} | ||
|
||
bool DeviceGlobalMapEntry::isAvailableInContext(const context_impl *CtxImpl) { | ||
std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex}; | ||
for (const auto &It : MDeviceToUSMPtrMap) | ||
if (It.first.second == CtxImpl) | ||
return true; | ||
return false; | ||
0x12CC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
bool DeviceGlobalMapEntry::isProfileCounter() { | ||
const std::string CounterPrefix = "__profc_"; | ||
return MUniqueId.substr(0, CounterPrefix.size()) == CounterPrefix; | ||
0x12CC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
extern "C" void __attribute__((weak)) | ||
__sycl_increment_profile_counters(std::uint64_t FnHash, std::size_t NumCounters, | ||
const std::uint64_t *Increments); | ||
|
||
void DeviceGlobalMapEntry::cleanupProfileCounter(context_impl *CtxImpl) { | ||
std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex}; | ||
0x12CC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const std::size_t NumCounters = MDeviceGlobalTSize / sizeof(std::uint64_t); | ||
const std::uint64_t FnHash = [&] { | ||
const auto PrefixSize = std::string{"__profc_"}.size(); | ||
0x12CC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
constexpr int DecimalBase = 10; | ||
return std::strtoull(MUniqueId.substr(PrefixSize).c_str(), nullptr, | ||
DecimalBase); | ||
}(); | ||
for (const device_impl &Device : CtxImpl->getDevices()) { | ||
auto USMPtrIt = MDeviceToUSMPtrMap.find({&Device, CtxImpl}); | ||
if (USMPtrIt != MDeviceToUSMPtrMap.end()) { | ||
0x12CC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
DeviceGlobalUSMMem &USMMem = USMPtrIt->second; | ||
|
||
// Get the increments from the USM pointer. | ||
std::vector<std::uint64_t> Increments(NumCounters); | ||
const std::uint64_t *Counters = static_cast<std::uint64_t *>(USMMem.MPtr); | ||
for (std::size_t I = 0; I < NumCounters; ++I) | ||
Increments[I] = Counters[I]; | ||
|
||
|
||
// Call the weak symbol to update the profile counters. | ||
if (__sycl_increment_profile_counters) | ||
__sycl_increment_profile_counters(FnHash, Increments.size(), | ||
Increments.data()); | ||
|
||
// Free the USM memory and release the event if it exists. | ||
detail::usm::freeInternal(USMMem.MPtr, CtxImpl); | ||
if (USMMem.MInitEvent != nullptr) | ||
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>( | ||
USMMem.MInitEvent); | ||
|
||
// Set to nullptr to avoid double free. | ||
USMMem.MPtr = nullptr; | ||
USMMem.MInitEvent = nullptr; | ||
MDeviceToUSMPtrMap.erase(USMPtrIt); | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
DeviceGlobalUSMMem & | ||
DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) { | ||
assert(!MIsDeviceImageScopeDecorated && | ||
|
@@ -67,7 +123,8 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) { | |
return DGUSMPtr->second; | ||
|
||
void *NewDGUSMPtr = detail::usm::alignedAllocInternal( | ||
0, MDeviceGlobalTSize, &CtxImpl, &DevImpl, sycl::usm::alloc::device); | ||
0, MDeviceGlobalTSize, &CtxImpl, &DevImpl, | ||
isProfileCounter() ? sycl::usm::alloc::shared : sycl::usm::alloc::device); | ||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
auto NewAllocIt = MDeviceToUSMPtrMap.emplace( | ||
std::piecewise_construct, std::forward_as_tuple(&DevImpl, &CtxImpl), | ||
|
@@ -125,7 +182,8 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(const context &Context) { | |
return DGUSMPtr->second; | ||
|
||
void *NewDGUSMPtr = detail::usm::alignedAllocInternal( | ||
0, MDeviceGlobalTSize, &CtxImpl, &DevImpl, sycl::usm::alloc::device); | ||
0, MDeviceGlobalTSize, &CtxImpl, &DevImpl, | ||
isProfileCounter() ? sycl::usm::alloc::shared : sycl::usm::alloc::device); | ||
|
||
auto NewAllocIt = MDeviceToUSMPtrMap.emplace( | ||
std::piecewise_construct, std::forward_as_tuple(&DevImpl, &CtxImpl), | ||
|
Uh oh!
There was an error while loading. Please reload this page.