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
12 changes: 12 additions & 0 deletions extension/apple/Benchmark/App/App.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.developer.kernel.increased-memory-limit</key>
<true/>
</dict>
</plist>
16 changes: 16 additions & 0 deletions extension/apple/Benchmark/App/App.swift
Original file line number Diff line number Diff line change
@@ -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.
*/

import SwiftUI

@main
struct BenchmarkApp: App {
var body: some Scene {
WindowGroup {}
}
}
535 changes: 535 additions & 0 deletions extension/apple/Benchmark/Benchmark.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03B2D3632C8A515A0046936E"
BuildableName = "Benchmark.app"
BlueprintName = "App"
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:Tests/Tests.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03B2D3742C8A515C0046936E"
BuildableName = "Tests.xctest"
BlueprintName = "Tests"
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03B2D37E2C8A515C0046936E"
BuildableName = "BenchmarkUITests.xctest"
BlueprintName = "BenchmarkUITests"
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03B2D3632C8A515A0046936E"
BuildableName = "Benchmark.app"
BlueprintName = "App"
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03B2D3632C8A515A0046936E"
BuildableName = "Benchmark.app"
BlueprintName = "App"
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
105 changes: 105 additions & 0 deletions extension/apple/Benchmark/Tests/Tests.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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 <XCTest/XCTest.h>

#import <objc/runtime.h>

#import <executorch/extension/module/module.h>
#import <executorch/extension/tensor/tensor.h>

using namespace ::executorch::extension;
using namespace ::executorch::runtime;

@interface Tests : XCTestCase
@end

@implementation Tests

+ (void)initialize {
if (self == [Tests class]) {
NSString *modelsDir = [[NSBundle bundleForClass:[self class]].resourcePath
stringByAppendingPathComponent:@"Models"];
NSArray *models =
[NSFileManager.defaultManager contentsOfDirectoryAtPath:modelsDir
error:nil];
for (NSString *model in models) {
NSString *modelName = model.stringByDeletingPathExtension;
NSString *modelPath = [modelsDir stringByAppendingPathComponent:model];
XCTAssertGreaterThan(modelPath.length, 0);

SEL testLoadSelector = NSSelectorFromString(
[NSString stringWithFormat:@"test_load_%@", modelName]);
IMP testLoadImplementation = imp_implementationWithBlock(^(id _self) {
auto __block module = std::make_unique<Module>(modelPath.UTF8String);
[_self
measureWithMetrics:@[ [XCTClockMetric new], [XCTMemoryMetric new] ]
options:XCTMeasureOptions.defaultOptions
block:^{
XCTAssertEqual(module->load_method("forward"),
Error::Ok);
}];
});
class_addMethod(
[self class], testLoadSelector, testLoadImplementation, "v@:");

SEL testForwardSelector = NSSelectorFromString(
[NSString stringWithFormat:@"test_forward_%@", modelName]);
IMP testForwardImplementation = imp_implementationWithBlock(^(id _self) {
auto __block module = std::make_unique<Module>(modelPath.UTF8String);
XCTAssertEqual(module->load_method("forward"), Error::Ok);

const auto method_meta = module->method_meta("forward");
XCTAssertEqual(method_meta.error(), Error::Ok);

const auto num_inputs = method_meta->num_inputs();
XCTAssertGreaterThan(num_inputs, 0);

std::vector<std::vector<uint8_t>> buffers;
buffers.reserve(num_inputs);
std::vector<TensorPtr> tensors;
tensors.reserve(num_inputs);
std::vector<EValue> __block inputs;
inputs.reserve(num_inputs);

for (auto index = 0; index < num_inputs; ++index) {
auto input_tag = method_meta->input_tag(index);
XCTAssertEqual(input_tag.error(), Error::Ok);

switch (*input_tag) {
case Tag::Tensor: {
const auto tensor_meta = method_meta->input_tensor_meta(index);
XCTAssertEqual(tensor_meta.error(), Error::Ok);

const auto sizes = tensor_meta->sizes();
buffers.emplace_back(tensor_meta->nbytes(),
0b01010101); // Set all bytes to be non-zero.
tensors.emplace_back(from_blob(buffers.rbegin()->data(),
{sizes.begin(), sizes.end()},
tensor_meta->scalar_type()));
inputs.emplace_back(tensors.back());
} break;
default:
XCTFail("Unsupported tag %i at input %d", *input_tag, index);
}
}
[_self
measureWithMetrics:@[ [XCTClockMetric new], [XCTMemoryMetric new] ]
options:XCTMeasureOptions.defaultOptions
block:^{
XCTAssertEqual(module->forward(inputs).error(),
Error::Ok);
}];
});
class_addMethod(
[self class], testForwardSelector, testForwardImplementation, "v@:");
}
}
}

@end
26 changes: 26 additions & 0 deletions extension/apple/Benchmark/Tests/Tests.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
OTHER_LDFLAGS[sdk=iphonesimulator*] = $(inherited) \
-force_load $(BUILT_PRODUCTS_DIR)/libexecutorch-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_portable-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_custom-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_quantized-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_coreml-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_mps-simulator-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-simulator-release.a

OTHER_LDFLAGS[sdk=iphoneos*] = $(inherited) \
-force_load $(BUILT_PRODUCTS_DIR)/libexecutorch-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_portable-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_custom-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_quantized-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_coreml-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_mps-ios-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-ios-release.a

OTHER_LDFLAGS[sdk=macos*] = $(inherited) \
-force_load $(BUILT_PRODUCTS_DIR)/libexecutorch-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_portable-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_custom-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libkernels_quantized-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_coreml-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_mps-macos-release.a \
-force_load $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-macos-release.a
28 changes: 28 additions & 0 deletions extension/apple/Benchmark/Tests/Tests.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"configurations" : [
{
"id" : "0430A5ED-FD8D-444E-9933-740E01CCD53C",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"targetForVariableExpansion" : {
"containerPath" : "container:Benchmark.xcodeproj",
"identifier" : "03B2D3632C8A515A0046936E",
"name" : "App"
}
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:Benchmark.xcodeproj",
"identifier" : "03B2D3742C8A515C0046936E",
"name" : "Tests"
}
}
],
"version" : 1
}
Loading