Skip to content

Commit

Permalink
[iOS][CoreML] Check backend availability at runtime. (pytorch#65315)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#65315

ghstack-source-id: 138703808

Test Plan:
- OSS builds and BUCK builds
- CircleCI

Reviewed By: hanton

Differential Revision: D31048011

fbshipit-source-id: 824a8e32d65de2caf25e41efef2b022ddbb63156
  • Loading branch information
xta0 authored and facebook-github-bot committed Sep 22, 2021
1 parent 2898ef7 commit 1c20b98
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions torch/csrc/jit/backends/coreml/objc/PTMCoreMLBackend.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#import <CoreML/CoreML.h>

#if C10_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <Foundation/NSProcessInfo.h>
#endif

namespace torch {
namespace jit {
namespace mobile {
Expand Down Expand Up @@ -242,13 +248,18 @@ class API_AVAILABLE(ios(11.0), macos(10.13)) CoreMLBackend
bool is_available() override {
#if !defined(__APPLE__)
return false;
#else
if (@available(iOS 14, macOS 10.13, *)) {
#elif TARGET_OS_IPHONE
if ([UIDevice currentDevice].systemVersion.floatValue > 14.0) {
return true;
}
#elif TARGET_OS_MAC
NSOperatingSystemVersion supportedVer = {10, 13, 0};
if ([[NSProcessInfo processInfo]
isOperatingSystemAtLeastVersion:supportedVer]) {
return true;
} else {
return false;
}
#endif
return false;
}
};

Expand Down

0 comments on commit 1c20b98

Please sign in to comment.