[iOS][CoreML] Check backend availability at runtime. (#65315)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65315

ghstack-source-id: 138703808

Test Plan:
- OSS builds and BUCK builds
- CircleCI

Reviewed By: hanton

Differential Revision: D31048011

fbshipit-source-id: 824a8e32d65de2caf25e41efef2b022ddbb63156
This commit is contained in:
Tao Xu 2021-09-22 15:33:26 -07:00 committed by Facebook GitHub Bot
parent 2898ef7549
commit 1c20b98b4b

View File

@ -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 {
@ -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;
}
};