Skip to content

Conversation

manuelcandales
Copy link
Contributor

Implement foundational types and utilities for Metal backend including:

  • AOTI type aliases (AOTITensorHandle, AOTIRuntimeError, AOTITorchError)
  • Device type handling functions
  • Tensor storage size queries
  • Tensor attribute utilities

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Oct 10, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15019

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 12 New Failures, 8 Unrelated Failures

As of commit 7590e37 with merge base 9560800 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
Comment on lines 22 to 23
// Let's use 2 for MPS
return 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines +28 to +29
using AOTIRuntimeError = Error;
using AOTITorchError = Error;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to distinguish both errors? Seems like AOTIRuntimeError is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, AOTInductorModelContainerRun and family return AOTIRuntimeError while aoti_torch_empty_strided and family return AOTITorchError

Comment on lines 49 to 88
// Utility function to convert sizes pointer to vector
std::vector<executorch::aten::SizesType> convert_sizes_to_vector(
int64_t ndim,
const int64_t* sizes_ptr) {
std::vector<executorch::aten::SizesType> sizes(ndim);
for (int i = 0; i < ndim; i++) {
sizes[i] = static_cast<executorch::aten::SizesType>(sizes_ptr[i]);
}
return sizes;
}

// Utility function to convert strides pointer to vector or calculate from sizes
std::vector<executorch::aten::StridesType> convert_strides_to_vector(
int64_t ndim,
const int64_t* sizes_ptr,
const int64_t* strides_ptr) {
std::vector<executorch::aten::StridesType> strides(ndim);

if (strides_ptr != nullptr) {
// Use provided strides.
for (int64_t i = 0; i < ndim; i++) {
strides[i] = static_cast<executorch::aten::StridesType>(strides_ptr[i]);
}
} else {
// Calculate strides from sizes.
if (ndim > 0) {
strides[ndim - 1] = static_cast<executorch::aten::StridesType>(
1); // Last dimension has stride 1
for (int64_t i = ndim - 2; i >= 0; i--) {
if (sizes_ptr[i + 1] == 0) {
strides[i] = strides[i + 1]; // Copy stride when size is 0
} else {
strides[i] = static_cast<executorch::aten::StridesType>(
static_cast<int64_t>(strides[i + 1]) * sizes_ptr[i + 1]);
}
}
}
}
return strides;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move these to a different common location. There's no metal specific logic here. Maybe backends/aoti/utils.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Comment on lines 59 to 60
std::vector<executorch::aten::SizesType> sizes,
std::vector<executorch::aten::StridesType> strides) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this implementation will copy. maybe do this

     const std::vector<executorch::aten::SizesType>& sizes,
     const std::vector<executorch::aten::StridesType>& strides

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

[ghstack-poisoned]
[ghstack-poisoned]
@manuelcandales manuelcandales added the release notes: none Do not include this in the release notes label Oct 13, 2025
manuelcandales added a commit to manuelcandales/executorch-1 that referenced this pull request Oct 14, 2025
Implement foundational types and utilities for Metal backend including:
- AOTI type aliases (AOTITensorHandle, AOTIRuntimeError, AOTITorchError)
- Device type handling functions
- Tensor storage size queries
- Tensor attribute utilities

ghstack-source-id: 7bfa3ae
ghstack-comment-id: 3392299883
Pull-Request: pytorch#15019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants