Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorch+Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,47 @@

@_exported import ExecuTorch

@available(*, deprecated, message: "This API is experimental.")
public extension TensorMetadata {
/// The size of each dimension.
var shape: [Int] { __shape.map(\.intValue) }

/// The layout order of each dimension.
var dimensionOrder: [Int] { __dimensionOrder.map(\.intValue) }
}

@available(*, deprecated, message: "This API is experimental.")
public extension MethodMetadata {
/// The declared input tags.
var inputValueTags: [ValueTag] {
__inputValueTags.map { ValueTag(rawValue: $0.uint32Value)! }
}

/// The declared output tags.
var outputValueTags: [ValueTag] {
__outputValueTags.map { ValueTag(rawValue: $0.uint32Value)! }
}

/// A dictionary mapping each input index to its `TensorMetadata`.
var inputTensorMetadata: [Int: TensorMetadata] {
Dictionary(uniqueKeysWithValues:
__inputTensorMetadata.map { (key, value) in (key.intValue, value) }
)
}

/// A dictionary mapping each output index to its `TensorMetadata`.
var outputTensorMetadata: [Int: TensorMetadata] {
Dictionary(uniqueKeysWithValues:
__outputTensorMetadata.map { (key, value) in (key.intValue, value) }
)
}

/// The sizes of all memory-planned buffers as a native Swift array of `Int`.
var memoryPlannedBufferSizes: [Int] {
__memoryPlannedBufferSizes.map(\.intValue)
}
}

@available(*, deprecated, message: "This API is experimental.")
public extension Module {
/// Executes a specific method with the provided input values.
Expand Down
23 changes: 15 additions & 8 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ __attribute__((deprecated("This API is experimental.")))
@interface ExecuTorchTensorMetadata : NSObject

/** The size of each dimension. */
@property (nonatomic, readonly) NSArray<NSNumber *> *shape;
@property (nonatomic, readonly) NSArray<NSNumber *> *shape
NS_REFINED_FOR_SWIFT;

/** The order in which dimensions are laid out. */
@property (nonatomic, readonly) NSArray<NSNumber *> *dimensionOrder;
@property (nonatomic, readonly) NSArray<NSNumber *> *dimensionOrder
NS_REFINED_FOR_SWIFT;

/** The scalar type of each element in the tensor. */
@property (nonatomic, readonly) ExecuTorchDataType dataType;
Expand Down Expand Up @@ -52,28 +54,33 @@ __attribute__((deprecated("This API is experimental.")))
@property (nonatomic, readonly) NSString *name;

/** An array of ExecuTorchValueTag raw values, one per declared input. */
@property (nonatomic, readonly) NSArray<NSNumber *> *inputValueTags;
@property (nonatomic, readonly) NSArray<NSNumber *> *inputValueTags
NS_REFINED_FOR_SWIFT;

/** An array of ExecuTorchValueTag raw values, one per declared output. */
@property (nonatomic, readonly) NSArray<NSNumber *> *outputValueTags;
@property (nonatomic, readonly) NSArray<NSNumber *> *outputValueTags
NS_REFINED_FOR_SWIFT;

/**
* Mapping from input-index to TensorMetadata.
* Only present for those indices whose tag == .tensor
*/
@property (nonatomic, readonly) NSDictionary<NSNumber *, ExecuTorchTensorMetadata *> *inputTensorMetadatas;
@property (nonatomic, readonly) NSDictionary<NSNumber *, ExecuTorchTensorMetadata *> *inputTensorMetadata
NS_REFINED_FOR_SWIFT;

/**
* Mapping from output-index to TensorMetadata.
* Only present for those indices whose tag == .tensor
*/
@property (nonatomic, readonly) NSDictionary<NSNumber *, ExecuTorchTensorMetadata *> *outputTensorMetadatas;
@property (nonatomic, readonly) NSDictionary<NSNumber *, ExecuTorchTensorMetadata *> *outputTensorMetadata
NS_REFINED_FOR_SWIFT;

/** A list of attribute TensorsMetadata. */
@property (nonatomic, readonly) NSArray<ExecuTorchTensorMetadata *> *attributeTensorMetadatas;
@property (nonatomic, readonly) NSArray<ExecuTorchTensorMetadata *> *attributeTensorMetadata;

/** A list of memory-planned buffer sizes. */
@property (nonatomic, readonly) NSArray<NSNumber *> *memoryPlannedBufferSizes;
@property (nonatomic, readonly) NSArray<NSNumber *> *memoryPlannedBufferSizes
NS_REFINED_FOR_SWIFT;

/** Names of all backends this method can run on. */
@property (nonatomic, readonly) NSArray<NSString *> *backendNames;
Expand Down
30 changes: 15 additions & 15 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ @implementation ExecuTorchMethodMetadata {
NSString *_name;
NSMutableArray<NSNumber *> *_inputValueTags;
NSMutableArray<NSNumber *> *_outputValueTags;
NSMutableDictionary<NSNumber *, ExecuTorchTensorMetadata *> *_inputTensorMetadatas;
NSMutableDictionary<NSNumber *, ExecuTorchTensorMetadata *> *_outputTensorMetadatas;
NSMutableArray<ExecuTorchTensorMetadata *> *_attributeTensorMetadatas;
NSMutableDictionary<NSNumber *, ExecuTorchTensorMetadata *> *_inputTensorMetadata;
NSMutableDictionary<NSNumber *, ExecuTorchTensorMetadata *> *_outputTensorMetadata;
NSMutableArray<ExecuTorchTensorMetadata *> *_attributeTensorMetadata;
NSMutableArray<NSNumber *> *_memoryPlannedBufferSizes;
NSMutableArray<NSString *> *_backendNames;
NSInteger _instructionCount;
Expand All @@ -127,9 +127,9 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
_instructionCount = methodMeta.num_instructions();
_inputValueTags = [[NSMutableArray alloc] initWithCapacity:inputCount];
_outputValueTags = [[NSMutableArray alloc] initWithCapacity:outputCount];
_inputTensorMetadatas = [NSMutableDictionary new];
_outputTensorMetadatas = [NSMutableDictionary new];
_attributeTensorMetadatas = [[NSMutableArray alloc] initWithCapacity:attributeCount];
_inputTensorMetadata = [NSMutableDictionary new];
_outputTensorMetadata = [NSMutableDictionary new];
_attributeTensorMetadata = [[NSMutableArray alloc] initWithCapacity:attributeCount];
_memoryPlannedBufferSizes = [[NSMutableArray alloc] initWithCapacity:memoryPlannedBufferCount];
_backendNames = [[NSMutableArray alloc] initWithCapacity:backendCount];

Expand All @@ -152,7 +152,7 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
}
return nil;
}
_inputTensorMetadatas[@(index)] = [[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:tensorMetadataResult.get()];
_inputTensorMetadata[@(index)] = [[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:tensorMetadataResult.get()];
}
}
for (NSInteger index = 0; index < outputCount; ++index) {
Expand All @@ -174,7 +174,7 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
}
return nil;
}
_outputTensorMetadatas[@(index)] = [[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:tensorMetadataResult.get()];
_outputTensorMetadata[@(index)] = [[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:tensorMetadataResult.get()];
}
}
for (NSInteger index = 0; index < attributeCount; ++index) {
Expand All @@ -185,7 +185,7 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
}
return nil;
}
[_attributeTensorMetadatas addObject:[[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:result.get()]];
[_attributeTensorMetadata addObject:[[ExecuTorchTensorMetadata alloc] initWithTensorMetadata:result.get()]];
}
for (NSInteger index = 0; index < memoryPlannedBufferCount; ++index) {
auto result = methodMeta.memory_planned_buffer_size(index);
Expand Down Expand Up @@ -221,16 +221,16 @@ - (nullable instancetype)initWithMethodMetadata:(const MethodMeta &)methodMeta
return _outputValueTags;
}

- (NSDictionary<NSNumber *,ExecuTorchTensorMetadata *> *)inputTensorMetadatas {
return _inputTensorMetadatas;
- (NSDictionary<NSNumber *,ExecuTorchTensorMetadata *> *)inputTensorMetadata {
return _inputTensorMetadata;
}

- (NSDictionary<NSNumber *,ExecuTorchTensorMetadata *> *)outputTensorMetadatas {
return _outputTensorMetadatas;
- (NSDictionary<NSNumber *,ExecuTorchTensorMetadata *> *)outputTensorMetadata {
return _outputTensorMetadata;
}

- (NSArray<ExecuTorchTensorMetadata *> *)attributeTensorMetadatas {
return _attributeTensorMetadatas;
- (NSArray<ExecuTorchTensorMetadata *> *)attributeTensorMetadata {
return _attributeTensorMetadata;
}

- (NSArray<NSNumber *> *)memoryPlannedBufferSizes {
Expand Down
14 changes: 7 additions & 7 deletions extension/apple/ExecuTorch/__tests__/ModuleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ class ModuleTest: XCTestCase {
XCTAssertEqual(methodMetadata.inputValueTags.count, 2)
XCTAssertEqual(methodMetadata.outputValueTags.count, 1)

XCTAssertEqual(ValueTag(rawValue: methodMetadata.inputValueTags[0].uint32Value), .tensor)
let inputTensorMetadata1 = methodMetadata.inputTensorMetadatas[0]
XCTAssertEqual(methodMetadata.inputValueTags[0], .tensor)
let inputTensorMetadata1 = methodMetadata.inputTensorMetadata[0]
XCTAssertEqual(inputTensorMetadata1?.shape, [1])
XCTAssertEqual(inputTensorMetadata1?.dimensionOrder, [0])
XCTAssertEqual(inputTensorMetadata1?.dataType, .float)
XCTAssertEqual(inputTensorMetadata1?.isMemoryPlanned, true)
XCTAssertEqual(inputTensorMetadata1?.name, "")

XCTAssertEqual(ValueTag(rawValue: methodMetadata.inputValueTags[1].uint32Value), .tensor)
let inputTensorMetadata2 = methodMetadata.inputTensorMetadatas[1]
XCTAssertEqual(methodMetadata.inputValueTags[1], .tensor)
let inputTensorMetadata2 = methodMetadata.inputTensorMetadata[1]
XCTAssertEqual(inputTensorMetadata2?.shape, [1])
XCTAssertEqual(inputTensorMetadata2?.dimensionOrder, [0])
XCTAssertEqual(inputTensorMetadata2?.dataType, .float)
XCTAssertEqual(inputTensorMetadata2?.isMemoryPlanned, true)
XCTAssertEqual(inputTensorMetadata2?.name, "")

XCTAssertEqual(ValueTag(rawValue: methodMetadata.outputValueTags[0].uint32Value), .tensor)
let outputTensorMetadata = methodMetadata.outputTensorMetadatas[0]
XCTAssertEqual(methodMetadata.outputValueTags[0], .tensor)
let outputTensorMetadata = methodMetadata.outputTensorMetadata[0]
XCTAssertEqual(outputTensorMetadata?.shape, [1])
XCTAssertEqual(outputTensorMetadata?.dimensionOrder, [0])
XCTAssertEqual(outputTensorMetadata?.dataType, .float)
XCTAssertEqual(outputTensorMetadata?.isMemoryPlanned, true)
XCTAssertEqual(outputTensorMetadata?.name, "")

XCTAssertEqual(methodMetadata.attributeTensorMetadatas.count, 0)
XCTAssertEqual(methodMetadata.attributeTensorMetadata.count, 0)
XCTAssertEqual(methodMetadata.memoryPlannedBufferSizes.count, 1)
XCTAssertEqual(methodMetadata.memoryPlannedBufferSizes[0], 48)
XCTAssertEqual(methodMetadata.backendNames.count, 0)
Expand Down
Loading