Skip to content
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

Store the residency set in MVKPhysicalDevice. #2448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

js6i
Copy link
Collaborator

@js6i js6i commented Feb 14, 2025

@billhollings Attaching once to the MTLQueue seems like the more efficient thing to do, but on the other hand Metal presumably caches things and does not do big intersections repeatedly when the same set is attached to all command buffers. If we care about having separate sets for each device that's something to consider.

Fixes #2444

Since the MTLQueues are shared between MVKDevices, an application that creates
many devices (CTS, in particular) may run out of the number of residency sets
that can be added to a single MTLQueue.

This patch keeps a single residency set in MVKPhysicalDevice, which is added
once to each queue and shared as the queues are.

We could instead attach each MVKDevice's residency set to every created
MTLCommandBuffer, but that may incur a performance overhead of processing the
entries each time, which would affect all applications.

Fixes KhronosGroup#2444
@CLAassistant
Copy link

CLAassistant commented Feb 14, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@billhollings billhollings left a comment

Choose a reason for hiding this comment

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

Attaching once to the MTLQueue seems like the more efficient thing to do, but on the other hand Metal presumably caches things and does not do big intersections repeatedly when the same set is attached to all command buffers. If we care about having separate sets for each device that's something to consider.

I assume another way of fixing this would be to stick with your existing design around MVKDevice, and simply call removeResidencySet: in the MVKQueue destructor? That would be a good RAII complement to the existing addResidencySet: in the MVKQueue constructor, and would seem to better track to the idea of tracking separate sets per device.

If you want to stick with this design, around physical device, I've added some minor review recommendations.

Also, I'm not sure why it's asking you to renew your CLA, but please do so, before we can merge any changes.

@@ -830,9 +839,9 @@ class MVKDevice : public MVKDispatchableVulkanAPIObject {
void makeResident(id allocation) {}
#else
void makeResident(id<MTLAllocation> allocation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're moving the residency set to MVKPhysicalDevice, these functions will be more consistent if moved there too.

Then elsewhere, just call getPhysicalDevice()->makeResident() where you now call getDevice()->makeResident().

#if MVK_XCODE_16
if (_isUsingMetalArgumentBuffers && _metalFeatures.residencySets) {
MTLResidencySetDescriptor *setDescriptor;
setDescriptor = [MTLResidencySetDescriptor new];
Copy link
Contributor

Choose a reason for hiding this comment

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

No biggie, but I'm never a fan of uninitialized vars. It would read nicer if these two lines were combined.

_mtlResidencySet = [_mtlDevice newResidencySetWithDescriptor:setDescriptor
error:&error];
if (error) {
reportMessage(MVK_CONFIG_LOG_LEVEL_ERROR, "Error allocating residency set: %s", error.description.UTF8String);
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use reportError(VK_ERROR_INITIALIZATION_FAILED, ...) instead.

@js6i
Copy link
Collaborator Author

js6i commented Feb 18, 2025

I assume another way of fixing this would be to stick with your existing design around MVKDevice, and simply call removeResidencySet: in the MVKQueue destructor? That would be a good RAII complement to the existing addResidencySet: in the MVKQueue constructor, and would seem to better track to the idea of tracking separate sets per device.

Right, I guess I assumed the devices were created in parallel before I noticed the queues are shared, and they clearly just retain the sets. If we're OK with having the 32 live devices limit (which seems fine) that's better. I created a new PR, let's shelve this one for now.

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.

Failed assertion 'IOGPUMetalCommandQueue: command queue residency set limit of 32 exceeded' in VK CTS
3 participants