Skip to content
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

Closed
wants to merge 7 commits into from
Closed

[GPU] Enable Metal on macosx #47635

wants to merge 7 commits into from

Conversation

xta0
Copy link
Contributor

@xta0 xta0 commented Nov 9, 2020

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!

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]
xta0 added a commit that referenced this pull request Nov 9, 2020
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
@dr-ci
Copy link

dr-ci bot commented Nov 10, 2020

💊 CI failures summary and remediations

As of commit 5a06789 (more details on the Dr. CI page):


  • 2/8 failures possibly* introduced in this PR
    • 2/2 non-CircleCI failure(s)
  • 6/8 broken upstream at merge base fa0acb7 since Nov 16

🚧 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.

See how this bot performed.

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]
xta0 added a commit that referenced this pull request Nov 13, 2020
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/)!
@xta0 xta0 requested a review from ljk53 November 13, 2020 09:35
Copy link
Contributor

@ljk53 ljk53 left a 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.

Comment on lines 13 to 33
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems very similar to iOS.cmake - any chance to factor out?
also cc: @malfet @xuhdev

@@ -3,7 +3,7 @@
#include <ATen/ATen.h>


#if defined(C10_IOS)
#if (C10_IOS || TARGET_OS_MAC)
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

@xta0 xta0 Nov 14, 2020

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]
xta0 added a commit that referenced this pull request Nov 13, 2020
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]
Copy link
Contributor

@ljk53 ljk53 left a 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]
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 3846e35.

@PeterL1n
Copy link
Contributor

Does this mean PyTorch will support inferencing and training on Mac using GPU in the future?

@leovinus2001
Copy link

leovinus2001 commented Dec 7, 2020

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?
Train vs inference?
macOS vs iOS?
Metal throughout PyTorch or just ATen (based on checkins I see :)
Metal just for CNN or also Linear/LSTM?

When more clarity is provided then it is easier to see whether we can contribute :)

jasperzhong pushed a commit to jasperzhong/swift that referenced this pull request Nov 25, 2021
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/)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants