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]
[ghstack-poisoned]
[ghstack-poisoned]
[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.

✅ No Failures

As of commit f46adc5 with merge base 926312e (image):
💚 Looks good so far! There are no failures yet. 💚

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.

Don't you wanna be consistent with c10/core/DeviceType.h?

https://github.com/pytorch/pytorch/blob/2beead75236dd7dbc1af5130217889ccf6771103/torch/headeronly/core/DeviceType.h#L44-L46

It is either 11 or 13

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]
[ghstack-poisoned]
[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
Base automatically changed from gh/manuelcandales/138/head to main October 14, 2025 22:35
[ghstack-poisoned]
[ghstack-poisoned]
@manuelcandales manuelcandales merged commit 6e0c9f6 into main Oct 15, 2025
145 checks passed
@manuelcandales manuelcandales deleted the gh/manuelcandales/139/head branch October 15, 2025 02:58
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