Skip to content

Support MPS Backend also on iOS < 16 (#9089) #9095

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 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions backends/apple/mps/runtime/MPSDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ static inline MTLLanguageVersion getMetalLanguageVersion(const id<MTLDevice>& de
// MPS Advanced Indexing needs at least Metal 2.0 (support for Argument Buffers and function constants)
// host_name attribute needs at least Metal 2.2 and ulong needs Metal 2.3 (supported on MacOS 11+)
MTLLanguageVersion languageVersion = MTLLanguageVersion2_3;
#if defined(__MAC_13_0)
if (macOS13Plus) {
languageVersion = MTLLanguageVersion3_0;
if (@available(iOS 16, macOS 13, *)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for the change

if (macOS13Plus) {
languageVersion = MTLLanguageVersion3_0;
}
}
#endif

ET_CHECK_MSG([device supportsFamily:MTLGPUFamilyMac2], "Missing Metal support for MTLGPUFamilyMac2");
return languageVersion;
Expand Down
41 changes: 24 additions & 17 deletions backends/apple/mps/runtime/operations/IndexingOps.mm
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,32 @@

Error
MPSGraphBuilder::mpsScatterOp(NodePtr nodePtr) {
auto graphNode = nodePtr->mpsnode_union_as_MPSScatter();
ET_LOG(
Debug, "%s %d: %d",
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
);
if (@available(iOS 15.4, macOS 12.3, *)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch

auto graphNode = nodePtr->mpsnode_union_as_MPSScatter();
ET_LOG(
Debug, "%s %d: %d",
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
);

int64_t dim = graphNode->dim();
MPSGraphTensor* inputTensor = getMPSGraphTensor(graphNode->input1_id());
MPSGraphTensor* indicesTensor = getMPSGraphTensor(graphNode->idx_id());
MPSGraphTensor* updatesTensor = getMPSGraphTensor(graphNode->src_id());
int64_t dim = graphNode->dim();
MPSGraphTensor* inputTensor = getMPSGraphTensor(graphNode->input1_id());
MPSGraphTensor* indicesTensor = getMPSGraphTensor(graphNode->idx_id());
MPSGraphTensor* updatesTensor = getMPSGraphTensor(graphNode->src_id());

_idToMPSGraphTensor[graphNode->output_id()] =
[_mpsGraph scatterAlongAxis:dim
withDataTensor:inputTensor
updatesTensor:updatesTensor
indicesTensor:indicesTensor
mode:MPSGraphScatterModeSet
name:nil];
return Error::Ok;
_idToMPSGraphTensor[graphNode->output_id()] =
[_mpsGraph scatterAlongAxis:dim
withDataTensor:inputTensor
updatesTensor:updatesTensor
indicesTensor:indicesTensor
mode:MPSGraphScatterModeSet
name:nil];

return Error::Ok;
} else {
ET_LOG(Error, "MPS: scatter op is not supported on iOS < 15.4 and macOS < 12.3");

return Error::NotSupported;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, one minor thing - can you add an error log here like

ET_LOG(Error, "...")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, and I also changed the requirements to iOS 15.4 and MacOS 12.3

}
}


Expand Down
Loading