-
Notifications
You must be signed in to change notification settings - Fork 354
Add RHI Device Caching and Test Prefix Exclusion #8448
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
Conversation
/format |
🌈 Formatted, please merge the changes from this PR |
Automated code formatting for #8448 Co-authored-by: slangbot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few comments but it looks good enough as it is.
std::size_t DeviceCache::DeviceCacheKeyHash::operator()(const DeviceCacheKey& key) const | ||
{ | ||
std::size_t h1 = std::hash<int>{}(static_cast<int>(key.deviceType)); | ||
std::size_t h2 = std::hash<bool>{}(key.enableValidation); | ||
std::size_t h3 = std::hash<bool>{}(key.enableRayTracingValidation); | ||
std::size_t h4 = std::hash<std::string>{}(key.profileName); | ||
|
||
std::size_t h5 = 0; | ||
for (const auto& feature : key.requiredFeatures) | ||
{ | ||
h5 ^= std::hash<std::string>{}(feature) + 0x9e3779b9 + (h5 << 6) + (h5 >> 2); | ||
} | ||
|
||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3) ^ (h5 << 4); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, chatGPT suggested the following as a cleaner alternative,
return std::hash<
std::tuple<
int, bool, bool, std::string, std::vector<std::string>
>
>{}(
std::tuple{
static_cast<int>(key.deviceType),
key.enableValidation,
key.enableRayTracingValidation,
key.profileName,
key.requiredFeatures
}
);
I haven't tried it.
// Skip caching for CUDA devices due to crashes | ||
if (desc.deviceType == rhi::DeviceType::CUDA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not caching for CUDA?
What is the problem with this?
If this is a temporary WAR, we may need a new github issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During the CUDA device destroying, it calls the debugCall func pointer.
Our debug callback lifetime is per-test, and doesn't out live the device.
I tried a few approaches and but seems there is no easy fix. That requires a careful design to be threadsafe. I will create another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't we make debug callback also have the same lifetime as the device?
uint64_t& DeviceCache::getNextCreationOrder() | ||
{ | ||
static uint64_t instance = 0; | ||
return instance; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to have a function scoped static for "getMutex".
But when the type is just a primitive type, it seems unnecessary.
Feel free to ignore this comment but I would go with a simpler/traditional code like,
static uint64_t s_nextCreationOrder = 0;
}; | ||
|
||
private: | ||
static constexpr int MAX_CACHED_DEVICES = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore this comment, but we may want to set the value from the command-line argument for a debugging purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do that in a follow up PR, as this will require we adding another option to both render-test-tool and cmdline arg to slang-test.
" -verbose-paths Use verbose paths in output\n" | ||
" -category <name> Only run tests in specified category\n" | ||
" -exclude <name> Exclude tests in specified category\n" | ||
" -exclude-prefix <prefix> Exclude tests with specified path prefix\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be a separate PR for adding "exclude-XXX"
The tricky part is "prefix" is often not enough to describe which one to exclude.
The workaround had been just delete the files locally if you want to exclude them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some tests that we need to exclude for running GPU tests in aarch64. I filed an issue to track that #8468
I'd like to get this feature to enable the GPU tests for aarch64 ASAP.
for (auto& excludePrefix : context->options.excludePrefixes) | ||
{ | ||
if (filePath.startsWith(excludePrefix)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can print an information message when the verbose option is enabled.
Something like,
XXX file is excluded from the test because it is found from the exclusion list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. Updated.
std::sort(key.requiredFeatures.begin(), key.requiredFeatures.end()); | ||
|
||
// Evict oldest device if we've reached the limit | ||
evictOldestDeviceIfNeeded(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may want to print some message when the verbose mode is enabled for a debugging purpose.
It will be useful if we can track when certain devices were created and when certain devices were evicted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be good, but I haven't seen verbose
option in render-test-tool. That would requires us adding another option.
I will do that in a follow up PR
for (int i = 0; i < desc.requiredFeatureCount; ++i) | ||
{ | ||
key.requiredFeatures.push_back(desc.requiredFeatures[i]); | ||
} | ||
std::sort(key.requiredFeatures.begin(), key.requiredFeatures.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to use std::set
if the list has to be always sorted?
4dcc652
to
fe4f205
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
Automated code formatting for #8448 Co-authored-by: slangbot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Add RHI Device Caching and Test Prefix Exclusion
Summary
This PR introduces two key improvements to the Slang test infrastructure:
-exclude-prefix
option to skip tests matching specified path prefixesChanges
RHI Device Caching
DeviceCache
class (slang-test-device-cache.h/cpp
): Thread-safe device cache with LRU eviction (max 10 devices)-cache-rhi-device
flag in bothslang-test
andrender-test
Test Prefix Exclusion
-exclude-prefix <prefix>
option in slang-test-category
and individual test filtering optionsUsage Examples
This change should significantly improve test execution performance, particularly in CI environments with frequent device operations. This is needed for running the GPU test in aarch64, where repeated device creation/destroy is causing driver issues.
Needed by: #8346