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
[GPU] Enable Metal on macosx #47635
[GPU] Enable Metal on macosx #47635
Conversation
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! ghstack-source-id: 116242312 Pull Request resolved: #47635
💊 CI failures summary and remediationsAs of commit 5a06789 (more details on the Dr. CI page):
🚧 6 ongoing upstream failures:These were probably caused by upstream breakages that are not fixed yet:
ci.pytorch.org: 2 failed
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 28 times. |
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
Pull Request resolved: #47635 Add macosx support for metal. The supported os version is 10.13 and above. ghstack-source-id: 116617355 Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)!
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.
LGTM, just some nits and questions about convention.
cmake/Metal.cmake
Outdated
if(NOT DEFINED CMAKE_OSX_DEVELOPER_ROOT) | ||
if(EXISTS ${XCODE_POST_43_ROOT}) | ||
set(CMAKE_OSX_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) | ||
elseif(EXISTS ${XCODE_PRE_43_ROOT}) | ||
set(CMAKE_OSX_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) | ||
endif(EXISTS ${XCODE_POST_43_ROOT}) | ||
endif(NOT DEFINED CMAKE_OSX_DEVELOPER_ROOT) | ||
set(CMAKE_OSX_DEVELOPER_ROOT ${CMAKE_OSX_DEVELOPER_ROOT} CACHE PATH "Location of OSX SDKs root directory") | ||
|
||
if(NOT DEFINED CMAKE_OSX_SDK_ROOT) | ||
file(GLOB _CMAKE_OSX_SDKS "${CMAKE_OSX_DEVELOPER_ROOT}/SDKs/*") | ||
if(_CMAKE_OSX_SDKS) | ||
list(SORT _CMAKE_OSX_SDKS) | ||
list(REVERSE _CMAKE_OSX_SDKS) | ||
list(GET _CMAKE_OSX_SDKS 0 CMAKE_OSX_SDK_ROOT) | ||
message(STATUS "_CMAKE_OSX_SDKS: ${_CMAKE_OSX_SDKS}") | ||
else(_CMAKE_OSX_SDKS) | ||
message(FATAL_ERROR "No OSX SDK's found in default search path ${CMAKE_OSX_DEVELOPER_ROOT}.") | ||
endif(_CMAKE_OSX_SDKS) | ||
message(STATUS "Toolchain using default OSX SDK: ${CMAKE_OSX_SDK_ROOT}") | ||
endif(NOT DEFINED CMAKE_OSX_SDK_ROOT) |
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.
@@ -3,7 +3,7 @@ | |||
#include <ATen/ATen.h> | |||
|
|||
|
|||
#if defined(C10_IOS) | |||
#if (C10_IOS || TARGET_OS_MAC) |
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.
Nothing wrong about this - just feel that having C10_IOS (defined by us) and TARGET_OS_MAC (defined by apple) on the same condition is a little unbalanced, lol.
If this condition is going to be used at other places, shall we create a dedicated macro? Not sure what's the best convention in PyTorch codebase (cc: @dzhulgakov):
- if it's targeting apple devices, shall we introduce 'C10_APPLE'?
- or, can we simply use some master feature switch? e.g. '#if AT_METAL_ENABLED()' seems to be one of the common pattern.
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.
How about (TARGET_OS_PHONE || TARGET_OS_MAC). Would that make you feel better 🤣
return mpscnn::conv2d(input, *op_context); | ||
#else | ||
TORCH_CHECK(false, "conv2d_prepack_run can only be invoked on iOS"); | ||
TORCH_CHECK(false, "conv2d_prepack_run can only be invoked on iOS and MacOS"); | ||
return input; |
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.
nit: I don't think we need 'return input;' here as TORCH_CHECK(false, ...) throws.
return mpscnn::copy_to_host(input); | ||
#else | ||
TORCH_CHECK(false, "copy_to_host can only be invoked on iOS"); | ||
TORCH_CHECK(false, "copy_to_host can only be invoked on iOS and MacOS"); | ||
return input; |
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.
ditto
@@ -1195,6 +1195,18 @@ if(USE_CUDA) | |||
|
|||
endif() | |||
|
|||
# ---[ Metal(OSX) modification | |||
if(APPLE AND USE_PYTORCH_METAL) |
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.
nit: can we make 'USE_PYTORCH_METAL' only enabled when 'APPLE' is true?
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.
USE_PYTORCH_METAL
is also available on Linux. In that case, only one cpp file under aten/native/metal
will be compiled. The reason is that users can still do optimize_for_mobile
on Linux machines to export models for metal.
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
Pull Request resolved: #47635 Add macosx support for metal. The supported os version is 10.13 and above. ghstack-source-id: 116664268 Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)!
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
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.
accept to unblock - we could clean up these bool conditions (C10_IOS || TARGET_OS_MAC) later if they are going to be used a lot in the codebase in the future.
Add macosx support for metal. The supported os version is 10.13 and above. Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)! [ghstack-poisoned]
This pull request has been merged in 3846e35. |
Does this mean PyTorch will support inferencing and training on Mac using GPU in the future? |
I am wondering the same. Could someone in the know write a few sentences pls as to the goal here? When more clarity is provided then it is easier to see whether we can contribute :) |
Pull Request resolved: pytorch/pytorch#47635 Add macosx support for metal. The supported os version is 10.13 and above. ghstack-source-id: 116607205 Differential Revision: [D24825088](https://our.internmc.facebook.com/intern/diff/D24825088/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D24825088/)!
Stack from ghstack:
Add macosx support for metal. The supported os version is 10.13 and above.
Differential Revision: D24825088
NOTE FOR REVIEWERS: This PR has internal Facebook specific changes or comments, please review them on Phabricator!