From bf1ea14fbc1bf796f7e233b9d43e15cb6d0705c0 Mon Sep 17 00:00:00 2001 From: Tao Xu Date: Thu, 22 Oct 2020 16:46:44 -0700 Subject: [PATCH] [CI][IOS] Add a arm64 ios job for Metal (#46646) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/46646 Test Plan: Imported from OSS Reviewed By: seemethere, linbinyu Differential Revision: D24459597 Pulled By: xta0 fbshipit-source-id: e93a3a26897614c66768804c71658928cd26ede7 --- .circleci/cimodel/data/simple/ios_definitions.py | 11 ++++++----- .circleci/config.yml | 15 +++++++++++++++ .../build-parameters/pytorch-build-params.yml | 4 ++++ .../job-specs/job-specs-custom.yml | 4 ++++ scripts/build_ios.sh | 6 +++++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.circleci/cimodel/data/simple/ios_definitions.py b/.circleci/cimodel/data/simple/ios_definitions.py index 9c9fd2ebccd..7af6e36300a 100644 --- a/.circleci/cimodel/data/simple/ios_definitions.py +++ b/.circleci/cimodel/data/simple/ios_definitions.py @@ -1,16 +1,16 @@ from cimodel.data.simple.util.versions import MultiPartVersion - +import cimodel.lib.miniutils as miniutils XCODE_VERSION = MultiPartVersion([12, 0, 0]) class ArchVariant: - def __init__(self, name, is_custom=False): + def __init__(self, name, custom_build_name=""): self.name = name - self.is_custom = is_custom + self.custom_build_name = custom_build_name def render(self): - extra_parts = ["custom"] if self.is_custom else [] + extra_parts = [self.custom_build_name] if len(self.custom_build_name) > 0 else [] return "_".join([self.name] + extra_parts) @@ -63,7 +63,8 @@ class IOSJob: WORKFLOW_DATA = [ IOSJob(XCODE_VERSION, ArchVariant("x86_64"), is_org_member_context=False), IOSJob(XCODE_VERSION, ArchVariant("arm64")), - IOSJob(XCODE_VERSION, ArchVariant("arm64", True), extra_props={"op_list": "mobilenetv2.yaml"}), + IOSJob(XCODE_VERSION, ArchVariant("arm64", "metal"), extra_props={"use_metal": miniutils.quote(str(int(True)))}), + IOSJob(XCODE_VERSION, ArchVariant("arm64", "custom"), extra_props={"op_list": "mobilenetv2.yaml"}), ] diff --git a/.circleci/config.yml b/.circleci/config.yml index d37f85f4d2c..2a8966a68f9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -302,11 +302,15 @@ pytorch_ios_params: &pytorch_ios_params op_list: type: string default: "" + use_metal: + type: string + default: "0" environment: BUILD_ENVIRONMENT: << parameters.build_environment >> IOS_ARCH: << parameters.ios_arch >> IOS_PLATFORM: << parameters.ios_platform >> SELECTED_OP_LIST: << parameters.op_list >> + USE_PYTORCH_METAL: << parameters.use_metal >> pytorch_windows_params: &pytorch_windows_params parameters: @@ -1584,6 +1588,7 @@ jobs: chmod a+x ${PROJ_ROOT}/scripts/build_ios.sh echo "IOS_ARCH: ${IOS_ARCH}" echo "IOS_PLATFORM: ${IOS_PLATFORM}" + echo "USE_PYTORCH_METAL": "${USE_METAL}" #check the custom build flag echo "SELECTED_OP_LIST: ${SELECTED_OP_LIST}" @@ -1592,6 +1597,9 @@ jobs: fi export IOS_ARCH=${IOS_ARCH} export IOS_PLATFORM=${IOS_PLATFORM} + if [ ${IOS_PLATFORM} != "SIMULATOR" ]; then + export USE_PYTORCH_METAL=${USE_METAL} + fi unbuffer ${PROJ_ROOT}/scripts/build_ios.sh 2>&1 | ts - run: name: Run Build Test @@ -6983,6 +6991,13 @@ workflows: ios_arch: arm64 ios_platform: OS name: pytorch_ios_12_0_0_arm64_build + - pytorch_ios_build: + build_environment: pytorch-ios-12.0.0-arm64_metal_build + context: org-member + ios_arch: arm64 + ios_platform: OS + name: pytorch_ios_12_0_0_arm64_metal_build + use_metal: "1" - pytorch_ios_build: build_environment: pytorch-ios-12.0.0-arm64_custom_build context: org-member diff --git a/.circleci/verbatim-sources/build-parameters/pytorch-build-params.yml b/.circleci/verbatim-sources/build-parameters/pytorch-build-params.yml index 41f72a1baa9..e031e01ba84 100644 --- a/.circleci/verbatim-sources/build-parameters/pytorch-build-params.yml +++ b/.circleci/verbatim-sources/build-parameters/pytorch-build-params.yml @@ -36,11 +36,15 @@ pytorch_ios_params: &pytorch_ios_params op_list: type: string default: "" + use_metal: + type: string + default: "0" environment: BUILD_ENVIRONMENT: << parameters.build_environment >> IOS_ARCH: << parameters.ios_arch >> IOS_PLATFORM: << parameters.ios_platform >> SELECTED_OP_LIST: << parameters.op_list >> + USE_PYTORCH_METAL: << parameters.use_metal >> pytorch_windows_params: &pytorch_windows_params parameters: diff --git a/.circleci/verbatim-sources/job-specs/job-specs-custom.yml b/.circleci/verbatim-sources/job-specs/job-specs-custom.yml index 6e5123ec934..aacb45f41a5 100644 --- a/.circleci/verbatim-sources/job-specs/job-specs-custom.yml +++ b/.circleci/verbatim-sources/job-specs/job-specs-custom.yml @@ -439,6 +439,7 @@ chmod a+x ${PROJ_ROOT}/scripts/build_ios.sh echo "IOS_ARCH: ${IOS_ARCH}" echo "IOS_PLATFORM: ${IOS_PLATFORM}" + echo "USE_PYTORCH_METAL": "${USE_METAL}" #check the custom build flag echo "SELECTED_OP_LIST: ${SELECTED_OP_LIST}" @@ -447,6 +448,9 @@ fi export IOS_ARCH=${IOS_ARCH} export IOS_PLATFORM=${IOS_PLATFORM} + if [ ${IOS_PLATFORM} != "SIMULATOR" ]; then + export USE_PYTORCH_METAL=${USE_METAL} + fi unbuffer ${PROJ_ROOT}/scripts/build_ios.sh 2>&1 | ts - run: name: Run Build Test diff --git a/scripts/build_ios.sh b/scripts/build_ios.sh index 387c588ff88..b4d77878282 100755 --- a/scripts/build_ios.sh +++ b/scripts/build_ios.sh @@ -92,9 +92,13 @@ CMAKE_ARGS+=("-DUSE_LEVELDB=OFF") CMAKE_ARGS+=("-DUSE_MPI=OFF") CMAKE_ARGS+=("-DUSE_NUMPY=OFF") CMAKE_ARGS+=("-DUSE_NNPACK=OFF") -CMAKE_ARGS+=("-DUSE_PYTORCH_METAL=OFF") CMAKE_ARGS+=("-DUSE_MKLDNN=OFF") +# Metal +if [ "${USE_PYTORCH_METAL:-}" == "1" ]; then + CMAKE_ARGS+=("-DUSE_PYTORCH_METAL=ON") +fi + # pthreads CMAKE_ARGS+=("-DCMAKE_THREAD_LIBS_INIT=-lpthread") CMAKE_ARGS+=("-DCMAKE_HAVE_THREADS_LIBRARY=1")