Skip to content

Commit e970dd9

Browse files
malfetpytorchmergebot
authored andcommitted
[CI] Compile on M1 natively (pytorch#95719)
We have plenty of runners now, let's use them for compilation as well. To achieve that, remove `xcode-version: "13.3.1"` property and tweak Metal framework detection logic to work with command line tools(which are installed in `/Library/Developer/CommandLineTools`) and SDK is in `/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk`) rather than full Xcode installation. TODO: Fix/enable OpenMP accelerated native builds (which are currently broken with `OMP: Error pytorch#15: Initializing libomp.dylib, but found libomp.dylib already initialized.`), but this matches existing behavior as cross-builds are compiled with OpenMP disabled. Pull Request resolved: pytorch#95719 Approved by: https://github.com/huydhn
1 parent e79b2b7 commit e970dd9

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

.ci/pytorch/macos-build.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ cross_compile_arm64() {
4040
USE_DISTRIBUTED=0 CMAKE_OSX_ARCHITECTURES=arm64 MACOSX_DEPLOYMENT_TARGET=11.0 USE_MKLDNN=OFF USE_QNNPACK=OFF WERROR=1 BUILD_TEST=OFF USE_PYTORCH_METAL=1 python setup.py bdist_wheel
4141
}
4242

43+
compile_arm64() {
44+
# Compilation for arm64
45+
# TODO: Compile with OpenMP support (but this causes CI regressions as cross-compilation were done with OpenMP disabled)
46+
USE_DISTRIBUTED=0 USE_OPENMP=0 MACOSX_DEPLOYMENT_TARGET=11.0 WERROR=1 BUILD_TEST=OFF USE_PYTORCH_METAL=1 python setup.py bdist_wheel
47+
}
48+
49+
compile_x86_64() {
50+
USE_DISTRIBUTED=0 WERROR=1 python setup.py bdist_wheel
51+
}
52+
4353
compile_x86_64() {
4454
USE_DISTRIBUTED=0 WERROR=1 python setup.py bdist_wheel
4555
}
@@ -63,7 +73,11 @@ build_lite_interpreter() {
6373
}
6474

6575
if [[ ${BUILD_ENVIRONMENT} = *arm64* ]]; then
66-
cross_compile_arm64
76+
if [[ $(uname -m) == "arm64" ]]; then
77+
compile_arm64
78+
else
79+
cross_compile_arm64
80+
fi
6781
elif [[ ${BUILD_ENVIRONMENT} = *lite-interpreter* ]]; then
6882
export BUILD_LITE_INTERPRETER=1
6983
build_lite_interpreter

.github/workflows/mac-mps.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
with:
1818
sync-tag: macos-12-py3-arm64-build
1919
build-environment: macos-12-py3-arm64
20-
xcode-version: "13.3.1"
21-
runner-type: macos-12-xl
20+
runner-type: macos-m1-12
2221
build-generates-artifacts: true
2322
# To match the one pre-installed in the m1 runners
2423
python_version: 3.9.12

.github/workflows/trunk.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ jobs:
200200
with:
201201
sync-tag: macos-12-py3-arm64-build
202202
build-environment: macos-12-py3-arm64
203-
xcode-version: "13.3.1"
204-
runner-type: macos-12-xl
203+
runner-type: macos-m1-12
205204
build-generates-artifacts: true
206205
# To match the one pre-installed in the m1 runners
207206
python_version: 3.9.12

cmake/Metal.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ if(NOT DEFINED CMAKE_OSX_DEVELOPER_ROOT)
1919
set(CMAKE_OSX_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
2020
elseif(EXISTS ${XCODE_PRE_43_ROOT})
2121
set(CMAKE_OSX_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
22-
endif(EXISTS ${XCODE_POST_43_ROOT})
22+
elseif(EXISTS ${CMAKE_XCODE_DEVELOPER_DIR} AND ${CMAKE_XCODE_DEVELOPER_DIR} STREQUAL "/Library/Developer/CommandLineTools")
23+
set(CMAKE_OSX_DEVELOPER_ROOT ${CMAKE_XCODE_DEVELOPER_DIR})
24+
endif()
2325
endif(NOT DEFINED CMAKE_OSX_DEVELOPER_ROOT)
2426
set(CMAKE_OSX_DEVELOPER_ROOT ${CMAKE_OSX_DEVELOPER_ROOT} CACHE PATH "Location of OSX SDKs root directory")
2527

0 commit comments

Comments
 (0)