-
Notifications
You must be signed in to change notification settings - Fork 687
Metal backend: Add operator implementations #15023
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
Open
manuelcandales
wants to merge
13
commits into
gh/manuelcandales/142/head
Choose a base branch
from
gh/manuelcandales/143/head
base: gh/manuelcandales/142/head
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,431
−0
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3bea537
Update
manuelcandales de83a9f
Update
manuelcandales 2f092af
Update
manuelcandales e9b3372
Update
manuelcandales aec8796
Update
manuelcandales 3229b92
Update
manuelcandales 7f178d3
Update
manuelcandales 780d883
Update
manuelcandales 61ead64
Update
manuelcandales 750badf
Update
manuelcandales 6a6ba04
Update
manuelcandales 7c1b9b2
Update
manuelcandales 4367977
Update
manuelcandales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <executorch/backends/apple/metal/runtime/shims/types.h> | ||
|
||
namespace executorch { | ||
namespace backends { | ||
namespace metal { | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* ExecutorTorch implementation of aoti_torch_mps_mm_out. | ||
* Performs simple matrix multiplication: out = self @ mat2 | ||
*/ | ||
AOTITorchError aoti_torch_mps_mm_out( | ||
AOTITensorHandle out, | ||
AOTITensorHandle self, | ||
AOTITensorHandle mat2); | ||
|
||
/** | ||
* ExecutorTorch implementation of aoti_torch_mps_convolution. | ||
* Performs 2D convolution operation - matches PyTorch AOTI signature | ||
*/ | ||
AOTITorchError aoti_torch_mps_convolution( | ||
AOTITensorHandle input, | ||
AOTITensorHandle weight, | ||
AOTITensorHandle* bias, | ||
const int64_t* stride, | ||
int64_t stride_len_, | ||
const int64_t* padding, | ||
int64_t padding_len_, | ||
const int64_t* dilation, | ||
int64_t dilation_len_, | ||
int32_t transposed, | ||
const int64_t* output_padding, | ||
int64_t output_padding_len_, | ||
int64_t groups, | ||
AOTITensorHandle* ret0); | ||
|
||
/** | ||
* ExecutorTorch implementation of | ||
* aoti_torch_mps__scaled_dot_product_attention_math_for_mps. Performs scaled | ||
* dot product attention calculation - matches PyTorch AOTI signature | ||
*/ | ||
AOTITorchError aoti_torch_mps__scaled_dot_product_attention_math_for_mps( | ||
AOTITensorHandle query, | ||
AOTITensorHandle key, | ||
AOTITensorHandle value, | ||
AOTITensorHandle* attn_mask, | ||
double dropout_p, | ||
int32_t is_causal, | ||
AOTITensorHandle* dropout_mask, | ||
double* scale, | ||
AOTITensorHandle* ret0, | ||
AOTITensorHandle* ret1); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
} // namespace metal | ||
} // namespace backends | ||
} // namespace executorch |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does custom ops use caching mechanism like the ETMetalShaderLibrary?
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.
No, not yet. These fallback ops are implemented using MPSGraph, so, here we would be caching the graph. This is something I want to look into later when optimizing performance. But this deserves time. In particular, since I never understood why MPSGraph operations have a non-trivial CPU overhead in PyTorch, in spite of PyTorch having a caching mechanism for MPSGraphs.