-
Notifications
You must be signed in to change notification settings - Fork 685
Metal backend: Implement the AOTI MPS shim #15022
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/141/head
Are you sure you want to change the base?
Metal backend: Implement the AOTI MPS shim #15022
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15022
Note: Links to docs will display an error until the docs builds have been completed. ❗ 2 Active SEVsThere are 2 currently active SEVs. If your PR is affected, please view them below:
❌ 3 New FailuresAs of commit 5dfcd4f with merge base 896178e ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
auto src_mtl_buffer = (id<MTLBuffer>)src_buffer; | ||
auto dst_mtl_buffer = (id<MTLBuffer>)dst_buffer; | ||
|
||
uint8_t* src_contents = static_cast<uint8_t*>([src_mtl_buffer contents]); | ||
uint8_t* dst_contents = static_cast<uint8_t*>([dst_mtl_buffer contents]); | ||
|
||
if (!src_contents || !dst_contents) { | ||
ET_LOG(Error, "aoti_torch_mps_copy_buffer: Failed to get buffer contents"); | ||
return Error::Internal; | ||
} | ||
|
||
memcpy(dst_contents + dst_offset, src_contents + src_offset, data_size); |
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.
aoti_torch_mps_free and aoti_torch_mps_memcpy expect contents ptr, but aoti_torch_mps_copy_buffer expects MTLBuffer objects. Is this intentional?
Isn't it something like this?
auto src_it = ptr_to_mtl_buffer.find(src_buffer);
auto dst_it = ptr_to_mtl_buffer.find(dst_buffer);
if (src_it == ptr_to_mtl_buffer.end()) {
ET_LOG(Error, "aoti_torch_mps_copy_buffer: src_buffer %p not found", src_buffer);
return Error::InvalidArgument;
}
if (dst_it == ptr_to_mtl_buffer.end()) {
ET_LOG(Error, "aoti_torch_mps_copy_buffer: dst_buffer %p not found", dst_buffer);
return Error::InvalidArgument;
}
id<MTLBuffer> src_mtl_buffer = src_it->second;
id<MTLBuffer> dst_mtl_buffer = dst_it->second;
ETMetalStream* stream = getCurrentMetalStream();
stream->copy(src_mtl_buffer, dst_mtl_buffer, data_size, src_offset, dst_offset, SyncType::NONE);
id<MTLBuffer> subBuffer = [device newBufferWithBytesNoCopy:buffer_pointer + constant_offset | ||
length:data_size | ||
options:MTLResourceCPUCacheModeWriteCombined | MTLResourceStorageModeShared | ||
deallocator:nil]; | ||
|
||
if (constant_offset != 0) { | ||
ptr_to_mtl_buffer[buffer_pointer + constant_offset] = subBuffer; // Map contents to buffer | ||
} |
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.
Why do you need this at all? subBuffer doesn't seem to be used anywhere
} | ||
} | ||
|
||
AOTITorchError aoti_torch_mps_get_kernel_function( |
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.
Call @autoreleasepool?
} | ||
} | ||
|
||
AOTITorchError aoti_torch_mps_start_encoding( |
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.
call @autoreleasepool
// Pure C dispatch functions - array versions | ||
AOTITorchError aoti_torch_mps_dispatch_array( | ||
AOTIMetalKernelFunctionHandle func, | ||
const uint64_t* length, |
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.
Validate length != nullptr
Includes: