From 964b9661b32debb6fcbc34995d10beec6f890d90 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Fri, 28 Feb 2025 00:25:52 -0800 Subject: [PATCH 1/4] Lay out ObjC/Swift bindings skeleton --- .../apple/ExecuTorch/Exported/ExecuTorch.h | 4 ++++ .../ExecuTorch/Exported/ExecuTorchError.h | 15 +++++++++++++ .../ExecuTorch/Exported/ExecuTorchError.m | 11 ++++++++++ .../ExecuTorch/Exported/ExecuTorchModule.h | 21 +++++++++++++++++++ .../ExecuTorch/Exported/ExecuTorchModule.mm | 20 ++++++++++++++++++ .../ExecuTorch/Exported/ExecuTorchTensor.h | 21 +++++++++++++++++++ .../ExecuTorch/Exported/ExecuTorchTensor.mm | 19 +++++++++++++++++ .../ExecuTorch/Exported/ExecuTorchValue.h | 18 ++++++++++++++++ .../ExecuTorch/Exported/ExecuTorchValue.m | 13 ++++++++++++ .../ExecuTorch/__tests__/ModuleTest.swift | 21 +++++++++++++++++++ .../ExecuTorch/__tests__/TensorTest.swift | 16 ++++++++++++++ .../ExecuTorch/__tests__/ValueTest.swift | 16 ++++++++++++++ 12 files changed, 195 insertions(+) create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchError.h create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchError.m create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchModule.h create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchValue.h create mode 100644 extension/apple/ExecuTorch/Exported/ExecuTorchValue.m create mode 100644 extension/apple/ExecuTorch/__tests__/ModuleTest.swift create mode 100644 extension/apple/ExecuTorch/__tests__/TensorTest.swift create mode 100644 extension/apple/ExecuTorch/__tests__/ValueTest.swift diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorch.h b/extension/apple/ExecuTorch/Exported/ExecuTorch.h index e16439714f2..3a12a5ddbae 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorch.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorch.h @@ -6,4 +6,8 @@ * LICENSE file in the root directory of this source tree. */ +#import "ExecuTorchError.h" #import "ExecuTorchLog.h" +#import "ExecuTorchModule.h" +#import "ExecuTorchTensor.h" +#import "ExecuTorchValue.h" diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchError.h b/extension/apple/ExecuTorch/Exported/ExecuTorchError.h new file mode 100644 index 00000000000..cdf52051d05 --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchError.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +FOUNDATION_EXPORT NSErrorDomain const ExecuTorchErrorDomain NS_SWIFT_NAME(ErrorDomain); + +NS_ASSUME_NONNULL_END diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchError.m b/extension/apple/ExecuTorch/Exported/ExecuTorchError.m new file mode 100644 index 00000000000..43996dc213e --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchError.m @@ -0,0 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchError.h" + +NSErrorDomain const ExecuTorchErrorDomain = @"org.pytorch.executorch.error"; diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h new file mode 100644 index 00000000000..af1c3e2d270 --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchValue.h" + +NS_ASSUME_NONNULL_BEGIN + +NS_SWIFT_NAME(Module) +@interface ExecuTorchModule : NSObject + ++ (instancetype)new NS_UNAVAILABLE; +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm new file mode 100644 index 00000000000..866dcc6901b --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm @@ -0,0 +1,20 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchModule.h" + +#import "ExecuTorchError.h" + +#import +#import + +@implementation ExecuTorchModule { + std::unique_ptr _module; +} + +@end diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h new file mode 100644 index 00000000000..10ed09b4507 --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +NS_SWIFT_NAME(Tensor) +@interface ExecuTorchTensor : NSObject + ++ (instancetype)new NS_UNAVAILABLE; +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm new file mode 100644 index 00000000000..4b072444bec --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchTensor.h" + +#import "ExecuTorchError.h" + +#import + +@implementation ExecuTorchTensor { + ::executorch::extension::TensorPtr _tensor; +} + +@end diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h new file mode 100644 index 00000000000..1d72079d6bb --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchTensor.h" + +NS_ASSUME_NONNULL_BEGIN + +NS_SWIFT_NAME(Value) +@interface ExecuTorchValue : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.m b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.m new file mode 100644 index 00000000000..98a6f774176 --- /dev/null +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.m @@ -0,0 +1,13 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "ExecuTorchValue.h" + +@implementation ExecuTorchValue + +@end diff --git a/extension/apple/ExecuTorch/__tests__/ModuleTest.swift b/extension/apple/ExecuTorch/__tests__/ModuleTest.swift new file mode 100644 index 00000000000..609727ec93f --- /dev/null +++ b/extension/apple/ExecuTorch/__tests__/ModuleTest.swift @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +@testable import ExecuTorch + +import XCTest + +class ModuleTest: XCTestCase { + func test() throws { + let bundle = Bundle(for: type(of: self)) + guard let modelPath = bundle.path(forResource: "add", ofType: "pte") else { + XCTFail("Couldn't find the model file") + return + } + } +} diff --git a/extension/apple/ExecuTorch/__tests__/TensorTest.swift b/extension/apple/ExecuTorch/__tests__/TensorTest.swift new file mode 100644 index 00000000000..f5c2ccdbeba --- /dev/null +++ b/extension/apple/ExecuTorch/__tests__/TensorTest.swift @@ -0,0 +1,16 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +@testable import ExecuTorch + +import XCTest + +class TensorTest: XCTestCase { + func test() { + } +} diff --git a/extension/apple/ExecuTorch/__tests__/ValueTest.swift b/extension/apple/ExecuTorch/__tests__/ValueTest.swift new file mode 100644 index 00000000000..56802ee540c --- /dev/null +++ b/extension/apple/ExecuTorch/__tests__/ValueTest.swift @@ -0,0 +1,16 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +@testable import ExecuTorch + +import XCTest + +class ValueTest: XCTestCase { + func test() { + } +} From cad870923cb1ec4e58c880be86b824ea16c5b239 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Fri, 28 Feb 2025 08:40:03 -0800 Subject: [PATCH 2/4] Add deprecation annotations --- extension/apple/ExecuTorch/Exported/ExecuTorchModule.h | 1 + extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h | 1 + extension/apple/ExecuTorch/Exported/ExecuTorchValue.h | 1 + 3 files changed, 3 insertions(+) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h index af1c3e2d270..ff1b22769ce 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +@available(*, message: "This API is experimental") NS_SWIFT_NAME(Module) @interface ExecuTorchModule : NSObject diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h index 10ed09b4507..1ad041bfa15 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +@available(*, message: "This API is experimental") NS_SWIFT_NAME(Tensor) @interface ExecuTorchTensor : NSObject diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index 1d72079d6bb..020ae44e749 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +@available(*, message: "This API is experimental") NS_SWIFT_NAME(Value) @interface ExecuTorchValue : NSObject From 81ba357be5573338e3254c9b564d2c355e608e6b Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Fri, 28 Feb 2025 09:06:42 -0800 Subject: [PATCH 3/4] Add deprecation annotations --- extension/apple/ExecuTorch/Exported/ExecuTorchModule.h | 2 +- extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h | 2 +- extension/apple/ExecuTorch/Exported/ExecuTorchValue.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h index ff1b22769ce..7d48c7a0882 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@available(*, message: "This API is experimental") +__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Module) @interface ExecuTorchModule : NSObject diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h index 1ad041bfa15..b4d5f56cf8f 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@available(*, message: "This API is experimental") +__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Tensor) @interface ExecuTorchTensor : NSObject diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index 020ae44e749..c7ce29ada73 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@available(*, message: "This API is experimental") +__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Value) @interface ExecuTorchValue : NSObject From 7833e70efb32bf96136d6472c59a95e952fec67f Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Fri, 28 Feb 2025 14:46:32 -0800 Subject: [PATCH 4/4] Add deprecation annotations --- extension/apple/ExecuTorch/Exported/ExecuTorchModule.h | 2 +- extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h | 2 +- extension/apple/ExecuTorch/Exported/ExecuTorchValue.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h index 7d48c7a0882..5e6e0ecaf47 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.h @@ -10,8 +10,8 @@ NS_ASSUME_NONNULL_BEGIN -__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Module) +__attribute__((deprecated("This API is experimental."))) @interface ExecuTorchModule : NSObject + (instancetype)new NS_UNAVAILABLE; diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h index b4d5f56cf8f..220e377b60d 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h @@ -10,8 +10,8 @@ NS_ASSUME_NONNULL_BEGIN -__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Tensor) +__attribute__((deprecated("This API is experimental."))) @interface ExecuTorchTensor : NSObject + (instancetype)new NS_UNAVAILABLE; diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index c7ce29ada73..9b2c8aaaae6 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -10,8 +10,8 @@ NS_ASSUME_NONNULL_BEGIN -__attribute__((deprecated("This API is experimental and may change without notice."))) NS_SWIFT_NAME(Value) +__attribute__((deprecated("This API is experimental."))) @interface ExecuTorchValue : NSObject @end