-
Notifications
You must be signed in to change notification settings - Fork 684
Add Metal backend type definitions and utilities #15019
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
base: gh/manuelcandales/138/head
Are you sure you want to change the base?
Add Metal backend type definitions and utilities #15019
Conversation
🔗 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 SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 12 New Failures, 8 Unrelated FailuresAs of commit 7590e37 with merge base 9560800 ( 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. |
// Let's use 2 for MPS | ||
return 2; |
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.
Don't you wanna be consistent with c10/core/DeviceType.h?
It is either 11 or 13
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.
Done!
using AOTIRuntimeError = Error; | ||
using AOTITorchError = Error; |
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.
Do you need to distinguish both errors? Seems like AOTIRuntimeError is not used
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.
Yes, AOTInductorModelContainerRun and family return AOTIRuntimeError while aoti_torch_empty_strided and family return AOTITorchError
// 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; | ||
} |
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.
Let's move these to a different common location. There's no metal specific logic here. Maybe backends/aoti/utils.h
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.
done!
std::vector<executorch::aten::SizesType> sizes, | ||
std::vector<executorch::aten::StridesType> strides) { |
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 implementation will copy. maybe do this
const std::vector<executorch::aten::SizesType>& sizes,
const std::vector<executorch::aten::StridesType>& strides
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.
done!
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
Implement foundational types and utilities for Metal backend including: