From b919949f9f3b5ffa207b98afe6dac6401f5413b4 Mon Sep 17 00:00:00 2001 From: jakmro Date: Tue, 25 Feb 2025 10:50:31 +0100 Subject: [PATCH 1/6] Add pre-commit code formatting --- lefthook.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lefthook.yml b/lefthook.yml index 30305336..4c9e1913 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -5,5 +5,17 @@ pre-commit: glob: '*.{js,ts,jsx,tsx}' run: npx eslint {staged_files} types: - glob: '*.{js,ts, jsx, tsx}' + glob: '*.{js,ts,jsx,tsx}' run: npx tsc --noEmit + format-js: + glob: '*.{js,ts,jsx,tsx}' + run: npx prettier --write {staged_files} && git add {staged_files} + format-objc: + glob: '*.{h,hpp,m,mm,c,cpp}' + run: clang-format -i {staged_files} && git add {staged_files} + format-kotlin: + glob: '*.{kt}' + run: ktlint -F {staged_files} && git add {staged_files} + format-other: + glob: '*.{json,yml,watchmanconfig,md,css}' + run: npx prettier --write {staged_files} && git add {staged_files} From 2c5db7e0f62ea3814eac59b83091b73fc184531d Mon Sep 17 00:00:00 2001 From: jakmro Date: Fri, 7 Mar 2025 18:40:08 +0100 Subject: [PATCH 2/6] Format code --- .github/ISSUE_TEMPLATE/bug-report.yml | 2 +- .github/ISSUE_TEMPLATE/feature-request.yml | 2 +- .github/pull_request_template.md | 10 +- .github/workflows/build-ios-llama-example.yml | 5 +- .github/workflows/docs-build-check.yml | 2 +- .watchmanconfig | 2 +- .yarnrc.yml | 4 +- .../swmansion/rnexecutorch/Classification.kt | 31 +- .../com/swmansion/rnexecutorch/ETModule.kt | 47 +- .../java/com/swmansion/rnexecutorch/LLM.kt | 30 +- .../java/com/swmansion/rnexecutorch/OCR.kt | 47 +- .../swmansion/rnexecutorch/ObjectDetection.kt | 39 +- .../rnexecutorch/RnExecutorchPackage.kt | 136 +- .../swmansion/rnexecutorch/SpeechToText.kt | 39 +- .../swmansion/rnexecutorch/StyleTransfer.kt | 24 +- .../com/swmansion/rnexecutorch/VerticalOCR.kt | 88 +- .../rnexecutorch/models/BaseModel.kt | 22 +- .../rnexecutorch/models/StyleTransferModel.kt | 12 +- .../classification/ClassificationModel.kt | 13 +- .../models/classification/Constants.kt | 7 +- .../models/classification/Utils.kt | 10 +- .../objectDetection/SSDLiteLargeModel.kt | 31 +- .../rnexecutorch/models/ocr/Detector.kt | 62 +- .../models/ocr/RecognitionHandler.kt | 45 +- .../rnexecutorch/models/ocr/Recognizer.kt | 15 +- .../models/ocr/VerticalDetector.kt | 66 +- .../models/ocr/utils/CTCLabelConverter.kt | 7 +- .../models/ocr/utils/DetectorUtils.kt | 193 +- .../models/ocr/utils/RecognizerUtils.kt | 80 +- .../models/speechToText/BaseS2TDecoder.kt | 11 +- .../models/speechToText/BaseS2TModule.kt | 22 +- .../models/speechToText/Moonshine.kt | 7 +- .../models/speechToText/MoonshineDecoder.kt | 14 +- .../models/speechToText/MoonshineEncoder.kt | 20 +- .../models/speechToText/Whisper.kt | 7 +- .../models/speechToText/WhisperDecoder.kt | 13 +- .../models/speechToText/WhisperEncoder.kt | 14 +- .../rnexecutorch/utils/ArrayUtils.kt | 37 +- .../swmansion/rnexecutorch/utils/ETError.kt | 50 +- .../rnexecutorch/utils/ImageProcessor.kt | 98 +- .../utils/ObjectDetectionUtils.kt | 21 +- .../utils/ProgressResponseBody.kt | 33 +- .../com/swmansion/rnexecutorch/utils/STFT.kt | 98 +- .../rnexecutorch/utils/TensorUtils.kt | 10 +- .../utils/llms/ConversationManager.kt | 37 +- docs/docs/fundamentals/getting-started.md | 2 +- docs/docs/speech-to-text/useSpeechToText.md | 4 +- .../FooterBackground/styles.module.css | 4 +- .../Hero/StartScreen/styles.module.css | 2 +- .../HomepageButton/styles.module.css | 4 +- .../components/Wave/WaveTop/styles.module.css | 2 +- docs/src/css/colors.css | 72 +- docs/src/pages/styles.module.css | 4 +- .../src/theme/MDXComponents/styles.module.css | 94 +- docs/src/theme/TOCItems/styles.module.css | 2 +- .../anonymous/computervision/MainActivity.kt | 50 +- .../computervision/MainApplication.kt | 46 +- .../ios/computervision/AppDelegate.h | 2 +- .../ios/computervision/AppDelegate.mm | 77 +- .../AppIcon.appiconset/Contents.json | 2 +- .../Images.xcassets/Contents.json | 6 +- .../Contents.json | 2 +- .../SplashScreenLogo.imageset/Contents.json | 2 +- .../computervision-Bridging-Header.h | 3 +- .../computer-vision/ios/computervision/main.m | 6 +- .../java/com/anonymous/llama/MainActivity.kt | 50 +- .../com/anonymous/llama/MainApplication.kt | 46 +- examples/llama/ios/llama/AppDelegate.h | 2 +- examples/llama/ios/llama/AppDelegate.mm | 77 +- .../AppIcon.appiconset/Contents.json | 2 +- .../ios/llama/Images.xcassets/Contents.json | 6 +- .../Contents.json | 2 +- .../SplashScreenLogo.imageset/Contents.json | 2 +- .../llama/ios/llama/llama-Bridging-Header.h | 3 +- examples/llama/ios/llama/main.m | 6 +- .../anonymous/speechtotext/MainActivity.kt | 50 +- .../anonymous/speechtotext/MainApplication.kt | 46 +- .../ios/speechtotext/AppDelegate.h | 2 +- .../ios/speechtotext/AppDelegate.mm | 77 +- .../AppIcon.appiconset/Contents.json | 2 +- .../Images.xcassets/Contents.json | 6 +- .../Contents.json | 2 +- .../SplashScreenLogo.imageset/Contents.json | 2 +- .../speech-to-text/ios/speechtotext/main.m | 6 +- .../speechtotext-Bridging-Header.h | 3 +- .../ExecutorchLib.framework/Headers/ETModel.h | 1 - .../Headers/LLaMARunner.h | 26 +- .../ExecutorchLib.framework/Headers/ETModel.h | 1 - .../Headers/LLaMARunner.h | 26 +- ios/RnExecutorch/SpeechToText.mm | 43 +- ios/RnExecutorch/VerticalOCR.mm | 189 +- ios/RnExecutorch/models/BaseModel.mm | 9 +- .../models/classification/Constants.mm | 2015 +++++++++-------- ios/RnExecutorch/models/ocr/Detector.mm | 2 +- .../models/ocr/RecognitionHandler.mm | 10 +- .../models/ocr/VerticalDetector.mm | 6 +- .../models/ocr/utils/CTCLabelConverter.mm | 2 +- .../models/ocr/utils/DetectorUtils.h | 12 +- .../models/ocr/utils/DetectorUtils.mm | 32 +- .../models/ocr/utils/RecognizerUtils.mm | 22 +- ios/RnExecutorch/models/stt/Moonshine.hpp | 6 +- ios/RnExecutorch/models/stt/Moonshine.mm | 37 +- .../models/stt/MoonshineDecoder.hpp | 5 +- .../models/stt/MoonshineDecoder.mm | 20 +- .../models/stt/MoonshineEncoder.hpp | 2 - .../models/stt/MoonshineEncoder.mm | 10 +- .../models/stt/SpeechToTextBaseModel.hpp | 15 +- .../models/stt/SpeechToTextBaseModel.mm | 11 +- ios/RnExecutorch/models/stt/Whisper.hpp | 3 +- ios/RnExecutorch/models/stt/Whisper.mm | 43 +- .../models/stt/WhisperDecoder.hpp | 5 +- ios/RnExecutorch/models/stt/WhisperDecoder.mm | 15 +- .../models/stt/WhisperEncoder.hpp | 2 - ios/RnExecutorch/models/stt/WhisperEncoder.mm | 6 +- ios/RnExecutorch/utils/ImageProcessor.mm | 24 +- ios/RnExecutorch/utils/SFFT.hpp | 8 +- ios/RnExecutorch/utils/ScalarType.h | 10 +- ios/RnExecutorch/utils/ScalarType.mm | 20 +- jitpack.yml | 4 +- .../ExecutorchLib/Exported/ETModel.h | 1 - .../ExecutorchLib/Exported/ETModel.mm | 45 +- .../ExecutorchLib/Exported/LLaMARunner.h | 26 +- .../ExecutorchLib/Exported/LLaMARunner.mm | 42 +- .../ios/ExecutorchLib/ExecutorchLib/Utils.hpp | 28 +- .../ExecutorchLib/model/Model.cpp | 8 +- .../ExecutorchLib/ExecutorchLib/model/Model.h | 8 +- .../ExecutorchLib/runner/runner.cpp | 128 +- .../ExecutorchLib/runner/runner.h | 23 +- .../ExecutorchLib/runner/stats.h | 67 +- .../runner/text_decoder_runner.cpp | 38 +- .../runner/text_decoder_runner.h | 65 +- .../ExecutorchLib/runner/text_prefiller.cpp | 27 +- .../ExecutorchLib/runner/text_prefiller.h | 17 +- .../runner/text_token_generator.h | 224 +- .../ExecutorchLib/ExecutorchLib/runner/util.h | 4 +- .../ExecutorchLib/sampler/sampler.cpp | 39 +- .../ExecutorchLib/sampler/sampler.h | 28 +- .../ExecutorchLib/tokenizer/base64.h | 45 +- .../ExecutorchLib/tokenizer/bpe_tokenizer.cpp | 61 +- .../ExecutorchLib/tokenizer/bpe_tokenizer.h | 17 +- .../tokenizer/llama_tiktoken.cpp | 55 +- .../ExecutorchLib/tokenizer/llama_tiktoken.h | 4 +- .../ExecutorchLib/tokenizer/tiktoken.cpp | 149 +- .../ExecutorchLib/tokenizer/tiktoken.h | 38 +- .../ExecutorchLib/tokenizer/tokenizer.h | 34 +- .../executorch/extension/module/module.h | 125 +- .../executorch/extension/tensor/tensor_ptr.h | 213 +- .../extension/tensor/tensor_ptr_maker.h | 232 +- .../backend/backend_execution_context.h | 26 +- .../runtime/backend/backend_init_context.h | 12 +- .../executorch/runtime/backend/interface.h | 30 +- .../executorch/runtime/core/array_ref.h | 87 +- .../executorch/runtime/core/data_loader.h | 23 +- .../Headers/executorch/runtime/core/error.h | 66 +- .../Headers/executorch/runtime/core/evalue.h | 161 +- .../executorch/runtime/core/event_tracer.h | 99 +- .../runtime/core/event_tracer_hooks.h | 68 +- .../core/event_tracer_hooks_delegate.h | 45 +- .../runtime/core/exec_aten/exec_aten.h | 77 +- .../core/exec_aten/util/dim_order_util.h | 76 +- .../core/exec_aten/util/scalar_type_util.h | 1301 +++++------ .../runtime/core/exec_aten/util/tensor_util.h | 959 ++++---- .../executorch/runtime/core/freeable_buffer.h | 55 +- .../runtime/core/hierarchical_allocator.h | 48 +- .../runtime/core/memory_allocator.h | 166 +- .../runtime/core/portable_type/bfloat16.h | 89 +- .../core/portable_type/bfloat16_math.h | 165 +- .../runtime/core/portable_type/complex.h | 6 +- .../runtime/core/portable_type/device.h | 10 +- .../runtime/core/portable_type/half.h | 300 +-- .../runtime/core/portable_type/optional.h | 53 +- .../runtime/core/portable_type/scalar.h | 35 +- .../runtime/core/portable_type/scalar_type.h | 48 +- .../runtime/core/portable_type/string_view.h | 291 ++- .../runtime/core/portable_type/tensor.h | 79 +- .../runtime/core/portable_type/tensor_impl.h | 83 +- .../Headers/executorch/runtime/core/result.h | 95 +- .../Headers/executorch/runtime/core/span.h | 41 +- .../Headers/executorch/runtime/core/tag.h | 24 +- .../runtime/executor/memory_manager.h | 44 +- .../executorch/runtime/executor/method.h | 115 +- .../executorch/runtime/executor/method_meta.h | 38 +- .../executorch/runtime/executor/program.h | 79 +- .../runtime/executor/tensor_parser.h | 38 +- .../runtime/kernel/kernel_runtime_context.h | 43 +- .../runtime/kernel/operator_registry.h | 96 +- .../executorch/runtime/platform/assert.h | 53 +- .../executorch/runtime/platform/compiler.h | 22 +- .../Headers/executorch/runtime/platform/log.h | 49 +- .../executorch/runtime/platform/platform.h | 20 +- .../executorch/runtime/platform/profiler.h | 103 +- .../executorch/runtime/platform/system.h | 6 +- .../executorch/schema/extended_header.h | 2 +- .../executorch/extension/module/module.h | 125 +- .../executorch/extension/tensor/tensor_ptr.h | 213 +- .../extension/tensor/tensor_ptr_maker.h | 232 +- .../backend/backend_execution_context.h | 26 +- .../runtime/backend/backend_init_context.h | 12 +- .../executorch/runtime/backend/interface.h | 30 +- .../executorch/runtime/core/array_ref.h | 87 +- .../executorch/runtime/core/data_loader.h | 23 +- .../Headers/executorch/runtime/core/error.h | 66 +- .../Headers/executorch/runtime/core/evalue.h | 161 +- .../executorch/runtime/core/event_tracer.h | 99 +- .../runtime/core/event_tracer_hooks.h | 68 +- .../core/event_tracer_hooks_delegate.h | 45 +- .../runtime/core/exec_aten/exec_aten.h | 77 +- .../core/exec_aten/util/dim_order_util.h | 76 +- .../core/exec_aten/util/scalar_type_util.h | 1301 +++++------ .../runtime/core/exec_aten/util/tensor_util.h | 959 ++++---- .../executorch/runtime/core/freeable_buffer.h | 55 +- .../runtime/core/hierarchical_allocator.h | 48 +- .../runtime/core/memory_allocator.h | 166 +- .../runtime/core/portable_type/bfloat16.h | 89 +- .../core/portable_type/bfloat16_math.h | 165 +- .../runtime/core/portable_type/complex.h | 6 +- .../runtime/core/portable_type/device.h | 10 +- .../runtime/core/portable_type/half.h | 300 +-- .../runtime/core/portable_type/optional.h | 53 +- .../runtime/core/portable_type/scalar.h | 35 +- .../runtime/core/portable_type/scalar_type.h | 48 +- .../runtime/core/portable_type/string_view.h | 291 ++- .../runtime/core/portable_type/tensor.h | 79 +- .../runtime/core/portable_type/tensor_impl.h | 83 +- .../Headers/executorch/runtime/core/result.h | 95 +- .../Headers/executorch/runtime/core/span.h | 41 +- .../Headers/executorch/runtime/core/tag.h | 24 +- .../runtime/executor/memory_manager.h | 44 +- .../executorch/runtime/executor/method.h | 115 +- .../executorch/runtime/executor/method_meta.h | 38 +- .../executorch/runtime/executor/program.h | 79 +- .../runtime/executor/tensor_parser.h | 38 +- .../runtime/kernel/kernel_runtime_context.h | 43 +- .../runtime/kernel/operator_registry.h | 96 +- .../executorch/runtime/platform/assert.h | 53 +- .../executorch/runtime/platform/compiler.h | 22 +- .../Headers/executorch/runtime/platform/log.h | 49 +- .../executorch/runtime/platform/platform.h | 20 +- .../executorch/runtime/platform/profiler.h | 103 +- .../executorch/runtime/platform/system.h | 6 +- .../executorch/schema/extended_header.h | 2 +- .../re2.framework/Headers/bitmap256.h | 16 +- .../re2.framework/Headers/filtered_re2.h | 45 +- .../re2.framework/Headers/pod_array.h | 36 +- .../re2.framework/Headers/prefilter.h | 58 +- .../re2.framework/Headers/prefilter_tree.h | 43 +- .../re2.framework/Headers/prog.h | 334 +-- .../re2.framework/Headers/re2.h | 373 ++- .../re2.framework/Headers/regexp.h | 361 +-- .../re2.framework/Headers/set.h | 36 +- .../re2.framework/Headers/sparse_array.h | 133 +- .../re2.framework/Headers/sparse_set.h | 79 +- .../re2.framework/Headers/stringpiece.h | 112 +- .../re2.framework/Headers/unicode_casefold.h | 10 +- .../re2.framework/Headers/unicode_groups.h | 17 +- .../re2.framework/Headers/walker-inl.h | 162 +- .../re2.framework/Headers/bitmap256.h | 16 +- .../re2.framework/Headers/filtered_re2.h | 45 +- .../re2.framework/Headers/pod_array.h | 36 +- .../re2.framework/Headers/prefilter.h | 58 +- .../re2.framework/Headers/prefilter_tree.h | 43 +- .../ios-arm64/re2.framework/Headers/prog.h | 334 +-- .../ios-arm64/re2.framework/Headers/re2.h | 373 ++- .../ios-arm64/re2.framework/Headers/regexp.h | 361 +-- .../ios-arm64/re2.framework/Headers/set.h | 36 +- .../re2.framework/Headers/sparse_array.h | 133 +- .../re2.framework/Headers/sparse_set.h | 79 +- .../re2.framework/Headers/stringpiece.h | 112 +- .../re2.framework/Headers/unicode_casefold.h | 10 +- .../re2.framework/Headers/unicode_groups.h | 17 +- .../re2.framework/Headers/walker-inl.h | 162 +- 271 files changed, 9949 insertions(+), 11677 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 1ae9402f..0a6bf08e 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -163,4 +163,4 @@ body: options: - 'Yes' validations: - required: true \ No newline at end of file + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index a72898d9..96b17718 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -47,4 +47,4 @@ body: description: > Add any other relevant context, code examples, or screenshots that should be considered. validations: - required: false \ No newline at end of file + required: false diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index b0a424a0..dd8e9152 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,30 +1,38 @@ ## Description + ### Type of change + - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on + - [ ] iOS - [ ] Android ### Testing instructions + ### Screenshots + ### Related issues + ### Checklist + - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [ ] My changes generate no new warnings ### Additional notes - \ No newline at end of file + + diff --git a/.github/workflows/build-ios-llama-example.yml b/.github/workflows/build-ios-llama-example.yml index ee371020..19ece36b 100644 --- a/.github/workflows/build-ios-llama-example.yml +++ b/.github/workflows/build-ios-llama-example.yml @@ -17,12 +17,12 @@ on: jobs: build: if: github.repository == 'software-mansion/react-native-executorch' - name: "Example app iOS build check" + name: 'Example app iOS build check' runs-on: macos-latest steps: - name: Check out Git repository uses: actions/checkout@v4 - + - name: Install node dependencies working-directory: examples/llama run: yarn @@ -42,4 +42,3 @@ jobs: -destination 'platform=iOS Simulator,name=iPhone 16 Pro' \ build \ CODE_SIGNING_ALLOWED=NO | xcbeautify - \ No newline at end of file diff --git a/.github/workflows/docs-build-check.yml b/.github/workflows/docs-build-check.yml index 41fcda6a..3c75c25e 100644 --- a/.github/workflows/docs-build-check.yml +++ b/.github/workflows/docs-build-check.yml @@ -31,4 +31,4 @@ jobs: run: mkdir -p .yarn/cache && yarn - name: Generate docs working-directory: ${{ env.WORKING_DIRECTORY }} - run: yarn build \ No newline at end of file + run: yarn build diff --git a/.watchmanconfig b/.watchmanconfig index 9e26dfee..0967ef42 100644 --- a/.watchmanconfig +++ b/.watchmanconfig @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/.yarnrc.yml b/.yarnrc.yml index 13215d63..5badb2e5 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -3,8 +3,8 @@ nmHoistingLimits: workspaces plugins: - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs - spec: "@yarnpkg/plugin-interactive-tools" + spec: '@yarnpkg/plugin-interactive-tools' - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs - spec: "@yarnpkg/plugin-workspace-tools" + spec: '@yarnpkg/plugin-workspace-tools' yarnPath: .yarn/releases/yarn-3.6.1.cjs diff --git a/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt b/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt index 3967a081..b371eb89 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt @@ -1,24 +1,25 @@ package com.swmansion.rnexecutorch import android.util.Log +import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.WritableMap import com.swmansion.rnexecutorch.models.classification.ClassificationModel import com.swmansion.rnexecutorch.utils.ETError import com.swmansion.rnexecutorch.utils.ImageProcessor import org.opencv.android.OpenCVLoader -import com.facebook.react.bridge.Arguments -import com.facebook.react.bridge.WritableMap - -class Classification(reactContext: ReactApplicationContext) : - NativeClassificationSpec(reactContext) { +class Classification( + reactContext: ReactApplicationContext, +) : NativeClassificationSpec(reactContext) { private lateinit var classificationModel: ClassificationModel companion object { const val NAME = "Classification" + init { - if(!OpenCVLoader.initLocal()){ + if (!OpenCVLoader.initLocal()) { Log.d("rn_executorch", "OpenCV not loaded") } else { Log.d("rn_executorch", "OpenCV loaded") @@ -26,7 +27,10 @@ class Classification(reactContext: ReactApplicationContext) : } } - override fun loadModule(modelSource: String, promise: Promise) { + override fun loadModule( + modelSource: String, + promise: Promise, + ) { try { classificationModel = ClassificationModel(reactApplicationContext) classificationModel.loadModel(modelSource) @@ -36,24 +40,25 @@ class Classification(reactContext: ReactApplicationContext) : } } - override fun forward(input: String, promise: Promise) { + override fun forward( + input: String, + promise: Promise, + ) { try { val image = ImageProcessor.readImage(input) val output = classificationModel.runModel(image) val writableMap: WritableMap = Arguments.createMap() - + for ((key, value) in output) { writableMap.putDouble(key, value.toDouble()) } promise.resolve(writableMap) - }catch(e: Exception){ + } catch (e: Exception) { promise.reject(e.message!!, e.message) } } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt b/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt index 929817e7..55fad74a 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt @@ -11,19 +11,26 @@ import org.pytorch.executorch.EValue import org.pytorch.executorch.Module import java.net.URL -class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(reactContext) { +class ETModule( + reactContext: ReactApplicationContext, +) : NativeETModuleSpec(reactContext) { private lateinit var module: Module - private var reactApplicationContext = reactContext; - override fun getName(): String { - return NAME - } + private var reactApplicationContext = reactContext + + override fun getName(): String = NAME - override fun loadModule(modelSource: String, promise: Promise) { + override fun loadModule( + modelSource: String, + promise: Promise, + ) { module = Module.load(URL(modelSource).path) promise.resolve(0) } - override fun loadMethod(methodName: String, promise: Promise) { + override fun loadMethod( + methodName: String, + promise: Promise, + ) { val result = module.loadMethod(methodName) if (result != 0) { promise.reject("Method loading failed", result.toString()) @@ -37,27 +44,30 @@ class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(react inputs: ReadableArray, shapes: ReadableArray, inputTypes: ReadableArray, - promise: Promise + promise: Promise, ) { val inputEValues = ArrayList() try { for (i in 0 until inputs.size()) { - val currentInput = inputs.getArray(i) - ?: throw Exception(ETError.InvalidArgument.code.toString()) - val currentShape = shapes.getArray(i) - ?: throw Exception(ETError.InvalidArgument.code.toString()) + val currentInput = + inputs.getArray(i) + ?: throw Exception(ETError.InvalidArgument.code.toString()) + val currentShape = + shapes.getArray(i) + ?: throw Exception(ETError.InvalidArgument.code.toString()) val currentInputType = inputTypes.getInt(i) - val currentEValue = TensorUtils.getExecutorchInput( - currentInput, - ArrayUtils.createLongArray(currentShape), - currentInputType - ) + val currentEValue = + TensorUtils.getExecutorchInput( + currentInput, + ArrayUtils.createLongArray(currentShape), + currentInputType, + ) inputEValues.add(currentEValue) } - val forwardOutputs = module.forward(*inputEValues.toTypedArray()); + val forwardOutputs = module.forward(*inputEValues.toTypedArray()) val outputArray = Arguments.createArray() for (output in forwardOutputs) { @@ -65,7 +75,6 @@ class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(react outputArray.pushArray(arr) } promise.resolve(outputArray) - } catch (e: IllegalArgumentException) { // The error is thrown when transformation to Tensor fails promise.reject("Forward Failed Execution", ETError.InvalidArgument.code.toString()) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt b/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt index 1626658e..6eba31ec 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt @@ -4,23 +4,23 @@ import android.util.Log import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableArray +import com.swmansion.rnexecutorch.utils.ArrayUtils import com.swmansion.rnexecutorch.utils.llms.ChatRole import com.swmansion.rnexecutorch.utils.llms.ConversationManager import com.swmansion.rnexecutorch.utils.llms.END_OF_TEXT_TOKEN import org.pytorch.executorch.LlamaCallback import org.pytorch.executorch.LlamaModule -import com.swmansion.rnexecutorch.utils.ArrayUtils import java.net.URL -class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext), LlamaCallback { - +class LLM( + reactContext: ReactApplicationContext, +) : NativeLLMSpec(reactContext), + LlamaCallback { private var llamaModule: LlamaModule? = null private var tempLlamaResponse = StringBuilder() private lateinit var conversationManager: ConversationManager - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME override fun initialize() { super.initialize() @@ -41,12 +41,15 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext), systemPrompt: String, messageHistory: ReadableArray, contextWindowLength: Double, - promise: Promise + promise: Promise, ) { try { - this.conversationManager = ConversationManager( - contextWindowLength.toInt(), systemPrompt, ArrayUtils.createMapArray(messageHistory) - ) + this.conversationManager = + ConversationManager( + contextWindowLength.toInt(), + systemPrompt, + ArrayUtils.createMapArray(messageHistory), + ) llamaModule = LlamaModule(1, URL(modelSource).path, URL(tokenizerSource).path, 0.7f) this.tempLlamaResponse.clear() promise.resolve("Model loaded successfully") @@ -55,7 +58,10 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext), } } - override fun runInference(input: String, promise: Promise) { + override fun runInference( + input: String, + promise: Promise, + ) { this.conversationManager.addResponse(input, ChatRole.USER) val conversation = this.conversationManager.getConversation() @@ -66,7 +72,7 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext), // generated sequence length is larger than specified in the JNI callback, hence we check if EOT // is there and if not, we append it to the output and emit the EOT token to the JS side. if (!this.tempLlamaResponse.endsWith(END_OF_TEXT_TOKEN)) { - this.onResult(END_OF_TEXT_TOKEN); + this.onResult(END_OF_TEXT_TOKEN) } // We want to add the LLM response to the conversation once all the tokens are generated. diff --git a/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt b/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt index 4f0b926b..b679d95d 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt @@ -3,17 +3,17 @@ package com.swmansion.rnexecutorch import android.util.Log import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext -import com.swmansion.rnexecutorch.utils.ETError -import com.swmansion.rnexecutorch.utils.ImageProcessor -import org.opencv.android.OpenCVLoader import com.swmansion.rnexecutorch.models.ocr.Detector import com.swmansion.rnexecutorch.models.ocr.RecognitionHandler import com.swmansion.rnexecutorch.models.ocr.utils.Constants +import com.swmansion.rnexecutorch.utils.ETError +import com.swmansion.rnexecutorch.utils.ImageProcessor +import org.opencv.android.OpenCVLoader import org.opencv.imgproc.Imgproc -class OCR(reactContext: ReactApplicationContext) : - NativeOCRSpec(reactContext) { - +class OCR( + reactContext: ReactApplicationContext, +) : NativeOCRSpec(reactContext) { private lateinit var detector: Detector private lateinit var recognitionHandler: RecognitionHandler @@ -35,21 +35,22 @@ class OCR(reactContext: ReactApplicationContext) : recognizerSourceMedium: String, recognizerSourceSmall: String, symbols: String, - promise: Promise + promise: Promise, ) { try { detector = Detector(reactApplicationContext) detector.loadModel(detectorSource) - recognitionHandler = RecognitionHandler( - symbols, - reactApplicationContext - ) + recognitionHandler = + RecognitionHandler( + symbols, + reactApplicationContext, + ) recognitionHandler.loadRecognizers( recognizerSourceLarge, recognizerSourceMedium, - recognizerSourceSmall + recognizerSourceSmall, ) { _, errorRecognizer -> if (errorRecognizer != null) { throw Error(errorRecognizer.message!!) @@ -62,18 +63,22 @@ class OCR(reactContext: ReactApplicationContext) : } } - override fun forward(input: String, promise: Promise) { + override fun forward( + input: String, + promise: Promise, + ) { try { val inputImage = ImageProcessor.readImage(input) val bBoxesList = detector.runModel(inputImage) val detectorSize = detector.getModelImageSize() Imgproc.cvtColor(inputImage, inputImage, Imgproc.COLOR_BGR2GRAY) - val result = recognitionHandler.recognize( - bBoxesList, - inputImage, - (detectorSize.width * Constants.RECOGNIZER_RATIO).toInt(), - (detectorSize.height * Constants.RECOGNIZER_RATIO).toInt() - ) + val result = + recognitionHandler.recognize( + bBoxesList, + inputImage, + (detectorSize.width * Constants.RECOGNIZER_RATIO).toInt(), + (detectorSize.height * Constants.RECOGNIZER_RATIO).toInt(), + ) promise.resolve(result) } catch (e: Exception) { Log.d("rn_executorch", "Error running model: ${e.message}") @@ -81,7 +86,5 @@ class OCR(reactContext: ReactApplicationContext) : } } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt b/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt index 54a34d5a..0c11e4f1 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt @@ -5,16 +5,14 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.WritableArray -import com.swmansion.rnexecutorch.models.BaseModel +import com.swmansion.rnexecutorch.models.objectdetection.SSDLiteLargeModel import com.swmansion.rnexecutorch.utils.ETError import com.swmansion.rnexecutorch.utils.ImageProcessor import org.opencv.android.OpenCVLoader -import com.swmansion.rnexecutorch.models.objectdetection.SSDLiteLargeModel -import org.opencv.core.Mat - -class ObjectDetection(reactContext: ReactApplicationContext) : - NativeObjectDetectionSpec(reactContext) { +class ObjectDetection( + reactContext: ReactApplicationContext, +) : NativeObjectDetectionSpec(reactContext) { private lateinit var ssdLiteLarge: SSDLiteLargeModel companion object { @@ -22,14 +20,17 @@ class ObjectDetection(reactContext: ReactApplicationContext) : } init { - if(!OpenCVLoader.initLocal()){ + if (!OpenCVLoader.initLocal()) { Log.d("rn_executorch", "OpenCV not loaded") } else { Log.d("rn_executorch", "OpenCV loaded") } } - override fun loadModule(modelSource: String, promise: Promise) { + override fun loadModule( + modelSource: String, + promise: Promise, + ) { try { ssdLiteLarge = SSDLiteLargeModel(reactApplicationContext) ssdLiteLarge.loadModel(modelSource) @@ -39,23 +40,25 @@ class ObjectDetection(reactContext: ReactApplicationContext) : } } - override fun forward(input: String, promise: Promise) { + override fun forward( + input: String, + promise: Promise, + ) { try { val inputImage = ImageProcessor.readImage(input) val output = ssdLiteLarge.runModel(inputImage) val outputWritableArray: WritableArray = Arguments.createArray() - output.map { detection -> - detection.toWritableMap() - }.forEach { writableMap -> - outputWritableArray.pushMap(writableMap) - } + output + .map { detection -> + detection.toWritableMap() + }.forEach { writableMap -> + outputWritableArray.pushMap(writableMap) + } promise.resolve(outputWritableArray) - } catch(e: Exception){ + } catch (e: Exception) { promise.reject(e.message!!, e.message) } } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt b/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt index 64f74661..c88e3870 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt @@ -8,11 +8,12 @@ import com.facebook.react.module.model.ReactModuleInfoProvider import com.facebook.react.uimanager.ViewManager class RnExecutorchPackage : TurboReactPackage() { - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf() - } + override fun createViewManagers(reactContext: ReactApplicationContext): List> = listOf() - override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = + override fun getModule( + name: String, + reactContext: ReactApplicationContext, + ): NativeModule? = if (name == LLM.NAME) { LLM(reactContext) } else if (name == ETModule.NAME) { @@ -33,66 +34,87 @@ class RnExecutorchPackage : TurboReactPackage() { null } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() - moduleInfos[LLM.NAME] = ReactModuleInfo( - LLM.NAME, - LLM.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true, - ) - moduleInfos[ETModule.NAME] = ReactModuleInfo( - ETModule.NAME, ETModule.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[LLM.NAME] = + ReactModuleInfo( + LLM.NAME, + LLM.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) + moduleInfos[ETModule.NAME] = + ReactModuleInfo( + ETModule.NAME, + ETModule.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[StyleTransfer.NAME] = ReactModuleInfo( - StyleTransfer.NAME, StyleTransfer.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[StyleTransfer.NAME] = + ReactModuleInfo( + StyleTransfer.NAME, + StyleTransfer.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[Classification.NAME] = ReactModuleInfo( - Classification.NAME, Classification.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[Classification.NAME] = + ReactModuleInfo( + Classification.NAME, + Classification.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[ObjectDetection.NAME] = ReactModuleInfo( - ObjectDetection.NAME, ObjectDetection.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[ObjectDetection.NAME] = + ReactModuleInfo( + ObjectDetection.NAME, + ObjectDetection.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[SpeechToText.NAME] = ReactModuleInfo( - SpeechToText.NAME, SpeechToText.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[SpeechToText.NAME] = + ReactModuleInfo( + SpeechToText.NAME, + SpeechToText.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[OCR.NAME] = ReactModuleInfo( - OCR.NAME, OCR.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[OCR.NAME] = + ReactModuleInfo( + OCR.NAME, + OCR.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) - moduleInfos[VerticalOCR.NAME] = ReactModuleInfo( - VerticalOCR.NAME, VerticalOCR.NAME, false, // canOverrideExistingModule - false, // needsEagerInit - false, // isCxxModule - true - ) + moduleInfos[VerticalOCR.NAME] = + ReactModuleInfo( + VerticalOCR.NAME, + VerticalOCR.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + false, // isCxxModule + true, + ) moduleInfos } - } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt b/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt index 91f31848..151fc856 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt @@ -14,27 +14,32 @@ import com.swmansion.rnexecutorch.utils.ArrayUtils import com.swmansion.rnexecutorch.utils.ArrayUtils.Companion.writableArrayToEValue import com.swmansion.rnexecutorch.utils.ETError -class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSpec(reactContext) { - - private lateinit var speechToTextModule: BaseS2TModule; +class SpeechToText( + reactContext: ReactApplicationContext, +) : NativeSpeechToTextSpec(reactContext) { + private lateinit var speechToTextModule: BaseS2TModule companion object { const val NAME = "SpeechToText" } - override fun loadModule(modelName: String, modelSources: ReadableArray, promise: Promise): Unit { + override fun loadModule( + modelName: String, + modelSources: ReadableArray, + promise: Promise, + ) { try { - if(modelName == "moonshine") { + if (modelName == "moonshine") { this.speechToTextModule = Moonshine() this.speechToTextModule.encoder = MoonshineEncoder(reactApplicationContext) this.speechToTextModule.decoder = MoonshineDecoder(reactApplicationContext) } - if(modelName == "whisper") { + if (modelName == "whisper") { this.speechToTextModule = Whisper() this.speechToTextModule.encoder = WhisperEncoder(reactApplicationContext) this.speechToTextModule.decoder = WhisperDecoder(reactApplicationContext) } - } catch(e: Exception){ + } catch (e: Exception) { promise.reject(e.message!!, ETError.InvalidModelSource.toString()) return } @@ -47,7 +52,10 @@ class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSp } } - override fun generate(waveform: ReadableArray, promise: Promise) { + override fun generate( + waveform: ReadableArray, + promise: Promise, + ) { val encoding = writableArrayToEValue(this.speechToTextModule.encode(waveform)) val generatedTokens = mutableListOf(this.speechToTextModule.START_TOKEN) var lastToken = 0 @@ -64,15 +72,20 @@ class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSp }.start() } - override fun encode(waveform: ReadableArray, promise: Promise) { + override fun encode( + waveform: ReadableArray, + promise: Promise, + ) { promise.resolve(this.speechToTextModule.encode(waveform)) } - override fun decode(prevTokens: ReadableArray, encoderOutput: ReadableArray, promise: Promise) { + override fun decode( + prevTokens: ReadableArray, + encoderOutput: ReadableArray, + promise: Promise, + ) { promise.resolve(this.speechToTextModule.decode(prevTokens, encoderOutput)) } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt b/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt index ed4e4a2b..54132b88 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt @@ -8,16 +8,16 @@ import com.swmansion.rnexecutorch.utils.ETError import com.swmansion.rnexecutorch.utils.ImageProcessor import org.opencv.android.OpenCVLoader -class StyleTransfer(reactContext: ReactApplicationContext) : - NativeStyleTransferSpec(reactContext) { - +class StyleTransfer( + reactContext: ReactApplicationContext, +) : NativeStyleTransferSpec(reactContext) { private lateinit var styleTransferModel: StyleTransferModel companion object { const val NAME = "StyleTransfer" init { - if(!OpenCVLoader.initLocal()){ + if (!OpenCVLoader.initLocal()) { Log.d("rn_executorch", "OpenCV not loaded") } else { Log.d("rn_executorch", "OpenCV loaded") @@ -25,7 +25,10 @@ class StyleTransfer(reactContext: ReactApplicationContext) : } } - override fun loadModule(modelSource: String, promise: Promise) { + override fun loadModule( + modelSource: String, + promise: Promise, + ) { try { styleTransferModel = StyleTransferModel(reactApplicationContext) styleTransferModel.loadModel(modelSource) @@ -35,16 +38,17 @@ class StyleTransfer(reactContext: ReactApplicationContext) : } } - override fun forward(input: String, promise: Promise) { + override fun forward( + input: String, + promise: Promise, + ) { try { val output = styleTransferModel.runModel(ImageProcessor.readImage(input)) promise.resolve(ImageProcessor.saveToTempFile(reactApplicationContext, output)) - }catch(e: Exception){ + } catch (e: Exception) { promise.reject(e.message!!, e.message) } } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt b/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt index 1b09d8f8..3e36b3ed 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt @@ -4,20 +4,20 @@ import android.util.Log import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext -import com.swmansion.rnexecutorch.utils.ETError -import com.swmansion.rnexecutorch.utils.ImageProcessor -import org.opencv.android.OpenCVLoader import com.swmansion.rnexecutorch.models.ocr.Recognizer import com.swmansion.rnexecutorch.models.ocr.VerticalDetector import com.swmansion.rnexecutorch.models.ocr.utils.CTCLabelConverter import com.swmansion.rnexecutorch.models.ocr.utils.Constants import com.swmansion.rnexecutorch.models.ocr.utils.RecognizerUtils +import com.swmansion.rnexecutorch.utils.ETError +import com.swmansion.rnexecutorch.utils.ImageProcessor +import org.opencv.android.OpenCVLoader import org.opencv.core.Core import org.opencv.core.Mat -class VerticalOCR(reactContext: ReactApplicationContext) : - NativeVerticalOCRSpec(reactContext) { - +class VerticalOCR( + reactContext: ReactApplicationContext, +) : NativeVerticalOCRSpec(reactContext) { private lateinit var detectorLarge: VerticalDetector private lateinit var detectorNarrow: VerticalDetector private lateinit var recognizer: Recognizer @@ -42,7 +42,7 @@ class VerticalOCR(reactContext: ReactApplicationContext) : recognizerSource: String, symbols: String, independentCharacters: Boolean, - promise: Promise + promise: Promise, ) { try { this.independentCharacters = independentCharacters @@ -61,16 +61,20 @@ class VerticalOCR(reactContext: ReactApplicationContext) : } } - override fun forward(input: String, promise: Promise) { + override fun forward( + input: String, + promise: Promise, + ) { try { val inputImage = ImageProcessor.readImage(input) val result = detectorLarge.runModel(inputImage) val largeDetectorSize = detectorLarge.getModelImageSize() - val resizedImage = ImageProcessor.resizeWithPadding( - inputImage, - largeDetectorSize.width.toInt(), - largeDetectorSize.height.toInt() - ) + val resizedImage = + ImageProcessor.resizeWithPadding( + inputImage, + largeDetectorSize.width.toInt(), + largeDetectorSize.height.toInt(), + ) val predictions = Arguments.createArray() for (box in result) { val cords = box.bBox @@ -80,12 +84,13 @@ class VerticalOCR(reactContext: ReactApplicationContext) : val boundingBox = RecognizerUtils.extractBoundingBox(cords) val croppedImage = Mat(resizedImage, boundingBox) - val paddings = RecognizerUtils.calculateResizeRatioAndPaddings( - inputImage.width(), - inputImage.height(), - largeDetectorSize.width.toInt(), - largeDetectorSize.height.toInt() - ) + val paddings = + RecognizerUtils.calculateResizeRatioAndPaddings( + inputImage.width(), + inputImage.height(), + largeDetectorSize.width.toInt(), + largeDetectorSize.height.toInt(), + ) var text = "" var confidenceScore = 0.0 @@ -96,20 +101,22 @@ class VerticalOCR(reactContext: ReactApplicationContext) : for (characterBox in boxResult) { val boxCords = characterBox.bBox - val paddingsBox = RecognizerUtils.calculateResizeRatioAndPaddings( - boxWidth.toInt(), - boxHeight.toInt(), - narrowDetectorSize.width.toInt(), - narrowDetectorSize.height.toInt() - ) - - var croppedCharacter = RecognizerUtils.cropImageWithBoundingBox( - inputImage, - boxCords, - cords, - paddingsBox, - paddings - ) + val paddingsBox = + RecognizerUtils.calculateResizeRatioAndPaddings( + boxWidth.toInt(), + boxHeight.toInt(), + narrowDetectorSize.width.toInt(), + narrowDetectorSize.height.toInt(), + ) + + var croppedCharacter = + RecognizerUtils.cropImageWithBoundingBox( + inputImage, + boxCords, + cords, + paddingsBox, + paddings, + ) if (this.independentCharacters) { croppedCharacter = RecognizerUtils.cropSingleCharacter(croppedCharacter) @@ -129,11 +136,12 @@ class VerticalOCR(reactContext: ReactApplicationContext) : } else { var mergedCharacters = Mat() Core.hconcat(croppedCharacters, mergedCharacters) - mergedCharacters = ImageProcessor.resizeWithPadding( - mergedCharacters, - Constants.LARGE_MODEL_WIDTH, - Constants.MODEL_HEIGHT - ) + mergedCharacters = + ImageProcessor.resizeWithPadding( + mergedCharacters, + Constants.LARGE_MODEL_WIDTH, + Constants.MODEL_HEIGHT, + ) mergedCharacters = RecognizerUtils.normalizeForRecognizer(mergedCharacters, 0.0) val recognitionResult = recognizer.runModel(mergedCharacters) @@ -167,7 +175,5 @@ class VerticalOCR(reactContext: ReactApplicationContext) : } } - override fun getName(): String { - return NAME - } + override fun getName(): String = NAME } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt index 28e661b1..c37a385f 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt @@ -7,8 +7,9 @@ import org.pytorch.executorch.Module import org.pytorch.executorch.Tensor import java.net.URL - -abstract class BaseModel(val context: Context) { +abstract class BaseModel( + val context: Context, +) { protected lateinit var module: Module fun loadModel(modelSource: String) { @@ -20,22 +21,27 @@ abstract class BaseModel(val context: Context) { val result = module.forward(input) return result } catch (e: IllegalArgumentException) { - //The error is thrown when transformation to Tensor fails + // The error is thrown when transformation to Tensor fails throw Error(ETError.InvalidArgument.code.toString()) } catch (e: Exception) { throw Error(e.message) } } - protected fun forward(inputs: Array, shapes: Array) : Array { - return this.execute("forward", inputs, shapes); - } + protected fun forward( + inputs: Array, + shapes: Array, + ): Array = this.execute("forward", inputs, shapes) - protected fun execute(methodName: String, inputs: Array, shapes: Array) : Array { + protected fun execute( + methodName: String, + inputs: Array, + shapes: Array, + ): Array { // We want to convert each input to EValue, a data structure accepted by ExecuTorch's // Module. The array below keeps track of that values. try { - val executorchInputs = inputs.mapIndexed { index, _ -> EValue.from(Tensor.fromBlob(inputs[index], shapes[index]))} + val executorchInputs = inputs.mapIndexed { index, _ -> EValue.from(Tensor.fromBlob(inputs[index], shapes[index])) } val forwardResult = module.execute(methodName, *executorchInputs.toTypedArray()) return forwardResult } catch (e: IllegalArgumentException) { diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt index 0a3dfee7..4e652dc5 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt @@ -5,11 +5,11 @@ import com.swmansion.rnexecutorch.utils.ImageProcessor import org.opencv.core.Mat import org.opencv.core.Size import org.opencv.imgproc.Imgproc -import org.pytorch.executorch.Tensor import org.pytorch.executorch.EValue - -class StyleTransferModel(reactApplicationContext: ReactApplicationContext) : BaseModel(reactApplicationContext) { +class StyleTransferModel( + reactApplicationContext: ReactApplicationContext, +) : BaseModel(reactApplicationContext) { private lateinit var originalSize: Size private fun getModelImageSize(): Size { @@ -35,8 +35,8 @@ class StyleTransferModel(reactApplicationContext: ReactApplicationContext) : Bas } override fun runModel(input: Mat): Mat { - val modelInput = preprocess(input) - val modelOutput = forward(modelInput) - return postprocess(modelOutput) + val modelInput = preprocess(input) + val modelOutput = forward(modelInput) + return postprocess(modelOutput) } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt index 64443801..132e7e9f 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt @@ -1,15 +1,16 @@ package com.swmansion.rnexecutorch.models.classification import com.facebook.react.bridge.ReactApplicationContext +import com.swmansion.rnexecutorch.models.BaseModel import com.swmansion.rnexecutorch.utils.ImageProcessor import org.opencv.core.Mat import org.opencv.core.Size import org.opencv.imgproc.Imgproc import org.pytorch.executorch.EValue -import com.swmansion.rnexecutorch.models.BaseModel - -class ClassificationModel(reactApplicationContext: ReactApplicationContext) : BaseModel>(reactApplicationContext) { +class ClassificationModel( + reactApplicationContext: ReactApplicationContext, +) : BaseModel>(reactApplicationContext) { private fun getModelImageSize(): Size { val inputShape = module.getInputShape(0) val width = inputShape[inputShape.lastIndex] @@ -37,8 +38,8 @@ class ClassificationModel(reactApplicationContext: ReactApplicationContext) : Ba } override fun runModel(input: Mat): Map { - val modelInput = preprocess(input) - val modelOutput = forward(modelInput) - return postprocess(modelOutput) + val modelInput = preprocess(input) + val modelOutput = forward(modelInput) + return postprocess(modelOutput) } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt index 49777b3d..7cebe4ad 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt @@ -1,6 +1,7 @@ package com.swmansion.rnexecutorch.models.classification -val imagenet1k_v1_labels: Array = arrayOf( +val imagenet1k_v1_labels: Array = + arrayOf( "tench, Tinca tinca", "goldfish, Carassius auratus", "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias", @@ -1000,5 +1001,5 @@ val imagenet1k_v1_labels: Array = arrayOf( "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa", "bolete", "ear, spike, capitulum", - "toilet tissue, toilet paper, bathroom tissue" -) + "toilet tissue, toilet paper, bathroom tissue", + ) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Utils.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Utils.kt index d40ba269..e919950a 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Utils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Utils.kt @@ -1,8 +1,8 @@ package com.swmansion.rnexecutorch.models.classification fun softmax(x: Array): Array { - val max = x.maxOrNull()!! - val exps = x.map { kotlin.math.exp(it - max) } - val sum = exps.sum() - return exps.map { it / sum }.toTypedArray() -} \ No newline at end of file + val max = x.maxOrNull()!! + val exps = x.map { kotlin.math.exp(it - max) } + val sum = exps.sum() + return exps.map { it / sum }.toTypedArray() +} diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt index f8c5748d..3969dfa3 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt @@ -1,21 +1,23 @@ package com.swmansion.rnexecutorch.models.objectdetection import com.facebook.react.bridge.ReactApplicationContext -import com.swmansion.rnexecutorch.utils.ImageProcessor -import org.opencv.core.Mat -import org.opencv.core.Size -import org.opencv.imgproc.Imgproc import com.swmansion.rnexecutorch.models.BaseModel import com.swmansion.rnexecutorch.utils.Bbox import com.swmansion.rnexecutorch.utils.CocoLabel import com.swmansion.rnexecutorch.utils.Detection +import com.swmansion.rnexecutorch.utils.ImageProcessor import com.swmansion.rnexecutorch.utils.nms +import org.opencv.core.Mat +import org.opencv.core.Size +import org.opencv.imgproc.Imgproc import org.pytorch.executorch.EValue const val detectionScoreThreshold = .7f const val iouThreshold = .55f -class SSDLiteLargeModel(reactApplicationContext: ReactApplicationContext) : BaseModel>(reactApplicationContext) { +class SSDLiteLargeModel( + reactApplicationContext: ReactApplicationContext, +) : BaseModel>(reactApplicationContext) { private var heightRatio: Float = 1.0f private var widthRatio: Float = 1.0f @@ -47,25 +49,26 @@ class SSDLiteLargeModel(reactApplicationContext: ReactApplicationContext) : Base val scores = scoresTensor.dataAsFloatArray val labels = output[2].toTensor().dataAsFloatArray - val detections: MutableList = mutableListOf(); + val detections: MutableList = mutableListOf() for (idx in 0 until numel.toInt()) { val score = scores[idx] if (score < detectionScoreThreshold) { continue } - val bbox = Bbox( - bboxes[idx * 4 + 0] * this.widthRatio, - bboxes[idx * 4 + 1] * this.heightRatio, - bboxes[idx * 4 + 2] * this.widthRatio, - bboxes[idx * 4 + 3] * this.heightRatio - ) + val bbox = + Bbox( + bboxes[idx * 4 + 0] * this.widthRatio, + bboxes[idx * 4 + 1] * this.heightRatio, + bboxes[idx * 4 + 2] * this.widthRatio, + bboxes[idx * 4 + 3] * this.heightRatio, + ) val label = labels[idx] detections.add( - Detection(bbox, score, CocoLabel.fromId(label.toInt())!!) + Detection(bbox, score, CocoLabel.fromId(label.toInt())!!), ) } - val detectionsPostNms = nms(detections, iouThreshold); + val detectionsPostNms = nms(detections, iouThreshold) return detectionsPostNms.toTypedArray() } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt index fb8e4329..d5736a2a 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt @@ -11,7 +11,7 @@ import org.opencv.core.Size import org.pytorch.executorch.EValue class Detector( - reactApplicationContext: ReactApplicationContext + reactApplicationContext: ReactApplicationContext, ) : BaseModel>(reactApplicationContext) { private lateinit var originalSize: Size @@ -27,12 +27,18 @@ class Detector( override fun preprocess(input: Mat): EValue { originalSize = Size(input.cols().toDouble(), input.rows().toDouble()) - val resizedImage = ImageProcessor.resizeWithPadding( - input, getModelImageSize().width.toInt(), getModelImageSize().height.toInt() - ) + val resizedImage = + ImageProcessor.resizeWithPadding( + input, + getModelImageSize().width.toInt(), + getModelImageSize().height.toInt(), + ) return ImageProcessor.matToEValue( - resizedImage, module.getInputShape(0), Constants.MEAN, Constants.VARIANCE + resizedImage, + module.getInputShape(0), + Constants.MEAN, + Constants.VARIANCE, ) } @@ -41,34 +47,36 @@ class Detector( val outputArray = outputTensor.dataAsFloatArray val modelImageSize = getModelImageSize() - val (scoreText, scoreLink) = DetectorUtils.interleavedArrayToMats( - outputArray, Size(modelImageSize.width / 2, modelImageSize.height / 2) - ) - var bBoxesList = DetectorUtils.getDetBoxesFromTextMap( - scoreText, - scoreLink, - Constants.TEXT_THRESHOLD, - Constants.LINK_THRESHOLD, - Constants.LOW_TEXT_THRESHOLD - ) + val (scoreText, scoreLink) = + DetectorUtils.interleavedArrayToMats( + outputArray, + Size(modelImageSize.width / 2, modelImageSize.height / 2), + ) + var bBoxesList = + DetectorUtils.getDetBoxesFromTextMap( + scoreText, + scoreLink, + Constants.TEXT_THRESHOLD, + Constants.LINK_THRESHOLD, + Constants.LOW_TEXT_THRESHOLD, + ) bBoxesList = DetectorUtils.restoreBoxRatio(bBoxesList, (Constants.RECOGNIZER_RATIO * 2).toFloat()) - bBoxesList = DetectorUtils.groupTextBoxes( - bBoxesList, - Constants.CENTER_THRESHOLD, - Constants.DISTANCE_THRESHOLD, - Constants.HEIGHT_THRESHOLD, - Constants.MIN_SIDE_THRESHOLD, - Constants.MAX_SIDE_THRESHOLD, - Constants.MAX_WIDTH - ) + bBoxesList = + DetectorUtils.groupTextBoxes( + bBoxesList, + Constants.CENTER_THRESHOLD, + Constants.DISTANCE_THRESHOLD, + Constants.HEIGHT_THRESHOLD, + Constants.MIN_SIDE_THRESHOLD, + Constants.MAX_SIDE_THRESHOLD, + Constants.MAX_WIDTH, + ) return bBoxesList.toList() } - override fun runModel(input: Mat): List { - return postprocess(forward(preprocess(input))) - } + override fun runModel(input: Mat): List = postprocess(forward(preprocess(input))) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt index 451445d8..356168d2 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt @@ -13,7 +13,7 @@ import org.opencv.core.Mat class RecognitionHandler( symbols: String, - reactApplicationContext: ReactApplicationContext + reactApplicationContext: ReactApplicationContext, ) { private val recognizerLarge = Recognizer(reactApplicationContext) private val recognizerMedium = Recognizer(reactApplicationContext) @@ -21,13 +21,14 @@ class RecognitionHandler( private val converter = CTCLabelConverter(symbols) private fun runModel(croppedImage: Mat): Pair, Double> { - val result: Pair, Double> = if (croppedImage.cols() >= Constants.LARGE_MODEL_WIDTH) { - recognizerLarge.runModel(croppedImage) - } else if (croppedImage.cols() >= Constants.MEDIUM_MODEL_WIDTH) { - recognizerMedium.runModel(croppedImage) - } else { - recognizerSmall.runModel(croppedImage) - } + val result: Pair, Double> = + if (croppedImage.cols() >= Constants.LARGE_MODEL_WIDTH) { + recognizerLarge.runModel(croppedImage) + } else if (croppedImage.cols() >= Constants.MEDIUM_MODEL_WIDTH) { + recognizerMedium.runModel(croppedImage) + } else { + recognizerSmall.runModel(croppedImage) + } return result } @@ -36,7 +37,7 @@ class RecognitionHandler( largeRecognizerPath: String, mediumRecognizerPath: String, smallRecognizerPath: String, - onComplete: (Int, Exception?) -> Unit + onComplete: (Int, Exception?) -> Unit, ) { try { recognizerLarge.loadModel(largeRecognizerPath) @@ -52,24 +53,26 @@ class RecognitionHandler( bBoxesList: List, imgGray: Mat, desiredWidth: Int, - desiredHeight: Int + desiredHeight: Int, ): WritableArray { val res: WritableArray = Arguments.createArray() - val ratioAndPadding = RecognizerUtils.calculateResizeRatioAndPaddings( - imgGray.width(), - imgGray.height(), - desiredWidth, - desiredHeight - ) + val ratioAndPadding = + RecognizerUtils.calculateResizeRatioAndPaddings( + imgGray.width(), + imgGray.height(), + desiredWidth, + desiredHeight, + ) val left = ratioAndPadding["left"] as Int val top = ratioAndPadding["top"] as Int val resizeRatio = ratioAndPadding["resizeRatio"] as Float - val resizedImg = ImageProcessor.resizeWithPadding( - imgGray, - desiredWidth, - desiredHeight - ) + val resizedImg = + ImageProcessor.resizeWithPadding( + imgGray, + desiredWidth, + desiredHeight, + ) for (box in bBoxesList) { var croppedImage = RecognizerUtils.getCroppedImage(box, resizedImg, Constants.MODEL_HEIGHT) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt index 2772cc4a..5e54fb3d 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt @@ -8,9 +8,9 @@ import org.opencv.core.Mat import org.opencv.core.Size import org.pytorch.executorch.EValue -class Recognizer(reactApplicationContext: ReactApplicationContext) : - BaseModel, Double>>(reactApplicationContext) { - +class Recognizer( + reactApplicationContext: ReactApplicationContext, +) : BaseModel, Double>>(reactApplicationContext) { private fun getModelOutputSize(): Size { val outputShape = module.getOutputShape(0) val width = outputShape[outputShape.lastIndex] @@ -19,9 +19,7 @@ class Recognizer(reactApplicationContext: ReactApplicationContext) : return Size(height.toDouble(), width.toDouble()) } - override fun preprocess(input: Mat): EValue { - return ImageProcessor.matToEValueGray(input) - } + override fun preprocess(input: Mat): EValue = ImageProcessor.matToEValueGray(input) override fun postprocess(output: Array): Pair, Double> { val modelOutputHeight = getModelOutputSize().height.toInt() @@ -49,8 +47,5 @@ class Recognizer(reactApplicationContext: ReactApplicationContext) : return Pair(indices, confidenceScore) } - - override fun runModel(input: Mat): Pair, Double> { - return postprocess(module.forward(preprocess(input))) - } + override fun runModel(input: Mat): Pair, Double> = postprocess(module.forward(preprocess(input))) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt index 15665256..90dd2602 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt @@ -12,9 +12,8 @@ import org.pytorch.executorch.EValue class VerticalDetector( private val detectSingleCharacter: Boolean, - reactApplicationContext: ReactApplicationContext -) : - BaseModel>(reactApplicationContext) { + reactApplicationContext: ReactApplicationContext, +) : BaseModel>(reactApplicationContext) { private lateinit var originalSize: Size fun getModelImageSize(): Size { @@ -29,17 +28,18 @@ class VerticalDetector( override fun preprocess(input: Mat): EValue { originalSize = Size(input.cols().toDouble(), input.rows().toDouble()) - val resizedImage = ImageProcessor.resizeWithPadding( - input, - getModelImageSize().width.toInt(), - getModelImageSize().height.toInt() - ) + val resizedImage = + ImageProcessor.resizeWithPadding( + input, + getModelImageSize().width.toInt(), + getModelImageSize().height.toInt(), + ) return ImageProcessor.matToEValue( resizedImage, module.getInputShape(0), Constants.MEAN, - Constants.VARIANCE + Constants.VARIANCE, ) } @@ -48,19 +48,21 @@ class VerticalDetector( val outputArray = outputTensor.dataAsFloatArray val modelImageSize = getModelImageSize() - val (scoreText, scoreLink) = DetectorUtils.interleavedArrayToMats( - outputArray, - Size(modelImageSize.width / 2, modelImageSize.height / 2) - ) + val (scoreText, scoreLink) = + DetectorUtils.interleavedArrayToMats( + outputArray, + Size(modelImageSize.width / 2, modelImageSize.height / 2), + ) val txtThreshold = if (detectSingleCharacter) Constants.TEXT_THRESHOLD else Constants.TEXT_THRESHOLD_VERTICAL - var bBoxesList = DetectorUtils.getDetBoxesFromTextMapVertical( - scoreText, - scoreLink, - txtThreshold, - Constants.LINK_THRESHOLD, - detectSingleCharacter - ) + var bBoxesList = + DetectorUtils.getDetBoxesFromTextMapVertical( + scoreText, + scoreLink, + txtThreshold, + Constants.LINK_THRESHOLD, + detectSingleCharacter, + ) bBoxesList = DetectorUtils.restoreBoxRatio(bBoxesList, (Constants.RESTORE_RATIO_VERTICAL).toFloat()) @@ -69,21 +71,19 @@ class VerticalDetector( return bBoxesList } - - bBoxesList = DetectorUtils.groupTextBoxes( - bBoxesList, - Constants.CENTER_THRESHOLD, - Constants.DISTANCE_THRESHOLD, - Constants.HEIGHT_THRESHOLD, - Constants.MIN_SIDE_THRESHOLD, - Constants.MAX_SIDE_THRESHOLD, - Constants.MAX_WIDTH - ) + bBoxesList = + DetectorUtils.groupTextBoxes( + bBoxesList, + Constants.CENTER_THRESHOLD, + Constants.DISTANCE_THRESHOLD, + Constants.HEIGHT_THRESHOLD, + Constants.MIN_SIDE_THRESHOLD, + Constants.MAX_SIDE_THRESHOLD, + Constants.MAX_WIDTH, + ) return bBoxesList.toList() } - override fun runModel(input: Mat): List { - return postprocess(forward(preprocess(input))) - } + override fun runModel(input: Mat): List = postprocess(forward(preprocess(input))) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt index 007e7e7c..b12538c2 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt @@ -1,7 +1,5 @@ package com.swmansion.rnexecutorch.models.ocr.utils -import java.io.File - class CTCLabelConverter( characters: String, ) { @@ -22,7 +20,10 @@ class CTCLabelConverter( ignoreIdx = ignoreIndexes.toList() } - fun decodeGreedy(textIndex: List, length: Int): List { + fun decodeGreedy( + textIndex: List, + length: Int, + ): List { val texts = mutableListOf() var index = 0 while (index < textIndex.size) { diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt index c6b5789a..7a0d5e9e 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt @@ -1,6 +1,5 @@ package com.swmansion.rnexecutorch.models.ocr.utils -import android.util.Log import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableArray import org.opencv.core.Core @@ -34,14 +33,18 @@ class DetectorUtils { return angle } - private fun midpoint(p1: BBoxPoint, p2: BBoxPoint): BBoxPoint { + private fun midpoint( + p1: BBoxPoint, + p2: BBoxPoint, + ): BBoxPoint { val midpoint = BBoxPoint((p1.x + p2.x) / 2, (p1.y + p2.y) / 2) return midpoint } - private fun distanceBetweenPoints(p1: BBoxPoint, p2: BBoxPoint): Double { - return sqrt((p1.x - p2.x).pow(2.0) + (p1.y - p2.y).pow(2.0)) - } + private fun distanceBetweenPoints( + p1: BBoxPoint, + p2: BBoxPoint, + ): Double = sqrt((p1.x - p2.x).pow(2.0) + (p1.y - p2.y).pow(2.0)) private fun centerOfBox(box: OCRbBox): BBoxPoint { val p1 = box.bBox[0] @@ -77,8 +80,10 @@ class DetectorUtils { return minSideLength } - - private fun calculateMinimalDistanceBetweenBoxes(box1: OCRbBox, box2: OCRbBox): Double { + private fun calculateMinimalDistanceBetweenBoxes( + box1: OCRbBox, + box2: OCRbBox, + ): Double { var minDistance = Double.MAX_VALUE for (i in 0 until 4) { for (j in 0 until 4) { @@ -92,16 +97,20 @@ class DetectorUtils { return minDistance } - private fun rotateBox(box: OCRbBox, angle: Double): OCRbBox { + private fun rotateBox( + box: OCRbBox, + angle: Double, + ): OCRbBox { val center = centerOfBox(box) val radians = angle * Math.PI / 180 - val newBBox = box.bBox.map { point -> - val translatedX = point.x - center.x - val translatedY = point.y - center.y - val rotatedX = translatedX * cos(radians) - translatedY * sin(radians) - val rotatedY = translatedX * sin(radians) + translatedY * cos(radians) - BBoxPoint(rotatedX + center.x, rotatedY + center.y) - } + val newBBox = + box.bBox.map { point -> + val translatedX = point.x - center.x + val translatedY = point.y - center.y + val rotatedX = translatedX * cos(radians) - translatedY * sin(radians) + val rotatedY = translatedX * sin(radians) + translatedY * cos(radians) + BBoxPoint(rotatedX + center.x, rotatedY + center.y) + } return OCRbBox(newBBox, box.angle) } @@ -140,7 +149,10 @@ class DetectorUtils { return OCRbBox(listOf(topLeft, topRight, bottomRight, bottomLeft), box.angle) } - private fun mergeRotatedBoxes(box1: OCRbBox, box2: OCRbBox): OCRbBox { + private fun mergeRotatedBoxes( + box1: OCRbBox, + box2: OCRbBox, + ): OCRbBox { val orderedBox1 = orderPointsClockwise(box1) val orderedBox2 = orderPointsClockwise(box2) @@ -171,11 +183,11 @@ class DetectorUtils { private fun removeSmallBoxes( boxes: MutableList, minSideThreshold: Int, - maxSideThreshold: Int - ): MutableList { - return boxes.filter { minSideLength(it) > minSideThreshold && maxSideLength(it) > maxSideThreshold } + maxSideThreshold: Int, + ): MutableList = + boxes + .filter { minSideLength(it) > minSideThreshold && maxSideLength(it) > maxSideThreshold } .toMutableList() - } private fun minimumYFromBox(box: List): Double = box.minOf { it.y } @@ -199,31 +211,42 @@ class DetectorUtils { val dx = abs(midpoint2.x - midpoint1.x) val line = MatOfFloat4() - val isVertical = if (dx < 20) { - for (point in arrayOf(midpoint1, midpoint2)) { - val temp = point.x - point.x = point.y - point.y = temp + val isVertical = + if (dx < 20) { + for (point in arrayOf(midpoint1, midpoint2)) { + val temp = point.x + point.x = point.y + point.y = temp + } + Imgproc.fitLine( + MatOfPoint2f( + Point(midpoint1.x, midpoint1.y), + Point(midpoint2.x, midpoint2.y), + ), + line, + Imgproc.DIST_L2, + 0.0, + 0.01, + 0.01, + ) + true + } else { + Imgproc.fitLine( + MatOfPoint2f( + Point(midpoint1.x, midpoint1.y), + Point(midpoint2.x, midpoint2.y), + ), + line, + Imgproc.DIST_L2, + 0.0, + 0.01, + 0.01, + ) + false } - Imgproc.fitLine( - MatOfPoint2f( - Point(midpoint1.x, midpoint1.y), - Point(midpoint2.x, midpoint2.y) - ), line, Imgproc.DIST_L2, 0.0, 0.01, 0.01 - ) - true - } else { - Imgproc.fitLine( - MatOfPoint2f( - Point(midpoint1.x, midpoint1.y), - Point(midpoint2.x, midpoint2.y) - ), line, Imgproc.DIST_L2, 0.0, 0.01, 0.01 - ) - false - } - val m = line.get(1, 0)[0] / line.get(0, 0)[0] // slope - val c = line.get(3, 0)[0] - m * line.get(2, 0)[0] // intercept + val m = line.get(1, 0)[0] / line.get(0, 0)[0] // slope + val c = line.get(3, 0)[0] - m * line.get(2, 0)[0] // intercept return LineInfo(m, c, isVertical) } @@ -234,7 +257,7 @@ class DetectorUtils { isVertical: Boolean, m: Double, c: Double, - centerThreshold: Double + centerThreshold: Double, ): Pair? { var smallestDistance = Double.MAX_VALUE var idx = -1 @@ -250,10 +273,12 @@ class DetectorUtils { return@forEachIndexed } boxHeight = minSideLength(box) - val lineDistance = if (isVertical) - abs(centerOfProcessedBox.x - (m * centerOfProcessedBox.y + c)) - else - abs(centerOfProcessedBox.y - (m * centerOfProcessedBox.x + c)) + val lineDistance = + if (isVertical) { + abs(centerOfProcessedBox.x - (m * centerOfProcessedBox.y + c)) + } else { + abs(centerOfProcessedBox.y - (m * centerOfProcessedBox.x + c)) + } if (lineDistance < boxHeight * centerThreshold) { idx = i @@ -264,7 +289,10 @@ class DetectorUtils { return if (idx == -1) null else Pair(idx, boxHeight) } - private fun createMaskFromLabels(labels: Mat, labelValue: Int): Mat { + private fun createMaskFromLabels( + labels: Mat, + labelValue: Int, + ): Mat { val mask = Mat.zeros(labels.size(), CvType.CV_8U) Core.compare(labels, Scalar(labelValue.toDouble()), mask, Core.CMP_EQ) @@ -272,7 +300,10 @@ class DetectorUtils { return mask } - fun interleavedArrayToMats(array: FloatArray, size: Size): Pair { + fun interleavedArrayToMats( + array: FloatArray, + size: Size, + ): Pair { val mat1 = Mat(size.height.toInt(), size.width.toInt(), CvType.CV_32F) val mat2 = Mat(size.height.toInt(), size.width.toInt(), CvType.CV_32F) @@ -294,7 +325,7 @@ class DetectorUtils { affinityMap: Mat, textThreshold: Double, linkThreshold: Double, - independentCharacters: Boolean + independentCharacters: Boolean, ): MutableList { val imgH = textMap.rows() val imgW = textMap.cols() @@ -304,10 +335,11 @@ class DetectorUtils { Imgproc.threshold(textMap, textScore, textThreshold, 1.0, Imgproc.THRESH_BINARY) Imgproc.threshold(affinityMap, affinityScore, linkThreshold, 1.0, Imgproc.THRESH_BINARY) val textScoreComb = Mat() - var kernel = Imgproc.getStructuringElement( - Imgproc.MORPH_RECT, - Size(3.0, 3.0) - ) + var kernel = + Imgproc.getStructuringElement( + Imgproc.MORPH_RECT, + Size(3.0, 3.0), + ) if (independentCharacters) { Core.subtract(textScore, affinityScore, textScoreComb) Imgproc.threshold(textScoreComb, textScoreComb, 0.0, 0.0, Imgproc.THRESH_TOZERO) @@ -353,10 +385,11 @@ class DetectorUtils { val sy = max(y - dilationRadius, 0) val ey = min(y + h + dilationRadius + 1, imgH) val roi = Rect(sx, sy, ex - sx, ey - sy) - kernel = Imgproc.getStructuringElement( - Imgproc.MORPH_RECT, - Size((1 + dilationRadius).toDouble(), (1 + dilationRadius).toDouble()) - ) + kernel = + Imgproc.getStructuringElement( + Imgproc.MORPH_RECT, + Size((1 + dilationRadius).toDouble(), (1 + dilationRadius).toDouble()), + ) val roiSegMap = Mat(segMap, roi) Imgproc.dilate(roiSegMap, roiSegMap, kernel, Point(-1.0, -1.0), 2) @@ -366,7 +399,7 @@ class DetectorUtils { contours, Mat(), Imgproc.RETR_EXTERNAL, - Imgproc.CHAIN_APPROX_SIMPLE + Imgproc.CHAIN_APPROX_SIMPLE, ) if (contours.isNotEmpty()) { val minRect = Imgproc.minAreaRect(MatOfPoint2f(*contours[0].toArray())) @@ -386,7 +419,7 @@ class DetectorUtils { affinityMap: Mat, textThreshold: Double, linkThreshold: Double, - lowTextThreshold: Double + lowTextThreshold: Double, ): MutableList { val imgH = textMap.rows() val imgW = textMap.cols() @@ -428,10 +461,11 @@ class DetectorUtils { val sy = max(y - dilationRadius, 0) val ey = min(y + h + dilationRadius + 1, imgH) val roi = Rect(sx, sy, ex - sx, ey - sy) - val kernel = Imgproc.getStructuringElement( - Imgproc.MORPH_RECT, - Size((1 + dilationRadius).toDouble(), (1 + dilationRadius).toDouble()) - ) + val kernel = + Imgproc.getStructuringElement( + Imgproc.MORPH_RECT, + Size((1 + dilationRadius).toDouble(), (1 + dilationRadius).toDouble()), + ) val roiSegMap = Mat(segMap, roi) Imgproc.dilate(roiSegMap, roiSegMap, kernel) @@ -441,7 +475,7 @@ class DetectorUtils { contours, Mat(), Imgproc.RETR_EXTERNAL, - Imgproc.CHAIN_APPROX_SIMPLE + Imgproc.CHAIN_APPROX_SIMPLE, ) if (contours.isNotEmpty()) { val minRect = Imgproc.minAreaRect(MatOfPoint2f(*contours[0].toArray())) @@ -456,7 +490,10 @@ class DetectorUtils { return detectedBoxes } - fun restoreBoxRatio(boxes: MutableList, restoreRatio: Float): MutableList { + fun restoreBoxRatio( + boxes: MutableList, + restoreRatio: Float, + ): MutableList { for (box in boxes) { for (b in box.bBox) { b.x *= restoreRatio @@ -474,7 +511,7 @@ class DetectorUtils { heightThreshold: Double, minSideThreshold: Int, maxSideThreshold: Int, - maxWidth: Int + maxWidth: Int, ): MutableList { boxes.sortByDescending { maxSideLength(it) } var mergedArray = mutableListOf() @@ -496,10 +533,16 @@ class DetectorUtils { lineAngle = -90.0 } - val closestBoxInfo = findClosestBox( - boxes, ignoredIds, currentBox, - isVertical, slope, intercept, centerThreshold - ) ?: break + val closestBoxInfo = + findClosestBox( + boxes, + ignoredIds, + currentBox, + isVertical, + slope, + intercept, + centerThreshold, + ) ?: break val candidateIdx = closestBoxInfo.first var candidateBox = boxes[candidateIdx] @@ -511,7 +554,9 @@ class DetectorUtils { val minDistance = calculateMinimalDistanceBetweenBoxes(candidateBox, currentBox) val mergedHeight = minSideLength(currentBox) - if (minDistance < distanceThreshold * candidateHeight && abs(mergedHeight - candidateHeight) < candidateHeight * heightThreshold) { + if (minDistance < distanceThreshold * candidateHeight && + abs(mergedHeight - candidateHeight) < candidateHeight * heightThreshold + ) { currentBox = mergeRotatedBoxes(currentBox, candidateBox) boxes.removeAt(candidateIdx) ignoredIds.clear() @@ -559,5 +604,5 @@ data class OCRbBox( data class LineInfo( val slope: Double, val intercept: Double, - val isVertical: Boolean + val isVertical: Boolean, ) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt index 1847e8ee..54a432b0 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt @@ -19,7 +19,10 @@ import kotlin.math.sqrt class RecognizerUtils { companion object { - private fun calculateRatio(width: Int, height: Int): Double { + private fun calculateRatio( + width: Int, + height: Int, + ): Double { var ratio = width.toDouble() / height.toDouble() if (ratio < 1.0) { ratio = 1.0 / ratio @@ -28,7 +31,10 @@ class RecognizerUtils { return ratio } - private fun findIntersection(r1: Rect, r2: Rect): Rect { + private fun findIntersection( + r1: Rect, + r2: Rect, + ): Rect { val aLeft = r1.x val aTop = r1.y val aRight = r1.x + r1.width @@ -51,7 +57,10 @@ class RecognizerUtils { } } - private fun adjustContrastGrey(img: Mat, target: Double): Mat { + private fun adjustContrastGrey( + img: Mat, + target: Double, + ): Mat { var high = 0 var low = 255 @@ -81,20 +90,33 @@ class RecognizerUtils { return img } - private fun computeRatioAndResize(img: Mat, width: Int, height: Int, modelHeight: Int): Mat { + private fun computeRatioAndResize( + img: Mat, + width: Int, + height: Int, + modelHeight: Int, + ): Mat { var ratio = width.toDouble() / height.toDouble() if (ratio < 1.0) { ratio = calculateRatio(width, height) Imgproc.resize( - img, img, Size(modelHeight.toDouble(), (modelHeight * ratio)), - 0.0, 0.0, Imgproc.INTER_LANCZOS4 + img, + img, + Size(modelHeight.toDouble(), (modelHeight * ratio)), + 0.0, + 0.0, + Imgproc.INTER_LANCZOS4, ) } else { Imgproc.resize( - img, img, Size((modelHeight * ratio), modelHeight.toDouble()), - 0.0, 0.0, Imgproc.INTER_LANCZOS4 + img, + img, + Size((modelHeight * ratio), modelHeight.toDouble()), + 0.0, + 0.0, + Imgproc.INTER_LANCZOS4, ) } @@ -122,7 +144,10 @@ class RecognizerUtils { return softmaxOutput } - fun sumProbabilityRows(probabilities: Mat, modelOutputHeight: Int): FloatArray { + fun sumProbabilityRows( + probabilities: Mat, + modelOutputHeight: Int, + ): FloatArray { val predsNorm = FloatArray(probabilities.rows()) for (i in 0 until probabilities.rows()) { @@ -136,7 +161,10 @@ class RecognizerUtils { return predsNorm } - fun divideMatrixByVector(matrix: Mat, vector: FloatArray): Mat { + fun divideMatrixByVector( + matrix: Mat, + vector: FloatArray, + ): Mat { for (i in 0 until matrix.rows()) { for (j in 0 until matrix.cols()) { val value = matrix.get(i, j)[0] / vector[i] @@ -162,7 +190,10 @@ class RecognizerUtils { return Pair(values, indices) } - fun computeConfidenceScore(valuesArray: DoubleArray, indicesArray: List): Double { + fun computeConfidenceScore( + valuesArray: DoubleArray, + indicesArray: List, + ): Double { val predsMaxProb = mutableListOf() for ((index, value) in indicesArray.withIndex()) { if (value != 0) predsMaxProb.add(valuesArray[index]) @@ -180,7 +211,7 @@ class RecognizerUtils { width: Int, height: Int, desiredWidth: Int, - desiredHeight: Int + desiredHeight: Int, ): Map { val newRatioH = desiredHeight.toFloat() / height val newRatioW = desiredWidth.toFloat() / width @@ -203,11 +234,15 @@ class RecognizerUtils { return mapOf( "resizeRatio" to resizeRatio, "top" to top, - "left" to left + "left" to left, ) } - fun getCroppedImage(box: OCRbBox, image: Mat, modelHeight: Int): Mat { + fun getCroppedImage( + box: OCRbBox, + image: Mat, + modelHeight: Int, + ): Mat { val cords = box.bBox val angle = box.angle val points = ArrayList() @@ -250,7 +285,7 @@ class RecognizerUtils { fun normalizeForRecognizer( image: Mat, adjustContrast: Double, - isVertical: Boolean = false + isVertical: Boolean = false, ): Mat { var img = image.clone() @@ -258,11 +293,12 @@ class RecognizerUtils { img = adjustContrastGrey(img, adjustContrast) } - val desiredWidth =when { - img.width() >= Constants.LARGE_MODEL_WIDTH -> Constants.LARGE_MODEL_WIDTH - img.width() >= Constants.MEDIUM_MODEL_WIDTH -> Constants.MEDIUM_MODEL_WIDTH - else -> if (isVertical) Constants.VERTICAL_SMALL_MODEL_WIDTH else Constants.SMALL_MODEL_WIDTH - } + val desiredWidth = + when { + img.width() >= Constants.LARGE_MODEL_WIDTH -> Constants.LARGE_MODEL_WIDTH + img.width() >= Constants.MEDIUM_MODEL_WIDTH -> Constants.MEDIUM_MODEL_WIDTH + else -> if (isVertical) Constants.VERTICAL_SMALL_MODEL_WIDTH else Constants.SMALL_MODEL_WIDTH + } img = ImageProcessor.resizeWithPadding(img, desiredWidth, Constants.MODEL_HEIGHT) img.convertTo(img, CvType.CV_32F, 1.0 / 255.0) @@ -277,7 +313,7 @@ class RecognizerUtils { box: List, originalBox: List, paddings: Map, - originalPaddings: Map + originalPaddings: Map, ): Mat { val topLeft = originalBox[0] val points = arrayOfNulls(4) @@ -333,7 +369,7 @@ class RecognizerUtils { Mat(), histogram, histSize, - range + range, ) val midPoint = 256 / 2 diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt index e8bf2256..9ba48918 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt @@ -1,13 +1,15 @@ package com.swmansion.rnexecutorch.models.speechtotext -import com.swmansion.rnexecutorch.models.BaseModel -import org.pytorch.executorch.EValue import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableArray +import com.swmansion.rnexecutorch.models.BaseModel import com.swmansion.rnexecutorch.utils.ArrayUtils.Companion.createFloatArray +import org.pytorch.executorch.EValue import org.pytorch.executorch.Tensor -abstract class BaseS2TDecoder(reactApplicationContext: ReactApplicationContext): BaseModel(reactApplicationContext) { +abstract class BaseS2TDecoder( + reactApplicationContext: ReactApplicationContext, +) : BaseModel(reactApplicationContext) { protected abstract var methodName: String abstract fun setGeneratedTokens(tokens: ReadableArray) @@ -19,7 +21,8 @@ abstract class BaseS2TDecoder(reactApplicationContext: ReactApplicationContext): return this.module .execute(methodName, tokensEValue, this.preprocess(input))[0] .toTensor() - .dataAsLongArray.last() + .dataAsLongArray + .last() .toInt() } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt index b1f43d4c..79788c3e 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt @@ -4,22 +4,24 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.WritableArray import com.swmansion.rnexecutorch.models.BaseModel - -abstract class BaseS2TModule() { +abstract class BaseS2TModule { lateinit var encoder: BaseModel lateinit var decoder: BaseS2TDecoder - abstract var START_TOKEN:Int - abstract var EOS_TOKEN:Int + abstract var START_TOKEN: Int + abstract var EOS_TOKEN: Int - fun encode(input: ReadableArray): WritableArray { - return this.encoder.runModel(input) - } + fun encode(input: ReadableArray): WritableArray = this.encoder.runModel(input) - abstract fun decode(prevTokens: ReadableArray, encoderOutput: ReadableArray): Int + abstract fun decode( + prevTokens: ReadableArray, + encoderOutput: ReadableArray, + ): Int - fun loadModel(encoderSource: String, decoderSource: String) { + fun loadModel( + encoderSource: String, + decoderSource: String, + ) { this.encoder.loadModel(encoderSource) this.decoder.loadModel(decoderSource) } - } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt index 14ba1813..87550f69 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt @@ -1,12 +1,15 @@ package com.swmansion.rnexecutorch.models.speechtotext import com.facebook.react.bridge.ReadableArray -import com.swmansion.rnexecutorch.utils.ArrayUtils class Moonshine : BaseS2TModule() { override var START_TOKEN = 1 override var EOS_TOKEN = 2 - override fun decode(prevTokens: ReadableArray, encoderOutput: ReadableArray): Int { + + override fun decode( + prevTokens: ReadableArray, + encoderOutput: ReadableArray, + ): Int { this.decoder.setGeneratedTokens(prevTokens) return this.decoder.runModel(encoderOutput) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt index f31d5f4b..649eef5c 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt @@ -6,9 +6,11 @@ import com.swmansion.rnexecutorch.utils.ArrayUtils import org.pytorch.executorch.EValue import org.pytorch.executorch.Tensor -class MoonshineDecoder(reactApplicationContext: ReactApplicationContext) : BaseS2TDecoder(reactApplicationContext) { +class MoonshineDecoder( + reactApplicationContext: ReactApplicationContext, +) : BaseS2TDecoder(reactApplicationContext) { private lateinit var generatedTokens: LongArray - private var innerDim: Long = 288; + private var innerDim: Long = 288 override var methodName: String get() = "forward_cached" @@ -18,11 +20,7 @@ class MoonshineDecoder(reactApplicationContext: ReactApplicationContext) : BaseS this.generatedTokens = ArrayUtils.createLongArray(tokens) } - override fun getTokensEValue(): EValue { - return EValue.from(Tensor.fromBlob(this.generatedTokens, longArrayOf(1, generatedTokens.size.toLong()))) - } + override fun getTokensEValue(): EValue = EValue.from(Tensor.fromBlob(this.generatedTokens, longArrayOf(1, generatedTokens.size.toLong()))) - override fun getInputShape(inputLength: Int): LongArray { - return longArrayOf(1, inputLength.toLong()/innerDim, innerDim) - } + override fun getInputShape(inputLength: Int): LongArray = longArrayOf(1, inputLength.toLong() / innerDim, innerDim) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt index 8dc32006..57b6d53e 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt @@ -9,12 +9,10 @@ import com.swmansion.rnexecutorch.utils.ArrayUtils.Companion.createFloatArray import org.pytorch.executorch.EValue import org.pytorch.executorch.Tensor -class MoonshineEncoder(reactApplicationContext: ReactApplicationContext) : - BaseModel(reactApplicationContext) { - - override fun runModel(input: ReadableArray): WritableArray { - return this.postprocess(this.module.forward(this.preprocess(input))) - } +class MoonshineEncoder( + reactApplicationContext: ReactApplicationContext, +) : BaseModel(reactApplicationContext) { + override fun runModel(input: ReadableArray): WritableArray = this.postprocess(this.module.forward(this.preprocess(input))) override fun preprocess(input: ReadableArray): EValue { val size = input.size() @@ -24,9 +22,11 @@ class MoonshineEncoder(reactApplicationContext: ReactApplicationContext) : public override fun postprocess(output: Array): WritableArray { val outputWritableArray: WritableArray = Arguments.createArray() - output[0].toTensor().dataAsFloatArray.map {outputWritableArray.pushDouble( - it.toDouble() - )} - return outputWritableArray; + output[0].toTensor().dataAsFloatArray.map { + outputWritableArray.pushDouble( + it.toDouble(), + ) + } + return outputWritableArray } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt index 24cab849..af07ea8c 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt @@ -1,12 +1,15 @@ package com.swmansion.rnexecutorch.models.speechtotext import com.facebook.react.bridge.ReadableArray -import com.swmansion.rnexecutorch.utils.ArrayUtils class Whisper : BaseS2TModule() { override var START_TOKEN = 50257 override var EOS_TOKEN = 50256 - override fun decode(prevTokens: ReadableArray, encoderOutput: ReadableArray): Int { + + override fun decode( + prevTokens: ReadableArray, + encoderOutput: ReadableArray, + ): Int { this.decoder.setGeneratedTokens(prevTokens) return this.decoder.runModel(encoderOutput) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt index e593a977..49370cfd 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt @@ -6,22 +6,19 @@ import com.swmansion.rnexecutorch.utils.ArrayUtils import org.pytorch.executorch.EValue import org.pytorch.executorch.Tensor -class WhisperDecoder(reactApplicationContext: ReactApplicationContext) : BaseS2TDecoder(reactApplicationContext) { +class WhisperDecoder( + reactApplicationContext: ReactApplicationContext, +) : BaseS2TDecoder(reactApplicationContext) { private lateinit var generatedTokens: IntArray override var methodName: String get() = "forward" set(value) {} - override fun setGeneratedTokens(tokens: ReadableArray) { this.generatedTokens = ArrayUtils.createIntArray(tokens) } - override fun getTokensEValue(): EValue { - return EValue.from(Tensor.fromBlob(this.generatedTokens, longArrayOf(1, generatedTokens.size.toLong()))) - } + override fun getTokensEValue(): EValue = EValue.from(Tensor.fromBlob(this.generatedTokens, longArrayOf(1, generatedTokens.size.toLong()))) - override fun getInputShape(inputLength: Int): LongArray { - return longArrayOf(1, 1500, 384) - } + override fun getInputShape(inputLength: Int): LongArray = longArrayOf(1, 1500, 384) } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt index 52f15c01..397d825f 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt @@ -1,19 +1,18 @@ package com.swmansion.rnexecutorch.models.speechtotext -import android.util.Log import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactApplicationContext -import com.swmansion.rnexecutorch.utils.ArrayUtils import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.WritableArray import com.swmansion.rnexecutorch.models.BaseModel +import com.swmansion.rnexecutorch.utils.ArrayUtils import com.swmansion.rnexecutorch.utils.STFT import org.pytorch.executorch.EValue import org.pytorch.executorch.Tensor -class WhisperEncoder(reactApplicationContext: ReactApplicationContext) : - BaseModel(reactApplicationContext) { - +class WhisperEncoder( + reactApplicationContext: ReactApplicationContext, +) : BaseModel(reactApplicationContext) { private val fftSize = 512 private val hopLength = 160 private val stftFrameSize = (this.fftSize / 2).toLong() @@ -39,8 +38,9 @@ class WhisperEncoder(reactApplicationContext: ReactApplicationContext) : output[0].toTensor().dataAsFloatArray.map { outputWritableArray.pushDouble( - it.toDouble() - )} + it.toDouble(), + ) + } return outputWritableArray } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt index 56651523..d55c187e 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt @@ -9,33 +9,28 @@ import org.pytorch.executorch.Tensor class ArrayUtils { companion object { - inline fun createTypedArrayFromReadableArray(input: ReadableArray, transform: (ReadableArray, Int) -> T): Array { - return Array(input.size()) { index -> transform(input, index) } - } + inline fun createTypedArrayFromReadableArray( + input: ReadableArray, + transform: (ReadableArray, Int) -> T, + ): Array = Array(input.size()) { index -> transform(input, index) } - fun createByteArray(input: ReadableArray): ByteArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toByte() }.toByteArray() - } + fun createByteArray(input: ReadableArray): ByteArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toByte() }.toByteArray() - fun createCharArray(input: ReadableArray): CharArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toChar() }.toCharArray() - } + fun createCharArray(input: ReadableArray): CharArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toChar() }.toCharArray() - fun createIntArray(input: ReadableArray): IntArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index) }.toIntArray() - } + fun createIntArray(input: ReadableArray): IntArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index) }.toIntArray() - fun createFloatArray(input: ReadableArray): FloatArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getDouble(index).toFloat() }.toFloatArray() - } + fun createFloatArray(input: ReadableArray): FloatArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getDouble(index).toFloat() }.toFloatArray() - fun createLongArray(input: ReadableArray): LongArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toLong() }.toLongArray() - } + fun createLongArray(input: ReadableArray): LongArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toLong() }.toLongArray() - fun createDoubleArray(input: ReadableArray): DoubleArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getDouble(index) }.toDoubleArray() - } + fun createDoubleArray(input: ReadableArray): DoubleArray = + createTypedArrayFromReadableArray(input) { array, index -> array.getDouble(index) }.toDoubleArray() fun createMapArray(input: ReadableArray): Array> { val mapArray = Array>(input.size()) { mapOf() } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt index ce335f13..f4cd62c6 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt @@ -1,32 +1,34 @@ package com.swmansion.rnexecutorch.utils -enum class ETError(val code: Int) { - UndefinedError(0x65), - ModuleNotLoaded(0x66), - FileWriteFailed(0x67), - InvalidModelSource(0xff), +enum class ETError( + val code: Int, +) { + UndefinedError(0x65), + ModuleNotLoaded(0x66), + FileWriteFailed(0x67), + InvalidModelSource(0xff), // System errors - Ok(0x00), - Internal(0x01), - InvalidState(0x02), - EndOfMethod(0x03), + Ok(0x00), + Internal(0x01), + InvalidState(0x02), + EndOfMethod(0x03), - // Logical errors - NotSupported(0x10), - NotImplemented(0x11), - InvalidArgument(0x12), - InvalidType(0x13), - OperatorMissing(0x14), + // Logical errors + NotSupported(0x10), + NotImplemented(0x11), + InvalidArgument(0x12), + InvalidType(0x13), + OperatorMissing(0x14), - // Resource errors - NotFound(0x20), - MemoryAllocationFailed(0x21), - AccessFailed(0x22), - InvalidProgram(0x23), + // Resource errors + NotFound(0x20), + MemoryAllocationFailed(0x21), + AccessFailed(0x22), + InvalidProgram(0x23), - // Delegate errors - DelegateInvalidCompatibility(0x30), - DelegateMemoryAllocationFailed(0x31), - DelegateInvalidHandle(0x32); + // Delegate errors + DelegateInvalidCompatibility(0x30), + DelegateMemoryAllocationFailed(0x31), + DelegateInvalidHandle(0x32), } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt index 1e00aa48..e26a6244 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt @@ -3,7 +3,6 @@ package com.swmansion.rnexecutorch.utils import android.content.Context import android.net.Uri import android.util.Base64 -import android.util.Log import org.opencv.core.Core import org.opencv.core.CvType import org.opencv.core.Mat @@ -19,14 +18,19 @@ import java.net.URL import java.util.UUID import kotlin.math.floor - class ImageProcessor { companion object { - fun matToEValue(mat: Mat, shape: LongArray): EValue { - return matToEValue(mat, shape, Scalar(0.0, 0.0, 0.0), Scalar(1.0, 1.0, 1.0)) - } - - fun matToEValue(mat: Mat, shape: LongArray, mean: Scalar, variance: Scalar): EValue { + fun matToEValue( + mat: Mat, + shape: LongArray, + ): EValue = matToEValue(mat, shape, Scalar(0.0, 0.0, 0.0), Scalar(1.0, 1.0, 1.0)) + + fun matToEValue( + mat: Mat, + shape: LongArray, + mean: Scalar, + variance: Scalar, + ): EValue { val pixelCount = mat.cols() * mat.rows() val floatArray = FloatArray(pixelCount * 3) @@ -63,12 +67,16 @@ class ImageProcessor { return EValue.from( Tensor.fromBlob( floatArray, - longArrayOf(1, 1, mat.rows().toLong(), mat.cols().toLong()) - ) + longArrayOf(1, 1, mat.rows().toLong(), mat.cols().toLong()), + ), ) } - fun EValueToMat(array: FloatArray, width: Int, height: Int): Mat { + fun EValueToMat( + array: FloatArray, + width: Int, + height: Int, + ): Mat { val mat = Mat(height, width, CvType.CV_8UC3) val pixelCount = width * height @@ -86,7 +94,10 @@ class ImageProcessor { return mat } - fun saveToTempFile(context: Context, mat: Mat): String { + fun saveToTempFile( + context: Context, + mat: Mat, + ): String { try { val uniqueID = UUID.randomUUID().toString() val tempFile = File(context.cacheDir, "rn_executorch_$uniqueID.png") @@ -106,27 +117,28 @@ class ImageProcessor { when { scheme.equals("data", ignoreCase = true) -> { - //base64 + // base64 val parts = source.split(",", limit = 2) if (parts.size < 2) throw IllegalArgumentException(ETError.InvalidArgument.toString()) val encodedString = parts[1] val data = Base64.decode(encodedString, Base64.DEFAULT) - val encodedData = Mat(1, data.size, CvType.CV_8UC1).apply { - put(0, 0, data) - } + val encodedData = + Mat(1, data.size, CvType.CV_8UC1).apply { + put(0, 0, data) + } inputImage = Imgcodecs.imdecode(encodedData, Imgcodecs.IMREAD_COLOR) } scheme.equals("file", ignoreCase = true) -> { - //device storage + // device storage val path = uri.path inputImage = Imgcodecs.imread(path, Imgcodecs.IMREAD_COLOR) } else -> { - //external source + // external source val url = URL(source) val connection = url.openConnection() connection.connect() @@ -135,9 +147,10 @@ class ImageProcessor { val data = inputStream.readBytes() inputStream.close() - val encodedData = Mat(1, data.size, CvType.CV_8UC1).apply { - put(0, 0, data) - } + val encodedData = + Mat(1, data.size, CvType.CV_8UC1).apply { + put(0, 0, data) + } inputImage = Imgcodecs.imdecode(encodedData, Imgcodecs.IMREAD_COLOR) } } @@ -149,7 +162,11 @@ class ImageProcessor { return inputImage } - fun resizeWithPadding(img: Mat, desiredWidth: Int, desiredHeight: Int): Mat { + fun resizeWithPadding( + img: Mat, + desiredWidth: Int, + desiredHeight: Int, + ): Mat { val height = img.rows() val width = img.cols() val heightRatio = desiredHeight.toFloat() / height @@ -165,32 +182,35 @@ class ImageProcessor { Size(newWidth.toDouble(), newHeight.toDouble()), 0.0, 0.0, - Imgproc.INTER_AREA + Imgproc.INTER_AREA, ) val cornerPatchSize = maxOf(1, minOf(width, height) / 30) - val corners = listOf( - img.submat(0, cornerPatchSize, 0, cornerPatchSize), - img.submat(0, cornerPatchSize, width - cornerPatchSize, width), - img.submat(height - cornerPatchSize, height, 0, cornerPatchSize), - img.submat(height - cornerPatchSize, height, width - cornerPatchSize, width) - ) + val corners = + listOf( + img.submat(0, cornerPatchSize, 0, cornerPatchSize), + img.submat(0, cornerPatchSize, width - cornerPatchSize, width), + img.submat(height - cornerPatchSize, height, 0, cornerPatchSize), + img.submat(height - cornerPatchSize, height, width - cornerPatchSize, width), + ) var backgroundScalar = Core.mean(corners[0]) for (i in 1 until corners.size) { val mean = Core.mean(corners[i]) - backgroundScalar = Scalar( - backgroundScalar.`val`[0] + mean.`val`[0], - backgroundScalar.`val`[1] + mean.`val`[1], - backgroundScalar.`val`[2] + mean.`val`[2] - ) + backgroundScalar = + Scalar( + backgroundScalar.`val`[0] + mean.`val`[0], + backgroundScalar.`val`[1] + mean.`val`[1], + backgroundScalar.`val`[2] + mean.`val`[2], + ) } - backgroundScalar = Scalar( - floor(backgroundScalar.`val`[0] / corners.size), - floor(backgroundScalar.`val`[1] / corners.size), - floor(backgroundScalar.`val`[2] / corners.size) - ) + backgroundScalar = + Scalar( + floor(backgroundScalar.`val`[0] / corners.size), + floor(backgroundScalar.`val`[1] / corners.size), + floor(backgroundScalar.`val`[2] / corners.size), + ) val deltaW = desiredWidth - newWidth val deltaH = desiredHeight - newHeight @@ -208,7 +228,7 @@ class ImageProcessor { left, right, Core.BORDER_CONSTANT, - backgroundScalar + backgroundScalar, ) return centeredImg diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt index 00fd3fb1..6f58f373 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt @@ -5,7 +5,7 @@ import com.facebook.react.bridge.WritableMap fun nms( detections: MutableList, - iouThreshold: Float + iouThreshold: Float, ): List { if (detections.isEmpty()) { return emptyList() @@ -39,7 +39,7 @@ fun nms( while (iterator.hasNext()) { val other = iterator.next() if (calculateIoU(current.bbox, other.bbox) > iouThreshold) { - iterator.remove() // Remove detection if IoU is above threshold + iterator.remove() // Remove detection if IoU is above threshold } } } @@ -51,7 +51,10 @@ fun nms( return result } -fun calculateIoU(bbox1: Bbox, bbox2: Bbox): Float { +fun calculateIoU( + bbox1: Bbox, + bbox2: Bbox, +): Float { val x1 = maxOf(bbox1.x1, bbox2.x1) val y1 = maxOf(bbox1.y1, bbox2.y1) val x2 = minOf(bbox1.x2, bbox2.x2) @@ -65,12 +68,11 @@ fun calculateIoU(bbox1: Bbox, bbox2: Bbox): Float { return if (unionArea == 0f) 0f else intersectionArea / unionArea } - data class Bbox( val x1: Float, val y1: Float, val x2: Float, - val y2: Float + val y2: Float, ) { fun toWritableMap(): WritableMap { val map = Arguments.createMap() @@ -82,7 +84,6 @@ data class Bbox( } } - data class Detection( val bbox: Bbox, val score: Float, @@ -97,7 +98,9 @@ data class Detection( } } -enum class CocoLabel(val id: Int) { +enum class CocoLabel( + val id: Int, +) { PERSON(1), BICYCLE(2), CAR(3), @@ -187,10 +190,12 @@ enum class CocoLabel(val id: Int) { TEDDY_BEAR(88), HAIR_DRIER(89), TOOTHBRUSH(90), - HAIR_BRUSH(91); + HAIR_BRUSH(91), + ; companion object { private val idToLabelMap = values().associateBy(CocoLabel::id) + fun fromId(id: Int): CocoLabel? = idToLabelMap[id] } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt index 7005cb8a..a5ff5679 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt @@ -7,11 +7,14 @@ import java.io.IOException class ProgressResponseBody( private val responseBody: ResponseBody, - private val progressListener: ProgressListener + private val progressListener: ProgressListener, ) : ResponseBody() { - interface ProgressListener { - fun onProgress(bytesRead: Long, contentLength: Long, done: Boolean) + fun onProgress( + bytesRead: Long, + contentLength: Long, + done: Boolean, + ) } private var bufferedSource: BufferedSource? = null @@ -27,15 +30,19 @@ class ProgressResponseBody( return bufferedSource!! } - private fun source(source: Source): Source = object : ForwardingSource(source) { - var totalBytesRead = 0L - - @Throws(IOException::class) - override fun read(sink: Buffer, byteCount: Long): Long { - val bytesRead = super.read(sink, byteCount) - totalBytesRead += if (bytesRead != -1L) bytesRead else 0 - progressListener.onProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1L) - return bytesRead + private fun source(source: Source): Source = + object : ForwardingSource(source) { + var totalBytesRead = 0L + + @Throws(IOException::class) + override fun read( + sink: Buffer, + byteCount: Long, + ): Long { + val bytesRead = super.read(sink, byteCount) + totalBytesRead += if (bytesRead != -1L) bytesRead else 0 + progressListener.onProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1L) + return bytesRead + } } - } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt index b97e81a9..a3026ad4 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt @@ -1,48 +1,50 @@ - package com.swmansion.rnexecutorch.utils - - import java.util.Vector - import kotlin.math.cos - import kotlin.math.PI - import org.jtransforms.fft.FloatFFT_1D - import kotlin.math.sqrt - - class STFT public constructor(var fftSize: Int = 512, var hopLength: Int = 160) { - private val fftModule = FloatFFT_1D(this.fftSize.toLong()) - private val magnitudeScale = 1.0 / this.fftSize - // https://www.mathworks.com/help/signal/ref/hann.html - private val hannWindow = FloatArray(this.fftSize) { i ->0.5f - 0.5f * cos(2f * PI.toFloat() * i / this.fftSize) } - - - fun fromWaveform(signal: FloatArray): FloatArray { - val numFftFrames = (signal.size - this.fftSize) / this.hopLength - // The output of FFT is always 2x smaller - val stft = FloatArray(numFftFrames * (this.fftSize / 2)) - - var windowStartIdx = 0 - var outputIndex = 0 - // TODO: i dont think the substraction at the end is needed - while (windowStartIdx + this.fftSize < signal.size - this.fftSize) { - val currentWindow = signal.copyOfRange(windowStartIdx, windowStartIdx + this.fftSize) - // Apply Hann window to the current slice - for (i in currentWindow.indices) currentWindow[i] *= this.hannWindow[i] - - // Perform in-place FFT - this.fftModule.realForward(currentWindow) - - stft[outputIndex++] = kotlin.math.abs(currentWindow[0]) - for (i in 1 until this.fftSize / 2 - 1) { - val real = currentWindow[2 * i] - val imag = currentWindow[2 * i + 1] - - val currentMagnitude = (sqrt(real * real + imag * imag) * this.magnitudeScale).toFloat() - // FIXME: we don't need that, but if we remove this we have to get rid of - // reversing this operation in the preprocessing part - stft[outputIndex++] = 20 * kotlin.math.log10(currentMagnitude) - } - // Nyquist frequency - stft[outputIndex++] = kotlin.math.abs(currentWindow[1]) - windowStartIdx += this.hopLength - } - return stft - } - } +package com.swmansion.rnexecutorch.utils + +import org.jtransforms.fft.FloatFFT_1D +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.sqrt + +class STFT public constructor( + var fftSize: Int = 512, + var hopLength: Int = 160, +) { + private val fftModule = FloatFFT_1D(this.fftSize.toLong()) + private val magnitudeScale = 1.0 / this.fftSize + + // https://www.mathworks.com/help/signal/ref/hann.html + private val hannWindow = FloatArray(this.fftSize) { i -> 0.5f - 0.5f * cos(2f * PI.toFloat() * i / this.fftSize) } + + fun fromWaveform(signal: FloatArray): FloatArray { + val numFftFrames = (signal.size - this.fftSize) / this.hopLength + // The output of FFT is always 2x smaller + val stft = FloatArray(numFftFrames * (this.fftSize / 2)) + + var windowStartIdx = 0 + var outputIndex = 0 + // TODO: i dont think the substraction at the end is needed + while (windowStartIdx + this.fftSize < signal.size - this.fftSize) { + val currentWindow = signal.copyOfRange(windowStartIdx, windowStartIdx + this.fftSize) + // Apply Hann window to the current slice + for (i in currentWindow.indices) currentWindow[i] *= this.hannWindow[i] + + // Perform in-place FFT + this.fftModule.realForward(currentWindow) + + stft[outputIndex++] = kotlin.math.abs(currentWindow[0]) + for (i in 1 until this.fftSize / 2 - 1) { + val real = currentWindow[2 * i] + val imag = currentWindow[2 * i + 1] + + val currentMagnitude = (sqrt(real * real + imag * imag) * this.magnitudeScale).toFloat() + // FIXME: we don't need that, but if we remove this we have to get rid of + // reversing this operation in the preprocessing part + stft[outputIndex++] = 20 * kotlin.math.log10(currentMagnitude) + } + // Nyquist frequency + stft[outputIndex++] = kotlin.math.abs(currentWindow[1]) + windowStartIdx += this.hopLength + } + return stft + } +} diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt index 212b415e..ca855245 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt @@ -9,7 +9,11 @@ import java.nio.FloatBuffer class TensorUtils { companion object { - fun getExecutorchInput(input: ReadableArray, shape: LongArray, type: Int): EValue { + fun getExecutorchInput( + input: ReadableArray, + shape: LongArray, + type: Int, + ): EValue { try { when (type) { 1 -> { @@ -91,8 +95,8 @@ class TensorUtils { val g = Color.green(c) / 255.0f val b = Color.blue(c) / 255.0f outBuffer.put(i, r) - outBuffer.put( offsetG + i, g) - outBuffer.put( offsetB + i, b) + outBuffer.put(offsetG + i, g) + outBuffer.put(offsetB + i, b) } } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt index 78654b29..08388a2c 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt @@ -3,7 +3,7 @@ package com.swmansion.rnexecutorch.utils.llms enum class ChatRole { SYSTEM, USER, - ASSISTANT + ASSISTANT, } const val BEGIN_OF_TEXT_TOKEN = "<|begin_of_text|>" @@ -14,18 +14,18 @@ const val END_HEADER_ID_TOKEN = "<|end_header_id|>" class ConversationManager( private val numMessagesContextWindow: Int, systemPrompt: String, - messageHistory: Array> + messageHistory: Array>, ) { - private val basePrompt: String; - private val messages = ArrayDeque(); + private val basePrompt: String + private val messages = ArrayDeque() init { this.basePrompt = BEGIN_OF_TEXT_TOKEN + - getHeaderTokenFromRole(ChatRole.SYSTEM) + - systemPrompt + - END_OF_TEXT_TOKEN + - getHeaderTokenFromRole(ChatRole.USER) + getHeaderTokenFromRole(ChatRole.SYSTEM) + + systemPrompt + + END_OF_TEXT_TOKEN + + getHeaderTokenFromRole(ChatRole.USER) messageHistory.forEach { message -> when (message["role"]) { @@ -35,15 +35,19 @@ class ConversationManager( } } - fun addResponse(text: String, senderRole: ChatRole) { + fun addResponse( + text: String, + senderRole: ChatRole, + ) { if (this.messages.size >= this.numMessagesContextWindow) { this.messages.removeFirst() } - val formattedMessage: String = if (senderRole == ChatRole.ASSISTANT) { - text + getHeaderTokenFromRole(ChatRole.USER) - } else { - text + END_OF_TEXT_TOKEN + getHeaderTokenFromRole(ChatRole.ASSISTANT) - } + val formattedMessage: String = + if (senderRole == ChatRole.ASSISTANT) { + text + getHeaderTokenFromRole(ChatRole.USER) + } else { + text + END_OF_TEXT_TOKEN + getHeaderTokenFromRole(ChatRole.ASSISTANT) + } this.messages.add(formattedMessage) } @@ -55,11 +59,10 @@ class ConversationManager( return prompt.toString() } - private fun getHeaderTokenFromRole(role: ChatRole): String { - return when (role) { + private fun getHeaderTokenFromRole(role: ChatRole): String = + when (role) { ChatRole.SYSTEM -> START_HEADER_ID_TOKEN + "system" + END_HEADER_ID_TOKEN ChatRole.USER -> START_HEADER_ID_TOKEN + "user" + END_HEADER_ID_TOKEN ChatRole.ASSISTANT -> START_HEADER_ID_TOKEN + "assistant" + END_HEADER_ID_TOKEN } - } } diff --git a/docs/docs/fundamentals/getting-started.md b/docs/docs/fundamentals/getting-started.md index 34444f05..c80c95a4 100644 --- a/docs/docs/fundamentals/getting-started.md +++ b/docs/docs/fundamentals/getting-started.md @@ -62,7 +62,7 @@ When using Expo, please note that you need to use a custom development build of ::: :::caution -If you encountered an error that native modules for React Native Audio API were not installed, please make sure to install react-native-audio-api. +If you encountered an error that native modules for React Native Audio API were not installed, please make sure to install react-native-audio-api. ::: :::info diff --git a/docs/docs/speech-to-text/useSpeechToText.md b/docs/docs/speech-to-text/useSpeechToText.md index 6cde2e04..4233ece2 100644 --- a/docs/docs/speech-to-text/useSpeechToText.md +++ b/docs/docs/speech-to-text/useSpeechToText.md @@ -63,8 +63,8 @@ Specifies the size of each audio chunk (expressed in seconds). | ------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `transcribe` | `(input?: number[]) => Promise` | Starts a transcription process for a given input array, which should be a waveform at 16kHz. When no input is provided, it uses an internal state which is set by calling `loadAudio`. Resolves a promise with the output transcription when the model is finished. | | `loadAudio` | `(url: string) => void` | Loads audio file from given url. It sets an internal state which serves as an input to `transcribe()`. | -| `error` | Error | undefined | Contains the error message if the model failed to load. | -| `sequence` | string | This property is updated with each generated token. If you're looking to obtain tokens as they're generated, you should use this property. | +| `error` | Error | undefined | Contains the error message if the model failed to load. | +| `sequence` | string | This property is updated with each generated token. If you're looking to obtain tokens as they're generated, you should use this property. | | `isGenerating` | `boolean` | Indicates whether the model is currently processing an inference. | | `isReady` | `boolean` | Indicates whether the model has successfully loaded and is ready for inference. | | `downloadProgress` | `number` | Tracks the progress of the model download process. | diff --git a/docs/src/components/FooterBackground/styles.module.css b/docs/src/components/FooterBackground/styles.module.css index 5fdda1a2..995f0ab5 100644 --- a/docs/src/components/FooterBackground/styles.module.css +++ b/docs/src/components/FooterBackground/styles.module.css @@ -11,11 +11,11 @@ .linearGradient { height: 106px; width: 100%; - background: linear-gradient(#7394FF, #FFFFFF 150%); + background: linear-gradient(#7394ff, #ffffff 150%); } [data-theme='dark'] .linearGradient { - background: linear-gradient(#313C9C, #160042 150%); + background: linear-gradient(#313c9c, #160042 150%); } @media (max-width: 996px) { diff --git a/docs/src/components/Hero/StartScreen/styles.module.css b/docs/src/components/Hero/StartScreen/styles.module.css index 24e8c447..b256e497 100644 --- a/docs/src/components/Hero/StartScreen/styles.module.css +++ b/docs/src/components/Hero/StartScreen/styles.module.css @@ -73,7 +73,7 @@ } @media (max-width: 420px) { - .heading { + .heading { margin-top: 6rem; } .headingLabel { diff --git a/docs/src/components/HomepageButton/styles.module.css b/docs/src/components/HomepageButton/styles.module.css index feffb4d2..942338fd 100644 --- a/docs/src/components/HomepageButton/styles.module.css +++ b/docs/src/components/HomepageButton/styles.module.css @@ -10,7 +10,9 @@ background-color: var(--swm-navy-light-100); cursor: pointer; - transition: background-color 0.3s, color 0.3s; + transition: + background-color 0.3s, + color 0.3s; } a.homepageButtonLink:hover { diff --git a/docs/src/components/Wave/WaveTop/styles.module.css b/docs/src/components/Wave/WaveTop/styles.module.css index 4b347bd8..694ce522 100644 --- a/docs/src/components/Wave/WaveTop/styles.module.css +++ b/docs/src/components/Wave/WaveTop/styles.module.css @@ -10,4 +10,4 @@ .wave { margin-bottom: -29%; } -} \ No newline at end of file +} diff --git a/docs/src/css/colors.css b/docs/src/css/colors.css index dacf3a74..001560cb 100644 --- a/docs/src/css/colors.css +++ b/docs/src/css/colors.css @@ -88,37 +88,37 @@ --swm-cornflower-140: #23326f; --swm-cornflower-120: #3851b4; - --swm-cornflower-100: #4B6CF4; - --swm-cornflower-80: #7394FF; - --swm-cornflower-60: #A6C2FF; - --swm-cornflower-40: #D0E2FF; - --swm-cornflower-20: #E6EFFF; - --swm-cornflower-0: #F7FAFF; + --swm-cornflower-100: #4b6cf4; + --swm-cornflower-80: #7394ff; + --swm-cornflower-60: #a6c2ff; + --swm-cornflower-40: #d0e2ff; + --swm-cornflower-20: #e6efff; + --swm-cornflower-0: #f7faff; /* Admonitions colors */ - --swm-admonition-light-cornflower: #F4F5FC; - --swm-admonition-light-green: #EFF6F0; - --swm-admonition-light-red: #FAF2F2; - --swm-admonition-light-blue: #EBF4F7; - --swm-admonition-light-yellow: #FAF5EF; - - --swm-admonition-light-cornflower-shadow: #4B6CF4; - --swm-admonition-light-green-shadow: #10A05A; - --swm-admonition-light-red-shadow: #DC5153; - --swm-admonition-light-blue-shadow: #2AAFCD; - --swm-admonition-light-yellow-shadow: #C79C03; - - --swm-admonition-dark-cornflower: #425FD8; - --swm-admonition-dark-green: #0F8C4F; - --swm-admonition-dark-red: #C24C4E; - --swm-admonition-dark-blue: #269CB7; - --swm-admonition-dark-yellow: #B18B04; + --swm-admonition-light-cornflower: #f4f5fc; + --swm-admonition-light-green: #eff6f0; + --swm-admonition-light-red: #faf2f2; + --swm-admonition-light-blue: #ebf4f7; + --swm-admonition-light-yellow: #faf5ef; + + --swm-admonition-light-cornflower-shadow: #4b6cf4; + --swm-admonition-light-green-shadow: #10a05a; + --swm-admonition-light-red-shadow: #dc5153; + --swm-admonition-light-blue-shadow: #2aafcd; + --swm-admonition-light-yellow-shadow: #c79c03; + + --swm-admonition-dark-cornflower: #425fd8; + --swm-admonition-dark-green: #0f8c4f; + --swm-admonition-dark-red: #c24c4e; + --swm-admonition-dark-blue: #269cb7; + --swm-admonition-dark-yellow: #b18b04; --swm-admonition-dark-cornflower-shadow: #324387; --swm-admonition-dark-green-shadow: #195943; --swm-admonition-dark-red-shadow: #723942; --swm-admonition-dark-blue-shadow: #246177; - --swm-admonition-dark-yellow-shadow: #6A591D; + --swm-admonition-dark-yellow-shadow: #6a591d; /* Black & White palette, mainly for background settings */ --swm-off-white: #f8f9ff; @@ -185,11 +185,17 @@ --swm-admonition-color-info: var(--swm-admonition-light-blue); --swm-admonition-color-caution: var(--swm-admonition-light-yellow); - --swm-admonition-color-secondary-shadow: var(--swm-admonition-light-cornflower-shadow); - --swm-admonition-color-success-shadow: var(--swm-admonition-light-green-shadow); + --swm-admonition-color-secondary-shadow: var( + --swm-admonition-light-cornflower-shadow + ); + --swm-admonition-color-success-shadow: var( + --swm-admonition-light-green-shadow + ); --swm-admonition-color-danger-shadow: var(--swm-admonition-light-red-shadow); --swm-admonition-color-info-shadow: var(--swm-admonition-light-blue-shadow); - --swm-admonition-color-caution-shadow: var(--swm-admonition-light-yellow-shadow); + --swm-admonition-color-caution-shadow: var( + --swm-admonition-light-yellow-shadow + ); /* Details */ --swm-details-color: var(--swm-navy-light-100); @@ -372,11 +378,17 @@ --swm-admonition-color-info: var(--swm-admonition-dark-blue); --swm-admonition-color-caution: var(--swm-admonition-dark-yellow); - --swm-admonition-color-secondary-shadow: var(--swm-admonition-dark-cornflower-shadow); - --swm-admonition-color-success-shadow: var(--swm-admonition-dark-green-shadow); + --swm-admonition-color-secondary-shadow: var( + --swm-admonition-dark-cornflower-shadow + ); + --swm-admonition-color-success-shadow: var( + --swm-admonition-dark-green-shadow + ); --swm-admonition-color-danger-shadow: var(--swm-admonition-dark-red-shadow); --swm-admonition-color-info-shadow: var(--swm-admonition-dark-blue-shadow); - --swm-admonition-color-caution-shadow: var(--swm-admonition-dark-yellow-shadow); + --swm-admonition-color-caution-shadow: var( + --swm-admonition-dark-yellow-shadow + ); /* Details */ --swm-details-color: var(--swm-off-white); diff --git a/docs/src/pages/styles.module.css b/docs/src/pages/styles.module.css index 1635a7eb..69c87b59 100644 --- a/docs/src/pages/styles.module.css +++ b/docs/src/pages/styles.module.css @@ -14,7 +14,7 @@ position: relative; width: 100%; margin-top: 18rem; - background: linear-gradient(#7394FF, #FFFFFF); + background: linear-gradient(#7394ff, #ffffff); padding-top: 8.25rem; } @@ -31,7 +31,7 @@ color: var(--swm-off-white); } -[data-theme='dark'] .hireUsSection a div:hover svg{ +[data-theme='dark'] .hireUsSection a div:hover svg { stroke: var(--swm-off-white); } diff --git a/docs/src/theme/MDXComponents/styles.module.css b/docs/src/theme/MDXComponents/styles.module.css index 474f3525..4f95e1eb 100644 --- a/docs/src/theme/MDXComponents/styles.module.css +++ b/docs/src/theme/MDXComponents/styles.module.css @@ -1,50 +1,50 @@ .details { - background-color: var(--swm-details-foreground); - box-shadow: -8px 8px 0 var(--swm-details-background); - - color: var(--swm-details-color); - } - - .details a { - color: var(--swm-details-color); - } - - .details > summary { - display: flex; - align-items: center; - cursor: pointer; - list-style: none; - padding: 1.5em 2em; - } - - .details > summary > p { - margin: 0; - } - - /* TODO: deprecation, need to remove this after Safari will support `::marker` */ - .details > summary::-webkit-details-marker { - display: none; - } - - .arrow { - height: 12px; - width: 12px; - margin-right: 1.5rem; - left: 0; - - transition: var(--swm-expandable-transition); - } - - .details[open]:not(.isBrowser) > summary > .arrow, + background-color: var(--swm-details-foreground); + box-shadow: -8px 8px 0 var(--swm-details-background); + + color: var(--swm-details-color); +} + +.details a { + color: var(--swm-details-color); +} + +.details > summary { + display: flex; + align-items: center; + cursor: pointer; + list-style: none; + padding: 1.5em 2em; +} + +.details > summary > p { + margin: 0; +} + +/* TODO: deprecation, need to remove this after Safari will support `::marker` */ +.details > summary::-webkit-details-marker { + display: none; +} + +.arrow { + height: 12px; + width: 12px; + margin-right: 1.5rem; + left: 0; + + transition: var(--swm-expandable-transition); +} + +.details[open]:not(.isBrowser) > summary > .arrow, /* When JS works: we use the data-attribute for arrow animation */ .details[data-collapsed='false'].isBrowser > summary > .arrow { - transform: rotate(180deg); - } - - .collapsibleContent { - padding: 0 2em 1.5em 2em; - } - - .collapsibleContent > *:last-child { - margin-bottom: 0; - } \ No newline at end of file + transform: rotate(180deg); +} + +.collapsibleContent { + padding: 0 2em 1.5em 2em; +} + +.collapsibleContent > *:last-child { + margin-bottom: 0; +} diff --git a/docs/src/theme/TOCItems/styles.module.css b/docs/src/theme/TOCItems/styles.module.css index 25287a9c..5333bad7 100644 --- a/docs/src/theme/TOCItems/styles.module.css +++ b/docs/src/theme/TOCItems/styles.module.css @@ -1,3 +1,3 @@ [data-theme='light'] .TOCItemsWrapper > div { - background-color: var(--swm-cornflower-20); + background-color: var(--swm-cornflower-20); } diff --git a/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainActivity.kt b/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainActivity.kt index 0d4abb0a..30e94647 100644 --- a/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainActivity.kt +++ b/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainActivity.kt @@ -2,12 +2,10 @@ package com.anonymous.computervision import android.os.Build import android.os.Bundle - import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled import com.facebook.react.defaults.DefaultReactActivityDelegate - import expo.modules.ReactActivityDelegateWrapper class MainActivity : ReactActivity() { @@ -15,7 +13,7 @@ class MainActivity : ReactActivity() { // Set the theme to AppTheme BEFORE onCreate to support // coloring the background, status bar, and navigation bar. // This is required for expo-splash-screen. - setTheme(R.style.AppTheme); + setTheme(R.style.AppTheme) super.onCreate(null) } @@ -29,33 +27,33 @@ class MainActivity : ReactActivity() { * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] */ - override fun createReactActivityDelegate(): ReactActivityDelegate { - return ReactActivityDelegateWrapper( - this, - BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, - object : DefaultReactActivityDelegate( - this, - mainComponentName, - fabricEnabled - ){}) - } + override fun createReactActivityDelegate(): ReactActivityDelegate = + ReactActivityDelegateWrapper( + this, + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, + object : DefaultReactActivityDelegate( + this, + mainComponentName, + fabricEnabled, + ) {}, + ) /** - * Align the back button behavior with Android S - * where moving root activities to background instead of finishing activities. - * @see onBackPressed - */ + * Align the back button behavior with Android S + * where moving root activities to background instead of finishing activities. + * @see onBackPressed + */ override fun invokeDefaultOnBackPressed() { - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { - if (!moveTaskToBack(false)) { - // For non-root activities, use the default implementation to finish them. - super.invokeDefaultOnBackPressed() - } - return + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + if (!moveTaskToBack(false)) { + // For non-root activities, use the default implementation to finish them. + super.invokeDefaultOnBackPressed() } + return + } - // Use the default back button implementation on Android S - // because it's doing more than [Activity.moveTaskToBack] in fact. - super.invokeDefaultOnBackPressed() + // Use the default back button implementation on Android S + // because it's doing more than [Activity.moveTaskToBack] in fact. + super.invokeDefaultOnBackPressed() } } diff --git a/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainApplication.kt b/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainApplication.kt index c65fd4ad..4de3c8d7 100644 --- a/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainApplication.kt +++ b/examples/computer-vision/android/app/src/main/java/com/anonymous/computervision/MainApplication.kt @@ -2,40 +2,40 @@ package com.anonymous.computervision import android.app.Application import android.content.res.Configuration - import com.facebook.react.PackageList import com.facebook.react.ReactApplication +import com.facebook.react.ReactHost import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackage -import com.facebook.react.ReactHost import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.soloader.OpenSourceMergedSoMapping import com.facebook.soloader.SoLoader - import expo.modules.ApplicationLifecycleDispatcher import expo.modules.ReactNativeHostWrapper -class MainApplication : Application(), ReactApplication { - - override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper( - this, - object : DefaultReactNativeHost(this) { - override fun getPackages(): List { - val packages = PackageList(this).packages - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - return packages - } - - override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" - - override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG - - override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED - } - ) +class MainApplication : + Application(), + ReactApplication { + override val reactNativeHost: ReactNativeHost = + ReactNativeHostWrapper( + this, + object : DefaultReactNativeHost(this) { + override fun getPackages(): List { + val packages = PackageList(this).packages + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + return packages + } + + override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" + + override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG + + override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED + }, + ) override val reactHost: ReactHost get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost) diff --git a/examples/computer-vision/ios/computervision/AppDelegate.h b/examples/computer-vision/ios/computervision/AppDelegate.h index 1658a437..1f65766b 100644 --- a/examples/computer-vision/ios/computervision/AppDelegate.h +++ b/examples/computer-vision/ios/computervision/AppDelegate.h @@ -1,6 +1,6 @@ +#import #import #import -#import @interface AppDelegate : EXAppDelegateWrapper diff --git a/examples/computer-vision/ios/computervision/AppDelegate.mm b/examples/computer-vision/ios/computervision/AppDelegate.mm index b27f8328..9be55c97 100644 --- a/examples/computer-vision/ios/computervision/AppDelegate.mm +++ b/examples/computer-vision/ios/computervision/AppDelegate.mm @@ -5,58 +5,83 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleName = @"main"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge -{ +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [self bundleURL]; } -- (NSURL *)bundleURL -{ +- (NSURL *)bundleURL { #if DEBUG - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; + return [[RCTBundleURLProvider sharedSettings] + jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; #else - return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; + return [[NSBundle mainBundle] URLForResource:@"main" + withExtension:@"jsbundle"]; #endif } // Linking API -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { - return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]; +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + options: + (NSDictionary *)options { + return [super application:application openURL:url options:options] || + [RCTLinkingManager application:application + openURL:url + options:options]; } // Universal Links -- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { - BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; - return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result; +- (BOOL)application:(UIApplication *)application + continueUserActivity:(nonnull NSUserActivity *)userActivity + restorationHandler: + (nonnull void (^)(NSArray> *_Nullable)) + restorationHandler { + BOOL result = [RCTLinkingManager application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler]; + return [super application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler] || + result; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken -{ - return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + return [super application:application + didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error -{ - return [super application:application didFailToRegisterForRemoteNotificationsWithError:error]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + return [super application:application + didFailToRegisterForRemoteNotificationsWithError:error]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler -{ - return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didReceiveRemoteNotification:(NSDictionary *)userInfo + fetchCompletionHandler: + (void (^)(UIBackgroundFetchResult))completionHandler { + return [super application:application + didReceiveRemoteNotification:userInfo + fetchCompletionHandler:completionHandler]; } @end diff --git a/examples/computer-vision/ios/computervision/Images.xcassets/AppIcon.appiconset/Contents.json b/examples/computer-vision/ios/computervision/Images.xcassets/AppIcon.appiconset/Contents.json index 90d8d4c2..5f6956c1 100644 --- a/examples/computer-vision/ios/computervision/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/examples/computer-vision/ios/computervision/Images.xcassets/AppIcon.appiconset/Contents.json @@ -11,4 +11,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/computer-vision/ios/computervision/Images.xcassets/Contents.json b/examples/computer-vision/ios/computervision/Images.xcassets/Contents.json index ed285c2e..b4ded435 100644 --- a/examples/computer-vision/ios/computervision/Images.xcassets/Contents.json +++ b/examples/computer-vision/ios/computervision/Images.xcassets/Contents.json @@ -1,6 +1,6 @@ { - "info" : { - "version" : 1, - "author" : "expo" + "info": { + "version": 1, + "author": "expo" } } diff --git a/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenBackground.colorset/Contents.json b/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenBackground.colorset/Contents.json index 7e4c6dd2..ef225ac6 100644 --- a/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenBackground.colorset/Contents.json +++ b/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenBackground.colorset/Contents.json @@ -23,4 +23,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenLogo.imageset/Contents.json b/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenLogo.imageset/Contents.json index 94164eb1..f7878795 100644 --- a/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenLogo.imageset/Contents.json +++ b/examples/computer-vision/ios/computervision/Images.xcassets/SplashScreenLogo.imageset/Contents.json @@ -38,4 +38,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/computer-vision/ios/computervision/computervision-Bridging-Header.h b/examples/computer-vision/ios/computervision/computervision-Bridging-Header.h index e11d920b..339994e9 100644 --- a/examples/computer-vision/ios/computervision/computervision-Bridging-Header.h +++ b/examples/computer-vision/ios/computervision/computervision-Bridging-Header.h @@ -1,3 +1,4 @@ // -// Use this file to import your target's public headers that you would like to expose to Swift. +// Use this file to import your target's public headers that you would like to +// expose to Swift. // diff --git a/examples/computer-vision/ios/computervision/main.m b/examples/computer-vision/ios/computervision/main.m index 25181b6c..6b3a51ac 100644 --- a/examples/computer-vision/ios/computervision/main.m +++ b/examples/computer-vision/ios/computervision/main.m @@ -2,9 +2,9 @@ #import "AppDelegate.h" -int main(int argc, char * argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } - diff --git a/examples/llama/android/app/src/main/java/com/anonymous/llama/MainActivity.kt b/examples/llama/android/app/src/main/java/com/anonymous/llama/MainActivity.kt index b42378af..80ee29d0 100644 --- a/examples/llama/android/app/src/main/java/com/anonymous/llama/MainActivity.kt +++ b/examples/llama/android/app/src/main/java/com/anonymous/llama/MainActivity.kt @@ -2,12 +2,10 @@ package com.anonymous.llama import android.os.Build import android.os.Bundle - import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled import com.facebook.react.defaults.DefaultReactActivityDelegate - import expo.modules.ReactActivityDelegateWrapper class MainActivity : ReactActivity() { @@ -15,7 +13,7 @@ class MainActivity : ReactActivity() { // Set the theme to AppTheme BEFORE onCreate to support // coloring the background, status bar, and navigation bar. // This is required for expo-splash-screen. - setTheme(R.style.AppTheme); + setTheme(R.style.AppTheme) super.onCreate(null) } @@ -29,33 +27,33 @@ class MainActivity : ReactActivity() { * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] */ - override fun createReactActivityDelegate(): ReactActivityDelegate { - return ReactActivityDelegateWrapper( - this, - BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, - object : DefaultReactActivityDelegate( - this, - mainComponentName, - fabricEnabled - ){}) - } + override fun createReactActivityDelegate(): ReactActivityDelegate = + ReactActivityDelegateWrapper( + this, + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, + object : DefaultReactActivityDelegate( + this, + mainComponentName, + fabricEnabled, + ) {}, + ) /** - * Align the back button behavior with Android S - * where moving root activities to background instead of finishing activities. - * @see onBackPressed - */ + * Align the back button behavior with Android S + * where moving root activities to background instead of finishing activities. + * @see onBackPressed + */ override fun invokeDefaultOnBackPressed() { - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { - if (!moveTaskToBack(false)) { - // For non-root activities, use the default implementation to finish them. - super.invokeDefaultOnBackPressed() - } - return + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + if (!moveTaskToBack(false)) { + // For non-root activities, use the default implementation to finish them. + super.invokeDefaultOnBackPressed() } + return + } - // Use the default back button implementation on Android S - // because it's doing more than [Activity.moveTaskToBack] in fact. - super.invokeDefaultOnBackPressed() + // Use the default back button implementation on Android S + // because it's doing more than [Activity.moveTaskToBack] in fact. + super.invokeDefaultOnBackPressed() } } diff --git a/examples/llama/android/app/src/main/java/com/anonymous/llama/MainApplication.kt b/examples/llama/android/app/src/main/java/com/anonymous/llama/MainApplication.kt index 9ce30d09..70decaa2 100644 --- a/examples/llama/android/app/src/main/java/com/anonymous/llama/MainApplication.kt +++ b/examples/llama/android/app/src/main/java/com/anonymous/llama/MainApplication.kt @@ -2,40 +2,40 @@ package com.anonymous.llama import android.app.Application import android.content.res.Configuration - import com.facebook.react.PackageList import com.facebook.react.ReactApplication +import com.facebook.react.ReactHost import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackage -import com.facebook.react.ReactHost import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.soloader.OpenSourceMergedSoMapping import com.facebook.soloader.SoLoader - import expo.modules.ApplicationLifecycleDispatcher import expo.modules.ReactNativeHostWrapper -class MainApplication : Application(), ReactApplication { - - override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper( - this, - object : DefaultReactNativeHost(this) { - override fun getPackages(): List { - val packages = PackageList(this).packages - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - return packages - } - - override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" - - override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG - - override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED - } - ) +class MainApplication : + Application(), + ReactApplication { + override val reactNativeHost: ReactNativeHost = + ReactNativeHostWrapper( + this, + object : DefaultReactNativeHost(this) { + override fun getPackages(): List { + val packages = PackageList(this).packages + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + return packages + } + + override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" + + override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG + + override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED + }, + ) override val reactHost: ReactHost get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost) diff --git a/examples/llama/ios/llama/AppDelegate.h b/examples/llama/ios/llama/AppDelegate.h index 1658a437..1f65766b 100644 --- a/examples/llama/ios/llama/AppDelegate.h +++ b/examples/llama/ios/llama/AppDelegate.h @@ -1,6 +1,6 @@ +#import #import #import -#import @interface AppDelegate : EXAppDelegateWrapper diff --git a/examples/llama/ios/llama/AppDelegate.mm b/examples/llama/ios/llama/AppDelegate.mm index b27f8328..9be55c97 100644 --- a/examples/llama/ios/llama/AppDelegate.mm +++ b/examples/llama/ios/llama/AppDelegate.mm @@ -5,58 +5,83 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleName = @"main"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge -{ +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [self bundleURL]; } -- (NSURL *)bundleURL -{ +- (NSURL *)bundleURL { #if DEBUG - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; + return [[RCTBundleURLProvider sharedSettings] + jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; #else - return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; + return [[NSBundle mainBundle] URLForResource:@"main" + withExtension:@"jsbundle"]; #endif } // Linking API -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { - return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]; +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + options: + (NSDictionary *)options { + return [super application:application openURL:url options:options] || + [RCTLinkingManager application:application + openURL:url + options:options]; } // Universal Links -- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { - BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; - return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result; +- (BOOL)application:(UIApplication *)application + continueUserActivity:(nonnull NSUserActivity *)userActivity + restorationHandler: + (nonnull void (^)(NSArray> *_Nullable)) + restorationHandler { + BOOL result = [RCTLinkingManager application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler]; + return [super application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler] || + result; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken -{ - return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + return [super application:application + didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error -{ - return [super application:application didFailToRegisterForRemoteNotificationsWithError:error]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + return [super application:application + didFailToRegisterForRemoteNotificationsWithError:error]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler -{ - return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didReceiveRemoteNotification:(NSDictionary *)userInfo + fetchCompletionHandler: + (void (^)(UIBackgroundFetchResult))completionHandler { + return [super application:application + didReceiveRemoteNotification:userInfo + fetchCompletionHandler:completionHandler]; } @end diff --git a/examples/llama/ios/llama/Images.xcassets/AppIcon.appiconset/Contents.json b/examples/llama/ios/llama/Images.xcassets/AppIcon.appiconset/Contents.json index 90d8d4c2..5f6956c1 100644 --- a/examples/llama/ios/llama/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/examples/llama/ios/llama/Images.xcassets/AppIcon.appiconset/Contents.json @@ -11,4 +11,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/llama/ios/llama/Images.xcassets/Contents.json b/examples/llama/ios/llama/Images.xcassets/Contents.json index ed285c2e..b4ded435 100644 --- a/examples/llama/ios/llama/Images.xcassets/Contents.json +++ b/examples/llama/ios/llama/Images.xcassets/Contents.json @@ -1,6 +1,6 @@ { - "info" : { - "version" : 1, - "author" : "expo" + "info": { + "version": 1, + "author": "expo" } } diff --git a/examples/llama/ios/llama/Images.xcassets/SplashScreenBackground.colorset/Contents.json b/examples/llama/ios/llama/Images.xcassets/SplashScreenBackground.colorset/Contents.json index 15f02abe..3402288a 100644 --- a/examples/llama/ios/llama/Images.xcassets/SplashScreenBackground.colorset/Contents.json +++ b/examples/llama/ios/llama/Images.xcassets/SplashScreenBackground.colorset/Contents.json @@ -17,4 +17,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/llama/ios/llama/Images.xcassets/SplashScreenLogo.imageset/Contents.json b/examples/llama/ios/llama/Images.xcassets/SplashScreenLogo.imageset/Contents.json index f65c008b..f615695d 100644 --- a/examples/llama/ios/llama/Images.xcassets/SplashScreenLogo.imageset/Contents.json +++ b/examples/llama/ios/llama/Images.xcassets/SplashScreenLogo.imageset/Contents.json @@ -20,4 +20,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/llama/ios/llama/llama-Bridging-Header.h b/examples/llama/ios/llama/llama-Bridging-Header.h index e11d920b..339994e9 100644 --- a/examples/llama/ios/llama/llama-Bridging-Header.h +++ b/examples/llama/ios/llama/llama-Bridging-Header.h @@ -1,3 +1,4 @@ // -// Use this file to import your target's public headers that you would like to expose to Swift. +// Use this file to import your target's public headers that you would like to +// expose to Swift. // diff --git a/examples/llama/ios/llama/main.m b/examples/llama/ios/llama/main.m index 25181b6c..6b3a51ac 100644 --- a/examples/llama/ios/llama/main.m +++ b/examples/llama/ios/llama/main.m @@ -2,9 +2,9 @@ #import "AppDelegate.h" -int main(int argc, char * argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } - diff --git a/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainActivity.kt b/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainActivity.kt index a5aaee37..4d914068 100644 --- a/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainActivity.kt +++ b/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainActivity.kt @@ -2,12 +2,10 @@ package com.anonymous.speechtotext import android.os.Build import android.os.Bundle - import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled import com.facebook.react.defaults.DefaultReactActivityDelegate - import expo.modules.ReactActivityDelegateWrapper class MainActivity : ReactActivity() { @@ -15,7 +13,7 @@ class MainActivity : ReactActivity() { // Set the theme to AppTheme BEFORE onCreate to support // coloring the background, status bar, and navigation bar. // This is required for expo-splash-screen. - setTheme(R.style.AppTheme); + setTheme(R.style.AppTheme) super.onCreate(null) } @@ -29,33 +27,33 @@ class MainActivity : ReactActivity() { * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] */ - override fun createReactActivityDelegate(): ReactActivityDelegate { - return ReactActivityDelegateWrapper( - this, - BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, - object : DefaultReactActivityDelegate( - this, - mainComponentName, - fabricEnabled - ){}) - } + override fun createReactActivityDelegate(): ReactActivityDelegate = + ReactActivityDelegateWrapper( + this, + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, + object : DefaultReactActivityDelegate( + this, + mainComponentName, + fabricEnabled, + ) {}, + ) /** - * Align the back button behavior with Android S - * where moving root activities to background instead of finishing activities. - * @see onBackPressed - */ + * Align the back button behavior with Android S + * where moving root activities to background instead of finishing activities. + * @see onBackPressed + */ override fun invokeDefaultOnBackPressed() { - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { - if (!moveTaskToBack(false)) { - // For non-root activities, use the default implementation to finish them. - super.invokeDefaultOnBackPressed() - } - return + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { + if (!moveTaskToBack(false)) { + // For non-root activities, use the default implementation to finish them. + super.invokeDefaultOnBackPressed() } + return + } - // Use the default back button implementation on Android S - // because it's doing more than [Activity.moveTaskToBack] in fact. - super.invokeDefaultOnBackPressed() + // Use the default back button implementation on Android S + // because it's doing more than [Activity.moveTaskToBack] in fact. + super.invokeDefaultOnBackPressed() } } diff --git a/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainApplication.kt b/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainApplication.kt index 64a6dfba..da9e0487 100644 --- a/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainApplication.kt +++ b/examples/speech-to-text/android/app/src/main/java/com/anonymous/speechtotext/MainApplication.kt @@ -2,40 +2,40 @@ package com.anonymous.speechtotext import android.app.Application import android.content.res.Configuration - import com.facebook.react.PackageList import com.facebook.react.ReactApplication +import com.facebook.react.ReactHost import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackage -import com.facebook.react.ReactHost import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.soloader.OpenSourceMergedSoMapping import com.facebook.soloader.SoLoader - import expo.modules.ApplicationLifecycleDispatcher import expo.modules.ReactNativeHostWrapper -class MainApplication : Application(), ReactApplication { - - override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper( - this, - object : DefaultReactNativeHost(this) { - override fun getPackages(): List { - val packages = PackageList(this).packages - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - return packages - } - - override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" - - override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG - - override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED - } - ) +class MainApplication : + Application(), + ReactApplication { + override val reactNativeHost: ReactNativeHost = + ReactNativeHostWrapper( + this, + object : DefaultReactNativeHost(this) { + override fun getPackages(): List { + val packages = PackageList(this).packages + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + return packages + } + + override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" + + override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG + + override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED + }, + ) override val reactHost: ReactHost get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost) diff --git a/examples/speech-to-text/ios/speechtotext/AppDelegate.h b/examples/speech-to-text/ios/speechtotext/AppDelegate.h index 1658a437..1f65766b 100644 --- a/examples/speech-to-text/ios/speechtotext/AppDelegate.h +++ b/examples/speech-to-text/ios/speechtotext/AppDelegate.h @@ -1,6 +1,6 @@ +#import #import #import -#import @interface AppDelegate : EXAppDelegateWrapper diff --git a/examples/speech-to-text/ios/speechtotext/AppDelegate.mm b/examples/speech-to-text/ios/speechtotext/AppDelegate.mm index b27f8328..9be55c97 100644 --- a/examples/speech-to-text/ios/speechtotext/AppDelegate.mm +++ b/examples/speech-to-text/ios/speechtotext/AppDelegate.mm @@ -5,58 +5,83 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleName = @"main"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge -{ +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [self bundleURL]; } -- (NSURL *)bundleURL -{ +- (NSURL *)bundleURL { #if DEBUG - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; + return [[RCTBundleURLProvider sharedSettings] + jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; #else - return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; + return [[NSBundle mainBundle] URLForResource:@"main" + withExtension:@"jsbundle"]; #endif } // Linking API -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { - return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]; +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + options: + (NSDictionary *)options { + return [super application:application openURL:url options:options] || + [RCTLinkingManager application:application + openURL:url + options:options]; } // Universal Links -- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { - BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; - return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result; +- (BOOL)application:(UIApplication *)application + continueUserActivity:(nonnull NSUserActivity *)userActivity + restorationHandler: + (nonnull void (^)(NSArray> *_Nullable)) + restorationHandler { + BOOL result = [RCTLinkingManager application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler]; + return [super application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler] || + result; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken -{ - return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + return [super application:application + didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error -{ - return [super application:application didFailToRegisterForRemoteNotificationsWithError:error]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + return [super application:application + didFailToRegisterForRemoteNotificationsWithError:error]; } -// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler -{ - return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; +// Explicitly define remote notification delegates to ensure compatibility with +// some third-party libraries +- (void)application:(UIApplication *)application + didReceiveRemoteNotification:(NSDictionary *)userInfo + fetchCompletionHandler: + (void (^)(UIBackgroundFetchResult))completionHandler { + return [super application:application + didReceiveRemoteNotification:userInfo + fetchCompletionHandler:completionHandler]; } @end diff --git a/examples/speech-to-text/ios/speechtotext/Images.xcassets/AppIcon.appiconset/Contents.json b/examples/speech-to-text/ios/speechtotext/Images.xcassets/AppIcon.appiconset/Contents.json index 90d8d4c2..5f6956c1 100644 --- a/examples/speech-to-text/ios/speechtotext/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/examples/speech-to-text/ios/speechtotext/Images.xcassets/AppIcon.appiconset/Contents.json @@ -11,4 +11,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/speech-to-text/ios/speechtotext/Images.xcassets/Contents.json b/examples/speech-to-text/ios/speechtotext/Images.xcassets/Contents.json index ed285c2e..b4ded435 100644 --- a/examples/speech-to-text/ios/speechtotext/Images.xcassets/Contents.json +++ b/examples/speech-to-text/ios/speechtotext/Images.xcassets/Contents.json @@ -1,6 +1,6 @@ { - "info" : { - "version" : 1, - "author" : "expo" + "info": { + "version": 1, + "author": "expo" } } diff --git a/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenBackground.colorset/Contents.json b/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenBackground.colorset/Contents.json index 15f02abe..3402288a 100644 --- a/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenBackground.colorset/Contents.json +++ b/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenBackground.colorset/Contents.json @@ -17,4 +17,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenLogo.imageset/Contents.json b/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenLogo.imageset/Contents.json index f65c008b..f615695d 100644 --- a/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenLogo.imageset/Contents.json +++ b/examples/speech-to-text/ios/speechtotext/Images.xcassets/SplashScreenLogo.imageset/Contents.json @@ -20,4 +20,4 @@ "version": 1, "author": "expo" } -} \ No newline at end of file +} diff --git a/examples/speech-to-text/ios/speechtotext/main.m b/examples/speech-to-text/ios/speechtotext/main.m index 25181b6c..6b3a51ac 100644 --- a/examples/speech-to-text/ios/speechtotext/main.m +++ b/examples/speech-to-text/ios/speechtotext/main.m @@ -2,9 +2,9 @@ #import "AppDelegate.h" -int main(int argc, char * argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } - diff --git a/examples/speech-to-text/ios/speechtotext/speechtotext-Bridging-Header.h b/examples/speech-to-text/ios/speechtotext/speechtotext-Bridging-Header.h index e11d920b..339994e9 100644 --- a/examples/speech-to-text/ios/speechtotext/speechtotext-Bridging-Header.h +++ b/examples/speech-to-text/ios/speechtotext/speechtotext-Bridging-Header.h @@ -1,3 +1,4 @@ // -// Use this file to import your target's public headers that you would like to expose to Swift. +// Use this file to import your target's public headers that you would like to +// expose to Swift. // diff --git a/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/ETModel.h b/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/ETModel.h index 2c7477c1..79b547ad 100644 --- a/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/ETModel.h +++ b/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/ETModel.h @@ -22,7 +22,6 @@ - (NSNumber *)getOutputType:(NSNumber *)index; - (NSArray *)getOutputShape:(NSNumber *)index; - @end #endif // ETModel_hpp diff --git a/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h b/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h index 39e867d0..e269d041 100644 --- a/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h +++ b/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h @@ -16,13 +16,13 @@ FOUNDATION_EXPORT NSErrorDomain const LLaVARunnerErrorDomain; NS_SWIFT_NAME(Runner) @interface LLaMARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(NSString*)prompt - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(NSString *)prompt + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; @@ -33,17 +33,17 @@ NS_SWIFT_NAME(Runner) NS_SWIFT_NAME(LLaVARunner) @interface LLaVARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(void*)imageBuffer +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(void *)imageBuffer width:(CGFloat)width height:(CGFloat)height - prompt:(NSString*)prompt + prompt:(NSString *)prompt sequenceLength:(NSInteger)seq_len - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; diff --git a/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/ETModel.h b/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/ETModel.h index 2c7477c1..79b547ad 100644 --- a/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/ETModel.h +++ b/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/ETModel.h @@ -22,7 +22,6 @@ - (NSNumber *)getOutputType:(NSNumber *)index; - (NSArray *)getOutputShape:(NSNumber *)index; - @end #endif // ETModel_hpp diff --git a/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h b/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h index 39e867d0..e269d041 100644 --- a/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h +++ b/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h @@ -16,13 +16,13 @@ FOUNDATION_EXPORT NSErrorDomain const LLaVARunnerErrorDomain; NS_SWIFT_NAME(Runner) @interface LLaMARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(NSString*)prompt - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(NSString *)prompt + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; @@ -33,17 +33,17 @@ NS_SWIFT_NAME(Runner) NS_SWIFT_NAME(LLaVARunner) @interface LLaVARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(void*)imageBuffer +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(void *)imageBuffer width:(CGFloat)width height:(CGFloat)height - prompt:(NSString*)prompt + prompt:(NSString *)prompt sequenceLength:(NSInteger)seq_len - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; diff --git a/ios/RnExecutorch/SpeechToText.mm b/ios/RnExecutorch/SpeechToText.mm index 1e89f5c9..54589d9e 100644 --- a/ios/RnExecutorch/SpeechToText.mm +++ b/ios/RnExecutorch/SpeechToText.mm @@ -1,13 +1,13 @@ #import "SpeechToText.h" +#import "./utils/ScalarType.h" #import "models/BaseModel.h" -#import -#import "models/stt/Whisper.hpp" #import "models/stt/Moonshine.hpp" +#import "models/stt/SpeechToTextBaseModel.hpp" +#import "models/stt/Whisper.hpp" #import "utils/SFFT.hpp" +#import #import #import -#import "./utils/ScalarType.h" -#import "models/stt/SpeechToTextBaseModel.hpp" @implementation SpeechToText { Whisper *whisper; @@ -20,17 +20,19 @@ - (void)generate:(NSArray *)waveform resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { @try { - SpeechToTextBaseModel* model = self->whisper ? self->whisper : self->moonshine; + SpeechToTextBaseModel *model = + self->whisper ? self->whisper : self->moonshine; dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSArray *encodingResult = [model encode:waveform]; - NSMutableArray *mutablePrevTokens = [NSMutableArray arrayWithObject:model->START_TOKEN]; + NSMutableArray *mutablePrevTokens = + [NSMutableArray arrayWithObject:model->START_TOKEN]; NSNumber *currentSeqLen = @0; - while ([currentSeqLen unsignedIntegerValue] < model->maxSeqLen) { + while ([currentSeqLen unsignedIntegerValue] < model -> maxSeqLen) { NSArray *result = [model decode:mutablePrevTokens - encoderLastHiddenState:encodingResult]; + encoderLastHiddenState:encodingResult]; if (!result || result.count == 0) { reject(@"forward_error", @"Decoder returned an empty result.", nil); @@ -54,7 +56,7 @@ - (void)generate:(NSArray *)waveform } - (void)loadModule:(NSString *)modelName - modelSources:(NSArray*)modelSources + modelSources:(NSArray *)modelSources resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { @@ -62,17 +64,17 @@ - (void)loadModule:(NSString *)modelName reject(@"corrupted model sources", nil, nil); return; } - if (![@[@"moonshine", @"whisper"] containsObject:modelName]) { - reject(@"invalid_model_identifier", nil, nil); - return; + if (![@[ @"moonshine", @"whisper" ] containsObject:modelName]) { + reject(@"invalid_model_identifier", nil, nil); + return; } - SpeechToTextBaseModel* model; - if([modelName isEqualToString:@"moonshine"]) { + SpeechToTextBaseModel *model; + if ([modelName isEqualToString:@"moonshine"]) { moonshine = [[Moonshine alloc] init]; model = moonshine; } - if([modelName isEqualToString:@"whisper"]) { + if ([modelName isEqualToString:@"whisper"]) { whisper = [[Whisper alloc] init]; model = whisper; } @@ -81,14 +83,16 @@ - (void)loadModule:(NSString *)modelName [model loadModules:modelSources]; resolve(@(0)); } @catch (NSException *exception) { - reject(@"init_decoder_error", [NSString stringWithFormat:@"%@", exception.reason], nil); + reject(@"init_decoder_error", + [NSString stringWithFormat:@"%@", exception.reason], nil); } } - (void)encode:(NSArray *)input resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { - SpeechToTextBaseModel* model = self->whisper ? self->whisper : self->moonshine; + SpeechToTextBaseModel *model = + self->whisper ? self->whisper : self->moonshine; @try { NSArray *encodingResult = [model encode:input]; resolve(encodingResult); @@ -102,10 +106,11 @@ - (void)decode:(NSArray *)prevTokens encoderOutput:(NSArray *)encoderOutput resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { - SpeechToTextBaseModel* model = self->whisper ? self->whisper : self->moonshine; + SpeechToTextBaseModel *model = + self->whisper ? self->whisper : self->moonshine; @try { NSArray *token = [model decode:prevTokens - encoderLastHiddenState:encoderOutput]; + encoderLastHiddenState:encoderOutput]; resolve(token); } @catch (NSException *exception) { reject(@"forward_error", diff --git a/ios/RnExecutorch/VerticalOCR.mm b/ios/RnExecutorch/VerticalOCR.mm index ef5e58a2..843fcd23 100644 --- a/ios/RnExecutorch/VerticalOCR.mm +++ b/ios/RnExecutorch/VerticalOCR.mm @@ -1,13 +1,13 @@ #import "VerticalOCR.h" -#import "models/ocr/VerticalDetector.h" #import "models/ocr/RecognitionHandler.h" #import "models/ocr/Recognizer.h" +#import "models/ocr/VerticalDetector.h" +#import "models/ocr/utils/CTCLabelConverter.h" +#import "models/ocr/utils/OCRUtils.h" #import "models/ocr/utils/RecognizerUtils.h" #import "utils/ImageProcessor.h" #import #import -#import "models/ocr/utils/OCRUtils.h" -#import "models/ocr/utils/CTCLabelConverter.h" @implementation VerticalOCR { VerticalDetector *detectorLarge; @@ -20,47 +20,48 @@ @implementation VerticalOCR { RCT_EXPORT_MODULE() - (void)loadModule:(NSString *)detectorLargeSource -detectorNarrowSource:(NSString *)detectorNarrowSource - recognizerSource:(NSString *)recognizerSource - symbols:(NSString *)symbols -independentCharacters:(BOOL)independentCharacters - resolve:(RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject { + detectorNarrowSource:(NSString *)detectorNarrowSource + recognizerSource:(NSString *)recognizerSource + symbols:(NSString *)symbols + independentCharacters:(BOOL)independentCharacters + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject { detectorLarge = [[VerticalDetector alloc] initWithDetectSingleCharacters:NO]; - converter = [[CTCLabelConverter alloc] initWithCharacters:symbols separatorList:@{}]; + converter = [[CTCLabelConverter alloc] initWithCharacters:symbols + separatorList:@{}]; self->independentCharacters = independentCharacters; [detectorLarge - loadModel:[NSURL URLWithString:detectorLargeSource] - completion:^(BOOL success, NSNumber *errorCode) { - if (!success) { - reject(@"init_module_error", @"Failed to initialize detector module", - nil); - return; - } - self->detectorNarrow = [[VerticalDetector alloc] initWithDetectSingleCharacters:YES]; - [self->detectorNarrow - loadModel:[NSURL URLWithString:detectorNarrowSource] - completion:^(BOOL success, NSNumber *errorCode) { - if (!success) { - reject(@"init_module_error", - @"Failed to initialize detector module", nil); - return; - } - - self->recognizer = [[Recognizer alloc] init]; - [self->recognizer - loadModel:[NSURL URLWithString:recognizerSource] - completion:^(BOOL success, NSNumber *errorCode) { + loadModel:[NSURL URLWithString:detectorLargeSource] + completion:^(BOOL success, NSNumber *errorCode) { if (!success) { - reject(@"init_module_error", - @"Failed to initialize recognizer module", nil); + reject(@"init_module_error", @"Failed to initialize detector module", + nil); + return; } - - resolve(@(YES)); + self->detectorNarrow = + [[VerticalDetector alloc] initWithDetectSingleCharacters:YES]; + [self->detectorNarrow + loadModel:[NSURL URLWithString:detectorNarrowSource] + completion:^(BOOL success, NSNumber *errorCode) { + if (!success) { + reject(@"init_module_error", + @"Failed to initialize detector module", nil); + return; + } + + self->recognizer = [[Recognizer alloc] init]; + [self->recognizer + loadModel:[NSURL URLWithString:recognizerSource] + completion:^(BOOL success, NSNumber *errorCode) { + if (!success) { + reject(@"init_module_error", + @"Failed to initialize recognizer module", nil); + } + + resolve(@(YES)); + }]; + }]; }]; - }]; - }]; - } - (void)forward:(NSString *)input @@ -70,77 +71,103 @@ - (void)forward:(NSString *)input cv::Mat image = [ImageProcessor readImage:input]; NSArray *result = [detectorLarge runModel:image]; cv::Size largeDetectorSize = [detectorLarge getModelImageSize]; - cv::Mat resizedImage = [OCRUtils resizeWithPadding:image desiredWidth:largeDetectorSize.width desiredHeight:largeDetectorSize.height]; + cv::Mat resizedImage = + [OCRUtils resizeWithPadding:image + desiredWidth:largeDetectorSize.width + desiredHeight:largeDetectorSize.height]; NSMutableArray *predictions = [NSMutableArray array]; - - for (NSDictionary *box in result){ + + for (NSDictionary *box in result) { NSArray *cords = box[@"bbox"]; - const int boxWidth = [[cords objectAtIndex:2] CGPointValue].x - [[cords objectAtIndex:0] CGPointValue].x; - const int boxHeight = [[cords objectAtIndex:2] CGPointValue].y - [[cords objectAtIndex:0] CGPointValue].y; - + const int boxWidth = [[cords objectAtIndex:2] CGPointValue].x - + [[cords objectAtIndex:0] CGPointValue].x; + const int boxHeight = [[cords objectAtIndex:2] CGPointValue].y - + [[cords objectAtIndex:0] CGPointValue].y; + cv::Rect boundingBox = [OCRUtils extractBoundingBox:cords]; cv::Mat croppedImage = resizedImage(boundingBox); - NSDictionary *paddings = - [RecognizerUtils calculateResizeRatioAndPaddings:image.cols - height:image.rows - desiredWidth:largeDetectorSize.width - desiredHeight:largeDetectorSize.height]; - + NSDictionary *paddings = [RecognizerUtils + calculateResizeRatioAndPaddings:image.cols + height:image.rows + desiredWidth:largeDetectorSize.width + desiredHeight:largeDetectorSize.height]; + NSString *text = @""; NSNumber *confidenceScore = @0.0; NSArray *boxResult = [detectorNarrow runModel:croppedImage]; std::vector croppedCharacters; cv::Size narrowRecognizerSize = [detectorNarrow getModelImageSize]; - for(NSDictionary *characterBox in boxResult){ + for (NSDictionary *characterBox in boxResult) { NSArray *boxCords = characterBox[@"bbox"]; - NSDictionary *paddingsBox = [RecognizerUtils calculateResizeRatioAndPaddings:boxWidth height:boxHeight desiredWidth:narrowRecognizerSize.width desiredHeight:narrowRecognizerSize.height]; - cv::Mat croppedCharacter = [RecognizerUtils cropImageWithBoundingBox:image bbox:boxCords originalBbox:cords paddings:paddingsBox originalPaddings:paddings]; - if(self->independentCharacters){ - croppedCharacter = [RecognizerUtils cropSingleCharacter:croppedCharacter]; - croppedCharacter = [RecognizerUtils normalizeForRecognizer:croppedCharacter adjustContrast:0.0 isVertical: YES]; + NSDictionary *paddingsBox = [RecognizerUtils + calculateResizeRatioAndPaddings:boxWidth + height:boxHeight + desiredWidth:narrowRecognizerSize.width + desiredHeight:narrowRecognizerSize.height]; + cv::Mat croppedCharacter = + [RecognizerUtils cropImageWithBoundingBox:image + bbox:boxCords + originalBbox:cords + paddings:paddingsBox + originalPaddings:paddings]; + if (self->independentCharacters) { + croppedCharacter = + [RecognizerUtils cropSingleCharacter:croppedCharacter]; + croppedCharacter = + [RecognizerUtils normalizeForRecognizer:croppedCharacter + adjustContrast:0.0 + isVertical:YES]; NSArray *recognitionResult = [recognizer runModel:croppedCharacter]; NSArray *predIndex = [recognitionResult objectAtIndex:0]; - NSArray *decodedText = [converter decodeGreedy: predIndex length:(int)(predIndex.count)]; + NSArray *decodedText = + [converter decodeGreedy:predIndex length:(int)(predIndex.count)]; text = [text stringByAppendingString:decodedText[0]]; - confidenceScore = @([confidenceScore floatValue] + [[recognitionResult objectAtIndex:1] floatValue]); - }else{ + confidenceScore = @([confidenceScore floatValue] + + [[recognitionResult objectAtIndex:1] floatValue]); + } else { croppedCharacters.push_back(croppedCharacter); } } - - if(self->independentCharacters){ + + if (self->independentCharacters) { confidenceScore = @([confidenceScore floatValue] / boxResult.count); - }else{ + } else { cv::Mat mergedCharacters; - cv::hconcat(croppedCharacters.data(), (int)croppedCharacters.size(), mergedCharacters); - mergedCharacters = [OCRUtils resizeWithPadding:mergedCharacters desiredWidth:largeRecognizerWidth desiredHeight:recognizerHeight]; - mergedCharacters = [RecognizerUtils normalizeForRecognizer:mergedCharacters adjustContrast:0.0 isVertical: NO]; + cv::hconcat(croppedCharacters.data(), (int)croppedCharacters.size(), + mergedCharacters); + mergedCharacters = [OCRUtils resizeWithPadding:mergedCharacters + desiredWidth:largeRecognizerWidth + desiredHeight:recognizerHeight]; + mergedCharacters = + [RecognizerUtils normalizeForRecognizer:mergedCharacters + adjustContrast:0.0 + isVertical:NO]; NSArray *recognitionResult = [recognizer runModel:mergedCharacters]; NSArray *predIndex = [recognitionResult objectAtIndex:0]; - NSArray *decodedText = [converter decodeGreedy: predIndex length:(int)(predIndex.count)]; + NSArray *decodedText = [converter decodeGreedy:predIndex + length:(int)(predIndex.count)]; text = [text stringByAppendingString:decodedText[0]]; - confidenceScore = @([confidenceScore floatValue] + [[recognitionResult objectAtIndex:1] floatValue]); + confidenceScore = @([confidenceScore floatValue] + + [[recognitionResult objectAtIndex:1] floatValue]); } - + NSMutableArray *newCoords = [NSMutableArray arrayWithCapacity:4]; - for (NSValue *cord in cords){ + for (NSValue *cord in cords) { const CGPoint point = [cord CGPointValue]; - + [newCoords addObject:@{ - @"x" : @((point.x - [paddings[@"left"] intValue]) * [paddings[@"resizeRatio"] floatValue]), - @"y" : @((point.y - [paddings[@"top"] intValue]) * [paddings[@"resizeRatio"] floatValue]) + @"x" : @((point.x - [paddings[@"left"] intValue]) * + [paddings[@"resizeRatio"] floatValue]), + @"y" : @((point.y - [paddings[@"top"] intValue]) * + [paddings[@"resizeRatio"] floatValue]) }]; } - - NSDictionary *res = @{ - @"text" : text, - @"bbox" : newCoords, - @"score" : confidenceScore - }; + + NSDictionary *res = + @{@"text" : text, @"bbox" : newCoords, @"score" : confidenceScore}; [predictions addObject:res]; } - - + resolve(predictions); } @catch (NSException *exception) { reject(@"forward_error", @@ -149,7 +176,7 @@ - (void)forward:(NSString *)input } - (std::shared_ptr)getTurboModule: -(const facebook::react::ObjCTurboModule::InitParams &)params { + (const facebook::react::ObjCTurboModule::InitParams &)params { return std::make_shared(params); } diff --git a/ios/RnExecutorch/models/BaseModel.mm b/ios/RnExecutorch/models/BaseModel.mm index e39dab8c..3e0a8fbe 100644 --- a/ios/RnExecutorch/models/BaseModel.mm +++ b/ios/RnExecutorch/models/BaseModel.mm @@ -13,7 +13,9 @@ - (NSArray *)forward:(NSArray *)input { [inputTypes addObject:[module getInputType:[NSNumber numberWithInt:i]]]; } - NSArray *result = [module forward:@[input] shapes:shapes inputTypes:inputTypes]; + NSArray *result = [module forward:@[ input ] + shapes:shapes + inputTypes:inputTypes]; return result; } @@ -28,7 +30,10 @@ - (NSArray *)execute:(NSString *)methodName inputs:(NSArray *)inputs shapes:(NSArray *)shapes inputTypes:(NSArray *)inputTypes { - NSArray *result = [module execute:methodName inputs:inputs shapes:shapes inputTypes:inputTypes]; + NSArray *result = [module execute:methodName + inputs:inputs + shapes:shapes + inputTypes:inputTypes]; return result; } diff --git a/ios/RnExecutorch/models/classification/Constants.mm b/ios/RnExecutorch/models/classification/Constants.mm index c83b4d4e..92e6284b 100644 --- a/ios/RnExecutorch/models/classification/Constants.mm +++ b/ios/RnExecutorch/models/classification/Constants.mm @@ -2,1004 +2,1017 @@ #import const std::string imagenet1k_v1_labels[] = { - "tench, Tinca tinca", - "goldfish, Carassius auratus", - "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias", - "tiger shark, Galeocerdo cuvieri", - "hammerhead, hammerhead shark", - "electric ray, crampfish, numbfish, torpedo", - "stingray", - "cock", - "hen", - "ostrich, Struthio camelus", - "brambling, Fringilla montifringilla", - "goldfinch, Carduelis carduelis", - "house finch, linnet, Carpodacus mexicanus", - "junco, snowbird", - "indigo bunting, indigo finch, indigo bird, Passerina cyanea", - "robin, American robin, Turdus migratorius", - "bulbul", - "jay", - "magpie", - "chickadee", - "water ouzel, dipper", - "kite", - "bald eagle, American eagle, Haliaeetus leucocephalus", - "vulture", - "great grey owl, great gray owl, Strix nebulosa", - "European fire salamander, Salamandra salamandra", - "common newt, Triturus vulgaris", - "eft", - "spotted salamander, Ambystoma maculatum", - "axolotl, mud puppy, Ambystoma mexicanum", - "bullfrog, Rana catesbeiana", - "tree frog, tree-frog", - "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui", - "loggerhead, loggerhead turtle, Caretta caretta", - "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea", - "mud turtle", - "terrapin", - "box turtle, box tortoise", - "banded gecko", - "common iguana, iguana, Iguana iguana", - "American chameleon, anole, Anolis carolinensis", - "whiptail, whiptail lizard", - "agama", - "frilled lizard, Chlamydosaurus kingi", - "alligator lizard", - "Gila monster, Heloderma suspectum", - "green lizard, Lacerta viridis", - "African chameleon, Chamaeleo chamaeleon", - "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis", - "African crocodile, Nile crocodile, Crocodylus niloticus", - "American alligator, Alligator mississipiensis", - "triceratops", - "thunder snake, worm snake, Carphophis amoenus", - "ringneck snake, ring-necked snake, ring snake", - "hognose snake, puff adder, sand viper", - "green snake, grass snake", - "king snake, kingsnake", - "garter snake, grass snake", - "water snake", - "vine snake", - "night snake, Hypsiglena torquata", - "boa constrictor, Constrictor constrictor", - "rock python, rock snake, Python sebae", - "Indian cobra, Naja naja", - "green mamba", - "sea snake", - "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus", - "diamondback, diamondback rattlesnake, Crotalus adamanteus", - "sidewinder, horned rattlesnake, Crotalus cerastes", - "trilobite", - "harvestman, daddy longlegs, Phalangium opilio", - "scorpion", - "black and gold garden spider, Argiope aurantia", - "barn spider, Araneus cavaticus", - "garden spider, Aranea diademata", - "black widow, Latrodectus mactans", - "tarantula", - "wolf spider, hunting spider", - "tick", - "centipede", - "black grouse", - "ptarmigan", - "ruffed grouse, partridge, Bonasa umbellus", - "prairie chicken, prairie grouse, prairie fowl", - "peacock", - "quail", - "partridge", - "African grey, African gray, Psittacus erithacus", - "macaw", - "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita", - "lorikeet", - "coucal", - "bee eater", - "hornbill", - "hummingbird", - "jacamar", - "toucan", - "drake", - "red-breasted merganser, Mergus serrator", - "goose", - "black swan, Cygnus atratus", - "tusker", - "echidna, spiny anteater, anteater", - "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus", - "wallaby, brush kangaroo", - "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus", - "wombat", - "jellyfish", - "sea anemone, anemone", - "brain coral", - "flatworm, platyhelminth", - "nematode, nematode worm, roundworm", - "conch", - "snail", - "slug", - "sea slug, nudibranch", - "chiton, coat-of-mail shell, sea cradle, polyplacophore", - "chambered nautilus, pearly nautilus, nautilus", - "Dungeness crab, Cancer magister", - "rock crab, Cancer irroratus", - "fiddler crab", - "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica", - "American lobster, Northern lobster, Maine lobster, Homarus americanus", - "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish", - "crayfish, crawfish, crawdad, crawdaddy", - "hermit crab", - "isopod", - "white stork, Ciconia ciconia", - "black stork, Ciconia nigra", - "spoonbill", - "flamingo", - "little blue heron, Egretta caerulea", - "American egret, great white heron, Egretta albus", - "bittern", - "crane", - "limpkin, Aramus pictus", - "European gallinule, Porphyrio porphyrio", - "American coot, marsh hen, mud hen, water hen, Fulica americana", - "bustard", - "ruddy turnstone, Arenaria interpres", - "red-backed sandpiper, dunlin, Erolia alpina", - "redshank, Tringa totanus", - "dowitcher", - "oystercatcher, oyster catcher", - "pelican", - "king penguin, Aptenodytes patagonica", - "albatross, mollymawk", - "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus", - "killer whale, killer, orca, grampus, sea wolf, Orcinus orca", - "dugong, Dugong dugon", - "sea lion", - "Chihuahua", - "Japanese spaniel", - "Maltese dog, Maltese terrier, Maltese", - "Pekinese, Pekingese, Peke", - "Shih-Tzu", - "Blenheim spaniel", - "papillon", - "toy terrier", - "Rhodesian ridgeback", - "Afghan hound, Afghan", - "basset, basset hound", - "beagle", - "bloodhound, sleuthhound", - "bluetick", - "black-and-tan coonhound", - "Walker hound, Walker foxhound", - "English foxhound", - "redbone", - "borzoi, Russian wolfhound", - "Irish wolfhound", - "Italian greyhound", - "whippet", - "Ibizan hound, Ibizan Podenco", - "Norwegian elkhound, elkhound", - "otterhound, otter hound", - "Saluki, gazelle hound", - "Scottish deerhound, deerhound", - "Weimaraner", - "Staffordshire bullterrier, Staffordshire bull terrier", - "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier", - "Bedlington terrier", - "Border terrier", - "Kerry blue terrier", - "Irish terrier", - "Norfolk terrier", - "Norwich terrier", - "Yorkshire terrier", - "wire-haired fox terrier", - "Lakeland terrier", - "Sealyham terrier, Sealyham", - "Airedale, Airedale terrier", - "cairn, cairn terrier", - "Australian terrier", - "Dandie Dinmont, Dandie Dinmont terrier", - "Boston bull, Boston terrier", - "miniature schnauzer", - "giant schnauzer", - "standard schnauzer", - "Scotch terrier, Scottish terrier, Scottie", - "Tibetan terrier, chrysanthemum dog", - "silky terrier, Sydney silky", - "soft-coated wheaten terrier", - "West Highland white terrier", - "Lhasa, Lhasa apso", - "flat-coated retriever", - "curly-coated retriever", - "golden retriever", - "Labrador retriever", - "Chesapeake Bay retriever", - "German short-haired pointer", - "vizsla, Hungarian pointer", - "English setter", - "Irish setter, red setter", - "Gordon setter", - "Brittany spaniel", - "clumber, clumber spaniel", - "English springer, English springer spaniel", - "Welsh springer spaniel", - "cocker spaniel, English cocker spaniel, cocker", - "Sussex spaniel", - "Irish water spaniel", - "kuvasz", - "schipperke", - "groenendael", - "malinois", - "briard", - "kelpie", - "komondor", - "Old English sheepdog, bobtail", - "Shetland sheepdog, Shetland sheep dog, Shetland", - "collie", - "Border collie", - "Bouvier des Flandres, Bouviers des Flandres", - "Rottweiler", - "German shepherd, German shepherd dog, German police dog, alsatian", - "Doberman, Doberman pinscher", - "miniature pinscher", - "Greater Swiss Mountain dog", - "Bernese mountain dog", - "Appenzeller", - "EntleBucher", - "boxer", - "bull mastiff", - "Tibetan mastiff", - "French bulldog", - "Great Dane", - "Saint Bernard, St Bernard", - "Eskimo dog, husky", - "malamute, malemute, Alaskan malamute", - "Siberian husky", - "dalmatian, coach dog, carriage dog", - "affenpinscher, monkey pinscher, monkey dog", - "basenji", - "pug, pug-dog", - "Leonberg", - "Newfoundland, Newfoundland dog", - "Great Pyrenees", - "Samoyed, Samoyede", - "Pomeranian", - "chow, chow chow", - "keeshond", - "Brabancon griffon", - "Pembroke, Pembroke Welsh corgi", - "Cardigan, Cardigan Welsh corgi", - "toy poodle", - "miniature poodle", - "standard poodle", - "Mexican hairless", - "timber wolf, grey wolf, gray wolf, Canis lupus", - "white wolf, Arctic wolf, Canis lupus tundrarum", - "red wolf, maned wolf, Canis rufus, Canis niger", - "coyote, prairie wolf, brush wolf, Canis latrans", - "dingo, warrigal, warragal, Canis dingo", - "dhole, Cuon alpinus", - "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus", - "hyena, hyaena", - "red fox, Vulpes vulpes", - "kit fox, Vulpes macrotis", - "Arctic fox, white fox, Alopex lagopus", - "grey fox, gray fox, Urocyon cinereoargenteus", - "tabby, tabby cat", - "tiger cat", - "Persian cat", - "Siamese cat, Siamese", - "Egyptian cat", - "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor", - "lynx, catamount", - "leopard, Panthera pardus", - "snow leopard, ounce, Panthera uncia", - "jaguar, panther, Panthera onca, Felis onca", - "lion, king of beasts, Panthera leo", - "tiger, Panthera tigris", - "cheetah, chetah, Acinonyx jubatus", - "brown bear, bruin, Ursus arctos", - "American black bear, black bear, Ursus americanus, Euarctos americanus", - "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus", - "sloth bear, Melursus ursinus, Ursus ursinus", - "mongoose", - "meerkat, mierkat", - "tiger beetle", - "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle", - "ground beetle, carabid beetle", - "long-horned beetle, longicorn, longicorn beetle", - "leaf beetle, chrysomelid", - "dung beetle", - "rhinoceros beetle", - "weevil", - "fly", - "bee", - "ant, emmet, pismire", - "grasshopper, hopper", - "cricket", - "walking stick, walkingstick, stick insect", - "cockroach, roach", - "mantis, mantid", - "cicada, cicala", - "leafhopper", - "lacewing, lacewing fly", - "dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk", - "damselfly", - "admiral", - "ringlet, ringlet butterfly", - "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus", - "cabbage butterfly", - "sulphur butterfly, sulfur butterfly", - "lycaenid, lycaenid butterfly", - "starfish, sea star", - "sea urchin", - "sea cucumber, holothurian", - "wood rabbit, cottontail, cottontail rabbit", - "hare", - "Angora, Angora rabbit", - "hamster", - "porcupine, hedgehog", - "fox squirrel, eastern fox squirrel, Sciurus niger", - "marmot", - "beaver", - "guinea pig, Cavia cobaya", - "sorrel", - "zebra", - "hog, pig, grunter, squealer, Sus scrofa", - "wild boar, boar, Sus scrofa", - "warthog", - "hippopotamus, hippo, river horse, Hippopotamus amphibius", - "ox", - "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis", - "bison", - "ram, tup", - "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis", - "ibex, Capra ibex", - "hartebeest", - "impala, Aepyceros melampus", - "gazelle", - "Arabian camel, dromedary, Camelus dromedarius", - "llama", - "weasel", - "mink", - "polecat, fitch, foulmart, foumart, Mustela putorius", - "black-footed ferret, ferret, Mustela nigripes", - "otter", - "skunk, polecat, wood pussy", - "badger", - "armadillo", - "three-toed sloth, ai, Bradypus tridactylus", - "orangutan, orang, orangutang, Pongo pygmaeus", - "gorilla, Gorilla gorilla", - "chimpanzee, chimp, Pan troglodytes", - "gibbon, Hylobates lar", - "siamang, Hylobates syndactylus, Symphalangus syndactylus", - "guenon, guenon monkey", - "patas, hussar monkey, Erythrocebus patas", - "baboon", - "macaque", - "langur", - "colobus, colobus monkey", - "proboscis monkey, Nasalis larvatus", - "marmoset", - "capuchin, ringtail, Cebus capucinus", - "howler monkey, howler", - "titi, titi monkey", - "spider monkey, Ateles geoffroyi", - "squirrel monkey, Saimiri sciureus", - "Madagascar cat, ring-tailed lemur, Lemur catta", - "indri, indris, Indri indri, Indri brevicaudatus", - "Indian elephant, Elephas maximus", - "African elephant, Loxodonta africana", - "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens", - "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca", - "barracouta, snoek", - "eel", - "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch", - "rock beauty, Holocanthus tricolor", - "anemone fish", - "sturgeon", - "gar, garfish, garpike, billfish, Lepisosteus osseus", - "lionfish", - "puffer, pufferfish, blowfish, globefish", - "abacus", - "abaya", - "academic gown, academic robe, judge's robe", - "accordion, piano accordion, squeeze box", - "acoustic guitar", - "aircraft carrier, carrier, flattop, attack aircraft carrier", - "airliner", - "airship, dirigible", - "altar", - "ambulance", - "amphibian, amphibious vehicle", - "analog clock", - "apiary, bee house", - "apron", - "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin", - "assault rifle, assault gun", - "backpack, back pack, knapsack, packsack, rucksack, haversack", - "bakery, bakeshop, bakehouse", - "balance beam, beam", - "balloon", - "ballpoint, ballpoint pen, ballpen, Biro", - "Band Aid", - "banjo", - "bannister, banister, balustrade, balusters, handrail", - "barbell", - "barber chair", - "barbershop", - "barn", - "barometer", - "barrel, cask", - "barrow, garden cart, lawn cart, wheelbarrow", - "baseball", - "basketball", - "bassinet", - "bassoon", - "bathing cap, swimming cap", - "bath towel", - "bathtub, bathing tub, bath, tub", - "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon", - "beacon, lighthouse, beacon light, pharos", - "beaker", - "bearskin, busby, shako", - "beer bottle", - "beer glass", - "bell cote, bell cot", - "bib", - "bicycle-built-for-two, tandem bicycle, tandem", - "bikini, two-piece", - "binder, ring-binder", - "binoculars, field glasses, opera glasses", - "birdhouse", - "boathouse", - "bobsled, bobsleigh, bob", - "bolo tie, bolo, bola tie, bola", - "bonnet, poke bonnet", - "bookcase", - "bookshop, bookstore, bookstall", - "bottlecap", - "bow", - "bow tie, bow-tie, bowtie", - "brass, memorial tablet, plaque", - "brassiere, bra, bandeau", - "breakwater, groin, groyne, mole, bulwark, seawall, jetty", - "breastplate, aegis, egis", - "broom", - "bucket, pail", - "buckle", - "bulletproof vest", - "bullet train, bullet", - "butcher shop, meat market", - "cab, hack, taxi, taxicab", - "caldron, cauldron", - "candle, taper, wax light", - "cannon", - "canoe", - "can opener, tin opener", - "cardigan", - "car mirror", - "carousel, carrousel, merry-go-round, roundabout, whirligig", - "carpenter's kit, tool kit", - "carton", - "car wheel", - "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM", - "cassette", - "cassette player", - "castle", - "catamaran", - "CD player", - "cello, violoncello", - "cellular telephone, cellular phone, cellphone, cell, mobile phone", - "chain", - "chainlink fence", - "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour", - "chain saw, chainsaw", - "chest", - "chiffonier, commode", - "chime, bell, gong", - "china cabinet, china closet", - "Christmas stocking", - "church, church building", - "cinema, movie theater, movie theatre, movie house, picture palace", - "cleaver, meat cleaver, chopper", - "cliff dwelling", - "cloak", - "clog, geta, patten, sabot", - "cocktail shaker", - "coffee mug", - "coffeepot", - "coil, spiral, volute, whorl, helix", - "combination lock", - "computer keyboard, keypad", - "confectionery, confectionary, candy store", - "container ship, containership, container vessel", - "convertible", - "corkscrew, bottle screw", - "cornet, horn, trumpet, trump", - "cowboy boot", - "cowboy hat, ten-gallon hat", - "cradle", - "crane", - "crash helmet", - "crate", - "crib, cot", - "Crock Pot", - "croquet ball", - "crutch", - "cuirass", - "dam, dike, dyke", - "desk", - "desktop computer", - "dial telephone, dial phone", - "diaper, nappy, napkin", - "digital clock", - "digital watch", - "dining table, board", - "dishrag, dishcloth", - "dishwasher, dish washer, dishwashing machine", - "disk brake, disc brake", - "dock, dockage, docking facility", - "dogsled, dog sled, dog sleigh", - "dome", - "doormat, welcome mat", - "drilling platform, offshore rig", - "drum, membranophone, tympan", - "drumstick", - "dumbbell", - "Dutch oven", - "electric fan, blower", - "electric guitar", - "electric locomotive", - "entertainment center", - "envelope", - "espresso maker", - "face powder", - "feather boa, boa", - "file, file cabinet, filing cabinet", - "fireboat", - "fire engine, fire truck", - "fire screen, fireguard", - "flagpole, flagstaff", - "flute, transverse flute", - "folding chair", - "football helmet", - "forklift", - "fountain", - "fountain pen", - "four-poster", - "freight car", - "French horn, horn", - "frying pan, frypan, skillet", - "fur coat", - "garbage truck, dustcart", - "gasmask, respirator, gas helmet", - "gas pump, gasoline pump, petrol pump, island dispenser", - "goblet", - "go-kart", - "golf ball", - "golfcart, golf cart", - "gondola", - "gong, tam-tam", - "gown", - "grand piano, grand", - "greenhouse, nursery, glasshouse", - "grille, radiator grille", - "grocery store, grocery, food market, market", - "guillotine", - "hair slide", - "hair spray", - "half track", - "hammer", - "hamper", - "hand blower, blow dryer, blow drier, hair dryer, hair drier", - "hand-held computer, hand-held microcomputer", - "handkerchief, hankie, hanky, hankey", - "hard disc, hard disk, fixed disk", - "harmonica, mouth organ, harp, mouth harp", - "harp", - "harvester, reaper", - "hatchet", - "holster", - "home theater, home theatre", - "honeycomb", - "hook, claw", - "hoopskirt, crinoline", - "horizontal bar, high bar", - "horse cart, horse-cart", - "hourglass", - "iPod", - "iron, smoothing iron", - "jack-o'-lantern", - "jean, blue jean, denim", - "jeep, landrover", - "jersey, T-shirt, tee shirt", - "jigsaw puzzle", - "jinrikisha, ricksha, rickshaw", - "joystick", - "kimono", - "knee pad", - "knot", - "lab coat, laboratory coat", - "ladle", - "lampshade, lamp shade", - "laptop, laptop computer", - "lawn mower, mower", - "lens cap, lens cover", - "letter opener, paper knife, paperknife", - "library", - "lifeboat", - "lighter, light, igniter, ignitor", - "limousine, limo", - "liner, ocean liner", - "lipstick, lip rouge", - "Loafer", - "lotion", - "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system", - "loupe, jeweler's loupe", - "lumbermill, sawmill", - "magnetic compass", - "mailbag, postbag", - "mailbox, letter box", - "maillot", - "maillot, tank suit", - "manhole cover", - "maraca", - "marimba, xylophone", - "mask", - "matchstick", - "maypole", - "maze, labyrinth", - "measuring cup", - "medicine chest, medicine cabinet", - "megalith, megalithic structure", - "microphone, mike", - "microwave, microwave oven", - "military uniform", - "milk can", - "minibus", - "miniskirt, mini", - "minivan", - "missile", - "mitten", - "mixing bowl", - "mobile home, manufactured home", - "Model T", - "modem", - "monastery", - "monitor", - "moped", - "mortar", - "mortarboard", - "mosque", - "mosquito net", - "motor scooter, scooter", - "mountain bike, all-terrain bike, off-roader", - "mountain tent", - "mouse, computer mouse", - "mousetrap", - "moving van", - "muzzle", - "nail", - "neck brace", - "necklace", - "nipple", - "notebook, notebook computer", - "obelisk", - "oboe, hautboy, hautbois", - "ocarina, sweet potato", - "odometer, hodometer, mileometer, milometer", - "oil filter", - "organ, pipe organ", - "oscilloscope, scope, cathode-ray oscilloscope, CRO", - "overskirt", - "oxcart", - "oxygen mask", - "packet", - "paddle, boat paddle", - "paddlewheel, paddle wheel", - "padlock", - "paintbrush", - "pajama, pyjama, pj's, jammies", - "palace", - "panpipe, pandean pipe, syrinx", - "paper towel", - "parachute, chute", - "parallel bars, bars", - "park bench", - "parking meter", - "passenger car, coach, carriage", - "patio, terrace", - "pay-phone, pay-station", - "pedestal, plinth, footstall", - "pencil box, pencil case", - "pencil sharpener", - "perfume, essence", - "Petri dish", - "photocopier", - "pick, plectrum, plectron", - "pickelhaube", - "picket fence, paling", - "pickup, pickup truck", - "pier", - "piggy bank, penny bank", - "pill bottle", - "pillow", - "ping-pong ball", - "pinwheel", - "pirate, pirate ship", - "pitcher, ewer", - "plane, carpenter's plane, woodworking plane", - "planetarium", - "plastic bag", - "plate rack", - "plow, plough", - "plunger, plumber's helper", - "Polaroid camera, Polaroid Land camera", - "pole", - "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria", - "poncho", - "pool table, billiard table, snooker table", - "pop bottle, soda bottle", - "pot, flowerpot", - "potter's wheel", - "power drill", - "prayer rug, prayer mat", - "printer", - "prison, prison house", - "projectile, missile", - "projector", - "puck, hockey puck", - "punching bag, punch bag, punching ball, punchball", - "purse", - "quill, quill pen", - "quilt, comforter, comfort, puff", - "racer, race car, racing car", - "racket, racquet", - "radiator", - "radio, wireless", - "radio telescope, radio reflector", - "rain barrel", - "recreational vehicle, RV, R.V.", - "reel", - "reflex camera", - "refrigerator, icebox", - "remote control, remote", - "restaurant, eating house, eating place, eatery", - "revolver, six-gun, six-shooter", - "rifle", - "rocking chair, rocker", - "rotisserie", - "rubber eraser, rubber, pencil eraser", - "rugby ball", - "rule, ruler", - "running shoe", - "safe", - "safety pin", - "saltshaker, salt shaker", - "sandal", - "sarong", - "sax, saxophone", - "scabbard", - "scale, weighing machine", - "school bus", - "schooner", - "scoreboard", - "screen, CRT screen", - "screw", - "screwdriver", - "seat belt, seatbelt", - "sewing machine", - "shield, buckler", - "shoe shop, shoe-shop, shoe store", - "shoji", - "shopping basket", - "shopping cart", - "shovel", - "shower cap", - "shower curtain", - "ski", - "ski mask", - "sleeping bag", - "slide rule, slipstick", - "sliding door", - "slot, one-armed bandit", - "snorkel", - "snowmobile", - "snowplow, snowplough", - "soap dispenser", - "soccer ball", - "sock", - "solar dish, solar collector, solar furnace", - "sombrero", - "soup bowl", - "space bar", - "space heater", - "space shuttle", - "spatula", - "speedboat", - "spider web, spider's web", - "spindle", - "sports car, sport car", - "spotlight, spot", - "stage", - "steam locomotive", - "steel arch bridge", - "steel drum", - "stethoscope", - "stole", - "stone wall", - "stopwatch, stop watch", - "stove", - "strainer", - "streetcar, tram, tramcar, trolley, trolley car", - "stretcher", - "studio couch, day bed", - "stupa, tope", - "submarine, pigboat, sub, U-boat", - "suit, suit of clothes", - "sundial", - "sunglass", - "sunglasses, dark glasses, shades", - "sunscreen, sunblock, sun blocker", - "suspension bridge", - "swab, swob, mop", - "sweatshirt", - "swimming trunks, bathing trunks", - "swing", - "switch, electric switch, electrical switch", - "syringe", - "table lamp", - "tank, army tank, armored combat vehicle, armoured combat vehicle", - "tape player", - "teapot", - "teddy, teddy bear", - "television, television system", - "tennis ball", - "thatch, thatched roof", - "theater curtain, theatre curtain", - "thimble", - "thresher, thrasher, threshing machine", - "throne", - "tile roof", - "toaster", - "tobacco shop, tobacconist shop, tobacconist", - "toilet seat", - "torch", - "totem pole", - "tow truck, tow car, wrecker", - "toyshop", - "tractor", - "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi", - "tray", - "trench coat", - "tricycle, trike, velocipede", - "trimaran", - "tripod", - "triumphal arch", - "trolleybus, trolley coach, trackless trolley", - "trombone", - "tub, vat", - "turnstile", - "typewriter keyboard", - "umbrella", - "unicycle, monocycle", - "upright, upright piano", - "vacuum, vacuum cleaner", - "vase", - "vault", - "velvet", - "vending machine", - "vestment", - "viaduct", - "violin, fiddle", - "volleyball", - "waffle iron", - "wall clock", - "wallet, billfold, notecase, pocketbook", - "wardrobe, closet, press", - "warplane, military plane", - "washbasin, handbasin, washbowl, lavabo, wash-hand basin", - "washer, automatic washer, washing machine", - "water bottle", - "water jug", - "water tower", - "whiskey jug", - "whistle", - "wig", - "window screen", - "window shade", - "Windsor tie", - "wine bottle", - "wing", - "wok", - "wooden spoon", - "wool, woolen, woollen", - "worm fence, snake fence, snake-rail fence, Virginia fence", - "wreck", - "yawl", - "yurt", - "web site, website, internet site, site", - "comic book", - "crossword puzzle, crossword", - "street sign", - "traffic light, traffic signal, stoplight", - "book jacket, dust cover, dust jacket, dust wrapper", - "menu", - "plate", - "guacamole", - "consomme", - "hot pot, hotpot", - "trifle", - "ice cream, icecream", - "ice lolly, lolly, lollipop, popsicle", - "French loaf", - "bagel, beigel", - "pretzel", - "cheeseburger", - "hotdog, hot dog, red hot", - "mashed potato", - "head cabbage", - "broccoli", - "cauliflower", - "zucchini, courgette", - "spaghetti squash", - "acorn squash", - "butternut squash", - "cucumber, cuke", - "artichoke, globe artichoke", - "bell pepper", - "cardoon", - "mushroom", - "Granny Smith", - "strawberry", - "orange", - "lemon", - "fig", - "pineapple, ananas", - "banana", - "jackfruit, jak, jack", - "custard apple", - "pomegranate", - "hay", - "carbonara", - "chocolate sauce, chocolate syrup", - "dough", - "meat loaf, meatloaf", - "pizza, pizza pie", - "potpie", - "burrito", - "red wine", - "espresso", - "cup", - "eggnog", - "alp", - "bubble", - "cliff, drop, drop-off", - "coral reef", - "geyser", - "lakeside, lakeshore", - "promontory, headland, head, foreland", - "sandbar, sand bar", - "seashore, coast, seacoast, sea-coast", - "valley, vale", - "volcano", - "ballplayer, baseball player", - "groom, bridegroom", - "scuba diver", - "rapeseed", - "daisy", - "yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum", - "corn", - "acorn", - "hip, rose hip, rosehip", - "buckeye, horse chestnut, conker", - "coral fungus", - "agaric", - "gyromitra", - "stinkhorn, carrion fungus", - "earthstar", - "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa", - "bolete", - "ear, spike, capitulum", - "toilet tissue, toilet paper, bathroom tissue" -}; + "tench, Tinca tinca", + "goldfish, Carassius auratus", + "great white shark, white shark, man-eater, man-eating shark, Carcharodon " + "carcharias", + "tiger shark, Galeocerdo cuvieri", + "hammerhead, hammerhead shark", + "electric ray, crampfish, numbfish, torpedo", + "stingray", + "cock", + "hen", + "ostrich, Struthio camelus", + "brambling, Fringilla montifringilla", + "goldfinch, Carduelis carduelis", + "house finch, linnet, Carpodacus mexicanus", + "junco, snowbird", + "indigo bunting, indigo finch, indigo bird, Passerina cyanea", + "robin, American robin, Turdus migratorius", + "bulbul", + "jay", + "magpie", + "chickadee", + "water ouzel, dipper", + "kite", + "bald eagle, American eagle, Haliaeetus leucocephalus", + "vulture", + "great grey owl, great gray owl, Strix nebulosa", + "European fire salamander, Salamandra salamandra", + "common newt, Triturus vulgaris", + "eft", + "spotted salamander, Ambystoma maculatum", + "axolotl, mud puppy, Ambystoma mexicanum", + "bullfrog, Rana catesbeiana", + "tree frog, tree-frog", + "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui", + "loggerhead, loggerhead turtle, Caretta caretta", + "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea", + "mud turtle", + "terrapin", + "box turtle, box tortoise", + "banded gecko", + "common iguana, iguana, Iguana iguana", + "American chameleon, anole, Anolis carolinensis", + "whiptail, whiptail lizard", + "agama", + "frilled lizard, Chlamydosaurus kingi", + "alligator lizard", + "Gila monster, Heloderma suspectum", + "green lizard, Lacerta viridis", + "African chameleon, Chamaeleo chamaeleon", + "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus " + "komodoensis", + "African crocodile, Nile crocodile, Crocodylus niloticus", + "American alligator, Alligator mississipiensis", + "triceratops", + "thunder snake, worm snake, Carphophis amoenus", + "ringneck snake, ring-necked snake, ring snake", + "hognose snake, puff adder, sand viper", + "green snake, grass snake", + "king snake, kingsnake", + "garter snake, grass snake", + "water snake", + "vine snake", + "night snake, Hypsiglena torquata", + "boa constrictor, Constrictor constrictor", + "rock python, rock snake, Python sebae", + "Indian cobra, Naja naja", + "green mamba", + "sea snake", + "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus", + "diamondback, diamondback rattlesnake, Crotalus adamanteus", + "sidewinder, horned rattlesnake, Crotalus cerastes", + "trilobite", + "harvestman, daddy longlegs, Phalangium opilio", + "scorpion", + "black and gold garden spider, Argiope aurantia", + "barn spider, Araneus cavaticus", + "garden spider, Aranea diademata", + "black widow, Latrodectus mactans", + "tarantula", + "wolf spider, hunting spider", + "tick", + "centipede", + "black grouse", + "ptarmigan", + "ruffed grouse, partridge, Bonasa umbellus", + "prairie chicken, prairie grouse, prairie fowl", + "peacock", + "quail", + "partridge", + "African grey, African gray, Psittacus erithacus", + "macaw", + "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita", + "lorikeet", + "coucal", + "bee eater", + "hornbill", + "hummingbird", + "jacamar", + "toucan", + "drake", + "red-breasted merganser, Mergus serrator", + "goose", + "black swan, Cygnus atratus", + "tusker", + "echidna, spiny anteater, anteater", + "platypus, duckbill, duckbilled platypus, duck-billed platypus, " + "Ornithorhynchus anatinus", + "wallaby, brush kangaroo", + "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus", + "wombat", + "jellyfish", + "sea anemone, anemone", + "brain coral", + "flatworm, platyhelminth", + "nematode, nematode worm, roundworm", + "conch", + "snail", + "slug", + "sea slug, nudibranch", + "chiton, coat-of-mail shell, sea cradle, polyplacophore", + "chambered nautilus, pearly nautilus, nautilus", + "Dungeness crab, Cancer magister", + "rock crab, Cancer irroratus", + "fiddler crab", + "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes " + "camtschatica", + "American lobster, Northern lobster, Maine lobster, Homarus americanus", + "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish", + "crayfish, crawfish, crawdad, crawdaddy", + "hermit crab", + "isopod", + "white stork, Ciconia ciconia", + "black stork, Ciconia nigra", + "spoonbill", + "flamingo", + "little blue heron, Egretta caerulea", + "American egret, great white heron, Egretta albus", + "bittern", + "crane", + "limpkin, Aramus pictus", + "European gallinule, Porphyrio porphyrio", + "American coot, marsh hen, mud hen, water hen, Fulica americana", + "bustard", + "ruddy turnstone, Arenaria interpres", + "red-backed sandpiper, dunlin, Erolia alpina", + "redshank, Tringa totanus", + "dowitcher", + "oystercatcher, oyster catcher", + "pelican", + "king penguin, Aptenodytes patagonica", + "albatross, mollymawk", + "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius " + "robustus", + "killer whale, killer, orca, grampus, sea wolf, Orcinus orca", + "dugong, Dugong dugon", + "sea lion", + "Chihuahua", + "Japanese spaniel", + "Maltese dog, Maltese terrier, Maltese", + "Pekinese, Pekingese, Peke", + "Shih-Tzu", + "Blenheim spaniel", + "papillon", + "toy terrier", + "Rhodesian ridgeback", + "Afghan hound, Afghan", + "basset, basset hound", + "beagle", + "bloodhound, sleuthhound", + "bluetick", + "black-and-tan coonhound", + "Walker hound, Walker foxhound", + "English foxhound", + "redbone", + "borzoi, Russian wolfhound", + "Irish wolfhound", + "Italian greyhound", + "whippet", + "Ibizan hound, Ibizan Podenco", + "Norwegian elkhound, elkhound", + "otterhound, otter hound", + "Saluki, gazelle hound", + "Scottish deerhound, deerhound", + "Weimaraner", + "Staffordshire bullterrier, Staffordshire bull terrier", + "American Staffordshire terrier, Staffordshire terrier, American pit bull " + "terrier, pit bull terrier", + "Bedlington terrier", + "Border terrier", + "Kerry blue terrier", + "Irish terrier", + "Norfolk terrier", + "Norwich terrier", + "Yorkshire terrier", + "wire-haired fox terrier", + "Lakeland terrier", + "Sealyham terrier, Sealyham", + "Airedale, Airedale terrier", + "cairn, cairn terrier", + "Australian terrier", + "Dandie Dinmont, Dandie Dinmont terrier", + "Boston bull, Boston terrier", + "miniature schnauzer", + "giant schnauzer", + "standard schnauzer", + "Scotch terrier, Scottish terrier, Scottie", + "Tibetan terrier, chrysanthemum dog", + "silky terrier, Sydney silky", + "soft-coated wheaten terrier", + "West Highland white terrier", + "Lhasa, Lhasa apso", + "flat-coated retriever", + "curly-coated retriever", + "golden retriever", + "Labrador retriever", + "Chesapeake Bay retriever", + "German short-haired pointer", + "vizsla, Hungarian pointer", + "English setter", + "Irish setter, red setter", + "Gordon setter", + "Brittany spaniel", + "clumber, clumber spaniel", + "English springer, English springer spaniel", + "Welsh springer spaniel", + "cocker spaniel, English cocker spaniel, cocker", + "Sussex spaniel", + "Irish water spaniel", + "kuvasz", + "schipperke", + "groenendael", + "malinois", + "briard", + "kelpie", + "komondor", + "Old English sheepdog, bobtail", + "Shetland sheepdog, Shetland sheep dog, Shetland", + "collie", + "Border collie", + "Bouvier des Flandres, Bouviers des Flandres", + "Rottweiler", + "German shepherd, German shepherd dog, German police dog, alsatian", + "Doberman, Doberman pinscher", + "miniature pinscher", + "Greater Swiss Mountain dog", + "Bernese mountain dog", + "Appenzeller", + "EntleBucher", + "boxer", + "bull mastiff", + "Tibetan mastiff", + "French bulldog", + "Great Dane", + "Saint Bernard, St Bernard", + "Eskimo dog, husky", + "malamute, malemute, Alaskan malamute", + "Siberian husky", + "dalmatian, coach dog, carriage dog", + "affenpinscher, monkey pinscher, monkey dog", + "basenji", + "pug, pug-dog", + "Leonberg", + "Newfoundland, Newfoundland dog", + "Great Pyrenees", + "Samoyed, Samoyede", + "Pomeranian", + "chow, chow chow", + "keeshond", + "Brabancon griffon", + "Pembroke, Pembroke Welsh corgi", + "Cardigan, Cardigan Welsh corgi", + "toy poodle", + "miniature poodle", + "standard poodle", + "Mexican hairless", + "timber wolf, grey wolf, gray wolf, Canis lupus", + "white wolf, Arctic wolf, Canis lupus tundrarum", + "red wolf, maned wolf, Canis rufus, Canis niger", + "coyote, prairie wolf, brush wolf, Canis latrans", + "dingo, warrigal, warragal, Canis dingo", + "dhole, Cuon alpinus", + "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus", + "hyena, hyaena", + "red fox, Vulpes vulpes", + "kit fox, Vulpes macrotis", + "Arctic fox, white fox, Alopex lagopus", + "grey fox, gray fox, Urocyon cinereoargenteus", + "tabby, tabby cat", + "tiger cat", + "Persian cat", + "Siamese cat, Siamese", + "Egyptian cat", + "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor", + "lynx, catamount", + "leopard, Panthera pardus", + "snow leopard, ounce, Panthera uncia", + "jaguar, panther, Panthera onca, Felis onca", + "lion, king of beasts, Panthera leo", + "tiger, Panthera tigris", + "cheetah, chetah, Acinonyx jubatus", + "brown bear, bruin, Ursus arctos", + "American black bear, black bear, Ursus americanus, Euarctos americanus", + "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus", + "sloth bear, Melursus ursinus, Ursus ursinus", + "mongoose", + "meerkat, mierkat", + "tiger beetle", + "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle", + "ground beetle, carabid beetle", + "long-horned beetle, longicorn, longicorn beetle", + "leaf beetle, chrysomelid", + "dung beetle", + "rhinoceros beetle", + "weevil", + "fly", + "bee", + "ant, emmet, pismire", + "grasshopper, hopper", + "cricket", + "walking stick, walkingstick, stick insect", + "cockroach, roach", + "mantis, mantid", + "cicada, cicala", + "leafhopper", + "lacewing, lacewing fly", + "dragonfly, darning needle, devil's darning needle, sewing needle, snake " + "feeder, snake doctor, mosquito hawk, skeeter hawk", + "damselfly", + "admiral", + "ringlet, ringlet butterfly", + "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus", + "cabbage butterfly", + "sulphur butterfly, sulfur butterfly", + "lycaenid, lycaenid butterfly", + "starfish, sea star", + "sea urchin", + "sea cucumber, holothurian", + "wood rabbit, cottontail, cottontail rabbit", + "hare", + "Angora, Angora rabbit", + "hamster", + "porcupine, hedgehog", + "fox squirrel, eastern fox squirrel, Sciurus niger", + "marmot", + "beaver", + "guinea pig, Cavia cobaya", + "sorrel", + "zebra", + "hog, pig, grunter, squealer, Sus scrofa", + "wild boar, boar, Sus scrofa", + "warthog", + "hippopotamus, hippo, river horse, Hippopotamus amphibius", + "ox", + "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis", + "bison", + "ram, tup", + "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain " + "sheep, Ovis canadensis", + "ibex, Capra ibex", + "hartebeest", + "impala, Aepyceros melampus", + "gazelle", + "Arabian camel, dromedary, Camelus dromedarius", + "llama", + "weasel", + "mink", + "polecat, fitch, foulmart, foumart, Mustela putorius", + "black-footed ferret, ferret, Mustela nigripes", + "otter", + "skunk, polecat, wood pussy", + "badger", + "armadillo", + "three-toed sloth, ai, Bradypus tridactylus", + "orangutan, orang, orangutang, Pongo pygmaeus", + "gorilla, Gorilla gorilla", + "chimpanzee, chimp, Pan troglodytes", + "gibbon, Hylobates lar", + "siamang, Hylobates syndactylus, Symphalangus syndactylus", + "guenon, guenon monkey", + "patas, hussar monkey, Erythrocebus patas", + "baboon", + "macaque", + "langur", + "colobus, colobus monkey", + "proboscis monkey, Nasalis larvatus", + "marmoset", + "capuchin, ringtail, Cebus capucinus", + "howler monkey, howler", + "titi, titi monkey", + "spider monkey, Ateles geoffroyi", + "squirrel monkey, Saimiri sciureus", + "Madagascar cat, ring-tailed lemur, Lemur catta", + "indri, indris, Indri indri, Indri brevicaudatus", + "Indian elephant, Elephas maximus", + "African elephant, Loxodonta africana", + "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens", + "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca", + "barracouta, snoek", + "eel", + "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch", + "rock beauty, Holocanthus tricolor", + "anemone fish", + "sturgeon", + "gar, garfish, garpike, billfish, Lepisosteus osseus", + "lionfish", + "puffer, pufferfish, blowfish, globefish", + "abacus", + "abaya", + "academic gown, academic robe, judge's robe", + "accordion, piano accordion, squeeze box", + "acoustic guitar", + "aircraft carrier, carrier, flattop, attack aircraft carrier", + "airliner", + "airship, dirigible", + "altar", + "ambulance", + "amphibian, amphibious vehicle", + "analog clock", + "apiary, bee house", + "apron", + "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, " + "dustbin, trash barrel, trash bin", + "assault rifle, assault gun", + "backpack, back pack, knapsack, packsack, rucksack, haversack", + "bakery, bakeshop, bakehouse", + "balance beam, beam", + "balloon", + "ballpoint, ballpoint pen, ballpen, Biro", + "Band Aid", + "banjo", + "bannister, banister, balustrade, balusters, handrail", + "barbell", + "barber chair", + "barbershop", + "barn", + "barometer", + "barrel, cask", + "barrow, garden cart, lawn cart, wheelbarrow", + "baseball", + "basketball", + "bassinet", + "bassoon", + "bathing cap, swimming cap", + "bath towel", + "bathtub, bathing tub, bath, tub", + "beach wagon, station wagon, wagon, estate car, beach waggon, station " + "waggon, waggon", + "beacon, lighthouse, beacon light, pharos", + "beaker", + "bearskin, busby, shako", + "beer bottle", + "beer glass", + "bell cote, bell cot", + "bib", + "bicycle-built-for-two, tandem bicycle, tandem", + "bikini, two-piece", + "binder, ring-binder", + "binoculars, field glasses, opera glasses", + "birdhouse", + "boathouse", + "bobsled, bobsleigh, bob", + "bolo tie, bolo, bola tie, bola", + "bonnet, poke bonnet", + "bookcase", + "bookshop, bookstore, bookstall", + "bottlecap", + "bow", + "bow tie, bow-tie, bowtie", + "brass, memorial tablet, plaque", + "brassiere, bra, bandeau", + "breakwater, groin, groyne, mole, bulwark, seawall, jetty", + "breastplate, aegis, egis", + "broom", + "bucket, pail", + "buckle", + "bulletproof vest", + "bullet train, bullet", + "butcher shop, meat market", + "cab, hack, taxi, taxicab", + "caldron, cauldron", + "candle, taper, wax light", + "cannon", + "canoe", + "can opener, tin opener", + "cardigan", + "car mirror", + "carousel, carrousel, merry-go-round, roundabout, whirligig", + "carpenter's kit, tool kit", + "carton", + "car wheel", + "cash machine, cash dispenser, automated teller machine, automatic teller " + "machine, automated teller, automatic teller, ATM", + "cassette", + "cassette player", + "castle", + "catamaran", + "CD player", + "cello, violoncello", + "cellular telephone, cellular phone, cellphone, cell, mobile phone", + "chain", + "chainlink fence", + "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring " + "armour", + "chain saw, chainsaw", + "chest", + "chiffonier, commode", + "chime, bell, gong", + "china cabinet, china closet", + "Christmas stocking", + "church, church building", + "cinema, movie theater, movie theatre, movie house, picture palace", + "cleaver, meat cleaver, chopper", + "cliff dwelling", + "cloak", + "clog, geta, patten, sabot", + "cocktail shaker", + "coffee mug", + "coffeepot", + "coil, spiral, volute, whorl, helix", + "combination lock", + "computer keyboard, keypad", + "confectionery, confectionary, candy store", + "container ship, containership, container vessel", + "convertible", + "corkscrew, bottle screw", + "cornet, horn, trumpet, trump", + "cowboy boot", + "cowboy hat, ten-gallon hat", + "cradle", + "crane", + "crash helmet", + "crate", + "crib, cot", + "Crock Pot", + "croquet ball", + "crutch", + "cuirass", + "dam, dike, dyke", + "desk", + "desktop computer", + "dial telephone, dial phone", + "diaper, nappy, napkin", + "digital clock", + "digital watch", + "dining table, board", + "dishrag, dishcloth", + "dishwasher, dish washer, dishwashing machine", + "disk brake, disc brake", + "dock, dockage, docking facility", + "dogsled, dog sled, dog sleigh", + "dome", + "doormat, welcome mat", + "drilling platform, offshore rig", + "drum, membranophone, tympan", + "drumstick", + "dumbbell", + "Dutch oven", + "electric fan, blower", + "electric guitar", + "electric locomotive", + "entertainment center", + "envelope", + "espresso maker", + "face powder", + "feather boa, boa", + "file, file cabinet, filing cabinet", + "fireboat", + "fire engine, fire truck", + "fire screen, fireguard", + "flagpole, flagstaff", + "flute, transverse flute", + "folding chair", + "football helmet", + "forklift", + "fountain", + "fountain pen", + "four-poster", + "freight car", + "French horn, horn", + "frying pan, frypan, skillet", + "fur coat", + "garbage truck, dustcart", + "gasmask, respirator, gas helmet", + "gas pump, gasoline pump, petrol pump, island dispenser", + "goblet", + "go-kart", + "golf ball", + "golfcart, golf cart", + "gondola", + "gong, tam-tam", + "gown", + "grand piano, grand", + "greenhouse, nursery, glasshouse", + "grille, radiator grille", + "grocery store, grocery, food market, market", + "guillotine", + "hair slide", + "hair spray", + "half track", + "hammer", + "hamper", + "hand blower, blow dryer, blow drier, hair dryer, hair drier", + "hand-held computer, hand-held microcomputer", + "handkerchief, hankie, hanky, hankey", + "hard disc, hard disk, fixed disk", + "harmonica, mouth organ, harp, mouth harp", + "harp", + "harvester, reaper", + "hatchet", + "holster", + "home theater, home theatre", + "honeycomb", + "hook, claw", + "hoopskirt, crinoline", + "horizontal bar, high bar", + "horse cart, horse-cart", + "hourglass", + "iPod", + "iron, smoothing iron", + "jack-o'-lantern", + "jean, blue jean, denim", + "jeep, landrover", + "jersey, T-shirt, tee shirt", + "jigsaw puzzle", + "jinrikisha, ricksha, rickshaw", + "joystick", + "kimono", + "knee pad", + "knot", + "lab coat, laboratory coat", + "ladle", + "lampshade, lamp shade", + "laptop, laptop computer", + "lawn mower, mower", + "lens cap, lens cover", + "letter opener, paper knife, paperknife", + "library", + "lifeboat", + "lighter, light, igniter, ignitor", + "limousine, limo", + "liner, ocean liner", + "lipstick, lip rouge", + "Loafer", + "lotion", + "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system", + "loupe, jeweler's loupe", + "lumbermill, sawmill", + "magnetic compass", + "mailbag, postbag", + "mailbox, letter box", + "maillot", + "maillot, tank suit", + "manhole cover", + "maraca", + "marimba, xylophone", + "mask", + "matchstick", + "maypole", + "maze, labyrinth", + "measuring cup", + "medicine chest, medicine cabinet", + "megalith, megalithic structure", + "microphone, mike", + "microwave, microwave oven", + "military uniform", + "milk can", + "minibus", + "miniskirt, mini", + "minivan", + "missile", + "mitten", + "mixing bowl", + "mobile home, manufactured home", + "Model T", + "modem", + "monastery", + "monitor", + "moped", + "mortar", + "mortarboard", + "mosque", + "mosquito net", + "motor scooter, scooter", + "mountain bike, all-terrain bike, off-roader", + "mountain tent", + "mouse, computer mouse", + "mousetrap", + "moving van", + "muzzle", + "nail", + "neck brace", + "necklace", + "nipple", + "notebook, notebook computer", + "obelisk", + "oboe, hautboy, hautbois", + "ocarina, sweet potato", + "odometer, hodometer, mileometer, milometer", + "oil filter", + "organ, pipe organ", + "oscilloscope, scope, cathode-ray oscilloscope, CRO", + "overskirt", + "oxcart", + "oxygen mask", + "packet", + "paddle, boat paddle", + "paddlewheel, paddle wheel", + "padlock", + "paintbrush", + "pajama, pyjama, pj's, jammies", + "palace", + "panpipe, pandean pipe, syrinx", + "paper towel", + "parachute, chute", + "parallel bars, bars", + "park bench", + "parking meter", + "passenger car, coach, carriage", + "patio, terrace", + "pay-phone, pay-station", + "pedestal, plinth, footstall", + "pencil box, pencil case", + "pencil sharpener", + "perfume, essence", + "Petri dish", + "photocopier", + "pick, plectrum, plectron", + "pickelhaube", + "picket fence, paling", + "pickup, pickup truck", + "pier", + "piggy bank, penny bank", + "pill bottle", + "pillow", + "ping-pong ball", + "pinwheel", + "pirate, pirate ship", + "pitcher, ewer", + "plane, carpenter's plane, woodworking plane", + "planetarium", + "plastic bag", + "plate rack", + "plow, plough", + "plunger, plumber's helper", + "Polaroid camera, Polaroid Land camera", + "pole", + "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria", + "poncho", + "pool table, billiard table, snooker table", + "pop bottle, soda bottle", + "pot, flowerpot", + "potter's wheel", + "power drill", + "prayer rug, prayer mat", + "printer", + "prison, prison house", + "projectile, missile", + "projector", + "puck, hockey puck", + "punching bag, punch bag, punching ball, punchball", + "purse", + "quill, quill pen", + "quilt, comforter, comfort, puff", + "racer, race car, racing car", + "racket, racquet", + "radiator", + "radio, wireless", + "radio telescope, radio reflector", + "rain barrel", + "recreational vehicle, RV, R.V.", + "reel", + "reflex camera", + "refrigerator, icebox", + "remote control, remote", + "restaurant, eating house, eating place, eatery", + "revolver, six-gun, six-shooter", + "rifle", + "rocking chair, rocker", + "rotisserie", + "rubber eraser, rubber, pencil eraser", + "rugby ball", + "rule, ruler", + "running shoe", + "safe", + "safety pin", + "saltshaker, salt shaker", + "sandal", + "sarong", + "sax, saxophone", + "scabbard", + "scale, weighing machine", + "school bus", + "schooner", + "scoreboard", + "screen, CRT screen", + "screw", + "screwdriver", + "seat belt, seatbelt", + "sewing machine", + "shield, buckler", + "shoe shop, shoe-shop, shoe store", + "shoji", + "shopping basket", + "shopping cart", + "shovel", + "shower cap", + "shower curtain", + "ski", + "ski mask", + "sleeping bag", + "slide rule, slipstick", + "sliding door", + "slot, one-armed bandit", + "snorkel", + "snowmobile", + "snowplow, snowplough", + "soap dispenser", + "soccer ball", + "sock", + "solar dish, solar collector, solar furnace", + "sombrero", + "soup bowl", + "space bar", + "space heater", + "space shuttle", + "spatula", + "speedboat", + "spider web, spider's web", + "spindle", + "sports car, sport car", + "spotlight, spot", + "stage", + "steam locomotive", + "steel arch bridge", + "steel drum", + "stethoscope", + "stole", + "stone wall", + "stopwatch, stop watch", + "stove", + "strainer", + "streetcar, tram, tramcar, trolley, trolley car", + "stretcher", + "studio couch, day bed", + "stupa, tope", + "submarine, pigboat, sub, U-boat", + "suit, suit of clothes", + "sundial", + "sunglass", + "sunglasses, dark glasses, shades", + "sunscreen, sunblock, sun blocker", + "suspension bridge", + "swab, swob, mop", + "sweatshirt", + "swimming trunks, bathing trunks", + "swing", + "switch, electric switch, electrical switch", + "syringe", + "table lamp", + "tank, army tank, armored combat vehicle, armoured combat vehicle", + "tape player", + "teapot", + "teddy, teddy bear", + "television, television system", + "tennis ball", + "thatch, thatched roof", + "theater curtain, theatre curtain", + "thimble", + "thresher, thrasher, threshing machine", + "throne", + "tile roof", + "toaster", + "tobacco shop, tobacconist shop, tobacconist", + "toilet seat", + "torch", + "totem pole", + "tow truck, tow car, wrecker", + "toyshop", + "tractor", + "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, " + "semi", + "tray", + "trench coat", + "tricycle, trike, velocipede", + "trimaran", + "tripod", + "triumphal arch", + "trolleybus, trolley coach, trackless trolley", + "trombone", + "tub, vat", + "turnstile", + "typewriter keyboard", + "umbrella", + "unicycle, monocycle", + "upright, upright piano", + "vacuum, vacuum cleaner", + "vase", + "vault", + "velvet", + "vending machine", + "vestment", + "viaduct", + "violin, fiddle", + "volleyball", + "waffle iron", + "wall clock", + "wallet, billfold, notecase, pocketbook", + "wardrobe, closet, press", + "warplane, military plane", + "washbasin, handbasin, washbowl, lavabo, wash-hand basin", + "washer, automatic washer, washing machine", + "water bottle", + "water jug", + "water tower", + "whiskey jug", + "whistle", + "wig", + "window screen", + "window shade", + "Windsor tie", + "wine bottle", + "wing", + "wok", + "wooden spoon", + "wool, woolen, woollen", + "worm fence, snake fence, snake-rail fence, Virginia fence", + "wreck", + "yawl", + "yurt", + "web site, website, internet site, site", + "comic book", + "crossword puzzle, crossword", + "street sign", + "traffic light, traffic signal, stoplight", + "book jacket, dust cover, dust jacket, dust wrapper", + "menu", + "plate", + "guacamole", + "consomme", + "hot pot, hotpot", + "trifle", + "ice cream, icecream", + "ice lolly, lolly, lollipop, popsicle", + "French loaf", + "bagel, beigel", + "pretzel", + "cheeseburger", + "hotdog, hot dog, red hot", + "mashed potato", + "head cabbage", + "broccoli", + "cauliflower", + "zucchini, courgette", + "spaghetti squash", + "acorn squash", + "butternut squash", + "cucumber, cuke", + "artichoke, globe artichoke", + "bell pepper", + "cardoon", + "mushroom", + "Granny Smith", + "strawberry", + "orange", + "lemon", + "fig", + "pineapple, ananas", + "banana", + "jackfruit, jak, jack", + "custard apple", + "pomegranate", + "hay", + "carbonara", + "chocolate sauce, chocolate syrup", + "dough", + "meat loaf, meatloaf", + "pizza, pizza pie", + "potpie", + "burrito", + "red wine", + "espresso", + "cup", + "eggnog", + "alp", + "bubble", + "cliff, drop, drop-off", + "coral reef", + "geyser", + "lakeside, lakeshore", + "promontory, headland, head, foreland", + "sandbar, sand bar", + "seashore, coast, seacoast, sea-coast", + "valley, vale", + "volcano", + "ballplayer, baseball player", + "groom, bridegroom", + "scuba diver", + "rapeseed", + "daisy", + "yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, " + "Cypripedium parviflorum", + "corn", + "acorn", + "hip, rose hip, rosehip", + "buckeye, horse chestnut, conker", + "coral fungus", + "agaric", + "gyromitra", + "stinkhorn, carrion fungus", + "earthstar", + "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa", + "bolete", + "ear, spike, capitulum", + "toilet tissue, toilet paper, bathroom tissue"}; diff --git a/ios/RnExecutorch/models/ocr/Detector.mm b/ios/RnExecutorch/models/ocr/Detector.mm index bca0f50c..5bec8836 100644 --- a/ios/RnExecutorch/models/ocr/Detector.mm +++ b/ios/RnExecutorch/models/ocr/Detector.mm @@ -21,7 +21,7 @@ @implementation Detector { NSArray *inputShape = [module getInputShape:@0]; NSNumber *widthNumber = inputShape[inputShape.count - 2]; NSNumber *heightNumber = inputShape.lastObject; - + const int height = [heightNumber intValue]; const int width = [widthNumber intValue]; modelSize = cv::Size(height, width); diff --git a/ios/RnExecutorch/models/ocr/RecognitionHandler.mm b/ios/RnExecutorch/models/ocr/RecognitionHandler.mm index a2632977..02d683cd 100644 --- a/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +++ b/ios/RnExecutorch/models/ocr/RecognitionHandler.mm @@ -1,9 +1,9 @@ #import "RecognitionHandler.h" #import "../../utils/ImageProcessor.h" #import "./utils/CTCLabelConverter.h" +#import "./utils/Constants.h" #import "./utils/OCRUtils.h" #import "./utils/RecognizerUtils.h" -#import "./utils/Constants.h" #import "ExecutorchLib/ETModel.h" #import "Recognizer.h" #import @@ -28,9 +28,8 @@ - (instancetype)initWithSymbols:(NSString *)symbols { recognizerMedium = [[Recognizer alloc] init]; recognizerSmall = [[Recognizer alloc] init]; - converter = [[CTCLabelConverter alloc] - initWithCharacters:symbols - separatorList:@{}]; + converter = [[CTCLabelConverter alloc] initWithCharacters:symbols + separatorList:@{}]; } return self; } @@ -109,7 +108,8 @@ - (NSArray *)recognize:(NSArray *)bBoxesList continue; } croppedImage = [RecognizerUtils normalizeForRecognizer:croppedImage - adjustContrast:adjustContrast isVertical:NO]; + adjustContrast:adjustContrast + isVertical:NO]; NSArray *result = [self runModel:croppedImage]; NSNumber *confidenceScore = [result objectAtIndex:1]; diff --git a/ios/RnExecutorch/models/ocr/VerticalDetector.mm b/ios/RnExecutorch/models/ocr/VerticalDetector.mm index 087604dd..b36a29a2 100644 --- a/ios/RnExecutorch/models/ocr/VerticalDetector.mm +++ b/ios/RnExecutorch/models/ocr/VerticalDetector.mm @@ -80,9 +80,9 @@ group each character into a single instance (sequence) Both matrices are outputMat2:scoreAffinityCV withSize:cv::Size(modelImageSize.width / 2, modelImageSize.height / 2)]; - CGFloat txtThreshold = (self->detectSingleCharacters) ? textThreshold - : textThresholdVertical; - + CGFloat txtThreshold = + (self->detectSingleCharacters) ? textThreshold : textThresholdVertical; + NSArray *bBoxesList = [DetectorUtils getDetBoxesFromTextMapVertical:scoreTextCV affinityMap:scoreAffinityCV diff --git a/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm b/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm index 7d50e381..125da613 100644 --- a/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm +++ b/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm @@ -3,7 +3,7 @@ @implementation CTCLabelConverter - (instancetype)initWithCharacters:(NSString *)characters - separatorList:(NSDictionary *)separatorList{ + separatorList:(NSDictionary *)separatorList { self = [super init]; if (self) { _dict = [NSMutableDictionary dictionary]; diff --git a/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h b/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h index 70467169..1c473b00 100644 --- a/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h +++ b/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h @@ -21,11 +21,11 @@ constexpr int verticalLineThreshold = 20; + (NSArray *)restoreBboxRatio:(NSArray *)boxes usingRestoreRatio:(CGFloat)restoreRatio; + (NSArray *)groupTextBoxes:(NSArray *)polys - centerThreshold:(CGFloat)centerThreshold - distanceThreshold:(CGFloat)distanceThreshold - heightThreshold:(CGFloat)heightThreshold - minSideThreshold:(int)minSideThreshold - maxSideThreshold:(int)maxSideThreshold - maxWidth:(int)maxWidth; + centerThreshold:(CGFloat)centerThreshold + distanceThreshold:(CGFloat)distanceThreshold + heightThreshold:(CGFloat)heightThreshold + minSideThreshold:(int)minSideThreshold + maxSideThreshold:(int)maxSideThreshold + maxWidth:(int)maxWidth; @end diff --git a/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm b/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm index 0bdd6a76..abc72681 100644 --- a/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm +++ b/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm @@ -637,14 +637,13 @@ + (NSDictionary *)findClosestBox:(NSArray *)boxes * criteria. * 4. Sort the final array of boxes by their vertical positions. */ -+ (NSArray *)groupTextBoxes: - (NSMutableArray *)boxes - centerThreshold:(CGFloat)centerThreshold - distanceThreshold:(CGFloat)distanceThreshold - heightThreshold:(CGFloat)heightThreshold - minSideThreshold:(int)minSideThreshold - maxSideThreshold:(int)maxSideThreshold - maxWidth:(int)maxWidth { ++ (NSArray *)groupTextBoxes:(NSMutableArray *)boxes + centerThreshold:(CGFloat)centerThreshold + distanceThreshold:(CGFloat)distanceThreshold + heightThreshold:(CGFloat)heightThreshold + minSideThreshold:(int)minSideThreshold + maxSideThreshold:(int)maxSideThreshold + maxWidth:(int)maxWidth { // Sort boxes based on their maximum side length boxes = [boxes sortedArrayUsingComparator:^NSComparisonResult( NSDictionary *obj1, NSDictionary *obj2) { @@ -738,16 +737,17 @@ + (NSArray *)groupTextBoxes: : (minY1 > minY2) ? NSOrderedDescending : NSOrderedSame; }]; - - NSMutableArray *orderedSortedBoxes = [[NSMutableArray alloc] initWithCapacity:[sortedBoxes count]]; + + NSMutableArray *orderedSortedBoxes = + [[NSMutableArray alloc] initWithCapacity:[sortedBoxes count]]; for (NSDictionary *dict in sortedBoxes) { - NSMutableDictionary *mutableDict = [dict mutableCopy]; - NSArray *originalBBox = mutableDict[@"bbox"]; - NSArray *orderedBBox = [self orderPointsClockwise:originalBBox]; - mutableDict[@"bbox"] = orderedBBox; - [orderedSortedBoxes addObject:mutableDict]; + NSMutableDictionary *mutableDict = [dict mutableCopy]; + NSArray *originalBBox = mutableDict[@"bbox"]; + NSArray *orderedBBox = [self orderPointsClockwise:originalBBox]; + mutableDict[@"bbox"] = orderedBBox; + [orderedSortedBoxes addObject:mutableDict]; } - + return orderedSortedBoxes; } diff --git a/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm b/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm index f69e6756..47f186da 100644 --- a/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm +++ b/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm @@ -1,6 +1,6 @@ #import "RecognizerUtils.h" -#import "OCRUtils.h" #import "Constants.h" +#import "OCRUtils.h" @implementation RecognizerUtils @@ -63,7 +63,8 @@ + (CGFloat)calculateRatio:(int)width height:(int)height { image = [self adjustContrastGrey:image target:adjustContrast]; } - int desiredWidth = (isVertical) ? smallVerticalRecognizerWidth : smallRecognizerWidth; + int desiredWidth = + (isVertical) ? smallVerticalRecognizerWidth : smallRecognizerWidth; if (image.cols >= largeRecognizerWidth) { desiredWidth = largeRecognizerWidth; @@ -251,12 +252,13 @@ + (double)computeConfidenceScore:(NSArray *)valuesArray points.emplace_back(cv::Point2f(point.x, point.y)); } - + cv::Rect rect = cv::boundingRect(points); cv::Mat croppedImage = img(rect); cv::cvtColor(croppedImage, croppedImage, cv::COLOR_BGR2GRAY); - cv::resize(croppedImage, croppedImage, cv::Size(smallVerticalRecognizerWidth, recognizerHeight), 0, 0, - cv::INTER_AREA); + cv::resize(croppedImage, croppedImage, + cv::Size(smallVerticalRecognizerWidth, recognizerHeight), 0, 0, + cv::INTER_AREA); cv::medianBlur(img, img, 1); return croppedImage; } @@ -270,8 +272,8 @@ + (double)computeConfidenceScore:(NSArray *)valuesArray const float *histRange = {range}; bool uniform = true, accumulate = false; - cv::calcHist(&img, 1, 0, cv::Mat(), histogram, 1, &histSize, &histRange, uniform, - accumulate); + cv::calcHist(&img, 1, 0, cv::Mat(), histogram, 1, &histSize, &histRange, + uniform, accumulate); int midPoint = histSize / 2; @@ -283,7 +285,8 @@ + (double)computeConfidenceScore:(NSArray *)valuesArray sumRight += histogram.at(i); } - const int thresholdType = (sumLeft < sumRight) ? cv::THRESH_BINARY_INV : cv::THRESH_BINARY; + const int thresholdType = + (sumLeft < sumRight) ? cv::THRESH_BINARY_INV : cv::THRESH_BINARY; cv::Mat thresh; cv::threshold(img, thresh, 0, 255, thresholdType + cv::THRESH_OTSU); @@ -307,7 +310,8 @@ + (double)computeConfidenceScore:(NSArray *)valuesArray const double cx = centroids.at(i, 0); const double cy = centroids.at(i, 1); - if (minX < cx && cx < maxX && minY < cy && cy < maxY && area > singleCharacterMinSize) { + if (minX < cx && cx < maxX && minY < cy && cy < maxY && + area > singleCharacterMinSize) { if (selectedComponent == -1 || area > stats.at(selectedComponent, cv::CC_STAT_AREA)) { selectedComponent = i; diff --git a/ios/RnExecutorch/models/stt/Moonshine.hpp b/ios/RnExecutorch/models/stt/Moonshine.hpp index d913cf31..098cde0d 100644 --- a/ios/RnExecutorch/models/stt/Moonshine.hpp +++ b/ios/RnExecutorch/models/stt/Moonshine.hpp @@ -1,15 +1,13 @@ #ifndef Moonshine_hpp #define Moonshine_hpp -#import -#import #import "MoonshineEncoder.hpp" #import "Moonshinedecoder.hpp" #import "SpeechToTextBaseModel.hpp" +#import +#import @interface Moonshine : SpeechToTextBaseModel @end - - #endif /* Moonshine_hpp */ diff --git a/ios/RnExecutorch/models/stt/Moonshine.mm b/ios/RnExecutorch/models/stt/Moonshine.mm index 0bf31bfe..f35a87b7 100644 --- a/ios/RnExecutorch/models/stt/Moonshine.mm +++ b/ios/RnExecutorch/models/stt/Moonshine.mm @@ -1,9 +1,9 @@ #import "Moonshine.hpp" #import "ExecutorchLib/ETModel.h" -#import -#import #import "MoonshineEncoder.hpp" #import "Moonshinedecoder.hpp" +#import +#import @implementation Moonshine { MoonshineEncoder *encoder; @@ -27,8 +27,10 @@ - (NSArray *)encode:(NSArray *)waveform { return [self->encoder encode:[NSArray arrayWithObject:waveform]]; } -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState { - return [self->decoder decode:prevTokens encoderLastHiddenState:encoderLastHiddenState]; +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState { + return [self->decoder decode:prevTokens + encoderLastHiddenState:encoderLastHiddenState]; } - (void)loadModules:(NSArray *)modelSources { @@ -38,19 +40,20 @@ - (void)loadModules:(NSArray *)modelSources { // Load encoder [self loadModuleHelper:self->encoder - withSource:[modelSources objectAtIndex:0] - onSuccess:^{ - // Load decoder after encoder - [self loadModuleHelper:self->decoder - withSource:[modelSources objectAtIndex:1] - onSuccess:^{} - onFailure:^(NSString *errorCode) { - [NSException raise:@"init_decoder_error" format:@"%d", errorCode]; - }]; - } - onFailure:^(NSString *errorCode) { - [NSException raise:@"init_encoder_error" format:@"%d", errorCode]; - }]; + withSource:[modelSources objectAtIndex:0] + onSuccess:^{ + // Load decoder after encoder + [self loadModuleHelper:self->decoder + withSource:[modelSources objectAtIndex:1] + onSuccess:^{ + } + onFailure:^(NSString *errorCode) { + [NSException raise:@"init_decoder_error" format:@"%d", errorCode]; + }]; + } + onFailure:^(NSString *errorCode) { + [NSException raise:@"init_encoder_error" format:@"%d", errorCode]; + }]; } @end \ No newline at end of file diff --git a/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp b/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp index a12c0e0d..21c83c38 100644 --- a/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp +++ b/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp @@ -8,10 +8,9 @@ @interface MoonshineDecoder : BaseModel -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState; +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState; @end - - #endif /* MoonshineDecoder_hpp */ diff --git a/ios/RnExecutorch/models/stt/MoonshineDecoder.mm b/ios/RnExecutorch/models/stt/MoonshineDecoder.mm index 07133c5d..08038e85 100644 --- a/ios/RnExecutorch/models/stt/MoonshineDecoder.mm +++ b/ios/RnExecutorch/models/stt/MoonshineDecoder.mm @@ -3,15 +3,19 @@ @implementation MoonshineDecoder -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState { +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState { NSNumber *innerDim = @288; - NSNumber *noEncoderTokens = @(@([[encoderLastHiddenState objectAtIndex:0] count]).intValue / [innerDim intValue]); - NSArray *encoderLastHiddenStateShape = @[@1, noEncoderTokens, innerDim]; - NSArray *prevTokensShape = @[@1, @([prevTokens count])]; - NSArray *predictedToken = [self execute:@"forward_cached" - inputs:@[prevTokens, encoderLastHiddenState] - shapes:@[prevTokensShape, encoderLastHiddenStateShape] - inputTypes:@[ScalarType.Long, ScalarType.Float]]; + NSNumber *noEncoderTokens = + @(@([[encoderLastHiddenState objectAtIndex:0] count]).intValue / + [innerDim intValue]); + NSArray *encoderLastHiddenStateShape = @[ @1, noEncoderTokens, innerDim ]; + NSArray *prevTokensShape = @[ @1, @([prevTokens count]) ]; + NSArray *predictedToken = + [self execute:@"forward_cached" + inputs:@[ prevTokens, encoderLastHiddenState ] + shapes:@[ prevTokensShape, encoderLastHiddenStateShape ] + inputTypes:@[ ScalarType.Long, ScalarType.Float ]]; return [predictedToken objectAtIndex:0]; } diff --git a/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp b/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp index 61d5cecf..5491f7f4 100644 --- a/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp +++ b/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp @@ -12,6 +12,4 @@ @end - - #endif /* MoonshineEncoder_hpp */ diff --git a/ios/RnExecutorch/models/stt/MoonshineEncoder.mm b/ios/RnExecutorch/models/stt/MoonshineEncoder.mm index dbd52e32..fa2d031d 100644 --- a/ios/RnExecutorch/models/stt/MoonshineEncoder.mm +++ b/ios/RnExecutorch/models/stt/MoonshineEncoder.mm @@ -6,11 +6,13 @@ @implementation MoonshineEncoder - (NSArray *)encode:(NSArray *)waveform { - NSArray *waveformShape = [NSArray arrayWithObject:@[@1, @([waveform[0] count])]]; - NSArray *result = [self forward:waveform shapes:waveformShape inputTypes:waveformTypes]; - + NSArray *waveformShape = + [NSArray arrayWithObject:@[ @1, @([waveform[0] count]) ]]; + NSArray *result = [self forward:waveform + shapes:waveformShape + inputTypes:waveformTypes]; + return [result objectAtIndex:0]; } - @end diff --git a/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp b/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp index 9d445dc6..305b2821 100644 --- a/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp +++ b/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp @@ -1,10 +1,10 @@ #ifndef SpeechToTextBaseModel_hpp #define SpeechToTextBaseModel_hpp +#import "../BaseModel.h" #import #import -#import "../BaseModel.h" -@interface SpeechToTextBaseModel : NSObject{ +@interface SpeechToTextBaseModel : NSObject { @public NSNumber *START_TOKEN; NSNumber *EOS_TOKEN; @@ -13,15 +13,14 @@ } - (NSArray *)encode:(NSArray *)waveform; -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState; +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState; - (void)loadModules:(NSArray *)modelSources; - (void)loadModuleHelper:(id)model - withSource:(NSString *)source - onSuccess:(void (^)(void))success - onFailure:(void (^)(NSString *))failure; + withSource:(NSString *)source + onSuccess:(void (^)(void))success + onFailure:(void (^)(NSString *))failure; @end - - #endif /* SpeechToTextBaseModel_hpp */ diff --git a/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm b/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm index 47dc34b9..48cd4f50 100644 --- a/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +++ b/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm @@ -1,20 +1,21 @@ +#import "SpeechToTextBaseModel.hpp" #import #import -#import "SpeechToTextBaseModel.hpp" @implementation SpeechToTextBaseModel - (void)loadModuleHelper:(BaseModel *)model - withSource:(NSString *)source - onSuccess:(void (^)(void))success - onFailure:(void (^)(NSString *))failure { + withSource:(NSString *)source + onSuccess:(void (^)(void))success + onFailure:(void (^)(NSString *))failure { [model loadModel:[NSURL URLWithString:source] completion:^(BOOL isSuccess, NSNumber *errorCode) { if (isSuccess) { success(); } else { - failure([NSString stringWithFormat:@"%ld", (long)[errorCode longValue]]); + failure([NSString + stringWithFormat:@"%ld", (long)[errorCode longValue]]); } }]; } diff --git a/ios/RnExecutorch/models/stt/Whisper.hpp b/ios/RnExecutorch/models/stt/Whisper.hpp index 3da4b360..b13a05c0 100644 --- a/ios/RnExecutorch/models/stt/Whisper.hpp +++ b/ios/RnExecutorch/models/stt/Whisper.hpp @@ -2,12 +2,11 @@ #define Whisper_hpp #import "ExecutorchLib/ETModel.h" +#import "SpeechToTextBaseModel.hpp" #import #import -#import "SpeechToTextBaseModel.hpp" @interface Whisper : SpeechToTextBaseModel @end - #endif /* Whisper_hpp */ diff --git a/ios/RnExecutorch/models/stt/Whisper.mm b/ios/RnExecutorch/models/stt/Whisper.mm index 46c85504..d4ad811c 100644 --- a/ios/RnExecutorch/models/stt/Whisper.mm +++ b/ios/RnExecutorch/models/stt/Whisper.mm @@ -1,11 +1,11 @@ #import "Whisper.hpp" +#import "../../utils/SFFT.hpp" +#import "../../utils/ScalarType.h" #import "ExecutorchLib/ETModel.h" -#import -#import #import "WhisperEncoder.hpp" #import "Whisperdecoder.hpp" -#import "../../utils/SFFT.hpp" -#import "../../utils/ScalarType.h" +#import +#import @implementation Whisper { WhisperEncoder *encoder; @@ -30,15 +30,17 @@ - (NSArray *)encode:(NSArray *)waveform { [NSException raise:@"model_initialization_error" format:nil]; } NSArray *encodingResult = [self->encoder encode:waveform]; - + if (!encodingResult) { [NSException raise:@"forward_error" format:nil]; } return encodingResult; } -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState{ - return [self->decoder decode:prevTokens encoderLastHiddenState:encoderLastHiddenState]; +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState { + return [self->decoder decode:prevTokens + encoderLastHiddenState:encoderLastHiddenState]; } - (void)loadModules:(NSArray *)modelSources { @@ -48,19 +50,20 @@ - (void)loadModules:(NSArray *)modelSources { // Load encoder after preprocessor [self loadModuleHelper:self->encoder - withSource:[modelSources objectAtIndex:0] - onSuccess:^{ - // Load decoder after encoder - [self loadModuleHelper:self->decoder - withSource:[modelSources objectAtIndex:1] - onSuccess:^{} - onFailure:^(NSString *errorCode) { - [NSException raise:@"init_decoder_error" format:@"%d", errorCode]; - }]; - } - onFailure:^(NSString *errorCode) { - [NSException raise:@"init_encoder_error" format:@"%d", errorCode]; - }]; + withSource:[modelSources objectAtIndex:0] + onSuccess:^{ + // Load decoder after encoder + [self loadModuleHelper:self->decoder + withSource:[modelSources objectAtIndex:1] + onSuccess:^{ + } + onFailure:^(NSString *errorCode) { + [NSException raise:@"init_decoder_error" format:@"%d", errorCode]; + }]; + } + onFailure:^(NSString *errorCode) { + [NSException raise:@"init_encoder_error" format:@"%d", errorCode]; + }]; } @end diff --git a/ios/RnExecutorch/models/stt/WhisperDecoder.hpp b/ios/RnExecutorch/models/stt/WhisperDecoder.hpp index a8dfc9ab..ae6e74ed 100644 --- a/ios/RnExecutorch/models/stt/WhisperDecoder.hpp +++ b/ios/RnExecutorch/models/stt/WhisperDecoder.hpp @@ -8,10 +8,9 @@ @interface WhisperDecoder : BaseModel -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState; +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState; @end - - #endif /* WhisperDecoder_hpp */ diff --git a/ios/RnExecutorch/models/stt/WhisperDecoder.mm b/ios/RnExecutorch/models/stt/WhisperDecoder.mm index 9cfbd39e..902e738f 100644 --- a/ios/RnExecutorch/models/stt/WhisperDecoder.mm +++ b/ios/RnExecutorch/models/stt/WhisperDecoder.mm @@ -3,17 +3,20 @@ NSNumber *encoderLastHiddenStateType = ScalarType.Float; NSNumber *prevTokensType = ScalarType.Int32; -NSArray *decoderInputTypes = @[prevTokensType, encoderLastHiddenStateType]; -NSArray *encoderLastHiddenStateShape = @[@1, @1500, @384]; +NSArray *decoderInputTypes = @[ prevTokensType, encoderLastHiddenStateType ]; +NSArray *encoderLastHiddenStateShape = @[ @1, @1500, @384 ]; @implementation WhisperDecoder -- (NSArray *)decode:(NSArray *)prevTokens encoderLastHiddenState:(NSArray *)encoderLastHiddenState { +- (NSArray *)decode:(NSArray *)prevTokens + encoderLastHiddenState:(NSArray *)encoderLastHiddenState { NSNumber *tokensCount = @([prevTokens count]); - NSArray *prevTokensShape = @[@1, tokensCount]; - NSArray *predictedToken = [self forward:@[prevTokens, encoderLastHiddenState] shapes:@[prevTokensShape, encoderLastHiddenStateShape] inputTypes:decoderInputTypes]; + NSArray *prevTokensShape = @[ @1, tokensCount ]; + NSArray *predictedToken = + [self forward:@[ prevTokens, encoderLastHiddenState ] + shapes:@[ prevTokensShape, encoderLastHiddenStateShape ] + inputTypes:decoderInputTypes]; return [predictedToken objectAtIndex:0]; - } @end diff --git a/ios/RnExecutorch/models/stt/WhisperEncoder.hpp b/ios/RnExecutorch/models/stt/WhisperEncoder.hpp index 4dd4fc7a..46077b61 100644 --- a/ios/RnExecutorch/models/stt/WhisperEncoder.hpp +++ b/ios/RnExecutorch/models/stt/WhisperEncoder.hpp @@ -12,6 +12,4 @@ @end - - #endif /* WhisperEncoder_hpp */ diff --git a/ios/RnExecutorch/models/stt/WhisperEncoder.mm b/ios/RnExecutorch/models/stt/WhisperEncoder.mm index 9348d0be..f1a8c589 100644 --- a/ios/RnExecutorch/models/stt/WhisperEncoder.mm +++ b/ios/RnExecutorch/models/stt/WhisperEncoder.mm @@ -1,6 +1,6 @@ #import "WhisperEncoder.hpp" -#import "../../utils/ScalarType.h" #import "../../utils/SFFT.hpp" +#import "../../utils/ScalarType.h" NSArray *spectrogramInputType = [NSArray arrayWithObject:ScalarType.Float]; NSNumber *fftFrameSize = @256; @@ -11,7 +11,9 @@ - (NSArray *)encode:(NSArray *)waveform { NSArray *stft = [SFFT sfftFromWaveform:waveform fftSize:512 fftHopLength:160]; NSNumber *numFrames = [NSNumber numberWithDouble:([stft count] / 256)]; NSArray *inputShape = @[ @[ numFrames, fftFrameSize ] ]; - NSArray *result = [self forward:@[stft] shapes:inputShape inputTypes:spectrogramInputType]; + NSArray *result = [self forward:@[ stft ] + shapes:inputShape + inputTypes:spectrogramInputType]; // unsquezing before the return, since forward returns an array of results; return [result objectAtIndex:0]; } diff --git a/ios/RnExecutorch/utils/ImageProcessor.mm b/ios/RnExecutorch/utils/ImageProcessor.mm index be389746..d2da07df 100644 --- a/ios/RnExecutorch/utils/ImageProcessor.mm +++ b/ios/RnExecutorch/utils/ImageProcessor.mm @@ -4,7 +4,9 @@ @implementation ImageProcessor + (NSArray *)matToNSArray:(const cv::Mat &)mat { - return [ImageProcessor matToNSArray:mat mean:cv::Scalar(0.0, 0.0, 0.0) variance:cv::Scalar(1.0, 1.0, 1.0)]; + return [ImageProcessor matToNSArray:mat + mean:cv::Scalar(0.0, 0.0, 0.0) + variance:cv::Scalar(1.0, 1.0, 1.0)]; } + (NSArray *)matToNSArray:(const cv::Mat &)mat @@ -21,24 +23,28 @@ + (NSArray *)matToNSArray:(const cv::Mat &)mat int row = i / mat.cols; int col = i % mat.cols; cv::Vec3b pixel = mat.at(row, col); - floatArray[0 * pixelCount + i] = @((pixel[0] - mean[0] * 255.0) / (variance[0] * 255.0)); - floatArray[1 * pixelCount + i] = @((pixel[1] - mean[1] * 255.0) / (variance[1] * 255.0)); - floatArray[2 * pixelCount + i] = @((pixel[2] - mean[2] * 255.0) / (variance[2] * 255.0)); + floatArray[0 * pixelCount + i] = + @((pixel[0] - mean[0] * 255.0) / (variance[0] * 255.0)); + floatArray[1 * pixelCount + i] = + @((pixel[1] - mean[1] * 255.0) / (variance[1] * 255.0)); + floatArray[2 * pixelCount + i] = + @((pixel[2] - mean[2] * 255.0) / (variance[2] * 255.0)); } return floatArray; } + (NSArray *)matToNSArrayGray:(const cv::Mat &)mat { - NSMutableArray *pixelArray = [[NSMutableArray alloc] initWithCapacity:mat.cols * mat.rows]; - + NSMutableArray *pixelArray = + [[NSMutableArray alloc] initWithCapacity:mat.cols * mat.rows]; + for (int row = 0; row < mat.rows; row++) { for (int col = 0; col < mat.cols; col++) { float pixelValue = mat.at(row, col); [pixelArray addObject:@(pixelValue)]; } } - + return pixelArray; } @@ -64,7 +70,7 @@ + (NSArray *)matToNSArrayGray:(const cv::Mat &)mat { + (cv::Mat)arrayToMatGray:(NSArray *)array width:(int)width height:(int)height { cv::Mat mat(height, width, CV_32F); - + int pixelCount = width * height; for (int i = 0; i < pixelCount; i++) { int row = i / width; @@ -72,7 +78,7 @@ + (NSArray *)matToNSArrayGray:(const cv::Mat &)mat { float value = [array[i] floatValue]; mat.at(row, col) = value; } - + return mat; } diff --git a/ios/RnExecutorch/utils/SFFT.hpp b/ios/RnExecutorch/utils/SFFT.hpp index b0710e0d..8ce6cd3d 100644 --- a/ios/RnExecutorch/utils/SFFT.hpp +++ b/ios/RnExecutorch/utils/SFFT.hpp @@ -1,5 +1,5 @@ -#import #import +#import @interface SFFT : NSObject @@ -7,7 +7,7 @@ fftSize:(int)fftSize fftHopLength:(int)fftHopLength; + (void)fft:(float *)signal - fftSetup:(FFTSetup)fftSetup - fftSize:(int)fftSize - magnitudes:(NSMutableArray *)magnitudes; + fftSetup:(FFTSetup)fftSetup + fftSize:(int)fftSize + magnitudes:(NSMutableArray *)magnitudes; @end diff --git a/ios/RnExecutorch/utils/ScalarType.h b/ios/RnExecutorch/utils/ScalarType.h index 4a2e0fa8..81a51167 100644 --- a/ios/RnExecutorch/utils/ScalarType.h +++ b/ios/RnExecutorch/utils/ScalarType.h @@ -5,11 +5,11 @@ @interface ScalarType : NSObject -@property (class, nonatomic, readonly) NSNumber *Int8; -@property (class, nonatomic, readonly) NSNumber *Int32; -@property (class, nonatomic, readonly) NSNumber *Long; -@property (class, nonatomic, readonly) NSNumber *Float; -@property (class, nonatomic, readonly) NSNumber *Double; +@property(class, nonatomic, readonly) NSNumber *Int8; +@property(class, nonatomic, readonly) NSNumber *Int32; +@property(class, nonatomic, readonly) NSNumber *Long; +@property(class, nonatomic, readonly) NSNumber *Float; +@property(class, nonatomic, readonly) NSNumber *Double; @end diff --git a/ios/RnExecutorch/utils/ScalarType.mm b/ios/RnExecutorch/utils/ScalarType.mm index 6d55be10..cdd9a8a8 100644 --- a/ios/RnExecutorch/utils/ScalarType.mm +++ b/ios/RnExecutorch/utils/ScalarType.mm @@ -2,10 +2,20 @@ @implementation ScalarType -+ (NSNumber *)Int8 { return @1; } -+ (NSNumber *)Int32 { return @3; } -+ (NSNumber *)Long { return @4; } -+ (NSNumber *)Float { return @6; } -+ (NSNumber *)Double { return @7; } ++ (NSNumber *)Int8 { + return @1; +} ++ (NSNumber *)Int32 { + return @3; +} ++ (NSNumber *)Long { + return @4; +} ++ (NSNumber *)Float { + return @6; +} ++ (NSNumber *)Double { + return @7; +} @end diff --git a/jitpack.yml b/jitpack.yml index af034d83..3b14bc09 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,3 +1,3 @@ install: -- FILE="-Dfile=third-party/android/libs/executorch.aar" -- mvn install:install-file $FILE -DgroupId=com.software-mansion.executorch -DartifactId=repo -Dversion=0.1.2 -Dpackaging=aar -DgeneratePom=true \ No newline at end of file + - FILE="-Dfile=third-party/android/libs/executorch.aar" + - mvn install:install-file $FILE -DgroupId=com.software-mansion.executorch -DartifactId=repo -Dversion=0.1.2 -Dpackaging=aar -DgeneratePom=true diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h index 2c7477c1..79b547ad 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h @@ -22,7 +22,6 @@ - (NSNumber *)getOutputType:(NSNumber *)index; - (NSArray *)getOutputShape:(NSNumber *)index; - @end #endif // ETModel_hpp diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm index 604d9d9d..28c63047 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm @@ -192,43 +192,47 @@ - (NSArray *)execute:(NSString *)methodName inputTypes:(NSArray *)inputTypes { std::vector inputTensors; std::vector inputTensorPtrs; - + for (NSUInteger i = 0; i < [inputTypes count]; i++) { NSArray *inputShapeNSArray = [shapes objectAtIndex:i]; - + std::vector inputShape = NSArrayToIntVector(inputShapeNSArray); int inputType = [[inputTypes objectAtIndex:i] intValue]; - + NSArray *input = [inputs objectAtIndex:i]; - + TensorPtr currentTensor = NSArrayToTensorPtr(input, inputShape, inputType); if (!currentTensor) { throw [NSException - exceptionWithName:@"forward_error" - reason:[NSString stringWithFormat:@"%d", Error::InvalidArgument] - userInfo:nil]; + exceptionWithName:@"forward_error" + reason:[NSString + stringWithFormat:@"%d", Error::InvalidArgument] + userInfo:nil]; } - - // Since pushing back to inputTensors would cast to EValue (forward accepts a vector of EValues) - // We also push back to inputTensorPtrs to keep the underlying tensor alive. - // inputTensorPtrs vector retains shared ownership to prevent premature destruction + + // Since pushing back to inputTensors would cast to EValue (forward accepts + // a vector of EValues) We also push back to inputTensorPtrs to keep the + // underlying tensor alive. inputTensorPtrs vector retains shared ownership + // to prevent premature destruction inputTensors.push_back(*currentTensor); inputTensorPtrs.push_back(currentTensor); } - + Result result = _model->execute([methodName UTF8String], inputTensors); - + if (!result.ok()) { throw [NSException - exceptionWithName:@"forward_error" - reason:[NSString stringWithFormat:@"%d", result.error()] - userInfo:nil]; + exceptionWithName:@"forward_error" + reason:[NSString stringWithFormat:@"%d", result.error()] + userInfo:nil]; } - + NSMutableArray *output = [NSMutableArray new]; for (int i = 0; i < result->size(); i++) { auto currentResultTensor = result->at(i).toTensor(); - NSArray *currentOutput = arrayToNsArray(currentResultTensor.const_data_ptr(), currentResultTensor.numel(), currentResultTensor.scalar_type()); + NSArray *currentOutput = arrayToNsArray( + currentResultTensor.const_data_ptr(), currentResultTensor.numel(), + currentResultTensor.scalar_type()); [output addObject:currentOutput]; } return output; @@ -236,7 +240,10 @@ - (NSArray *)execute:(NSString *)methodName - (NSArray *)forward:(NSArray *)inputs shapes:(NSArray *)shapes inputTypes:(NSArray *)inputTypes { - return [self execute:@"forward" inputs:inputs shapes:shapes inputTypes:inputTypes]; + return [self execute:@"forward" + inputs:inputs + shapes:shapes + inputTypes:inputTypes]; } @end diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h index 39e867d0..e269d041 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h @@ -16,13 +16,13 @@ FOUNDATION_EXPORT NSErrorDomain const LLaVARunnerErrorDomain; NS_SWIFT_NAME(Runner) @interface LLaMARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(NSString*)prompt - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(NSString *)prompt + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; @@ -33,17 +33,17 @@ NS_SWIFT_NAME(Runner) NS_SWIFT_NAME(LLaVARunner) @interface LLaVARunner : NSObject -- (instancetype)initWithModelPath:(NSString*)filePath - tokenizerPath:(NSString*)tokenizerPath; +- (instancetype)initWithModelPath:(NSString *)filePath + tokenizerPath:(NSString *)tokenizerPath; - (BOOL)isloaded; -- (BOOL)loadWithError:(NSError**)error; -- (BOOL)generate:(void*)imageBuffer +- (BOOL)loadWithError:(NSError **)error; +- (BOOL)generate:(void *)imageBuffer width:(CGFloat)width height:(CGFloat)height - prompt:(NSString*)prompt + prompt:(NSString *)prompt sequenceLength:(NSInteger)seq_len - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error; + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error; - (void)stop; + (instancetype)new NS_UNAVAILABLE; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm index 1c0b7c79..ab9392f3 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm @@ -8,28 +8,28 @@ #import "LLaMARunner.h" -#import #import "runner.h" +#import using namespace ::torch::executor; NSErrorDomain const LLaMARunnerErrorDomain = @"LLaMARunnerErrorDomain"; NSErrorDomain const LLaVARunnerErrorDomain = @"LLaVARunnerErrorDomain"; -@interface LLaMARunner () +@interface LLaMARunner () @end @implementation LLaMARunner { std::unique_ptr _runner; } -- (instancetype)initWithModelPath:(NSString*)modelPath - tokenizerPath:(NSString*)tokenizerPath { +- (instancetype)initWithModelPath:(NSString *)modelPath + tokenizerPath:(NSString *)tokenizerPath { self = [super init]; if (self) { [ExecuTorchLog.sharedLog addSink:self]; - _runner = std::make_unique( - modelPath.UTF8String, tokenizerPath.UTF8String); + _runner = std::make_unique(modelPath.UTF8String, + tokenizerPath.UTF8String); } return self; } @@ -42,7 +42,7 @@ - (BOOL)isloaded { return _runner->is_loaded(); } -- (BOOL)loadWithError:(NSError**)error { +- (BOOL)loadWithError:(NSError **)error { const auto status = _runner->load(); if (status != Error::Ok) { if (error) { @@ -55,13 +55,12 @@ - (BOOL)loadWithError:(NSError**)error { return YES; } -- (BOOL)generate:(NSString*)prompt - withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error { +- (BOOL)generate:(NSString *)prompt + withTokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error { const auto status = _runner->generate( - prompt.UTF8String, [callback](const std::string& token) { - callback(@(token.c_str())); - }); + prompt.UTF8String, + [callback](const std::string &token) { callback(@(token.c_str())); }); if (status != Error::Ok) { if (error) { *error = [NSError errorWithDomain:LLaMARunnerErrorDomain @@ -81,24 +80,17 @@ - (void)stop { - (void)logWithLevel:(ExecuTorchLogLevel)level timestamp:(NSTimeInterval)timestamp - filename:(NSString*)filename + filename:(NSString *)filename line:(NSUInteger)line - message:(NSString*)message { + message:(NSString *)message { NSUInteger totalSeconds = (NSUInteger)timestamp; NSUInteger hours = (totalSeconds / 3600) % 24; NSUInteger minutes = (totalSeconds / 60) % 60; NSUInteger seconds = totalSeconds % 60; NSUInteger microseconds = (timestamp - totalSeconds) * 1000000; - NSLog( - @"%c %02lu:%02lu:%02lu.%06lu executorch:%s:%zu] %s", - (char)level, - hours, - minutes, - seconds, - microseconds, - filename.UTF8String, - line, - message.UTF8String); + NSLog(@"%c %02lu:%02lu:%02lu.%06lu executorch:%s:%zu] %s", (char)level, hours, + minutes, seconds, microseconds, filename.UTF8String, line, + message.UTF8String); } @end diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp b/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp index 7c3fd7cb..fc71c7f0 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp @@ -83,19 +83,19 @@ NSNumber *scalarTypeToNSNumber(ScalarType scalarType) { return @(static_cast(scalarType)); } -NSArray* flattenArray(NSArray *array) { - NSMutableArray *flatArray = [NSMutableArray array]; - - for (id element in array) { - if ([element isKindOfClass:[NSArray class]]) { - NSArray *nestedArray = flattenArray(element); - [flatArray addObjectsFromArray:nestedArray]; - } else { - [flatArray addObject:element]; - } +NSArray *flattenArray(NSArray *array) { + NSMutableArray *flatArray = [NSMutableArray array]; + + for (id element in array) { + if ([element isKindOfClass:[NSArray class]]) { + NSArray *nestedArray = flattenArray(element); + [flatArray addObjectsFromArray:nestedArray]; + } else { + [flatArray addObject:element]; } + } - return [flatArray copy]; + return [flatArray copy]; } void *NSArrayToVoidArray(NSArray *nsArray, ScalarType inputScalarType, @@ -140,7 +140,8 @@ TensorPtr NSArrayToTensorPtr(NSArray *nsArray, std::vector shape, void *data = NSArrayToVoidArray(nsArray, inputScalarType, arraySize); std::function deleter = getDeleterForScalarType(inputScalarType); - auto tensor = make_tensor_ptr(shape, data, inputScalarType, TensorShapeDynamism::DYNAMIC_UNBOUND, deleter); + auto tensor = make_tensor_ptr(shape, data, inputScalarType, + TensorShapeDynamism::DYNAMIC_UNBOUND, deleter); return tensor; } @@ -170,7 +171,8 @@ NSArray *arrayToNSArray(const std::vector> &dataPtrVec) { return [nsArray copy]; } -NSArray *arrayToNsArray(const void *dataPtr, size_t numel, ScalarType scalarType) { +NSArray *arrayToNsArray(const void *dataPtr, size_t numel, + ScalarType scalarType) { switch (scalarType) { case ScalarType::Char: { NSArray *outputArray = arrayToNSArray(dataPtr, numel); diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp index ade6b2e0..e7f8c8b6 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp @@ -4,12 +4,8 @@ using ::executorch::extension::Module; -Model::Model( - const std::string& file_path - ){ +Model::Model(const std::string &file_path) { module_ = std::make_unique(file_path); } -void Model::forward(){ - return; -} +void Model::forward() { return; } diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h b/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h index 9de07873..8e3b7fbd 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h @@ -1,11 +1,11 @@ #include class Model { - public: - explicit Model( - const std::string& file_path); +public: + explicit Model(const std::string &file_path); void forward(); - private: + +private: std::unique_ptr<::executorch::extension::Module> module_; }; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp index 3fdaa7f3..34c5cb92 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp @@ -39,35 +39,29 @@ static constexpr auto kUseKVCache = "use_kv_cache"; static constexpr auto kUseSDPAWithKVCache = "use_sdpa_with_kv_cache"; } // namespace -Runner::Runner( - const std::string& model_path, - const std::string& tokenizer_path, - const float temperature) +Runner::Runner(const std::string &model_path, const std::string &tokenizer_path, + const float temperature) // NOTE: we observed ~2x loading performance increase on iPhone 15 // and a ~5% improvement on Galaxy S22 by switching to // FileDataLoader instead of MmapDataLoader + UseMlockIgnoreErrors. : temperature_(temperature), module_(std::make_unique(model_path, Module::LoadMode::File)), - tokenizer_path_(tokenizer_path), - metadata_({ - {kAppendEosToPrompt, false}, - {kEnableDynamicShape, false}, - {kMaxSeqLen, 128}, - {kNBos, 1}, - {kNEos, 1}, - {kUseKVCache, true}, - {kUseSDPAWithKVCache, false}, - }) { - ET_LOG( - Info, - "Creating LLaMa runner: model_path=%s, tokenizer_path=%s", - model_path.c_str(), - tokenizer_path.c_str()); + tokenizer_path_(tokenizer_path), metadata_({ + {kAppendEosToPrompt, false}, + {kEnableDynamicShape, false}, + {kMaxSeqLen, 128}, + {kNBos, 1}, + {kNEos, 1}, + {kUseKVCache, true}, + {kUseSDPAWithKVCache, false}, + }) { + ET_LOG(Info, "Creating LLaMa runner: model_path=%s, tokenizer_path=%s", + model_path.c_str(), tokenizer_path.c_str()); } bool Runner::is_loaded() const { return module_->is_loaded() && tokenizer_ && text_decoder_runner_ && - text_prefiller_ && text_token_generator_; + text_prefiller_ && text_token_generator_; } Error Runner::load() { @@ -82,10 +76,9 @@ Error Runner::load() { // Rely on tiktoken to throw error if the artifact is incompatible. Then we // fallback to BPE tokenizer. if (err == Error::InvalidArgument) { - ET_LOG( - Info, - "Failed to load %s as a Tiktoken artifact, trying BPE tokenizer", - tokenizer_path_.c_str()); + ET_LOG(Info, + "Failed to load %s as a Tiktoken artifact, trying BPE tokenizer", + tokenizer_path_.c_str()); tokenizer_.reset(); tokenizer_ = std::make_unique(); tokenizer_->load(tokenizer_path_); @@ -101,56 +94,46 @@ Error Runner::load() { const auto method_names = ET_UNWRAP(module_->method_names(), "Failed reading method names"); - for (auto& pair : metadata_) { - const auto& method_name = pair.first; - auto& value = pair.second; + for (auto &pair : metadata_) { + const auto &method_name = pair.first; + auto &value = pair.second; if (method_names.count(method_name)) { value = ET_UNWRAP(module_->get(method_name)) .toScalar() .to(); } else { - ET_LOG( - Info, - "Methond %s not found, using the default value %" PRId64, - method_name.c_str(), - value); + ET_LOG(Info, "Methond %s not found, using the default value %" PRId64, + method_name.c_str(), value); } ET_LOG(Info, "Metadata: %s = %" PRId64, method_name.c_str(), value); } if (method_names.count(kEosIds)) { eos_ids->clear(); - for (const auto& eos_id : ET_UNWRAP(module_->execute(kEosIds))) { + for (const auto &eos_id : ET_UNWRAP(module_->execute(kEosIds))) { auto value = eos_id.toScalar().to(); eos_ids->emplace(value); ET_LOG(Info, "eos_id = %" PRId64, value); } } text_decoder_runner_ = std::make_unique( - module_.get(), - metadata_.at(kUseKVCache), - metadata_.at(kVocabSize), + module_.get(), metadata_.at(kUseKVCache), metadata_.at(kVocabSize), temperature_); text_prefiller_ = std::make_unique( - text_decoder_runner_.get(), - metadata_.at(kUseKVCache), + text_decoder_runner_.get(), metadata_.at(kUseKVCache), metadata_.at(kEnableDynamicShape)); text_token_generator_ = std::make_unique( - tokenizer_.get(), - text_decoder_runner_.get(), - metadata_.at(kUseKVCache), - std::move(eos_ids), - &stats_); + tokenizer_.get(), text_decoder_runner_.get(), metadata_.at(kUseKVCache), + std::move(eos_ids), &stats_); return Error::Ok; } -Error Runner::generate( - const std::string& prompt, - std::function token_callback, - std::function stats_callback, - bool echo) { +Error Runner::generate(const std::string &prompt, + std::function token_callback, + std::function stats_callback, + bool echo) { // Prepare the inputs. // Use ones-initialized inputs. ET_CHECK_MSG(!prompt.empty(), "Prompt cannot be null"); @@ -160,14 +143,12 @@ Error Runner::generate( stats_.model_load_end_ms = llm::time_in_ms(); } - ET_LOG( - Info, - "RSS after loading model: %f MiB (0 if unsupported)", - llm::get_rss_bytes() / 1024.0 / 1024.0); + ET_LOG(Info, "RSS after loading model: %f MiB (0 if unsupported)", + llm::get_rss_bytes() / 1024.0 / 1024.0); // Wrap the token_callback with print function - std::function wrapped_callback = - [token_callback](const std::string& piece) { + std::function wrapped_callback = + [token_callback](const std::string &piece) { llm::safe_printf(piece.c_str()); fflush(stdout); if (token_callback) { @@ -184,29 +165,26 @@ Error Runner::generate( int32_t seq_len = metadata_.at(kMaxSeqLen); Result> encode_res = tokenizer_->encode( - prompt, - metadata_.at(kNBos), + prompt, metadata_.at(kNBos), metadata_.at(kAppendEosToPrompt) ? metadata_.at(kNEos) : 0); - ET_CHECK_OK_OR_RETURN_ERROR( - encode_res.error(), "Failed to encode prompt %s", prompt.c_str()); + ET_CHECK_OK_OR_RETURN_ERROR(encode_res.error(), "Failed to encode prompt %s", + prompt.c_str()); // encode the (string) prompt into tokens sequence std::vector prompt_tokens = encode_res.get(); int num_prompt_tokens = prompt_tokens.size(); ET_CHECK_MSG(num_prompt_tokens >= 1, "Expected at least 1 prompt token"); - ET_CHECK_MSG( - num_prompt_tokens < metadata_.at(kMaxSeqLen), - "num_prompt_tokens %d >= max_seq_len_ %" PRId64 - ", Max seq length exceeded - please increase max seq len value in .../llama2/model.py", - num_prompt_tokens, - metadata_.at(kMaxSeqLen)); - ET_CHECK_MSG( - num_prompt_tokens < seq_len, - "num_prompt_tokens %d >= seq_len %d, Sequence length exceeded - please increase the seq_len value passed to generate()", - num_prompt_tokens, - seq_len); + ET_CHECK_MSG(num_prompt_tokens < metadata_.at(kMaxSeqLen), + "num_prompt_tokens %d >= max_seq_len_ %" PRId64 + ", Max seq length exceeded - please increase max seq len value " + "in .../llama2/model.py", + num_prompt_tokens, metadata_.at(kMaxSeqLen)); + ET_CHECK_MSG(num_prompt_tokens < seq_len, + "num_prompt_tokens %d >= seq_len %d, Sequence length exceeded - " + "please increase the seq_len value passed to generate()", + num_prompt_tokens, seq_len); // Prefill first // Here feed all tokens to the model and get the next predicted token @@ -225,10 +203,8 @@ Error Runner::generate( // print the first token from prefill. No prev_token so use cur_token for it. wrapped_callback(ET_UNWRAP(tokenizer_->decode(cur_token, cur_token))); - ET_LOG( - Info, - "RSS after prompt prefill: %f MiB (0 if unsupported)", - llm::get_rss_bytes() / 1024.0 / 1024.0); + ET_LOG(Info, "RSS after prompt prefill: %f MiB (0 if unsupported)", + llm::get_rss_bytes() / 1024.0 / 1024.0); // start the main loop prompt_tokens.push_back(cur_token); @@ -237,10 +213,8 @@ Error Runner::generate( stats_.inference_end_ms = llm::time_in_ms(); printf("\n"); - ET_LOG( - Info, - "RSS after finishing text generation: %f MiB (0 if unsupported)", - llm::get_rss_bytes() / 1024.0 / 1024.0); + ET_LOG(Info, "RSS after finishing text generation: %f MiB (0 if unsupported)", + llm::get_rss_bytes() / 1024.0 / 1024.0); if (num_prompt_tokens + num_generated_tokens == seq_len) { ET_LOG(Info, "Sequence length (%i tokens) reached!", seq_len); diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h index 25ab9ee8..98d5a2bb 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h @@ -27,23 +27,22 @@ namespace example { class Runner { - public: - explicit Runner( - const std::string& model_path, - const std::string& tokenizer_path, - const float temperature = 0.8f); +public: + explicit Runner(const std::string &model_path, + const std::string &tokenizer_path, + const float temperature = 0.8f); bool is_loaded() const; ::executorch::runtime::Error load(); - ::executorch::runtime::Error generate( - const std::string& prompt, - std::function token_callback = {}, - std::function - stats_callback = {}, - bool echo = true); + ::executorch::runtime::Error + generate(const std::string &prompt, + std::function token_callback = {}, + std::function + stats_callback = {}, + bool echo = true); void stop(); - private: +private: float temperature_; bool shouldStop_{false}; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h index df8acbb7..958c51f3 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h @@ -9,8 +9,8 @@ // Runner stats for LLM #pragma once #include "util.h" -#include #include +#include #include // patternlint-disable-next-line executorch-cpp-nostdinc #include @@ -52,13 +52,13 @@ struct Stats { aggregate_sampling_timer_start_timestamp = 0; } - private: +private: long aggregate_sampling_timer_start_timestamp = 0; }; static constexpr auto kTopp = 0.9f; -inline std::string stats_to_json_string(const Stats& stats) { +inline std::string stats_to_json_string(const Stats &stats) { std::stringstream ss; ss << "{\"prompt_tokens\":" << stats.num_prompt_tokens << "," << "\"generated_tokens\":" << stats.num_generated_tokens << "," @@ -74,20 +74,15 @@ inline std::string stats_to_json_string(const Stats& stats) { return ss.str(); } -inline void print_report(const Stats& stats) { +inline void print_report(const Stats &stats) { printf("PyTorchObserver %s\n", stats_to_json_string(stats).c_str()); - ET_LOG( - Info, - "\tPrompt Tokens: %" PRIu64 " Generated Tokens: %" PRIu64, - stats.num_prompt_tokens, - stats.num_generated_tokens); + ET_LOG(Info, "\tPrompt Tokens: %" PRIu64 " Generated Tokens: %" PRIu64, + stats.num_prompt_tokens, stats.num_generated_tokens); - ET_LOG( - Info, - "\tModel Load Time:\t\t%f (seconds)", - ((double)(stats.model_load_end_ms - stats.model_load_start_ms) / - stats.SCALING_FACTOR_UNITS_PER_SECOND)); + ET_LOG(Info, "\tModel Load Time:\t\t%f (seconds)", + ((double)(stats.model_load_end_ms - stats.model_load_start_ms) / + stats.SCALING_FACTOR_UNITS_PER_SECOND)); double inference_time_ms = (double)(stats.inference_end_ms - stats.inference_start_ms); ET_LOG( @@ -100,38 +95,32 @@ inline void print_report(const Stats& stats) { stats.SCALING_FACTOR_UNITS_PER_SECOND); double prompt_eval_time = (double)(stats.prompt_eval_end_ms - stats.inference_start_ms); - ET_LOG( - Info, - "\t\tPrompt evaluation:\t%f (seconds)\t\t Rate: \t%f (tokens/second)", - prompt_eval_time / stats.SCALING_FACTOR_UNITS_PER_SECOND, - (stats.num_prompt_tokens) / prompt_eval_time * - stats.SCALING_FACTOR_UNITS_PER_SECOND); + ET_LOG(Info, + "\t\tPrompt evaluation:\t%f (seconds)\t\t Rate: \t%f (tokens/second)", + prompt_eval_time / stats.SCALING_FACTOR_UNITS_PER_SECOND, + (stats.num_prompt_tokens) / prompt_eval_time * + stats.SCALING_FACTOR_UNITS_PER_SECOND); double eval_time = (double)(stats.inference_end_ms - stats.prompt_eval_end_ms); - ET_LOG( - Info, - "\t\tGenerated %" PRIu64 - " tokens:\t%f (seconds)\t\t Rate: \t%f (tokens/second)", - stats.num_generated_tokens, - eval_time / stats.SCALING_FACTOR_UNITS_PER_SECOND, - stats.num_generated_tokens / eval_time * - stats.SCALING_FACTOR_UNITS_PER_SECOND); + ET_LOG(Info, + "\t\tGenerated %" PRIu64 + " tokens:\t%f (seconds)\t\t Rate: \t%f (tokens/second)", + stats.num_generated_tokens, + eval_time / stats.SCALING_FACTOR_UNITS_PER_SECOND, + stats.num_generated_tokens / eval_time * + stats.SCALING_FACTOR_UNITS_PER_SECOND); // Time to first token is measured from the start of inference, excluding // model load time. - ET_LOG( - Info, - "\tTime to first generated token:\t%f (seconds)", - ((double)(stats.first_token_ms - stats.inference_start_ms) / - stats.SCALING_FACTOR_UNITS_PER_SECOND)); + ET_LOG(Info, "\tTime to first generated token:\t%f (seconds)", + ((double)(stats.first_token_ms - stats.inference_start_ms) / + stats.SCALING_FACTOR_UNITS_PER_SECOND)); - ET_LOG( - Info, - "\tSampling time over %" PRIu64 " tokens:\t%f (seconds)", - stats.num_prompt_tokens + stats.num_generated_tokens, - (double)stats.aggregate_sampling_time_ms / - stats.SCALING_FACTOR_UNITS_PER_SECOND); + ET_LOG(Info, "\tSampling time over %" PRIu64 " tokens:\t%f (seconds)", + stats.num_prompt_tokens + stats.num_generated_tokens, + (double)stats.aggregate_sampling_time_ms / + stats.SCALING_FACTOR_UNITS_PER_SECOND); } } // namespace llm diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp index 17955228..33eef3be 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp @@ -21,49 +21,39 @@ namespace llm { // NOTE: we observed ~2x loading performance increase on iPhone 15 // and a ~5% improvement on Galaxy S22 by switching to // FileDataLoader instead of MmapDataLoader + UseMlockIgnoreErrors. -TextDecoderRunner::TextDecoderRunner( - Module* module, - bool use_kv_cache, - int32_t vocab_size, - float temperature) +TextDecoderRunner::TextDecoderRunner(Module *module, bool use_kv_cache, + int32_t vocab_size, float temperature) : module_(module), sampler_(std::make_unique( - vocab_size, - temperature, - kTopp, + vocab_size, temperature, kTopp, static_cast(std::time(nullptr)))), use_kv_cache_(use_kv_cache) {} // This function is functional, meaning it shouldn't modify any state of the // input. It should be safe to call multiple times with the same inputs. The // outer loop (call site) is responsible for managing state. -::executorch::runtime::Result TextDecoderRunner::step( - TensorPtr& tokens, - TensorPtr& start_pos) { +::executorch::runtime::Result +TextDecoderRunner::step(TensorPtr &tokens, TensorPtr &start_pos) { // ET_LOG(Info, "Input token %" PRIu64, input_token); if (use_kv_cache_) { auto outputs_res = module_->forward({tokens, start_pos}); ET_CHECK_OK_OR_RETURN_ERROR(outputs_res.error()); - ET_CHECK_MSG( - outputs_res.get().size() == 1, - "More then one output returned from executing LLM."); - ET_CHECK_MSG( - outputs_res.get()[0].isTensor(), - "Non Tensor Output returned from executing LLM"); + ET_CHECK_MSG(outputs_res.get().size() == 1, + "More then one output returned from executing LLM."); + ET_CHECK_MSG(outputs_res.get()[0].isTensor(), + "Non Tensor Output returned from executing LLM"); // Return the logits tensor return outputs_res.get()[0].toTensor(); - } else { // no kv cache + } else { // no kv cache (void)start_pos; // unused auto outputs_res = module_->forward(tokens); ET_CHECK_OK_OR_RETURN_ERROR(outputs_res.error()); - ET_CHECK_MSG( - outputs_res.get().size() == 1, - "More then one output returned from executing LLM."); - ET_CHECK_MSG( - outputs_res.get()[0].isTensor(), - "Non Tensor Output returned from executing LLM"); + ET_CHECK_MSG(outputs_res.get().size() == 1, + "More then one output returned from executing LLM."); + ET_CHECK_MSG(outputs_res.get()[0].isTensor(), + "Non Tensor Output returned from executing LLM"); // Return the logits tensor return outputs_res.get()[0].toTensor(); diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h index e3532379..97d63f28 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h @@ -21,12 +21,9 @@ namespace extension { namespace llm { class TextDecoderRunner { - public: - TextDecoderRunner( - Module* module, - bool use_kv_cache, - int32_t vocab_size, - float temperature); +public: + TextDecoderRunner(Module *module, bool use_kv_cache, int32_t vocab_size, + float temperature); virtual ~TextDecoderRunner() = default; @@ -37,9 +34,8 @@ class TextDecoderRunner { * Module. * @return The output of the LLM Module. This will be a tensor of logits. */ - virtual ::executorch::runtime::Result step( - TensorPtr& input, - TensorPtr& start_pos); + virtual ::executorch::runtime::Result + step(TensorPtr &input, TensorPtr &start_pos); /** * Load the Module for text decode purpose. @@ -57,46 +53,39 @@ class TextDecoderRunner { return module_->is_method_loaded("forward"); } - inline void stop() { - should_stop_ = true; - } + inline void stop() { should_stop_ = true; } /** * Sample the next token from the logits tensor. * @param logits_tensor The logits tensor. * @return The next token. */ - inline int32_t logits_to_token(const exec_aten::Tensor& logits_tensor) { + inline int32_t logits_to_token(const exec_aten::Tensor &logits_tensor) { int32_t result = 0; - ET_SWITCH_THREE_TYPES( - Float, - Half, - BFloat16, - logits_tensor.scalar_type(), - unused, - "logits_to_token", - CTYPE, - [&]() { - // If the logit_tensor rank is 3, the shape is [batch, seq_length, - // vocab_size], get the last logits, sample and return. Else the model - // outputs the last logit, directly sample and return. - auto* logits = logits_tensor.mutable_data_ptr(); - if (logits_tensor.dim() == 3) { - auto num_tokens = logits_tensor.size(1); - auto vocab_size = logits_tensor.size(2); - auto* logits_last = logits; - logits_last += (num_tokens - 1) * vocab_size; - result = sampler_->sample(logits_last); - } else { - result = sampler_->sample(logits); - } - }); + ET_SWITCH_THREE_TYPES(Float, Half, BFloat16, logits_tensor.scalar_type(), + unused, "logits_to_token", CTYPE, [&]() { + // If the logit_tensor rank is 3, the shape is + // [batch, seq_length, vocab_size], get the last + // logits, sample and return. Else the model outputs + // the last logit, directly sample and return. + auto *logits = + logits_tensor.mutable_data_ptr(); + if (logits_tensor.dim() == 3) { + auto num_tokens = logits_tensor.size(1); + auto vocab_size = logits_tensor.size(2); + auto *logits_last = logits; + logits_last += (num_tokens - 1) * vocab_size; + result = sampler_->sample(logits_last); + } else { + result = sampler_->sample(logits); + } + }); return result; } - protected: +protected: // TODO: use shared_ptr for module - Module* module_; + Module *module_; std::unique_ptr sampler_; bool use_kv_cache_; bool should_stop_{false}; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp index 70263faa..34f7347d 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp @@ -15,17 +15,14 @@ namespace executorch { namespace extension { namespace llm { -TextPrefiller::TextPrefiller( - TextDecoderRunner* text_decoder_runner, - bool use_kv_cache, - bool enable_parallel_prefill) - : text_decoder_runner_(text_decoder_runner), - use_kv_cache_(use_kv_cache), +TextPrefiller::TextPrefiller(TextDecoderRunner *text_decoder_runner, + bool use_kv_cache, bool enable_parallel_prefill) + : text_decoder_runner_(text_decoder_runner), use_kv_cache_(use_kv_cache), enable_parallel_prefill_(enable_parallel_prefill) {} -::executorch::runtime::Result TextPrefiller::prefill( - std::vector& prompt_tokens, - int64_t& start_pos) { +::executorch::runtime::Result +TextPrefiller::prefill(std::vector &prompt_tokens, + int64_t &start_pos) { ET_CHECK_MSG(!prompt_tokens.empty(), "Prompt cannot be null"); if (!text_decoder_runner_->is_method_loaded()) { ET_CHECK_OK_OR_RETURN_ERROR(text_decoder_runner_->load()); @@ -38,10 +35,8 @@ ::executorch::runtime::Result TextPrefiller::prefill( uint64_t cur_token; if (enable_parallel_prefill_ || !use_kv_cache_) { // initialize tensor wrappers - auto tokens = from_blob( - prompt_tokens.data(), - {1, num_prompt_tokens}, - exec_aten::ScalarType::Long); + auto tokens = from_blob(prompt_tokens.data(), {1, num_prompt_tokens}, + exec_aten::ScalarType::Long); auto start_pos_tensor = from_blob(&start_pos, {1}, exec_aten::ScalarType::Long); @@ -49,12 +44,12 @@ ::executorch::runtime::Result TextPrefiller::prefill( auto outputs_res = text_decoder_runner_->step(tokens, start_pos_tensor); ET_CHECK_OK_OR_RETURN_ERROR(outputs_res.error()); - ET_LOG( - Info, "Prefill token result numel(): %zu", outputs_res.get().numel()); + ET_LOG(Info, "Prefill token result numel(): %zu", + outputs_res.get().numel()); start_pos += num_prompt_tokens; cur_token = text_decoder_runner_->logits_to_token(outputs_res.get()); - } else { // sequential prefill + } else { // sequential prefill int64_t pos = 0; // position in the sequence // NOLINTNEXTLINE(facebook-hte-ParameterUncheckedArrayBounds) cur_token = prompt_tokens[0]; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h index c81b403e..9d40d451 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h @@ -21,11 +21,9 @@ namespace extension { namespace llm { class TextPrefiller { - public: - TextPrefiller( - TextDecoderRunner* text_decoder_runner, - bool use_kv_cache_, - bool enable_parallel_prefill); +public: + TextPrefiller(TextDecoderRunner *text_decoder_runner, bool use_kv_cache_, + bool enable_parallel_prefill); /** * Prefill an LLM Module with the given text input. * @param prompt_tokens The text prompt tokens to the LLM Module. Encoded by @@ -34,12 +32,11 @@ class TextPrefiller { * Module. * @return The next token of the LLM Module after prefill. */ - ::executorch::runtime::Result prefill( - std::vector& prompt_tokens, - int64_t& start_pos); + ::executorch::runtime::Result + prefill(std::vector &prompt_tokens, int64_t &start_pos); - private: - TextDecoderRunner* text_decoder_runner_; +private: + TextDecoderRunner *text_decoder_runner_; bool use_kv_cache_; bool enable_parallel_prefill_; }; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h index 042ca378..e1c62dab 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h @@ -20,125 +20,117 @@ namespace llm { class TextTokenGenerator { public: - TextTokenGenerator( - Tokenizer* tokenizer, - TextDecoderRunner* text_decoder_runner, - bool use_kv_cache, - std::unique_ptr>&& eos_ids, - Stats* stats) - : tokenizer_(tokenizer), - text_decoder_runner_(text_decoder_runner), - eos_ids_(std::move(eos_ids)), - use_kv_cache_(use_kv_cache), - stats_(stats) {} - - /** - * Token generation loop. - * @param tokens prompt tokens as well as the first token generated by - * prefill. - * @param start_pos the start position of the new tokens, based on how many - * prompt tokens is prefilled. - * @param seq_len the total sequence length, including the prompt tokens, next - * token from prefill and new tokens. - * @param token_callback what to do after a token is generated. - * @return how many tokens are generated. - */ - inline ::executorch::runtime::Result generate( - std::vector tokens, - int64_t start_pos, - int32_t seq_len, - std::function token_callback) { - ET_CHECK_MSG( - !tokens.empty(), "Token generation loop shouldn't take empty tokens"); - int64_t pos = start_pos; // position in the sequence - should_stop_ = false; - - std::vector token_data; // allocate space for the tokens - std::vector token_shape; - - // Token after prefill - uint64_t cur_token = tokens.back(); - uint64_t prev_token; - - if (use_kv_cache_) { - // hard code these to size 1 as kv cache is locked to static size right - // now. - token_data = {cur_token}; - token_shape = {1, 1}; - } else { - token_data = tokens; - token_shape = {1, static_cast(tokens.size())}; - } - - // initialize tensor wrappers - auto tokens_managed = - from_blob(token_data.data(), token_shape, exec_aten::ScalarType::Long); - - auto start_pos_managed = from_blob(&pos, {1}, exec_aten::ScalarType::Long); - - // Generate our tokens - while (pos < seq_len - 1) { - // Run the model - auto logits_res = - text_decoder_runner_->step(tokens_managed, start_pos_managed); - - ET_CHECK_OK_OR_RETURN_ERROR(logits_res.error()); - exec_aten::Tensor& logits_tensor = logits_res.get(); - - prev_token = cur_token; - - stats_->on_sampling_begin(); - cur_token = text_decoder_runner_->logits_to_token(logits_tensor); - stats_->on_sampling_end(); - - pos++; - - if (use_kv_cache_) { - // update the token tensor. token_data will not be empty. - // NOLINTNEXTLINE(facebook-hte-LocalUncheckedArrayBounds) - token_data[0] = cur_token; - } else { - // push it to the back - token_data.push_back(cur_token); - ET_CHECK_OK_OR_RETURN_ERROR(resize_tensor_ptr( - tokens_managed, {1, static_cast(token_data.size())})); - } - - // print the token as string, decode it with the Tokenizer object - token_callback(ET_UNWRAP(tokenizer_->decode(prev_token, cur_token))); - - if (should_stop_) { - break; - } - - // data-dependent terminating condition: we have n_eos_ number of EOS - if (eos_ids_->find(cur_token) != eos_ids_->end()) { - printf("\n"); - ET_LOG(Info, "\nReached to the end of generation"); - break; - } - } - return pos - start_pos; + TextTokenGenerator(Tokenizer *tokenizer, + TextDecoderRunner *text_decoder_runner, bool use_kv_cache, + std::unique_ptr> &&eos_ids, + Stats *stats) + : tokenizer_(tokenizer), text_decoder_runner_(text_decoder_runner), + eos_ids_(std::move(eos_ids)), use_kv_cache_(use_kv_cache), + stats_(stats) {} + + /** + * Token generation loop. + * @param tokens prompt tokens as well as the first token generated by + * prefill. + * @param start_pos the start position of the new tokens, based on how many + * prompt tokens is prefilled. + * @param seq_len the total sequence length, including the prompt tokens, next + * token from prefill and new tokens. + * @param token_callback what to do after a token is generated. + * @return how many tokens are generated. + */ + inline ::executorch::runtime::Result + generate(std::vector tokens, int64_t start_pos, int32_t seq_len, + std::function token_callback) { + ET_CHECK_MSG(!tokens.empty(), + "Token generation loop shouldn't take empty tokens"); + int64_t pos = start_pos; // position in the sequence + should_stop_ = false; + + std::vector token_data; // allocate space for the tokens + std::vector token_shape; + + // Token after prefill + uint64_t cur_token = tokens.back(); + uint64_t prev_token; + + if (use_kv_cache_) { + // hard code these to size 1 as kv cache is locked to static size right + // now. + token_data = {cur_token}; + token_shape = {1, 1}; + } else { + token_data = tokens; + token_shape = {1, static_cast(tokens.size())}; } - - /** - * Stop the generation loop. - */ - inline void stop() { - should_stop_ = true; + + // initialize tensor wrappers + auto tokens_managed = + from_blob(token_data.data(), token_shape, exec_aten::ScalarType::Long); + + auto start_pos_managed = from_blob(&pos, {1}, exec_aten::ScalarType::Long); + + // Generate our tokens + while (pos < seq_len - 1) { + // Run the model + auto logits_res = + text_decoder_runner_->step(tokens_managed, start_pos_managed); + + ET_CHECK_OK_OR_RETURN_ERROR(logits_res.error()); + exec_aten::Tensor &logits_tensor = logits_res.get(); + + prev_token = cur_token; + + stats_->on_sampling_begin(); + cur_token = text_decoder_runner_->logits_to_token(logits_tensor); + stats_->on_sampling_end(); + + pos++; + + if (use_kv_cache_) { + // update the token tensor. token_data will not be empty. + // NOLINTNEXTLINE(facebook-hte-LocalUncheckedArrayBounds) + token_data[0] = cur_token; + } else { + // push it to the back + token_data.push_back(cur_token); + ET_CHECK_OK_OR_RETURN_ERROR(resize_tensor_ptr( + tokens_managed, {1, static_cast(token_data.size())})); + } + + // print the token as string, decode it with the Tokenizer object + token_callback(ET_UNWRAP(tokenizer_->decode(prev_token, cur_token))); + + if (should_stop_) { + break; + } + + // data-dependent terminating condition: we have n_eos_ number of EOS + if (eos_ids_->find(cur_token) != eos_ids_->end()) { + printf("\n"); + ET_LOG(Info, "\nReached to the end of generation"); + break; + } } - + return pos - start_pos; + } + + /** + * Stop the generation loop. + */ + inline void stop() { should_stop_ = true; } + private: - Tokenizer* tokenizer_; - TextDecoderRunner* text_decoder_runner_; - std::unique_ptr> eos_ids_; - bool use_kv_cache_; - - // state machine - bool should_stop_ = false; - - // stats - Stats* stats_; + Tokenizer *tokenizer_; + TextDecoderRunner *text_decoder_runner_; + std::unique_ptr> eos_ids_; + bool use_kv_cache_; + + // state machine + bool should_stop_ = false; + + // stats + Stats *stats_; }; } // namespace llm diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h index 2f1d0848..28b887fa 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h @@ -7,9 +7,9 @@ */ #pragma once +#include #include #include -#include #if defined(__linux__) || defined(__ANDROID__) || defined(__unix__) #include #endif @@ -18,7 +18,7 @@ namespace executorch { namespace extension { namespace llm { -void inline safe_printf(const char* piece) { +void inline safe_printf(const char *piece) { // piece might be a raw byte token, and we only want to print printable chars // or whitespace because some of the other bytes can be various control codes, // backspace, etc. diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp index 8700c328..7ba81528 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp @@ -40,8 +40,7 @@ namespace extension { namespace llm { // sampler stuff -template -int32_t Sampler::sample_argmax(T* probabilities) { +template int32_t Sampler::sample_argmax(T *probabilities) { // return the index that has the highest probability int max_i = 0; T max_p = probabilities[0]; @@ -55,7 +54,7 @@ int32_t Sampler::sample_argmax(T* probabilities) { } template -int32_t Sampler::sample_mult(T* probabilities, float coin) { +int32_t Sampler::sample_mult(T *probabilities, float coin) { // sample index from probabilities (they must sum to 1!) // coin is a random number in [0, 1), usually from random_f32() T cdf = 0.0; @@ -69,7 +68,7 @@ int32_t Sampler::sample_mult(T* probabilities, float coin) { } template -int32_t Sampler::sample_topp(T* probabilities, float coin) { +int32_t Sampler::sample_topp(T *probabilities, float coin) { // top-p sampling (or "nucleus sampling") samples from the smallest set of // tokens that exceed probability topp. This way we never sample tokens that // have very low probabilities and are less likely to go "off the rails". @@ -91,7 +90,7 @@ int32_t Sampler::sample_topp(T* probabilities, float coin) { } } - auto compare = [](const ProbIndex& a, const ProbIndex& b) { + auto compare = [](const ProbIndex &a, const ProbIndex &b) { return a.prob > b.prob; }; std::sort(probindex.get(), probindex.get() + n0, compare); @@ -108,7 +107,7 @@ int32_t Sampler::sample_topp(T* probabilities, float coin) { } // sample from the truncated list - const T& r = coin * cumulative_prob; + const T &r = coin * cumulative_prob; T cdf = 0; for (int i = 0; i <= last_idx; i++) { cdf += probindex[i].prob; @@ -119,18 +118,13 @@ int32_t Sampler::sample_topp(T* probabilities, float coin) { return probindex[last_idx].index; // in case of rounding errors } -Sampler::Sampler( - int vocab_size, - float temperature, - float topp, - unsigned long long rng_seed) +Sampler::Sampler(int vocab_size, float temperature, float topp, + unsigned long long rng_seed) : vocab_size_(vocab_size), inv_temperature_(static_cast(temperature) ? 1.0f / temperature : 0), - topp_(topp), - rng_state_(rng_seed) {} + topp_(topp), rng_state_(rng_seed) {} -template -static void softmax(T* x, int size) { +template static void softmax(T *x, int size) { // find max value (for numerical stability) T max_val = x[0]; for (int i = 1; i < size; i++) { @@ -150,7 +144,7 @@ static void softmax(T* x, int size) { } } -static unsigned int random_u32(unsigned long long* state) { +static unsigned int random_u32(unsigned long long *state) { // xorshift rng: https://en.wikipedia.org/wiki/Xorshift#xorshift.2A *state ^= *state >> 12; *state ^= *state << 25; @@ -158,12 +152,11 @@ static unsigned int random_u32(unsigned long long* state) { return (*state * 0x2545F4914F6CDD1Dull) >> 32; } -static float random_f32(unsigned long long* state) { // random float32 in [0,1) +static float random_f32(unsigned long long *state) { // random float32 in [0,1) return (random_u32(state) >> 8) / 16777216.0f; } -template -int32_t Sampler::sample(T* logits) { +template int32_t Sampler::sample(T *logits) { // sample the token given the logits and some hyperparameters int next; if (inv_temperature_ == 0.0f) { @@ -190,10 +183,10 @@ int32_t Sampler::sample(T* logits) { return next; } -template int32_t Sampler::sample(float* logits); -template int32_t Sampler::sample(exec_aten::Half* logits); -template int32_t Sampler::sample( - exec_aten::BFloat16* logits); +template int32_t Sampler::sample(float *logits); +template int32_t Sampler::sample(exec_aten::Half *logits); +template int32_t +Sampler::sample(exec_aten::BFloat16 *logits); } // namespace llm } // namespace extension diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h b/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h index 9d6d742e..0b29ca9f 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h @@ -25,32 +25,24 @@ namespace extension { namespace llm { // A simple llama2 sampler. -template -struct ProbIndex { +template struct ProbIndex { T prob; int32_t index; }; // struct used when sorting probabilities during top-p sampling class Sampler { - public: - Sampler( - int32_t vocab_size, - float temperature, - float topp, - unsigned long long rng_seed); +public: + Sampler(int32_t vocab_size, float temperature, float topp, + unsigned long long rng_seed); - template - int32_t sample(T* logits); + template int32_t sample(T *logits); - private: - template - int32_t sample_topp(T* probabilities, float coin); - template - int32_t sample_mult(T* probabilities, float coin); - template - int32_t sample_argmax(T* probabilities); +private: + template int32_t sample_topp(T *probabilities, float coin); + template int32_t sample_mult(T *probabilities, float coin); + template int32_t sample_argmax(T *probabilities); - private: +private: int32_t vocab_size_; // reciprocal of temperature, or 0 if temperature == 0. float inv_temperature_; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h index 83ef9e06..722fe390 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h @@ -24,10 +24,10 @@ #pragma once +#include #include #include #include -#include #include #include @@ -35,12 +35,11 @@ namespace executorch { namespace extension { namespace llm { using Error = executorch::runtime::Error; -template -using Result = executorch::runtime::Result; +template using Result = executorch::runtime::Result; namespace base64 { -Result decode(const std::string_view& input); +Result decode(const std::string_view &input); namespace detail { @@ -69,12 +68,9 @@ inline Error validate(uint32_t v) { return Error::Ok; } -inline Error decode(const std::string_view& input, std::string& output) { - ET_CHECK_OR_RETURN_ERROR( - input.size() == 4, - InvalidArgument, - "input length must be 4, got %zu", - input.size()); +inline Error decode(const std::string_view &input, std::string &output) { + ET_CHECK_OR_RETURN_ERROR(input.size() == 4, InvalidArgument, + "input length must be 4, got %zu", input.size()); uint32_t val = 0; @@ -104,14 +100,10 @@ inline Error decode(const std::string_view& input, std::string& output) { return Error::Ok; } -inline Error decode_1_padding( - const std::string_view& input, - std::string& output) { - ET_CHECK_OR_RETURN_ERROR( - input.size() == 3, - InvalidArgument, - "input length must be 3, got %zu", - input.size()); +inline Error decode_1_padding(const std::string_view &input, + std::string &output) { + ET_CHECK_OR_RETURN_ERROR(input.size() == 3, InvalidArgument, + "input length must be 3, got %zu", input.size()); uint32_t val = 0; @@ -135,14 +127,10 @@ inline Error decode_1_padding( return Error::Ok; } -inline Error decode_2_padding( - const std::string_view& input, - std::string& output) { - ET_CHECK_OR_RETURN_ERROR( - input.size() == 2, - InvalidArgument, - "input length must be 2, got %zu", - input.size()); +inline Error decode_2_padding(const std::string_view &input, + std::string &output) { + ET_CHECK_OR_RETURN_ERROR(input.size() == 2, InvalidArgument, + "input length must be 2, got %zu", input.size()); uint32_t val = 0; @@ -162,13 +150,12 @@ inline Error decode_2_padding( } // namespace detail -inline Result decode(const std::string_view& input) { +inline Result decode(const std::string_view &input) { ET_CHECK_OR_RETURN_ERROR(!input.empty(), InvalidArgument, "empty input"); // Faster than `input.size() % 4`. ET_CHECK_OR_RETURN_ERROR( - (input.size() & 3) == 0 && input.size() >= 4, - InvalidArgument, + (input.size() & 3) == 0 && input.size() >= 4, InvalidArgument, "input length must be larger than 4 and is multiple of 4, got %zu", input.size()); diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp index 86d8a823..aa0a6d1b 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp @@ -17,14 +17,14 @@ namespace executorch { namespace extension { namespace llm { -static int compare_tokens(const void* a, const void* b) { - if (((TokenIndex*)a)->str == nullptr) { +static int compare_tokens(const void *a, const void *b) { + if (((TokenIndex *)a)->str == nullptr) { return -1; } - if (((TokenIndex*)b)->str == nullptr) { + if (((TokenIndex *)b)->str == nullptr) { return 1; } - return strcmp(((TokenIndex*)a)->str, ((TokenIndex*)b)->str); + return strcmp(((TokenIndex *)a)->str, ((TokenIndex *)b)->str); } BPETokenizer::BPETokenizer() : Tokenizer() { @@ -44,13 +44,13 @@ BPETokenizer::BPETokenizer() : Tokenizer() { * @param tokenizer_path The path to the tokenizer file. * @return Error */ -Error BPETokenizer::load(const std::string& tokenizer_path) { +Error BPETokenizer::load(const std::string &tokenizer_path) { if (initialized_) { ET_LOG(Info, "Tokenizer already initialized"); return Error::Ok; } // read in the file - FILE* file = fopen(tokenizer_path.c_str(), "rb"); + FILE *file = fopen(tokenizer_path.c_str(), "rb"); if (!file) { ET_LOG(Error, "couldn't load %s", tokenizer_path.c_str()); return Error::InvalidArgument; @@ -58,10 +58,10 @@ Error BPETokenizer::load(const std::string& tokenizer_path) { int32_t metadata[4]; for (int i = 0; i < 4; i++) { if (fread(metadata + i, sizeof(int32_t), 1, file) != 1) { - ET_LOG( - Error, - "Failed to read the metadata at position %d, the tokenizer file is not valid!", - i); + ET_LOG(Error, + "Failed to read the metadata at position %d, the tokenizer file " + "is not valid!", + i); return Error::InvalidArgument; } } @@ -75,7 +75,7 @@ Error BPETokenizer::load(const std::string& tokenizer_path) { max_token_length_ = metadata[3]; // allocate space for the vocabulary - vocab_ = std::make_unique(vocab_size_); + vocab_ = std::make_unique(vocab_size_); vocab_scores_ = std::make_unique(vocab_size_); sorted_vocab_ = std::make_unique(vocab_size_); @@ -96,11 +96,8 @@ Error BPETokenizer::load(const std::string& tokenizer_path) { } vocab_[i] = new char[len + 1]; if (fread(vocab_[i], len, 1, file) != 1) { - ET_LOG( - Error, - "Failed to read the word, total length %d, index %d\n", - len, - i); + ET_LOG(Error, "Failed to read the word, total length %d, index %d\n", len, + i); return Error::InvalidArgument; } vocab_[i][len] = '\0'; // add the string terminating token @@ -131,10 +128,10 @@ BPETokenizer::~BPETokenizer() { * @return Result A pointer to the string representation of the * token. */ -Result BPETokenizer::decode(uint64_t prev_token, uint64_t token) - const { +Result BPETokenizer::decode(uint64_t prev_token, + uint64_t token) const { ET_CHECK_OK_OR_RETURN_ERROR(Tokenizer::decode_verify(token)); - const char* piece = vocab_[token]; + const char *piece = vocab_[token]; // following BOS token, sentencepiece decoder strips any leading // whitespace if (prev_token == bos_tok_ && piece[0] == ' ') { @@ -144,19 +141,19 @@ Result BPETokenizer::decode(uint64_t prev_token, uint64_t token) // parse this and convert and return the actual byte unsigned char byte_val; if (sscanf(piece, "<0x%02hhX>", &byte_val) == 1) { - piece = (char*)byte_pieces_ + byte_val * 2; + piece = (char *)byte_pieces_ + byte_val * 2; } std::string res(piece); return res; } -static int32_t -str_lookup(const char* str, TokenIndex* sorted_vocab, int32_t vocab_size) { +static int32_t str_lookup(const char *str, TokenIndex *sorted_vocab, + int32_t vocab_size) { // efficiently find the perfect match for str in vocab, return its index or -1 // if not found TokenIndex tok = {.str = str}; // acts as the key to search for - TokenIndex* res = (TokenIndex*)bsearch( - &tok, sorted_vocab, vocab_size, sizeof(TokenIndex), compare_tokens); + TokenIndex *res = (TokenIndex *)bsearch(&tok, sorted_vocab, vocab_size, + sizeof(TokenIndex), compare_tokens); return res != nullptr ? res->id : -1; } @@ -171,7 +168,7 @@ str_lookup(const char* str, TokenIndex* sorted_vocab, int32_t vocab_size) { * @return Result> */ Result> -BPETokenizer::encode(const std::string& text, int8_t bos, int8_t eos) const { +BPETokenizer::encode(const std::string &text, int8_t bos, int8_t eos) const { if (!initialized_) { ET_LOG(Error, "Tokenizer not initialized"); return Error::NotSupported; @@ -187,7 +184,7 @@ BPETokenizer::encode(const std::string& text, int8_t bos, int8_t eos) const { // create a temporary buffer that will store merge candidates of always two // consecutive tokens *2 for concat, +1 for null terminator +2 for UTF8 (in // case max_token_length is 1) - char* str_buffer = new char[max_token_length_ * 2 + 1 + 2]; + char *str_buffer = new char[max_token_length_ * 2 + 1 + 2]; size_t str_len = 0; // start at 0 tokens @@ -208,7 +205,7 @@ BPETokenizer::encode(const std::string& text, int8_t bos, int8_t eos) const { // TODO: pretty sure this isn't correct in the general case but I don't have // the energy to read more of the sentencepiece code to figure out what it's // doing - const char* space = " "; + const char *space = " "; if (text[0] != '\0') { int dummy_prefix = str_lookup(space, sorted_vocab_.get(), vocab_size_); tokens.push_back(dummy_prefix); @@ -223,7 +220,7 @@ BPETokenizer::encode(const std::string& text, int8_t bos, int8_t eos) const { // U+10000 U+10FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // process the raw (UTF-8) byte sequence of the input string - for (const char* c = text.c_str(); *c != '\0'; c++) { + for (const char *c = text.c_str(); *c != '\0'; c++) { // reset buffer if the current byte is ASCII or a leading byte // 0xC0 is 11000000, so (*c & 0xC0) keeps the first 2 bits and zeros the // rest 0x80 is 10000000 in UTF-8, all continuation bytes start with "10" in @@ -273,12 +270,8 @@ BPETokenizer::encode(const std::string& text, int8_t bos, int8_t eos) const { for (int i = 0; i < tokens.size() - 1; i++) { // check if we can merge the pair (tokens[i], tokens[i+1]) - snprintf( - str_buffer, - max_token_length_ * 2 + 3, - "%s%s", - vocab_[tokens[i]], - vocab_[tokens[i + 1]]); + snprintf(str_buffer, max_token_length_ * 2 + 3, "%s%s", vocab_[tokens[i]], + vocab_[tokens[i + 1]]); int id = str_lookup(str_buffer, sorted_vocab_.get(), vocab_size_); if (id != -1 && vocab_scores_[id] > best_score) { // this merge pair exists in vocab! record its score and position diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h index 7b53d714..b6199057 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h @@ -16,28 +16,27 @@ namespace extension { namespace llm { struct TokenIndex { - const char* str; + const char *str; int32_t id; }; // A simple Byte Pair Encoding (BPE) Tokenizer. Note that the current C++ code // won't work with this class, it needs to go through tokenizer.py first. class BPETokenizer : public Tokenizer { - public: +public: explicit BPETokenizer(); ~BPETokenizer() override; - ::executorch::runtime::Error load(const std::string& tokenizer_path) override; + ::executorch::runtime::Error load(const std::string &tokenizer_path) override; ::executorch::runtime::Result> - encode(const std::string& input, int8_t bos, int8_t eos) const override; + encode(const std::string &input, int8_t bos, int8_t eos) const override; - ::executorch::runtime::Result decode( - uint64_t prev_token, - uint64_t token) const override; + ::executorch::runtime::Result + decode(uint64_t prev_token, uint64_t token) const override; - private: - std::unique_ptr vocab_ = nullptr; +private: + std::unique_ptr vocab_ = nullptr; std::unique_ptr vocab_scores_ = nullptr; std::unique_ptr sorted_vocab_ = nullptr; unsigned int max_token_length_ = 0; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp index dbf6bc04..8bc7ef48 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp @@ -21,23 +21,16 @@ static inline std::unique_ptr> _get_default_special_tokens() { auto special_tokens = std::make_unique>(std::vector{ - "<|begin_of_text|>", - "<|end_of_text|>", - "<|reserved_special_token_0|>", - "<|reserved_special_token_1|>", - "<|finetune_right_pad_id|>", - "<|step_id|>", - "<|start_header_id|>", - "<|end_header_id|>", - "<|eom_id|>", - "<|eot_id|>", - "<|python_tag|>"}); + "<|begin_of_text|>", "<|end_of_text|>", + "<|reserved_special_token_0|>", "<|reserved_special_token_1|>", + "<|finetune_right_pad_id|>", "<|step_id|>", "<|start_header_id|>", + "<|end_header_id|>", "<|eom_id|>", "<|eot_id|>", "<|python_tag|>"}); // pad the rest of the special tokens with reserved tokens ssize_t reserved_special_token_num = 2; while (special_tokens->size() < kSpecialTokensSize) { - special_tokens->emplace_back( - "<|reserved_special_token_" + - std::to_string(reserved_special_token_num++) + "|>"); + special_tokens->emplace_back("<|reserved_special_token_" + + std::to_string(reserved_special_token_num++) + + "|>"); } return special_tokens; } @@ -46,25 +39,19 @@ static inline std::unique_ptr> _get_multimodal_special_tokens() { auto special_tokens = std::make_unique>(std::vector{ - "<|begin_of_text|>", - "<|end_of_text|>", - "<|reserved_special_token_0|>", - "<|reserved_special_token_1|>", - "<|reserved_special_token_2|>", - "<|reserved_special_token_3|>", - "<|start_header_id|>", - "<|end_header_id|>", - "<|eom_id|>", - "<|eot_id|>", - "<|image|>"}); + "<|begin_of_text|>", "<|end_of_text|>", + "<|reserved_special_token_0|>", "<|reserved_special_token_1|>", + "<|reserved_special_token_2|>", "<|reserved_special_token_3|>", + "<|start_header_id|>", "<|end_header_id|>", "<|eom_id|>", + "<|eot_id|>", "<|image|>"}); // pad the rest of the special tokens with reserved tokens except the last // one ssize_t reserved_special_token_num = 4; while (special_tokens->size() < kSpecialTokensSize - 1) { - special_tokens->emplace_back( - "<|reserved_special_token_" + - std::to_string(reserved_special_token_num++) + "|>"); + special_tokens->emplace_back("<|reserved_special_token_" + + std::to_string(reserved_special_token_num++) + + "|>"); } special_tokens->emplace_back("<|python_tag|>"); @@ -74,18 +61,18 @@ _get_multimodal_special_tokens() { std::unique_ptr> _get_special_tokens(Version version) { switch (version) { - case Version::Multimodal: - return _get_multimodal_special_tokens(); - default: - return _get_default_special_tokens(); + case Version::Multimodal: + return _get_multimodal_special_tokens(); + default: + return _get_default_special_tokens(); } } } // namespace std::unique_ptr get_tiktoken_for_llama(Version version) { - return std::make_unique( - _get_special_tokens(version), kBOSTokenIndex, kEOSTokenIndex); + return std::make_unique(_get_special_tokens(version), + kBOSTokenIndex, kEOSTokenIndex); } } // namespace example diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h index 7ea224a6..10e106f1 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h @@ -17,7 +17,7 @@ enum class Version { Multimodal, }; -std::unique_ptr<::executorch::extension::llm::Tiktoken> get_tiktoken_for_llama( - Version version = Version::Default); +std::unique_ptr<::executorch::extension::llm::Tiktoken> +get_tiktoken_for_llama(Version version = Version::Default); } // namespace example diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp index 322a945e..aad4de6f 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp @@ -25,8 +25,8 @@ limitations under the License. *************************************************************************/ -#include "base64.h" #include "tiktoken.h" +#include "base64.h" #include #include #include @@ -40,19 +40,17 @@ namespace llm { // ------------------------------Util start------------------------------------ -static uint64_t _max_size() { - return std::numeric_limits::max(); -} +static uint64_t _max_size() { return std::numeric_limits::max(); } -static Re2UPtr _create_regex(const std::string& pattern) { +static Re2UPtr _create_regex(const std::string &pattern) { assert(!pattern.empty()); return std::make_unique("(" + pattern + ")"); } -static Re2UPtr _build_special_token_regex(const Encoder& special_encoder) { +static Re2UPtr _build_special_token_regex(const Encoder &special_encoder) { std::string special_pattern; - for (const auto& ele : special_encoder) { + for (const auto &ele : special_encoder) { if (!special_pattern.empty()) { special_pattern += "|"; } @@ -66,68 +64,61 @@ static Re2UPtr _build_special_token_regex(const Encoder& special_encoder) { return _create_regex(special_pattern); } -static Result> _parse( - const std::string& line) { +static Result> +_parse(const std::string &line) { // Tiktoken format // https://github.com/openai/tiktoken/blob/main/tiktoken/load.py#L140 auto pos = line.find(" "); - ET_CHECK_OR_RETURN_ERROR( - pos != std::string::npos, - InvalidArgument, - "invalid tiktoken line: %s", - line.c_str()); + ET_CHECK_OR_RETURN_ERROR(pos != std::string::npos, InvalidArgument, + "invalid tiktoken line: %s", line.c_str()); auto token = ET_UNWRAP(base64::decode({line.data(), pos})); uint64_t rank = 0; try { rank = std::stoul(line.substr(pos + 1)); - } catch (const std::exception&) { - ET_CHECK_OR_RETURN_ERROR( - false, InvalidArgument, "invalid encoder rank: %s", line.c_str()); + } catch (const std::exception &) { + ET_CHECK_OR_RETURN_ERROR(false, InvalidArgument, "invalid encoder rank: %s", + line.c_str()); } return std::pair{std::move(token), rank}; } -static Result _load_encoder(const std::string& path) { +static Result _load_encoder(const std::string &path) { std::ifstream file(path); - ET_CHECK_OR_RETURN_ERROR( - file, InvalidArgument, "failed to open encoder file: %s", path.c_str()); + ET_CHECK_OR_RETURN_ERROR(file, InvalidArgument, + "failed to open encoder file: %s", path.c_str()); Encoder encoder; std::string line; while (std::getline(file, line)) { auto [token, rank] = ET_UNWRAP(_parse(line)); - ET_CHECK_OR_RETURN_ERROR( - encoder.emplace(std::move(token), rank).second, - InvalidArgument, - "duplicate item: %s", - line.c_str()); + ET_CHECK_OR_RETURN_ERROR(encoder.emplace(std::move(token), rank).second, + InvalidArgument, "duplicate item: %s", + line.c_str()); } return encoder; } -static Result _build_decoder(const Encoder& encoder) { +static Result _build_decoder(const Encoder &encoder) { Decoder decoder; - for (const auto& [k, v] : encoder) { + for (const auto &[k, v] : encoder) { decoder.emplace(v, k); } - ET_CHECK_OR_RETURN_ERROR( - encoder.size() == decoder.size(), - InvalidArgument, - "duplicate items in encoder"); + ET_CHECK_OR_RETURN_ERROR(encoder.size() == decoder.size(), InvalidArgument, + "duplicate items in encoder"); return decoder; } -static std::vector _byte_pair_merge( - const std::string& piece, - const std::unordered_map& ranks, - std::function func) { +static std::vector +_byte_pair_merge(const std::string &piece, + const std::unordered_map &ranks, + std::function func) { // This is a vector of (start, rank). // The rank is of the byte pair starting at position start. // The rank of the last item in the vector is not a valid value. @@ -137,10 +128,10 @@ static std::vector _byte_pair_merge( parts.emplace_back(idx, _max_size()); } - auto get_rank = [&piece, &ranks]( - const std::vector>& parts, - uint64_t start_idx, - uint64_t skip) -> std::optional { + auto get_rank = + [&piece, &ranks](const std::vector> &parts, + uint64_t start_idx, + uint64_t skip) -> std::optional { if (start_idx + skip + 2 < parts.size()) { auto s = parts[start_idx].first; auto e = parts[start_idx + skip + 2].first; @@ -228,9 +219,8 @@ static std::vector _byte_pair_merge( return out; } -static std::vector _byte_pair_encode( - const std::string& piece, - const Encoder& encoder) { +static std::vector _byte_pair_encode(const std::string &piece, + const Encoder &encoder) { if (piece.size() == 1) { auto iter = encoder.find(piece); if (iter != encoder.end()) { @@ -241,27 +231,26 @@ static std::vector _byte_pair_encode( } } - return _byte_pair_merge( - piece, encoder, [&piece, &encoder](uint64_t start, uint64_t stop) { - std::string key = piece.substr(start, stop - start); - auto iter = encoder.find(key); - if (iter != encoder.end()) { - return iter->second; - } else { - // TODO: what if key does not exist? Should we return `unknown`? - // assert(false); // ?? - return uint64_t(0); - } - }); + return _byte_pair_merge(piece, encoder, + [&piece, &encoder](uint64_t start, uint64_t stop) { + std::string key = piece.substr(start, stop - start); + auto iter = encoder.find(key); + if (iter != encoder.end()) { + return iter->second; + } else { + // TODO: what if key does not exist? Should we + // return `unknown`? assert(false); // ?? + return uint64_t(0); + } + }); } // ------------------------------Util end------------------------------------ // -------------------------private method start------------------------------- template std::pair, re2::StringPiece> -Tiktoken::_split_with_allowed_special_token( - re2::StringPiece& input, - const T& allowed_special) const { +Tiktoken::_split_with_allowed_special_token(re2::StringPiece &input, + const T &allowed_special) const { if (!_special_token_regex) { return std::make_pair(std::nullopt, input); } @@ -269,7 +258,7 @@ Tiktoken::_split_with_allowed_special_token( #if __cplusplus >= 202002L auto start = input.begin(); #else - const char* start = input.data(); + const char *start = input.data(); #endif std::string special; while (true) { @@ -295,10 +284,8 @@ Tiktoken::_split_with_allowed_special_token( return std::make_pair(std::nullopt, input); } -void Tiktoken::_encode( - re2::StringPiece& input, - std::vector& ret, - uint64_t& last_piece_token_len) const { +void Tiktoken::_encode(re2::StringPiece &input, std::vector &ret, + uint64_t &last_piece_token_len) const { std::string piece; assert(_regex); while (re2::RE2::FindAndConsume(&input, *_regex, &piece)) { @@ -315,9 +302,9 @@ void Tiktoken::_encode( } template -std::pair, uint64_t> Tiktoken::_encode_with_special_token( - const std::string& text, - const T& allowed_special) const { +std::pair, uint64_t> +Tiktoken::_encode_with_special_token(const std::string &text, + const T &allowed_special) const { std::vector tokens; uint64_t last_piece_token_len = 0; re2::StringPiece input(text); @@ -331,7 +318,7 @@ std::pair, uint64_t> Tiktoken::_encode_with_special_token( uint64_t token = 0; try { token = _special_token_encoder.at(*special); - } catch (const std::out_of_range&) { + } catch (const std::out_of_range &) { // Should never go here, since special pattern includes all special // chars. ET_CHECK_MSG(false, "unknown special token: %s", special->c_str()); @@ -361,25 +348,17 @@ Encoder Tiktoken::_build_special_token_encoder(ssize_t num_base_tokens) const { // -------------------------private method end------------------------------- // -------------------------public method start------------------------------- -Tiktoken::Tiktoken( - std::unique_ptr> special_tokens, - size_t bos_token_index, - size_t eos_token_index) - : Tokenizer(), - _special_tokens(std::move(special_tokens)), - _bos_token_index(bos_token_index), - _eos_token_index(eos_token_index) { - ET_CHECK_MSG( - _bos_token_index < _special_tokens->size(), - "invalid bos_token_index %zu", - _bos_token_index); - ET_CHECK_MSG( - _eos_token_index < _special_tokens->size(), - "invalid eos_token_index %zu", - _eos_token_index); +Tiktoken::Tiktoken(std::unique_ptr> special_tokens, + size_t bos_token_index, size_t eos_token_index) + : Tokenizer(), _special_tokens(std::move(special_tokens)), + _bos_token_index(bos_token_index), _eos_token_index(eos_token_index) { + ET_CHECK_MSG(_bos_token_index < _special_tokens->size(), + "invalid bos_token_index %zu", _bos_token_index); + ET_CHECK_MSG(_eos_token_index < _special_tokens->size(), + "invalid eos_token_index %zu", _eos_token_index); } -Error Tiktoken::load(const std::string& path) { +Error Tiktoken::load(const std::string &path) { _encoder = ET_UNWRAP(_load_encoder(path)); _special_token_encoder = _build_special_token_encoder(_encoder.size()); @@ -405,8 +384,8 @@ Error Tiktoken::load(const std::string& path) { return Error::Ok; } -Result> -Tiktoken::encode(const std::string& text, int8_t bos, int8_t eos) const { +Result> Tiktoken::encode(const std::string &text, + int8_t bos, int8_t eos) const { if (!initialized_) { return Error::NotSupported; } diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h index 0403c60e..5eed7e94 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h @@ -9,9 +9,9 @@ #pragma once #include "tokenizer.h" -#include #include #include +#include #include namespace executorch { @@ -23,42 +23,36 @@ using Decoder = std::unordered_map; using Re2UPtr = std::unique_ptr; class Tiktoken : public Tokenizer { - public: +public: /** * @param[in] special_tokens List of special tokens including bos, eos; * @param[in] bos_token_index Index of the bos token in special_tokens; * @param[in] eos_token_index Index of the eos token in special_tokens. */ - explicit Tiktoken( - std::unique_ptr> special_tokens, - size_t bos_token_index, - size_t eos_token_index); + explicit Tiktoken(std::unique_ptr> special_tokens, + size_t bos_token_index, size_t eos_token_index); - ::executorch::runtime::Error load(const std::string& tokenizer_path) override; + ::executorch::runtime::Error load(const std::string &tokenizer_path) override; ::executorch::runtime::Result> - encode(const std::string& input, int8_t bos, int8_t eos) const override; + encode(const std::string &input, int8_t bos, int8_t eos) const override; - ::executorch::runtime::Result decode( - uint64_t prev_token, - uint64_t token) const override; + ::executorch::runtime::Result + decode(uint64_t prev_token, uint64_t token) const override; - private: +private: template std::pair, re2::StringPiece> - _split_with_allowed_special_token( - re2::StringPiece& input, - const T& allowed_special) const; + _split_with_allowed_special_token(re2::StringPiece &input, + const T &allowed_special) const; - void _encode( - re2::StringPiece& input, - std::vector& ret, - uint64_t& last_piece_token_len) const; + void _encode(re2::StringPiece &input, std::vector &ret, + uint64_t &last_piece_token_len) const; template - std::pair, uint64_t> _encode_with_special_token( - const std::string& text, - const T& allowed_special) const; + std::pair, uint64_t> + _encode_with_special_token(const std::string &text, + const T &allowed_special) const; Encoder _build_special_token_encoder(ssize_t num_base_tokens) const; diff --git a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h index 3115cbdf..948cccc0 100644 --- a/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h +++ b/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h @@ -23,15 +23,15 @@ namespace llm { // A tokenizer interface. class Tokenizer { - public: +public: explicit Tokenizer() {} virtual ~Tokenizer() {} - virtual ::executorch::runtime::Error load( - const std::string& tokenizer_path) = 0; + virtual ::executorch::runtime::Error + load(const std::string &tokenizer_path) = 0; virtual ::executorch::runtime::Result> - encode(const std::string& input, int8_t bos, int8_t eos) const = 0; + encode(const std::string &input, int8_t bos, int8_t eos) const = 0; ::executorch::runtime::Error decode_verify(uint64_t token) const { if (!initialized_) { @@ -39,34 +39,24 @@ class Tokenizer { return ::executorch::runtime::Error::NotSupported; } if (token >= vocab_size_) { - ET_LOG( - Error, - "token %" PRIu64 " is out side of vacab range %d", - token, - vocab_size_); + ET_LOG(Error, "token %" PRIu64 " is out side of vacab range %d", token, + vocab_size_); return ::executorch::runtime::Error::NotSupported; } return ::executorch::runtime::Error::Ok; } - virtual ::executorch::runtime::Result decode( - uint64_t prev_token, - uint64_t token) const = 0; + virtual ::executorch::runtime::Result + decode(uint64_t prev_token, uint64_t token) const = 0; // getters - int32_t vocab_size() const { - return vocab_size_; - } + int32_t vocab_size() const { return vocab_size_; } - uint64_t bos_tok() const { - return bos_tok_; - } + uint64_t bos_tok() const { return bos_tok_; } - uint64_t eos_tok() const { - return eos_tok_; - } + uint64_t eos_tok() const { return eos_tok_; } - protected: +protected: bool initialized_ = false; int32_t vocab_size_ = 0; uint64_t bos_tok_ = 0; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h index 45ed38a7..5fb2723c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h @@ -23,7 +23,7 @@ namespace extension { * A facade class for loading programs and executing methods within them. */ class Module { - public: +public: /** * Enum to define loading behavior. */ @@ -46,10 +46,9 @@ class Module { * @param[in] load_mode The loading mode to use. * @param[in] event_tracer A EventTracer used for tracking and logging events. */ - explicit Module( - const std::string& file_path, - const LoadMode load_mode = LoadMode::MmapUseMlock, - std::unique_ptr event_tracer = nullptr); + explicit Module(const std::string &file_path, + const LoadMode load_mode = LoadMode::MmapUseMlock, + std::unique_ptr event_tracer = nullptr); /** * Constructs an instance with the provided data loader and memory allocator. @@ -82,10 +81,10 @@ class Module { std::unique_ptr temp_allocator = nullptr, std::unique_ptr event_tracer = nullptr); - Module(const Module&) = delete; - Module& operator=(const Module&) = delete; - Module(Module&&) = delete; - Module& operator=(Module&&) = delete; + Module(const Module &) = delete; + Module &operator=(const Module &) = delete; + Module(Module &&) = delete; + Module &operator=(Module &&) = delete; /** * Loads the program if needed. @@ -96,18 +95,15 @@ class Module { * @returns An Error to indicate success or failure of the loading process. */ ET_NODISCARD - runtime::Error load( - const runtime::Program::Verification verification = - runtime::Program::Verification::Minimal); + runtime::Error load(const runtime::Program::Verification verification = + runtime::Program::Verification::Minimal); /** * Checks if the program is loaded. * * @returns true if the program is loaded, false otherwise. */ - inline bool is_loaded() const { - return program_ != nullptr; - } + inline bool is_loaded() const { return program_ != nullptr; } /** * Get the program. The data loader used by the program is guaranteed to be @@ -115,9 +111,7 @@ class Module { * * @returns Shared pointer to the program or nullptr if it's not yet loaded. */ - inline std::shared_ptr program() const { - return program_; - } + inline std::shared_ptr program() const { return program_; } /** * Get a list of method names available in the loaded program. @@ -141,9 +135,9 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error load_method( - const std::string& method_name, - torch::executor::EventTracer* event_tracer = nullptr); + runtime::Error + load_method(const std::string &method_name, + torch::executor::EventTracer *event_tracer = nullptr); /** * Load the 'forward' method from the program and set up memory management if @@ -154,8 +148,8 @@ class Module { * * @returns An Error to indicate success or failure. */ - ET_NODISCARD inline runtime::Error load_forward( - torch::executor::EventTracer* event_tracer = nullptr) { + ET_NODISCARD inline runtime::Error + load_forward(torch::executor::EventTracer *event_tracer = nullptr) { return load_method("forward", event_tracer); } @@ -167,7 +161,7 @@ class Module { * @returns true if the method specified by method_name is loaded, false * otherwise. */ - inline bool is_method_loaded(const std::string& method_name) const { + inline bool is_method_loaded(const std::string &method_name) const { return methods_.count(method_name); } @@ -180,8 +174,8 @@ class Module { * @returns A method metadata, or an error if the program or method failed to * load. */ - runtime::Result method_meta( - const std::string& method_name); + runtime::Result + method_meta(const std::string &method_name); /** * Execute a specific method with the given input values and retrieve the @@ -195,9 +189,9 @@ class Module { * from the method or an error to indicate failure. */ ET_NODISCARD - runtime::Result> execute( - const std::string& method_name, - const std::vector& input_values); + runtime::Result> + execute(const std::string &method_name, + const std::vector &input_values); /** * Execute a specific method with a single input value. @@ -209,9 +203,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> execute( - const std::string& method_name, - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result> + execute(const std::string &method_name, const runtime::EValue &input_value) { return execute(method_name, std::vector{input_value}); } @@ -224,8 +217,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> execute( - const std::string& method_name) { + ET_NODISCARD inline runtime::Result> + execute(const std::string &method_name) { return execute(method_name, std::vector{}); } @@ -240,9 +233,9 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name, - const std::vector& input_values) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name, + const std::vector &input_values) { auto result = ET_UNWRAP(execute(method_name, input_values)); if (result.empty()) { return runtime::Error::InvalidArgument; @@ -260,9 +253,8 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name, - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name, const runtime::EValue &input_value) { return get(method_name, std::vector{input_value}); } @@ -275,8 +267,8 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name) { return get(method_name, std::vector{}); } @@ -289,8 +281,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the 'forward' method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> forward( - const std::vector& input_values) { + ET_NODISCARD inline runtime::Result> + forward(const std::vector &input_values) { return execute("forward", input_values); } @@ -303,8 +295,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the 'forward' method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> forward( - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result> + forward(const runtime::EValue &input_value) { return forward(std::vector{input_value}); } @@ -329,10 +321,9 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error set_input( - const std::string& method_name, - const runtime::EValue& input_value, - size_t input_index); + runtime::Error set_input(const std::string &method_name, + const runtime::EValue &input_value, + size_t input_index); /** * Sets a single input value for the "forward" method. @@ -343,9 +334,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - inline runtime::Error set_input( - const runtime::EValue& input_value, - size_t input_index) { + inline runtime::Error set_input(const runtime::EValue &input_value, + size_t input_index) { return set_input("forward", input_value, input_index); } @@ -358,9 +348,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error set_inputs( - const std::string& method_name, - const std::vector& input_values); + runtime::Error set_inputs(const std::string &method_name, + const std::vector &input_values); /** * Sets all input values for the "forward" method. @@ -370,8 +359,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - inline runtime::Error set_inputs( - const std::vector& input_values) { + inline runtime::Error + set_inputs(const std::vector &input_values) { return set_inputs("forward", input_values); } @@ -388,10 +377,9 @@ class Module { * @note Only Tensor outputs are currently supported for setting. */ ET_NODISCARD - runtime::Error set_output( - const std::string& method_name, - runtime::EValue output_value, - size_t output_index = 0); + runtime::Error set_output(const std::string &method_name, + runtime::EValue output_value, + size_t output_index = 0); /** * Sets the output tensor for the "forward" method. @@ -405,9 +393,8 @@ class Module { * @note Only Tensor outputs are currently supported for setting. */ ET_NODISCARD - inline runtime::Error set_output( - runtime::EValue output_value, - size_t output_index = 0) { + inline runtime::Error set_output(runtime::EValue output_value, + size_t output_index = 0) { return set_output("forward", std::move(output_value), output_index); } @@ -419,11 +406,11 @@ class Module { * @returns A pointer to the EventTracer instance. Returns nullptr if no * EventTracer is set. */ - inline runtime::EventTracer* event_tracer() const { + inline runtime::EventTracer *event_tracer() const { return event_tracer_.get(); } - private: +private: struct MethodHolder { std::vector> planned_buffers; std::vector> planned_spans; @@ -433,7 +420,7 @@ class Module { std::vector inputs; }; - private: +private: std::string file_path_; LoadMode load_mode_{LoadMode::MmapUseMlock}; std::shared_ptr program_; @@ -442,7 +429,7 @@ class Module { std::unique_ptr temp_allocator_; std::unique_ptr event_tracer_; - protected: +protected: std::unordered_map methods_; friend class ExecuTorchJni; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h index f41c6f77..f223a2ce 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h @@ -38,16 +38,15 @@ using TensorPtr = std::shared_ptr; * object is destroyed. * @return A TensorPtr that manages the newly created Tensor. */ -TensorPtr make_tensor_ptr( - std::vector sizes, - void* data, - std::vector dim_order, - std::vector strides, - const executorch::aten::ScalarType type = - executorch::aten::ScalarType::Float, - const executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, - std::function deleter = nullptr); +TensorPtr +make_tensor_ptr(std::vector sizes, void *data, + std::vector dim_order, + std::vector strides, + const executorch::aten::ScalarType type = + executorch::aten::ScalarType::Float, + const executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, + std::function deleter = nullptr); /** * Creates a TensorPtr that manages a Tensor with the specified properties. @@ -61,16 +60,15 @@ TensorPtr make_tensor_ptr( * object is destroyed. * @return A TensorPtr that manages the newly created Tensor. */ -inline TensorPtr make_tensor_ptr( - std::vector sizes, - void* data, - const executorch::aten::ScalarType type = - executorch::aten::ScalarType::Float, - const executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, - std::function deleter = nullptr) { - return make_tensor_ptr( - std::move(sizes), data, {}, {}, type, dynamism, std::move(deleter)); +inline TensorPtr +make_tensor_ptr(std::vector sizes, void *data, + const executorch::aten::ScalarType type = + executorch::aten::ScalarType::Float, + const executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, + std::function deleter = nullptr) { + return make_tensor_ptr(std::move(sizes), data, {}, {}, type, dynamism, + std::move(deleter)); } /** @@ -93,52 +91,37 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, - std::vector dim_order = {}, - std::vector strides = {}, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector sizes, + std::vector data, + std::vector dim_order = {}, + std::vector strides = {}, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type != deduced_type) { - ET_CHECK_MSG( - runtime::canCast(deduced_type, type), - "Cannot cast deduced type to specified type."); + ET_CHECK_MSG(runtime::canCast(deduced_type, type), + "Cannot cast deduced type to specified type."); std::vector casted_data(data.size() * runtime::elementSize(type)); ET_SWITCH_REALHBBF16_TYPES(type, nullptr, "make_tensor_ptr", CTYPE, [&] { - std::transform( - data.begin(), - data.end(), - reinterpret_cast(casted_data.data()), - [](const T& val) { return static_cast(val); }); + std::transform(data.begin(), data.end(), + reinterpret_cast(casted_data.data()), + [](const T &val) { return static_cast(val); }); }); const auto raw_data_ptr = casted_data.data(); auto data_ptr = std::make_shared>(std::move(casted_data)); - return make_tensor_ptr( - std::move(sizes), - raw_data_ptr, - std::move(dim_order), - std::move(strides), - type, - dynamism, - [data_ptr = std::move(data_ptr)](void*) {}); + return make_tensor_ptr(std::move(sizes), raw_data_ptr, std::move(dim_order), + std::move(strides), type, dynamism, + [data_ptr = std::move(data_ptr)](void *) {}); } const auto raw_data_ptr = data.data(); auto data_ptr = std::make_shared>(std::move(data)); - return make_tensor_ptr( - std::move(sizes), - raw_data_ptr, - std::move(dim_order), - std::move(strides), - type, - dynamism, - [data_ptr = std::move(data_ptr)](void*) {}); + return make_tensor_ptr(std::move(sizes), raw_data_ptr, std::move(dim_order), + std::move(strides), type, dynamism, + [data_ptr = std::move(data_ptr)](void *) {}); } /** @@ -158,19 +141,17 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector data, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector data, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { std::vector sizes{ executorch::aten::SizesType(data.size())}; - return make_tensor_ptr( - std::move(sizes), std::move(data), {0}, {1}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(data), {0}, {1}, type, + dynamism); } /** @@ -195,25 +176,19 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::initializer_list list, - std::vector dim_order = {}, - std::vector strides = {}, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { - return make_tensor_ptr( - std::move(sizes), - std::vector(std::move(list)), - std::move(dim_order), - std::move(strides), - type, - dynamism); +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector sizes, + std::initializer_list list, + std::vector dim_order = {}, + std::vector strides = {}, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { + return make_tensor_ptr(std::move(sizes), std::vector(std::move(list)), + std::move(dim_order), std::move(strides), type, + dynamism); } /** @@ -235,19 +210,17 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::initializer_list list, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::initializer_list list, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { std::vector sizes{ executorch::aten::SizesType(list.size())}; - return make_tensor_ptr( - std::move(sizes), std::move(list), {0}, {1}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(list), {0}, {1}, type, + dynamism); } /** @@ -257,8 +230,7 @@ inline TensorPtr make_tensor_ptr( * @param value The scalar value to be used for the Tensor. * @return A TensorPtr that manages the newly created TensorImpl. */ -template -inline TensorPtr make_tensor_ptr(T value) { +template inline TensorPtr make_tensor_ptr(T value) { return make_tensor_ptr({}, std::vector{value}); } @@ -278,8 +250,7 @@ inline TensorPtr make_tensor_ptr(T value) { * @return A TensorPtr managing the newly created Tensor. */ TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, + std::vector sizes, std::vector data, std::vector dim_order, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, @@ -300,13 +271,12 @@ TensorPtr make_tensor_ptr( * @return A TensorPtr managing the newly created Tensor. */ inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, + std::vector sizes, std::vector data, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { - return make_tensor_ptr( - std::move(sizes), std::move(data), {}, {}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(data), {}, {}, type, + dynamism); } /** @@ -317,22 +287,21 @@ inline TensorPtr make_tensor_ptr( * @return A new TensorPtr managing a Tensor with the same properties as the * original. */ -inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor& tensor) { +inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor &tensor) { return make_tensor_ptr( - std::vector( - tensor.sizes().begin(), tensor.sizes().end()), + std::vector(tensor.sizes().begin(), + tensor.sizes().end()), tensor.mutable_data_ptr(), #ifndef USE_ATEN_LIB - std::vector( - tensor.dim_order().begin(), tensor.dim_order().end()), - std::vector( - tensor.strides().begin(), tensor.strides().end()), - tensor.scalar_type(), - tensor.shape_dynamism() -#else // USE_ATEN_LIB + std::vector(tensor.dim_order().begin(), + tensor.dim_order().end()), + std::vector(tensor.strides().begin(), + tensor.strides().end()), + tensor.scalar_type(), tensor.shape_dynamism() +#else // USE_ATEN_LIB {}, - std::vector( - tensor.strides().begin(), tensor.strides().end()), + std::vector(tensor.strides().begin(), + tensor.strides().end()), tensor.scalar_type() #endif // USE_ATEN_LIB ); @@ -347,7 +316,7 @@ inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor& tensor) { * @return A new TensorPtr that manages a Tensor with the same properties as the * original but with copied data. */ -TensorPtr clone_tensor_ptr(const executorch::aten::Tensor& tensor); +TensorPtr clone_tensor_ptr(const executorch::aten::Tensor &tensor); /** * Creates a new TensorPtr by cloning the given TensorPtr, copying the @@ -357,7 +326,7 @@ TensorPtr clone_tensor_ptr(const executorch::aten::Tensor& tensor); * @return A new TensorPtr that manages a Tensor with the same properties as the * original but with copied data. */ -inline TensorPtr clone_tensor_ptr(const TensorPtr& tensor) { +inline TensorPtr clone_tensor_ptr(const TensorPtr &tensor) { return clone_tensor_ptr(*tensor); } @@ -369,9 +338,9 @@ inline TensorPtr clone_tensor_ptr(const TensorPtr& tensor) { * @return Error::Ok on success, or an appropriate error code on failure. */ ET_NODISCARD -runtime::Error resize_tensor_ptr( - TensorPtr& tensor, - const std::vector& sizes); +runtime::Error +resize_tensor_ptr(TensorPtr &tensor, + const std::vector &sizes); } // namespace extension } // namespace executorch diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h index e3351fe3..f6a70dd4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h @@ -24,13 +24,13 @@ namespace extension { * by converting TensorPtrMaker to TensorPtr. */ class TensorPtrMaker final { - public: +public: // This class may have non-copyable members in the future. - TensorPtrMaker(const TensorPtrMaker&) = delete; - TensorPtrMaker& operator=(const TensorPtrMaker&) = delete; + TensorPtrMaker(const TensorPtrMaker &) = delete; + TensorPtrMaker &operator=(const TensorPtrMaker &) = delete; // But it is movable. - TensorPtrMaker(TensorPtrMaker&&) = default; - TensorPtrMaker& operator=(TensorPtrMaker&&) = default; + TensorPtrMaker(TensorPtrMaker &&) = default; + TensorPtrMaker &operator=(TensorPtrMaker &&) = default; /** * Sets the scalar type of the tensor elements. @@ -38,7 +38,7 @@ class TensorPtrMaker final { * @param type The scalar type (e.g., float, int, bool). * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& type(executorch::aten::ScalarType type) { + TensorPtrMaker &&type(executorch::aten::ScalarType type) { type_ = type; return std::move(*this); } @@ -49,8 +49,8 @@ class TensorPtrMaker final { * @param dim_order A vector specifying the dimension order. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& dim_order( - std::vector dim_order) { + TensorPtrMaker && + dim_order(std::vector dim_order) { dim_order_ = std::move(dim_order); return std::move(*this); } @@ -61,7 +61,7 @@ class TensorPtrMaker final { * @param strides A vector specifying the stride for each dimension. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& strides(std::vector strides) { + TensorPtrMaker &&strides(std::vector strides) { strides_ = std::move(strides); return std::move(*this); } @@ -73,7 +73,7 @@ class TensorPtrMaker final { * bounded. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& dynamism(executorch::aten::TensorShapeDynamism dynamism) { + TensorPtrMaker &&dynamism(executorch::aten::TensorShapeDynamism dynamism) { dynamism_ = dynamism; return std::move(*this); } @@ -87,7 +87,7 @@ class TensorPtrMaker final { * lambda that has captured some state. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& deleter(std::function&& deleter) { + TensorPtrMaker &&deleter(std::function &&deleter) { deleter_ = std::move(deleter); return std::move(*this); } @@ -100,13 +100,8 @@ class TensorPtrMaker final { */ TensorPtr make_tensor_ptr() && { return ::executorch::extension::make_tensor_ptr( - std::move(sizes_), - data_, - std::move(dim_order_), - std::move(strides_), - type_, - dynamism_, - std::move(deleter_)); + std::move(sizes_), data_, std::move(dim_order_), std::move(strides_), + type_, dynamism_, std::move(deleter_)); } /** @@ -114,30 +109,25 @@ class TensorPtrMaker final { * * @return A TensorPtr instance that manages the newly created Tensor. */ - operator TensorPtr() && { - return std::move(*this).make_tensor_ptr(); - } + operator TensorPtr() && { return std::move(*this).make_tensor_ptr(); } - private: - TensorPtrMaker( - void* data, - std::vector sizes, - executorch::aten::ScalarType type) +private: + TensorPtrMaker(void *data, std::vector sizes, + executorch::aten::ScalarType type) : sizes_(std::move(sizes)), data_(data), type_(type) {} - private: +private: // The following properties are required to create a Tensor. - friend TensorPtrMaker for_blob( - void* data, - std::vector sizes, - executorch::aten::ScalarType type); + friend TensorPtrMaker for_blob(void *data, + std::vector sizes, + executorch::aten::ScalarType type); - private: +private: std::vector sizes_; std::vector strides_; std::vector dim_order_; - std::function deleter_ = nullptr; - void* data_ = nullptr; + std::function deleter_ = nullptr; + void *data_ = nullptr; executorch::aten::ScalarType type_ = executorch::aten::ScalarType::Float; executorch::aten::TensorShapeDynamism dynamism_ = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND; @@ -158,8 +148,7 @@ class TensorPtrMaker final { * @return A TensorPtrMaker instance for creating a TensorPtr. */ inline TensorPtrMaker for_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float) { return TensorPtrMaker(data, std::move(sizes), type); } @@ -180,8 +169,7 @@ inline TensorPtrMaker for_blob( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr from_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -208,8 +196,7 @@ inline TensorPtr from_blob( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr from_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = @@ -236,13 +223,12 @@ inline TensorPtr from_blob( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance that manages the newly created Tensor. */ -inline TensorPtr from_blob( - void* data, - std::vector sizes, - executorch::aten::ScalarType type, - std::function&& deleter, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +from_blob(void *data, std::vector sizes, + executorch::aten::ScalarType type, + std::function &&deleter, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return for_blob(data, std::move(sizes), type) .deleter(std::move(deleter)) .dynamism(dynamism) @@ -266,14 +252,13 @@ inline TensorPtr from_blob( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance that manages the newly created Tensor. */ -inline TensorPtr from_blob( - void* data, - std::vector sizes, - std::vector strides, - executorch::aten::ScalarType type, - std::function&& deleter, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +from_blob(void *data, std::vector sizes, + std::vector strides, + executorch::aten::ScalarType type, + std::function &&deleter, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return for_blob(data, std::move(sizes), type) .strides(std::move(strides)) .deleter(std::move(deleter)) @@ -316,18 +301,16 @@ TensorPtr empty_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr empty_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return empty_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return empty_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -341,11 +324,11 @@ inline TensorPtr empty_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr empty( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +empty(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return empty_strided(std::move(sizes), {}, type, dynamism); } @@ -380,20 +363,16 @@ TensorPtr full_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr full_like( - const TensorPtr& other, - executorch::aten::Scalar fill_value, + const TensorPtr &other, executorch::aten::Scalar fill_value, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return full_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - fill_value, - type, - dynamism); + return full_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, + fill_value, type, dynamism); } /** @@ -405,12 +384,12 @@ inline TensorPtr full_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr full( - std::vector sizes, - executorch::aten::Scalar fill_value, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +full(std::vector sizes, + executorch::aten::Scalar fill_value, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full_strided(std::move(sizes), {}, fill_value, type, dynamism); } @@ -439,7 +418,7 @@ inline TensorPtr scalar_tensor( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr ones_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -454,11 +433,11 @@ inline TensorPtr ones_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr ones( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +ones(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full(std::move(sizes), 1, type, dynamism); } @@ -474,7 +453,7 @@ inline TensorPtr ones( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr zeros_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -489,11 +468,11 @@ inline TensorPtr zeros_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr zeros( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +zeros(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full(std::move(sizes), 0, type, dynamism); } @@ -524,18 +503,16 @@ TensorPtr rand_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr rand_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return rand_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return rand_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -546,11 +523,11 @@ inline TensorPtr rand_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr rand( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +rand(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return rand_strided(std::move(sizes), {}, type, dynamism); } @@ -582,18 +559,16 @@ TensorPtr randn_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr randn_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return randn_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return randn_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -605,11 +580,11 @@ inline TensorPtr randn_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr randn( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +randn(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return randn_strided(std::move(sizes), {}, type, dynamism); } @@ -625,9 +600,7 @@ inline TensorPtr randn( * @return A TensorPtr instance managing the newly created Tensor. */ TensorPtr randint_strided( - int64_t low, - int64_t high, - std::vector sizes, + int64_t low, int64_t high, std::vector sizes, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, executorch::aten::TensorShapeDynamism dynamism = @@ -646,9 +619,7 @@ TensorPtr randint_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr randint_like( - const TensorPtr& other, - int64_t low, - int64_t high, + const TensorPtr &other, int64_t low, int64_t high, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -656,12 +627,8 @@ inline TensorPtr randint_like( type = other->scalar_type(); } return randint_strided( - low, - high, - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + low, high, {other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, dynamism); } /** @@ -675,13 +642,12 @@ inline TensorPtr randint_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr randint( - int64_t low, - int64_t high, - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +randint(int64_t low, int64_t high, + std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return randint_strided(low, high, std::move(sizes), {}, type, dynamism); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h index 7890f4f9..19514c7a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h @@ -18,10 +18,9 @@ namespace runtime { * BackendExecutionContext will be used to inject run time context. */ class BackendExecutionContext final { - public: - BackendExecutionContext( - EventTracer* event_tracer = nullptr, - MemoryAllocator* temp_allocator = nullptr) +public: + BackendExecutionContext(EventTracer *event_tracer = nullptr, + MemoryAllocator *temp_allocator = nullptr) : event_tracer_(event_tracer), temp_allocator_(temp_allocator) {} /** @@ -29,17 +28,14 @@ class BackendExecutionContext final { * logging inside the delegate backend. Users will need access to this pointer * to use any of the event tracer APIs. */ - EventTracer* event_tracer() { - return event_tracer_; - } + EventTracer *event_tracer() { return event_tracer_; } /** * Returns a pointer to the address allocated by temp allocator. This * allocator will be reset after every delegate call during execution. */ - void* allocate( - size_t size, - size_t alignment = MemoryAllocator::kDefaultAlignment) { + void *allocate(size_t size, + size_t alignment = MemoryAllocator::kDefaultAlignment) { // TODO(chenlai): depends on the need, we may expose more functionality for // memory allocation. return temp_allocator_->allocate(size, alignment); @@ -48,13 +44,11 @@ class BackendExecutionContext final { /** * Returns the temp allocator. This allocator will be reset every instruction. */ - MemoryAllocator* get_temp_allocator() { - return temp_allocator_; - } + MemoryAllocator *get_temp_allocator() { return temp_allocator_; } - private: - EventTracer* event_tracer_ = nullptr; - MemoryAllocator* temp_allocator_ = nullptr; +private: + EventTracer *event_tracer_ = nullptr; + MemoryAllocator *temp_allocator_ = nullptr; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h index 75413493..bb23427a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h @@ -17,20 +17,18 @@ namespace runtime { * delegate. */ class BackendInitContext final { - public: - explicit BackendInitContext(MemoryAllocator* runtime_allocator) +public: + explicit BackendInitContext(MemoryAllocator *runtime_allocator) : runtime_allocator_(runtime_allocator) {} /** Get the runtime allocator passed from Method. It's the same runtime * executor used by the standard executor runtime and the life span is the * same as the model. */ - MemoryAllocator* get_runtime_allocator() { - return runtime_allocator_; - } + MemoryAllocator *get_runtime_allocator() { return runtime_allocator_; } - private: - MemoryAllocator* runtime_allocator_ = nullptr; +private: + MemoryAllocator *runtime_allocator_ = nullptr; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h index c0305f68..42f8698e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h @@ -24,12 +24,12 @@ namespace executorch { namespace runtime { struct SizedBuffer { - void* buffer; + void *buffer; size_t nbytes; // number of bytes of buffer }; struct CompileSpec { - const char* key; // spec key + const char *key; // spec key SizedBuffer value; // spec value }; @@ -40,7 +40,7 @@ struct CompileSpec { using DelegateHandle = void; class BackendInterface { - public: +public: virtual ~BackendInterface() = 0; /** @@ -78,10 +78,9 @@ class BackendInterface { * Error::DelegateInvalidCompatibility. Other backend delegate * specific error codes can be found in error.h. */ - ET_NODISCARD virtual Result init( - BackendInitContext& context, - FreeableBuffer* processed, - ArrayRef compile_specs) const = 0; + ET_NODISCARD virtual Result + init(BackendInitContext &context, FreeableBuffer *processed, + ArrayRef compile_specs) const = 0; /** * Responsible for executing the given method’s handle, as it was produced @@ -93,10 +92,9 @@ class BackendInterface { * @param[in] args The method’s inputs and outputs. * @retval Error::Ok if successful. */ - ET_NODISCARD virtual Error execute( - BackendExecutionContext& context, - DelegateHandle* handle, - EValue** args) const = 0; + ET_NODISCARD virtual Error execute(BackendExecutionContext &context, + DelegateHandle *handle, + EValue **args) const = 0; /** * Responsible for destroying a handle, if it's required for some backend. @@ -107,7 +105,7 @@ class BackendInterface { * @param[in] handle The handle to be destroyed. An opaque handle returned by * `init()`. */ - virtual void destroy(ET_UNUSED DelegateHandle* handle) const {} + virtual void destroy(ET_UNUSED DelegateHandle *handle) const {} }; /** @@ -118,16 +116,16 @@ class BackendInterface { * @retval Pointer to the appropriate object that implements BackendInterface. * Nullptr if it can't find anything with the given name. */ -BackendInterface* get_backend_class(const char* name); +BackendInterface *get_backend_class(const char *name); /** * A named instance of a backend. */ struct Backend { /// The name of the backend. Must match the string used in the PTE file. - const char* name; + const char *name; /// The instance of the backend to use when loading and executing programs. - BackendInterface* backend; + BackendInterface *backend; }; /** @@ -137,7 +135,7 @@ struct Backend { * @param[in] backend Backend object * @retval Error code representing whether registration was successful. */ -ET_NODISCARD Error register_backend(const Backend& backend); +ET_NODISCARD Error register_backend(const Backend &backend); } // namespace runtime } // namespace executorch diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h index 463284d9..e4468251 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h @@ -52,22 +52,21 @@ namespace runtime { * This is intended to be trivially copyable, so it should be passed by * value. */ -template -class ArrayRef final { - public: - using iterator = const T*; - using const_iterator = const T*; +template class ArrayRef final { +public: + using iterator = const T *; + using const_iterator = const T *; using size_type = size_t; using value_type = T; - private: +private: /// The start of the array, in an external buffer. - const T* Data; + const T *Data; /// The number of elements. size_type Length; - public: +public: /// @name Constructors /// @{ @@ -76,16 +75,16 @@ class ArrayRef final { /// Construct a ArrayRef from a single element. Implicitly convert element /// type. It is aligned with PyTorch's c10::ArrayRef. - /* implicit */ constexpr ArrayRef(const T& OneElt) + /* implicit */ constexpr ArrayRef(const T &OneElt) : Data(&OneElt), Length(1) {} /// Construct a ArrayRef from a pointer and length. - ArrayRef(const T* data, size_t length) : Data(data), Length(length) { + ArrayRef(const T *data, size_t length) : Data(data), Length(length) { ET_DCHECK(Data != nullptr || Length == 0); } /// Construct a ArrayRef from a range. - ArrayRef(const T* begin, const T* end) : Data(begin), Length(end - begin) {} + ArrayRef(const T *begin, const T *end) : Data(begin), Length(end - begin) {} /// Construct a ArrayRef from a C array. template @@ -95,45 +94,31 @@ class ArrayRef final { /// @name Simple Operations /// @{ - constexpr iterator begin() const { - return Data; - } - constexpr iterator end() const { - return Data + Length; - } + constexpr iterator begin() const { return Data; } + constexpr iterator end() const { return Data + Length; } // These are actually the same as iterator, since ArrayRef only // gives you const iterators. - constexpr const_iterator cbegin() const { - return Data; - } - constexpr const_iterator cend() const { - return Data + Length; - } + constexpr const_iterator cbegin() const { return Data; } + constexpr const_iterator cend() const { return Data + Length; } /// empty - Check if the array is empty. - constexpr bool empty() const { - return Length == 0; - } + constexpr bool empty() const { return Length == 0; } - constexpr const T* data() const { - return Data; - } + constexpr const T *data() const { return Data; } /// size - Get the array size. - constexpr size_t size() const { - return Length; - } + constexpr size_t size() const { return Length; } /// front - Get the first element. - const T& front() const { + const T &front() const { // ArrayRef: attempted to access front() of empty list ET_CHECK(!empty()); return Data[0]; } /// back - Get the last element. - const T& back() const { + const T &back() const { // ArrayRef: attempted to access back() of empty list ET_CHECK(!empty()); return Data[Length - 1]; @@ -160,19 +145,15 @@ class ArrayRef final { } /// slice(n) - Chop off the first N elements of the array. - constexpr ArrayRef slice(size_t N) const { - return slice(N, size() - N); - } + constexpr ArrayRef slice(size_t N) const { return slice(N, size() - N); } /// @} /// @name Operator Overloads /// @{ - constexpr const T& operator[](size_t Index) const { - return Data[Index]; - } + constexpr const T &operator[](size_t Index) const { return Data[Index]; } /// Vector compatibility - const T& at(size_t Index) const { + const T &at(size_t Index) const { // invalid index ET_CHECK(Index < Length); return Data[Index]; @@ -185,38 +166,32 @@ class ArrayRef final { /// @{ /// Construct an ArrayRef from a single element. -template -ArrayRef makeArrayRef(const T& OneElt) { +template ArrayRef makeArrayRef(const T &OneElt) { return OneElt; } /// Construct an ArrayRef from a pointer and length. -template -ArrayRef makeArrayRef(const T* data, size_t length) { +template ArrayRef makeArrayRef(const T *data, size_t length) { return ArrayRef(data, length); } /// Construct an ArrayRef from a range. -template -ArrayRef makeArrayRef(const T* begin, const T* end) { +template ArrayRef makeArrayRef(const T *begin, const T *end) { return ArrayRef(begin, end); } /// Construct an ArrayRef from an ArrayRef (no-op) (const) -template -ArrayRef makeArrayRef(const ArrayRef& Vec) { +template ArrayRef makeArrayRef(const ArrayRef &Vec) { return Vec; } /// Construct an ArrayRef from an ArrayRef (no-op) -template -ArrayRef& makeArrayRef(ArrayRef& Vec) { +template ArrayRef &makeArrayRef(ArrayRef &Vec) { return Vec; } /// Construct an ArrayRef from a C array. -template -ArrayRef makeArrayRef(const T (&Arr)[N]) { +template ArrayRef makeArrayRef(const T (&Arr)[N]) { return ArrayRef(Arr); } @@ -224,13 +199,11 @@ ArrayRef makeArrayRef(const T (&Arr)[N]) { // conversions to get you to an ArrayRef, which is why we need so // many overloads. -template -bool operator==(ArrayRef a1, ArrayRef a2) { +template bool operator==(ArrayRef a1, ArrayRef a2) { return a1.equals(a2); } -template -bool operator!=(ArrayRef a1, ArrayRef a2) { +template bool operator!=(ArrayRef a1, ArrayRef a2) { return !a1.equals(a2); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h index 876212de..25244fb9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h @@ -23,7 +23,7 @@ namespace runtime { * See //executorch/extension/data_loader for common implementations. */ class DataLoader { - public: +public: /** * Describes the content of the segment. */ @@ -60,16 +60,13 @@ class DataLoader { /// An optional, null-terminated string describing the segment. For /// `Backend` segments, this is the backend ID. Null for other segment /// types. - const char* descriptor; + const char *descriptor; SegmentInfo() = default; - explicit SegmentInfo( - Type segment_type, - size_t segment_index = 0, - const char* descriptor = nullptr) - : segment_type(segment_type), - segment_index(segment_index), + explicit SegmentInfo(Type segment_type, size_t segment_index = 0, + const char *descriptor = nullptr) + : segment_type(segment_type), segment_index(segment_index), descriptor(descriptor) {} }; @@ -88,7 +85,7 @@ class DataLoader { * @returns a `FreeableBuffer` that owns the loaded data. */ ET_NODISCARD virtual Result - load(size_t offset, size_t size, const SegmentInfo& segment_info) const = 0; + load(size_t offset, size_t size, const SegmentInfo &segment_info) const = 0; /** * Loads data from the underlying data source into the provided buffer. @@ -104,11 +101,9 @@ class DataLoader { * * @returns an Error indicating if the load was successful. */ - ET_NODISCARD virtual Error load_into( - size_t offset, - size_t size, - const SegmentInfo& segment_info, - void* buffer) const { + ET_NODISCARD virtual Error load_into(size_t offset, size_t size, + const SegmentInfo &segment_info, + void *buffer) const { // Using a stub implementation here instead of pure virtual to expand the // data_loader interface in a backwards compatible way. (void)buffer; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h index 4babb4d1..62ea8f16 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h @@ -115,12 +115,12 @@ using ::executorch::runtime::error_code_t; * @param[in] message__ Format string for the log error message. * @param[in] ... Optional additional arguments for the format string. */ -#define ET_CHECK_OR_RETURN_ERROR(cond__, error__, message__, ...) \ - { \ - if (!(cond__)) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return ::executorch::runtime::Error::error__; \ - } \ +#define ET_CHECK_OR_RETURN_ERROR(cond__, error__, message__, ...) \ + { \ + if (!(cond__)) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return ::executorch::runtime::Error::error__; \ + } \ } /** @@ -132,13 +132,13 @@ using ::executorch::runtime::error_code_t; * @param[in] ... Optional format string for the log error message and its * arguments. */ -#define ET_CHECK_OK_OR_RETURN_ERROR(error__, ...) \ +#define ET_CHECK_OK_OR_RETURN_ERROR(error__, ...) \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(error__, ##__VA_ARGS__) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \ - ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT( \ - __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \ + ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, \ + 4, 3, 2, 1) \ (__VA_ARGS__) /** @@ -165,43 +165,43 @@ using ::executorch::runtime::error_code_t; * ET_CHECK_OK_OR_RETURN_ERROR(error_code); // Calls v1 * ET_CHECK_OK_OR_RETURN_ERROR(error_code, "Error message", ...); // Calls v2 */ -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(_1, _2, _3, _4, _5, _6, \ + _7, _8, _9, _10, N, ...) \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ - do { \ - const auto et_error__ = (error__); \ - if (et_error__ != ::executorch::runtime::Error::Ok) { \ - return et_error__; \ - } \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ + do { \ + const auto et_error__ = (error__); \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ + return et_error__; \ + } \ } while (0) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \ - do { \ - const auto et_error__ = (error__); \ - if (et_error__ != ::executorch::runtime::Error::Ok) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return et_error__; \ - } \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \ + do { \ + const auto et_error__ = (error__); \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return et_error__; \ + } \ } while (0) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h index 8003a89c..2b7ea205 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h @@ -20,24 +20,21 @@ namespace internal { // Tensor gets proper reference treatment because its expensive to copy in aten // mode, all other types are just copied. -template -struct evalue_to_const_ref_overload_return { +template struct evalue_to_const_ref_overload_return { using type = T; }; template <> struct evalue_to_const_ref_overload_return { - using type = const executorch::aten::Tensor&; + using type = const executorch::aten::Tensor &; }; -template -struct evalue_to_ref_overload_return { +template struct evalue_to_ref_overload_return { using type = T; }; -template <> -struct evalue_to_ref_overload_return { - using type = executorch::aten::Tensor&; +template <> struct evalue_to_ref_overload_return { + using type = executorch::aten::Tensor &; }; } // namespace internal @@ -52,9 +49,8 @@ struct evalue_to_ref_overload_return { * the tensor changes). To solve this instead they must be created dynamically * whenever they are used. */ -template -class BoxedEvalueList { - public: +template class BoxedEvalueList { +public: BoxedEvalueList() = default; /* * Wrapped_vals is a list of pointers into the values table of the runtime @@ -62,18 +58,18 @@ class BoxedEvalueList { * is a container of the same size whose serves as memory to construct the * unwrapped vals. */ - BoxedEvalueList(EValue** wrapped_vals, T* unwrapped_vals, int size) + BoxedEvalueList(EValue **wrapped_vals, T *unwrapped_vals, int size) : wrapped_vals_(wrapped_vals, size), unwrapped_vals_(unwrapped_vals) {} /* * Constructs and returns the list of T specified by the EValue pointers */ executorch::aten::ArrayRef get() const; - private: +private: // Source of truth for the list - executorch::aten::ArrayRef wrapped_vals_; + executorch::aten::ArrayRef wrapped_vals_; // Same size as wrapped_vals - mutable T* unwrapped_vals_; + mutable T *unwrapped_vals_; }; template <> @@ -119,13 +115,11 @@ struct EValue { Tag tag; // Basic ctors and assignments - EValue(const EValue& rhs) : EValue(rhs.payload, rhs.tag) {} + EValue(const EValue &rhs) : EValue(rhs.payload, rhs.tag) {} - EValue(EValue&& rhs) noexcept : tag(rhs.tag) { - moveFrom(std::move(rhs)); - } + EValue(EValue &&rhs) noexcept : tag(rhs.tag) { moveFrom(std::move(rhs)); } - EValue& operator=(EValue&& rhs) & noexcept { + EValue &operator=(EValue &&rhs) & noexcept { if (&rhs == this) { return *this; } @@ -135,33 +129,25 @@ struct EValue { return *this; } - EValue& operator=(EValue const& rhs) & { + EValue &operator=(EValue const &rhs) & { // Define copy assignment through copy ctor and move assignment *this = EValue(rhs); return *this; } - ~EValue() { - destroy(); - } + ~EValue() { destroy(); } /****** None Type ******/ - EValue() : tag(Tag::None) { - payload.copyable_union.as_int = 0; - } + EValue() : tag(Tag::None) { payload.copyable_union.as_int = 0; } - bool isNone() const { - return tag == Tag::None; - } + bool isNone() const { return tag == Tag::None; } /****** Int Type ******/ /*implicit*/ EValue(int64_t i) : tag(Tag::Int) { payload.copyable_union.as_int = i; } - bool isInt() const { - return tag == Tag::Int; - } + bool isInt() const { return tag == Tag::Int; } int64_t toInt() const { ET_CHECK_MSG(isInt(), "EValue is not an int."); @@ -173,9 +159,7 @@ struct EValue { payload.copyable_union.as_double = d; } - bool isDouble() const { - return tag == Tag::Double; - } + bool isDouble() const { return tag == Tag::Double; } double toDouble() const { ET_CHECK_MSG(isDouble(), "EValue is not a Double."); @@ -187,9 +171,7 @@ struct EValue { payload.copyable_union.as_bool = b; } - bool isBool() const { - return tag == Tag::Bool; - } + bool isBool() const { return tag == Tag::Bool; } bool toBool() const { ET_CHECK_MSG(isBool(), "EValue is not a Bool."); @@ -244,10 +226,9 @@ struct EValue { // from. template /*implicit*/ EValue( - T&& value, + T &&value, typename std::enable_if(value)), - EValue>::value>::type* = 0) { + decltype(*std::forward(value)), EValue>::value>::type * = 0) { ET_CHECK_MSG(value != nullptr, "Pointer is null."); // Note that this ctor does not initialize this->tag directly; it is set by // moving in the new value. @@ -255,12 +236,9 @@ struct EValue { } // Delete constructor for raw pointers to ensure they cannot be used. - template - explicit EValue(T* value) = delete; + template explicit EValue(T *value) = delete; - bool isTensor() const { - return tag == Tag::Tensor; - } + bool isTensor() const { return tag == Tag::Tensor; } executorch::aten::Tensor toTensor() && { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); @@ -269,25 +247,23 @@ struct EValue { return res; } - executorch::aten::Tensor& toTensor() & { + executorch::aten::Tensor &toTensor() & { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); return payload.as_tensor; } - const executorch::aten::Tensor& toTensor() const& { + const executorch::aten::Tensor &toTensor() const & { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); return payload.as_tensor; } /****** String Type ******/ - /*implicit*/ EValue(const char* s, size_t size) : tag(Tag::String) { + /*implicit*/ EValue(const char *s, size_t size) : tag(Tag::String) { payload.copyable_union.as_string = executorch::aten::ArrayRef(s, size); } - bool isString() const { - return tag == Tag::String; - } + bool isString() const { return tag == Tag::String; } executorch::aten::string_view toString() const { ET_CHECK_MSG(isString(), "EValue is not a String."); @@ -301,9 +277,7 @@ struct EValue { payload.copyable_union.as_int_list = i; } - bool isIntList() const { - return tag == Tag::ListInt; - } + bool isIntList() const { return tag == Tag::ListInt; } executorch::aten::ArrayRef toIntList() const { ET_CHECK_MSG(isIntList(), "EValue is not an Int List."); @@ -315,9 +289,7 @@ struct EValue { payload.copyable_union.as_bool_list = b; } - bool isBoolList() const { - return tag == Tag::ListBool; - } + bool isBoolList() const { return tag == Tag::ListBool; } executorch::aten::ArrayRef toBoolList() const { ET_CHECK_MSG(isBoolList(), "EValue is not a Bool List."); @@ -330,9 +302,7 @@ struct EValue { payload.copyable_union.as_double_list = d; } - bool isDoubleList() const { - return tag == Tag::ListDouble; - } + bool isDoubleList() const { return tag == Tag::ListDouble; } executorch::aten::ArrayRef toDoubleList() const { ET_CHECK_MSG(isDoubleList(), "EValue is not a Double List."); @@ -345,9 +315,7 @@ struct EValue { payload.copyable_union.as_tensor_list = t; } - bool isTensorList() const { - return tag == Tag::ListTensor; - } + bool isTensorList() const { return tag == Tag::ListTensor; } executorch::aten::ArrayRef toTensorList() const { ET_CHECK_MSG(isTensorList(), "EValue is not a Tensor List."); @@ -361,9 +329,7 @@ struct EValue { payload.copyable_union.as_list_optional_tensor = t; } - bool isListOptionalTensor() const { - return tag == Tag::ListOptionalTensor; - } + bool isListOptionalTensor() const { return tag == Tag::ListOptionalTensor; } executorch::aten::ArrayRef< executorch::aten::optional> @@ -394,16 +360,14 @@ struct EValue { /****** Device Type ******/ executorch::aten::Device toDevice() const { ET_CHECK_MSG(isInt(), "EValue is not a Device."); - return executorch::aten::Device( - static_cast( - payload.copyable_union.as_int), - -1); + return executorch::aten::Device(static_cast( + payload.copyable_union.as_int), + -1); } + template T to() &&; template - T to() &&; - template - typename internal::evalue_to_const_ref_overload_return::type to() const&; + typename internal::evalue_to_const_ref_overload_return::type to() const &; template typename internal::evalue_to_ref_overload_return::type to() &; @@ -419,7 +383,7 @@ struct EValue { return this->to(); } - private: +private: // Pre cond: the payload value has had its destructor called void clearToNone() noexcept { payload.copyable_union.as_int = 0; @@ -427,7 +391,7 @@ struct EValue { } // Shared move logic - void moveFrom(EValue&& rhs) noexcept { + void moveFrom(EValue &&rhs) noexcept { if (rhs.isTensor()) { new (&payload.as_tensor) executorch::aten::Tensor(std::move(rhs.payload.as_tensor)); @@ -448,17 +412,17 @@ struct EValue { if (isTensor()) { payload.as_tensor.~Tensor(); } else if (isTensorList()) { - for (auto& tensor : toTensorList()) { + for (auto &tensor : toTensorList()) { tensor.~Tensor(); } } else if (isListOptionalTensor()) { - for (auto& optional_tensor : toListOptionalTensor()) { + for (auto &optional_tensor : toListOptionalTensor()) { optional_tensor.~optional(); } } } - EValue(const Payload& p, Tag t) : tag(t) { + EValue(const Payload &p, Tag t) : tag(t) { if (isTensor()) { new (&payload.as_tensor) executorch::aten::Tensor(p.as_tensor); } else { @@ -468,14 +432,13 @@ struct EValue { }; #define EVALUE_DEFINE_TO(T, method_name) \ - template <> \ - inline T EValue::to()&& { \ + template <> inline T EValue::to() && { \ return static_cast(std::move(*this).method_name()); \ } \ template <> \ inline ::executorch::runtime::internal::evalue_to_const_ref_overload_return< \ T>::type \ - EValue::to() const& { \ + EValue::to() const & { \ typedef ::executorch::runtime::internal:: \ evalue_to_const_ref_overload_return::type return_type; \ return static_cast(this->method_name()); \ @@ -483,7 +446,7 @@ struct EValue { template <> \ inline ::executorch::runtime::internal::evalue_to_ref_overload_return< \ T>::type \ - EValue::to()& { \ + EValue::to() & { \ typedef ::executorch::runtime::internal::evalue_to_ref_overload_return< \ T>::type return_type; \ return static_cast(this->method_name()); \ @@ -499,9 +462,8 @@ EVALUE_DEFINE_TO(executorch::aten::MemoryFormat, toMemoryFormat) EVALUE_DEFINE_TO(executorch::aten::Layout, toLayout) EVALUE_DEFINE_TO(executorch::aten::Device, toDevice) // Tensor and Optional Tensor -EVALUE_DEFINE_TO( - executorch::aten::optional, - toOptional) +EVALUE_DEFINE_TO(executorch::aten::optional, + toOptional) EVALUE_DEFINE_TO(executorch::aten::Tensor, toTensor) // IntList and Optional IntList @@ -512,37 +474,32 @@ EVALUE_DEFINE_TO( // DoubleList and Optional DoubleList EVALUE_DEFINE_TO(executorch::aten::ArrayRef, toDoubleList) -EVALUE_DEFINE_TO( - executorch::aten::optional>, - toOptional>) +EVALUE_DEFINE_TO(executorch::aten::optional>, + toOptional>) // BoolList and Optional BoolList EVALUE_DEFINE_TO(executorch::aten::ArrayRef, toBoolList) -EVALUE_DEFINE_TO( - executorch::aten::optional>, - toOptional>) +EVALUE_DEFINE_TO(executorch::aten::optional>, + toOptional>) // TensorList and Optional TensorList -EVALUE_DEFINE_TO( - executorch::aten::ArrayRef, - toTensorList) +EVALUE_DEFINE_TO(executorch::aten::ArrayRef, + toTensorList) EVALUE_DEFINE_TO( executorch::aten::optional< executorch::aten::ArrayRef>, toOptional>) // List of Optional Tensor -EVALUE_DEFINE_TO( - executorch::aten::ArrayRef< - executorch::aten::optional>, - toListOptionalTensor) +EVALUE_DEFINE_TO(executorch::aten::ArrayRef< + executorch::aten::optional>, + toListOptionalTensor) #undef EVALUE_DEFINE_TO template executorch::aten::ArrayRef BoxedEvalueList::get() const { for (typename executorch::aten::ArrayRef::size_type i = 0; - i < wrapped_vals_.size(); - i++) { + i < wrapped_vals_.size(); i++) { ET_CHECK(wrapped_vals_[i] != nullptr); unwrapped_vals_[i] = wrapped_vals_[i]->template to(); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h index 5cf4f74a..ffb60066 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h @@ -6,11 +6,11 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include #include -#include #pragma once @@ -113,7 +113,7 @@ struct EventTracerEntry { * flatbuffer. */ class EventTracer { - public: +public: /** * Start a new event block (can consist of profiling and/or debugging events.) * identified by this name. A block is conceptually a set of events that we @@ -125,7 +125,7 @@ class EventTracer { * pointer around. The string must be copied over into internal memory during * this call. */ - virtual void create_event_block(const char* name) = 0; + virtual void create_event_block(const char *name) = 0; /** * Start the profiling of the event identified by name and debug_handle. @@ -147,10 +147,9 @@ class EventTracer { * @return Returns an instance of EventTracerEntry which should be passed back * into the end_profiling() call. */ - virtual EventTracerEntry start_profiling( - const char* name, - ChainID chain_id = kUnsetChainId, - DebugHandle debug_handle = kUnsetDebugHandle) = 0; + virtual EventTracerEntry + start_profiling(const char *name, ChainID chain_id = kUnsetChainId, + DebugHandle debug_handle = kUnsetDebugHandle) = 0; /** * Start the profiling of a delegate event. Similar to start_profiling it will @@ -168,9 +167,9 @@ class EventTracer { * based names are used by this delegate to identify ops executed in the * backend then kUnsetDebugHandle should be passed in here. */ - virtual EventTracerEntry start_profiling_delegate( - const char* name, - DebugHandle delegate_debug_index) = 0; + virtual EventTracerEntry + start_profiling_delegate(const char *name, + DebugHandle delegate_debug_index) = 0; /** * Signal the end of the delegate profiling event contained in @@ -186,10 +185,9 @@ class EventTracer { * make it available for the user again in the post-processing stage. * @param[in] metadata_len Length of the metadata buffer. */ - virtual void end_profiling_delegate( - EventTracerEntry event_tracer_entry, - const void* metadata = nullptr, - size_t metadata_len = 0) = 0; + virtual void end_profiling_delegate(EventTracerEntry event_tracer_entry, + const void *metadata = nullptr, + size_t metadata_len = 0) = 0; /** * Some delegates get access to the profiling details only after the complete @@ -216,13 +214,12 @@ class EventTracer { * make it available for the user again in the post-processing stage. * @param[in] metadata_len Length of the metadata buffer. */ - virtual void log_profiling_delegate( - const char* name, - DebugHandle delegate_debug_index, - et_timestamp_t start_time, - et_timestamp_t end_time, - const void* metadata = nullptr, - size_t metadata_len = 0) = 0; + virtual void log_profiling_delegate(const char *name, + DebugHandle delegate_debug_index, + et_timestamp_t start_time, + et_timestamp_t end_time, + const void *metadata = nullptr, + size_t metadata_len = 0) = 0; /** * End the profiling of the event identified by prof_entry @@ -251,7 +248,7 @@ class EventTracer { * * @return Identifier to uniquely identify this allocator. */ - virtual AllocatorID track_allocator(const char* name) = 0; + virtual AllocatorID track_allocator(const char *name) = 0; /** * Log an evalue during the execution of the model. This is useful for @@ -265,9 +262,8 @@ class EventTracer { * @param[in] evalue_type Indicates what type of output this is logging e.g. * an intermediate output, program output etc. */ - virtual void log_evalue( - const EValue& evalue, - LoggedEValueType evalue_type) = 0; + virtual void log_evalue(const EValue &evalue, + LoggedEValueType evalue_type) = 0; /** * Log an intermediate tensor output from a delegate. @@ -284,10 +280,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The tensor type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const executorch::aten::Tensor& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const executorch::aten::Tensor &output) = 0; /** * Log an intermediate tensor array output from a delegate. @@ -305,8 +301,7 @@ class EventTracer { * @param[in] output The tensor array type output to be logged. */ virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, + const char *name, DebugHandle delegate_debug_index, const ArrayRef output) = 0; /** @@ -324,10 +319,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The int type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const int& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const int &output) = 0; /** * Log an intermediate bool output from a delegate. @@ -344,10 +339,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The bool type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const bool& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const bool &output) = 0; /** * Log an intermediate double output from a delegate. @@ -364,10 +359,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The double type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const double& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const double &output) = 0; /** * Helper function to set the chain id ands debug handle. Users have two @@ -416,9 +411,7 @@ class EventTracer { /** * Return the current bundled input index. */ - int bundled_input_index() { - return bundled_input_index_; - } + int bundled_input_index() { return bundled_input_index_; } /** * Set the level of event tracer debug logging that is desired. @@ -438,8 +431,8 @@ class EventTracer { /** * Set the level of event tracer profiling that is desired. */ - void set_event_tracer_profiling_level( - EventTracerProfilingLevel profiling_level) { + void + set_event_tracer_profiling_level(EventTracerProfilingLevel profiling_level) { event_tracer_profiling_level_ = profiling_level; } @@ -462,22 +455,18 @@ class EventTracer { * * @return Current chain id. */ - ChainID current_chain_id() { - return chain_id_; - } + ChainID current_chain_id() { return chain_id_; } /** * Get the current debug handle. * * @return Current debug handle. */ - DebugHandle current_debug_handle() { - return debug_handle_; - } + DebugHandle current_debug_handle() { return debug_handle_; } virtual ~EventTracer() {} - protected: +protected: ChainID chain_id_ = kUnsetChainId; DebugHandle debug_handle_ = kUnsetDebugHandle; bool event_tracer_enable_debugging_ = false; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h index 40754160..1e46013c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h @@ -38,8 +38,8 @@ namespace internal { * operators only. If operator profiling is disabled then this class is a no-op. */ class EventTracerProfileOpScope final { - public: - EventTracerProfileOpScope(EventTracer* event_tracer, const char* name) { +public: + EventTracerProfileOpScope(EventTracer *event_tracer, const char *name) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -67,9 +67,9 @@ class EventTracerProfileOpScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; EventTracerEntry event_entry_; #endif }; @@ -83,8 +83,8 @@ using EventTracerProfileScope = EventTracerProfileOpScope; * be used for profiling methods in the runtime. */ class EventTracerProfileMethodScope final { - public: - EventTracerProfileMethodScope(EventTracer* event_tracer, const char* name) { +public: + EventTracerProfileMethodScope(EventTracer *event_tracer, const char *name) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -106,9 +106,9 @@ class EventTracerProfileMethodScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; EventTracerEntry event_entry_; #endif }; @@ -122,11 +122,10 @@ class EventTracerProfileMethodScope final { * debug handle to defaults when this object goes out of scope. */ class EventTracerProfileInstructionScope final { - public: - EventTracerProfileInstructionScope( - EventTracer* event_tracer, - ChainID chain_idx, - DebugHandle debug_handle) { +public: + EventTracerProfileInstructionScope(EventTracer *event_tracer, + ChainID chain_idx, + DebugHandle debug_handle) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -149,9 +148,9 @@ class EventTracerProfileInstructionScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; #endif }; @@ -166,9 +165,8 @@ inline bool event_tracer_enabled() { * Create a new event block with the specified name. Any events logged * after this will be associated with this new event block. */ -inline void event_tracer_create_event_block( - EventTracer* event_tracer, - char const* name) { +inline void event_tracer_create_event_block(EventTracer *event_tracer, + char const *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->create_event_block(name); @@ -185,9 +183,9 @@ inline void event_tracer_create_event_block( * around and pass into the corresponding event_tracer_end_profiling_event * call. */ -inline EventTracerEntry event_tracer_begin_profiling_event( - EventTracer* event_tracer, - char const* name) { +inline EventTracerEntry +event_tracer_begin_profiling_event(EventTracer *event_tracer, + char const *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->start_profiling(name); @@ -204,9 +202,8 @@ inline EventTracerEntry event_tracer_begin_profiling_event( * Mark the end of a profiling event passing in the entry token * returned by a previous call to ET_EVENT_TRACER_BEGIN_PROFILING_EVENT. */ -inline void event_tracer_end_profiling_event( - EventTracer* event_tracer, - EventTracerEntry event) { +inline void event_tracer_end_profiling_event(EventTracer *event_tracer, + EventTracerEntry event) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->end_profiling(event); @@ -222,9 +219,8 @@ inline void event_tracer_end_profiling_event( * an AllocatorID that will be used to track all subsequent allocations done by * this allocator. */ -inline AllocatorID event_tracer_track_allocator( - EventTracer* event_tracer, - const char* name) { +inline AllocatorID event_tracer_track_allocator(EventTracer *event_tracer, + const char *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->track_allocator(name); @@ -238,10 +234,8 @@ inline AllocatorID event_tracer_track_allocator( } /// Log the allocation event done via the allocator represented by id. -inline void event_tracer_track_allocation( - EventTracer* event_tracer, - AllocatorID id, - size_t size) { +inline void event_tracer_track_allocation(EventTracer *event_tracer, + AllocatorID id, size_t size) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->track_allocation(id, size); @@ -254,7 +248,7 @@ inline void event_tracer_track_allocation( } /// Log an intermediate value. -inline void event_tracer_log_evalue(EventTracer* event_tracer, EValue& evalue) { +inline void event_tracer_log_evalue(EventTracer *event_tracer, EValue &evalue) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { if (event_tracer->event_tracer_debug_level() >= @@ -269,9 +263,8 @@ inline void event_tracer_log_evalue(EventTracer* event_tracer, EValue& evalue) { } /// Log a program output. -inline void event_tracer_log_evalue_output( - EventTracer* event_tracer, - const EValue& evalue) { +inline void event_tracer_log_evalue_output(EventTracer *event_tracer, + const EValue &evalue) { #ifdef ET_EVENT_TRACER_ENABLED /* * If debugging via event tracer is enabled but intermediate output logging is @@ -291,9 +284,8 @@ inline void event_tracer_log_evalue_output( // Set the bundled input index of the current bundled input being used by the // method. -inline void event_tracer_set_bundled_input_index( - EventTracer* event_tracer, - int bundled_input_index) { +inline void event_tracer_set_bundled_input_index(EventTracer *event_tracer, + int bundled_input_index) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->set_bundled_input_index(bundled_input_index); diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h index b2369fc2..17024630 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h @@ -47,10 +47,10 @@ namespace runtime { * based names are used by this delegate to identify ops executed in the * backend then kUnsetDebugHandle should be passed in here. */ -inline EventTracerEntry event_tracer_start_profiling_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id) { +inline EventTracerEntry +event_tracer_start_profiling_delegate(EventTracer *event_tracer, + const char *name, + DebugHandle delegate_debug_id) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->start_profiling_delegate(name, delegate_debug_id); @@ -80,14 +80,12 @@ inline EventTracerEntry event_tracer_start_profiling_delegate( * @param[in] metadata_len Length of the metadata buffer. */ inline void event_tracer_end_profiling_delegate( - EventTracer* event_tracer, - EventTracerEntry event_tracer_entry, - const void* metadata = nullptr, - size_t metadata_len = 0) { + EventTracer *event_tracer, EventTracerEntry event_tracer_entry, + const void *metadata = nullptr, size_t metadata_len = 0) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { - event_tracer->end_profiling_delegate( - event_tracer_entry, metadata, metadata_len); + event_tracer->end_profiling_delegate(event_tracer_entry, metadata, + metadata_len); } #else //! ET_EVENT_TRACER_ENABLED (void)event_tracer_entry; @@ -124,17 +122,13 @@ inline void event_tracer_end_profiling_delegate( * @param[in] metadata_len Length of the metadata buffer. */ inline void event_tracer_log_profiling_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id, - et_timestamp_t start_time, - et_timestamp_t end_time, - const void* metadata = nullptr, - size_t metadata_len = 0) { + EventTracer *event_tracer, const char *name, DebugHandle delegate_debug_id, + et_timestamp_t start_time, et_timestamp_t end_time, + const void *metadata = nullptr, size_t metadata_len = 0) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { - event_tracer->log_profiling_delegate( - name, delegate_debug_id, start_time, end_time, metadata, metadata_len); + event_tracer->log_profiling_delegate(name, delegate_debug_id, start_time, + end_time, metadata, metadata_len); } #else //! ET_EVENT_TRACER_ENABLED (void)name; @@ -166,11 +160,10 @@ inline void event_tracer_log_profiling_delegate( * @param[in] output The output to be logged. */ template -inline void event_tracer_log_output_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id, - const T& output) { +inline void event_tracer_log_output_delegate(EventTracer *event_tracer, + const char *name, + DebugHandle delegate_debug_id, + const T &output) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { static_assert( @@ -179,8 +172,8 @@ inline void event_tracer_log_output_delegate( std::is_same::value || std::is_same>::value, "Unsupported type for intermediate output"); - event_tracer->log_intermediate_output_delegate( - name, delegate_debug_id, output); + event_tracer->log_intermediate_output_delegate(name, delegate_debug_id, + output); } #else //! ET_EVENT_TRACER_ENABLED (void)name; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h index 84b918bf..c2443d36 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h @@ -12,36 +12,36 @@ #ifdef USE_ATEN_LIB #include // @manual #include -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include -#else // use executor -#include // @manual -#include // @manual +#else // use executor +#include // @manual +#include // @manual #include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include // @manual #endif @@ -57,10 +57,8 @@ using Tensor = at::Tensor; using TensorList = at::TensorList; using TensorImpl = at::TensorImpl; using string_view = c10::string_view; -template -using ArrayRef = c10::ArrayRef; -template -using optional = std::optional; +template using ArrayRef = c10::ArrayRef; +template using optional = std::optional; using nullopt_t = c10::nullopt_t; using c10::nullopt; using ScalarType = at::ScalarType; @@ -75,8 +73,7 @@ using Layout = c10::Layout; // Custom types that map to ScalarType using Half = c10::Half; -template -using complex = c10::complex; +template using complex = c10::complex; using qint8 = c10::qint8; using quint8 = c10::quint8; using qint32 = c10::qint32; @@ -85,11 +82,10 @@ using quint4x2 = c10::quint4x2; using quint2x4 = c10::quint2x4; using IntArrayRef = at::IntArrayRef; -template -using OptionalArrayRef = c10::OptionalArrayRef; +template using OptionalArrayRef = c10::OptionalArrayRef; using OptionalIntArrayRef = OptionalArrayRef; -inline ssize_t compute_numel(const SizesType* sizes, ssize_t dim) { +inline ssize_t compute_numel(const SizesType *sizes, ssize_t dim) { return static_cast( c10::multiply_integers(c10::ArrayRef(sizes, dim))); } @@ -99,10 +95,8 @@ inline ssize_t compute_numel(const SizesType* sizes, ssize_t dim) { using Tensor = torch::executor::Tensor; using TensorImpl = torch::executor::TensorImpl; using string_view = torch::executor::string_view; -template -using ArrayRef = torch::executor::ArrayRef; -template -using optional = torch::executor::optional; +template using ArrayRef = torch::executor::ArrayRef; +template using optional = torch::executor::optional; using nullopt_t = torch::executor::nullopt_t; // NOLINTNEXTLINE(facebook-hte-NamespaceScopedStaticDeclaration) static constexpr nullopt_t nullopt{0}; @@ -119,8 +113,7 @@ using Layout = torch::executor::Layout; // Custom types that map to ScalarType using Half = torch::executor::Half; -template -using complex = torch::executor::complex; +template using complex = torch::executor::complex; using qint8 = torch::executor::qint8; using quint8 = torch::executor::quint8; using qint32 = torch::executor::qint32; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h index 4c5858fb..c1ea45b8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h @@ -19,7 +19,7 @@ namespace runtime { namespace { template -bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { +bool validate_dim_order(const DimOrderType *dim_order, const size_t dims) { for (int32_t i = 0; i < dims; ++i) { if (dim_order[i] >= dims) { return false; @@ -37,9 +37,8 @@ bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { * @param[in] dims length of the dim_order array */ template -inline bool is_contiguous_dim_order( - const DimOrderType* dim_order, - const size_t dims) { +inline bool is_contiguous_dim_order(const DimOrderType *dim_order, + const size_t dims) { for (int i = 0; i < dims; ++i) { if (dim_order[i] != i) { return false; @@ -56,9 +55,8 @@ inline bool is_contiguous_dim_order( * @param[in] dims length of the dim_order array */ template -bool is_channels_last_dim_order( - const DimOrderType* dim_order, - const size_t dims) { +bool is_channels_last_dim_order(const DimOrderType *dim_order, + const size_t dims) { if (dims != 4 && dims != 5) { return false; } @@ -108,11 +106,10 @@ bool is_channels_last_dim_order( * dim_order_to_stride which will check that the dim order is valid. */ template -inline void dim_order_to_stride_nocheck( - const SizesType* sizes, - const DimOrderType* dim_order, - const size_t dims, - StridesType* strides) { +inline void dim_order_to_stride_nocheck(const SizesType *sizes, + const DimOrderType *dim_order, + const size_t dims, + StridesType *strides) { // For 0 dim tensors, just return ok. if (dims == 0) { return; @@ -134,20 +131,17 @@ inline void dim_order_to_stride_nocheck( } template -ET_NODISCARD inline Error dim_order_to_stride( - const SizesType* sizes, - const DimOrderType* dim_order, - const size_t dims, - StridesType* strides) { +ET_NODISCARD inline Error +dim_order_to_stride(const SizesType *sizes, const DimOrderType *dim_order, + const size_t dims, StridesType *strides) { // For 0 dim tensors, just return ok. if (dims == 0) { return Error::Ok; } - ET_CHECK_OR_RETURN_ERROR( - validate_dim_order(dim_order, dims), - InvalidArgument, - "Invalid dim order. One of the value is larger than the number of dims %zu", - dims); + ET_CHECK_OR_RETURN_ERROR(validate_dim_order(dim_order, dims), InvalidArgument, + "Invalid dim order. One of the value is larger than " + "the number of dims %zu", + dims); dim_order_to_stride_nocheck(sizes, dim_order, dims, strides); return Error::Ok; @@ -155,23 +149,21 @@ ET_NODISCARD inline Error dim_order_to_stride( namespace internal { -template -struct StrideDimOrder { +template struct StrideDimOrder { StridesType stride; DimOrderType dim_order; StrideDimOrder(StridesType stride, DimOrderType dim_order) : stride(stride), dim_order(dim_order) {} StrideDimOrder() = default; - bool operator>(const StrideDimOrder& other) const { + bool operator>(const StrideDimOrder &other) const { // descending order return stride < other.stride; } }; -template -struct Sorter { - public: +template struct Sorter { +public: void quick_sort(ValueType arr[], int32_t low, int32_t high) { if (low < high) { ValueType pivot = arr[high]; @@ -182,15 +174,15 @@ struct Sorter { } } - private: +private: void swap(ValueType arr[], int32_t pos1, int32_t pos2) noexcept { ValueType temp = arr[pos1]; arr[pos1] = arr[pos2]; arr[pos2] = temp; } - int32_t - partition(ValueType arr[], int32_t low, int32_t high, ValueType pivot) { + int32_t partition(ValueType arr[], int32_t low, int32_t high, + ValueType pivot) { int32_t i = low; int32_t j = low; while (i <= high) { @@ -226,21 +218,15 @@ struct Sorter { * TODO(T148342910) */ template -ET_NODISCARD inline Error stride_to_dim_order( - const StridesType* strides, - const size_t dims, - DimOrderType* dim_order) { +ET_NODISCARD inline Error stride_to_dim_order(const StridesType *strides, + const size_t dims, + DimOrderType *dim_order) { const size_t kMaxNumOfDimensions = 16; - ET_CHECK_OR_RETURN_ERROR( - dim_order != nullptr, - MemoryAllocationFailed, - "Need memory to get dim_order."); - ET_CHECK_OR_RETURN_ERROR( - dims <= kMaxNumOfDimensions, - NotSupported, - "dims %zu exceeds maximum allowed %zu", - dims, - kMaxNumOfDimensions); + ET_CHECK_OR_RETURN_ERROR(dim_order != nullptr, MemoryAllocationFailed, + "Need memory to get dim_order."); + ET_CHECK_OR_RETURN_ERROR(dims <= kMaxNumOfDimensions, NotSupported, + "dims %zu exceeds maximum allowed %zu", dims, + kMaxNumOfDimensions); internal::StrideDimOrder array[kMaxNumOfDimensions]; for (DimOrderType i = 0; i < dims; i++) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h index e500167f..6016dab8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h @@ -67,19 +67,17 @@ namespace runtime { template struct is_floating_point : std::integral_constant< - bool, - std::is_floating_point::value || - std::is_same::value || - std::is_same::value> {}; + bool, std::is_floating_point::value || + std::is_same::value || + std::is_same::value> {}; // Util to figure out if the scalar type is one of the // reduced precision floating point types. template struct is_reduced_floating_point : std::integral_constant< - bool, - std::is_same::value || - std::is_same::value> {}; + bool, std::is_same::value || + std::is_same::value> {}; template constexpr bool is_reduced_floating_point_v = @@ -87,13 +85,12 @@ constexpr bool is_reduced_floating_point_v = #endif /// Maps ScalarTypes to C++ types. -template <::executorch::aten::ScalarType N> -struct ScalarTypeToCppType; +template <::executorch::aten::ScalarType N> struct ScalarTypeToCppType; -#define SPECIALIZE_ScalarTypeToCppType(cpp_type, scalar_type) \ - template <> \ - struct ScalarTypeToCppType<::executorch::aten::ScalarType::scalar_type> { \ - using type = cpp_type; \ +#define SPECIALIZE_ScalarTypeToCppType(cpp_type, scalar_type) \ + template <> \ + struct ScalarTypeToCppType<::executorch::aten::ScalarType::scalar_type> { \ + using type = cpp_type; \ }; ET_FORALL_SCALAR_TYPES(SPECIALIZE_ScalarTypeToCppType) @@ -101,15 +98,14 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_ScalarTypeToCppType) #undef SPECIALIZE_ScalarTypeToCppType /// Maps C++ types to ScalarTypes. -template -struct CppTypeToScalarType; +template struct CppTypeToScalarType; -#define SPECIALIZE_CppTypeToScalarType(cpp_type, scalar_type) \ - template <> \ - struct CppTypeToScalarType \ - : std::integral_constant< \ - ::executorch::aten::ScalarType, \ - ::executorch::aten::ScalarType::scalar_type> {}; +#define SPECIALIZE_CppTypeToScalarType(cpp_type, scalar_type) \ + template <> \ + struct CppTypeToScalarType \ + : std::integral_constant<::executorch::aten::ScalarType, \ + ::executorch::aten::ScalarType::scalar_type> { \ + }; ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) @@ -131,221 +127,221 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) // In this context, "INT" means integer C types, which is why the quantized // integer types are not included. -#define ET_FORALL_INT_TYPES(_) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ +#define ET_FORALL_INT_TYPES(_) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ _(int64_t, Long) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. -#define ET_FORALL_INT_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ +#define ET_FORALL_INT_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ _(ANOTHER_INPUT, int64_t, Long) -#define ET_FORALL_INT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ +#define ET_FORALL_INT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) -#define ET_FORALL_INT_TYPES_AND(SCALARTYPE, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_INT_TYPES_AND(SCALARTYPE, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) // In this context, "FLOAT" means float C types, which is why BFloat16 is not // included. -#define ET_FORALL_FLOAT_TYPES(_) \ - _(float, Float) \ +#define ET_FORALL_FLOAT_TYPES(_) \ + _(float, Float) \ _(double, Double) -#define ET_FORALL_FLOAT_TYPES_AND(SCALARTYPE, _) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_FLOAT_TYPES_AND(SCALARTYPE, _) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_FLOAT_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_FLOAT_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) #define ET_FORALL_FLOATH_TYPES(_) ET_FORALL_FLOAT_TYPES_AND(Half, _) -#define ET_FORALL_FLOATHBF16_TYPES(_) \ +#define ET_FORALL_FLOATHBF16_TYPES(_) \ ET_FORALL_FLOAT_TYPES_AND2(Half, BFloat16, _) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. Not to be confused with another scalar type as in // `ET_FORALL_FLOAT_TYPES_AND`. -#define ET_FORALL_FLOAT_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, float, Float) \ +#define ET_FORALL_FLOAT_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, float, Float) \ _(ANOTHER_INPUT, double, Double) -#define ET_FORALL_FLOAT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ +#define ET_FORALL_FLOAT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) -#define ET_FORALL_FLOATHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ +#define ET_FORALL_FLOATHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::BFloat16, BFloat16) // In this context, "REAL" means integer/float C types, which is why BFloat16 // and Half are not included. -#define ET_FORALL_REAL_TYPES(_) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ +#define ET_FORALL_REAL_TYPES(_) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ _(double, Double) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. Not to be confused with another scalar type as in // `ET_FORALL_REAL_TYPES_AND`. -#define ET_FORALL_REAL_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ - _(ANOTHER_INPUT, int64_t, Long) \ - _(ANOTHER_INPUT, float, Float) \ +#define ET_FORALL_REAL_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ + _(ANOTHER_INPUT, int64_t, Long) \ + _(ANOTHER_INPUT, float, Float) \ _(ANOTHER_INPUT, double, Double) -#define ET_FORALL_REAL_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ +#define ET_FORALL_REAL_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) -#define ET_FORALL_REALHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ +#define ET_FORALL_REALHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::BFloat16, BFloat16) // For macros that take `SCALARTYPEn` parameters, those parameters should be // an unquoted/unqualified enumerator name like `Int` or `Float`. -#define ET_FORALL_REAL_TYPES_AND(SCALARTYPE, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_REAL_TYPES_AND(SCALARTYPE, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) #define ET_FORALL_REALH_TYPES(_) ET_FORALL_REAL_TYPES_AND(Half, _) -#define ET_FORALL_REALHBF16_TYPES(_) \ +#define ET_FORALL_REALHBF16_TYPES(_) \ ET_FORALL_REAL_TYPES_AND2(Half, BFloat16, _) -#define ET_FORALL_REALHBBF16_TYPES(_) \ +#define ET_FORALL_REALHBBF16_TYPES(_) \ ET_FORALL_REAL_TYPES_AND3(Bool, Half, BFloat16, _) -#define ET_FORALL_REAL_TYPES_AND_WITH(SCALARTYPE, ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ - _(ANOTHER_INPUT, int64_t, Long) \ - _(ANOTHER_INPUT, float, Float) \ - _(ANOTHER_INPUT, double, Double) \ - _(ANOTHER_INPUT, \ - ::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_REAL_TYPES_AND_WITH(SCALARTYPE, ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ + _(ANOTHER_INPUT, int64_t, Long) \ + _(ANOTHER_INPUT, float, Float) \ + _(ANOTHER_INPUT, double, Double) \ + _(ANOTHER_INPUT, \ + ::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) -#define ET_FORALL_REAL_TYPES_AND3(SCALARTYPE1, SCALARTYPE2, SCALARTYPE3, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ - SCALARTYPE2) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE3>::type, \ +#define ET_FORALL_REAL_TYPES_AND3(SCALARTYPE1, SCALARTYPE2, SCALARTYPE3, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ + SCALARTYPE2) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE3>::type, \ SCALARTYPE3) -#define ET_FORALL_QINT_TYPES(_) \ - _(::torch::executor::qint8, QInt8) \ - _(::torch::executor::quint8, QUInt8) \ - _(::torch::executor::qint32, QInt32) \ - _(::torch::executor::quint4x2, QUInt4x2) \ +#define ET_FORALL_QINT_TYPES(_) \ + _(::torch::executor::qint8, QInt8) \ + _(::torch::executor::quint8, QUInt8) \ + _(::torch::executor::qint32, QInt32) \ + _(::torch::executor::quint4x2, QUInt4x2) \ _(::torch::executor::quint2x4, QUInt2x4) // In this context, "COMPLEX" means complex types based on primitive C types, // which is why ComplexHalf is not included. -#define ET_FORALL_COMPLEX_TYPES(_) \ - _(::torch::executor::complex, ComplexFloat) \ +#define ET_FORALL_COMPLEX_TYPES(_) \ + _(::torch::executor::complex, ComplexFloat) \ _(::torch::executor::complex, ComplexDouble) // @@ -358,8 +354,8 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) */ inline bool isValid(::executorch::aten::ScalarType type) { return static_cast(type) >= 0 && - type < ::executorch::aten::ScalarType::NumOptions && - type != ::executorch::aten::ScalarType::Undefined; + type < ::executorch::aten::ScalarType::NumOptions && + type != ::executorch::aten::ScalarType::Undefined; } /** @@ -368,17 +364,17 @@ inline bool isValid(::executorch::aten::ScalarType type) { * @param[in] t The type to get the name of. * @return The name of the type, or "UNKNOWN_SCALAR" if the type is not known. */ -inline const char* toString(::executorch::aten::ScalarType t) { -#define DEFINE_CASE(_, name) \ - case ::executorch::aten::ScalarType::name: \ +inline const char *toString(::executorch::aten::ScalarType t) { +#define DEFINE_CASE(_, name) \ + case ::executorch::aten::ScalarType::name: \ return #name; switch (t) { ET_FORALL_SCALAR_TYPES(DEFINE_CASE) - case ::executorch::aten::ScalarType::Undefined: - return "Undefined"; - default: - return "UNKNOWN_SCALAR"; + case ::executorch::aten::ScalarType::Undefined: + return "Undefined"; + default: + return "UNKNOWN_SCALAR"; } #undef DEFINE_CASE } @@ -392,64 +388,59 @@ inline const char* toString(::executorch::aten::ScalarType t) { * @return The size of the associated C type in bytes. */ inline size_t elementSize(::executorch::aten::ScalarType t) { -#define CASE_ELEMENTSIZE_CASE(ctype, name) \ - case ::executorch::aten::ScalarType::name: \ +#define CASE_ELEMENTSIZE_CASE(ctype, name) \ + case ::executorch::aten::ScalarType::name: \ return sizeof(ctype); switch (t) { ET_FORALL_SCALAR_TYPES(CASE_ELEMENTSIZE_CASE) - default: - ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); + default: + ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); } #undef CASE_ELEMENTSIZE_CASE } -inline constexpr bool isIntegralType( - ::executorch::aten::ScalarType t, - bool includeBool) { +inline constexpr bool isIntegralType(::executorch::aten::ScalarType t, + bool includeBool) { return (includeBool && t == ::executorch::aten::ScalarType::Bool) || - (t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Short); + (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Short); } template struct is_integral_type : public std::integral_constant< - bool, - isIntegralType(CppTypeToScalarType::value, includeBool)> {}; + bool, isIntegralType(CppTypeToScalarType::value, includeBool)> {}; inline constexpr bool isFloatingType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Double || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Half || - t == ::executorch::aten::ScalarType::BFloat16); + return (t == ::executorch::aten::ScalarType::Double || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Half || + t == ::executorch::aten::ScalarType::BFloat16); } inline bool isRealType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Short || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Double); + return (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Short || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Double); } inline bool isRealHType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Short || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Double || - t == ::executorch::aten::ScalarType::Half); + return (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Short || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Double || + t == ::executorch::aten::ScalarType::Half); } inline bool isRealHBType(::executorch::aten::ScalarType t) { @@ -465,23 +456,22 @@ inline bool isRealHBBF16Type(::executorch::aten::ScalarType t) { } inline constexpr bool isComplexType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::ComplexHalf || - t == ::executorch::aten::ScalarType::ComplexFloat || - t == ::executorch::aten::ScalarType::ComplexDouble); + return (t == ::executorch::aten::ScalarType::ComplexHalf || + t == ::executorch::aten::ScalarType::ComplexFloat || + t == ::executorch::aten::ScalarType::ComplexDouble); } template -struct is_complex_type : std::integral_constant< - bool, +struct is_complex_type + : std::integral_constant::value)> {}; constexpr bool isBitsType(::executorch::aten::ScalarType t) { return t == ::executorch::aten::ScalarType::Bits1x8 || - t == ::executorch::aten::ScalarType::Bits2x4 || - t == ::executorch::aten::ScalarType::Bits4x2 || - t == ::executorch::aten::ScalarType::Bits8 || - t == ::executorch::aten::ScalarType::Bits16; + t == ::executorch::aten::ScalarType::Bits2x4 || + t == ::executorch::aten::ScalarType::Bits4x2 || + t == ::executorch::aten::ScalarType::Bits8 || + t == ::executorch::aten::ScalarType::Bits16; } template @@ -492,10 +482,10 @@ struct is_bits_type constexpr bool isQIntType(::executorch::aten::ScalarType t) { // Don't forget to extend this when adding new QInt types return t == ::executorch::aten::ScalarType::QInt8 || - t == ::executorch::aten::ScalarType::QUInt8 || - t == ::executorch::aten::ScalarType::QInt32 || - t == ::executorch::aten::ScalarType::QUInt4x2 || - t == ::executorch::aten::ScalarType::QUInt2x4; + t == ::executorch::aten::ScalarType::QUInt8 || + t == ::executorch::aten::ScalarType::QInt32 || + t == ::executorch::aten::ScalarType::QUInt4x2 || + t == ::executorch::aten::ScalarType::QUInt2x4; } template @@ -503,162 +493,149 @@ struct is_qint_type : std::integral_constant::value)> { }; -inline ::executorch::aten::ScalarType toQIntType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toQIntType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::Byte: - return ::executorch::aten::ScalarType::QUInt8; - case ::executorch::aten::ScalarType::Char: - return ::executorch::aten::ScalarType::QInt8; - case ::executorch::aten::ScalarType::Int: - return ::executorch::aten::ScalarType::QInt32; - default: - return t; + case ::executorch::aten::ScalarType::Byte: + return ::executorch::aten::ScalarType::QUInt8; + case ::executorch::aten::ScalarType::Char: + return ::executorch::aten::ScalarType::QInt8; + case ::executorch::aten::ScalarType::Int: + return ::executorch::aten::ScalarType::QInt32; + default: + return t; } } -inline ::executorch::aten::ScalarType toUnderlying( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toUnderlying(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::QUInt8: - return ::executorch::aten::ScalarType::Byte; - case ::executorch::aten::ScalarType::QInt8: - return ::executorch::aten::ScalarType::Char; - case ::executorch::aten::ScalarType::QInt32: - return ::executorch::aten::ScalarType::Int; - case ::executorch::aten::ScalarType::QUInt4x2: - return ::executorch::aten::ScalarType::Byte; - case ::executorch::aten::ScalarType::QUInt2x4: - return ::executorch::aten::ScalarType::Byte; - default: - return t; + case ::executorch::aten::ScalarType::QUInt8: + return ::executorch::aten::ScalarType::Byte; + case ::executorch::aten::ScalarType::QInt8: + return ::executorch::aten::ScalarType::Char; + case ::executorch::aten::ScalarType::QInt32: + return ::executorch::aten::ScalarType::Int; + case ::executorch::aten::ScalarType::QUInt4x2: + return ::executorch::aten::ScalarType::Byte; + case ::executorch::aten::ScalarType::QUInt2x4: + return ::executorch::aten::ScalarType::Byte; + default: + return t; } } inline bool isSignedType(::executorch::aten::ScalarType t) { - ET_CHECK_MSG( - !::executorch::runtime::isQIntType(t), - "isSignedType not supported for quantized types like %" PRId8, - static_cast(t)); -#define CASE_SIGNED(ctype, name) \ - case ::executorch::aten::ScalarType::name: \ + ET_CHECK_MSG(!::executorch::runtime::isQIntType(t), + "isSignedType not supported for quantized types like %" PRId8, + static_cast(t)); +#define CASE_SIGNED(ctype, name) \ + case ::executorch::aten::ScalarType::name: \ return std::numeric_limits::is_signed; switch (t) { - case ::executorch::aten::ScalarType::ComplexHalf: - case ::executorch::aten::ScalarType::ComplexFloat: - case ::executorch::aten::ScalarType::ComplexDouble: - return true; - ET_FORALL_REAL_TYPES_AND3(Half, Bool, BFloat16, CASE_SIGNED) - default: - ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); + case ::executorch::aten::ScalarType::ComplexHalf: + case ::executorch::aten::ScalarType::ComplexFloat: + case ::executorch::aten::ScalarType::ComplexDouble: + return true; + ET_FORALL_REAL_TYPES_AND3(Half, Bool, BFloat16, CASE_SIGNED) + default: + ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); } #undef CASE_SIGNED } -inline bool isUnderlying( - ::executorch::aten::ScalarType type, - ::executorch::aten::ScalarType qtype) { +inline bool isUnderlying(::executorch::aten::ScalarType type, + ::executorch::aten::ScalarType qtype) { return type == ::executorch::runtime::toUnderlying(qtype); } -inline ::executorch::aten::ScalarType toRealValueType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toRealValueType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::ComplexHalf: - return ::executorch::aten::ScalarType::Half; - case ::executorch::aten::ScalarType::ComplexFloat: - return ::executorch::aten::ScalarType::Float; - case ::executorch::aten::ScalarType::ComplexDouble: - return ::executorch::aten::ScalarType::Double; - default: - return t; + case ::executorch::aten::ScalarType::ComplexHalf: + return ::executorch::aten::ScalarType::Half; + case ::executorch::aten::ScalarType::ComplexFloat: + return ::executorch::aten::ScalarType::Float; + case ::executorch::aten::ScalarType::ComplexDouble: + return ::executorch::aten::ScalarType::Double; + default: + return t; } } -inline ::executorch::aten::ScalarType toComplexType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toComplexType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::BFloat16: - // BFloat16 has range equivalent to Float, - // so we map it to ComplexFloat. - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::Half: - return ::executorch::aten::ScalarType::ComplexHalf; - case ::executorch::aten::ScalarType::Float: - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::Double: - return ::executorch::aten::ScalarType::ComplexDouble; - case ::executorch::aten::ScalarType::ComplexHalf: - return ::executorch::aten::ScalarType::ComplexHalf; - case ::executorch::aten::ScalarType::ComplexFloat: - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::ComplexDouble: - return ::executorch::aten::ScalarType::ComplexDouble; - default: - ET_CHECK_MSG( - false, - "Unknown Complex ScalarType for %" PRId8, - static_cast(t)); + case ::executorch::aten::ScalarType::BFloat16: + // BFloat16 has range equivalent to Float, + // so we map it to ComplexFloat. + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::Half: + return ::executorch::aten::ScalarType::ComplexHalf; + case ::executorch::aten::ScalarType::Float: + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::Double: + return ::executorch::aten::ScalarType::ComplexDouble; + case ::executorch::aten::ScalarType::ComplexHalf: + return ::executorch::aten::ScalarType::ComplexHalf; + case ::executorch::aten::ScalarType::ComplexFloat: + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::ComplexDouble: + return ::executorch::aten::ScalarType::ComplexDouble; + default: + ET_CHECK_MSG(false, "Unknown Complex ScalarType for %" PRId8, + static_cast(t)); } } /** * Encodes type casting rules that are consistent with ATen behaviour. */ -inline constexpr bool canCast( - const ::executorch::aten::ScalarType from, - const ::executorch::aten::ScalarType to) { +inline constexpr bool canCast(const ::executorch::aten::ScalarType from, + const ::executorch::aten::ScalarType to) { // Disallow complex -> non-complex return !(::executorch::runtime::isComplexType(from) && !::executorch::runtime::isComplexType(to)) && - // Disallow float -> integral - !(::executorch::runtime::isFloatingType(from) && - ::executorch::runtime::isIntegralType(to, /*includeBool=*/false)) && - // Treat bool as a special category. Disallow non-bool -> bool - !(from != ::executorch::aten::ScalarType::Bool && - to == ::executorch::aten::ScalarType::Bool); + // Disallow float -> integral + !(::executorch::runtime::isFloatingType(from) && + ::executorch::runtime::isIntegralType(to, /*includeBool=*/false)) && + // Treat bool as a special category. Disallow non-bool -> bool + !(from != ::executorch::aten::ScalarType::Bool && + to == ::executorch::aten::ScalarType::Bool); } template -struct can_cast : std::integral_constant< - bool, - canCast( - CppTypeToScalarType::value, - CppTypeToScalarType::value)> {}; +struct can_cast + : std::integral_constant::value, + CppTypeToScalarType::value)> {}; /** * When casting from floating point to integral type, if the floating value is * outside the integral type range, then an error is thrown if sanitization is * enabled. To circumvent this, we cast the floating point to int64_t first. */ -template < - typename To, - typename From, - typename std::enable_if< - (std::is_floating_point::value && std::is_integral::value), - int>::type = 0> +template ::value && + std::is_integral::value), + int>::type = 0> To convert(From val) { return static_cast(static_cast(val)); } -template < - typename To, - typename From, - typename std::enable_if< - !(std::is_floating_point::value && std::is_integral::value), - int>::type = 0> +template ::value && + std::is_integral::value), + int>::type = 0> To convert(From val) { return static_cast(val); } namespace internal { -template -struct promote_types_lookup; +template struct promote_types_lookup; -template -struct promote_types_lookup { +template struct promote_types_lookup { using type = T1; }; @@ -689,10 +666,9 @@ using B1 = using BF = typename ScalarTypeToCppType< ::executorch::aten::ScalarType::BFloat16>::type; -#define TABLE_ENTRY(key1, key2, value) \ - template <> \ - struct promote_types_lookup { \ - using type = value; \ +#define TABLE_ENTRY(key1, key2, value) \ + template <> struct promote_types_lookup { \ + using type = value; \ } /* promote_types_lookup is a compile-time-accessible version of the @@ -874,20 +850,18 @@ TABLE_ENTRY(BF, BF, BF); template struct promote_types { - private: - static_assert( - std::is_same::value || - (!is_qint_type::value && !is_qint_type::value), - "promote_types not valid for quantized dtypes"); - static_assert( - std::is_same::value || - (!is_bits_type::value && !is_bits_type::value), - "promote_types not valid for bits dtypes"); +private: + static_assert(std::is_same::value || + (!is_qint_type::value && !is_qint_type::value), + "promote_types not valid for quantized dtypes"); + static_assert(std::is_same::value || + (!is_bits_type::value && !is_bits_type::value), + "promote_types not valid for bits dtypes"); using promoted_type_not_respecting_half_to_float = typename internal::promote_types_lookup::type; - public: +public: using type = typename std::conditional< half_to_float && (std::is_same< @@ -908,10 +882,9 @@ struct promote_types { * If half_to_float is set to true, then half and bfloat16 will be promoted to * float instead */ -inline ::executorch::aten::ScalarType promoteTypes( - ::executorch::aten::ScalarType a, - ::executorch::aten::ScalarType b, - bool half_to_float = false) { +inline ::executorch::aten::ScalarType +promoteTypes(::executorch::aten::ScalarType a, ::executorch::aten::ScalarType b, + bool half_to_float = false) { // This is generated according to NumPy's promote_types constexpr auto u1 = ::executorch::aten::ScalarType::Byte; constexpr auto i1 = ::executorch::aten::ScalarType::Char; @@ -948,12 +921,12 @@ inline ::executorch::aten::ScalarType promoteTypes( // 12 types are handled by this function, see the constexpr definitions above const int NUM_PROMOTE_TYPES = 13; - static constexpr std:: - array - dtype2index = {{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1, - }}; + static constexpr std::array + dtype2index = {{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1, + }}; auto ix_a = dtype2index[(int)a]; ET_CHECK(ix_a != -1); auto ix_b = dtype2index[(int)b]; @@ -997,200 +970,197 @@ inline ::executorch::aten::ScalarType promoteTypes( // #ifdef ET_INTERNAL_CHECK_SELECTIVE_BUILD -#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ - case enum_type: { \ - ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type); \ - using CTYPE_ALIAS = \ - ::executorch::runtime::ScalarTypeToCppType::type; \ - return __VA_ARGS__(); \ +#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ + case enum_type: { \ + ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type); \ + using CTYPE_ALIAS = \ + ::executorch::runtime::ScalarTypeToCppType::type; \ + return __VA_ARGS__(); \ } #else -#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ - case enum_type: { \ - using CTYPE_ALIAS = \ - ::executorch::runtime::ScalarTypeToCppType::type; \ - return __VA_ARGS__(); \ +#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ + case enum_type: { \ + using CTYPE_ALIAS = \ + ::executorch::runtime::ScalarTypeToCppType::type; \ + return __VA_ARGS__(); \ } #endif -#define ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, ...) \ - [&] { \ - const auto& _st = TYPE; \ - constexpr const char* et_switch_name = NAME; \ - (void)et_switch_name; /* Suppress unused var */ \ - switch (_st) { \ - __VA_ARGS__ \ - default: \ - ET_CHECK_MSG( \ - false, \ - "Unhandled dtype %s for %s", \ - ::executorch::runtime::toString(_st), \ - et_switch_name); \ - } \ +#define ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, ...) \ + [&] { \ + const auto &_st = TYPE; \ + constexpr const char *et_switch_name = NAME; \ + (void)et_switch_name; /* Suppress unused var */ \ + switch (_st) { \ + __VA_ARGS__ \ + default: \ + ET_CHECK_MSG(false, "Unhandled dtype %s for %s", \ + ::executorch::runtime::toString(_st), et_switch_name); \ + } \ }() #define ET_INTERNAL_SWITCH_CASE_ALL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Half, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexHalf, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexFloat, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexDouble, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::BFloat16, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt2x4, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits1x8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits2x4, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits16, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ - ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL3, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ - ADDITIONAL1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt2x4, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexFloat, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexDouble, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Half, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexHalf, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexFloat, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexDouble, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::BFloat16, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt2x4, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits1x8, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits2x4, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits16, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL1, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3(ADDITIONAL1, ADDITIONAL2, \ + ADDITIONAL3, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL3, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt2x4, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexFloat, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexDouble, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) // // Switch case macros @@ -1228,188 +1198,137 @@ inline ::executorch::aten::ScalarType promoteTypes( // used to alias the ctype associated with the ScalarType that is being handled. // -#define ET_SWITCH_ALL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_ALL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_ALL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REAL_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_REAL_TYPES_AND3( \ - ADDITIONAL1, \ - ADDITIONAL2, \ - ADDITIONAL3, \ - TYPE, \ - CONTEXT, \ - NAME, \ - CTYPE_ALIAS, \ - ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ +#define ET_SWITCH_REAL_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, \ + NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ + ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_REAL_TYPES_AND3(ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, TYPE, \ + CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REALH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_REALH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_REAL_TYPES_AND(Half, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_REALHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND2( \ - Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND2(Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_REALB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_REALB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_REAL_TYPES_AND(Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_REALHB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND2( \ - Half, Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND2(Half, Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_REALHBBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND3( \ - Half, Bool, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHBBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND3(Half, Bool, BFloat16, TYPE, CONTEXT, NAME, \ + CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_INT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_INT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_INT_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOAT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_INT_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOAT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_FLOAT_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOATH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_FLOAT_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOAT_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, \ + NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ + ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOATH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_FLOAT_TYPES_AND(Half, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_FLOATHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_FLOAT_TYPES_AND2( \ - Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_FLOATHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_FLOAT_TYPES_AND2(Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_QINT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_QINT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_COMPLEX_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_COMPLEX_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_SCALAR_OBJ_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_SCALAR_OBJ_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, __VA_ARGS__)) #define ET_SWITCH_SCALAR_OBJ_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) #define ET_SWITCH_SCALAR_OBJ_INTB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_SCALAR_OBJ_FLOATB_TYPES( \ - TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES( \ - CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_TWO_TYPES(T1, T2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_THREE_TYPES( \ - T1, T2, T3, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T3, \ - CTYPE_ALIAS, \ - __VA_ARGS__)) +#define ET_SWITCH_SCALAR_OBJ_FLOATB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES( \ + CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_TWO_TYPES(T1, T2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T2, \ + CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_THREE_TYPES(T1, T2, T3, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T3, \ + CTYPE_ALIAS, __VA_ARGS__)) } // namespace runtime } // namespace executorch @@ -1418,7 +1337,7 @@ namespace executorch { namespace aten { #ifdef USE_ATEN_LIB using ::at::elementSize; -#else // USE_ATEN_LIB +#else // USE_ATEN_LIB using ::executorch::runtime::elementSize; #endif // USE_ATEN_LIB } // namespace aten diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h index eb57f3e0..935f9f5c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h @@ -9,7 +9,7 @@ #pragma once #include -#include // std::array +#include // std::array #include // PRId64 #include #include // size_t @@ -30,28 +30,22 @@ #define ET_NORMALIZE_IX(IX, UPPER_BOUND) IX < 0 ? IX + UPPER_BOUND : IX -#define ET_CHECK_VALID_IX(IX, UPPER_BOUND) \ - ET_CHECK_MSG( \ - IX >= -static_cast(UPPER_BOUND) && \ - IX < static_cast(UPPER_BOUND), \ - "index %" PRId64 " must be within range [-%zd, %zd)", \ - IX, \ - UPPER_BOUND, \ - UPPER_BOUND) - -#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \ - ET_CHECK_MSG( \ - DIM >= -static_cast(UPPER_BOUND) && \ - DIM < static_cast(UPPER_BOUND), \ - "dim %" PRId64 " must be within range [-%zd, %zd)", \ - DIM, \ - UPPER_BOUND, \ - UPPER_BOUND) - -#define ET_CHECK_NON_ZERO_DIM_SIZE(DIM, T) \ - const size_t udim = ET_NORMALIZE_IX(DIM, T.dim()); \ - ET_CHECK_MSG( \ - T.size(udim) != 0, "Expected dim %zd to have non-zero size.", udim); +#define ET_CHECK_VALID_IX(IX, UPPER_BOUND) \ + ET_CHECK_MSG(IX >= -static_cast(UPPER_BOUND) && \ + IX < static_cast(UPPER_BOUND), \ + "index %" PRId64 " must be within range [-%zd, %zd)", IX, \ + UPPER_BOUND, UPPER_BOUND) + +#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \ + ET_CHECK_MSG(DIM >= -static_cast(UPPER_BOUND) && \ + DIM < static_cast(UPPER_BOUND), \ + "dim %" PRId64 " must be within range [-%zd, %zd)", DIM, \ + UPPER_BOUND, UPPER_BOUND) + +#define ET_CHECK_NON_ZERO_DIM_SIZE(DIM, T) \ + const size_t udim = ET_NORMALIZE_IX(DIM, T.dim()); \ + ET_CHECK_MSG(T.size(udim) != 0, "Expected dim %zd to have non-zero size.", \ + udim); /** * Asserts that all tensors have the same shape. @@ -60,91 +54,72 @@ * iterating over the dimensions we make sure that we pick the smallest * dimension of all the tensors as the upper bound for the for loop. */ -#define ET_CHECK_SAME_SHAPE2(a__, b__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1) || (a_dim__ == b_dim__)), \ - ET_TENSOR_CHECK_PREFIX__ ": numel={%zu, %zu}, dim={%zu, %zu}", \ - a_numel__, \ - b_numel__, \ - a_dim__, \ - b_dim__); \ - for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE2(a__, b__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + ET_CHECK_MSG( \ + a_numel__ == b_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1) || (a_dim__ == b_dim__)), \ + ET_TENSOR_CHECK_PREFIX__ ": numel={%zu, %zu}, dim={%zu, %zu}", \ + a_numel__, b_numel__, a_dim__, b_dim__); \ + for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ + dim__, a_size__, b_size__); \ + } \ }) -#define ET_CHECK_SAME_SHAPE3(a__, b__, c__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t c_numel__ = (c__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const size_t c_dim__ = (c__).dim(); \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ - a_dim__ == b_dim__ && b_dim__ == c_dim__), \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}", \ - a_numel__, \ - b_numel__, \ - c_numel__, \ - a_dim__, \ - b_dim__, \ - c_dim__); \ - for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ - ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - size_t c_size__ = (c__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__ && b_size__ == c_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__, \ - c_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE3(a__, b__, c__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t c_numel__ = (c__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const size_t c_dim__ = (c__).dim(); \ + ET_CHECK_MSG(a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ + a_dim__ == b_dim__ && b_dim__ == c_dim__), \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}", \ + a_numel__, b_numel__, c_numel__, a_dim__, b_dim__, c_dim__); \ + for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ + ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + size_t c_size__ = (c__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__ && b_size__ == c_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ + dim__, a_size__, b_size__, c_size__); \ + } \ }) /// Asserts that all tensors have the same dtype. -#define ET_CHECK_SAME_DTYPE2(a__, b__) \ - ({ \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - ET_CHECK_MSG( \ - a_type__ == b_type__, \ - ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 "}", \ - static_cast(a_type__), \ - static_cast(b_type__)); \ +#define ET_CHECK_SAME_DTYPE2(a__, b__) \ + ({ \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + ET_CHECK_MSG(a_type__ == b_type__, \ + ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 "}", \ + static_cast(a_type__), \ + static_cast(b_type__)); \ }) -#define ET_CHECK_SAME_DTYPE3(a__, b__, c__) \ - ({ \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ - ET_CHECK_MSG( \ - a_type__ == b_type__ && b_type__ == c_type__, \ - ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 ", %" PRId8 \ - "}", \ - static_cast(a_type__), \ - static_cast(b_type__), \ - static_cast(c_type__)); \ +#define ET_CHECK_SAME_DTYPE3(a__, b__, c__) \ + ({ \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ + ET_CHECK_MSG(a_type__ == b_type__ && b_type__ == c_type__, \ + ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 \ + ", %" PRId8 "}", \ + static_cast(a_type__), static_cast(b_type__), \ + static_cast(c_type__)); \ }) /** @@ -153,108 +128,85 @@ * This macro should produce less code/data than calling the SHAPE and DTYPE * macros independently, because it only calls ET_CHECK_MSG once. */ -#define ET_CHECK_SAME_SHAPE_AND_DTYPE2(a__, b__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1) || a_dim__ == b_dim__) && \ - a_type__ == b_type__, \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu}, dim={%zu, %zu}, dtype={%" PRId8 ", %" PRId8 "}", \ - a_numel__, \ - b_numel__, \ - a_dim__, \ - b_dim__, \ - static_cast(a_type__), \ - static_cast(b_type__)); \ - for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE_AND_DTYPE2(a__, b__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + \ + ET_CHECK_MSG( \ + a_numel__ == b_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1) || a_dim__ == b_dim__) && \ + a_type__ == b_type__, \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu}, dim={%zu, %zu}, dtype={%" PRId8 ", %" PRId8 "}", \ + a_numel__, b_numel__, a_dim__, b_dim__, static_cast(a_type__), \ + static_cast(b_type__)); \ + for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ + dim__, a_size__, b_size__); \ + } \ }) -#define ET_CHECK_SAME_SHAPE_AND_DTYPE3(a__, b__, c__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t c_numel__ = (c__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const size_t c_dim__ = (c__).dim(); \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ - \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ - (a_dim__ == b_dim__ && b_dim__ == c_dim__)) && \ - a_type__ == b_type__ && b_type__ == c_type__, \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}, " \ - "dtype={%" PRId8 ", %" PRId8 ", %" PRId8 "}", \ - a_numel__, \ - b_numel__, \ - c_numel__, \ - a_dim__, \ - b_dim__, \ - c_dim__, \ - static_cast(a_type__), \ - static_cast(b_type__), \ - static_cast(c_type__)); \ - for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ - ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - size_t c_size__ = (c__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__ && b_size__ == c_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__, \ - c_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE_AND_DTYPE3(a__, b__, c__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t c_numel__ = (c__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const size_t c_dim__ = (c__).dim(); \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ + \ + ET_CHECK_MSG(a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ + (a_dim__ == b_dim__ && b_dim__ == c_dim__)) && \ + a_type__ == b_type__ && b_type__ == c_type__, \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}, " \ + "dtype={%" PRId8 ", %" PRId8 ", %" PRId8 "}", \ + a_numel__, b_numel__, c_numel__, a_dim__, b_dim__, c_dim__, \ + static_cast(a_type__), static_cast(b_type__), \ + static_cast(c_type__)); \ + for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ + ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + size_t c_size__ = (c__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__ && b_size__ == c_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ + dim__, a_size__, b_size__, c_size__); \ + } \ }) /** * Assert that the input tensor is contiguous tensor. */ -#define ET_CHECK_CONTIGUOUS(a__) \ - ({ \ - const ::executorch::aten::ArrayRef \ - strides = a__.strides(); \ - const ::executorch::aten::ArrayRef sizes = \ - a__.sizes(); \ - ET_CHECK_MSG( \ - strides[strides.size() - 1] == 1, \ - "The stride of the last dimension shall be 1 for contiguous tensor, " \ - "not %d", \ - strides[strides.size() - 1]); \ - for (size_t i = strides.size() - 1; i > 0; i--) { \ - ET_CHECK_MSG( \ - strides[i - 1] == strides[i] * sizes[i], \ - "The stride of the %zu-th dimension shall equal to " \ - "strides[%zu] * sizes[%zu], now is %d and %d", \ - i - 1, \ - i, \ - i, \ - strides[i - 1], \ - strides[i] * sizes[i]); \ - } \ +#define ET_CHECK_CONTIGUOUS(a__) \ + ({ \ + const ::executorch::aten::ArrayRef \ + strides = a__.strides(); \ + const ::executorch::aten::ArrayRef sizes = \ + a__.sizes(); \ + ET_CHECK_MSG( \ + strides[strides.size() - 1] == 1, \ + "The stride of the last dimension shall be 1 for contiguous tensor, " \ + "not %d", \ + strides[strides.size() - 1]); \ + for (size_t i = strides.size() - 1; i > 0; i--) { \ + ET_CHECK_MSG(strides[i - 1] == strides[i] * sizes[i], \ + "The stride of the %zu-th dimension shall equal to " \ + "strides[%zu] * sizes[%zu], now is %d and %d", \ + i - 1, i, i, strides[i - 1], strides[i] * sizes[i]); \ + } \ }) /** @@ -267,21 +219,16 @@ ET_CHECK_MSG( \ a__.dim() == b__.dim(), \ "Two tensors shall have same number of strides, but not %zu and %zu.", \ - a__.dim(), \ - b__.dim()); \ + a__.dim(), b__.dim()); \ const ::executorch::aten::ArrayRef \ a_strides = a__.strides(); \ const ::executorch::aten::ArrayRef \ b_strides = b__.strides(); \ for (size_t i = 0; i < a__.dim(); i++) { \ - ET_CHECK_MSG( \ - a_strides[i] == b_strides[i], \ - "a.strides()[%zu] shall equal to b.strides()[%zu], " \ - "but now is %d and %d.", \ - i, \ - i, \ - (int32_t)a_strides[i], \ - (int32_t)b_strides[i]); \ + ET_CHECK_MSG(a_strides[i] == b_strides[i], \ + "a.strides()[%zu] shall equal to b.strides()[%zu], " \ + "but now is %d and %d.", \ + i, i, (int32_t)a_strides[i], (int32_t)b_strides[i]); \ } \ }) @@ -290,43 +237,35 @@ * Noted that this function does not make any check or promise on the contiguity * of any input tensors. */ -#define ET_CHECK_SAME_STRIDES3(a__, b__, c__) \ - ({ \ - ET_CHECK_MSG( \ - a__.dim() == b__.dim() && b__.dim() == c__.dim(), \ - "Three tensors shall have same number of strides, " \ - "but not %zu, %zu and %zu.", \ - a__.dim(), \ - b__.dim(), \ - c__.dim()); \ - const ::executorch::aten::ArrayRef \ - a_strides = a__.strides(); \ - const ::executorch::aten::ArrayRef \ - b_strides = b__.strides(); \ - const ::executorch::aten::ArrayRef \ - c_strides = c__.strides(); \ - for (size_t i = 0; i < a__.dim(); i++) { \ - ET_CHECK_MSG( \ - a_strides[i] == b_strides[i] && b_strides[i] == c_strides[i], \ - "a_strides[%zu], b_strides[%zu] and c_strides[%zu] " \ - "shall share same value, but now is %d, %d and %d", \ - i, \ - i, \ - i, \ - (int32_t)a_strides[i], \ - (int32_t)b_strides[i], \ - (int32_t)c_strides[i]); \ - } \ +#define ET_CHECK_SAME_STRIDES3(a__, b__, c__) \ + ({ \ + ET_CHECK_MSG(a__.dim() == b__.dim() && b__.dim() == c__.dim(), \ + "Three tensors shall have same number of strides, " \ + "but not %zu, %zu and %zu.", \ + a__.dim(), b__.dim(), c__.dim()); \ + const ::executorch::aten::ArrayRef \ + a_strides = a__.strides(); \ + const ::executorch::aten::ArrayRef \ + b_strides = b__.strides(); \ + const ::executorch::aten::ArrayRef \ + c_strides = c__.strides(); \ + for (size_t i = 0; i < a__.dim(); i++) { \ + ET_CHECK_MSG(a_strides[i] == b_strides[i] && \ + b_strides[i] == c_strides[i], \ + "a_strides[%zu], b_strides[%zu] and c_strides[%zu] " \ + "shall share same value, but now is %d, %d and %d", \ + i, i, i, (int32_t)a_strides[i], (int32_t)b_strides[i], \ + (int32_t)c_strides[i]); \ + } \ }) -#define ET_CHECK_DEFAULT_OR_CHANNELSLAST_DIMORDER(t__) \ - ({ \ - ET_CHECK_MSG( \ - is_contiguous_dim_order( \ - t__.dim_order().data(), t__.dim_order().size()) || \ - is_channels_last_dim_order( \ - t__.dim_order().data(), t__.dim_order().size()), \ - "Tensor must have default or channels last dim order"); \ +#define ET_CHECK_DEFAULT_OR_CHANNELSLAST_DIMORDER(t__) \ + ({ \ + ET_CHECK_MSG(is_contiguous_dim_order(t__.dim_order().data(), \ + t__.dim_order().size()) || \ + is_channels_last_dim_order(t__.dim_order().data(), \ + t__.dim_order().size()), \ + "Tensor must have default or channels last dim order"); \ }) /** @@ -336,12 +275,12 @@ * * @param[in] cond the condition to check */ -#define ET_LOG_AND_RETURN_IF_FALSE(cond) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): ", #cond); \ - return false; \ - } \ +#define ET_LOG_AND_RETURN_IF_FALSE(cond) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): ", #cond); \ + return false; \ + } \ } while (false) /** @@ -352,12 +291,12 @@ * @param[in] cond the condition to check * @param[in] message an additional message to log with `cond` */ -#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ - return false; \ - } \ +#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ + return false; \ + } \ } while (false) /** @@ -369,13 +308,13 @@ * @param[in] error torch::executor::Error enum value (e.g `InvalidArgument`) * @param[in] retval return value of the kernel to allow for early exit */ -#define ET_KERNEL_CHECK(context, cond, error, retval) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): ", #cond); \ - context.fail(torch::executor::Error::error); \ - return retval; \ - } \ +#define ET_KERNEL_CHECK(context, cond, error, retval) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): ", #cond); \ + context.fail(torch::executor::Error::error); \ + return retval; \ + } \ } while (false) /** @@ -387,22 +326,21 @@ * @param[in] error torch::executor::Error enum value (e.g `InvalidArgument`) * @param[in] retval return value of the kernel to allow for early exit */ -#define ET_KERNEL_CHECK_MSG(context, cond, error, retval, message, ...) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ - context.fail(torch::executor::Error::error); \ - return retval; \ - } \ +#define ET_KERNEL_CHECK_MSG(context, cond, error, retval, message, ...) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ + context.fail(torch::executor::Error::error); \ + return retval; \ + } \ } while (false) /** * Convenience macro to extract a scalar tensor into a value */ -#define ET_EXTRACT_SCALAR_TENSOR(scalar_tensor, out_val) \ - ET_CHECK_MSG( \ - extract_scalar_tensor(scalar_tensor, &out_val), \ - #scalar_tensor " could not be extracted: wrong type or out of range"); +#define ET_EXTRACT_SCALAR_TENSOR(scalar_tensor, out_val) \ + ET_CHECK_MSG(extract_scalar_tensor(scalar_tensor, &out_val), #scalar_tensor \ + " could not be extracted: wrong type or out of range"); namespace executorch { namespace runtime { @@ -422,9 +360,7 @@ inline bool dim_is_valid(int64_t dim, int64_t upper_bound) { "Dimension %" PRId64 " is out of range. Dimension should be between %" PRId64 " and %" PRId64 ", inclusive.", - dim, - -upper_bound, - upper_bound - 1); + dim, -upper_bound, upper_bound - 1); return true; } @@ -435,7 +371,7 @@ inline bool dim_is_valid(int64_t dim, int64_t upper_bound) { * the zero dimensional tensors in some kernels, that treat them as 1D tensors * with a single element. */ -inline ssize_t nonzero_dim(const executorch::aten::Tensor& tensor) { +inline ssize_t nonzero_dim(const executorch::aten::Tensor &tensor) { return tensor.dim() == 0 ? 1 : tensor.dim(); } @@ -445,15 +381,13 @@ inline ssize_t nonzero_dim(const executorch::aten::Tensor& tensor) { * the zero dimensional tensors in some kernels, that treat them as 1D tensors * with a single element. */ -inline ssize_t nonempty_size( - const executorch::aten::Tensor& tensor, - ssize_t dim) { +inline ssize_t nonempty_size(const executorch::aten::Tensor &tensor, + ssize_t dim) { return tensor.dim() == 0 ? 1 : tensor.size(dim); } -inline bool tensor_can_cast_to( - executorch::aten::Tensor a, - executorch::aten::ScalarType dtype) { +inline bool tensor_can_cast_to(executorch::aten::Tensor a, + executorch::aten::ScalarType dtype) { ET_LOG_MSG_AND_RETURN_IF_FALSE( torch::executor::canCast(a.scalar_type(), dtype), "Tensor of dtype %s cannot cast to dtype %s", @@ -472,9 +406,8 @@ inline bool tensor_is_bool_type(executorch::aten::Tensor t) { return true; } -inline bool tensor_is_type( - executorch::aten::Tensor t, - executorch::aten::ScalarType dtype) { +inline bool tensor_is_type(executorch::aten::Tensor t, + executorch::aten::ScalarType dtype) { ET_LOG_MSG_AND_RETURN_IF_FALSE( t.scalar_type() == dtype, "Expected to find %s type, but tensor has type %s", @@ -484,9 +417,8 @@ inline bool tensor_is_type( return true; } -inline bool tensor_is_integral_type( - executorch::aten::Tensor t, - bool includeBool = false) { +inline bool tensor_is_integral_type(executorch::aten::Tensor t, + bool includeBool = false) { ET_LOG_MSG_AND_RETURN_IF_FALSE( torch::executor::isIntegralType(t.scalar_type(), includeBool), "Expected to find a integral type, but tensor has type %s", @@ -567,21 +499,18 @@ inline bool tensor_is_bits_type(executorch::aten::Tensor t) { return true; } -inline bool tensors_have_same_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { - ET_LOG_MSG_AND_RETURN_IF_FALSE( - a.scalar_type() == b.scalar_type(), - ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s}", - torch::executor::toString(a.scalar_type()), - torch::executor::toString(b.scalar_type())); +inline bool tensors_have_same_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b) { + ET_LOG_MSG_AND_RETURN_IF_FALSE(a.scalar_type() == b.scalar_type(), + ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s}", + torch::executor::toString(a.scalar_type()), + torch::executor::toString(b.scalar_type())); return true; } -inline bool tensors_have_same_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { ET_LOG_MSG_AND_RETURN_IF_FALSE( a.scalar_type() == b.scalar_type() && b.scalar_type() == c.scalar_type(), ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s, %s}", @@ -593,34 +522,26 @@ inline bool tensors_have_same_dtype( inline bool tensor_is_rank(executorch::aten::Tensor t, size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() == rank, - "Expected tensor.dim() to be %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() == rank, "Expected tensor.dim() to be %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } -inline bool tensor_has_rank_greater_or_equal_to( - executorch::aten::Tensor t, - size_t rank) { +inline bool tensor_has_rank_greater_or_equal_to(executorch::aten::Tensor t, + size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() >= rank, - "Expected tensor.dim() to be >= %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() >= rank, "Expected tensor.dim() to be >= %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } -inline bool tensor_has_rank_smaller_or_equal_to( - executorch::aten::Tensor t, - size_t rank) { +inline bool tensor_has_rank_smaller_or_equal_to(executorch::aten::Tensor t, + size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() <= rank, - "Expected tensor.dim() to be <= %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() <= rank, "Expected tensor.dim() to be <= %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } @@ -628,15 +549,13 @@ inline bool tensor_has_rank_smaller_or_equal_to( inline bool tensor_has_dim(executorch::aten::Tensor t, int64_t d) { if (t.dim() == 0) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - d == 0 || d == -1, - "dim must be 0 or -1 for 0-dim tensor, got %" PRId64, + d == 0 || d == -1, "dim must be 0 or -1 for 0-dim tensor, got %" PRId64, d); } else { ET_LOG_MSG_AND_RETURN_IF_FALSE( d > 0 ? d < t.dim() : t.dim() + d >= 0, "%zu-dim tensor does not have dim at index %zu", - static_cast(t.dim()), - static_cast(d)); + static_cast(t.dim()), static_cast(d)); } return true; } @@ -648,8 +567,8 @@ inline bool tensor_has_non_empty_dim(executorch::aten::Tensor t, int64_t d) { return true; } -inline bool -tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, int64_t ix) { +inline bool tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, + int64_t ix) { // Indexing ops don't support zero-dim tensors ET_CHECK(t.dim() != 0); if (d < 0) { @@ -660,64 +579,46 @@ tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, int64_t ix) { ET_LOG_MSG_AND_RETURN_IF_FALSE( ix >= -t.size(d) && ix < t.size(d), - "index %" PRId64 " out of range [-%zu,%zu) at dimension %" PRId64 ")", - ix, - static_cast(t.size(d)), - static_cast(t.size(d)), - d); + "index %" PRId64 " out of range [-%zu,%zu) at dimension %" PRId64 ")", ix, + static_cast(t.size(d)), static_cast(t.size(d)), d); return true; } -inline bool tensors_have_same_size_at_dims( - executorch::aten::Tensor a, - size_t dim_a, - executorch::aten::Tensor b, - size_t dim_b) { +inline bool tensors_have_same_size_at_dims(executorch::aten::Tensor a, + size_t dim_a, + executorch::aten::Tensor b, + size_t dim_b) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - dim_a < a.dim(), - "Cannot retrieve dim %zu from tensor with dim %zu", - static_cast(dim_a), - static_cast(a.dim())); + dim_a < a.dim(), "Cannot retrieve dim %zu from tensor with dim %zu", + static_cast(dim_a), static_cast(a.dim())); ET_LOG_MSG_AND_RETURN_IF_FALSE( - dim_b < b.dim(), - "Cannot retrieve dim %zu from tensor with dim %zu", - static_cast(dim_b), - static_cast(b.dim())); + dim_b < b.dim(), "Cannot retrieve dim %zu from tensor with dim %zu", + static_cast(dim_b), static_cast(b.dim())); ET_LOG_MSG_AND_RETURN_IF_FALSE( a.size(dim_a) == b.size(dim_b), ET_TENSOR_CHECK_PREFIX__ ": a.size(%zu) = %zu does not match b.size(%zu) = %zu", - static_cast(dim_a), - static_cast(a.size(dim_a)), - static_cast(dim_b), - static_cast(b.size(dim_b))); + static_cast(dim_a), static_cast(a.size(dim_a)), + static_cast(dim_b), static_cast(b.size(dim_b))); return true; } -inline bool tensors_have_same_shape( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_shape(executorch::aten::Tensor a, + executorch::aten::Tensor b) { if (a.numel() == 1 && b.numel() == 1) { // PyTorch operators treat all scalar tensors as the same shape even if // they have different dims. return true; } if (!(a.sizes() == b.sizes() && a.numel() == b.numel())) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu), dim=(%zu, %zu)", - static_cast(a.numel()), - static_cast(b.numel()), - static_cast(a.dim()), - static_cast(b.dim())); + ET_LOG(Error, + ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu), dim=(%zu, %zu)", + static_cast(a.numel()), static_cast(b.numel()), + static_cast(a.dim()), static_cast(b.dim())); for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(b.size(d))); + ET_LOG(Error, " size(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.size(d)), static_cast(b.size(d))); } return false; @@ -726,10 +627,9 @@ inline bool tensors_have_same_shape( return true; } -inline bool tensors_have_same_shape( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_shape(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { if (a.numel() == 1 && b.numel() == 1 && c.numel() == 1) { // PyTorch operators treat all scalar tensors as the same shape even if // they have different dims. @@ -739,23 +639,16 @@ inline bool tensors_have_same_shape( bool cond2 = (b.sizes() == c.sizes()) && (b.numel() == c.numel()); if (!(cond1 && cond2)) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu, %zu), dim=(%zu, %zu, %zu)", - static_cast(a.numel()), - static_cast(b.numel()), - static_cast(c.numel()), - static_cast(a.dim()), - static_cast(b.dim()), - static_cast(c.dim())); + ET_LOG(Error, + ET_TENSOR_CHECK_PREFIX__ + ": numel=(%zu, %zu, %zu), dim=(%zu, %zu, %zu)", + static_cast(a.numel()), static_cast(b.numel()), + static_cast(c.numel()), static_cast(a.dim()), + static_cast(b.dim()), static_cast(c.dim())); for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(b.size(d)), - static_cast(c.size(d))); + ET_LOG(Error, " size(%zu): (%zu, %zu, %zu)", static_cast(d), + static_cast(a.size(d)), static_cast(b.size(d)), + static_cast(c.size(d))); } return false; @@ -764,16 +657,14 @@ inline bool tensors_have_same_shape( return true; } -inline bool tensors_have_same_shape_and_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_shape_and_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b) { return tensors_have_same_shape(a, b) && tensors_have_same_dtype(a, b); } -inline bool tensors_have_same_shape_and_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_shape_and_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { return tensors_have_same_shape(a, b, c) && tensors_have_same_dtype(a, b, c); } @@ -781,20 +672,15 @@ inline bool tensor_has_expected_size( executorch::aten::Tensor a, executorch::aten::ArrayRef expected_sizes) { if (!(a.sizes() == expected_sizes)) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", - static_cast(a.dim()), - static_cast(expected_sizes.size())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", + static_cast(a.dim()), + static_cast(expected_sizes.size())); size_t a_dim = static_cast(a.dim()); size_t expected_dim = static_cast(expected_sizes.size()); for (size_t d = 0; d < ET_MIN2(a_dim, expected_dim); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(expected_sizes[d])); + ET_LOG(Error, " size(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.size(d)), + static_cast(expected_sizes[d])); } return false; @@ -802,22 +688,15 @@ inline bool tensor_has_expected_size( return true; } -inline bool tensors_have_same_strides( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_strides(executorch::aten::Tensor a, + executorch::aten::Tensor b) { if (a.strides() != b.strides()) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", - static_cast(a.dim()), - static_cast(b.dim())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", + static_cast(a.dim()), static_cast(b.dim())); for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { - ET_LOG( - Error, - " stride(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.strides()[d]), - static_cast(b.strides()[d])); + ET_LOG(Error, " stride(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.strides()[d]), + static_cast(b.strides()[d])); } return false; @@ -825,25 +704,18 @@ inline bool tensors_have_same_strides( return true; } -inline bool tensors_have_same_strides( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_strides(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { if (!(a.strides() == b.strides() && b.strides() == c.strides())) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu, %zu)", - static_cast(a.dim()), - static_cast(b.dim()), - static_cast(c.dim())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu, %zu)", + static_cast(a.dim()), static_cast(b.dim()), + static_cast(c.dim())); for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { - ET_LOG( - Error, - " stride(%zu): (%zu, %zu, %zu)", - static_cast(d), - static_cast(a.strides()[d]), - static_cast(b.strides()[d]), - static_cast(c.strides()[d])); + ET_LOG(Error, " stride(%zu): (%zu, %zu, %zu)", static_cast(d), + static_cast(a.strides()[d]), + static_cast(b.strides()[d]), + static_cast(c.strides()[d])); } return false; @@ -868,23 +740,18 @@ inline bool tensor_is_contiguous(executorch::aten::Tensor t) { strides[i - 1] == strides[i] * sizes[i], "Tensor is not contiguous; the stride of dim %zu should be equal to " "strides[%zu] * sizes[%zu] = %zu, but found %zu", - static_cast(i - 1), - static_cast(i), - static_cast(i), - static_cast(strides[i] * sizes[i]), + static_cast(i - 1), static_cast(i), + static_cast(i), static_cast(strides[i] * sizes[i]), static_cast(strides[i - 1])); } return true; } -inline bool tensors_have_same_rank( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { - ET_LOG_MSG_AND_RETURN_IF_FALSE( - a.dim() == b.dim(), - ET_TENSOR_CHECK_PREFIX__ ": rank={%zd, %zd}", - ssize_t(a.dim()), - ssize_t(b.dim())); +inline bool tensors_have_same_rank(executorch::aten::Tensor a, + executorch::aten::Tensor b) { + ET_LOG_MSG_AND_RETURN_IF_FALSE(a.dim() == b.dim(), + ET_TENSOR_CHECK_PREFIX__ ": rank={%zd, %zd}", + ssize_t(a.dim()), ssize_t(b.dim())); return true; } @@ -903,15 +770,12 @@ inline bool tensor_is_scalar(executorch::aten::Tensor t) { constexpr size_t kTensorDimensionLimit = 16; /// Returns the product of dim[0:dim), not including dim. -inline size_t getLeadingDims( - const executorch::aten::Tensor& tensor, - int64_t dim) { - ET_CHECK_MSG( - dim >= 0 && dim <= tensor.dim(), - "Ending dimension %" PRId64 - " should be in the range [0, tensor.dim() %zd].", - dim, - ssize_t(tensor.dim())); +inline size_t getLeadingDims(const executorch::aten::Tensor &tensor, + int64_t dim) { + ET_CHECK_MSG(dim >= 0 && dim <= tensor.dim(), + "Ending dimension %" PRId64 + " should be in the range [0, tensor.dim() %zd].", + dim, ssize_t(tensor.dim())); size_t dims = 1; for (size_t i = 0; i < dim; ++i) { dims *= static_cast(tensor.size(i)); @@ -920,15 +784,12 @@ inline size_t getLeadingDims( } /// Returns the product of dim[dim+1:]. -inline size_t getTrailingDims( - const executorch::aten::Tensor& tensor, - int64_t dim) { - ET_CHECK_MSG( - dim >= -1 && dim < tensor.dim(), - "Starting dimension %" PRId64 - " should be in the range [-1, tensor.dim() -1 %zd).", - dim, - ssize_t(tensor.dim())); +inline size_t getTrailingDims(const executorch::aten::Tensor &tensor, + int64_t dim) { + ET_CHECK_MSG(dim >= -1 && dim < tensor.dim(), + "Starting dimension %" PRId64 + " should be in the range [-1, tensor.dim() -1 %zd).", + dim, ssize_t(tensor.dim())); size_t dims = 1; for (size_t i = dim + 1; i < tensor.dim(); ++i) { dims *= static_cast(tensor.size(i)); @@ -946,9 +807,8 @@ inline size_t getTrailingDims( * @param[out] index The linear index to element at the specified coordinate * in the tensor. */ -inline size_t coordinateToIndex( - const executorch::aten::Tensor& tensor, - const size_t* const coordinate) { +inline size_t coordinateToIndex(const executorch::aten::Tensor &tensor, + const size_t *const coordinate) { size_t index = 0; for (int d = 0; d < tensor.dim(); ++d) { index += coordinate[d] * getTrailingDims(tensor, d); @@ -961,9 +821,9 @@ inline size_t coordinateToIndex( * coordinateToIndexWithTrailingDimsMemo, which will be faster than * repeated calls to coordinateToIndex. */ -inline void memoizeTrailingDims( - const executorch::aten::Tensor& tensor, - size_t trailing_dims_memo[kTensorDimensionLimit]) { +inline void +memoizeTrailingDims(const executorch::aten::Tensor &tensor, + size_t trailing_dims_memo[kTensorDimensionLimit]) { const auto tensorDim = tensor.dim(); size_t dims = 1; for (int ii = tensorDim - 1; ii >= 0; --ii) { @@ -978,8 +838,7 @@ inline void memoizeTrailingDims( * memoizeTrailingDims. */ inline size_t coordinateToIndexWithTrailingDimsMemo( - const executorch::aten::Tensor& tensor, - const size_t* const coordinate, + const executorch::aten::Tensor &tensor, const size_t *const coordinate, const size_t trailing_dims_memo[kTensorDimensionLimit]) { size_t index = 0; for (int d = 0; d < tensor.dim(); ++d) { @@ -999,10 +858,8 @@ inline size_t coordinateToIndexWithTrailingDimsMemo( * index. It is assumed that the array has kTensorDimensionLimit elements. * @returns void */ -inline void indexToCoordinate( - const executorch::aten::Tensor& tensor, - size_t index, - size_t* coordinate) { +inline void indexToCoordinate(const executorch::aten::Tensor &tensor, + size_t index, size_t *coordinate) { ET_CHECK(index < tensor.numel()); for (auto i = 0; i < tensor.dim(); ++i) { auto dim = tensor.dim() - 1 - i; @@ -1022,30 +879,29 @@ inline void indexToCoordinate( * integer Scalar Tensor, or the value of that Scalar Tensor could not be * represented by INT_T. */ -template < - typename INT_T, - typename std::enable_if< - std::is_integral::value && !std::is_same::value, - bool>::type = true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T* out_val) { +template ::value && + !std::is_same::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T *out_val) { if (tensor.numel() != 1) { return false; } -#define CASE_INT_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ - case executorch::aten::ScalarType::TENSOR_DTYPE: { \ - const TENSOR_CTYPE val = tensor.const_data_ptr()[0]; \ - if (val < std::numeric_limits::lowest() || \ - val > std::numeric_limits::max()) { \ - return false; \ - } \ - *out_val = static_cast(val); \ - return true; \ +#define CASE_INT_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ + case executorch::aten::ScalarType::TENSOR_DTYPE: { \ + const TENSOR_CTYPE val = tensor.const_data_ptr()[0]; \ + if (val < std::numeric_limits::lowest() || \ + val > std::numeric_limits::max()) { \ + return false; \ + } \ + *out_val = static_cast(val); \ + return true; \ } switch (tensor.scalar_type()) { ET_FORALL_INT_TYPES(CASE_INT_DTYPE); - default: - return false; + default: + return false; } #undef CASE_INT_DTYPE } @@ -1060,32 +916,30 @@ bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T* out_val) { * floating point Scalar Tensor, or the value of that Scalar Tensor could not * be represented by FLOAT_T. */ -template < - typename FLOAT_T, - typename std::enable_if::value, bool>:: - type = true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T* out_val) { +template ::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T *out_val) { if (tensor.numel() != 1) { return false; } -#define CASE_REAL_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ - case executorch::aten::ScalarType::TENSOR_DTYPE: { \ - /* ET_FORALL_REAL_TYPES guarantees TENSOR_CTYPE is a real type. */ \ - double val = \ - static_cast(tensor.const_data_ptr()[0]); \ - if (std::isfinite(val) && \ - (val < std::numeric_limits::lowest() || \ - val > std::numeric_limits::max())) { \ - return false; \ - } \ - *out_val = static_cast(val); \ - return true; \ +#define CASE_REAL_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ + case executorch::aten::ScalarType::TENSOR_DTYPE: { \ + /* ET_FORALL_REAL_TYPES guarantees TENSOR_CTYPE is a real type. */ \ + double val = \ + static_cast(tensor.const_data_ptr()[0]); \ + if (std::isfinite(val) && (val < std::numeric_limits::lowest() || \ + val > std::numeric_limits::max())) { \ + return false; \ + } \ + *out_val = static_cast(val); \ + return true; \ } switch (tensor.scalar_type()) { ET_FORALL_REAL_TYPES(CASE_REAL_DTYPE); - default: - return false; + default: + return false; } #undef CASE_REAL_DTYPE } @@ -1098,11 +952,10 @@ bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T* out_val) { * @returns `true` if a value was extracted, and sets `*out_val` to that * value. `false` if a value could not be extracted, i.e. not a boolean */ -template < - typename BOOL_T, - typename std::enable_if::value, bool>::type = - true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, BOOL_T* out_val) { +template ::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, BOOL_T *out_val) { if (tensor.scalar_type() != executorch::aten::ScalarType::Bool) { return false; } @@ -1122,35 +975,31 @@ namespace internal { /** * Share t_src's data_ptr with t_dst. */ -ET_NODISCARD Error share_tensor_data( - const executorch::aten::Tensor& t_dst, - const executorch::aten::Tensor& t_src); +ET_NODISCARD Error share_tensor_data(const executorch::aten::Tensor &t_dst, + const executorch::aten::Tensor &t_src); /** * Copy t_src's data_ptr to t_dst. */ -ET_NODISCARD Error copy_tensor_data( - const executorch::aten::Tensor& t_dst, - const executorch::aten::Tensor& t_src); +ET_NODISCARD Error copy_tensor_data(const executorch::aten::Tensor &t_dst, + const executorch::aten::Tensor &t_src); /** * Set the data_ptr of t to buffer. */ -ET_NODISCARD Error set_tensor_data( - const executorch::aten::Tensor& t, - void* buffer, - size_t buffer_size); +ET_NODISCARD Error set_tensor_data(const executorch::aten::Tensor &t, + void *buffer, size_t buffer_size); /** * Reset tensor's data_ptr, clear all the storage for at::Tensor. */ -void reset_data_ptr(const executorch::aten::Tensor& tensor); +void reset_data_ptr(const executorch::aten::Tensor &tensor); /** * Resize tensor impl */ ET_NODISCARD Error resize_tensor_impl( - executorch::aten::TensorImpl* impl, + executorch::aten::TensorImpl *impl, executorch::aten::ArrayRef new_sizes); } // namespace internal @@ -1179,14 +1028,12 @@ ET_NODISCARD inline Error resize_tensor( * settled, will likely move to be a class method on a TensorResizer object * passed in through runtimeContext. */ -template < - typename T, - typename std::enable_if< - !std::is_same::value, - int>::type = 0> -ET_NODISCARD inline Error resize_tensor( - executorch::aten::Tensor t, - executorch::aten::ArrayRef new_sizes) { +template ::value, + int>::type = 0> +ET_NODISCARD inline Error +resize_tensor(executorch::aten::Tensor t, + executorch::aten::ArrayRef new_sizes) { // Need to cast the input array to an array of Tensor::SizesType std::array new_sizes_casted{}; @@ -1201,12 +1048,12 @@ ET_NODISCARD inline Error resize_tensor( } /// DEPRECATED: Use `resize_tensor()` instead, which can fail non-fatally. -ET_DEPRECATED inline void resize( - executorch::aten::Tensor t, - executorch::aten::ArrayRef new_sizes) { +ET_DEPRECATED inline void +resize(executorch::aten::Tensor t, + executorch::aten::ArrayRef new_sizes) { Error err = resize_tensor(t, new_sizes); - ET_CHECK_MSG( - err == Error::Ok, "Could not resize Tensor; see logs for details"); + ET_CHECK_MSG(err == Error::Ok, + "Could not resize Tensor; see logs for details"); } /** * Get dim_order of a Tensor and write it to out_dim_order. @@ -1215,10 +1062,9 @@ ET_DEPRECATED inline void resize( * dim order into it. * @param out_dim_order_size Size of the DimOrderType array. */ -ET_NODISCARD Error get_dim_order( - const executorch::aten::Tensor& tensor, - executorch::aten::DimOrderType* out_dim_order, - size_t out_dim_order_size); +ET_NODISCARD Error get_dim_order(const executorch::aten::Tensor &tensor, + executorch::aten::DimOrderType *out_dim_order, + size_t out_dim_order_size); /** * Checks whether a tensor has a valid dim order. If the dim order could not @@ -1269,9 +1115,8 @@ bool tensors_have_same_dim_order( * sizes, etc. */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b) { executorch::aten::Tensor tensor_list[2] = {a, b}; return tensors_have_same_dim_order(tensor_list); } @@ -1284,10 +1129,9 @@ inline bool tensors_have_same_dim_order( * */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b, - const executorch::aten::Tensor& c) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b, + const executorch::aten::Tensor &c) { executorch::aten::Tensor tensor_list[3] = {a, b, c}; return tensors_have_same_dim_order(tensor_list); } @@ -1300,11 +1144,10 @@ inline bool tensors_have_same_dim_order( * */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b, - const executorch::aten::Tensor& c, - const executorch::aten::Tensor& d) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b, + const executorch::aten::Tensor &c, + const executorch::aten::Tensor &d) { executorch::aten::Tensor tensor_list[4] = {a, b, c, d}; return tensors_have_same_dim_order(tensor_list); } @@ -1317,10 +1160,10 @@ inline bool tensors_have_same_dim_order( * @param strides Pointer to the array of strides. * @param ndim Number of dimensions in the tensor. */ -inline size_t calculate_linear_index( - const executorch::aten::SizesType* coordinate, - const executorch::aten::StridesType* strides, - const size_t ndim) { +inline size_t +calculate_linear_index(const executorch::aten::SizesType *coordinate, + const executorch::aten::StridesType *strides, + const size_t ndim) { size_t index = 0; for (size_t i = 0; i < ndim; i++) { index += coordinate[i] * strides[i]; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h index a90c8991..09c5efca 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h @@ -17,18 +17,16 @@ namespace runtime { * A read-only buffer than can be freed. */ class FreeableBuffer final { - public: +public: // Callback signature for the function that does the freeing. - using FreeFn = void (*)(void* context, void* data, size_t size); + using FreeFn = void (*)(void *context, void *data, size_t size); /** * Creates an empty FreeableBuffer with size zero and a null data pointer. */ FreeableBuffer() - : free_fn_(nullptr), - free_fn_context_(nullptr), - data_(nullptr), - size_(0) {} + : free_fn_(nullptr), free_fn_context_(nullptr), data_(nullptr), size_(0) { + } /** * Creates a FreeableBuffer with an optional free function. @@ -42,34 +40,25 @@ class FreeableBuffer final { * @param[in] free_fn_context Opaque pointer to pass as the `context` * parameter of `free_fn`. May be nullptr. */ - FreeableBuffer( - const void* data, - size_t size, - FreeFn free_fn, - void* free_fn_context = nullptr) - : free_fn_(free_fn), - free_fn_context_(free_fn_context), - data_(data), + FreeableBuffer(const void *data, size_t size, FreeFn free_fn, + void *free_fn_context = nullptr) + : free_fn_(free_fn), free_fn_context_(free_fn_context), data_(data), size_(size) {} /** * Move ctor. Takes the ownership of the data previously owned by `rhs`, * leaving `rhs` pointing to nullptr. */ - FreeableBuffer(FreeableBuffer&& rhs) noexcept - : free_fn_(rhs.free_fn_), - free_fn_context_(rhs.free_fn_context_), - data_(rhs.data_), - size_(rhs.size_) { + FreeableBuffer(FreeableBuffer &&rhs) noexcept + : free_fn_(rhs.free_fn_), free_fn_context_(rhs.free_fn_context_), + data_(rhs.data_), size_(rhs.size_) { rhs.free_fn_ = nullptr; rhs.free_fn_context_ = nullptr; rhs.data_ = nullptr; rhs.size_ = 0; } - ~FreeableBuffer() { - Free(); - } + ~FreeableBuffer() { Free(); } /** * Frees the data if not already free. Safe to call multiple times. @@ -77,7 +66,7 @@ class FreeableBuffer final { void Free() { if (data_ != nullptr) { if (free_fn_ != nullptr) { - free_fn_(free_fn_context_, const_cast(data_), size_); + free_fn_(free_fn_context_, const_cast(data_), size_); } data_ = nullptr; size_ = 0; @@ -87,26 +76,22 @@ class FreeableBuffer final { /** * Size of the data in bytes. Returns 0 if the data has been freed. */ - size_t size() const { - return size_; - } + size_t size() const { return size_; } /** * Pointer to the data. Returns nullptr if the data has been freed. */ - const void* data() const { - return data_; - } + const void *data() const { return data_; } - private: +private: // Delete other rule-of-five methods. - FreeableBuffer(const FreeableBuffer& rhs) = delete; - FreeableBuffer& operator=(FreeableBuffer&& rhs) noexcept = delete; - FreeableBuffer& operator=(const FreeableBuffer& rhs) = delete; + FreeableBuffer(const FreeableBuffer &rhs) = delete; + FreeableBuffer &operator=(FreeableBuffer &&rhs) noexcept = delete; + FreeableBuffer &operator=(const FreeableBuffer &rhs) = delete; FreeFn free_fn_; - void* free_fn_context_; - const void* data_; + void *free_fn_context_; + const void *data_; size_t size_; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h index b5ba8b04..d894c080 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h @@ -8,13 +8,13 @@ #pragma once +#include #include #include #include #include #include #include -#include namespace executorch { namespace runtime { @@ -23,7 +23,7 @@ namespace runtime { * A group of buffers that can be used to represent a device's memory hierarchy. */ class HierarchicalAllocator final { - public: +public: /** * Constructs a new hierarchical allocator with the given array of buffers. * @@ -38,9 +38,8 @@ class HierarchicalAllocator final { /** * DEPRECATED: Use spans instead. */ - ET_DEPRECATED HierarchicalAllocator( - uint32_t n_allocators, - MemoryAllocator* allocators) + ET_DEPRECATED HierarchicalAllocator(uint32_t n_allocators, + MemoryAllocator *allocators) : buffers_(to_spans(n_allocators, allocators)) {} /** @@ -55,30 +54,22 @@ class HierarchicalAllocator final { * @returns On success, the address of the requested byte offset into the * specified buffer. On failure, a non-Ok Error. */ - ET_NODISCARD Result get_offset_address( - uint32_t memory_id, - size_t offset_bytes, - size_t size_bytes) { - ET_CHECK_OR_RETURN_ERROR( - memory_id < buffers_.size(), - InvalidArgument, - "id %" PRIu32 " >= %zu", - memory_id, - buffers_.size()); + ET_NODISCARD Result get_offset_address(uint32_t memory_id, + size_t offset_bytes, + size_t size_bytes) { + ET_CHECK_OR_RETURN_ERROR(memory_id < buffers_.size(), InvalidArgument, + "id %" PRIu32 " >= %zu", memory_id, + buffers_.size()); Span buffer = buffers_[memory_id]; ET_CHECK_OR_RETURN_ERROR( - offset_bytes + size_bytes <= buffer.size(), - MemoryAllocationFailed, + offset_bytes + size_bytes <= buffer.size(), MemoryAllocationFailed, "offset_bytes (%zu) + size_bytes (%zu) >= allocator size (%zu) " "for memory_id %" PRIu32, - offset_bytes, - size_bytes, - buffer.size(), - memory_id); + offset_bytes, size_bytes, buffer.size(), memory_id); return buffer.data() + offset_bytes; } - private: +private: // TODO(T162089316): Remove the span array and to_spans once all users move to // spans. This array is necessary to hold the pointers and sizes that were // originally provided as MemoryAllocator instances. @@ -86,14 +77,11 @@ class HierarchicalAllocator final { // NOTE: span_array_ must be declared before buffers_ so that it isn't // re-initialized to zeros after initializing buffers_. Span span_array_[kSpanArraySize]; - Span> to_spans( - uint32_t n_allocators, - MemoryAllocator* allocators) { - ET_CHECK_MSG( - n_allocators <= kSpanArraySize, - "n_allocators %" PRIu32 " > %zu", - n_allocators, - kSpanArraySize); + Span> to_spans(uint32_t n_allocators, + MemoryAllocator *allocators) { + ET_CHECK_MSG(n_allocators <= kSpanArraySize, + "n_allocators %" PRIu32 " > %zu", n_allocators, + kSpanArraySize); for (uint32_t i = 0; i < n_allocators; ++i) { span_array_[i] = Span(allocators[i].base_address(), allocators[i].size()); diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h index 5149abda..80bdd150 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h @@ -8,9 +8,9 @@ #pragma once -#include #include #include +#include #include #include @@ -38,13 +38,13 @@ namespace runtime { * allocator.allocate() to keep iterating cur_ pointer */ class MemoryAllocator { - public: +public: /** * Default alignment of memory returned by this class. Ensures that pointer * fields of structs will be aligned. Larger types like `long double` may not * be, however, depending on the toolchain and architecture. */ - static constexpr size_t kDefaultAlignment = alignof(void*); + static constexpr size_t kDefaultAlignment = alignof(void *); /** * Constructs a new memory allocator of a given `size`, starting at the @@ -55,10 +55,8 @@ class MemoryAllocator { * ownership of this buffer, so it must be valid for the lifetime of of * the MemoryAllocator. */ - MemoryAllocator(uint32_t size, uint8_t* base_address) - : begin_(base_address), - end_(base_address + size), - cur_(base_address), + MemoryAllocator(uint32_t size, uint8_t *base_address) + : begin_(base_address), end_(base_address + size), cur_(base_address), size_(size) {} /** @@ -71,7 +69,7 @@ class MemoryAllocator { * @returns Aligned pointer to the allocated memory on success. * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ - virtual void* allocate(size_t size, size_t alignment = kDefaultAlignment) { + virtual void *allocate(size_t size, size_t alignment = kDefaultAlignment) { if (!isPowerOf2(alignment)) { ET_LOG(Error, "Alignment %zu is not a power of 2", alignment); return nullptr; @@ -79,17 +77,16 @@ class MemoryAllocator { // The allocation will occupy [start, end), where the start is the next // position that's a multiple of alignment. - uint8_t* start = alignPointer(cur_, alignment); - uint8_t* end = start + size; + uint8_t *start = alignPointer(cur_, alignment); + uint8_t *end = start + size; // If the end of this allocation exceeds the end of this allocator, print // error messages and return nullptr if (end > end_) { - ET_LOG( - Error, - "Memory allocation failed: %zuB requested (adjusted for alignment), %zuB available", - static_cast(end - cur_), - static_cast(end_ - cur_)); + ET_LOG(Error, + "Memory allocation failed: %zuB requested (adjusted for " + "alignment), %zuB available", + static_cast(end - cur_), static_cast(end_ - cur_)); return nullptr; } @@ -98,7 +95,7 @@ class MemoryAllocator { // instead of (end - start) because start > cur_ if there is a misalignment EXECUTORCH_TRACK_ALLOCATION(prof_id_, end - cur_); cur_ = end; - return static_cast(start); + return static_cast(start); } /** @@ -116,9 +113,8 @@ class MemoryAllocator { * @returns Aligned pointer to the allocated memory on success. * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ - template - T* allocateInstance(size_t alignment = alignof(T)) { - return static_cast(this->allocate(sizeof(T), alignment)); + template T *allocateInstance(size_t alignment = alignof(T)) { + return static_cast(this->allocate(sizeof(T), alignment)); } /** @@ -133,42 +129,34 @@ class MemoryAllocator { * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ template - T* allocateList(size_t size, size_t alignment = alignof(T)) { + T *allocateList(size_t size, size_t alignment = alignof(T)) { // Some users of this method allocate lists of pointers, causing the next // line to expand to `sizeof(type *)`, which triggers a clang-tidy warning. // NOLINTNEXTLINE(bugprone-sizeof-expression) - return static_cast(this->allocate(size * sizeof(T), alignment)); + return static_cast(this->allocate(size * sizeof(T), alignment)); } // Returns the allocator memory's base address. - virtual uint8_t* base_address() const { - return begin_; - } + virtual uint8_t *base_address() const { return begin_; } // Returns the total size of the allocator's memory buffer. - virtual uint32_t size() const { - return size_; - } + virtual uint32_t size() const { return size_; } // Resets the current pointer to the base address. It does nothing to // the contents. - virtual void reset() { - cur_ = begin_; - } + virtual void reset() { cur_ = begin_; } - void enable_profiling(ET_UNUSED const char* name) { + void enable_profiling(ET_UNUSED const char *name) { prof_id_ = EXECUTORCH_TRACK_ALLOCATOR(name); } virtual ~MemoryAllocator() {} - protected: +protected: /** * Returns the profiler ID for this allocator. */ - int32_t prof_id() const { - return prof_id_; - } + int32_t prof_id() const { return prof_id_; } /** * Returns true if the value is an integer power of 2. @@ -180,20 +168,20 @@ class MemoryAllocator { /** * Returns the next alignment for a given pointer. */ - static uint8_t* alignPointer(void* ptr, size_t alignment) { + static uint8_t *alignPointer(void *ptr, size_t alignment) { intptr_t addr = reinterpret_cast(ptr); if ((addr & (alignment - 1)) == 0) { // Already aligned. - return reinterpret_cast(ptr); + return reinterpret_cast(ptr); } addr = (addr | (alignment - 1)) + 1; - return reinterpret_cast(addr); + return reinterpret_cast(addr); } - private: - uint8_t* const begin_; - uint8_t* const end_; - uint8_t* cur_; +private: + uint8_t *const begin_; + uint8_t *const end_; + uint8_t *cur_; uint32_t const size_; int32_t prof_id_ = -1; }; @@ -214,15 +202,15 @@ class MemoryAllocator { * }); * @endcode */ -#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ - ({ \ - void* et_try_allocate_result = memory_allocator__->allocate(nbytes__); \ - if (et_try_allocate_result == nullptr && nbytes__ > 0) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ + ({ \ + void *et_try_allocate_result = memory_allocator__->allocate(nbytes__); \ + if (et_try_allocate_result == nullptr && nbytes__ > 0) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) /** @@ -240,16 +228,16 @@ class MemoryAllocator { * { *out_err = Error::MemoryAllocationFailed; return nullopt; }); * @endcode */ -#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ - ({ \ - type__* et_try_allocate_result = \ - memory_allocator__->allocateInstance(); \ - if (et_try_allocate_result == nullptr) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ + ({ \ + type__ *et_try_allocate_result = \ + memory_allocator__->allocateInstance(); \ + if (et_try_allocate_result == nullptr) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) /** @@ -268,16 +256,16 @@ class MemoryAllocator { * }); * @endcode */ -#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ - ({ \ - type__* et_try_allocate_result = \ - memory_allocator__->allocateList(nelem__); \ - if (et_try_allocate_result == nullptr && nelem__ > 0) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ + ({ \ + type__ *et_try_allocate_result = \ + memory_allocator__->allocateList(nelem__); \ + if (et_try_allocate_result == nullptr && nelem__ > 0) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) #else // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS /** @@ -285,10 +273,8 @@ class MemoryAllocator { * is to directly allocate the memory. * e.g. memory_allocator__->allocate(nbytes__); */ -#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_OR uses statement expressions and \ +#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_OR uses statement expressions and \ thus is not available for use with this compiler."); /** @@ -296,10 +282,8 @@ class MemoryAllocator { * is to directly allocate the memory. * e.g. memory_allocator__->allocateInstance(); */ -#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_INSTANCE_OR uses statement \ +#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_INSTANCE_OR uses statement \ expressions and thus is not available for use with this compiler."); /** @@ -307,10 +291,8 @@ class MemoryAllocator { * is to directly use allocate the memory. * e.g. memory_allocator__->allocateList(nelem__); */ -#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_LIST_OR uses statement \ +#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_LIST_OR uses statement \ expressions and thus is not available for use with this compiler."); #endif // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS @@ -326,9 +308,9 @@ class MemoryAllocator { * char* buf = ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator, bufsize); * @endcode */ -#define ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator__, nbytes__) \ - ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator__, nbytes__) \ + ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -344,9 +326,9 @@ class MemoryAllocator { * char* buf = ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator, MyType); * @endcode */ -#define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator__, type__) \ - ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator__, type__) \ + ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -363,9 +345,9 @@ class MemoryAllocator { * memory_allocator, Tensor, num_tensors); * @endcode */ -#define ET_ALLOCATE_LIST_OR_RETURN_ERROR(memory_allocator__, type__, nelem__) \ - ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_LIST_OR_RETURN_ERROR(memory_allocator__, type__, nelem__) \ + ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h index c1ff2508..2ae42a8e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h @@ -50,76 +50,70 @@ struct alignas(2) BFloat16 { BFloat16() = default; struct from_bits_t {}; - static constexpr from_bits_t from_bits() { - return from_bits_t(); - } + static constexpr from_bits_t from_bits() { return from_bits_t(); } constexpr BFloat16(unsigned short bits, from_bits_t) : x(bits) {} /* implicit */ BFloat16(float value) : x(internal::round_to_nearest_even(value)) {} - operator float() const { - return internal::f32_from_bits(x); - } + operator float() const { return internal::f32_from_bits(x); } }; -inline std::ostream& operator<<(std::ostream& out, const BFloat16& value) { +inline std::ostream &operator<<(std::ostream &out, const BFloat16 &value) { out << (float)value; return out; } /// Arithmetic -inline BFloat16 operator+(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator+(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) + static_cast(b); } -inline BFloat16 operator-(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator-(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) - static_cast(b); } -inline BFloat16 operator*(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator*(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) * static_cast(b); } -inline BFloat16 operator/(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator/(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) / static_cast(b); } -inline BFloat16 operator-(const BFloat16& a) { - return -static_cast(a); -} +inline BFloat16 operator-(const BFloat16 &a) { return -static_cast(a); } -inline BFloat16& operator+=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator+=(BFloat16 &a, const BFloat16 &b) { a = a + b; return a; } -inline BFloat16& operator-=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator-=(BFloat16 &a, const BFloat16 &b) { a = a - b; return a; } -inline BFloat16& operator*=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator*=(BFloat16 &a, const BFloat16 &b) { a = a * b; return a; } -inline BFloat16& operator/=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator/=(BFloat16 &a, const BFloat16 &b) { a = a / b; return a; } -inline BFloat16& operator|(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator|(BFloat16 &a, const BFloat16 &b) { a.x = a.x | b.x; return a; } -inline BFloat16& operator^(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator^(BFloat16 &a, const BFloat16 &b) { a.x = a.x ^ b.x; return a; } -inline BFloat16& operator&(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator&(BFloat16 &a, const BFloat16 &b) { a.x = a.x & b.x; return a; } @@ -152,16 +146,16 @@ inline float operator/(float a, BFloat16 b) { return a / static_cast(b); } -inline float& operator+=(float& a, const BFloat16& b) { +inline float &operator+=(float &a, const BFloat16 &b) { return a += static_cast(b); } -inline float& operator-=(float& a, const BFloat16& b) { +inline float &operator-=(float &a, const BFloat16 &b) { return a -= static_cast(b); } -inline float& operator*=(float& a, const BFloat16& b) { +inline float &operator*=(float &a, const BFloat16 &b) { return a *= static_cast(b); } -inline float& operator/=(float& a, const BFloat16& b) { +inline float &operator/=(float &a, const BFloat16 &b) { return a /= static_cast(b); } @@ -251,11 +245,11 @@ inline BFloat16 operator/(int64_t a, BFloat16 b) { // Overloading < and > operators, because std::max and std::min use them. -inline bool operator>(BFloat16& lhs, BFloat16& rhs) { +inline bool operator>(BFloat16 &lhs, BFloat16 &rhs) { return float(lhs) > float(rhs); } -inline bool operator<(BFloat16& lhs, BFloat16& rhs) { +inline bool operator<(BFloat16 &lhs, BFloat16 &rhs) { return float(lhs) < float(rhs); } @@ -273,9 +267,8 @@ using ::executorch::runtime::etensor::BFloat16; namespace std { -template <> -class numeric_limits { - public: +template <> class numeric_limits { +public: static constexpr bool is_signed = true; static constexpr bool is_specialized = true; static constexpr bool is_integer = false; @@ -303,40 +296,40 @@ class numeric_limits { numeric_limits::tinyness_before; static constexpr torch::executor::BFloat16 min() { - return torch::executor::BFloat16( - 0x0080, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x0080, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 lowest() { - return torch::executor::BFloat16( - 0xFF7F, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0xFF7F, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 max() { - return torch::executor::BFloat16( - 0x7F7F, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F7F, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 epsilon() { - return torch::executor::BFloat16( - 0x3C00, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x3C00, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 round_error() { - return torch::executor::BFloat16( - 0x3F00, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x3F00, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 infinity() { - return torch::executor::BFloat16( - 0x7F80, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F80, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 quiet_NaN() { - return torch::executor::BFloat16( - 0x7FC0, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7FC0, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 signaling_NaN() { - return torch::executor::BFloat16( - 0x7F80, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F80, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 denorm_min() { - return torch::executor::BFloat16( - 0x0001, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x0001, + torch::executor::BFloat16::from_bits()); } }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h index 68ee77cf..3f6fd400 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h @@ -16,196 +16,164 @@ namespace std { template struct is_reduced_floating_point : std::integral_constant< - bool, - std::is_same::value || - std::is_same::value> {}; + bool, std::is_same::value || + std::is_same::value> {}; -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T acos(T a) { return std::acos(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T asin(T a) { return std::asin(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T atan(T a) { return std::atan(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T atanh(T a) { return std::atanh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T erf(T a) { return std::erf(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T erfc(T a) { return std::erfc(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T exp(T a) { return std::exp(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T expm1(T a) { return std::expm1(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline bool isfinite(T a) { return std::isfinite(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log(T a) { return std::log(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log10(T a) { return std::log10(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log1p(T a) { return std::log1p(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log2(T a) { return std::log2(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T ceil(T a) { return std::ceil(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T cos(T a) { return std::cos(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T floor(T a) { return std::floor(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T nearbyint(T a) { return std::nearbyint(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sin(T a) { return std::sin(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T tan(T a) { return std::tan(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sinh(T a) { return std::sinh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T cosh(T a) { return std::cosh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T tanh(T a) { return std::tanh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T trunc(T a) { return std::trunc(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T lgamma(T a) { return std::lgamma(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sqrt(T a) { return std::sqrt(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T rsqrt(T a) { return 1.0 / std::sqrt(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T abs(T a) { return std::abs(float(a)); } #if defined(_MSC_VER) && defined(__CUDACC__) -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, double b) { return std::pow(float(a), float(b)); } #else -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, double b) { return std::pow(float(a), b); } #endif -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, T b) { return std::pow(float(a), float(b)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T fmod(T a, T b) { return std::fmod(float(a), float(b)); } @@ -236,9 +204,8 @@ inline T fmod(T a, T b) { SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ---------------------------------------------------------------------- */ -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T nextafter(T from, T to) { // Reference: // https://git.musl-libc.org/cgit/musl/tree/src/math/nextafter.c diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h index e89a19e5..56ed55d4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h @@ -18,8 +18,7 @@ namespace etensor { * An implementation of complex numbers, compatible with c10/util/complex.h from * pytorch core. */ -template -struct alignas(sizeof(T) * 2) complex { +template struct alignas(sizeof(T) * 2) complex { T real_ = T(0); T imag_ = T(0); }; @@ -27,8 +26,7 @@ struct alignas(sizeof(T) * 2) complex { /** * Specialization for Half, which is not a primitive C numeric type. */ -template <> -struct alignas(4) complex { +template <> struct alignas(4) complex { Half real_; Half imag_; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h index d789df8a..7f4f447b 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h @@ -40,14 +40,10 @@ struct Device final { : type_(type), index_(index) {} /// Returns the type of device this is. Only CPU is supported. - DeviceType type() const noexcept { - return type_; - } + DeviceType type() const noexcept { return type_; } /// Returns true if the device is of CPU type. - bool is_cpu() const noexcept { - return type_ == DeviceType::CPU; - } + bool is_cpu() const noexcept { return type_ == DeviceType::CPU; } /// Returns the device index. Always 0 if specified or -1 if not provided. DeviceIndex index() const noexcept { @@ -55,7 +51,7 @@ struct Device final { return index_; } - private: +private: DeviceType type_; DeviceIndex index_ = -1; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h index fa40a807..fd48fabe 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h @@ -8,10 +8,10 @@ #pragma once -#include #include #include #include +#include #include #if defined(__GNUC__) || defined(__clang__) @@ -23,14 +23,14 @@ #endif // GNUC or clang #if defined(__GNUC__) || defined(__clang__) -#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \ +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \ defined(_M_IX86) #if defined(__AVX2__) #define X86_F16 1 #include // import conversion ops from f16cintrin.h -#endif // __AVX2__ -#endif // __x86_64__ || _M_X64 || __i386 || _M_IX86 -#endif // __GNUC__ || __clang__ +#endif // __AVX2__ +#endif // __x86_64__ || _M_X64 || __i386 || _M_IX86 +#endif // __GNUC__ || __clang__ namespace executorch { namespace runtime { @@ -49,9 +49,7 @@ struct alignas(2) Half { }; struct from_bits_t {}; - static constexpr from_bits_t from_bits() { - return from_bits_t(); - } + static constexpr from_bits_t from_bits() { return from_bits_t(); } Half() = default; @@ -171,9 +169,9 @@ inline uint32_t fp16_ieee_to_fp32_bits(uint16_t h) { * 7. Combine with the sign of the input number. */ return sign | - ((((nonsign << renorm_shift >> 3) + ((0x70 - renorm_shift) << 23)) | - inf_nan_mask) & - ~zero_mask); + ((((nonsign << renorm_shift >> 3) + ((0x70 - renorm_shift) << 23)) | + inf_nan_mask) & + ~zero_mask); } /* @@ -308,9 +306,9 @@ inline float fp16_ieee_to_fp32_value(uint16_t h) { * of the input number. */ constexpr uint32_t denormalized_cutoff = UINT32_C(1) << 27; - const uint32_t result = sign | - (two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) - : fp32_to_bits(normalized_value)); + const uint32_t result = + sign | (two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) + : fp32_to_bits(normalized_value)); return fp32_from_bits(result); #endif // not X86_F16 @@ -336,8 +334,8 @@ inline uint16_t fp16_ieee_from_fp32_value(float f) { constexpr uint32_t scale_to_zero_bits = (uint32_t)17 << 23; float scale_to_inf_val = 0, scale_to_zero_val = 0; std::memcpy(&scale_to_inf_val, &scale_to_inf_bits, sizeof(scale_to_inf_val)); - std::memcpy( - &scale_to_zero_val, &scale_to_zero_bits, sizeof(scale_to_zero_val)); + std::memcpy(&scale_to_zero_val, &scale_to_zero_bits, + sizeof(scale_to_zero_val)); const float scale_to_inf = scale_to_inf_val; const float scale_to_zero = scale_to_zero_val; @@ -378,9 +376,7 @@ inline Half::Half(float value) /// Implicit conversions #ifdef NATIVE_FP16 -inline Half::operator float() const { - return (float)y; -} +inline Half::operator float() const { return (float)y; } #else inline Half::operator float() const { return internal::fp16_ieee_to_fp32_value(x); @@ -391,92 +387,82 @@ inline Half::operator float() const { #ifdef NATIVE_FP16 -#define return_half(r) \ - do { \ - Half ret; \ - ret.y = r; \ - return ret; \ +#define return_half(r) \ + do { \ + Half ret; \ + ret.y = r; \ + return ret; \ } while (0) -inline Half operator+(const Half& a, const Half& b) { - return_half(a.y + b.y); -} +inline Half operator+(const Half &a, const Half &b) { return_half(a.y + b.y); } -inline Half operator-(const Half& a, const Half& b) { +inline Half operator-(const Half &a, const Half &b) { return_half(a.y - b.y); return static_cast(a) - static_cast(b); } -inline Half operator*(const Half& a, const Half& b) { - return_half(a.y * b.y); -} +inline Half operator*(const Half &a, const Half &b) { return_half(a.y * b.y); } -inline Half operator/(const Half& a, const Half& b) { - return_half(a.y / b.y); -} +inline Half operator/(const Half &a, const Half &b) { return_half(a.y / b.y); } -inline Half operator-(const Half& a) { - return_half(-a.y); -} +inline Half operator-(const Half &a) { return_half(-a.y); } -inline Half& operator+=(Half& a, const Half& b) { +inline Half &operator+=(Half &a, const Half &b) { a.y += b.y; return a; } -inline Half& operator-=(Half& a, const Half& b) { +inline Half &operator-=(Half &a, const Half &b) { a.y -= b.y; return a; } -inline Half& operator*=(Half& a, const Half& b) { +inline Half &operator*=(Half &a, const Half &b) { a.y *= b.y; return a; } -inline Half& operator/=(Half& a, const Half& b) { +inline Half &operator/=(Half &a, const Half &b) { a.y /= b.y; return a; } #else -inline Half operator+(const Half& a, const Half& b) { +inline Half operator+(const Half &a, const Half &b) { return static_cast(a) + static_cast(b); } -inline Half operator-(const Half& a, const Half& b) { +inline Half operator-(const Half &a, const Half &b) { return static_cast(a) - static_cast(b); } -inline Half operator*(const Half& a, const Half& b) { +inline Half operator*(const Half &a, const Half &b) { return static_cast(a) * static_cast(b); } -inline Half operator/(const Half& a, const Half& b) { +inline Half operator/(const Half &a, const Half &b) { return static_cast(a) / static_cast(b); } -inline Half operator-(const Half& a) { - return -static_cast(a); -} +inline Half operator-(const Half &a) { return -static_cast(a); } -inline Half& operator+=(Half& a, const Half& b) { +inline Half &operator+=(Half &a, const Half &b) { a = a + b; return a; } -inline Half& operator-=(Half& a, const Half& b) { +inline Half &operator-=(Half &a, const Half &b) { a = a - b; return a; } -inline Half& operator*=(Half& a, const Half& b) { +inline Half &operator*=(Half &a, const Half &b) { a = a * b; return a; } -inline Half& operator/=(Half& a, const Half& b) { +inline Half &operator/=(Half &a, const Half &b) { a = a / b; return a; } @@ -485,130 +471,66 @@ inline Half& operator/=(Half& a, const Half& b) { /// Arithmetic with floats -inline float operator+(Half a, float b) { - return static_cast(a) + b; -} -inline float operator-(Half a, float b) { - return static_cast(a) - b; -} -inline float operator*(Half a, float b) { - return static_cast(a) * b; -} -inline float operator/(Half a, float b) { - return static_cast(a) / b; -} +inline float operator+(Half a, float b) { return static_cast(a) + b; } +inline float operator-(Half a, float b) { return static_cast(a) - b; } +inline float operator*(Half a, float b) { return static_cast(a) * b; } +inline float operator/(Half a, float b) { return static_cast(a) / b; } -inline float operator+(float a, Half b) { - return a + static_cast(b); -} -inline float operator-(float a, Half b) { - return a - static_cast(b); -} -inline float operator*(float a, Half b) { - return a * static_cast(b); -} -inline float operator/(float a, Half b) { - return a / static_cast(b); -} +inline float operator+(float a, Half b) { return a + static_cast(b); } +inline float operator-(float a, Half b) { return a - static_cast(b); } +inline float operator*(float a, Half b) { return a * static_cast(b); } +inline float operator/(float a, Half b) { return a / static_cast(b); } -inline float& operator+=(float& a, const Half& b) { +inline float &operator+=(float &a, const Half &b) { return a += static_cast(b); } -inline float& operator-=(float& a, const Half& b) { +inline float &operator-=(float &a, const Half &b) { return a -= static_cast(b); } -inline float& operator*=(float& a, const Half& b) { +inline float &operator*=(float &a, const Half &b) { return a *= static_cast(b); } -inline float& operator/=(float& a, const Half& b) { +inline float &operator/=(float &a, const Half &b) { return a /= static_cast(b); } /// Arithmetic with doubles -inline double operator+(Half a, double b) { - return static_cast(a) + b; -} -inline double operator-(Half a, double b) { - return static_cast(a) - b; -} -inline double operator*(Half a, double b) { - return static_cast(a) * b; -} -inline double operator/(Half a, double b) { - return static_cast(a) / b; -} +inline double operator+(Half a, double b) { return static_cast(a) + b; } +inline double operator-(Half a, double b) { return static_cast(a) - b; } +inline double operator*(Half a, double b) { return static_cast(a) * b; } +inline double operator/(Half a, double b) { return static_cast(a) / b; } -inline double operator+(double a, Half b) { - return a + static_cast(b); -} -inline double operator-(double a, Half b) { - return a - static_cast(b); -} -inline double operator*(double a, Half b) { - return a * static_cast(b); -} -inline double operator/(double a, Half b) { - return a / static_cast(b); -} +inline double operator+(double a, Half b) { return a + static_cast(b); } +inline double operator-(double a, Half b) { return a - static_cast(b); } +inline double operator*(double a, Half b) { return a * static_cast(b); } +inline double operator/(double a, Half b) { return a / static_cast(b); } /// Arithmetic with ints #ifdef NATIVE_FP16 -inline Half operator+(Half a, int32_t b) { - return_half(a.y + b); -} -inline Half operator-(Half a, int32_t b) { - return_half(a.y - b); -} -inline Half operator*(Half a, int32_t b) { - return_half(a.y * b); -} -inline Half operator/(Half a, int32_t b) { - return_half(a.y / b); -} +inline Half operator+(Half a, int32_t b) { return_half(a.y + b); } +inline Half operator-(Half a, int32_t b) { return_half(a.y - b); } +inline Half operator*(Half a, int32_t b) { return_half(a.y * b); } +inline Half operator/(Half a, int32_t b) { return_half(a.y / b); } -inline Half operator+(int32_t a, Half b) { - return_half(a + b.y); -} -inline Half operator-(int32_t a, Half b) { - return_half(a - b.y); -} -inline Half operator*(int32_t a, Half b) { - return_half(a * b.y); -} -inline Half operator/(int32_t a, Half b) { - return_half(a / b.y); -} +inline Half operator+(int32_t a, Half b) { return_half(a + b.y); } +inline Half operator-(int32_t a, Half b) { return_half(a - b.y); } +inline Half operator*(int32_t a, Half b) { return_half(a * b.y); } +inline Half operator/(int32_t a, Half b) { return_half(a / b.y); } #else -inline Half operator+(Half a, int32_t b) { - return a + static_cast(b); -} -inline Half operator-(Half a, int32_t b) { - return a - static_cast(b); -} -inline Half operator*(Half a, int32_t b) { - return a * static_cast(b); -} -inline Half operator/(Half a, int32_t b) { - return a / static_cast(b); -} +inline Half operator+(Half a, int32_t b) { return a + static_cast(b); } +inline Half operator-(Half a, int32_t b) { return a - static_cast(b); } +inline Half operator*(Half a, int32_t b) { return a * static_cast(b); } +inline Half operator/(Half a, int32_t b) { return a / static_cast(b); } -inline Half operator+(int32_t a, Half b) { - return static_cast(a) + b; -} -inline Half operator-(int32_t a, Half b) { - return static_cast(a) - b; -} -inline Half operator*(int32_t a, Half b) { - return static_cast(a) * b; -} -inline Half operator/(int32_t a, Half b) { - return static_cast(a) / b; -} +inline Half operator+(int32_t a, Half b) { return static_cast(a) + b; } +inline Half operator-(int32_t a, Half b) { return static_cast(a) - b; } +inline Half operator*(int32_t a, Half b) { return static_cast(a) * b; } +inline Half operator/(int32_t a, Half b) { return static_cast(a) / b; } #endif @@ -616,68 +538,35 @@ inline Half operator/(int32_t a, Half b) { #ifdef NATIVE_FP16 -inline Half operator+(Half a, int64_t b) { - return_half(a.y + b); -} -inline Half operator-(Half a, int64_t b) { - return_half(a.y - b); -} -inline Half operator*(Half a, int64_t b) { - return_half(a.y * b); -} -inline Half operator/(Half a, int64_t b) { - return_half(a.y / b); -} +inline Half operator+(Half a, int64_t b) { return_half(a.y + b); } +inline Half operator-(Half a, int64_t b) { return_half(a.y - b); } +inline Half operator*(Half a, int64_t b) { return_half(a.y * b); } +inline Half operator/(Half a, int64_t b) { return_half(a.y / b); } -inline Half operator+(int64_t a, Half b) { - return_half(a + b.y); -} -inline Half operator-(int64_t a, Half b) { - return_half(a - b.y); -} -inline Half operator*(int64_t a, Half b) { - return_half(a * b.y); -} -inline Half operator/(int64_t a, Half b) { - return_half(a / b.y); -} +inline Half operator+(int64_t a, Half b) { return_half(a + b.y); } +inline Half operator-(int64_t a, Half b) { return_half(a - b.y); } +inline Half operator*(int64_t a, Half b) { return_half(a * b.y); } +inline Half operator/(int64_t a, Half b) { return_half(a / b.y); } #else -inline Half operator+(Half a, int64_t b) { - return a + static_cast(b); -} -inline Half operator-(Half a, int64_t b) { - return a - static_cast(b); -} -inline Half operator*(Half a, int64_t b) { - return a * static_cast(b); -} -inline Half operator/(Half a, int64_t b) { - return a / static_cast(b); -} +inline Half operator+(Half a, int64_t b) { return a + static_cast(b); } +inline Half operator-(Half a, int64_t b) { return a - static_cast(b); } +inline Half operator*(Half a, int64_t b) { return a * static_cast(b); } +inline Half operator/(Half a, int64_t b) { return a / static_cast(b); } -inline Half operator+(int64_t a, Half b) { - return static_cast(a) + b; -} -inline Half operator-(int64_t a, Half b) { - return static_cast(a) - b; -} -inline Half operator*(int64_t a, Half b) { - return static_cast(a) * b; -} -inline Half operator/(int64_t a, Half b) { - return static_cast(a) / b; -} +inline Half operator+(int64_t a, Half b) { return static_cast(a) + b; } +inline Half operator-(int64_t a, Half b) { return static_cast(a) - b; } +inline Half operator*(int64_t a, Half b) { return static_cast(a) * b; } +inline Half operator/(int64_t a, Half b) { return static_cast(a) / b; } #endif /// NOTE: we do not define comparisons directly and instead rely on the implicit /// conversion Half to float. -static inline std::ostream& operator<<( - std::ostream& out, - const executorch::runtime::etensor::Half& value) { +static inline std::ostream & +operator<<(std::ostream &out, const executorch::runtime::etensor::Half &value) { out << (float)value; return out; } @@ -695,9 +584,8 @@ using ::executorch::runtime::etensor::Half; namespace std { -template <> -class numeric_limits { - public: +template <> class numeric_limits { +public: static constexpr bool is_specialized = true; static constexpr bool is_signed = true; static constexpr bool is_integer = false; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h index 21fe0d39..f9df4681 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h @@ -26,9 +26,8 @@ struct nullopt_t final { constexpr nullopt_t nullopt{0}; /// Leaner optional class, subset of c10, std, and boost optional APIs. -template -class optional final { - public: +template class optional final { +public: /// The type wrapped by the optional class. using value_type = T; @@ -40,7 +39,7 @@ class optional final { : storage_(trivial_init), init_(false) {} /// Constructs an optional object that matches the state of v. - /* implicit */ optional(const optional& v) + /* implicit */ optional(const optional &v) : storage_(trivial_init), init_(v.init_) { if (init_) { new (&storage_.value_) T(v.storage_.value_); @@ -48,10 +47,10 @@ class optional final { } /// Constructs an optional object that contains the specified value. - /* implicit */ optional(const T& v) : storage_(v), init_(true) {} + /* implicit */ optional(const T &v) : storage_(v), init_(true) {} /// Constructs an optional object from v. - /* implicit */ optional(optional&& v) noexcept( + /* implicit */ optional(optional &&v) noexcept( std::is_nothrow_move_constructible::value) : storage_(trivial_init), init_(v.init_) { if (init_) { @@ -60,9 +59,9 @@ class optional final { } /// Constructs an optional object that contains the specified value. - /* implicit */ optional(T&& v) : storage_(std::forward(v)), init_(true) {} + /* implicit */ optional(T &&v) : storage_(std::forward(v)), init_(true) {} - optional& operator=(const optional& rhs) { + optional &operator=(const optional &rhs) { if (init_ && !rhs.init_) { clear(); } else if (!init_ && rhs.init_) { @@ -74,7 +73,7 @@ class optional final { return *this; } - optional& operator=(optional&& rhs) noexcept( + optional &operator=(optional &&rhs) noexcept( std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) { if (init_ && !rhs.init_) { @@ -95,43 +94,39 @@ class optional final { } } - optional& operator=(nullopt_t) noexcept { + optional &operator=(nullopt_t) noexcept { clear(); return *this; } /// Returns true if the object contains a value, false otherwise - explicit operator bool() const noexcept { - return init_; - } + explicit operator bool() const noexcept { return init_; } /// Returns true if the object contains a value, false otherwise - bool has_value() const noexcept { - return init_; - } + bool has_value() const noexcept { return init_; } /// Returns a constant reference to the contained value. Calls ET_CHECK if /// the object does not contain a value. - T const& value() const& { + T const &value() const & { ET_CHECK(init_); return contained_val(); } /// Returns a mutable reference to the contained value. Calls ET_CHECK if the /// object does not contain a value. - T& value() & { + T &value() & { ET_CHECK(init_); return contained_val(); } /// Returns an rvalue of the contained value. Calls ET_CHECK if the object /// does not contain a value. - T&& value() && { + T &&value() && { ET_CHECK(init_); return std::forward(contained_val()); } - private: +private: // Used to invoke the dummy ctor of storage_t in the initializer lists of // optional_base as default ctor is implicitly deleted because T is nontrivial struct trivial_init_t { @@ -147,25 +142,17 @@ class optional final { /// The constructed value itself, if optional::has_value_ is true. T value_; - /* implicit */ storage_t(trivial_init_t) { - dummy_ = 0; - } + /* implicit */ storage_t(trivial_init_t) { dummy_ = 0; } template - storage_t(Args&&... args) : value_(std::forward(args)...) {} + storage_t(Args &&...args) : value_(std::forward(args)...) {} ~storage_t() {} }; - const T& contained_val() const& { - return storage_.value_; - } - T&& contained_val() && { - return std::move(storage_.value_); - } - T& contained_val() & { - return storage_.value_; - } + const T &contained_val() const & { return storage_.value_; } + T &&contained_val() && { return std::move(storage_.value_); } + T &contained_val() & { return storage_.value_; } void clear() noexcept { if (init_) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h index 0922cec6..f503990e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h @@ -27,27 +27,21 @@ namespace etensor { * semantics/behavior should also match the c10 version. */ class Scalar { - public: +public: Scalar() : Scalar(int64_t(0)) {} - template < - typename T, - typename std::enable_if::value, bool>::type = true> + template ::value, + bool>::type = true> /*implicit*/ Scalar(T val) : tag(Tag::Int) { v.as_int = static_cast(val); } - /*implicit*/ Scalar(bool val) : tag(Tag::Bool) { - v.as_bool = val; - } - /*implicit*/ Scalar(double val) : tag(Tag::Double) { - v.as_double = val; - } + /*implicit*/ Scalar(bool val) : tag(Tag::Bool) { v.as_bool = val; } + /*implicit*/ Scalar(double val) : tag(Tag::Double) { v.as_double = val; } /*implicit*/ Scalar(BFloat16 val) : Scalar((double)(float)val) {} /*implicit*/ Scalar(Half val) : Scalar((double)(float)val) {} /// Returns the concrete scalar value stored within. - template - T to() const; + template T to() const; /// Returns true if the scalar is integral, false otherwise. bool isIntegral(bool includeBool) const { @@ -55,16 +49,12 @@ class Scalar { } /// Returns true if the scalar is a floating point, false otherwise. - bool isFloatingPoint() const { - return tag == Tag::Double; - } + bool isFloatingPoint() const { return tag == Tag::Double; } /// Returns true if the scalar is a boolean, false otherwise. - bool isBoolean() const { - return tag == Tag::Bool; - } + bool isBoolean() const { return tag == Tag::Bool; } - private: +private: int64_t toInt() const { if (isIntegral(/*includeBool=*/false)) { return v.as_int; @@ -99,11 +89,8 @@ class Scalar { } v; }; -#define ET_DEFINE_SCALAR_TO_METHOD(T, name) \ - template <> \ - inline T Scalar::to() const { \ - return to##name(); \ - } +#define ET_DEFINE_SCALAR_TO_METHOD(T, name) \ + template <> inline T Scalar::to() const { return to##name(); } ET_DEFINE_SCALAR_TO_METHOD(double, Double) ET_DEFINE_SCALAR_TO_METHOD(int64_t, Int) diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h index 286aee33..f91344b4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h @@ -59,30 +59,30 @@ namespace etensor { * @param _ A macro that takes two parameters: the name of a C type, and the * name of the corresponding ScalarType enumerator. */ -#define ET_FORALL_SCALAR_TYPES(_) \ - _(uint8_t, Byte) /* 0 */ \ - _(int8_t, Char) /* 1 */ \ - _(int16_t, Short) /* 2 */ \ - _(int32_t, Int) /* 3 */ \ - _(int64_t, Long) /* 4 */ \ - _(::torch::executor::Half, Half) /* 5 */ \ - _(float, Float) /* 6 */ \ - _(double, Double) /* 7 */ \ - _(::torch::executor::complex<::torch::executor::Half>, ComplexHalf) /* 8 */ \ - _(::torch::executor::complex, ComplexFloat) /* 9 */ \ - _(::torch::executor::complex, ComplexDouble) /* 10 */ \ - _(bool, Bool) /* 11 */ \ - _(::torch::executor::qint8, QInt8) /* 12 */ \ - _(::torch::executor::quint8, QUInt8) /* 13 */ \ - _(::torch::executor::qint32, QInt32) /* 14 */ \ - _(::torch::executor::BFloat16, BFloat16) /* 15 */ \ - _(::torch::executor::quint4x2, QUInt4x2) /* 16 */ \ - _(::torch::executor::quint2x4, QUInt2x4) /* 17 */ \ - _(::torch::executor::bits1x8, Bits1x8) /* 18 */ \ - _(::torch::executor::bits2x4, Bits2x4) /* 19 */ \ - _(::torch::executor::bits4x2, Bits4x2) /* 20 */ \ - _(::torch::executor::bits8, Bits8) /* 21 */ \ - _(::torch::executor::bits16, Bits16) /* 22 */ +#define ET_FORALL_SCALAR_TYPES(_) \ + _(uint8_t, Byte) /* 0 */ \ + _(int8_t, Char) /* 1 */ \ + _(int16_t, Short) /* 2 */ \ + _(int32_t, Int) /* 3 */ \ + _(int64_t, Long) /* 4 */ \ + _(::torch::executor::Half, Half) /* 5 */ \ + _(float, Float) /* 6 */ \ + _(double, Double) /* 7 */ \ + _(::torch::executor::complex<::torch::executor::Half>, ComplexHalf) /* 8 */ \ + _(::torch::executor::complex, ComplexFloat) /* 9 */ \ + _(::torch::executor::complex, ComplexDouble) /* 10 */ \ + _(bool, Bool) /* 11 */ \ + _(::torch::executor::qint8, QInt8) /* 12 */ \ + _(::torch::executor::quint8, QUInt8) /* 13 */ \ + _(::torch::executor::qint32, QInt32) /* 14 */ \ + _(::torch::executor::BFloat16, BFloat16) /* 15 */ \ + _(::torch::executor::quint4x2, QUInt4x2) /* 16 */ \ + _(::torch::executor::quint2x4, QUInt2x4) /* 17 */ \ + _(::torch::executor::bits1x8, Bits1x8) /* 18 */ \ + _(::torch::executor::bits2x4, Bits2x4) /* 19 */ \ + _(::torch::executor::bits4x2, Bits4x2) /* 20 */ \ + _(::torch::executor::bits8, Bits8) /* 21 */ \ + _(::torch::executor::bits16, Bits16) /* 22 */ /** * Data types (dtypes) that can be used as element types in ETensors. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h index 977a0f54..067ac10e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h @@ -25,15 +25,14 @@ namespace internal { * Mostly copy pasted from the c10 implementation but modified some to remove * broader c10 dependencies */ -template -class basic_string_view final { - public: +template class basic_string_view final { +public: using value_type = CharT; - using pointer = CharT*; - using const_pointer = const CharT*; - using reference = CharT&; - using const_reference = const CharT&; - using const_iterator = const CharT*; + using pointer = CharT *; + using const_pointer = const CharT *; + using reference = CharT &; + using const_reference = const CharT &; + using const_iterator = const CharT *; using iterator = const_iterator; using size_type = std::size_t; @@ -47,21 +46,13 @@ class basic_string_view final { /* implicit */ constexpr basic_string_view(const_pointer str) : basic_string_view(str, strlen_(str)) {} - constexpr const_iterator begin() const noexcept { - return cbegin(); - } + constexpr const_iterator begin() const noexcept { return cbegin(); } - constexpr const_iterator cbegin() const noexcept { - return begin_; - } + constexpr const_iterator cbegin() const noexcept { return begin_; } - constexpr const_iterator end() const noexcept { - return cend(); - } + constexpr const_iterator end() const noexcept { return cend(); } - constexpr const_iterator cend() const noexcept { - return begin_ + size_; - } + constexpr const_iterator cend() const noexcept { return begin_ + size_; } friend constexpr const_iterator begin(basic_string_view sv) noexcept { return sv.begin(); @@ -71,40 +62,25 @@ class basic_string_view final { return sv.end(); } - constexpr const_reference operator[](size_type pos) const { - return at_(pos); - } + constexpr const_reference operator[](size_type pos) const { return at_(pos); } constexpr const_reference at(size_type pos) const { - ET_CHECK_MSG( - pos >= size_, - "string_view::operator[] or string_view::at() out of range"); + ET_CHECK_MSG(pos >= size_, + "string_view::operator[] or string_view::at() out of range"); return at_(pos); } - constexpr const_reference front() const { - return *begin_; - } + constexpr const_reference front() const { return *begin_; } - constexpr const_reference back() const { - return *(begin_ + size_ - 1); - } + constexpr const_reference back() const { return *(begin_ + size_ - 1); } - constexpr const_pointer data() const noexcept { - return begin_; - } + constexpr const_pointer data() const noexcept { return begin_; } - constexpr size_type size() const noexcept { - return size_; - } + constexpr size_type size() const noexcept { return size_; } - constexpr size_type length() const noexcept { - return size(); - } + constexpr size_type length() const noexcept { return size(); } - constexpr bool empty() const noexcept { - return size() == 0; - } + constexpr bool empty() const noexcept { return size() == 0; } void remove_prefix(size_type n) { ET_CHECK_MSG(n > size(), "basic_string_view::remove_prefix: out of range."); @@ -117,7 +93,7 @@ class basic_string_view final { size_ -= n; } - void swap(basic_string_view& sv) noexcept { + void swap(basic_string_view &sv) noexcept { auto tmp = *this; *this = sv; sv = tmp; @@ -132,10 +108,10 @@ class basic_string_view final { return copy_length; } - constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) - const { - ET_CHECK_MSG( - pos > size_, "basic_string_view::substr parameter out of bounds."); + constexpr basic_string_view substr(size_type pos = 0, + size_type count = npos) const { + ET_CHECK_MSG(pos > size_, + "basic_string_view::substr parameter out of bounds."); return substr_(pos, count); } @@ -159,25 +135,21 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (size() == 0 && rhs.size() == 0) ? 0 - : (size() == 0) ? -1 - : (rhs.size() == 0) ? 1 - : (front() < rhs.front()) ? -1 - : (front() > rhs.front()) ? 1 - : substr_(1).compare(rhs.substr_(1)); + : (size() == 0) ? -1 + : (rhs.size() == 0) ? 1 + : (front() < rhs.front()) ? -1 + : (front() > rhs.front()) ? 1 + : substr_(1).compare(rhs.substr_(1)); #endif } - constexpr int compare(size_type pos1, size_type count1, basic_string_view v) - const { + constexpr int compare(size_type pos1, size_type count1, + basic_string_view v) const { return substr(pos1, count1).compare(v); } - constexpr int compare( - size_type pos1, - size_type count1, - basic_string_view v, - size_type pos2, - size_type count2) const { + constexpr int compare(size_type pos1, size_type count1, basic_string_view v, + size_type pos2, size_type count2) const { return substr(pos1, count1).compare(v.substr(pos2, count2)); } @@ -185,52 +157,43 @@ class basic_string_view final { return compare(basic_string_view(s)); } - constexpr int compare(size_type pos1, size_type count1, const_pointer s) - const { + constexpr int compare(size_type pos1, size_type count1, + const_pointer s) const { return substr(pos1, count1).compare(basic_string_view(s)); } - constexpr int compare( - size_type pos1, - size_type count1, - const_pointer s, - size_type count2) const { + constexpr int compare(size_type pos1, size_type count1, const_pointer s, + size_type count2) const { return substr(pos1, count1).compare(basic_string_view(s, count2)); } - friend constexpr bool operator==( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator==(basic_string_view lhs, + basic_string_view rhs) noexcept { return lhs.equals_(rhs); } - friend constexpr bool operator!=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator!=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs == rhs); } - friend constexpr bool operator<( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator<(basic_string_view lhs, + basic_string_view rhs) noexcept { return lhs.compare(rhs) < 0; } - friend constexpr bool operator>=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator>=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs < rhs); } - friend constexpr bool operator>( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator>(basic_string_view lhs, + basic_string_view rhs) noexcept { return rhs < lhs; } - friend constexpr bool operator<=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator<=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs > rhs); } @@ -249,8 +212,8 @@ class basic_string_view final { constexpr bool ends_with(basic_string_view suffix) const noexcept { return (suffix.size() > size()) - ? false - : suffix.equals_(substr_(size() - suffix.size(), suffix.size())); + ? false + : suffix.equals_(substr_(size() - suffix.size(), suffix.size())); } constexpr bool ends_with(CharT suffix) const noexcept { @@ -261,8 +224,8 @@ class basic_string_view final { return ends_with(basic_string_view(suffix)); } - constexpr size_type find(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find(basic_string_view v, + size_type pos = 0) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (v.size() == 0) { @@ -281,12 +244,12 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (v.size() == 0) ? (pos <= size() ? pos : npos) - : (pos + v.size() > size()) ? npos - : (v.at_(0) == at_(pos) && - v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) - ? pos - : find(v, pos + 1); + return (v.size() == 0) ? (pos <= size() ? pos : npos) + : (pos + v.size() > size()) ? npos + : (v.at_(0) == at_(pos) && + v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) + ? pos + : find(v, pos + 1); #endif } @@ -294,8 +257,8 @@ class basic_string_view final { return find_first_if_(pos, charIsEqual_{ch}); } - constexpr size_type find(const_pointer s, size_type pos, size_type count) - const { + constexpr size_type find(const_pointer s, size_type pos, + size_type count) const { return find(basic_string_view(s, count), pos); } @@ -303,8 +266,8 @@ class basic_string_view final { return find(basic_string_view(s), pos); } - constexpr size_type rfind(basic_string_view v, size_type pos = npos) - const noexcept { + constexpr size_type rfind(basic_string_view v, + size_type pos = npos) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (v.size() == 0) { @@ -324,14 +287,14 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (v.size() == 0) ? (pos <= size() ? pos : size()) - : (v.size() > size()) ? npos - : (size() - v.size() < pos) ? rfind(v, size() - v.size()) - : (v.at_(0) == at_(pos) && - v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) - ? pos - : (pos == 0) ? npos - : rfind(v, pos - 1); + return (v.size() == 0) ? (pos <= size() ? pos : size()) + : (v.size() > size()) ? npos + : (size() - v.size() < pos) ? rfind(v, size() - v.size()) + : (v.at_(0) == at_(pos) && + v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) + ? pos + : (pos == 0) ? npos + : rfind(v, pos - 1); #endif } @@ -339,8 +302,8 @@ class basic_string_view final { return find_last_if_(pos, charIsEqual_{ch}); } - constexpr size_type rfind(const_pointer s, size_type pos, size_type count) - const { + constexpr size_type rfind(const_pointer s, size_type pos, + size_type count) const { return rfind(basic_string_view(s, count), pos); } @@ -348,18 +311,18 @@ class basic_string_view final { return rfind(basic_string_view(s), pos); } - constexpr size_type find_first_of(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find_first_of(basic_string_view v, + size_type pos = 0) const noexcept { return find_first_if_(pos, stringViewContainsChar_{v}); } - constexpr size_type find_first_of(CharT ch, size_type pos = 0) - const noexcept { + constexpr size_type find_first_of(CharT ch, + size_type pos = 0) const noexcept { return find_first_if_(pos, charIsEqual_{ch}); } - constexpr size_type - find_first_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_first_of(const_pointer s, size_type pos, + size_type count) const { return find_first_of(basic_string_view(s, count), pos); } @@ -367,68 +330,67 @@ class basic_string_view final { return find_first_of(basic_string_view(s), pos); } - constexpr size_type find_last_of(basic_string_view v, size_type pos = npos) - const noexcept { + constexpr size_type find_last_of(basic_string_view v, + size_type pos = npos) const noexcept { return find_last_if_(pos, stringViewContainsChar_{v}); } - constexpr size_type find_last_of(CharT ch, size_type pos = npos) - const noexcept { + constexpr size_type find_last_of(CharT ch, + size_type pos = npos) const noexcept { return find_last_if_(pos, charIsEqual_{ch}); } - constexpr size_type - find_last_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_last_of(const_pointer s, size_type pos, + size_type count) const { return find_last_of(basic_string_view(s, count), pos); } - constexpr size_type find_last_of(const_pointer s, size_type pos = npos) - const { + constexpr size_type find_last_of(const_pointer s, + size_type pos = npos) const { return find_last_of(basic_string_view(s), pos); } - constexpr size_type find_first_not_of(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find_first_not_of(basic_string_view v, + size_type pos = 0) const noexcept { return find_first_if_(pos, stringViewDoesNotContainChar_{v}); } - constexpr size_type find_first_not_of(CharT ch, size_type pos = 0) - const noexcept { + constexpr size_type find_first_not_of(CharT ch, + size_type pos = 0) const noexcept { return find_first_if_(pos, charIsNotEqual_{ch}); } - constexpr size_type - find_first_not_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_first_not_of(const_pointer s, size_type pos, + size_type count) const { return find_first_not_of(basic_string_view(s, count), pos); } - constexpr size_type find_first_not_of(const_pointer s, size_type pos = 0) - const { + constexpr size_type find_first_not_of(const_pointer s, + size_type pos = 0) const { return find_first_not_of(basic_string_view(s), pos); } - constexpr size_type find_last_not_of( - basic_string_view v, - size_type pos = npos) const noexcept { + constexpr size_type find_last_not_of(basic_string_view v, + size_type pos = npos) const noexcept { return find_last_if_(pos, stringViewDoesNotContainChar_{v}); } - constexpr size_type find_last_not_of(CharT ch, size_type pos = npos) - const noexcept { + constexpr size_type find_last_not_of(CharT ch, + size_type pos = npos) const noexcept { return find_last_if_(pos, charIsNotEqual_{ch}); } - constexpr size_type - find_last_not_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_last_not_of(const_pointer s, size_type pos, + size_type count) const { return find_last_not_of(basic_string_view(s, count), pos); } - constexpr size_type find_last_not_of(const_pointer s, size_type pos = npos) - const { + constexpr size_type find_last_not_of(const_pointer s, + size_type pos = npos) const { return find_last_not_of(basic_string_view(s), pos); } - private: +private: static constexpr std::size_t min_(const std::size_t a, const std::size_t b) { return (b < a) ? b : a; } @@ -452,14 +414,14 @@ class basic_string_view final { return *(begin_ + pos); } - constexpr basic_string_view substr_(size_type pos = 0, size_type count = npos) - const { + constexpr basic_string_view substr_(size_type pos = 0, + size_type count = npos) const { return basic_string_view{begin_ + pos, min_(count, size() - pos)}; } template - constexpr size_type find_first_if_(size_type pos, Condition&& condition) - const noexcept { + constexpr size_type find_first_if_(size_type pos, + Condition &&condition) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (pos + 1 <= size()) { @@ -474,15 +436,15 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (pos + 1 > size()) ? npos - : condition(at_(pos)) - ? pos - : find_first_if_(pos + 1, std::forward(condition)); + : condition(at_(pos)) + ? pos + : find_first_if_(pos + 1, std::forward(condition)); #endif } template - constexpr size_type find_last_if_(size_type pos, Condition&& condition) - const noexcept { + constexpr size_type find_last_if_(size_type pos, + Condition &&condition) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (size() > 0) { @@ -498,12 +460,12 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (size() == 0) ? npos - : (pos >= size()) - ? find_last_if_(size() - 1, std::forward(condition)) - : condition(at_(pos)) ? pos - : (pos == 0) - ? npos - : find_last_if_(pos - 1, std::forward(condition)); + : (pos >= size()) + ? find_last_if_(size() - 1, std::forward(condition)) + : condition(at_(pos)) ? pos + : (pos == 0) + ? npos + : find_last_if_(pos - 1, std::forward(condition)); #endif } @@ -525,10 +487,10 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (size() != rhs.size()) ? false - : (size() == 0) ? true - : (front() != rhs.front()) ? false - : (substr_(1).equals_(rhs.substr_(1))); + return (size() != rhs.size()) ? false + : (size() == 0) ? true + : (front() != rhs.front()) ? false + : (substr_(1).equals_(rhs.substr_(1))); #endif } @@ -565,9 +527,8 @@ class basic_string_view final { }; template -inline void swap( - basic_string_view& lhs, - basic_string_view& rhs) noexcept { +inline void swap(basic_string_view &lhs, + basic_string_view &rhs) noexcept { lhs.swap(rhs); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h index 775bccc1..7e9efaa4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h @@ -27,7 +27,7 @@ namespace etensor { * types used here and how they relate to at::Tensor. */ class Tensor { - public: +public: /// The type used for elements of `sizes()`. using SizesType = TensorImpl::SizesType; /// The type used for elements of `dim_order()`. @@ -36,7 +36,7 @@ class Tensor { using StridesType = TensorImpl::StridesType; Tensor() = delete; - explicit constexpr Tensor(TensorImpl* impl) : impl_(impl) {} + explicit constexpr Tensor(TensorImpl *impl) : impl_(impl) {} /** * Returns a pointer to the underlying TensorImpl. @@ -44,7 +44,7 @@ class Tensor { * NOTE: Clients should be wary of operating on the TensorImpl * directly instead of the Tensor. It is easy to break things. */ - TensorImpl* unsafeGetTensorImpl() const { + TensorImpl *unsafeGetTensorImpl() const { // TODO(T154114015): See if we can make this api private with friends. return impl_; } @@ -55,9 +55,7 @@ class Tensor { * NOTE: Only the alive space is returned not the total capacity of the * underlying data blob. */ - size_t nbytes() const { - return impl_->nbytes(); - } + size_t nbytes() const { return impl_->nbytes(); } /** * Returns the size of the tensor at the given dimension. @@ -67,86 +65,57 @@ class Tensor { * this method more compatible with at::Tensor, and more consistent with the * rest of the methods on this class and in ETensor. */ - ssize_t size(ssize_t dim) const { - return impl_->size(dim); - } + ssize_t size(ssize_t dim) const { return impl_->size(dim); } /// Returns the tensor's number of dimensions. - ssize_t dim() const { - return impl_->dim(); - } + ssize_t dim() const { return impl_->dim(); } /// Returns the number of elements in the tensor. - ssize_t numel() const { - return impl_->numel(); - } + ssize_t numel() const { return impl_->numel(); } /// Returns the type of the elements in the tensor (int32, float, bool, etc). - ScalarType scalar_type() const { - return impl_->scalar_type(); - } + ScalarType scalar_type() const { return impl_->scalar_type(); } - inline ScalarType dtype() const { - return scalar_type(); - } + inline ScalarType dtype() const { return scalar_type(); } /// Returns the size in bytes of one element of the tensor. - ssize_t element_size() const { - return impl_->element_size(); - } + ssize_t element_size() const { return impl_->element_size(); } /// Returns the sizes of the tensor at each dimension. - const ArrayRef sizes() const { - return impl_->sizes(); - } + const ArrayRef sizes() const { return impl_->sizes(); } /// Returns the order the dimensions are laid out in memory. - const ArrayRef dim_order() const { - return impl_->dim_order(); - } + const ArrayRef dim_order() const { return impl_->dim_order(); } /// Returns the strides of the tensor at each dimension. - const ArrayRef strides() const { - return impl_->strides(); - } + const ArrayRef strides() const { return impl_->strides(); } /// Returns the mutability of the shape of the tensor. - TensorShapeDynamism shape_dynamism() const { - return impl_->shape_dynamism(); - } + TensorShapeDynamism shape_dynamism() const { return impl_->shape_dynamism(); } /// Returns a pointer of type T to the constant underlying data blob. - template - inline const T* const_data_ptr() const { + template inline const T *const_data_ptr() const { return impl_->data(); } /// Returns a pointer to the constant underlying data blob. - inline const void* const_data_ptr() const { - return impl_->data(); - } + inline const void *const_data_ptr() const { return impl_->data(); } /// Returns a pointer of type T to the mutable underlying data blob. - template - inline T* mutable_data_ptr() const { + template inline T *mutable_data_ptr() const { return impl_->mutable_data(); } /// Returns a pointer to the mutable underlying data blob. - inline void* mutable_data_ptr() const { - return impl_->mutable_data(); - } + inline void *mutable_data_ptr() const { return impl_->mutable_data(); } /// DEPRECATED: Use const_data_ptr or mutable_data_ptr instead. - template - ET_DEPRECATED inline T* data_ptr() const { + template ET_DEPRECATED inline T *data_ptr() const { return impl_->mutable_data(); } /// DEPRECATED: Use const_data_ptr or mutable_data_ptr instead. - ET_DEPRECATED inline void* data_ptr() const { - return impl_->mutable_data(); - } + ET_DEPRECATED inline void *data_ptr() const { return impl_->mutable_data(); } /** * DEPRECATED: Changes the data_ptr the tensor aliases. Does not free the @@ -154,12 +123,10 @@ class Tensor { * ptr. This api does not exist in at::Tensor so kernel developers should * avoid it. */ - ET_DEPRECATED void set_data(void* ptr) const { - impl_->set_data(ptr); - } + ET_DEPRECATED void set_data(void *ptr) const { impl_->set_data(ptr); } - private: - TensorImpl* impl_ = nullptr; +private: + TensorImpl *impl_ = nullptr; }; } // namespace etensor diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h index fd2fd124..7357fffa 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h @@ -53,7 +53,7 @@ namespace etensor { * with `#ifdef USE_ATEN_LIB`. */ class TensorImpl { - public: +public: /** * The type used for elements of `sizes()`. * @@ -100,14 +100,10 @@ class TensorImpl { * entries. * @param dynamism The mutability of the shape of the tensor. */ - TensorImpl( - ScalarType type, - ssize_t dim, - SizesType* sizes, - void* data = nullptr, - DimOrderType* dim_order = nullptr, - StridesType* strides = nullptr, - TensorShapeDynamism dynamism = TensorShapeDynamism::STATIC); + TensorImpl(ScalarType type, ssize_t dim, SizesType *sizes, + void *data = nullptr, DimOrderType *dim_order = nullptr, + StridesType *strides = nullptr, + TensorShapeDynamism dynamism = TensorShapeDynamism::STATIC); /** * Returns the size of the tensor in bytes. @@ -126,32 +122,23 @@ class TensorImpl { * rest of the methods on this class and in ETensor. */ ssize_t size(ssize_t dim) const { - ET_CHECK_MSG( - dim < dim_ && dim >= 0, - "Dimension out of range (expected to be in range of [0, %zd], but got %zd", - dim_ - 1, - dim); + ET_CHECK_MSG(dim < dim_ && dim >= 0, + "Dimension out of range (expected to be in range of [0, %zd], " + "but got %zd", + dim_ - 1, dim); return sizes_[dim]; } /// Returns the tensor's number of dimensions. - ssize_t dim() const { - return dim_; - } + ssize_t dim() const { return dim_; } /// Returns the number of elements in the tensor. - ssize_t numel() const { - return numel_; - } + ssize_t numel() const { return numel_; } /// Returns the type of the elements in the tensor (int32, float, bool, etc). - ScalarType scalar_type() const { - return type_; - } + ScalarType scalar_type() const { return type_; } - inline ScalarType dtype() const { - return scalar_type(); - } + inline ScalarType dtype() const { return scalar_type(); } /// Returns the size in bytes of one element of the tensor. ssize_t element_size() const; @@ -172,36 +159,26 @@ class TensorImpl { } /// Returns the mutability of the shape of the tensor. - TensorShapeDynamism shape_dynamism() const { - return shape_dynamism_; - } + TensorShapeDynamism shape_dynamism() const { return shape_dynamism_; } /// Returns a pointer of type T to the constant underlying data blob. - template - inline const T* data() const { - return static_cast(data()); + template inline const T *data() const { + return static_cast(data()); } /// Returns a pointer to the constant underlying data blob. - const void* data() const { - return data_; - } + const void *data() const { return data_; } /// Returns a pointer of type T to the mutable underlying data blob. - template - inline T* mutable_data() const { - return static_cast(mutable_data()); + template inline T *mutable_data() const { + return static_cast(mutable_data()); } /// Returns a pointer to the mutable underlying data blob. - void* mutable_data() const { - return data_; - } + void *mutable_data() const { return data_; } /// Sets the underlying data blob to the passed in pointer. - void set_data(void* ptr) { - data_ = ptr; - } + void set_data(void *ptr) { data_ = ptr; } /* * DEPRECATED: Use torch::executor::resize_tensor() or @@ -210,11 +187,11 @@ class TensorImpl { ET_DEPRECATED void set_sizes_contiguous(ArrayRef new_sizes) { Error err = internal_resize_contiguous(new_sizes); - ET_CHECK_MSG( - err == Error::Ok, "Could not resize Tensor; see logs for details"); + ET_CHECK_MSG(err == Error::Ok, + "Could not resize Tensor; see logs for details"); } - private: +private: // For access to internal_resize_contiguous(). friend class ::executorch::runtime::internal::TensorResizerFriend; @@ -231,20 +208,20 @@ class TensorImpl { */ ET_NODISCARD Error internal_resize_contiguous(ArrayRef new_sizes); - private: +private: // Keep fields arranged to avoid unnecessary alignment holes. /// List of sizes of each dimension in the tensor. - SizesType* sizes_; + SizesType *sizes_; /// List of the order that dimensions are laid out in memory. - DimOrderType* dim_order_; + DimOrderType *dim_order_; // TODO(T148356881): Get rid of strides from ETensor - StridesType* strides_; + StridesType *strides_; /// Pointer to underlying data blob. NOTE: Can be null. - void* data_; + void *data_; /// Tensor's number of dimensions. const ssize_t dim_; @@ -267,7 +244,7 @@ class TensorImpl { * Compute the number of elements based on the sizes of a tensor. */ ssize_t compute_numel( - const ::executorch::runtime::etensor::TensorImpl::SizesType* sizes, + const ::executorch::runtime::etensor::TensorImpl::SizesType *sizes, ssize_t dim); } // namespace etensor diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h index 7b404bca..00cc7bb8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h @@ -45,9 +45,8 @@ namespace runtime { * } * @endcode */ -template -class Result final { - public: +template class Result final { +public: /// `value_type` member for generic programming. typedef T value_type; @@ -59,17 +58,17 @@ class Result final { * a non-Ok value. */ /* implicit */ Result(Error error) - : error_(error == Error::Ok ? Error::Internal : error), - hasValue_(false) {} + : error_(error == Error::Ok ? Error::Internal : error), hasValue_(false) { + } /// Value copy constructor. - /* implicit */ Result(const T& val) : value_(val), hasValue_(true) {} + /* implicit */ Result(const T &val) : value_(val), hasValue_(true) {} /// Value move constructor. - /* implicit */ Result(T&& val) : value_(std::move(val)), hasValue_(true) {} + /* implicit */ Result(T &&val) : value_(std::move(val)), hasValue_(true) {} /// Result move constructor. - /* implicit */ Result(Result&& rhs) noexcept : hasValue_(rhs.hasValue_) { + /* implicit */ Result(Result &&rhs) noexcept : hasValue_(rhs.hasValue_) { if (hasValue_) { // Use the value type's move constructor. new (&value_) T(std::move(rhs.value_)); @@ -92,9 +91,7 @@ class Result final { * If true, it is guaranteed that `error()` will return `Error::Ok`. * If false, it is guaranteed that `error()` will not return `Error::Ok`. */ - ET_NODISCARD bool ok() const { - return hasValue_; - } + ET_NODISCARD bool ok() const { return hasValue_; } /** * Returns the error code of this Result. @@ -116,7 +113,7 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - T& get() { + T &get() { CheckOk(); return value_; } @@ -126,7 +123,7 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - const T& get() const { + const T &get() const { CheckOk(); return value_; } @@ -136,37 +133,35 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - const T& operator*() const&; - T& operator*() &; + const T &operator*() const &; + T &operator*() &; /* * Returns a pointer to the Result's value. * * Only legal to call if `ok()` returns true. */ - const T* operator->() const; - T* operator->(); + const T *operator->() const; + T *operator->(); - private: +private: /** * Delete default constructor since all Results should contain a value or * error. */ Result() = delete; /// Delete copy constructor since T may not be copyable. - Result(const Result&) = delete; + Result(const Result &) = delete; /// Delete copy assignment since T may not be copyable. - Result& operator=(const Result&) = delete; + Result &operator=(const Result &) = delete; /// Delete move assignment since it's not a supported pattern to reuse Result. - Result& operator=(Result&& rhs) = delete; + Result &operator=(Result &&rhs) = delete; // Panics if ok() would return false; - void CheckOk() const { - ET_CHECK(hasValue_); - } + void CheckOk() const { ET_CHECK(hasValue_); } union { - T value_; // Used if hasValue_ is true. + T value_; // Used if hasValue_ is true. Error error_; // Used if hasValue_ is false. }; @@ -174,26 +169,22 @@ class Result final { const bool hasValue_; }; -template -const T& Result::operator*() const& { +template const T &Result::operator*() const & { CheckOk(); return value_; } -template -T& Result::operator*() & { +template T &Result::operator*() & { CheckOk(); return value_; } -template -const T* Result::operator->() const { +template const T *Result::operator->() const { CheckOk(); return &value_; } -template -T* Result::operator->() { +template T *Result::operator->() { CheckOk(); return &value_; } @@ -222,34 +213,34 @@ using ::executorch::runtime::Result; #define ET_UNWRAP(result__, ...) ET_INTERNAL_UNWRAP(result__, ##__VA_ARGS__) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP(...) \ - ET_INTERNAL_UNWRAP_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ +#define ET_INTERNAL_UNWRAP(...) \ + ET_INTERNAL_UNWRAP_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ (__VA_ARGS__) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_SELECT( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) \ +#define ET_INTERNAL_UNWRAP_SELECT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, \ + ...) \ ET_INTERNAL_UNWRAP_##N // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_1(result__) \ - ({ \ - auto et_result__ = (result__); \ - if (!et_result__.ok()) { \ - return et_result__.error(); \ - } \ - std::move(*et_result__); \ +#define ET_INTERNAL_UNWRAP_1(result__) \ + ({ \ + auto et_result__ = (result__); \ + if (!et_result__.ok()) { \ + return et_result__.error(); \ + } \ + std::move(*et_result__); \ }) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_2(result__, message__, ...) \ - ({ \ - auto et_result__ = (result__); \ - if (!et_result__.ok()) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return et_result__.error(); \ - } \ - std::move(*et_result__); \ +#define ET_INTERNAL_UNWRAP_2(result__, message__, ...) \ + ({ \ + auto et_result__ = (result__); \ + if (!et_result__.ok()) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return et_result__.error(); \ + } \ + std::move(*et_result__); \ }) // Internal only: Use ET_UNWRAP() instead. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h index b671f340..903a6d27 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h @@ -32,62 +32,49 @@ namespace runtime { * This is intended to be trivially copyable, so it should be passed by * value. */ -template -class Span final { - public: - using iterator = T*; +template class Span final { +public: + using iterator = T *; using size_type = size_t; - public: +public: /// Construct an empty Span. /* implicit */ constexpr Span() noexcept : data_(nullptr), length_(0) {} /// Construct a Span from a pointer and length. - Span(T* data, size_t length) : data_(data), length_(length) { + Span(T *data, size_t length) : data_(data), length_(length) { ET_DCHECK(data_ != nullptr || length_ == 0); } /// Construct a Span from a range. - Span(T* begin, T* end) : data_(begin), length_(end - begin) {} + Span(T *begin, T *end) : data_(begin), length_(end - begin) {} /// Construct a Span from a C array. template /* implicit */ constexpr Span(T (&Arr)[N]) : data_(Arr), length_(N) {} /// @returns a pointer to the start of the underlying element buffer. - iterator begin() const noexcept { - return data_; - } + iterator begin() const noexcept { return data_; } /// @returns a pointer to the end of the underlying element buffer. - iterator end() const noexcept { - return data_ + length_; - } + iterator end() const noexcept { return data_ + length_; } /// @retval a boolean indicating if the Span is empty. - constexpr bool empty() const noexcept { - return length_ == 0; - } + constexpr bool empty() const noexcept { return length_ == 0; } /// @returns a pointer to the start of the underlying element buffer. - constexpr T* data() const noexcept { - return data_; - } + constexpr T *data() const noexcept { return data_; } /// @returns the number of elements in the Span. - constexpr size_t size() const noexcept { - return length_; - } + constexpr size_t size() const noexcept { return length_; } /// Unchecked index into the array according to the argument index. /// @returns a reference to the element at the specified index. - T& operator[](size_t index) const { - return data_[index]; - } + T &operator[](size_t index) const { return data_[index]; } - private: +private: /// The start of the array, in an external buffer. - T* data_; + T *data_; /// The number of elements. size_type length_; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h index 7dda80dd..8c329105 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h @@ -13,18 +13,18 @@ namespace executorch { namespace runtime { -#define EXECUTORCH_FORALL_TAGS(_) \ - _(None) \ - _(Tensor) \ - _(String) \ - _(Double) \ - _(Int) \ - _(Bool) \ - _(ListBool) \ - _(ListDouble) \ - _(ListInt) \ - _(ListTensor) \ - _(ListScalar) \ +#define EXECUTORCH_FORALL_TAGS(_) \ + _(None) \ + _(Tensor) \ + _(String) \ + _(Double) \ + _(Int) \ + _(Bool) \ + _(ListBool) \ + _(ListDouble) \ + _(ListInt) \ + _(ListTensor) \ + _(ListScalar) \ _(ListOptionalTensor) /** diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h index 1d3d7a6f..674d7022 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h @@ -28,7 +28,7 @@ namespace runtime { * and kernels use these provided allocators whenever possible. */ class MemoryManager final { - public: +public: /** * Constructs a new MemoryManager. * @@ -49,16 +49,13 @@ class MemoryManager final { * delegates that allocate temporary data. This allocator will be reset * after every kernel or delegate call during execution. */ - explicit MemoryManager( - MemoryAllocator* method_allocator, - HierarchicalAllocator* planned_memory = nullptr, - MemoryAllocator* temp_allocator = nullptr) - : method_allocator_(method_allocator), - planned_memory_(planned_memory), + explicit MemoryManager(MemoryAllocator *method_allocator, + HierarchicalAllocator *planned_memory = nullptr, + MemoryAllocator *temp_allocator = nullptr) + : method_allocator_(method_allocator), planned_memory_(planned_memory), temp_allocator_(temp_allocator) { - ET_CHECK_MSG( - method_allocator != temp_allocator, - "method allocator cannot be the same as temp allocator"); + ET_CHECK_MSG(method_allocator != temp_allocator, + "method allocator cannot be the same as temp allocator"); } /** @@ -71,10 +68,9 @@ class MemoryManager final { // bug that triggers a syntax error when using [[maybe_unused]] on the // first parameter of a constructor: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 - __attribute__((unused)) MemoryAllocator* constant_allocator, - HierarchicalAllocator* non_constant_allocator, - MemoryAllocator* runtime_allocator, - MemoryAllocator* temporary_allocator) + __attribute__((unused)) MemoryAllocator *constant_allocator, + HierarchicalAllocator *non_constant_allocator, + MemoryAllocator *runtime_allocator, MemoryAllocator *temporary_allocator) : MemoryManager( /*method_allocator=*/runtime_allocator, /*planned_memory=*/non_constant_allocator, @@ -85,16 +81,12 @@ class MemoryManager final { * structures while loading a Method. Must not be used after its associated * Method has been loaded. */ - MemoryAllocator* method_allocator() const { - return method_allocator_; - } + MemoryAllocator *method_allocator() const { return method_allocator_; } /** * Returns the memory-planned buffers to use for mutable tensor data. */ - HierarchicalAllocator* planned_memory() const { - return planned_memory_; - } + HierarchicalAllocator *planned_memory() const { return planned_memory_; } /** * Returns the allocator to use for allocating temporary data during kernel or @@ -103,14 +95,12 @@ class MemoryManager final { * This allocator will be reset after every kernel or delegate call during * execution. */ - MemoryAllocator* temp_allocator() const { - return temp_allocator_; - } + MemoryAllocator *temp_allocator() const { return temp_allocator_; } - private: - MemoryAllocator* method_allocator_; - HierarchicalAllocator* planned_memory_; - MemoryAllocator* temp_allocator_; +private: + MemoryAllocator *method_allocator_; + HierarchicalAllocator *planned_memory_; + MemoryAllocator *temp_allocator_; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h index 8b3330fb..06aaf5a8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h @@ -34,35 +34,30 @@ class Program; class BackendDelegate; struct Chain; class KernelRuntimeContext; -using OpFunction = void (*)(KernelRuntimeContext&, EValue**); +using OpFunction = void (*)(KernelRuntimeContext &, EValue **); /// A list of pointers into the master values table that together compose the /// argument list for a single instruction -using InstructionArgs = Span; +using InstructionArgs = Span; /** * An executable method of an executorch program. Maps to a python method like * `forward()` on the original nn.Module. */ class Method final { - public: +public: /** * Move ctor. Takes ownership of resources previously owned by `rhs`, * and leaves `rhs` in an uninitialized state. */ - Method(Method&& rhs) noexcept - : step_state_(rhs.step_state_), - program_(rhs.program_), + Method(Method &&rhs) noexcept + : step_state_(rhs.step_state_), program_(rhs.program_), memory_manager_(rhs.memory_manager_), temp_allocator_(rhs.temp_allocator_), serialization_plan_(rhs.serialization_plan_), - event_tracer_(rhs.event_tracer_), - n_value_(rhs.n_value_), - values_(rhs.values_), - n_delegate_(rhs.n_delegate_), - delegates_(rhs.delegates_), - n_chains_(rhs.n_chains_), - chains_(rhs.chains_), - init_state_(rhs.init_state_) { + event_tracer_(rhs.event_tracer_), n_value_(rhs.n_value_), + values_(rhs.values_), n_delegate_(rhs.n_delegate_), + delegates_(rhs.delegates_), n_chains_(rhs.n_chains_), + chains_(rhs.chains_), init_state_(rhs.init_state_) { // Required: clear out fields that the dtor looks at, so that we don't free // anything twice. rhs.n_value_ = 0; @@ -100,7 +95,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error set_input(const EValue& input_evalue, size_t input_idx); + ET_NODISCARD Error set_input(const EValue &input_evalue, size_t input_idx); /** * Sets the values of all method inputs. @@ -115,7 +110,7 @@ class Method final { * @returns Error::Ok on success, non-Ok on failure. */ ET_NODISCARD Error - set_inputs(const executorch::aten::ArrayRef& input_evalues); + set_inputs(const executorch::aten::ArrayRef &input_evalues); /** * Sets the data buffer of the specified method output to the provided value. @@ -136,8 +131,8 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error - set_output_data_ptr(void* buffer, size_t size, size_t output_idx); + ET_NODISCARD Error set_output_data_ptr(void *buffer, size_t size, + size_t output_idx); /** * Copies the method's outputs into the provided array. @@ -156,7 +151,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error get_outputs(EValue* output_evalues, size_t length); + ET_NODISCARD Error get_outputs(EValue *output_evalues, size_t length); /** * Copies the method's inputs into the provided array. @@ -172,7 +167,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error get_inputs(EValue* input_evalues, size_t length); + ET_NODISCARD Error get_inputs(EValue *input_evalues, size_t length); /** * Execute the method. @@ -228,27 +223,27 @@ class Method final { /** * Retrieves the output at the specified index. */ - const EValue& get_output(size_t i) const; + const EValue &get_output(size_t i) const; - EventTracer* get_event_tracer(); + EventTracer *get_event_tracer(); /// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to /// update Method inputs. - ET_DEPRECATED const EValue& get_input(size_t i) const; + ET_DEPRECATED const EValue &get_input(size_t i) const; /// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to /// update Method inputs. - ET_DEPRECATED EValue& mutable_input(size_t i); + ET_DEPRECATED EValue &mutable_input(size_t i); /// DEPRECATED: Use MethodMeta instead to access metadata, and get_output to /// retrieve Method outputs. - ET_DEPRECATED EValue& mutable_output(size_t i); + ET_DEPRECATED EValue &mutable_output(size_t i); ~Method(); - private: +private: // Delete other rule-of-five methods. - Method(const Method&) = delete; - Method& operator=(const Method&) noexcept = delete; - Method& operator=(Method&&) = delete; + Method(const Method &) = delete; + Method &operator=(const Method &) noexcept = delete; + Method &operator=(Method &&) = delete; // Let Program call load(). friend class Program; @@ -267,46 +262,33 @@ class Method final { size_t instr_idx; }; - Method( - const Program* program, - MemoryManager* memory_manager, - EventTracer* event_tracer, - MemoryAllocator* temp_allocator) - : step_state_(), - program_(program), - memory_manager_(memory_manager), - temp_allocator_(temp_allocator), - serialization_plan_(nullptr), - event_tracer_(event_tracer), - n_value_(0), - values_(nullptr), - n_delegate_(0), - delegates_(nullptr), - n_chains_(0), - chains_(nullptr), + Method(const Program *program, MemoryManager *memory_manager, + EventTracer *event_tracer, MemoryAllocator *temp_allocator) + : step_state_(), program_(program), memory_manager_(memory_manager), + temp_allocator_(temp_allocator), serialization_plan_(nullptr), + event_tracer_(event_tracer), n_value_(0), values_(nullptr), + n_delegate_(0), delegates_(nullptr), n_chains_(0), chains_(nullptr), init_state_(InitializationState::Uninitialized) {} /// Static factory used by Program. - ET_NODISCARD static Result load( - executorch_flatbuffer::ExecutionPlan* s_plan, - const Program* program, - MemoryManager* memory_manager, - EventTracer* event_tracer); + ET_NODISCARD static Result + load(executorch_flatbuffer::ExecutionPlan *s_plan, const Program *program, + MemoryManager *memory_manager, EventTracer *event_tracer); /** * Initialize the method from its serialized representation. * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan* s_plan); + ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan *s_plan); /// Returns true if the Method was successfully initialized. inline bool initialized() const { return init_state_ == InitializationState::Initialized; } - const EValue& get_value(size_t i) const; - EValue& mutable_value(size_t i); + const EValue &get_value(size_t i) const; + EValue &mutable_value(size_t i); size_t get_input_index(size_t i) const; size_t get_output_index(size_t i) const; @@ -314,20 +296,20 @@ class Method final { ET_NODISCARD Error execute_instruction(); StepState step_state_; - const Program* program_; - MemoryManager* memory_manager_; - MemoryAllocator* temp_allocator_; - executorch_flatbuffer::ExecutionPlan* serialization_plan_; - EventTracer* event_tracer_; + const Program *program_; + MemoryManager *memory_manager_; + MemoryAllocator *temp_allocator_; + executorch_flatbuffer::ExecutionPlan *serialization_plan_; + EventTracer *event_tracer_; size_t n_value_; - EValue* values_; + EValue *values_; size_t n_delegate_; - BackendDelegate* delegates_; + BackendDelegate *delegates_; size_t n_chains_; - Chain* chains_; + Chain *chains_; InitializationState init_state_; @@ -338,12 +320,9 @@ class Method final { */ ET_NODISCARD Error parse_values(); - ET_NODISCARD Error resolve_operator( - int32_t op_index, - OpFunction* kernels, - size_t kernel_index, - InstructionArgs args, - size_t n_args); + ET_NODISCARD Error resolve_operator(int32_t op_index, OpFunction *kernels, + size_t kernel_index, InstructionArgs args, + size_t n_args); void log_outputs(); }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h index 569b93c0..08644d20 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h @@ -29,12 +29,12 @@ namespace runtime { * TensorInfo must outlive this TensorInfo. */ class TensorInfo final { - public: +public: TensorInfo() = delete; - TensorInfo(const TensorInfo&) = default; - TensorInfo(TensorInfo&&) = default; - TensorInfo& operator=(const TensorInfo&) = default; - TensorInfo& operator=(TensorInfo&& other) = default; + TensorInfo(const TensorInfo &) = default; + TensorInfo(TensorInfo &&) = default; + TensorInfo &operator=(const TensorInfo &) = default; + TensorInfo &operator=(TensorInfo &&other) = default; ~TensorInfo() = default; /** @@ -62,15 +62,13 @@ class TensorInfo final { */ size_t nbytes() const; - private: +private: // Let MethodMeta create TensorInfo. friend class MethodMeta; - TensorInfo( - Span sizes, - Span dim_order, - executorch::aten::ScalarType scalar_type, - const bool is_memory_planned); + TensorInfo(Span sizes, Span dim_order, + executorch::aten::ScalarType scalar_type, + const bool is_memory_planned); /** * The sizes of the tensor. @@ -106,12 +104,12 @@ class TensorInfo final { * paying the initialization cost of loading the full Method. */ class MethodMeta final { - public: +public: MethodMeta() = delete; - MethodMeta(const MethodMeta&) = default; - MethodMeta(MethodMeta&&) = default; - MethodMeta& operator=(const MethodMeta&) = default; - MethodMeta& operator=(MethodMeta&& other) = default; + MethodMeta(const MethodMeta &) = default; + MethodMeta(MethodMeta &&) = default; + MethodMeta &operator=(const MethodMeta &) = default; + MethodMeta &operator=(MethodMeta &&other) = default; ~MethodMeta() = default; /** @@ -119,7 +117,7 @@ class MethodMeta final { * * @returns The method name. */ - const char* name() const; + const char *name() const; /** * Get the number of inputs to this method. @@ -199,14 +197,14 @@ class MethodMeta final { return memory_planned_buffer_size(index); } - private: +private: // Let Program create MethodMeta. friend class Program; - explicit MethodMeta(const executorch_flatbuffer::ExecutionPlan* s_plan); + explicit MethodMeta(const executorch_flatbuffer::ExecutionPlan *s_plan); /// Source of truth for method information - const executorch_flatbuffer::ExecutionPlan* s_plan_; + const executorch_flatbuffer::ExecutionPlan *s_plan_; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h index f7469eb2..3c4e30ef 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h @@ -44,7 +44,7 @@ class TensorParser; * A deserialized ExecuTorch program binary. */ class Program final { - public: +public: /** * Types of validation that the Program can do before parsing the data. */ @@ -78,19 +78,17 @@ class Program final { * @param[in] verification The type of verification to do before returning * success. */ - ET_NODISCARD static Result load( - DataLoader* loader, - Verification verification = Verification::Minimal); + ET_NODISCARD static Result + load(DataLoader *loader, Verification verification = Verification::Minimal); /// DEPRECATED: Use the lowercase `load()` instead. - ET_DEPRECATED ET_NODISCARD static Result Load( - DataLoader* loader, - Verification verification = Verification::Minimal) { + ET_DEPRECATED ET_NODISCARD static Result + Load(DataLoader *loader, Verification verification = Verification::Minimal) { return load(loader, verification); } // Movable, to be compatible with Result. - Program(Program&&) noexcept = default; + Program(Program &&) noexcept = default; ~Program() = default; /** @@ -99,8 +97,8 @@ class Program final { * @param[in] nbytes the number of bytes to read from the buffer. * @return The buffer with corresponding index. */ - Result get_constant_buffer_data(size_t buffer_idx, size_t nbytes) - const; + Result get_constant_buffer_data(size_t buffer_idx, + size_t nbytes) const; /** * Returns the number of methods in the program. @@ -116,7 +114,7 @@ class Program final { * @returns The name of the requested method. The pointer is owned by the * Program, and has the same lifetime as the Program. */ - Result get_method_name(size_t method_index) const; + Result get_method_name(size_t method_index) const; /** * Loads the named method and prepares it for execution. @@ -129,17 +127,16 @@ class Program final { * * @returns The loaded method on success, or an error on failure. */ - Result load_method( - const char* method_name, - MemoryManager* memory_manager, - EventTracer* event_tracer = nullptr) const; + Result load_method(const char *method_name, + MemoryManager *memory_manager, + EventTracer *event_tracer = nullptr) const; /** * Gathers metadata for the named method. * * @param[in] method_name The name of the method to get metadata for. */ - Result method_meta(const char* method_name) const; + Result method_meta(const char *method_name) const; /** * DEPRECATED: Get the pytree encoding string for the output. Deprecated as @@ -149,8 +146,8 @@ class Program final { * * @return The pytree encoding string for the output */ - ET_DEPRECATED Result get_output_flattening_encoding( - const char* method_name = "forward") const; + ET_DEPRECATED Result + get_output_flattening_encoding(const char *method_name = "forward") const; /** * Describes the presence of an ExecuTorch program header. @@ -193,9 +190,9 @@ class Program final { * * @returns A value describing the presence of a header in the data. */ - static HeaderStatus check_header(const void* data, size_t size); + static HeaderStatus check_header(const void *data, size_t size); - private: +private: // Let some classes call these private methods. friend class BackendDelegate; friend class Executor; @@ -203,15 +200,13 @@ class Program final { friend class deserialization::TensorParser; friend class testing::ProgramTestFriend; - const executorch_flatbuffer::Program* get_internal_program() const { + const executorch_flatbuffer::Program *get_internal_program() const { return internal_program_; } // Used by Method to look up entries in the delegate data table. - Error get_backend_delegate_data( - size_t index, - const void** out_data, - size_t* out_size) const; + Error get_backend_delegate_data(size_t index, const void **out_data, + size_t *out_size) const; /** * Loads a segment by index. @@ -227,8 +222,8 @@ class Program final { * DataLoader: The Program.segment table is inconsistent, or the * data cannot be accessed. */ - ET_NODISCARD Result LoadSegment( - const DataLoader::SegmentInfo& segment_info) const; + ET_NODISCARD Result + LoadSegment(const DataLoader::SegmentInfo &segment_info) const; /** * Loads a portion of a mutable segment into the provided buffer. @@ -249,18 +244,14 @@ class Program final { * data cannot be accessed. */ ET_NODISCARD Error load_mutable_subsegment_into( - size_t mutable_data_segments_index, - size_t offset_index, - size_t size, - void* buffer) const; - - private: - Program( - DataLoader* loader, - size_t segment_base_offset, - FreeableBuffer&& program_data, - const executorch_flatbuffer::Program* internal_program, - FreeableBuffer&& constant_segment_data) + size_t mutable_data_segments_index, size_t offset_index, size_t size, + void *buffer) const; + +private: + Program(DataLoader *loader, size_t segment_base_offset, + FreeableBuffer &&program_data, + const executorch_flatbuffer::Program *internal_program, + FreeableBuffer &&constant_segment_data) : program_data_(std::move(program_data)), // Don't need the loader if there are no segments. loader_(segment_base_offset > 0 ? loader : nullptr), @@ -269,19 +260,19 @@ class Program final { constant_segment_data_(std::move(constant_segment_data)) {} // Not copyable or assignable. - Program(const Program& rhs) = delete; - Program& operator=(Program&& rhs) noexcept = delete; - Program& operator=(const Program& rhs) = delete; + Program(const Program &rhs) = delete; + Program &operator=(Program &&rhs) noexcept = delete; + Program &operator=(const Program &rhs) = delete; /// The serialized program data. Tensors will point directly into this buffer. FreeableBuffer program_data_; /// Used to load segment data. Null if there are no segments. - DataLoader* loader_; + DataLoader *loader_; /// The flatbuffer representation of the program. Must not be exposed to /// users. - const executorch_flatbuffer::Program* internal_program_; + const executorch_flatbuffer::Program *internal_program_; /// The offset to the first segment, in bytes. If zero, no segments should /// be present in internal_program_. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h index 1d860bfc..cd6e89e9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h @@ -18,31 +18,26 @@ namespace executorch { namespace runtime { namespace deserialization { -ET_NODISCARD Result parseTensor( - const Program* program, - MemoryManager* memory_manager, - const executorch_flatbuffer::Tensor* s_tensor); +ET_NODISCARD Result +parseTensor(const Program *program, MemoryManager *memory_manager, + const executorch_flatbuffer::Tensor *s_tensor); -ET_NODISCARD Result> parseTensorList( - const flatbuffers::Vector* tensor_indices, - EValue* values_, - MemoryManager* memory_manager); +ET_NODISCARD Result> +parseTensorList(const flatbuffers::Vector *tensor_indices, + EValue *values_, MemoryManager *memory_manager); // Deserializes a List of optional type. The code here is the same between all // list of optionals: list of optional Tensor, list of optional float etc, so we // just use a template to avoid boilerplate. template ET_NODISCARD Result>> -parseListOptionalType( - const flatbuffers::Vector* value_indices, - EValue* values_, - MemoryManager* memory_manager) { - auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( - memory_manager->method_allocator(), EValue*, value_indices->size()); +parseListOptionalType(const flatbuffers::Vector *value_indices, + EValue *values_, MemoryManager *memory_manager) { + auto *evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( + memory_manager->method_allocator(), EValue *, value_indices->size()); - auto* optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( - memory_manager->method_allocator(), - executorch::aten::optional, + auto *optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( + memory_manager->method_allocator(), executorch::aten::optional, value_indices->size()); size_t output_idx = 0; @@ -92,11 +87,10 @@ parseListOptionalType( * @returns On success, the data pointer to use for the tensor. On failure, a * non-Ok Error. */ -ET_NODISCARD Result getTensorDataPtr( - const executorch_flatbuffer::Tensor* s_tensor, - const Program* program, - size_t nbytes, - HierarchicalAllocator* allocator); +ET_NODISCARD Result +getTensorDataPtr(const executorch_flatbuffer::Tensor *s_tensor, + const Program *program, size_t nbytes, + HierarchicalAllocator *allocator); } // namespace deserialization } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h index 96ad3d51..e6367da9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h @@ -24,7 +24,7 @@ namespace runtime { * operators do not expect to receive a KernelRuntimeContext argument. */ class KernelRuntimeContext { - public: +public: /** * Construct a new kernel runtime context. * @@ -37,9 +37,8 @@ class KernelRuntimeContext { * temporary memory for the kernel. If not provided, an error will be * returned when calling allocate_temp. */ - KernelRuntimeContext( - EventTracer* event_tracer = nullptr, - MemoryAllocator* temp_allocator = nullptr) + KernelRuntimeContext(EventTracer *event_tracer = nullptr, + MemoryAllocator *temp_allocator = nullptr) : event_tracer_(event_tracer), temp_allocator_(temp_allocator) {} /** * Tells the runtime that the kernel call has failed. Prefer this over @@ -53,14 +52,10 @@ class KernelRuntimeContext { * compatible with core PyTorch ATen kernel signatures, which use exceptions * to report errors. But, ExecuTorch does not use exceptions. */ - void fail(Error error) { - failure_state_ = error; - } + void fail(Error error) { failure_state_ = error; } /// Returns the current failure state. - ET_NODISCARD Error failure_state() const { - return failure_state_; - } + ET_NODISCARD Error failure_state() const { return failure_state_; } /** * INTERNAL ONLY @@ -69,9 +64,7 @@ class KernelRuntimeContext { * logging inside the codegen layer. This is only for internal usage inside * the codegen layer and users should not be accessing this. */ - EventTracer* internal_event_tracer() { - return event_tracer_; - } + EventTracer *internal_event_tracer() { return event_tracer_; } /** * Allocates temporary memory that will be freed when the kernel returns. This @@ -85,25 +78,23 @@ class KernelRuntimeContext { * @returns A result object containing either a pointer to the allocated * memory or an error to indicate failure */ - Result allocate_temp( - size_t size, - size_t alignment = MemoryAllocator::kDefaultAlignment) { - ET_CHECK_OR_RETURN_ERROR( - temp_allocator_ != nullptr, NotFound, "No temp allocator provided"); - void* temp_memory = temp_allocator_->allocate(size, alignment); + Result + allocate_temp(size_t size, + size_t alignment = MemoryAllocator::kDefaultAlignment) { + ET_CHECK_OR_RETURN_ERROR(temp_allocator_ != nullptr, NotFound, + "No temp allocator provided"); + void *temp_memory = temp_allocator_->allocate(size, alignment); ET_CHECK_OR_RETURN_ERROR( - temp_memory != nullptr, - MemoryAllocationFailed, - "Failed to allocate temp memory. Bytes requested: %zu", - size); + temp_memory != nullptr, MemoryAllocationFailed, + "Failed to allocate temp memory. Bytes requested: %zu", size); return temp_memory; } // TODO(T147221312): Add a way to resize a tensor. - private: - EventTracer* event_tracer_ = nullptr; - MemoryAllocator* temp_allocator_ = nullptr; +private: + EventTracer *event_tracer_ = nullptr; + MemoryAllocator *temp_allocator_ = nullptr; Error failure_state_ = Error::Ok; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h index e4c5d670..095a6742 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h @@ -24,26 +24,23 @@ #include #endif -#define ET_LOG_KERNEL_KEY(k) \ - ET_LOG( \ - Error, \ - "key: %s, is_fallback: %s", \ - k.data(), \ - k.is_fallback() ? "true" : "false"); -#define ET_LOG_TENSOR_META(meta_list) \ - for (const auto& meta : meta_list) { \ - ET_LOG(Error, "dtype: %d | dim order: [", int(meta.dtype_)); \ - for (int i = 0; i < meta.dim_order_.size(); i++) { \ - ET_LOG(Error, "%d,", static_cast(meta.dim_order_[i])); \ - } \ - ET_LOG(Error, "]"); \ +#define ET_LOG_KERNEL_KEY(k) \ + ET_LOG(Error, "key: %s, is_fallback: %s", k.data(), \ + k.is_fallback() ? "true" : "false"); +#define ET_LOG_TENSOR_META(meta_list) \ + for (const auto &meta : meta_list) { \ + ET_LOG(Error, "dtype: %d | dim order: [", int(meta.dtype_)); \ + for (int i = 0; i < meta.dim_order_.size(); i++) { \ + ET_LOG(Error, "%d,", static_cast(meta.dim_order_[i])); \ + } \ + ET_LOG(Error, "]"); \ } namespace executorch { namespace runtime { class KernelRuntimeContext; // Forward declaration -using OpFunction = void (*)(KernelRuntimeContext&, EValue**); +using OpFunction = void (*)(KernelRuntimeContext &, EValue **); /** * Dtype and dim order metadata for a Tensor argument to an operator. @@ -54,20 +51,17 @@ struct TensorMeta { Span dim_order_; TensorMeta() = default; - TensorMeta( - executorch::aten::ScalarType dtype, - Span order) + TensorMeta(executorch::aten::ScalarType dtype, + Span order) : dtype_(dtype), dim_order_(order) {} - bool operator==(const TensorMeta& other) const { - return this->equals(other); - } + bool operator==(const TensorMeta &other) const { return this->equals(other); } - bool operator!=(const TensorMeta& other) const { + bool operator!=(const TensorMeta &other) const { return !this->equals(other); } - bool equals(const TensorMeta& other) const { + bool equals(const TensorMeta &other) const { if (dtype_ != other.dtype_) { return false; } @@ -83,7 +77,7 @@ struct TensorMeta { } #if defined(ET_OP_REGISTRY_DEBUG) - friend std::ostream& operator<<(std::ostream& os, const TensorMeta& meta) { + friend std::ostream &operator<<(std::ostream &os, const TensorMeta &meta) { os << "dtype: " << int(meta.dtype_) << " | dim order: ["; for (int i = 0; i < meta.dim_order_.size(); i++) { os << static_cast(meta.dim_order_[i]) << ", "; @@ -121,23 +115,19 @@ struct TensorMeta { * generated from kernel yaml. */ struct KernelKey { - public: +public: KernelKey() : is_fallback_(true) {} - /* implicit */ KernelKey(const char* kernel_key_data) + /* implicit */ KernelKey(const char *kernel_key_data) : kernel_key_data_(kernel_key_data), is_fallback_(false) {} constexpr static int MAX_SIZE = 691; - bool operator==(const KernelKey& other) const { - return this->equals(other); - } + bool operator==(const KernelKey &other) const { return this->equals(other); } - bool operator!=(const KernelKey& other) const { - return !this->equals(other); - } + bool operator!=(const KernelKey &other) const { return !this->equals(other); } - bool equals(const KernelKey& other) const { + bool equals(const KernelKey &other) const { if (is_fallback_ != other.is_fallback_) { return false; } @@ -147,23 +137,19 @@ struct KernelKey { return strncmp(kernel_key_data_, other.kernel_key_data_, MAX_SIZE) == 0; } - bool is_fallback() const { - return is_fallback_; - } + bool is_fallback() const { return is_fallback_; } - const char* data() const { - return kernel_key_data_; - } + const char *data() const { return kernel_key_data_; } #if defined(ET_OP_REGISTRY_DEBUG) - friend std::ostream& operator<<(std::ostream& os, const KernelKey& key) { + friend std::ostream &operator<<(std::ostream &os, const KernelKey &key) { os << key.kernel_key_data_ << std::endl; return os; } #endif - private: - const char* kernel_key_data_ = nullptr; +private: + const char *kernel_key_data_ = nullptr; bool is_fallback_; }; @@ -174,7 +160,7 @@ struct KernelKey { * kernel may or may not live in an `Operator`. */ struct Kernel { - const char* name_; + const char *name_; // String representation of kernel key, with the same format as // KernelKey.to_string_representation() // Data is not owned by the Kernel struct. @@ -185,16 +171,16 @@ struct Kernel { * itself, we require the lifetime of the operator name to be at least as long * as the operator registry. */ - explicit Kernel(const char* name, OpFunction func) : name_(name), op_(func) {} + explicit Kernel(const char *name, OpFunction func) : name_(name), op_(func) {} - explicit Kernel(const char* name, KernelKey key, OpFunction func) + explicit Kernel(const char *name, KernelKey key, OpFunction func) : name_(name), kernel_key_(key), op_(func) {} Kernel() {} }; namespace internal { -void make_kernel_key_string(Span key, char* buf); +void make_kernel_key_string(Span key, char *buf); } // namespace internal /** @@ -202,16 +188,15 @@ void make_kernel_key_string(Span key, char* buf); * TensorMeta is empty, it means this op does not have specialized kernels, so * it checks whether it has any fallback kernels. */ -bool registry_has_op_function( - const char* name, - Span meta_list = {}); +bool registry_has_op_function(const char *name, + Span meta_list = {}); /** * Returns the operator with a given name and TensorMeta list, if present. */ -::executorch::runtime::Result get_op_function_from_registry( - const char* name, - Span meta_list = {}); +::executorch::runtime::Result +get_op_function_from_registry(const char *name, + Span meta_list = {}); /** * Returns all registered kernels. @@ -234,7 +219,7 @@ ET_NODISCARD Error register_kernels(const Span); * @retval Error::Ok always. Panics on error. This function needs to return a * non-void type to run at static initialization time. */ -ET_NODISCARD inline Error register_kernel(const Kernel& kernel) { +ET_NODISCARD inline Error register_kernel(const Kernel &kernel) { return register_kernels({&kernel, 1}); }; @@ -256,15 +241,14 @@ inline ::executorch::runtime::Error register_kernels(ArrayRef kernels) { return ::executorch::runtime::register_kernels( {kernels.data(), kernels.size()}); } -inline OpFunction getOpsFn( - const char* name, - ArrayRef meta_list = {}) { +inline OpFunction getOpsFn(const char *name, + ArrayRef meta_list = {}) { auto result = ::executorch::runtime::get_op_function_from_registry( name, {meta_list.data(), meta_list.size()}); ET_CHECK(result.ok()); // get_op_function_from_registry() logs details. return *result; } -inline bool hasOpsFn(const char* name, ArrayRef meta_list = {}) { +inline bool hasOpsFn(const char *name, ArrayRef meta_list = {}) { return ::executorch::runtime::registry_has_op_function( name, {meta_list.data(), meta_list.size()}); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h index 3a574334..88d67f76 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h @@ -18,12 +18,9 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_ASSERT_MESSAGE_EMIT(_format, ...) \ - ET_LOG( \ - Fatal, \ - "In function %s(), assert failed" _format, \ - ET_FUNCTION, \ - ##__VA_ARGS__) +#define ET_ASSERT_MESSAGE_EMIT(_format, ...) \ + ET_LOG(Fatal, "In function %s(), assert failed" _format, ET_FUNCTION, \ + ##__VA_ARGS__) /** * Abort the runtime if the condition is not true. @@ -33,12 +30,12 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_CHECK_MSG(_cond, _format, ...) \ - ({ \ - if ET_UNLIKELY (!(_cond)) { \ - ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \ - ::executorch::runtime::runtime_abort(); \ - } \ +#define ET_CHECK_MSG(_cond, _format, ...) \ + ({ \ + if ET_UNLIKELY (!(_cond)) { \ + ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \ + ::executorch::runtime::runtime_abort(); \ + } \ }) /** @@ -47,12 +44,12 @@ * * @param[in] _cond Condition asserted as true. */ -#define ET_CHECK(_cond) \ - ({ \ - if ET_UNLIKELY (!(_cond)) { \ - ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \ - ::executorch::runtime::runtime_abort(); \ - } \ +#define ET_CHECK(_cond) \ + ({ \ + if ET_UNLIKELY (!(_cond)) { \ + ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \ + ::executorch::runtime::runtime_abort(); \ + } \ }) #ifdef NDEBUG @@ -85,7 +82,7 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_DCHECK_MSG(_cond, _format, ...) \ +#define ET_DCHECK_MSG(_cond, _format, ...) \ ET_CHECK_MSG(_cond, _format, ##__VA_ARGS__) /** @@ -101,10 +98,10 @@ /** * Assert that this code location is unreachable during execution. */ -#define ET_ASSERT_UNREACHABLE() \ - ({ \ - ET_CHECK_MSG(false, "Execution should not reach this point"); \ - ET_UNREACHABLE(); \ +#define ET_ASSERT_UNREACHABLE() \ + ({ \ + ET_CHECK_MSG(false, "Execution should not reach this point"); \ + ET_UNREACHABLE(); \ }) /** @@ -112,9 +109,9 @@ * * @param[in] _message Message on how to avoid this assertion error. */ -#define ET_ASSERT_UNREACHABLE_MSG(_message) \ - ({ \ - ET_CHECK_MSG( \ - false, "Execution should not reach this point. %s", _message); \ - ET_UNREACHABLE(); \ +#define ET_ASSERT_UNREACHABLE_MSG(_message) \ + ({ \ + ET_CHECK_MSG(false, "Execution should not reach this point. %s", \ + _message); \ + ET_UNREACHABLE(); \ }) diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h index b6f7fc86..bdccebd1 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h @@ -19,25 +19,25 @@ */ // https://gcc.gnu.org/projects/cxx-status.html#cxx17 -#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \ +#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \ __GNUC__ < 7 -#error \ +#error \ "You're trying to build ExecuTorch with a too old version of GCC. We need GCC 7 or later." #endif // https://clang.llvm.org/cxx_status.html#cxx17 #if defined(__clang__) && __clang_major__ < 5 -#error \ +#error \ "You're trying to build ExecuTorch with a too old version of Clang. We need Clang 5 or later." #endif -#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ +#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ (!defined(_MSC_VER) && __cplusplus < 201703L) #error "You need C++17 to compile ExecuTorch" #endif #if defined(_WIN32) && (defined(min) || defined(max)) -#error \ +#error \ "Macro clash with min and max -- define NOMINMAX when compiling your program on Windows" #endif @@ -69,8 +69,8 @@ #else // defined(__GNUC__) -#define ET_UNREACHABLE() \ - while (1) \ +#define ET_UNREACHABLE() \ + while (1) \ ; #endif // defined(__GNUC__) @@ -78,7 +78,7 @@ #if (__cplusplus) >= 201703L #define ET_DEPRECATED [[deprecated]] -#define ET_EXPERIMENTAL \ +#define ET_EXPERIMENTAL \ [[deprecated("This API is experimental and may change without notice.")]] #define ET_FALLTHROUGH [[fallthrough]] #define ET_NODISCARD [[nodiscard]] @@ -87,8 +87,8 @@ #else #define ET_DEPRECATED __attribute__((deprecated)) -#define ET_EXPERIMENTAL \ - __attribute__(( \ +#define ET_EXPERIMENTAL \ + __attribute__(( \ deprecated("This API is experimental and may change without notice."))) #define ET_FALLTHROUGH __attribute__((fallthrough)) #define ET_NODISCARD __attribute__((warn_unused_result)) @@ -120,7 +120,7 @@ * Annotation marking a function as printf-like, providing compiler support * for format string argument checking. */ -#define ET_PRINTFLIKE(_string_index, _va_index) \ +#define ET_PRINTFLIKE(_string_index, _va_index) \ __attribute__((format(printf, _string_index, _va_index))) /// Name of the source file without a directory string. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h index 2b1e791b..7f95bbc0 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h @@ -95,14 +95,8 @@ et_timestamp_t get_log_timestamp(); * @param[in] args Variable argument list. */ ET_PRINTFLIKE(6, 0) -void vlogf( - LogLevel level, - et_timestamp_t timestamp, - const char* filename, - const char* function, - size_t line, - const char* format, - va_list args); +void vlogf(LogLevel level, et_timestamp_t timestamp, const char *filename, + const char *function, size_t line, const char *format, va_list args); /** * Log a string message. @@ -117,14 +111,8 @@ void vlogf( * @param[in] format Format string. */ ET_PRINTFLIKE(6, 7) -inline void logf( - LogLevel level, - et_timestamp_t timestamp, - const char* filename, - const char* function, - size_t line, - const char* format, - ...) { +inline void logf(LogLevel level, et_timestamp_t timestamp, const char *filename, + const char *function, size_t line, const char *format, ...) { #if ET_LOG_ENABLED va_list args; va_start(args, format); @@ -154,23 +142,18 @@ using ::executorch::runtime::LogLevel; * @param[in] _level Log severity level. * @param[in] _format Log message format string. */ -#define ET_LOG(_level, _format, ...) \ - ({ \ - const auto _log_level = ::executorch::runtime::LogLevel::_level; \ - if (static_cast(_log_level) >= \ - static_cast( \ - ::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \ - const auto _timestamp = \ - ::executorch::runtime::internal::get_log_timestamp(); \ - ::executorch::runtime::internal::logf( \ - _log_level, \ - _timestamp, \ - ET_SHORT_FILENAME, \ - ET_FUNCTION, \ - ET_LINE, \ - _format, \ - ##__VA_ARGS__); \ - } \ +#define ET_LOG(_level, _format, ...) \ + ({ \ + const auto _log_level = ::executorch::runtime::LogLevel::_level; \ + if (static_cast(_log_level) >= \ + static_cast( \ + ::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \ + const auto _timestamp = \ + ::executorch::runtime::internal::get_log_timestamp(); \ + ::executorch::runtime::internal::logf(_log_level, _timestamp, \ + ET_SHORT_FILENAME, ET_FUNCTION, \ + ET_LINE, _format, ##__VA_ARGS__); \ + } \ }) #else // ET_LOG_ENABLED diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h index 03cdef8e..c5cf1dd1 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h @@ -79,8 +79,8 @@ et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS; * * @retval The ratio of nanoseconds to system ticks. */ -et_tick_ratio_t et_pal_ticks_to_ns_multiplier(void) - ET_INTERNAL_PLATFORM_WEAKNESS; +et_tick_ratio_t +et_pal_ticks_to_ns_multiplier(void) ET_INTERNAL_PLATFORM_WEAKNESS; /** * Severity level of a log message. Values must map to printable 7-bit ASCII @@ -106,14 +106,10 @@ typedef enum { * @param[in] message Message string to log. * @param[in] length Message string length. */ -void et_pal_emit_log_message( - et_timestamp_t timestamp, - et_pal_log_level_t level, - const char* filename, - const char* function, - size_t line, - const char* message, - size_t length) ET_INTERNAL_PLATFORM_WEAKNESS; +void et_pal_emit_log_message(et_timestamp_t timestamp, et_pal_log_level_t level, + const char *filename, const char *function, + size_t line, const char *message, + size_t length) ET_INTERNAL_PLATFORM_WEAKNESS; /** * NOTE: Core runtime code must not call this directly. It may only be called by @@ -125,13 +121,13 @@ void et_pal_emit_log_message( * @returns the allocated memory, or nullptr on failure. Must be freed using * et_pal_free(). */ -void* et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS; +void *et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS; /** * Frees memory allocated by et_pal_allocate(). * * @param[in] ptr Pointer to memory to free. May be nullptr. */ -void et_pal_free(void* ptr) ET_INTERNAL_PLATFORM_WEAKNESS; +void et_pal_free(void *ptr) ET_INTERNAL_PLATFORM_WEAKNESS; } // extern "C" diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h index 07ffd9c3..72f69b3d 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h @@ -50,7 +50,7 @@ namespace runtime { typedef struct alignas(8) { union { - const char* name_str; + const char *name_str; char name[PROF_NAME_MAX_LEN]; }; // chain_idx == -1 is a null value, when profile event happens out of chain @@ -72,7 +72,7 @@ typedef struct alignas(8) { } prof_allocator_t; typedef struct alignas(8) { - uint8_t* prof_data; + uint8_t *prof_data; uint32_t num_bytes; uint32_t num_blocks; } prof_result_t; @@ -103,8 +103,8 @@ This is what the layout of the profiling buffer looks like. // offsets of the various sections in the profiling buffer // Total size required for profiling buffer -constexpr uint32_t prof_buf_size = sizeof(prof_header_t) + - sizeof(prof_event_t) * MAX_PROFILE_EVENTS + +constexpr uint32_t prof_buf_size = + sizeof(prof_header_t) + sizeof(prof_event_t) * MAX_PROFILE_EVENTS + sizeof(mem_prof_event_t) * MAX_MEM_PROFILE_EVENTS + sizeof(prof_allocator_t) * MEM_PROFILE_MAX_ALLOCATORS; @@ -112,7 +112,8 @@ constexpr size_t prof_header_offset = 0; constexpr size_t prof_events_offset = sizeof(prof_header_t); constexpr size_t prof_mem_alloc_info_offset = prof_events_offset + sizeof(prof_event_t) * MAX_PROFILE_EVENTS; -constexpr size_t prof_mem_alloc_events_offset = prof_mem_alloc_info_offset + +constexpr size_t prof_mem_alloc_events_offset = + prof_mem_alloc_info_offset + sizeof(prof_allocator_t) * MEM_PROFILE_MAX_ALLOCATORS; // Set the initial state for the profiler assuming we're using the @@ -121,33 +122,33 @@ void profiler_init(void); // This starts the profiling of this event and returns a token // by which this event can be referred to in the future. -uint32_t begin_profiling(const char* name); +uint32_t begin_profiling(const char *name); // End profiling event represented by token_id void end_profiling(uint32_t token_id); // Dump profiler results, return pointer to prof event array and number of // events in it. -void dump_profile_stats(prof_result_t* prof_result); +void dump_profile_stats(prof_result_t *prof_result); void reset_profile_stats(); void track_allocation(int32_t id, uint32_t size); -uint32_t track_allocator(const char* name); +uint32_t track_allocator(const char *name); -void profiling_create_block(const char* name); +void profiling_create_block(const char *name); // This class enables scope based profiling where needed. Profiling // will be started when the object is created and will end when the // object goes out of scope. class ExecutorchProfiler { - public: - explicit ExecutorchProfiler(const char* name); +public: + explicit ExecutorchProfiler(const char *name); ~ExecutorchProfiler(); - private: +private: uint32_t prof_tok; }; @@ -156,27 +157,27 @@ typedef struct { uint32_t instruction_idx; } prof_state_t; -const prof_state_t& get_profile_tls_state(); +const prof_state_t &get_profile_tls_state(); -void set_profile_tls_state(const prof_state_t& state); +void set_profile_tls_state(const prof_state_t &state); class ExecutorchProfilerInstructionScope { - public: - explicit ExecutorchProfilerInstructionScope(const prof_state_t& state); +public: + explicit ExecutorchProfilerInstructionScope(const prof_state_t &state); ~ExecutorchProfilerInstructionScope(); // ScopeGuard: non-copyable, non-movable ExecutorchProfilerInstructionScope( - const ExecutorchProfilerInstructionScope&) = delete; - ExecutorchProfilerInstructionScope& operator=( - const ExecutorchProfilerInstructionScope&) = delete; + const ExecutorchProfilerInstructionScope &) = delete; + ExecutorchProfilerInstructionScope & + operator=(const ExecutorchProfilerInstructionScope &) = delete; - ExecutorchProfilerInstructionScope(ExecutorchProfilerInstructionScope&&) = + ExecutorchProfilerInstructionScope(ExecutorchProfilerInstructionScope &&) = delete; - ExecutorchProfilerInstructionScope& operator=( - ExecutorchProfilerInstructionScope&&) = delete; + ExecutorchProfilerInstructionScope & + operator=(ExecutorchProfilerInstructionScope &&) = delete; - private: +private: prof_state_t old_state_; }; @@ -215,70 +216,72 @@ using ::executorch::runtime::track_allocator; #ifdef PROFILING_ENABLED -#define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \ +#define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \ ::executorch::runtime::profiling_create_block(name); // Convenience macros to begin and end profiling. These can be inserted // anywhere as it'll be ensured that for the prod builds these will // essentially be noops. -#define EXECUTORCH_BEGIN_PROF(name) \ +#define EXECUTORCH_BEGIN_PROF(name) \ ::executorch::runtime::begin_profiling(name); -#define EXECUTORCH_END_PROF(token_id) \ +#define EXECUTORCH_END_PROF(token_id) \ ::executorch::runtime::end_profiling(token_id); -#define EXECUTORCH_SCOPE_PROF(name) \ +#define EXECUTORCH_SCOPE_PROF(name) \ ::executorch::runtime::ExecutorchProfiler profiler(name); -#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ - ::executorch::runtime::ExecutorchProfilerInstructionScope \ +#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ + ::executorch::runtime::ExecutorchProfilerInstructionScope \ __profiler_instruction_scope({chain_idx, instruction_idx}); -#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \ +#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \ ::executorch::runtime::dump_profile_stats(prof_result); -#define EXECUTORCH_RESET_PROFILE_RESULTS() \ +#define EXECUTORCH_RESET_PROFILE_RESULTS() \ ::executorch::runtime::reset_profile_stats(); -#define EXECUTORCH_TRACK_ALLOCATOR(name) \ +#define EXECUTORCH_TRACK_ALLOCATOR(name) \ ::executorch::runtime::track_allocator(name); -#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ +#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ ::executorch::runtime::track_allocation(id, size); #else #define EXECUTORCH_PROFILE_CREATE_BLOCK(name) ({ (void)(name); }) -#define EXECUTORCH_BEGIN_PROF(name) \ - {} +#define EXECUTORCH_BEGIN_PROF(name) \ + { \ + } #define EXECUTORCH_END_PROF(token_id) ({ (void)(token_id); }) #define EXECUTORCH_SCOPE_PROF(name) ({ (void)(name); }) -#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ - ({ \ - (void)(chain_idx); \ - (void)(instruction_idx); \ +#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ + ({ \ + (void)(chain_idx); \ + (void)(instruction_idx); \ }) -#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \ +#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \ memset(prof_result_test, 0, sizeof(::executorch::runtime::prof_result_t)); -#define EXECUTORCH_RESET_PROFILE_RESULTS() \ - {} +#define EXECUTORCH_RESET_PROFILE_RESULTS() \ + { \ + } -#define EXECUTORCH_TRACK_ALLOCATOR(name) \ - ({ \ - (void)(name); \ - -1; \ +#define EXECUTORCH_TRACK_ALLOCATOR(name) \ + ({ \ + (void)(name); \ + -1; \ }) -#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ - ({ \ - (void)(id); \ - (void)(size); \ +#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ + ({ \ + (void)(id); \ + (void)(size); \ }) #endif diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h index 18c6ee30..ae658507 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h @@ -22,8 +22,8 @@ #include #endif -static constexpr const char* DYNAMIC_LIBRARY_NOT_SUPPORTED = "NOT_SUPPORTED"; -static constexpr const char* DYNAMIC_LIBRARY_NOT_FOUND = "NOT_FOUND"; +static constexpr const char *DYNAMIC_LIBRARY_NOT_SUPPORTED = "NOT_SUPPORTED"; +static constexpr const char *DYNAMIC_LIBRARY_NOT_FOUND = "NOT_FOUND"; extern "C" { @@ -33,7 +33,7 @@ extern "C" { * @param[in] addr Address to the symbol we are looking for in shared libraries. * @retval The path to the shared library containing the symbol. */ -inline const char* et_pal_get_shared_library_name(const void* addr) { +inline const char *et_pal_get_shared_library_name(const void *addr) { #if defined(ET_USE_LIBDL) Dl_info info; if (dladdr(addr, &info) && info.dli_fname) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h index e6fe5783..59b28e30 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h @@ -57,7 +57,7 @@ struct ExtendedHeader { * error if size was too short, if the header was not found, or if the * header appeared to be corrupt. */ - static Result Parse(const void* data, size_t size); + static Result Parse(const void *data, size_t size); /** * The size in bytes of the Program flatbuffer data, starting from offset diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h index 45ed38a7..5fb2723c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h @@ -23,7 +23,7 @@ namespace extension { * A facade class for loading programs and executing methods within them. */ class Module { - public: +public: /** * Enum to define loading behavior. */ @@ -46,10 +46,9 @@ class Module { * @param[in] load_mode The loading mode to use. * @param[in] event_tracer A EventTracer used for tracking and logging events. */ - explicit Module( - const std::string& file_path, - const LoadMode load_mode = LoadMode::MmapUseMlock, - std::unique_ptr event_tracer = nullptr); + explicit Module(const std::string &file_path, + const LoadMode load_mode = LoadMode::MmapUseMlock, + std::unique_ptr event_tracer = nullptr); /** * Constructs an instance with the provided data loader and memory allocator. @@ -82,10 +81,10 @@ class Module { std::unique_ptr temp_allocator = nullptr, std::unique_ptr event_tracer = nullptr); - Module(const Module&) = delete; - Module& operator=(const Module&) = delete; - Module(Module&&) = delete; - Module& operator=(Module&&) = delete; + Module(const Module &) = delete; + Module &operator=(const Module &) = delete; + Module(Module &&) = delete; + Module &operator=(Module &&) = delete; /** * Loads the program if needed. @@ -96,18 +95,15 @@ class Module { * @returns An Error to indicate success or failure of the loading process. */ ET_NODISCARD - runtime::Error load( - const runtime::Program::Verification verification = - runtime::Program::Verification::Minimal); + runtime::Error load(const runtime::Program::Verification verification = + runtime::Program::Verification::Minimal); /** * Checks if the program is loaded. * * @returns true if the program is loaded, false otherwise. */ - inline bool is_loaded() const { - return program_ != nullptr; - } + inline bool is_loaded() const { return program_ != nullptr; } /** * Get the program. The data loader used by the program is guaranteed to be @@ -115,9 +111,7 @@ class Module { * * @returns Shared pointer to the program or nullptr if it's not yet loaded. */ - inline std::shared_ptr program() const { - return program_; - } + inline std::shared_ptr program() const { return program_; } /** * Get a list of method names available in the loaded program. @@ -141,9 +135,9 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error load_method( - const std::string& method_name, - torch::executor::EventTracer* event_tracer = nullptr); + runtime::Error + load_method(const std::string &method_name, + torch::executor::EventTracer *event_tracer = nullptr); /** * Load the 'forward' method from the program and set up memory management if @@ -154,8 +148,8 @@ class Module { * * @returns An Error to indicate success or failure. */ - ET_NODISCARD inline runtime::Error load_forward( - torch::executor::EventTracer* event_tracer = nullptr) { + ET_NODISCARD inline runtime::Error + load_forward(torch::executor::EventTracer *event_tracer = nullptr) { return load_method("forward", event_tracer); } @@ -167,7 +161,7 @@ class Module { * @returns true if the method specified by method_name is loaded, false * otherwise. */ - inline bool is_method_loaded(const std::string& method_name) const { + inline bool is_method_loaded(const std::string &method_name) const { return methods_.count(method_name); } @@ -180,8 +174,8 @@ class Module { * @returns A method metadata, or an error if the program or method failed to * load. */ - runtime::Result method_meta( - const std::string& method_name); + runtime::Result + method_meta(const std::string &method_name); /** * Execute a specific method with the given input values and retrieve the @@ -195,9 +189,9 @@ class Module { * from the method or an error to indicate failure. */ ET_NODISCARD - runtime::Result> execute( - const std::string& method_name, - const std::vector& input_values); + runtime::Result> + execute(const std::string &method_name, + const std::vector &input_values); /** * Execute a specific method with a single input value. @@ -209,9 +203,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> execute( - const std::string& method_name, - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result> + execute(const std::string &method_name, const runtime::EValue &input_value) { return execute(method_name, std::vector{input_value}); } @@ -224,8 +217,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> execute( - const std::string& method_name) { + ET_NODISCARD inline runtime::Result> + execute(const std::string &method_name) { return execute(method_name, std::vector{}); } @@ -240,9 +233,9 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name, - const std::vector& input_values) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name, + const std::vector &input_values) { auto result = ET_UNWRAP(execute(method_name, input_values)); if (result.empty()) { return runtime::Error::InvalidArgument; @@ -260,9 +253,8 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name, - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name, const runtime::EValue &input_value) { return get(method_name, std::vector{input_value}); } @@ -275,8 +267,8 @@ class Module { * @returns A Result object containing either the first output value from the * method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result get( - const std::string& method_name) { + ET_NODISCARD inline runtime::Result + get(const std::string &method_name) { return get(method_name, std::vector{}); } @@ -289,8 +281,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the 'forward' method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> forward( - const std::vector& input_values) { + ET_NODISCARD inline runtime::Result> + forward(const std::vector &input_values) { return execute("forward", input_values); } @@ -303,8 +295,8 @@ class Module { * @returns A Result object containing either a vector of output values * from the 'forward' method or an error to indicate failure. */ - ET_NODISCARD inline runtime::Result> forward( - const runtime::EValue& input_value) { + ET_NODISCARD inline runtime::Result> + forward(const runtime::EValue &input_value) { return forward(std::vector{input_value}); } @@ -329,10 +321,9 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error set_input( - const std::string& method_name, - const runtime::EValue& input_value, - size_t input_index); + runtime::Error set_input(const std::string &method_name, + const runtime::EValue &input_value, + size_t input_index); /** * Sets a single input value for the "forward" method. @@ -343,9 +334,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - inline runtime::Error set_input( - const runtime::EValue& input_value, - size_t input_index) { + inline runtime::Error set_input(const runtime::EValue &input_value, + size_t input_index) { return set_input("forward", input_value, input_index); } @@ -358,9 +348,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - runtime::Error set_inputs( - const std::string& method_name, - const std::vector& input_values); + runtime::Error set_inputs(const std::string &method_name, + const std::vector &input_values); /** * Sets all input values for the "forward" method. @@ -370,8 +359,8 @@ class Module { * @returns An Error to indicate success or failure. */ ET_NODISCARD - inline runtime::Error set_inputs( - const std::vector& input_values) { + inline runtime::Error + set_inputs(const std::vector &input_values) { return set_inputs("forward", input_values); } @@ -388,10 +377,9 @@ class Module { * @note Only Tensor outputs are currently supported for setting. */ ET_NODISCARD - runtime::Error set_output( - const std::string& method_name, - runtime::EValue output_value, - size_t output_index = 0); + runtime::Error set_output(const std::string &method_name, + runtime::EValue output_value, + size_t output_index = 0); /** * Sets the output tensor for the "forward" method. @@ -405,9 +393,8 @@ class Module { * @note Only Tensor outputs are currently supported for setting. */ ET_NODISCARD - inline runtime::Error set_output( - runtime::EValue output_value, - size_t output_index = 0) { + inline runtime::Error set_output(runtime::EValue output_value, + size_t output_index = 0) { return set_output("forward", std::move(output_value), output_index); } @@ -419,11 +406,11 @@ class Module { * @returns A pointer to the EventTracer instance. Returns nullptr if no * EventTracer is set. */ - inline runtime::EventTracer* event_tracer() const { + inline runtime::EventTracer *event_tracer() const { return event_tracer_.get(); } - private: +private: struct MethodHolder { std::vector> planned_buffers; std::vector> planned_spans; @@ -433,7 +420,7 @@ class Module { std::vector inputs; }; - private: +private: std::string file_path_; LoadMode load_mode_{LoadMode::MmapUseMlock}; std::shared_ptr program_; @@ -442,7 +429,7 @@ class Module { std::unique_ptr temp_allocator_; std::unique_ptr event_tracer_; - protected: +protected: std::unordered_map methods_; friend class ExecuTorchJni; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h index f41c6f77..f223a2ce 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h @@ -38,16 +38,15 @@ using TensorPtr = std::shared_ptr; * object is destroyed. * @return A TensorPtr that manages the newly created Tensor. */ -TensorPtr make_tensor_ptr( - std::vector sizes, - void* data, - std::vector dim_order, - std::vector strides, - const executorch::aten::ScalarType type = - executorch::aten::ScalarType::Float, - const executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, - std::function deleter = nullptr); +TensorPtr +make_tensor_ptr(std::vector sizes, void *data, + std::vector dim_order, + std::vector strides, + const executorch::aten::ScalarType type = + executorch::aten::ScalarType::Float, + const executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, + std::function deleter = nullptr); /** * Creates a TensorPtr that manages a Tensor with the specified properties. @@ -61,16 +60,15 @@ TensorPtr make_tensor_ptr( * object is destroyed. * @return A TensorPtr that manages the newly created Tensor. */ -inline TensorPtr make_tensor_ptr( - std::vector sizes, - void* data, - const executorch::aten::ScalarType type = - executorch::aten::ScalarType::Float, - const executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, - std::function deleter = nullptr) { - return make_tensor_ptr( - std::move(sizes), data, {}, {}, type, dynamism, std::move(deleter)); +inline TensorPtr +make_tensor_ptr(std::vector sizes, void *data, + const executorch::aten::ScalarType type = + executorch::aten::ScalarType::Float, + const executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND, + std::function deleter = nullptr) { + return make_tensor_ptr(std::move(sizes), data, {}, {}, type, dynamism, + std::move(deleter)); } /** @@ -93,52 +91,37 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, - std::vector dim_order = {}, - std::vector strides = {}, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector sizes, + std::vector data, + std::vector dim_order = {}, + std::vector strides = {}, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type != deduced_type) { - ET_CHECK_MSG( - runtime::canCast(deduced_type, type), - "Cannot cast deduced type to specified type."); + ET_CHECK_MSG(runtime::canCast(deduced_type, type), + "Cannot cast deduced type to specified type."); std::vector casted_data(data.size() * runtime::elementSize(type)); ET_SWITCH_REALHBBF16_TYPES(type, nullptr, "make_tensor_ptr", CTYPE, [&] { - std::transform( - data.begin(), - data.end(), - reinterpret_cast(casted_data.data()), - [](const T& val) { return static_cast(val); }); + std::transform(data.begin(), data.end(), + reinterpret_cast(casted_data.data()), + [](const T &val) { return static_cast(val); }); }); const auto raw_data_ptr = casted_data.data(); auto data_ptr = std::make_shared>(std::move(casted_data)); - return make_tensor_ptr( - std::move(sizes), - raw_data_ptr, - std::move(dim_order), - std::move(strides), - type, - dynamism, - [data_ptr = std::move(data_ptr)](void*) {}); + return make_tensor_ptr(std::move(sizes), raw_data_ptr, std::move(dim_order), + std::move(strides), type, dynamism, + [data_ptr = std::move(data_ptr)](void *) {}); } const auto raw_data_ptr = data.data(); auto data_ptr = std::make_shared>(std::move(data)); - return make_tensor_ptr( - std::move(sizes), - raw_data_ptr, - std::move(dim_order), - std::move(strides), - type, - dynamism, - [data_ptr = std::move(data_ptr)](void*) {}); + return make_tensor_ptr(std::move(sizes), raw_data_ptr, std::move(dim_order), + std::move(strides), type, dynamism, + [data_ptr = std::move(data_ptr)](void *) {}); } /** @@ -158,19 +141,17 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector data, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector data, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { std::vector sizes{ executorch::aten::SizesType(data.size())}; - return make_tensor_ptr( - std::move(sizes), std::move(data), {0}, {1}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(data), {0}, {1}, type, + dynamism); } /** @@ -195,25 +176,19 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::initializer_list list, - std::vector dim_order = {}, - std::vector strides = {}, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { - return make_tensor_ptr( - std::move(sizes), - std::vector(std::move(list)), - std::move(dim_order), - std::move(strides), - type, - dynamism); +template ::value> +inline TensorPtr +make_tensor_ptr(std::vector sizes, + std::initializer_list list, + std::vector dim_order = {}, + std::vector strides = {}, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { + return make_tensor_ptr(std::move(sizes), std::vector(std::move(list)), + std::move(dim_order), std::move(strides), type, + dynamism); } /** @@ -235,19 +210,17 @@ inline TensorPtr make_tensor_ptr( * @param dynamism Specifies the mutability of the tensor's shape. * @return A TensorPtr that manages the newly created TensorImpl. */ -template < - typename T = float, - executorch::aten::ScalarType deduced_type = - runtime::CppTypeToScalarType::value> -inline TensorPtr make_tensor_ptr( - std::initializer_list list, - executorch::aten::ScalarType type = deduced_type, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +template ::value> +inline TensorPtr +make_tensor_ptr(std::initializer_list list, + executorch::aten::ScalarType type = deduced_type, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { std::vector sizes{ executorch::aten::SizesType(list.size())}; - return make_tensor_ptr( - std::move(sizes), std::move(list), {0}, {1}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(list), {0}, {1}, type, + dynamism); } /** @@ -257,8 +230,7 @@ inline TensorPtr make_tensor_ptr( * @param value The scalar value to be used for the Tensor. * @return A TensorPtr that manages the newly created TensorImpl. */ -template -inline TensorPtr make_tensor_ptr(T value) { +template inline TensorPtr make_tensor_ptr(T value) { return make_tensor_ptr({}, std::vector{value}); } @@ -278,8 +250,7 @@ inline TensorPtr make_tensor_ptr(T value) { * @return A TensorPtr managing the newly created Tensor. */ TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, + std::vector sizes, std::vector data, std::vector dim_order, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, @@ -300,13 +271,12 @@ TensorPtr make_tensor_ptr( * @return A TensorPtr managing the newly created Tensor. */ inline TensorPtr make_tensor_ptr( - std::vector sizes, - std::vector data, + std::vector sizes, std::vector data, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { - return make_tensor_ptr( - std::move(sizes), std::move(data), {}, {}, type, dynamism); + return make_tensor_ptr(std::move(sizes), std::move(data), {}, {}, type, + dynamism); } /** @@ -317,22 +287,21 @@ inline TensorPtr make_tensor_ptr( * @return A new TensorPtr managing a Tensor with the same properties as the * original. */ -inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor& tensor) { +inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor &tensor) { return make_tensor_ptr( - std::vector( - tensor.sizes().begin(), tensor.sizes().end()), + std::vector(tensor.sizes().begin(), + tensor.sizes().end()), tensor.mutable_data_ptr(), #ifndef USE_ATEN_LIB - std::vector( - tensor.dim_order().begin(), tensor.dim_order().end()), - std::vector( - tensor.strides().begin(), tensor.strides().end()), - tensor.scalar_type(), - tensor.shape_dynamism() -#else // USE_ATEN_LIB + std::vector(tensor.dim_order().begin(), + tensor.dim_order().end()), + std::vector(tensor.strides().begin(), + tensor.strides().end()), + tensor.scalar_type(), tensor.shape_dynamism() +#else // USE_ATEN_LIB {}, - std::vector( - tensor.strides().begin(), tensor.strides().end()), + std::vector(tensor.strides().begin(), + tensor.strides().end()), tensor.scalar_type() #endif // USE_ATEN_LIB ); @@ -347,7 +316,7 @@ inline TensorPtr make_tensor_ptr(const executorch::aten::Tensor& tensor) { * @return A new TensorPtr that manages a Tensor with the same properties as the * original but with copied data. */ -TensorPtr clone_tensor_ptr(const executorch::aten::Tensor& tensor); +TensorPtr clone_tensor_ptr(const executorch::aten::Tensor &tensor); /** * Creates a new TensorPtr by cloning the given TensorPtr, copying the @@ -357,7 +326,7 @@ TensorPtr clone_tensor_ptr(const executorch::aten::Tensor& tensor); * @return A new TensorPtr that manages a Tensor with the same properties as the * original but with copied data. */ -inline TensorPtr clone_tensor_ptr(const TensorPtr& tensor) { +inline TensorPtr clone_tensor_ptr(const TensorPtr &tensor) { return clone_tensor_ptr(*tensor); } @@ -369,9 +338,9 @@ inline TensorPtr clone_tensor_ptr(const TensorPtr& tensor) { * @return Error::Ok on success, or an appropriate error code on failure. */ ET_NODISCARD -runtime::Error resize_tensor_ptr( - TensorPtr& tensor, - const std::vector& sizes); +runtime::Error +resize_tensor_ptr(TensorPtr &tensor, + const std::vector &sizes); } // namespace extension } // namespace executorch diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h index e3351fe3..f6a70dd4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h @@ -24,13 +24,13 @@ namespace extension { * by converting TensorPtrMaker to TensorPtr. */ class TensorPtrMaker final { - public: +public: // This class may have non-copyable members in the future. - TensorPtrMaker(const TensorPtrMaker&) = delete; - TensorPtrMaker& operator=(const TensorPtrMaker&) = delete; + TensorPtrMaker(const TensorPtrMaker &) = delete; + TensorPtrMaker &operator=(const TensorPtrMaker &) = delete; // But it is movable. - TensorPtrMaker(TensorPtrMaker&&) = default; - TensorPtrMaker& operator=(TensorPtrMaker&&) = default; + TensorPtrMaker(TensorPtrMaker &&) = default; + TensorPtrMaker &operator=(TensorPtrMaker &&) = default; /** * Sets the scalar type of the tensor elements. @@ -38,7 +38,7 @@ class TensorPtrMaker final { * @param type The scalar type (e.g., float, int, bool). * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& type(executorch::aten::ScalarType type) { + TensorPtrMaker &&type(executorch::aten::ScalarType type) { type_ = type; return std::move(*this); } @@ -49,8 +49,8 @@ class TensorPtrMaker final { * @param dim_order A vector specifying the dimension order. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& dim_order( - std::vector dim_order) { + TensorPtrMaker && + dim_order(std::vector dim_order) { dim_order_ = std::move(dim_order); return std::move(*this); } @@ -61,7 +61,7 @@ class TensorPtrMaker final { * @param strides A vector specifying the stride for each dimension. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& strides(std::vector strides) { + TensorPtrMaker &&strides(std::vector strides) { strides_ = std::move(strides); return std::move(*this); } @@ -73,7 +73,7 @@ class TensorPtrMaker final { * bounded. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& dynamism(executorch::aten::TensorShapeDynamism dynamism) { + TensorPtrMaker &&dynamism(executorch::aten::TensorShapeDynamism dynamism) { dynamism_ = dynamism; return std::move(*this); } @@ -87,7 +87,7 @@ class TensorPtrMaker final { * lambda that has captured some state. * @return Rvalue to this TensorPtrMaker for method chaining. */ - TensorPtrMaker&& deleter(std::function&& deleter) { + TensorPtrMaker &&deleter(std::function &&deleter) { deleter_ = std::move(deleter); return std::move(*this); } @@ -100,13 +100,8 @@ class TensorPtrMaker final { */ TensorPtr make_tensor_ptr() && { return ::executorch::extension::make_tensor_ptr( - std::move(sizes_), - data_, - std::move(dim_order_), - std::move(strides_), - type_, - dynamism_, - std::move(deleter_)); + std::move(sizes_), data_, std::move(dim_order_), std::move(strides_), + type_, dynamism_, std::move(deleter_)); } /** @@ -114,30 +109,25 @@ class TensorPtrMaker final { * * @return A TensorPtr instance that manages the newly created Tensor. */ - operator TensorPtr() && { - return std::move(*this).make_tensor_ptr(); - } + operator TensorPtr() && { return std::move(*this).make_tensor_ptr(); } - private: - TensorPtrMaker( - void* data, - std::vector sizes, - executorch::aten::ScalarType type) +private: + TensorPtrMaker(void *data, std::vector sizes, + executorch::aten::ScalarType type) : sizes_(std::move(sizes)), data_(data), type_(type) {} - private: +private: // The following properties are required to create a Tensor. - friend TensorPtrMaker for_blob( - void* data, - std::vector sizes, - executorch::aten::ScalarType type); + friend TensorPtrMaker for_blob(void *data, + std::vector sizes, + executorch::aten::ScalarType type); - private: +private: std::vector sizes_; std::vector strides_; std::vector dim_order_; - std::function deleter_ = nullptr; - void* data_ = nullptr; + std::function deleter_ = nullptr; + void *data_ = nullptr; executorch::aten::ScalarType type_ = executorch::aten::ScalarType::Float; executorch::aten::TensorShapeDynamism dynamism_ = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND; @@ -158,8 +148,7 @@ class TensorPtrMaker final { * @return A TensorPtrMaker instance for creating a TensorPtr. */ inline TensorPtrMaker for_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float) { return TensorPtrMaker(data, std::move(sizes), type); } @@ -180,8 +169,7 @@ inline TensorPtrMaker for_blob( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr from_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -208,8 +196,7 @@ inline TensorPtr from_blob( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr from_blob( - void* data, - std::vector sizes, + void *data, std::vector sizes, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, executorch::aten::TensorShapeDynamism dynamism = @@ -236,13 +223,12 @@ inline TensorPtr from_blob( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance that manages the newly created Tensor. */ -inline TensorPtr from_blob( - void* data, - std::vector sizes, - executorch::aten::ScalarType type, - std::function&& deleter, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +from_blob(void *data, std::vector sizes, + executorch::aten::ScalarType type, + std::function &&deleter, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return for_blob(data, std::move(sizes), type) .deleter(std::move(deleter)) .dynamism(dynamism) @@ -266,14 +252,13 @@ inline TensorPtr from_blob( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance that manages the newly created Tensor. */ -inline TensorPtr from_blob( - void* data, - std::vector sizes, - std::vector strides, - executorch::aten::ScalarType type, - std::function&& deleter, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +from_blob(void *data, std::vector sizes, + std::vector strides, + executorch::aten::ScalarType type, + std::function &&deleter, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return for_blob(data, std::move(sizes), type) .strides(std::move(strides)) .deleter(std::move(deleter)) @@ -316,18 +301,16 @@ TensorPtr empty_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr empty_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return empty_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return empty_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -341,11 +324,11 @@ inline TensorPtr empty_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr empty( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +empty(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return empty_strided(std::move(sizes), {}, type, dynamism); } @@ -380,20 +363,16 @@ TensorPtr full_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr full_like( - const TensorPtr& other, - executorch::aten::Scalar fill_value, + const TensorPtr &other, executorch::aten::Scalar fill_value, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return full_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - fill_value, - type, - dynamism); + return full_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, + fill_value, type, dynamism); } /** @@ -405,12 +384,12 @@ inline TensorPtr full_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr full( - std::vector sizes, - executorch::aten::Scalar fill_value, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +full(std::vector sizes, + executorch::aten::Scalar fill_value, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full_strided(std::move(sizes), {}, fill_value, type, dynamism); } @@ -439,7 +418,7 @@ inline TensorPtr scalar_tensor( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr ones_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -454,11 +433,11 @@ inline TensorPtr ones_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr ones( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +ones(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full(std::move(sizes), 1, type, dynamism); } @@ -474,7 +453,7 @@ inline TensorPtr ones( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr zeros_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -489,11 +468,11 @@ inline TensorPtr zeros_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr zeros( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +zeros(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return full(std::move(sizes), 0, type, dynamism); } @@ -524,18 +503,16 @@ TensorPtr rand_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr rand_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return rand_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return rand_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -546,11 +523,11 @@ inline TensorPtr rand_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr rand( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +rand(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return rand_strided(std::move(sizes), {}, type, dynamism); } @@ -582,18 +559,16 @@ TensorPtr randn_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr randn_like( - const TensorPtr& other, + const TensorPtr &other, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { if (type == executorch::aten::ScalarType::Undefined) { type = other->scalar_type(); } - return randn_strided( - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + return randn_strided({other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, + dynamism); } /** @@ -605,11 +580,11 @@ inline TensorPtr randn_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr randn( - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +randn(std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Float, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return randn_strided(std::move(sizes), {}, type, dynamism); } @@ -625,9 +600,7 @@ inline TensorPtr randn( * @return A TensorPtr instance managing the newly created Tensor. */ TensorPtr randint_strided( - int64_t low, - int64_t high, - std::vector sizes, + int64_t low, int64_t high, std::vector sizes, std::vector strides, executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, executorch::aten::TensorShapeDynamism dynamism = @@ -646,9 +619,7 @@ TensorPtr randint_strided( * @return A TensorPtr instance managing the newly created Tensor. */ inline TensorPtr randint_like( - const TensorPtr& other, - int64_t low, - int64_t high, + const TensorPtr &other, int64_t low, int64_t high, executorch::aten::ScalarType type = executorch::aten::ScalarType::Undefined, executorch::aten::TensorShapeDynamism dynamism = executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { @@ -656,12 +627,8 @@ inline TensorPtr randint_like( type = other->scalar_type(); } return randint_strided( - low, - high, - {other->sizes().begin(), other->sizes().end()}, - {other->strides().begin(), other->strides().end()}, - type, - dynamism); + low, high, {other->sizes().begin(), other->sizes().end()}, + {other->strides().begin(), other->strides().end()}, type, dynamism); } /** @@ -675,13 +642,12 @@ inline TensorPtr randint_like( * @param dynamism Specifies whether the tensor's shape is static or dynamic. * @return A TensorPtr instance managing the newly created Tensor. */ -inline TensorPtr randint( - int64_t low, - int64_t high, - std::vector sizes, - executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, - executorch::aten::TensorShapeDynamism dynamism = - executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { +inline TensorPtr +randint(int64_t low, int64_t high, + std::vector sizes, + executorch::aten::ScalarType type = executorch::aten::ScalarType::Int, + executorch::aten::TensorShapeDynamism dynamism = + executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) { return randint_strided(low, high, std::move(sizes), {}, type, dynamism); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h index 7890f4f9..19514c7a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h @@ -18,10 +18,9 @@ namespace runtime { * BackendExecutionContext will be used to inject run time context. */ class BackendExecutionContext final { - public: - BackendExecutionContext( - EventTracer* event_tracer = nullptr, - MemoryAllocator* temp_allocator = nullptr) +public: + BackendExecutionContext(EventTracer *event_tracer = nullptr, + MemoryAllocator *temp_allocator = nullptr) : event_tracer_(event_tracer), temp_allocator_(temp_allocator) {} /** @@ -29,17 +28,14 @@ class BackendExecutionContext final { * logging inside the delegate backend. Users will need access to this pointer * to use any of the event tracer APIs. */ - EventTracer* event_tracer() { - return event_tracer_; - } + EventTracer *event_tracer() { return event_tracer_; } /** * Returns a pointer to the address allocated by temp allocator. This * allocator will be reset after every delegate call during execution. */ - void* allocate( - size_t size, - size_t alignment = MemoryAllocator::kDefaultAlignment) { + void *allocate(size_t size, + size_t alignment = MemoryAllocator::kDefaultAlignment) { // TODO(chenlai): depends on the need, we may expose more functionality for // memory allocation. return temp_allocator_->allocate(size, alignment); @@ -48,13 +44,11 @@ class BackendExecutionContext final { /** * Returns the temp allocator. This allocator will be reset every instruction. */ - MemoryAllocator* get_temp_allocator() { - return temp_allocator_; - } + MemoryAllocator *get_temp_allocator() { return temp_allocator_; } - private: - EventTracer* event_tracer_ = nullptr; - MemoryAllocator* temp_allocator_ = nullptr; +private: + EventTracer *event_tracer_ = nullptr; + MemoryAllocator *temp_allocator_ = nullptr; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h index 75413493..bb23427a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h @@ -17,20 +17,18 @@ namespace runtime { * delegate. */ class BackendInitContext final { - public: - explicit BackendInitContext(MemoryAllocator* runtime_allocator) +public: + explicit BackendInitContext(MemoryAllocator *runtime_allocator) : runtime_allocator_(runtime_allocator) {} /** Get the runtime allocator passed from Method. It's the same runtime * executor used by the standard executor runtime and the life span is the * same as the model. */ - MemoryAllocator* get_runtime_allocator() { - return runtime_allocator_; - } + MemoryAllocator *get_runtime_allocator() { return runtime_allocator_; } - private: - MemoryAllocator* runtime_allocator_ = nullptr; +private: + MemoryAllocator *runtime_allocator_ = nullptr; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h index c0305f68..42f8698e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h @@ -24,12 +24,12 @@ namespace executorch { namespace runtime { struct SizedBuffer { - void* buffer; + void *buffer; size_t nbytes; // number of bytes of buffer }; struct CompileSpec { - const char* key; // spec key + const char *key; // spec key SizedBuffer value; // spec value }; @@ -40,7 +40,7 @@ struct CompileSpec { using DelegateHandle = void; class BackendInterface { - public: +public: virtual ~BackendInterface() = 0; /** @@ -78,10 +78,9 @@ class BackendInterface { * Error::DelegateInvalidCompatibility. Other backend delegate * specific error codes can be found in error.h. */ - ET_NODISCARD virtual Result init( - BackendInitContext& context, - FreeableBuffer* processed, - ArrayRef compile_specs) const = 0; + ET_NODISCARD virtual Result + init(BackendInitContext &context, FreeableBuffer *processed, + ArrayRef compile_specs) const = 0; /** * Responsible for executing the given method’s handle, as it was produced @@ -93,10 +92,9 @@ class BackendInterface { * @param[in] args The method’s inputs and outputs. * @retval Error::Ok if successful. */ - ET_NODISCARD virtual Error execute( - BackendExecutionContext& context, - DelegateHandle* handle, - EValue** args) const = 0; + ET_NODISCARD virtual Error execute(BackendExecutionContext &context, + DelegateHandle *handle, + EValue **args) const = 0; /** * Responsible for destroying a handle, if it's required for some backend. @@ -107,7 +105,7 @@ class BackendInterface { * @param[in] handle The handle to be destroyed. An opaque handle returned by * `init()`. */ - virtual void destroy(ET_UNUSED DelegateHandle* handle) const {} + virtual void destroy(ET_UNUSED DelegateHandle *handle) const {} }; /** @@ -118,16 +116,16 @@ class BackendInterface { * @retval Pointer to the appropriate object that implements BackendInterface. * Nullptr if it can't find anything with the given name. */ -BackendInterface* get_backend_class(const char* name); +BackendInterface *get_backend_class(const char *name); /** * A named instance of a backend. */ struct Backend { /// The name of the backend. Must match the string used in the PTE file. - const char* name; + const char *name; /// The instance of the backend to use when loading and executing programs. - BackendInterface* backend; + BackendInterface *backend; }; /** @@ -137,7 +135,7 @@ struct Backend { * @param[in] backend Backend object * @retval Error code representing whether registration was successful. */ -ET_NODISCARD Error register_backend(const Backend& backend); +ET_NODISCARD Error register_backend(const Backend &backend); } // namespace runtime } // namespace executorch diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h index 463284d9..e4468251 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h @@ -52,22 +52,21 @@ namespace runtime { * This is intended to be trivially copyable, so it should be passed by * value. */ -template -class ArrayRef final { - public: - using iterator = const T*; - using const_iterator = const T*; +template class ArrayRef final { +public: + using iterator = const T *; + using const_iterator = const T *; using size_type = size_t; using value_type = T; - private: +private: /// The start of the array, in an external buffer. - const T* Data; + const T *Data; /// The number of elements. size_type Length; - public: +public: /// @name Constructors /// @{ @@ -76,16 +75,16 @@ class ArrayRef final { /// Construct a ArrayRef from a single element. Implicitly convert element /// type. It is aligned with PyTorch's c10::ArrayRef. - /* implicit */ constexpr ArrayRef(const T& OneElt) + /* implicit */ constexpr ArrayRef(const T &OneElt) : Data(&OneElt), Length(1) {} /// Construct a ArrayRef from a pointer and length. - ArrayRef(const T* data, size_t length) : Data(data), Length(length) { + ArrayRef(const T *data, size_t length) : Data(data), Length(length) { ET_DCHECK(Data != nullptr || Length == 0); } /// Construct a ArrayRef from a range. - ArrayRef(const T* begin, const T* end) : Data(begin), Length(end - begin) {} + ArrayRef(const T *begin, const T *end) : Data(begin), Length(end - begin) {} /// Construct a ArrayRef from a C array. template @@ -95,45 +94,31 @@ class ArrayRef final { /// @name Simple Operations /// @{ - constexpr iterator begin() const { - return Data; - } - constexpr iterator end() const { - return Data + Length; - } + constexpr iterator begin() const { return Data; } + constexpr iterator end() const { return Data + Length; } // These are actually the same as iterator, since ArrayRef only // gives you const iterators. - constexpr const_iterator cbegin() const { - return Data; - } - constexpr const_iterator cend() const { - return Data + Length; - } + constexpr const_iterator cbegin() const { return Data; } + constexpr const_iterator cend() const { return Data + Length; } /// empty - Check if the array is empty. - constexpr bool empty() const { - return Length == 0; - } + constexpr bool empty() const { return Length == 0; } - constexpr const T* data() const { - return Data; - } + constexpr const T *data() const { return Data; } /// size - Get the array size. - constexpr size_t size() const { - return Length; - } + constexpr size_t size() const { return Length; } /// front - Get the first element. - const T& front() const { + const T &front() const { // ArrayRef: attempted to access front() of empty list ET_CHECK(!empty()); return Data[0]; } /// back - Get the last element. - const T& back() const { + const T &back() const { // ArrayRef: attempted to access back() of empty list ET_CHECK(!empty()); return Data[Length - 1]; @@ -160,19 +145,15 @@ class ArrayRef final { } /// slice(n) - Chop off the first N elements of the array. - constexpr ArrayRef slice(size_t N) const { - return slice(N, size() - N); - } + constexpr ArrayRef slice(size_t N) const { return slice(N, size() - N); } /// @} /// @name Operator Overloads /// @{ - constexpr const T& operator[](size_t Index) const { - return Data[Index]; - } + constexpr const T &operator[](size_t Index) const { return Data[Index]; } /// Vector compatibility - const T& at(size_t Index) const { + const T &at(size_t Index) const { // invalid index ET_CHECK(Index < Length); return Data[Index]; @@ -185,38 +166,32 @@ class ArrayRef final { /// @{ /// Construct an ArrayRef from a single element. -template -ArrayRef makeArrayRef(const T& OneElt) { +template ArrayRef makeArrayRef(const T &OneElt) { return OneElt; } /// Construct an ArrayRef from a pointer and length. -template -ArrayRef makeArrayRef(const T* data, size_t length) { +template ArrayRef makeArrayRef(const T *data, size_t length) { return ArrayRef(data, length); } /// Construct an ArrayRef from a range. -template -ArrayRef makeArrayRef(const T* begin, const T* end) { +template ArrayRef makeArrayRef(const T *begin, const T *end) { return ArrayRef(begin, end); } /// Construct an ArrayRef from an ArrayRef (no-op) (const) -template -ArrayRef makeArrayRef(const ArrayRef& Vec) { +template ArrayRef makeArrayRef(const ArrayRef &Vec) { return Vec; } /// Construct an ArrayRef from an ArrayRef (no-op) -template -ArrayRef& makeArrayRef(ArrayRef& Vec) { +template ArrayRef &makeArrayRef(ArrayRef &Vec) { return Vec; } /// Construct an ArrayRef from a C array. -template -ArrayRef makeArrayRef(const T (&Arr)[N]) { +template ArrayRef makeArrayRef(const T (&Arr)[N]) { return ArrayRef(Arr); } @@ -224,13 +199,11 @@ ArrayRef makeArrayRef(const T (&Arr)[N]) { // conversions to get you to an ArrayRef, which is why we need so // many overloads. -template -bool operator==(ArrayRef a1, ArrayRef a2) { +template bool operator==(ArrayRef a1, ArrayRef a2) { return a1.equals(a2); } -template -bool operator!=(ArrayRef a1, ArrayRef a2) { +template bool operator!=(ArrayRef a1, ArrayRef a2) { return !a1.equals(a2); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h index 876212de..25244fb9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h @@ -23,7 +23,7 @@ namespace runtime { * See //executorch/extension/data_loader for common implementations. */ class DataLoader { - public: +public: /** * Describes the content of the segment. */ @@ -60,16 +60,13 @@ class DataLoader { /// An optional, null-terminated string describing the segment. For /// `Backend` segments, this is the backend ID. Null for other segment /// types. - const char* descriptor; + const char *descriptor; SegmentInfo() = default; - explicit SegmentInfo( - Type segment_type, - size_t segment_index = 0, - const char* descriptor = nullptr) - : segment_type(segment_type), - segment_index(segment_index), + explicit SegmentInfo(Type segment_type, size_t segment_index = 0, + const char *descriptor = nullptr) + : segment_type(segment_type), segment_index(segment_index), descriptor(descriptor) {} }; @@ -88,7 +85,7 @@ class DataLoader { * @returns a `FreeableBuffer` that owns the loaded data. */ ET_NODISCARD virtual Result - load(size_t offset, size_t size, const SegmentInfo& segment_info) const = 0; + load(size_t offset, size_t size, const SegmentInfo &segment_info) const = 0; /** * Loads data from the underlying data source into the provided buffer. @@ -104,11 +101,9 @@ class DataLoader { * * @returns an Error indicating if the load was successful. */ - ET_NODISCARD virtual Error load_into( - size_t offset, - size_t size, - const SegmentInfo& segment_info, - void* buffer) const { + ET_NODISCARD virtual Error load_into(size_t offset, size_t size, + const SegmentInfo &segment_info, + void *buffer) const { // Using a stub implementation here instead of pure virtual to expand the // data_loader interface in a backwards compatible way. (void)buffer; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h index 4babb4d1..62ea8f16 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h @@ -115,12 +115,12 @@ using ::executorch::runtime::error_code_t; * @param[in] message__ Format string for the log error message. * @param[in] ... Optional additional arguments for the format string. */ -#define ET_CHECK_OR_RETURN_ERROR(cond__, error__, message__, ...) \ - { \ - if (!(cond__)) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return ::executorch::runtime::Error::error__; \ - } \ +#define ET_CHECK_OR_RETURN_ERROR(cond__, error__, message__, ...) \ + { \ + if (!(cond__)) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return ::executorch::runtime::Error::error__; \ + } \ } /** @@ -132,13 +132,13 @@ using ::executorch::runtime::error_code_t; * @param[in] ... Optional format string for the log error message and its * arguments. */ -#define ET_CHECK_OK_OR_RETURN_ERROR(error__, ...) \ +#define ET_CHECK_OK_OR_RETURN_ERROR(error__, ...) \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(error__, ##__VA_ARGS__) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \ - ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT( \ - __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \ + ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, \ + 4, 3, 2, 1) \ (__VA_ARGS__) /** @@ -165,43 +165,43 @@ using ::executorch::runtime::error_code_t; * ET_CHECK_OK_OR_RETURN_ERROR(error_code); // Calls v1 * ET_CHECK_OK_OR_RETURN_ERROR(error_code, "Error message", ...); // Calls v2 */ -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(_1, _2, _3, _4, _5, _6, \ + _7, _8, _9, _10, N, ...) \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ - do { \ - const auto et_error__ = (error__); \ - if (et_error__ != ::executorch::runtime::Error::Ok) { \ - return et_error__; \ - } \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ + do { \ + const auto et_error__ = (error__); \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ + return et_error__; \ + } \ } while (0) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \ - do { \ - const auto et_error__ = (error__); \ - if (et_error__ != ::executorch::runtime::Error::Ok) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return et_error__; \ - } \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \ + do { \ + const auto et_error__ = (error__); \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return et_error__; \ + } \ } while (0) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h index 8003a89c..2b7ea205 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h @@ -20,24 +20,21 @@ namespace internal { // Tensor gets proper reference treatment because its expensive to copy in aten // mode, all other types are just copied. -template -struct evalue_to_const_ref_overload_return { +template struct evalue_to_const_ref_overload_return { using type = T; }; template <> struct evalue_to_const_ref_overload_return { - using type = const executorch::aten::Tensor&; + using type = const executorch::aten::Tensor &; }; -template -struct evalue_to_ref_overload_return { +template struct evalue_to_ref_overload_return { using type = T; }; -template <> -struct evalue_to_ref_overload_return { - using type = executorch::aten::Tensor&; +template <> struct evalue_to_ref_overload_return { + using type = executorch::aten::Tensor &; }; } // namespace internal @@ -52,9 +49,8 @@ struct evalue_to_ref_overload_return { * the tensor changes). To solve this instead they must be created dynamically * whenever they are used. */ -template -class BoxedEvalueList { - public: +template class BoxedEvalueList { +public: BoxedEvalueList() = default; /* * Wrapped_vals is a list of pointers into the values table of the runtime @@ -62,18 +58,18 @@ class BoxedEvalueList { * is a container of the same size whose serves as memory to construct the * unwrapped vals. */ - BoxedEvalueList(EValue** wrapped_vals, T* unwrapped_vals, int size) + BoxedEvalueList(EValue **wrapped_vals, T *unwrapped_vals, int size) : wrapped_vals_(wrapped_vals, size), unwrapped_vals_(unwrapped_vals) {} /* * Constructs and returns the list of T specified by the EValue pointers */ executorch::aten::ArrayRef get() const; - private: +private: // Source of truth for the list - executorch::aten::ArrayRef wrapped_vals_; + executorch::aten::ArrayRef wrapped_vals_; // Same size as wrapped_vals - mutable T* unwrapped_vals_; + mutable T *unwrapped_vals_; }; template <> @@ -119,13 +115,11 @@ struct EValue { Tag tag; // Basic ctors and assignments - EValue(const EValue& rhs) : EValue(rhs.payload, rhs.tag) {} + EValue(const EValue &rhs) : EValue(rhs.payload, rhs.tag) {} - EValue(EValue&& rhs) noexcept : tag(rhs.tag) { - moveFrom(std::move(rhs)); - } + EValue(EValue &&rhs) noexcept : tag(rhs.tag) { moveFrom(std::move(rhs)); } - EValue& operator=(EValue&& rhs) & noexcept { + EValue &operator=(EValue &&rhs) & noexcept { if (&rhs == this) { return *this; } @@ -135,33 +129,25 @@ struct EValue { return *this; } - EValue& operator=(EValue const& rhs) & { + EValue &operator=(EValue const &rhs) & { // Define copy assignment through copy ctor and move assignment *this = EValue(rhs); return *this; } - ~EValue() { - destroy(); - } + ~EValue() { destroy(); } /****** None Type ******/ - EValue() : tag(Tag::None) { - payload.copyable_union.as_int = 0; - } + EValue() : tag(Tag::None) { payload.copyable_union.as_int = 0; } - bool isNone() const { - return tag == Tag::None; - } + bool isNone() const { return tag == Tag::None; } /****** Int Type ******/ /*implicit*/ EValue(int64_t i) : tag(Tag::Int) { payload.copyable_union.as_int = i; } - bool isInt() const { - return tag == Tag::Int; - } + bool isInt() const { return tag == Tag::Int; } int64_t toInt() const { ET_CHECK_MSG(isInt(), "EValue is not an int."); @@ -173,9 +159,7 @@ struct EValue { payload.copyable_union.as_double = d; } - bool isDouble() const { - return tag == Tag::Double; - } + bool isDouble() const { return tag == Tag::Double; } double toDouble() const { ET_CHECK_MSG(isDouble(), "EValue is not a Double."); @@ -187,9 +171,7 @@ struct EValue { payload.copyable_union.as_bool = b; } - bool isBool() const { - return tag == Tag::Bool; - } + bool isBool() const { return tag == Tag::Bool; } bool toBool() const { ET_CHECK_MSG(isBool(), "EValue is not a Bool."); @@ -244,10 +226,9 @@ struct EValue { // from. template /*implicit*/ EValue( - T&& value, + T &&value, typename std::enable_if(value)), - EValue>::value>::type* = 0) { + decltype(*std::forward(value)), EValue>::value>::type * = 0) { ET_CHECK_MSG(value != nullptr, "Pointer is null."); // Note that this ctor does not initialize this->tag directly; it is set by // moving in the new value. @@ -255,12 +236,9 @@ struct EValue { } // Delete constructor for raw pointers to ensure they cannot be used. - template - explicit EValue(T* value) = delete; + template explicit EValue(T *value) = delete; - bool isTensor() const { - return tag == Tag::Tensor; - } + bool isTensor() const { return tag == Tag::Tensor; } executorch::aten::Tensor toTensor() && { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); @@ -269,25 +247,23 @@ struct EValue { return res; } - executorch::aten::Tensor& toTensor() & { + executorch::aten::Tensor &toTensor() & { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); return payload.as_tensor; } - const executorch::aten::Tensor& toTensor() const& { + const executorch::aten::Tensor &toTensor() const & { ET_CHECK_MSG(isTensor(), "EValue is not a Tensor."); return payload.as_tensor; } /****** String Type ******/ - /*implicit*/ EValue(const char* s, size_t size) : tag(Tag::String) { + /*implicit*/ EValue(const char *s, size_t size) : tag(Tag::String) { payload.copyable_union.as_string = executorch::aten::ArrayRef(s, size); } - bool isString() const { - return tag == Tag::String; - } + bool isString() const { return tag == Tag::String; } executorch::aten::string_view toString() const { ET_CHECK_MSG(isString(), "EValue is not a String."); @@ -301,9 +277,7 @@ struct EValue { payload.copyable_union.as_int_list = i; } - bool isIntList() const { - return tag == Tag::ListInt; - } + bool isIntList() const { return tag == Tag::ListInt; } executorch::aten::ArrayRef toIntList() const { ET_CHECK_MSG(isIntList(), "EValue is not an Int List."); @@ -315,9 +289,7 @@ struct EValue { payload.copyable_union.as_bool_list = b; } - bool isBoolList() const { - return tag == Tag::ListBool; - } + bool isBoolList() const { return tag == Tag::ListBool; } executorch::aten::ArrayRef toBoolList() const { ET_CHECK_MSG(isBoolList(), "EValue is not a Bool List."); @@ -330,9 +302,7 @@ struct EValue { payload.copyable_union.as_double_list = d; } - bool isDoubleList() const { - return tag == Tag::ListDouble; - } + bool isDoubleList() const { return tag == Tag::ListDouble; } executorch::aten::ArrayRef toDoubleList() const { ET_CHECK_MSG(isDoubleList(), "EValue is not a Double List."); @@ -345,9 +315,7 @@ struct EValue { payload.copyable_union.as_tensor_list = t; } - bool isTensorList() const { - return tag == Tag::ListTensor; - } + bool isTensorList() const { return tag == Tag::ListTensor; } executorch::aten::ArrayRef toTensorList() const { ET_CHECK_MSG(isTensorList(), "EValue is not a Tensor List."); @@ -361,9 +329,7 @@ struct EValue { payload.copyable_union.as_list_optional_tensor = t; } - bool isListOptionalTensor() const { - return tag == Tag::ListOptionalTensor; - } + bool isListOptionalTensor() const { return tag == Tag::ListOptionalTensor; } executorch::aten::ArrayRef< executorch::aten::optional> @@ -394,16 +360,14 @@ struct EValue { /****** Device Type ******/ executorch::aten::Device toDevice() const { ET_CHECK_MSG(isInt(), "EValue is not a Device."); - return executorch::aten::Device( - static_cast( - payload.copyable_union.as_int), - -1); + return executorch::aten::Device(static_cast( + payload.copyable_union.as_int), + -1); } + template T to() &&; template - T to() &&; - template - typename internal::evalue_to_const_ref_overload_return::type to() const&; + typename internal::evalue_to_const_ref_overload_return::type to() const &; template typename internal::evalue_to_ref_overload_return::type to() &; @@ -419,7 +383,7 @@ struct EValue { return this->to(); } - private: +private: // Pre cond: the payload value has had its destructor called void clearToNone() noexcept { payload.copyable_union.as_int = 0; @@ -427,7 +391,7 @@ struct EValue { } // Shared move logic - void moveFrom(EValue&& rhs) noexcept { + void moveFrom(EValue &&rhs) noexcept { if (rhs.isTensor()) { new (&payload.as_tensor) executorch::aten::Tensor(std::move(rhs.payload.as_tensor)); @@ -448,17 +412,17 @@ struct EValue { if (isTensor()) { payload.as_tensor.~Tensor(); } else if (isTensorList()) { - for (auto& tensor : toTensorList()) { + for (auto &tensor : toTensorList()) { tensor.~Tensor(); } } else if (isListOptionalTensor()) { - for (auto& optional_tensor : toListOptionalTensor()) { + for (auto &optional_tensor : toListOptionalTensor()) { optional_tensor.~optional(); } } } - EValue(const Payload& p, Tag t) : tag(t) { + EValue(const Payload &p, Tag t) : tag(t) { if (isTensor()) { new (&payload.as_tensor) executorch::aten::Tensor(p.as_tensor); } else { @@ -468,14 +432,13 @@ struct EValue { }; #define EVALUE_DEFINE_TO(T, method_name) \ - template <> \ - inline T EValue::to()&& { \ + template <> inline T EValue::to() && { \ return static_cast(std::move(*this).method_name()); \ } \ template <> \ inline ::executorch::runtime::internal::evalue_to_const_ref_overload_return< \ T>::type \ - EValue::to() const& { \ + EValue::to() const & { \ typedef ::executorch::runtime::internal:: \ evalue_to_const_ref_overload_return::type return_type; \ return static_cast(this->method_name()); \ @@ -483,7 +446,7 @@ struct EValue { template <> \ inline ::executorch::runtime::internal::evalue_to_ref_overload_return< \ T>::type \ - EValue::to()& { \ + EValue::to() & { \ typedef ::executorch::runtime::internal::evalue_to_ref_overload_return< \ T>::type return_type; \ return static_cast(this->method_name()); \ @@ -499,9 +462,8 @@ EVALUE_DEFINE_TO(executorch::aten::MemoryFormat, toMemoryFormat) EVALUE_DEFINE_TO(executorch::aten::Layout, toLayout) EVALUE_DEFINE_TO(executorch::aten::Device, toDevice) // Tensor and Optional Tensor -EVALUE_DEFINE_TO( - executorch::aten::optional, - toOptional) +EVALUE_DEFINE_TO(executorch::aten::optional, + toOptional) EVALUE_DEFINE_TO(executorch::aten::Tensor, toTensor) // IntList and Optional IntList @@ -512,37 +474,32 @@ EVALUE_DEFINE_TO( // DoubleList and Optional DoubleList EVALUE_DEFINE_TO(executorch::aten::ArrayRef, toDoubleList) -EVALUE_DEFINE_TO( - executorch::aten::optional>, - toOptional>) +EVALUE_DEFINE_TO(executorch::aten::optional>, + toOptional>) // BoolList and Optional BoolList EVALUE_DEFINE_TO(executorch::aten::ArrayRef, toBoolList) -EVALUE_DEFINE_TO( - executorch::aten::optional>, - toOptional>) +EVALUE_DEFINE_TO(executorch::aten::optional>, + toOptional>) // TensorList and Optional TensorList -EVALUE_DEFINE_TO( - executorch::aten::ArrayRef, - toTensorList) +EVALUE_DEFINE_TO(executorch::aten::ArrayRef, + toTensorList) EVALUE_DEFINE_TO( executorch::aten::optional< executorch::aten::ArrayRef>, toOptional>) // List of Optional Tensor -EVALUE_DEFINE_TO( - executorch::aten::ArrayRef< - executorch::aten::optional>, - toListOptionalTensor) +EVALUE_DEFINE_TO(executorch::aten::ArrayRef< + executorch::aten::optional>, + toListOptionalTensor) #undef EVALUE_DEFINE_TO template executorch::aten::ArrayRef BoxedEvalueList::get() const { for (typename executorch::aten::ArrayRef::size_type i = 0; - i < wrapped_vals_.size(); - i++) { + i < wrapped_vals_.size(); i++) { ET_CHECK(wrapped_vals_[i] != nullptr); unwrapped_vals_[i] = wrapped_vals_[i]->template to(); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h index 5cf4f74a..ffb60066 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h @@ -6,11 +6,11 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include #include -#include #pragma once @@ -113,7 +113,7 @@ struct EventTracerEntry { * flatbuffer. */ class EventTracer { - public: +public: /** * Start a new event block (can consist of profiling and/or debugging events.) * identified by this name. A block is conceptually a set of events that we @@ -125,7 +125,7 @@ class EventTracer { * pointer around. The string must be copied over into internal memory during * this call. */ - virtual void create_event_block(const char* name) = 0; + virtual void create_event_block(const char *name) = 0; /** * Start the profiling of the event identified by name and debug_handle. @@ -147,10 +147,9 @@ class EventTracer { * @return Returns an instance of EventTracerEntry which should be passed back * into the end_profiling() call. */ - virtual EventTracerEntry start_profiling( - const char* name, - ChainID chain_id = kUnsetChainId, - DebugHandle debug_handle = kUnsetDebugHandle) = 0; + virtual EventTracerEntry + start_profiling(const char *name, ChainID chain_id = kUnsetChainId, + DebugHandle debug_handle = kUnsetDebugHandle) = 0; /** * Start the profiling of a delegate event. Similar to start_profiling it will @@ -168,9 +167,9 @@ class EventTracer { * based names are used by this delegate to identify ops executed in the * backend then kUnsetDebugHandle should be passed in here. */ - virtual EventTracerEntry start_profiling_delegate( - const char* name, - DebugHandle delegate_debug_index) = 0; + virtual EventTracerEntry + start_profiling_delegate(const char *name, + DebugHandle delegate_debug_index) = 0; /** * Signal the end of the delegate profiling event contained in @@ -186,10 +185,9 @@ class EventTracer { * make it available for the user again in the post-processing stage. * @param[in] metadata_len Length of the metadata buffer. */ - virtual void end_profiling_delegate( - EventTracerEntry event_tracer_entry, - const void* metadata = nullptr, - size_t metadata_len = 0) = 0; + virtual void end_profiling_delegate(EventTracerEntry event_tracer_entry, + const void *metadata = nullptr, + size_t metadata_len = 0) = 0; /** * Some delegates get access to the profiling details only after the complete @@ -216,13 +214,12 @@ class EventTracer { * make it available for the user again in the post-processing stage. * @param[in] metadata_len Length of the metadata buffer. */ - virtual void log_profiling_delegate( - const char* name, - DebugHandle delegate_debug_index, - et_timestamp_t start_time, - et_timestamp_t end_time, - const void* metadata = nullptr, - size_t metadata_len = 0) = 0; + virtual void log_profiling_delegate(const char *name, + DebugHandle delegate_debug_index, + et_timestamp_t start_time, + et_timestamp_t end_time, + const void *metadata = nullptr, + size_t metadata_len = 0) = 0; /** * End the profiling of the event identified by prof_entry @@ -251,7 +248,7 @@ class EventTracer { * * @return Identifier to uniquely identify this allocator. */ - virtual AllocatorID track_allocator(const char* name) = 0; + virtual AllocatorID track_allocator(const char *name) = 0; /** * Log an evalue during the execution of the model. This is useful for @@ -265,9 +262,8 @@ class EventTracer { * @param[in] evalue_type Indicates what type of output this is logging e.g. * an intermediate output, program output etc. */ - virtual void log_evalue( - const EValue& evalue, - LoggedEValueType evalue_type) = 0; + virtual void log_evalue(const EValue &evalue, + LoggedEValueType evalue_type) = 0; /** * Log an intermediate tensor output from a delegate. @@ -284,10 +280,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The tensor type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const executorch::aten::Tensor& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const executorch::aten::Tensor &output) = 0; /** * Log an intermediate tensor array output from a delegate. @@ -305,8 +301,7 @@ class EventTracer { * @param[in] output The tensor array type output to be logged. */ virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, + const char *name, DebugHandle delegate_debug_index, const ArrayRef output) = 0; /** @@ -324,10 +319,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The int type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const int& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const int &output) = 0; /** * Log an intermediate bool output from a delegate. @@ -344,10 +339,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The bool type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const bool& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const bool &output) = 0; /** * Log an intermediate double output from a delegate. @@ -364,10 +359,10 @@ class EventTracer { * backend then kUnsetDebugHandle should be passed in here. * @param[in] output The double type output to be logged. */ - virtual void log_intermediate_output_delegate( - const char* name, - DebugHandle delegate_debug_index, - const double& output) = 0; + virtual void + log_intermediate_output_delegate(const char *name, + DebugHandle delegate_debug_index, + const double &output) = 0; /** * Helper function to set the chain id ands debug handle. Users have two @@ -416,9 +411,7 @@ class EventTracer { /** * Return the current bundled input index. */ - int bundled_input_index() { - return bundled_input_index_; - } + int bundled_input_index() { return bundled_input_index_; } /** * Set the level of event tracer debug logging that is desired. @@ -438,8 +431,8 @@ class EventTracer { /** * Set the level of event tracer profiling that is desired. */ - void set_event_tracer_profiling_level( - EventTracerProfilingLevel profiling_level) { + void + set_event_tracer_profiling_level(EventTracerProfilingLevel profiling_level) { event_tracer_profiling_level_ = profiling_level; } @@ -462,22 +455,18 @@ class EventTracer { * * @return Current chain id. */ - ChainID current_chain_id() { - return chain_id_; - } + ChainID current_chain_id() { return chain_id_; } /** * Get the current debug handle. * * @return Current debug handle. */ - DebugHandle current_debug_handle() { - return debug_handle_; - } + DebugHandle current_debug_handle() { return debug_handle_; } virtual ~EventTracer() {} - protected: +protected: ChainID chain_id_ = kUnsetChainId; DebugHandle debug_handle_ = kUnsetDebugHandle; bool event_tracer_enable_debugging_ = false; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h index 40754160..1e46013c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h @@ -38,8 +38,8 @@ namespace internal { * operators only. If operator profiling is disabled then this class is a no-op. */ class EventTracerProfileOpScope final { - public: - EventTracerProfileOpScope(EventTracer* event_tracer, const char* name) { +public: + EventTracerProfileOpScope(EventTracer *event_tracer, const char *name) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -67,9 +67,9 @@ class EventTracerProfileOpScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; EventTracerEntry event_entry_; #endif }; @@ -83,8 +83,8 @@ using EventTracerProfileScope = EventTracerProfileOpScope; * be used for profiling methods in the runtime. */ class EventTracerProfileMethodScope final { - public: - EventTracerProfileMethodScope(EventTracer* event_tracer, const char* name) { +public: + EventTracerProfileMethodScope(EventTracer *event_tracer, const char *name) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -106,9 +106,9 @@ class EventTracerProfileMethodScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; EventTracerEntry event_entry_; #endif }; @@ -122,11 +122,10 @@ class EventTracerProfileMethodScope final { * debug handle to defaults when this object goes out of scope. */ class EventTracerProfileInstructionScope final { - public: - EventTracerProfileInstructionScope( - EventTracer* event_tracer, - ChainID chain_idx, - DebugHandle debug_handle) { +public: + EventTracerProfileInstructionScope(EventTracer *event_tracer, + ChainID chain_idx, + DebugHandle debug_handle) { #ifdef ET_EVENT_TRACER_ENABLED event_tracer_ = event_tracer; if (event_tracer_ == nullptr) { @@ -149,9 +148,9 @@ class EventTracerProfileInstructionScope final { #endif } - private: +private: #ifdef ET_EVENT_TRACER_ENABLED - EventTracer* event_tracer_; + EventTracer *event_tracer_; #endif }; @@ -166,9 +165,8 @@ inline bool event_tracer_enabled() { * Create a new event block with the specified name. Any events logged * after this will be associated with this new event block. */ -inline void event_tracer_create_event_block( - EventTracer* event_tracer, - char const* name) { +inline void event_tracer_create_event_block(EventTracer *event_tracer, + char const *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->create_event_block(name); @@ -185,9 +183,9 @@ inline void event_tracer_create_event_block( * around and pass into the corresponding event_tracer_end_profiling_event * call. */ -inline EventTracerEntry event_tracer_begin_profiling_event( - EventTracer* event_tracer, - char const* name) { +inline EventTracerEntry +event_tracer_begin_profiling_event(EventTracer *event_tracer, + char const *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->start_profiling(name); @@ -204,9 +202,8 @@ inline EventTracerEntry event_tracer_begin_profiling_event( * Mark the end of a profiling event passing in the entry token * returned by a previous call to ET_EVENT_TRACER_BEGIN_PROFILING_EVENT. */ -inline void event_tracer_end_profiling_event( - EventTracer* event_tracer, - EventTracerEntry event) { +inline void event_tracer_end_profiling_event(EventTracer *event_tracer, + EventTracerEntry event) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->end_profiling(event); @@ -222,9 +219,8 @@ inline void event_tracer_end_profiling_event( * an AllocatorID that will be used to track all subsequent allocations done by * this allocator. */ -inline AllocatorID event_tracer_track_allocator( - EventTracer* event_tracer, - const char* name) { +inline AllocatorID event_tracer_track_allocator(EventTracer *event_tracer, + const char *name) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->track_allocator(name); @@ -238,10 +234,8 @@ inline AllocatorID event_tracer_track_allocator( } /// Log the allocation event done via the allocator represented by id. -inline void event_tracer_track_allocation( - EventTracer* event_tracer, - AllocatorID id, - size_t size) { +inline void event_tracer_track_allocation(EventTracer *event_tracer, + AllocatorID id, size_t size) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->track_allocation(id, size); @@ -254,7 +248,7 @@ inline void event_tracer_track_allocation( } /// Log an intermediate value. -inline void event_tracer_log_evalue(EventTracer* event_tracer, EValue& evalue) { +inline void event_tracer_log_evalue(EventTracer *event_tracer, EValue &evalue) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { if (event_tracer->event_tracer_debug_level() >= @@ -269,9 +263,8 @@ inline void event_tracer_log_evalue(EventTracer* event_tracer, EValue& evalue) { } /// Log a program output. -inline void event_tracer_log_evalue_output( - EventTracer* event_tracer, - const EValue& evalue) { +inline void event_tracer_log_evalue_output(EventTracer *event_tracer, + const EValue &evalue) { #ifdef ET_EVENT_TRACER_ENABLED /* * If debugging via event tracer is enabled but intermediate output logging is @@ -291,9 +284,8 @@ inline void event_tracer_log_evalue_output( // Set the bundled input index of the current bundled input being used by the // method. -inline void event_tracer_set_bundled_input_index( - EventTracer* event_tracer, - int bundled_input_index) { +inline void event_tracer_set_bundled_input_index(EventTracer *event_tracer, + int bundled_input_index) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { event_tracer->set_bundled_input_index(bundled_input_index); diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h index b2369fc2..17024630 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h @@ -47,10 +47,10 @@ namespace runtime { * based names are used by this delegate to identify ops executed in the * backend then kUnsetDebugHandle should be passed in here. */ -inline EventTracerEntry event_tracer_start_profiling_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id) { +inline EventTracerEntry +event_tracer_start_profiling_delegate(EventTracer *event_tracer, + const char *name, + DebugHandle delegate_debug_id) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { return event_tracer->start_profiling_delegate(name, delegate_debug_id); @@ -80,14 +80,12 @@ inline EventTracerEntry event_tracer_start_profiling_delegate( * @param[in] metadata_len Length of the metadata buffer. */ inline void event_tracer_end_profiling_delegate( - EventTracer* event_tracer, - EventTracerEntry event_tracer_entry, - const void* metadata = nullptr, - size_t metadata_len = 0) { + EventTracer *event_tracer, EventTracerEntry event_tracer_entry, + const void *metadata = nullptr, size_t metadata_len = 0) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { - event_tracer->end_profiling_delegate( - event_tracer_entry, metadata, metadata_len); + event_tracer->end_profiling_delegate(event_tracer_entry, metadata, + metadata_len); } #else //! ET_EVENT_TRACER_ENABLED (void)event_tracer_entry; @@ -124,17 +122,13 @@ inline void event_tracer_end_profiling_delegate( * @param[in] metadata_len Length of the metadata buffer. */ inline void event_tracer_log_profiling_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id, - et_timestamp_t start_time, - et_timestamp_t end_time, - const void* metadata = nullptr, - size_t metadata_len = 0) { + EventTracer *event_tracer, const char *name, DebugHandle delegate_debug_id, + et_timestamp_t start_time, et_timestamp_t end_time, + const void *metadata = nullptr, size_t metadata_len = 0) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { - event_tracer->log_profiling_delegate( - name, delegate_debug_id, start_time, end_time, metadata, metadata_len); + event_tracer->log_profiling_delegate(name, delegate_debug_id, start_time, + end_time, metadata, metadata_len); } #else //! ET_EVENT_TRACER_ENABLED (void)name; @@ -166,11 +160,10 @@ inline void event_tracer_log_profiling_delegate( * @param[in] output The output to be logged. */ template -inline void event_tracer_log_output_delegate( - EventTracer* event_tracer, - const char* name, - DebugHandle delegate_debug_id, - const T& output) { +inline void event_tracer_log_output_delegate(EventTracer *event_tracer, + const char *name, + DebugHandle delegate_debug_id, + const T &output) { #ifdef ET_EVENT_TRACER_ENABLED if (event_tracer) { static_assert( @@ -179,8 +172,8 @@ inline void event_tracer_log_output_delegate( std::is_same::value || std::is_same>::value, "Unsupported type for intermediate output"); - event_tracer->log_intermediate_output_delegate( - name, delegate_debug_id, output); + event_tracer->log_intermediate_output_delegate(name, delegate_debug_id, + output); } #else //! ET_EVENT_TRACER_ENABLED (void)name; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h index 84b918bf..c2443d36 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h @@ -12,36 +12,36 @@ #ifdef USE_ATEN_LIB #include // @manual #include -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include -#else // use executor -#include // @manual -#include // @manual +#else // use executor +#include // @manual +#include // @manual #include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual -#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual +#include // @manual #include // @manual #endif @@ -57,10 +57,8 @@ using Tensor = at::Tensor; using TensorList = at::TensorList; using TensorImpl = at::TensorImpl; using string_view = c10::string_view; -template -using ArrayRef = c10::ArrayRef; -template -using optional = std::optional; +template using ArrayRef = c10::ArrayRef; +template using optional = std::optional; using nullopt_t = c10::nullopt_t; using c10::nullopt; using ScalarType = at::ScalarType; @@ -75,8 +73,7 @@ using Layout = c10::Layout; // Custom types that map to ScalarType using Half = c10::Half; -template -using complex = c10::complex; +template using complex = c10::complex; using qint8 = c10::qint8; using quint8 = c10::quint8; using qint32 = c10::qint32; @@ -85,11 +82,10 @@ using quint4x2 = c10::quint4x2; using quint2x4 = c10::quint2x4; using IntArrayRef = at::IntArrayRef; -template -using OptionalArrayRef = c10::OptionalArrayRef; +template using OptionalArrayRef = c10::OptionalArrayRef; using OptionalIntArrayRef = OptionalArrayRef; -inline ssize_t compute_numel(const SizesType* sizes, ssize_t dim) { +inline ssize_t compute_numel(const SizesType *sizes, ssize_t dim) { return static_cast( c10::multiply_integers(c10::ArrayRef(sizes, dim))); } @@ -99,10 +95,8 @@ inline ssize_t compute_numel(const SizesType* sizes, ssize_t dim) { using Tensor = torch::executor::Tensor; using TensorImpl = torch::executor::TensorImpl; using string_view = torch::executor::string_view; -template -using ArrayRef = torch::executor::ArrayRef; -template -using optional = torch::executor::optional; +template using ArrayRef = torch::executor::ArrayRef; +template using optional = torch::executor::optional; using nullopt_t = torch::executor::nullopt_t; // NOLINTNEXTLINE(facebook-hte-NamespaceScopedStaticDeclaration) static constexpr nullopt_t nullopt{0}; @@ -119,8 +113,7 @@ using Layout = torch::executor::Layout; // Custom types that map to ScalarType using Half = torch::executor::Half; -template -using complex = torch::executor::complex; +template using complex = torch::executor::complex; using qint8 = torch::executor::qint8; using quint8 = torch::executor::quint8; using qint32 = torch::executor::qint32; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h index 4c5858fb..c1ea45b8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h @@ -19,7 +19,7 @@ namespace runtime { namespace { template -bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { +bool validate_dim_order(const DimOrderType *dim_order, const size_t dims) { for (int32_t i = 0; i < dims; ++i) { if (dim_order[i] >= dims) { return false; @@ -37,9 +37,8 @@ bool validate_dim_order(const DimOrderType* dim_order, const size_t dims) { * @param[in] dims length of the dim_order array */ template -inline bool is_contiguous_dim_order( - const DimOrderType* dim_order, - const size_t dims) { +inline bool is_contiguous_dim_order(const DimOrderType *dim_order, + const size_t dims) { for (int i = 0; i < dims; ++i) { if (dim_order[i] != i) { return false; @@ -56,9 +55,8 @@ inline bool is_contiguous_dim_order( * @param[in] dims length of the dim_order array */ template -bool is_channels_last_dim_order( - const DimOrderType* dim_order, - const size_t dims) { +bool is_channels_last_dim_order(const DimOrderType *dim_order, + const size_t dims) { if (dims != 4 && dims != 5) { return false; } @@ -108,11 +106,10 @@ bool is_channels_last_dim_order( * dim_order_to_stride which will check that the dim order is valid. */ template -inline void dim_order_to_stride_nocheck( - const SizesType* sizes, - const DimOrderType* dim_order, - const size_t dims, - StridesType* strides) { +inline void dim_order_to_stride_nocheck(const SizesType *sizes, + const DimOrderType *dim_order, + const size_t dims, + StridesType *strides) { // For 0 dim tensors, just return ok. if (dims == 0) { return; @@ -134,20 +131,17 @@ inline void dim_order_to_stride_nocheck( } template -ET_NODISCARD inline Error dim_order_to_stride( - const SizesType* sizes, - const DimOrderType* dim_order, - const size_t dims, - StridesType* strides) { +ET_NODISCARD inline Error +dim_order_to_stride(const SizesType *sizes, const DimOrderType *dim_order, + const size_t dims, StridesType *strides) { // For 0 dim tensors, just return ok. if (dims == 0) { return Error::Ok; } - ET_CHECK_OR_RETURN_ERROR( - validate_dim_order(dim_order, dims), - InvalidArgument, - "Invalid dim order. One of the value is larger than the number of dims %zu", - dims); + ET_CHECK_OR_RETURN_ERROR(validate_dim_order(dim_order, dims), InvalidArgument, + "Invalid dim order. One of the value is larger than " + "the number of dims %zu", + dims); dim_order_to_stride_nocheck(sizes, dim_order, dims, strides); return Error::Ok; @@ -155,23 +149,21 @@ ET_NODISCARD inline Error dim_order_to_stride( namespace internal { -template -struct StrideDimOrder { +template struct StrideDimOrder { StridesType stride; DimOrderType dim_order; StrideDimOrder(StridesType stride, DimOrderType dim_order) : stride(stride), dim_order(dim_order) {} StrideDimOrder() = default; - bool operator>(const StrideDimOrder& other) const { + bool operator>(const StrideDimOrder &other) const { // descending order return stride < other.stride; } }; -template -struct Sorter { - public: +template struct Sorter { +public: void quick_sort(ValueType arr[], int32_t low, int32_t high) { if (low < high) { ValueType pivot = arr[high]; @@ -182,15 +174,15 @@ struct Sorter { } } - private: +private: void swap(ValueType arr[], int32_t pos1, int32_t pos2) noexcept { ValueType temp = arr[pos1]; arr[pos1] = arr[pos2]; arr[pos2] = temp; } - int32_t - partition(ValueType arr[], int32_t low, int32_t high, ValueType pivot) { + int32_t partition(ValueType arr[], int32_t low, int32_t high, + ValueType pivot) { int32_t i = low; int32_t j = low; while (i <= high) { @@ -226,21 +218,15 @@ struct Sorter { * TODO(T148342910) */ template -ET_NODISCARD inline Error stride_to_dim_order( - const StridesType* strides, - const size_t dims, - DimOrderType* dim_order) { +ET_NODISCARD inline Error stride_to_dim_order(const StridesType *strides, + const size_t dims, + DimOrderType *dim_order) { const size_t kMaxNumOfDimensions = 16; - ET_CHECK_OR_RETURN_ERROR( - dim_order != nullptr, - MemoryAllocationFailed, - "Need memory to get dim_order."); - ET_CHECK_OR_RETURN_ERROR( - dims <= kMaxNumOfDimensions, - NotSupported, - "dims %zu exceeds maximum allowed %zu", - dims, - kMaxNumOfDimensions); + ET_CHECK_OR_RETURN_ERROR(dim_order != nullptr, MemoryAllocationFailed, + "Need memory to get dim_order."); + ET_CHECK_OR_RETURN_ERROR(dims <= kMaxNumOfDimensions, NotSupported, + "dims %zu exceeds maximum allowed %zu", dims, + kMaxNumOfDimensions); internal::StrideDimOrder array[kMaxNumOfDimensions]; for (DimOrderType i = 0; i < dims; i++) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h index e500167f..6016dab8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h @@ -67,19 +67,17 @@ namespace runtime { template struct is_floating_point : std::integral_constant< - bool, - std::is_floating_point::value || - std::is_same::value || - std::is_same::value> {}; + bool, std::is_floating_point::value || + std::is_same::value || + std::is_same::value> {}; // Util to figure out if the scalar type is one of the // reduced precision floating point types. template struct is_reduced_floating_point : std::integral_constant< - bool, - std::is_same::value || - std::is_same::value> {}; + bool, std::is_same::value || + std::is_same::value> {}; template constexpr bool is_reduced_floating_point_v = @@ -87,13 +85,12 @@ constexpr bool is_reduced_floating_point_v = #endif /// Maps ScalarTypes to C++ types. -template <::executorch::aten::ScalarType N> -struct ScalarTypeToCppType; +template <::executorch::aten::ScalarType N> struct ScalarTypeToCppType; -#define SPECIALIZE_ScalarTypeToCppType(cpp_type, scalar_type) \ - template <> \ - struct ScalarTypeToCppType<::executorch::aten::ScalarType::scalar_type> { \ - using type = cpp_type; \ +#define SPECIALIZE_ScalarTypeToCppType(cpp_type, scalar_type) \ + template <> \ + struct ScalarTypeToCppType<::executorch::aten::ScalarType::scalar_type> { \ + using type = cpp_type; \ }; ET_FORALL_SCALAR_TYPES(SPECIALIZE_ScalarTypeToCppType) @@ -101,15 +98,14 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_ScalarTypeToCppType) #undef SPECIALIZE_ScalarTypeToCppType /// Maps C++ types to ScalarTypes. -template -struct CppTypeToScalarType; +template struct CppTypeToScalarType; -#define SPECIALIZE_CppTypeToScalarType(cpp_type, scalar_type) \ - template <> \ - struct CppTypeToScalarType \ - : std::integral_constant< \ - ::executorch::aten::ScalarType, \ - ::executorch::aten::ScalarType::scalar_type> {}; +#define SPECIALIZE_CppTypeToScalarType(cpp_type, scalar_type) \ + template <> \ + struct CppTypeToScalarType \ + : std::integral_constant<::executorch::aten::ScalarType, \ + ::executorch::aten::ScalarType::scalar_type> { \ + }; ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) @@ -131,221 +127,221 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) // In this context, "INT" means integer C types, which is why the quantized // integer types are not included. -#define ET_FORALL_INT_TYPES(_) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ +#define ET_FORALL_INT_TYPES(_) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ _(int64_t, Long) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. -#define ET_FORALL_INT_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ +#define ET_FORALL_INT_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ _(ANOTHER_INPUT, int64_t, Long) -#define ET_FORALL_INT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ +#define ET_FORALL_INT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) -#define ET_FORALL_INT_TYPES_AND(SCALARTYPE, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_INT_TYPES_AND(SCALARTYPE, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) // In this context, "FLOAT" means float C types, which is why BFloat16 is not // included. -#define ET_FORALL_FLOAT_TYPES(_) \ - _(float, Float) \ +#define ET_FORALL_FLOAT_TYPES(_) \ + _(float, Float) \ _(double, Double) -#define ET_FORALL_FLOAT_TYPES_AND(SCALARTYPE, _) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_FLOAT_TYPES_AND(SCALARTYPE, _) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_FLOAT_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_FLOAT_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) #define ET_FORALL_FLOATH_TYPES(_) ET_FORALL_FLOAT_TYPES_AND(Half, _) -#define ET_FORALL_FLOATHBF16_TYPES(_) \ +#define ET_FORALL_FLOATHBF16_TYPES(_) \ ET_FORALL_FLOAT_TYPES_AND2(Half, BFloat16, _) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. Not to be confused with another scalar type as in // `ET_FORALL_FLOAT_TYPES_AND`. -#define ET_FORALL_FLOAT_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, float, Float) \ +#define ET_FORALL_FLOAT_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, float, Float) \ _(ANOTHER_INPUT, double, Double) -#define ET_FORALL_FLOAT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ +#define ET_FORALL_FLOAT_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) -#define ET_FORALL_FLOATHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ +#define ET_FORALL_FLOATHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::BFloat16, BFloat16) // In this context, "REAL" means integer/float C types, which is why BFloat16 // and Half are not included. -#define ET_FORALL_REAL_TYPES(_) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ +#define ET_FORALL_REAL_TYPES(_) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ _(double, Double) // Here `ANOTHER_INPUT` should be another variable to be forwarded to a given // function. Not to be confused with another scalar type as in // `ET_FORALL_REAL_TYPES_AND`. -#define ET_FORALL_REAL_TYPES_WITH(ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ - _(ANOTHER_INPUT, int64_t, Long) \ - _(ANOTHER_INPUT, float, Float) \ +#define ET_FORALL_REAL_TYPES_WITH(ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ + _(ANOTHER_INPUT, int64_t, Long) \ + _(ANOTHER_INPUT, float, Float) \ _(ANOTHER_INPUT, double, Double) -#define ET_FORALL_REAL_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ +#define ET_FORALL_REAL_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) -#define ET_FORALL_REALHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ - _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ +#define ET_FORALL_REALHBF16_TYPES_WITH2(ANOTHER_INPUT1, ANOTHER_INPUT2, _) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, uint8_t, Byte) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int8_t, Char) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int16_t, Short) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int32_t, Int) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, int64_t, Long) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, float, Float) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, double, Double) \ + _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::Half, Half) \ _(ANOTHER_INPUT1, ANOTHER_INPUT2, ::executorch::aten::BFloat16, BFloat16) // For macros that take `SCALARTYPEn` parameters, those parameters should be // an unquoted/unqualified enumerator name like `Int` or `Float`. -#define ET_FORALL_REAL_TYPES_AND(SCALARTYPE, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_REAL_TYPES_AND(SCALARTYPE, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) #define ET_FORALL_REALH_TYPES(_) ET_FORALL_REAL_TYPES_AND(Half, _) -#define ET_FORALL_REALHBF16_TYPES(_) \ +#define ET_FORALL_REALHBF16_TYPES(_) \ ET_FORALL_REAL_TYPES_AND2(Half, BFloat16, _) -#define ET_FORALL_REALHBBF16_TYPES(_) \ +#define ET_FORALL_REALHBBF16_TYPES(_) \ ET_FORALL_REAL_TYPES_AND3(Bool, Half, BFloat16, _) -#define ET_FORALL_REAL_TYPES_AND_WITH(SCALARTYPE, ANOTHER_INPUT, _) \ - _(ANOTHER_INPUT, uint8_t, Byte) \ - _(ANOTHER_INPUT, int8_t, Char) \ - _(ANOTHER_INPUT, int16_t, Short) \ - _(ANOTHER_INPUT, int32_t, Int) \ - _(ANOTHER_INPUT, int64_t, Long) \ - _(ANOTHER_INPUT, float, Float) \ - _(ANOTHER_INPUT, double, Double) \ - _(ANOTHER_INPUT, \ - ::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE>::type, \ +#define ET_FORALL_REAL_TYPES_AND_WITH(SCALARTYPE, ANOTHER_INPUT, _) \ + _(ANOTHER_INPUT, uint8_t, Byte) \ + _(ANOTHER_INPUT, int8_t, Char) \ + _(ANOTHER_INPUT, int16_t, Short) \ + _(ANOTHER_INPUT, int32_t, Int) \ + _(ANOTHER_INPUT, int64_t, Long) \ + _(ANOTHER_INPUT, float, Float) \ + _(ANOTHER_INPUT, double, Double) \ + _(ANOTHER_INPUT, \ + ::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE>::type, \ SCALARTYPE) -#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ +#define ET_FORALL_REAL_TYPES_AND2(SCALARTYPE1, SCALARTYPE2, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ SCALARTYPE2) -#define ET_FORALL_REAL_TYPES_AND3(SCALARTYPE1, SCALARTYPE2, SCALARTYPE3, _) \ - _(uint8_t, Byte) \ - _(int8_t, Char) \ - _(int16_t, Short) \ - _(int32_t, Int) \ - _(int64_t, Long) \ - _(float, Float) \ - _(double, Double) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ - SCALARTYPE1) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ - SCALARTYPE2) \ - _(::executorch::runtime::ScalarTypeToCppType< \ - ::executorch::aten::ScalarType::SCALARTYPE3>::type, \ +#define ET_FORALL_REAL_TYPES_AND3(SCALARTYPE1, SCALARTYPE2, SCALARTYPE3, _) \ + _(uint8_t, Byte) \ + _(int8_t, Char) \ + _(int16_t, Short) \ + _(int32_t, Int) \ + _(int64_t, Long) \ + _(float, Float) \ + _(double, Double) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE1>::type, \ + SCALARTYPE1) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE2>::type, \ + SCALARTYPE2) \ + _(::executorch::runtime::ScalarTypeToCppType< \ + ::executorch::aten::ScalarType::SCALARTYPE3>::type, \ SCALARTYPE3) -#define ET_FORALL_QINT_TYPES(_) \ - _(::torch::executor::qint8, QInt8) \ - _(::torch::executor::quint8, QUInt8) \ - _(::torch::executor::qint32, QInt32) \ - _(::torch::executor::quint4x2, QUInt4x2) \ +#define ET_FORALL_QINT_TYPES(_) \ + _(::torch::executor::qint8, QInt8) \ + _(::torch::executor::quint8, QUInt8) \ + _(::torch::executor::qint32, QInt32) \ + _(::torch::executor::quint4x2, QUInt4x2) \ _(::torch::executor::quint2x4, QUInt2x4) // In this context, "COMPLEX" means complex types based on primitive C types, // which is why ComplexHalf is not included. -#define ET_FORALL_COMPLEX_TYPES(_) \ - _(::torch::executor::complex, ComplexFloat) \ +#define ET_FORALL_COMPLEX_TYPES(_) \ + _(::torch::executor::complex, ComplexFloat) \ _(::torch::executor::complex, ComplexDouble) // @@ -358,8 +354,8 @@ ET_FORALL_SCALAR_TYPES(SPECIALIZE_CppTypeToScalarType) */ inline bool isValid(::executorch::aten::ScalarType type) { return static_cast(type) >= 0 && - type < ::executorch::aten::ScalarType::NumOptions && - type != ::executorch::aten::ScalarType::Undefined; + type < ::executorch::aten::ScalarType::NumOptions && + type != ::executorch::aten::ScalarType::Undefined; } /** @@ -368,17 +364,17 @@ inline bool isValid(::executorch::aten::ScalarType type) { * @param[in] t The type to get the name of. * @return The name of the type, or "UNKNOWN_SCALAR" if the type is not known. */ -inline const char* toString(::executorch::aten::ScalarType t) { -#define DEFINE_CASE(_, name) \ - case ::executorch::aten::ScalarType::name: \ +inline const char *toString(::executorch::aten::ScalarType t) { +#define DEFINE_CASE(_, name) \ + case ::executorch::aten::ScalarType::name: \ return #name; switch (t) { ET_FORALL_SCALAR_TYPES(DEFINE_CASE) - case ::executorch::aten::ScalarType::Undefined: - return "Undefined"; - default: - return "UNKNOWN_SCALAR"; + case ::executorch::aten::ScalarType::Undefined: + return "Undefined"; + default: + return "UNKNOWN_SCALAR"; } #undef DEFINE_CASE } @@ -392,64 +388,59 @@ inline const char* toString(::executorch::aten::ScalarType t) { * @return The size of the associated C type in bytes. */ inline size_t elementSize(::executorch::aten::ScalarType t) { -#define CASE_ELEMENTSIZE_CASE(ctype, name) \ - case ::executorch::aten::ScalarType::name: \ +#define CASE_ELEMENTSIZE_CASE(ctype, name) \ + case ::executorch::aten::ScalarType::name: \ return sizeof(ctype); switch (t) { ET_FORALL_SCALAR_TYPES(CASE_ELEMENTSIZE_CASE) - default: - ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); + default: + ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); } #undef CASE_ELEMENTSIZE_CASE } -inline constexpr bool isIntegralType( - ::executorch::aten::ScalarType t, - bool includeBool) { +inline constexpr bool isIntegralType(::executorch::aten::ScalarType t, + bool includeBool) { return (includeBool && t == ::executorch::aten::ScalarType::Bool) || - (t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Short); + (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Short); } template struct is_integral_type : public std::integral_constant< - bool, - isIntegralType(CppTypeToScalarType::value, includeBool)> {}; + bool, isIntegralType(CppTypeToScalarType::value, includeBool)> {}; inline constexpr bool isFloatingType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Double || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Half || - t == ::executorch::aten::ScalarType::BFloat16); + return (t == ::executorch::aten::ScalarType::Double || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Half || + t == ::executorch::aten::ScalarType::BFloat16); } inline bool isRealType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Short || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Double); + return (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Short || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Double); } inline bool isRealHType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::Byte || - t == ::executorch::aten::ScalarType::Char || - t == ::executorch::aten::ScalarType::Short || - t == ::executorch::aten::ScalarType::Int || - t == ::executorch::aten::ScalarType::Long || - t == ::executorch::aten::ScalarType::Float || - t == ::executorch::aten::ScalarType::Double || - t == ::executorch::aten::ScalarType::Half); + return (t == ::executorch::aten::ScalarType::Byte || + t == ::executorch::aten::ScalarType::Char || + t == ::executorch::aten::ScalarType::Short || + t == ::executorch::aten::ScalarType::Int || + t == ::executorch::aten::ScalarType::Long || + t == ::executorch::aten::ScalarType::Float || + t == ::executorch::aten::ScalarType::Double || + t == ::executorch::aten::ScalarType::Half); } inline bool isRealHBType(::executorch::aten::ScalarType t) { @@ -465,23 +456,22 @@ inline bool isRealHBBF16Type(::executorch::aten::ScalarType t) { } inline constexpr bool isComplexType(::executorch::aten::ScalarType t) { - return ( - t == ::executorch::aten::ScalarType::ComplexHalf || - t == ::executorch::aten::ScalarType::ComplexFloat || - t == ::executorch::aten::ScalarType::ComplexDouble); + return (t == ::executorch::aten::ScalarType::ComplexHalf || + t == ::executorch::aten::ScalarType::ComplexFloat || + t == ::executorch::aten::ScalarType::ComplexDouble); } template -struct is_complex_type : std::integral_constant< - bool, +struct is_complex_type + : std::integral_constant::value)> {}; constexpr bool isBitsType(::executorch::aten::ScalarType t) { return t == ::executorch::aten::ScalarType::Bits1x8 || - t == ::executorch::aten::ScalarType::Bits2x4 || - t == ::executorch::aten::ScalarType::Bits4x2 || - t == ::executorch::aten::ScalarType::Bits8 || - t == ::executorch::aten::ScalarType::Bits16; + t == ::executorch::aten::ScalarType::Bits2x4 || + t == ::executorch::aten::ScalarType::Bits4x2 || + t == ::executorch::aten::ScalarType::Bits8 || + t == ::executorch::aten::ScalarType::Bits16; } template @@ -492,10 +482,10 @@ struct is_bits_type constexpr bool isQIntType(::executorch::aten::ScalarType t) { // Don't forget to extend this when adding new QInt types return t == ::executorch::aten::ScalarType::QInt8 || - t == ::executorch::aten::ScalarType::QUInt8 || - t == ::executorch::aten::ScalarType::QInt32 || - t == ::executorch::aten::ScalarType::QUInt4x2 || - t == ::executorch::aten::ScalarType::QUInt2x4; + t == ::executorch::aten::ScalarType::QUInt8 || + t == ::executorch::aten::ScalarType::QInt32 || + t == ::executorch::aten::ScalarType::QUInt4x2 || + t == ::executorch::aten::ScalarType::QUInt2x4; } template @@ -503,162 +493,149 @@ struct is_qint_type : std::integral_constant::value)> { }; -inline ::executorch::aten::ScalarType toQIntType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toQIntType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::Byte: - return ::executorch::aten::ScalarType::QUInt8; - case ::executorch::aten::ScalarType::Char: - return ::executorch::aten::ScalarType::QInt8; - case ::executorch::aten::ScalarType::Int: - return ::executorch::aten::ScalarType::QInt32; - default: - return t; + case ::executorch::aten::ScalarType::Byte: + return ::executorch::aten::ScalarType::QUInt8; + case ::executorch::aten::ScalarType::Char: + return ::executorch::aten::ScalarType::QInt8; + case ::executorch::aten::ScalarType::Int: + return ::executorch::aten::ScalarType::QInt32; + default: + return t; } } -inline ::executorch::aten::ScalarType toUnderlying( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toUnderlying(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::QUInt8: - return ::executorch::aten::ScalarType::Byte; - case ::executorch::aten::ScalarType::QInt8: - return ::executorch::aten::ScalarType::Char; - case ::executorch::aten::ScalarType::QInt32: - return ::executorch::aten::ScalarType::Int; - case ::executorch::aten::ScalarType::QUInt4x2: - return ::executorch::aten::ScalarType::Byte; - case ::executorch::aten::ScalarType::QUInt2x4: - return ::executorch::aten::ScalarType::Byte; - default: - return t; + case ::executorch::aten::ScalarType::QUInt8: + return ::executorch::aten::ScalarType::Byte; + case ::executorch::aten::ScalarType::QInt8: + return ::executorch::aten::ScalarType::Char; + case ::executorch::aten::ScalarType::QInt32: + return ::executorch::aten::ScalarType::Int; + case ::executorch::aten::ScalarType::QUInt4x2: + return ::executorch::aten::ScalarType::Byte; + case ::executorch::aten::ScalarType::QUInt2x4: + return ::executorch::aten::ScalarType::Byte; + default: + return t; } } inline bool isSignedType(::executorch::aten::ScalarType t) { - ET_CHECK_MSG( - !::executorch::runtime::isQIntType(t), - "isSignedType not supported for quantized types like %" PRId8, - static_cast(t)); -#define CASE_SIGNED(ctype, name) \ - case ::executorch::aten::ScalarType::name: \ + ET_CHECK_MSG(!::executorch::runtime::isQIntType(t), + "isSignedType not supported for quantized types like %" PRId8, + static_cast(t)); +#define CASE_SIGNED(ctype, name) \ + case ::executorch::aten::ScalarType::name: \ return std::numeric_limits::is_signed; switch (t) { - case ::executorch::aten::ScalarType::ComplexHalf: - case ::executorch::aten::ScalarType::ComplexFloat: - case ::executorch::aten::ScalarType::ComplexDouble: - return true; - ET_FORALL_REAL_TYPES_AND3(Half, Bool, BFloat16, CASE_SIGNED) - default: - ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); + case ::executorch::aten::ScalarType::ComplexHalf: + case ::executorch::aten::ScalarType::ComplexFloat: + case ::executorch::aten::ScalarType::ComplexDouble: + return true; + ET_FORALL_REAL_TYPES_AND3(Half, Bool, BFloat16, CASE_SIGNED) + default: + ET_CHECK_MSG(false, "Unknown ScalarType %" PRId8, static_cast(t)); } #undef CASE_SIGNED } -inline bool isUnderlying( - ::executorch::aten::ScalarType type, - ::executorch::aten::ScalarType qtype) { +inline bool isUnderlying(::executorch::aten::ScalarType type, + ::executorch::aten::ScalarType qtype) { return type == ::executorch::runtime::toUnderlying(qtype); } -inline ::executorch::aten::ScalarType toRealValueType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toRealValueType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::ComplexHalf: - return ::executorch::aten::ScalarType::Half; - case ::executorch::aten::ScalarType::ComplexFloat: - return ::executorch::aten::ScalarType::Float; - case ::executorch::aten::ScalarType::ComplexDouble: - return ::executorch::aten::ScalarType::Double; - default: - return t; + case ::executorch::aten::ScalarType::ComplexHalf: + return ::executorch::aten::ScalarType::Half; + case ::executorch::aten::ScalarType::ComplexFloat: + return ::executorch::aten::ScalarType::Float; + case ::executorch::aten::ScalarType::ComplexDouble: + return ::executorch::aten::ScalarType::Double; + default: + return t; } } -inline ::executorch::aten::ScalarType toComplexType( - ::executorch::aten::ScalarType t) { +inline ::executorch::aten::ScalarType +toComplexType(::executorch::aten::ScalarType t) { switch (t) { - case ::executorch::aten::ScalarType::BFloat16: - // BFloat16 has range equivalent to Float, - // so we map it to ComplexFloat. - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::Half: - return ::executorch::aten::ScalarType::ComplexHalf; - case ::executorch::aten::ScalarType::Float: - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::Double: - return ::executorch::aten::ScalarType::ComplexDouble; - case ::executorch::aten::ScalarType::ComplexHalf: - return ::executorch::aten::ScalarType::ComplexHalf; - case ::executorch::aten::ScalarType::ComplexFloat: - return ::executorch::aten::ScalarType::ComplexFloat; - case ::executorch::aten::ScalarType::ComplexDouble: - return ::executorch::aten::ScalarType::ComplexDouble; - default: - ET_CHECK_MSG( - false, - "Unknown Complex ScalarType for %" PRId8, - static_cast(t)); + case ::executorch::aten::ScalarType::BFloat16: + // BFloat16 has range equivalent to Float, + // so we map it to ComplexFloat. + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::Half: + return ::executorch::aten::ScalarType::ComplexHalf; + case ::executorch::aten::ScalarType::Float: + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::Double: + return ::executorch::aten::ScalarType::ComplexDouble; + case ::executorch::aten::ScalarType::ComplexHalf: + return ::executorch::aten::ScalarType::ComplexHalf; + case ::executorch::aten::ScalarType::ComplexFloat: + return ::executorch::aten::ScalarType::ComplexFloat; + case ::executorch::aten::ScalarType::ComplexDouble: + return ::executorch::aten::ScalarType::ComplexDouble; + default: + ET_CHECK_MSG(false, "Unknown Complex ScalarType for %" PRId8, + static_cast(t)); } } /** * Encodes type casting rules that are consistent with ATen behaviour. */ -inline constexpr bool canCast( - const ::executorch::aten::ScalarType from, - const ::executorch::aten::ScalarType to) { +inline constexpr bool canCast(const ::executorch::aten::ScalarType from, + const ::executorch::aten::ScalarType to) { // Disallow complex -> non-complex return !(::executorch::runtime::isComplexType(from) && !::executorch::runtime::isComplexType(to)) && - // Disallow float -> integral - !(::executorch::runtime::isFloatingType(from) && - ::executorch::runtime::isIntegralType(to, /*includeBool=*/false)) && - // Treat bool as a special category. Disallow non-bool -> bool - !(from != ::executorch::aten::ScalarType::Bool && - to == ::executorch::aten::ScalarType::Bool); + // Disallow float -> integral + !(::executorch::runtime::isFloatingType(from) && + ::executorch::runtime::isIntegralType(to, /*includeBool=*/false)) && + // Treat bool as a special category. Disallow non-bool -> bool + !(from != ::executorch::aten::ScalarType::Bool && + to == ::executorch::aten::ScalarType::Bool); } template -struct can_cast : std::integral_constant< - bool, - canCast( - CppTypeToScalarType::value, - CppTypeToScalarType::value)> {}; +struct can_cast + : std::integral_constant::value, + CppTypeToScalarType::value)> {}; /** * When casting from floating point to integral type, if the floating value is * outside the integral type range, then an error is thrown if sanitization is * enabled. To circumvent this, we cast the floating point to int64_t first. */ -template < - typename To, - typename From, - typename std::enable_if< - (std::is_floating_point::value && std::is_integral::value), - int>::type = 0> +template ::value && + std::is_integral::value), + int>::type = 0> To convert(From val) { return static_cast(static_cast(val)); } -template < - typename To, - typename From, - typename std::enable_if< - !(std::is_floating_point::value && std::is_integral::value), - int>::type = 0> +template ::value && + std::is_integral::value), + int>::type = 0> To convert(From val) { return static_cast(val); } namespace internal { -template -struct promote_types_lookup; +template struct promote_types_lookup; -template -struct promote_types_lookup { +template struct promote_types_lookup { using type = T1; }; @@ -689,10 +666,9 @@ using B1 = using BF = typename ScalarTypeToCppType< ::executorch::aten::ScalarType::BFloat16>::type; -#define TABLE_ENTRY(key1, key2, value) \ - template <> \ - struct promote_types_lookup { \ - using type = value; \ +#define TABLE_ENTRY(key1, key2, value) \ + template <> struct promote_types_lookup { \ + using type = value; \ } /* promote_types_lookup is a compile-time-accessible version of the @@ -874,20 +850,18 @@ TABLE_ENTRY(BF, BF, BF); template struct promote_types { - private: - static_assert( - std::is_same::value || - (!is_qint_type::value && !is_qint_type::value), - "promote_types not valid for quantized dtypes"); - static_assert( - std::is_same::value || - (!is_bits_type::value && !is_bits_type::value), - "promote_types not valid for bits dtypes"); +private: + static_assert(std::is_same::value || + (!is_qint_type::value && !is_qint_type::value), + "promote_types not valid for quantized dtypes"); + static_assert(std::is_same::value || + (!is_bits_type::value && !is_bits_type::value), + "promote_types not valid for bits dtypes"); using promoted_type_not_respecting_half_to_float = typename internal::promote_types_lookup::type; - public: +public: using type = typename std::conditional< half_to_float && (std::is_same< @@ -908,10 +882,9 @@ struct promote_types { * If half_to_float is set to true, then half and bfloat16 will be promoted to * float instead */ -inline ::executorch::aten::ScalarType promoteTypes( - ::executorch::aten::ScalarType a, - ::executorch::aten::ScalarType b, - bool half_to_float = false) { +inline ::executorch::aten::ScalarType +promoteTypes(::executorch::aten::ScalarType a, ::executorch::aten::ScalarType b, + bool half_to_float = false) { // This is generated according to NumPy's promote_types constexpr auto u1 = ::executorch::aten::ScalarType::Byte; constexpr auto i1 = ::executorch::aten::ScalarType::Char; @@ -948,12 +921,12 @@ inline ::executorch::aten::ScalarType promoteTypes( // 12 types are handled by this function, see the constexpr definitions above const int NUM_PROMOTE_TYPES = 13; - static constexpr std:: - array - dtype2index = {{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1, - }}; + static constexpr std::array + dtype2index = {{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1, + }}; auto ix_a = dtype2index[(int)a]; ET_CHECK(ix_a != -1); auto ix_b = dtype2index[(int)b]; @@ -997,200 +970,197 @@ inline ::executorch::aten::ScalarType promoteTypes( // #ifdef ET_INTERNAL_CHECK_SELECTIVE_BUILD -#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ - case enum_type: { \ - ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type); \ - using CTYPE_ALIAS = \ - ::executorch::runtime::ScalarTypeToCppType::type; \ - return __VA_ARGS__(); \ +#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ + case enum_type: { \ + ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type); \ + using CTYPE_ALIAS = \ + ::executorch::runtime::ScalarTypeToCppType::type; \ + return __VA_ARGS__(); \ } #else -#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ - case enum_type: { \ - using CTYPE_ALIAS = \ - ::executorch::runtime::ScalarTypeToCppType::type; \ - return __VA_ARGS__(); \ +#define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \ + case enum_type: { \ + using CTYPE_ALIAS = \ + ::executorch::runtime::ScalarTypeToCppType::type; \ + return __VA_ARGS__(); \ } #endif -#define ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, ...) \ - [&] { \ - const auto& _st = TYPE; \ - constexpr const char* et_switch_name = NAME; \ - (void)et_switch_name; /* Suppress unused var */ \ - switch (_st) { \ - __VA_ARGS__ \ - default: \ - ET_CHECK_MSG( \ - false, \ - "Unhandled dtype %s for %s", \ - ::executorch::runtime::toString(_st), \ - et_switch_name); \ - } \ +#define ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, ...) \ + [&] { \ + const auto &_st = TYPE; \ + constexpr const char *et_switch_name = NAME; \ + (void)et_switch_name; /* Suppress unused var */ \ + switch (_st) { \ + __VA_ARGS__ \ + default: \ + ET_CHECK_MSG(false, "Unhandled dtype %s for %s", \ + ::executorch::runtime::toString(_st), et_switch_name); \ + } \ }() #define ET_INTERNAL_SWITCH_CASE_ALL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Half, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexHalf, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexFloat, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexDouble, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::BFloat16, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt2x4, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits1x8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits2x4, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bits16, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ - ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL3, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Char, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Short, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Int, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ - ADDITIONAL1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt4x2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::QUInt2x4, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexFloat, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::ComplexDouble, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Long, CTYPE_ALIAS, __VA_ARGS__) - -#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES(CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Half, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexHalf, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexFloat, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexDouble, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::BFloat16, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt2x4, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits1x8, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits2x4, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bits16, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL1, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3(ADDITIONAL1, ADDITIONAL2, \ + ADDITIONAL3, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL3, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Byte, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Char, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Short, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Int, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Float, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND(ADDITIONAL1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ADDITIONAL2, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt8, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QInt32, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt4x2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::QUInt2x4, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexFloat, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::ComplexDouble, \ + CTYPE_ALIAS, __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Long, CTYPE_ALIAS, \ + __VA_ARGS__) + +#define ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES(CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::Double, CTYPE_ALIAS, \ + __VA_ARGS__) // // Switch case macros @@ -1228,188 +1198,137 @@ inline ::executorch::aten::ScalarType promoteTypes( // used to alias the ctype associated with the ScalarType that is being handled. // -#define ET_SWITCH_ALL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_ALL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_ALL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REAL_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_REAL_TYPES_AND3( \ - ADDITIONAL1, \ - ADDITIONAL2, \ - ADDITIONAL3, \ - TYPE, \ - CONTEXT, \ - NAME, \ - CTYPE_ALIAS, \ - ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ +#define ET_SWITCH_REAL_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_REAL_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, \ + NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND2( \ + ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_REAL_TYPES_AND3(ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, TYPE, \ + CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ ADDITIONAL1, ADDITIONAL2, ADDITIONAL3, CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_REALH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_REALH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_REAL_TYPES_AND(Half, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_REALHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND2( \ - Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND2(Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_REALB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_REALB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_REAL_TYPES_AND(Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_REALHB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND2( \ - Half, Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND2(Half, Bool, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_REALHBBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_REAL_TYPES_AND3( \ - Half, Bool, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_REALHBBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_REAL_TYPES_AND3(Half, Bool, BFloat16, TYPE, CONTEXT, NAME, \ + CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_INT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_INT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_INT_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOAT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_INT_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_INT_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOAT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_FLOAT_TYPES_AND( \ - ADDITIONAL, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ - ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ - ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_FLOATH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ +#define ET_SWITCH_FLOAT_TYPES_AND(ADDITIONAL, TYPE, CONTEXT, NAME, \ + CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND( \ + ADDITIONAL, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOAT_TYPES_AND2(ADDITIONAL1, ADDITIONAL2, TYPE, CONTEXT, \ + NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES_AND2( \ + ADDITIONAL1, ADDITIONAL2, CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_FLOATH_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_SWITCH_FLOAT_TYPES_AND(Half, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) -#define ET_SWITCH_FLOATHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_SWITCH_FLOAT_TYPES_AND2( \ - Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) +#define ET_SWITCH_FLOATHBF16_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_SWITCH_FLOAT_TYPES_AND2(Half, BFloat16, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + __VA_ARGS__) -#define ET_SWITCH_QINT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_QINT_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_QINT_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_COMPLEX_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_COMPLEX_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_SCALAR_OBJ_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ +#define ET_SWITCH_SCALAR_OBJ_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_TYPES(CTYPE_ALIAS, __VA_ARGS__)) #define ET_SWITCH_SCALAR_OBJ_REAL_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_REAL_TYPES(CTYPE_ALIAS, __VA_ARGS__)) #define ET_SWITCH_SCALAR_OBJ_INTB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ + TYPE, CONTEXT, NAME, \ ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_INTB_TYPES(CTYPE_ALIAS, __VA_ARGS__)) -#define ET_SWITCH_SCALAR_OBJ_FLOATB_TYPES( \ - TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES( \ - CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_TWO_TYPES(T1, T2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T2, CTYPE_ALIAS, __VA_ARGS__)) - -#define ET_SWITCH_THREE_TYPES( \ - T1, T2, T3, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ - ET_INTERNAL_SWITCH( \ - TYPE, \ - CONTEXT, \ - NAME, \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T1, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T2, CTYPE_ALIAS, __VA_ARGS__) \ - ET_INTERNAL_SWITCH_CASE( \ - ::executorch::aten::ScalarType::T3, \ - CTYPE_ALIAS, \ - __VA_ARGS__)) +#define ET_SWITCH_SCALAR_OBJ_FLOATB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH(TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE_SCALAR_OBJ_FLOATB_TYPES( \ + CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_TWO_TYPES(T1, T2, TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T2, \ + CTYPE_ALIAS, __VA_ARGS__)) + +#define ET_SWITCH_THREE_TYPES(T1, T2, T3, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \ + ...) \ + ET_INTERNAL_SWITCH( \ + TYPE, CONTEXT, NAME, \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T1, CTYPE_ALIAS, \ + __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T2, \ + CTYPE_ALIAS, __VA_ARGS__) \ + ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T3, \ + CTYPE_ALIAS, __VA_ARGS__)) } // namespace runtime } // namespace executorch @@ -1418,7 +1337,7 @@ namespace executorch { namespace aten { #ifdef USE_ATEN_LIB using ::at::elementSize; -#else // USE_ATEN_LIB +#else // USE_ATEN_LIB using ::executorch::runtime::elementSize; #endif // USE_ATEN_LIB } // namespace aten diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h index eb57f3e0..935f9f5c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h @@ -9,7 +9,7 @@ #pragma once #include -#include // std::array +#include // std::array #include // PRId64 #include #include // size_t @@ -30,28 +30,22 @@ #define ET_NORMALIZE_IX(IX, UPPER_BOUND) IX < 0 ? IX + UPPER_BOUND : IX -#define ET_CHECK_VALID_IX(IX, UPPER_BOUND) \ - ET_CHECK_MSG( \ - IX >= -static_cast(UPPER_BOUND) && \ - IX < static_cast(UPPER_BOUND), \ - "index %" PRId64 " must be within range [-%zd, %zd)", \ - IX, \ - UPPER_BOUND, \ - UPPER_BOUND) - -#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \ - ET_CHECK_MSG( \ - DIM >= -static_cast(UPPER_BOUND) && \ - DIM < static_cast(UPPER_BOUND), \ - "dim %" PRId64 " must be within range [-%zd, %zd)", \ - DIM, \ - UPPER_BOUND, \ - UPPER_BOUND) - -#define ET_CHECK_NON_ZERO_DIM_SIZE(DIM, T) \ - const size_t udim = ET_NORMALIZE_IX(DIM, T.dim()); \ - ET_CHECK_MSG( \ - T.size(udim) != 0, "Expected dim %zd to have non-zero size.", udim); +#define ET_CHECK_VALID_IX(IX, UPPER_BOUND) \ + ET_CHECK_MSG(IX >= -static_cast(UPPER_BOUND) && \ + IX < static_cast(UPPER_BOUND), \ + "index %" PRId64 " must be within range [-%zd, %zd)", IX, \ + UPPER_BOUND, UPPER_BOUND) + +#define ET_CHECK_VALID_DIM(DIM, UPPER_BOUND) \ + ET_CHECK_MSG(DIM >= -static_cast(UPPER_BOUND) && \ + DIM < static_cast(UPPER_BOUND), \ + "dim %" PRId64 " must be within range [-%zd, %zd)", DIM, \ + UPPER_BOUND, UPPER_BOUND) + +#define ET_CHECK_NON_ZERO_DIM_SIZE(DIM, T) \ + const size_t udim = ET_NORMALIZE_IX(DIM, T.dim()); \ + ET_CHECK_MSG(T.size(udim) != 0, "Expected dim %zd to have non-zero size.", \ + udim); /** * Asserts that all tensors have the same shape. @@ -60,91 +54,72 @@ * iterating over the dimensions we make sure that we pick the smallest * dimension of all the tensors as the upper bound for the for loop. */ -#define ET_CHECK_SAME_SHAPE2(a__, b__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1) || (a_dim__ == b_dim__)), \ - ET_TENSOR_CHECK_PREFIX__ ": numel={%zu, %zu}, dim={%zu, %zu}", \ - a_numel__, \ - b_numel__, \ - a_dim__, \ - b_dim__); \ - for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE2(a__, b__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + ET_CHECK_MSG( \ + a_numel__ == b_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1) || (a_dim__ == b_dim__)), \ + ET_TENSOR_CHECK_PREFIX__ ": numel={%zu, %zu}, dim={%zu, %zu}", \ + a_numel__, b_numel__, a_dim__, b_dim__); \ + for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ + dim__, a_size__, b_size__); \ + } \ }) -#define ET_CHECK_SAME_SHAPE3(a__, b__, c__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t c_numel__ = (c__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const size_t c_dim__ = (c__).dim(); \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ - a_dim__ == b_dim__ && b_dim__ == c_dim__), \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}", \ - a_numel__, \ - b_numel__, \ - c_numel__, \ - a_dim__, \ - b_dim__, \ - c_dim__); \ - for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ - ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - size_t c_size__ = (c__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__ && b_size__ == c_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__, \ - c_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE3(a__, b__, c__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t c_numel__ = (c__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const size_t c_dim__ = (c__).dim(); \ + ET_CHECK_MSG(a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ + a_dim__ == b_dim__ && b_dim__ == c_dim__), \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}", \ + a_numel__, b_numel__, c_numel__, a_dim__, b_dim__, c_dim__); \ + for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ + ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + size_t c_size__ = (c__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__ && b_size__ == c_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ + dim__, a_size__, b_size__, c_size__); \ + } \ }) /// Asserts that all tensors have the same dtype. -#define ET_CHECK_SAME_DTYPE2(a__, b__) \ - ({ \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - ET_CHECK_MSG( \ - a_type__ == b_type__, \ - ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 "}", \ - static_cast(a_type__), \ - static_cast(b_type__)); \ +#define ET_CHECK_SAME_DTYPE2(a__, b__) \ + ({ \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + ET_CHECK_MSG(a_type__ == b_type__, \ + ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 "}", \ + static_cast(a_type__), \ + static_cast(b_type__)); \ }) -#define ET_CHECK_SAME_DTYPE3(a__, b__, c__) \ - ({ \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ - ET_CHECK_MSG( \ - a_type__ == b_type__ && b_type__ == c_type__, \ - ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 ", %" PRId8 \ - "}", \ - static_cast(a_type__), \ - static_cast(b_type__), \ - static_cast(c_type__)); \ +#define ET_CHECK_SAME_DTYPE3(a__, b__, c__) \ + ({ \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ + ET_CHECK_MSG(a_type__ == b_type__ && b_type__ == c_type__, \ + ET_TENSOR_CHECK_PREFIX__ ": dtype={%" PRId8 ", %" PRId8 \ + ", %" PRId8 "}", \ + static_cast(a_type__), static_cast(b_type__), \ + static_cast(c_type__)); \ }) /** @@ -153,108 +128,85 @@ * This macro should produce less code/data than calling the SHAPE and DTYPE * macros independently, because it only calls ET_CHECK_MSG once. */ -#define ET_CHECK_SAME_SHAPE_AND_DTYPE2(a__, b__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1) || a_dim__ == b_dim__) && \ - a_type__ == b_type__, \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu}, dim={%zu, %zu}, dtype={%" PRId8 ", %" PRId8 "}", \ - a_numel__, \ - b_numel__, \ - a_dim__, \ - b_dim__, \ - static_cast(a_type__), \ - static_cast(b_type__)); \ - for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE_AND_DTYPE2(a__, b__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + \ + ET_CHECK_MSG( \ + a_numel__ == b_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1) || a_dim__ == b_dim__) && \ + a_type__ == b_type__, \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu}, dim={%zu, %zu}, dtype={%" PRId8 ", %" PRId8 "}", \ + a_numel__, b_numel__, a_dim__, b_dim__, static_cast(a_type__), \ + static_cast(b_type__)); \ + for (size_t dim__ = 0; dim__ < ET_MIN2(a_dim__, b_dim__); ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu}", \ + dim__, a_size__, b_size__); \ + } \ }) -#define ET_CHECK_SAME_SHAPE_AND_DTYPE3(a__, b__, c__) \ - ({ \ - const size_t a_numel__ = (a__).numel(); \ - const size_t b_numel__ = (b__).numel(); \ - const size_t c_numel__ = (c__).numel(); \ - const size_t a_dim__ = (a__).dim(); \ - const size_t b_dim__ = (b__).dim(); \ - const size_t c_dim__ = (c__).dim(); \ - const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ - const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ - const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ - \ - ET_CHECK_MSG( \ - a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ - ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ - (a_dim__ == b_dim__ && b_dim__ == c_dim__)) && \ - a_type__ == b_type__ && b_type__ == c_type__, \ - ET_TENSOR_CHECK_PREFIX__ \ - ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}, " \ - "dtype={%" PRId8 ", %" PRId8 ", %" PRId8 "}", \ - a_numel__, \ - b_numel__, \ - c_numel__, \ - a_dim__, \ - b_dim__, \ - c_dim__, \ - static_cast(a_type__), \ - static_cast(b_type__), \ - static_cast(c_type__)); \ - for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ - ++dim__) { \ - size_t a_size__ = (a__).size(dim__); \ - size_t b_size__ = (b__).size(dim__); \ - size_t c_size__ = (c__).size(dim__); \ - ET_CHECK_MSG( \ - a_size__ == b_size__ && b_size__ == c_size__, \ - ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ - dim__, \ - a_size__, \ - b_size__, \ - c_size__); \ - } \ +#define ET_CHECK_SAME_SHAPE_AND_DTYPE3(a__, b__, c__) \ + ({ \ + const size_t a_numel__ = (a__).numel(); \ + const size_t b_numel__ = (b__).numel(); \ + const size_t c_numel__ = (c__).numel(); \ + const size_t a_dim__ = (a__).dim(); \ + const size_t b_dim__ = (b__).dim(); \ + const size_t c_dim__ = (c__).dim(); \ + const ::executorch::aten::ScalarType a_type__ = (a__).scalar_type(); \ + const ::executorch::aten::ScalarType b_type__ = (b__).scalar_type(); \ + const ::executorch::aten::ScalarType c_type__ = (c__).scalar_type(); \ + \ + ET_CHECK_MSG(a_numel__ == b_numel__ && b_numel__ == c_numel__ && \ + ((a_numel__ == 1 && b_numel__ == 1 && c_numel__ == 1) || \ + (a_dim__ == b_dim__ && b_dim__ == c_dim__)) && \ + a_type__ == b_type__ && b_type__ == c_type__, \ + ET_TENSOR_CHECK_PREFIX__ \ + ": numel={%zu, %zu, %zu}, dim={%zu, %zu, %zu}, " \ + "dtype={%" PRId8 ", %" PRId8 ", %" PRId8 "}", \ + a_numel__, b_numel__, c_numel__, a_dim__, b_dim__, c_dim__, \ + static_cast(a_type__), static_cast(b_type__), \ + static_cast(c_type__)); \ + for (size_t dim__ = 0; dim__ < ET_MIN3(a_dim__, b_dim__, c_dim__); \ + ++dim__) { \ + size_t a_size__ = (a__).size(dim__); \ + size_t b_size__ = (b__).size(dim__); \ + size_t c_size__ = (c__).size(dim__); \ + ET_CHECK_MSG(a_size__ == b_size__ && b_size__ == c_size__, \ + ET_TENSOR_CHECK_PREFIX__ " at size(%zu): {%zu, %zu, %zu}", \ + dim__, a_size__, b_size__, c_size__); \ + } \ }) /** * Assert that the input tensor is contiguous tensor. */ -#define ET_CHECK_CONTIGUOUS(a__) \ - ({ \ - const ::executorch::aten::ArrayRef \ - strides = a__.strides(); \ - const ::executorch::aten::ArrayRef sizes = \ - a__.sizes(); \ - ET_CHECK_MSG( \ - strides[strides.size() - 1] == 1, \ - "The stride of the last dimension shall be 1 for contiguous tensor, " \ - "not %d", \ - strides[strides.size() - 1]); \ - for (size_t i = strides.size() - 1; i > 0; i--) { \ - ET_CHECK_MSG( \ - strides[i - 1] == strides[i] * sizes[i], \ - "The stride of the %zu-th dimension shall equal to " \ - "strides[%zu] * sizes[%zu], now is %d and %d", \ - i - 1, \ - i, \ - i, \ - strides[i - 1], \ - strides[i] * sizes[i]); \ - } \ +#define ET_CHECK_CONTIGUOUS(a__) \ + ({ \ + const ::executorch::aten::ArrayRef \ + strides = a__.strides(); \ + const ::executorch::aten::ArrayRef sizes = \ + a__.sizes(); \ + ET_CHECK_MSG( \ + strides[strides.size() - 1] == 1, \ + "The stride of the last dimension shall be 1 for contiguous tensor, " \ + "not %d", \ + strides[strides.size() - 1]); \ + for (size_t i = strides.size() - 1; i > 0; i--) { \ + ET_CHECK_MSG(strides[i - 1] == strides[i] * sizes[i], \ + "The stride of the %zu-th dimension shall equal to " \ + "strides[%zu] * sizes[%zu], now is %d and %d", \ + i - 1, i, i, strides[i - 1], strides[i] * sizes[i]); \ + } \ }) /** @@ -267,21 +219,16 @@ ET_CHECK_MSG( \ a__.dim() == b__.dim(), \ "Two tensors shall have same number of strides, but not %zu and %zu.", \ - a__.dim(), \ - b__.dim()); \ + a__.dim(), b__.dim()); \ const ::executorch::aten::ArrayRef \ a_strides = a__.strides(); \ const ::executorch::aten::ArrayRef \ b_strides = b__.strides(); \ for (size_t i = 0; i < a__.dim(); i++) { \ - ET_CHECK_MSG( \ - a_strides[i] == b_strides[i], \ - "a.strides()[%zu] shall equal to b.strides()[%zu], " \ - "but now is %d and %d.", \ - i, \ - i, \ - (int32_t)a_strides[i], \ - (int32_t)b_strides[i]); \ + ET_CHECK_MSG(a_strides[i] == b_strides[i], \ + "a.strides()[%zu] shall equal to b.strides()[%zu], " \ + "but now is %d and %d.", \ + i, i, (int32_t)a_strides[i], (int32_t)b_strides[i]); \ } \ }) @@ -290,43 +237,35 @@ * Noted that this function does not make any check or promise on the contiguity * of any input tensors. */ -#define ET_CHECK_SAME_STRIDES3(a__, b__, c__) \ - ({ \ - ET_CHECK_MSG( \ - a__.dim() == b__.dim() && b__.dim() == c__.dim(), \ - "Three tensors shall have same number of strides, " \ - "but not %zu, %zu and %zu.", \ - a__.dim(), \ - b__.dim(), \ - c__.dim()); \ - const ::executorch::aten::ArrayRef \ - a_strides = a__.strides(); \ - const ::executorch::aten::ArrayRef \ - b_strides = b__.strides(); \ - const ::executorch::aten::ArrayRef \ - c_strides = c__.strides(); \ - for (size_t i = 0; i < a__.dim(); i++) { \ - ET_CHECK_MSG( \ - a_strides[i] == b_strides[i] && b_strides[i] == c_strides[i], \ - "a_strides[%zu], b_strides[%zu] and c_strides[%zu] " \ - "shall share same value, but now is %d, %d and %d", \ - i, \ - i, \ - i, \ - (int32_t)a_strides[i], \ - (int32_t)b_strides[i], \ - (int32_t)c_strides[i]); \ - } \ +#define ET_CHECK_SAME_STRIDES3(a__, b__, c__) \ + ({ \ + ET_CHECK_MSG(a__.dim() == b__.dim() && b__.dim() == c__.dim(), \ + "Three tensors shall have same number of strides, " \ + "but not %zu, %zu and %zu.", \ + a__.dim(), b__.dim(), c__.dim()); \ + const ::executorch::aten::ArrayRef \ + a_strides = a__.strides(); \ + const ::executorch::aten::ArrayRef \ + b_strides = b__.strides(); \ + const ::executorch::aten::ArrayRef \ + c_strides = c__.strides(); \ + for (size_t i = 0; i < a__.dim(); i++) { \ + ET_CHECK_MSG(a_strides[i] == b_strides[i] && \ + b_strides[i] == c_strides[i], \ + "a_strides[%zu], b_strides[%zu] and c_strides[%zu] " \ + "shall share same value, but now is %d, %d and %d", \ + i, i, i, (int32_t)a_strides[i], (int32_t)b_strides[i], \ + (int32_t)c_strides[i]); \ + } \ }) -#define ET_CHECK_DEFAULT_OR_CHANNELSLAST_DIMORDER(t__) \ - ({ \ - ET_CHECK_MSG( \ - is_contiguous_dim_order( \ - t__.dim_order().data(), t__.dim_order().size()) || \ - is_channels_last_dim_order( \ - t__.dim_order().data(), t__.dim_order().size()), \ - "Tensor must have default or channels last dim order"); \ +#define ET_CHECK_DEFAULT_OR_CHANNELSLAST_DIMORDER(t__) \ + ({ \ + ET_CHECK_MSG(is_contiguous_dim_order(t__.dim_order().data(), \ + t__.dim_order().size()) || \ + is_channels_last_dim_order(t__.dim_order().data(), \ + t__.dim_order().size()), \ + "Tensor must have default or channels last dim order"); \ }) /** @@ -336,12 +275,12 @@ * * @param[in] cond the condition to check */ -#define ET_LOG_AND_RETURN_IF_FALSE(cond) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): ", #cond); \ - return false; \ - } \ +#define ET_LOG_AND_RETURN_IF_FALSE(cond) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): ", #cond); \ + return false; \ + } \ } while (false) /** @@ -352,12 +291,12 @@ * @param[in] cond the condition to check * @param[in] message an additional message to log with `cond` */ -#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ - return false; \ - } \ +#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ + return false; \ + } \ } while (false) /** @@ -369,13 +308,13 @@ * @param[in] error torch::executor::Error enum value (e.g `InvalidArgument`) * @param[in] retval return value of the kernel to allow for early exit */ -#define ET_KERNEL_CHECK(context, cond, error, retval) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): ", #cond); \ - context.fail(torch::executor::Error::error); \ - return retval; \ - } \ +#define ET_KERNEL_CHECK(context, cond, error, retval) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): ", #cond); \ + context.fail(torch::executor::Error::error); \ + return retval; \ + } \ } while (false) /** @@ -387,22 +326,21 @@ * @param[in] error torch::executor::Error enum value (e.g `InvalidArgument`) * @param[in] retval return value of the kernel to allow for early exit */ -#define ET_KERNEL_CHECK_MSG(context, cond, error, retval, message, ...) \ - do { \ - if (!(cond)) { \ - ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ - context.fail(torch::executor::Error::error); \ - return retval; \ - } \ +#define ET_KERNEL_CHECK_MSG(context, cond, error, retval, message, ...) \ + do { \ + if (!(cond)) { \ + ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \ + context.fail(torch::executor::Error::error); \ + return retval; \ + } \ } while (false) /** * Convenience macro to extract a scalar tensor into a value */ -#define ET_EXTRACT_SCALAR_TENSOR(scalar_tensor, out_val) \ - ET_CHECK_MSG( \ - extract_scalar_tensor(scalar_tensor, &out_val), \ - #scalar_tensor " could not be extracted: wrong type or out of range"); +#define ET_EXTRACT_SCALAR_TENSOR(scalar_tensor, out_val) \ + ET_CHECK_MSG(extract_scalar_tensor(scalar_tensor, &out_val), #scalar_tensor \ + " could not be extracted: wrong type or out of range"); namespace executorch { namespace runtime { @@ -422,9 +360,7 @@ inline bool dim_is_valid(int64_t dim, int64_t upper_bound) { "Dimension %" PRId64 " is out of range. Dimension should be between %" PRId64 " and %" PRId64 ", inclusive.", - dim, - -upper_bound, - upper_bound - 1); + dim, -upper_bound, upper_bound - 1); return true; } @@ -435,7 +371,7 @@ inline bool dim_is_valid(int64_t dim, int64_t upper_bound) { * the zero dimensional tensors in some kernels, that treat them as 1D tensors * with a single element. */ -inline ssize_t nonzero_dim(const executorch::aten::Tensor& tensor) { +inline ssize_t nonzero_dim(const executorch::aten::Tensor &tensor) { return tensor.dim() == 0 ? 1 : tensor.dim(); } @@ -445,15 +381,13 @@ inline ssize_t nonzero_dim(const executorch::aten::Tensor& tensor) { * the zero dimensional tensors in some kernels, that treat them as 1D tensors * with a single element. */ -inline ssize_t nonempty_size( - const executorch::aten::Tensor& tensor, - ssize_t dim) { +inline ssize_t nonempty_size(const executorch::aten::Tensor &tensor, + ssize_t dim) { return tensor.dim() == 0 ? 1 : tensor.size(dim); } -inline bool tensor_can_cast_to( - executorch::aten::Tensor a, - executorch::aten::ScalarType dtype) { +inline bool tensor_can_cast_to(executorch::aten::Tensor a, + executorch::aten::ScalarType dtype) { ET_LOG_MSG_AND_RETURN_IF_FALSE( torch::executor::canCast(a.scalar_type(), dtype), "Tensor of dtype %s cannot cast to dtype %s", @@ -472,9 +406,8 @@ inline bool tensor_is_bool_type(executorch::aten::Tensor t) { return true; } -inline bool tensor_is_type( - executorch::aten::Tensor t, - executorch::aten::ScalarType dtype) { +inline bool tensor_is_type(executorch::aten::Tensor t, + executorch::aten::ScalarType dtype) { ET_LOG_MSG_AND_RETURN_IF_FALSE( t.scalar_type() == dtype, "Expected to find %s type, but tensor has type %s", @@ -484,9 +417,8 @@ inline bool tensor_is_type( return true; } -inline bool tensor_is_integral_type( - executorch::aten::Tensor t, - bool includeBool = false) { +inline bool tensor_is_integral_type(executorch::aten::Tensor t, + bool includeBool = false) { ET_LOG_MSG_AND_RETURN_IF_FALSE( torch::executor::isIntegralType(t.scalar_type(), includeBool), "Expected to find a integral type, but tensor has type %s", @@ -567,21 +499,18 @@ inline bool tensor_is_bits_type(executorch::aten::Tensor t) { return true; } -inline bool tensors_have_same_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { - ET_LOG_MSG_AND_RETURN_IF_FALSE( - a.scalar_type() == b.scalar_type(), - ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s}", - torch::executor::toString(a.scalar_type()), - torch::executor::toString(b.scalar_type())); +inline bool tensors_have_same_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b) { + ET_LOG_MSG_AND_RETURN_IF_FALSE(a.scalar_type() == b.scalar_type(), + ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s}", + torch::executor::toString(a.scalar_type()), + torch::executor::toString(b.scalar_type())); return true; } -inline bool tensors_have_same_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { ET_LOG_MSG_AND_RETURN_IF_FALSE( a.scalar_type() == b.scalar_type() && b.scalar_type() == c.scalar_type(), ET_TENSOR_CHECK_PREFIX__ ": dtype={%s, %s, %s}", @@ -593,34 +522,26 @@ inline bool tensors_have_same_dtype( inline bool tensor_is_rank(executorch::aten::Tensor t, size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() == rank, - "Expected tensor.dim() to be %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() == rank, "Expected tensor.dim() to be %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } -inline bool tensor_has_rank_greater_or_equal_to( - executorch::aten::Tensor t, - size_t rank) { +inline bool tensor_has_rank_greater_or_equal_to(executorch::aten::Tensor t, + size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() >= rank, - "Expected tensor.dim() to be >= %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() >= rank, "Expected tensor.dim() to be >= %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } -inline bool tensor_has_rank_smaller_or_equal_to( - executorch::aten::Tensor t, - size_t rank) { +inline bool tensor_has_rank_smaller_or_equal_to(executorch::aten::Tensor t, + size_t rank) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - t.dim() <= rank, - "Expected tensor.dim() to be <= %zu, but got %zu", - static_cast(rank), - static_cast(t.dim())); + t.dim() <= rank, "Expected tensor.dim() to be <= %zu, but got %zu", + static_cast(rank), static_cast(t.dim())); return true; } @@ -628,15 +549,13 @@ inline bool tensor_has_rank_smaller_or_equal_to( inline bool tensor_has_dim(executorch::aten::Tensor t, int64_t d) { if (t.dim() == 0) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - d == 0 || d == -1, - "dim must be 0 or -1 for 0-dim tensor, got %" PRId64, + d == 0 || d == -1, "dim must be 0 or -1 for 0-dim tensor, got %" PRId64, d); } else { ET_LOG_MSG_AND_RETURN_IF_FALSE( d > 0 ? d < t.dim() : t.dim() + d >= 0, "%zu-dim tensor does not have dim at index %zu", - static_cast(t.dim()), - static_cast(d)); + static_cast(t.dim()), static_cast(d)); } return true; } @@ -648,8 +567,8 @@ inline bool tensor_has_non_empty_dim(executorch::aten::Tensor t, int64_t d) { return true; } -inline bool -tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, int64_t ix) { +inline bool tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, + int64_t ix) { // Indexing ops don't support zero-dim tensors ET_CHECK(t.dim() != 0); if (d < 0) { @@ -660,64 +579,46 @@ tensor_dim_has_index(executorch::aten::Tensor t, int64_t d, int64_t ix) { ET_LOG_MSG_AND_RETURN_IF_FALSE( ix >= -t.size(d) && ix < t.size(d), - "index %" PRId64 " out of range [-%zu,%zu) at dimension %" PRId64 ")", - ix, - static_cast(t.size(d)), - static_cast(t.size(d)), - d); + "index %" PRId64 " out of range [-%zu,%zu) at dimension %" PRId64 ")", ix, + static_cast(t.size(d)), static_cast(t.size(d)), d); return true; } -inline bool tensors_have_same_size_at_dims( - executorch::aten::Tensor a, - size_t dim_a, - executorch::aten::Tensor b, - size_t dim_b) { +inline bool tensors_have_same_size_at_dims(executorch::aten::Tensor a, + size_t dim_a, + executorch::aten::Tensor b, + size_t dim_b) { ET_LOG_MSG_AND_RETURN_IF_FALSE( - dim_a < a.dim(), - "Cannot retrieve dim %zu from tensor with dim %zu", - static_cast(dim_a), - static_cast(a.dim())); + dim_a < a.dim(), "Cannot retrieve dim %zu from tensor with dim %zu", + static_cast(dim_a), static_cast(a.dim())); ET_LOG_MSG_AND_RETURN_IF_FALSE( - dim_b < b.dim(), - "Cannot retrieve dim %zu from tensor with dim %zu", - static_cast(dim_b), - static_cast(b.dim())); + dim_b < b.dim(), "Cannot retrieve dim %zu from tensor with dim %zu", + static_cast(dim_b), static_cast(b.dim())); ET_LOG_MSG_AND_RETURN_IF_FALSE( a.size(dim_a) == b.size(dim_b), ET_TENSOR_CHECK_PREFIX__ ": a.size(%zu) = %zu does not match b.size(%zu) = %zu", - static_cast(dim_a), - static_cast(a.size(dim_a)), - static_cast(dim_b), - static_cast(b.size(dim_b))); + static_cast(dim_a), static_cast(a.size(dim_a)), + static_cast(dim_b), static_cast(b.size(dim_b))); return true; } -inline bool tensors_have_same_shape( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_shape(executorch::aten::Tensor a, + executorch::aten::Tensor b) { if (a.numel() == 1 && b.numel() == 1) { // PyTorch operators treat all scalar tensors as the same shape even if // they have different dims. return true; } if (!(a.sizes() == b.sizes() && a.numel() == b.numel())) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu), dim=(%zu, %zu)", - static_cast(a.numel()), - static_cast(b.numel()), - static_cast(a.dim()), - static_cast(b.dim())); + ET_LOG(Error, + ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu), dim=(%zu, %zu)", + static_cast(a.numel()), static_cast(b.numel()), + static_cast(a.dim()), static_cast(b.dim())); for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(b.size(d))); + ET_LOG(Error, " size(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.size(d)), static_cast(b.size(d))); } return false; @@ -726,10 +627,9 @@ inline bool tensors_have_same_shape( return true; } -inline bool tensors_have_same_shape( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_shape(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { if (a.numel() == 1 && b.numel() == 1 && c.numel() == 1) { // PyTorch operators treat all scalar tensors as the same shape even if // they have different dims. @@ -739,23 +639,16 @@ inline bool tensors_have_same_shape( bool cond2 = (b.sizes() == c.sizes()) && (b.numel() == c.numel()); if (!(cond1 && cond2)) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": numel=(%zu, %zu, %zu), dim=(%zu, %zu, %zu)", - static_cast(a.numel()), - static_cast(b.numel()), - static_cast(c.numel()), - static_cast(a.dim()), - static_cast(b.dim()), - static_cast(c.dim())); + ET_LOG(Error, + ET_TENSOR_CHECK_PREFIX__ + ": numel=(%zu, %zu, %zu), dim=(%zu, %zu, %zu)", + static_cast(a.numel()), static_cast(b.numel()), + static_cast(c.numel()), static_cast(a.dim()), + static_cast(b.dim()), static_cast(c.dim())); for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(b.size(d)), - static_cast(c.size(d))); + ET_LOG(Error, " size(%zu): (%zu, %zu, %zu)", static_cast(d), + static_cast(a.size(d)), static_cast(b.size(d)), + static_cast(c.size(d))); } return false; @@ -764,16 +657,14 @@ inline bool tensors_have_same_shape( return true; } -inline bool tensors_have_same_shape_and_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_shape_and_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b) { return tensors_have_same_shape(a, b) && tensors_have_same_dtype(a, b); } -inline bool tensors_have_same_shape_and_dtype( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_shape_and_dtype(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { return tensors_have_same_shape(a, b, c) && tensors_have_same_dtype(a, b, c); } @@ -781,20 +672,15 @@ inline bool tensor_has_expected_size( executorch::aten::Tensor a, executorch::aten::ArrayRef expected_sizes) { if (!(a.sizes() == expected_sizes)) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", - static_cast(a.dim()), - static_cast(expected_sizes.size())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", + static_cast(a.dim()), + static_cast(expected_sizes.size())); size_t a_dim = static_cast(a.dim()); size_t expected_dim = static_cast(expected_sizes.size()); for (size_t d = 0; d < ET_MIN2(a_dim, expected_dim); ++d) { - ET_LOG( - Error, - " size(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.size(d)), - static_cast(expected_sizes[d])); + ET_LOG(Error, " size(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.size(d)), + static_cast(expected_sizes[d])); } return false; @@ -802,22 +688,15 @@ inline bool tensor_has_expected_size( return true; } -inline bool tensors_have_same_strides( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { +inline bool tensors_have_same_strides(executorch::aten::Tensor a, + executorch::aten::Tensor b) { if (a.strides() != b.strides()) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", - static_cast(a.dim()), - static_cast(b.dim())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu)", + static_cast(a.dim()), static_cast(b.dim())); for (size_t d = 0; d < ET_MIN2(a.dim(), b.dim()); ++d) { - ET_LOG( - Error, - " stride(%zu): (%zu, %zu)", - static_cast(d), - static_cast(a.strides()[d]), - static_cast(b.strides()[d])); + ET_LOG(Error, " stride(%zu): (%zu, %zu)", static_cast(d), + static_cast(a.strides()[d]), + static_cast(b.strides()[d])); } return false; @@ -825,25 +704,18 @@ inline bool tensors_have_same_strides( return true; } -inline bool tensors_have_same_strides( - executorch::aten::Tensor a, - executorch::aten::Tensor b, - executorch::aten::Tensor c) { +inline bool tensors_have_same_strides(executorch::aten::Tensor a, + executorch::aten::Tensor b, + executorch::aten::Tensor c) { if (!(a.strides() == b.strides() && b.strides() == c.strides())) { - ET_LOG( - Error, - ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu, %zu)", - static_cast(a.dim()), - static_cast(b.dim()), - static_cast(c.dim())); + ET_LOG(Error, ET_TENSOR_CHECK_PREFIX__ ": dim=(%zu, %zu, %zu)", + static_cast(a.dim()), static_cast(b.dim()), + static_cast(c.dim())); for (size_t d = 0; d < ET_MIN3(a.dim(), b.dim(), c.dim()); ++d) { - ET_LOG( - Error, - " stride(%zu): (%zu, %zu, %zu)", - static_cast(d), - static_cast(a.strides()[d]), - static_cast(b.strides()[d]), - static_cast(c.strides()[d])); + ET_LOG(Error, " stride(%zu): (%zu, %zu, %zu)", static_cast(d), + static_cast(a.strides()[d]), + static_cast(b.strides()[d]), + static_cast(c.strides()[d])); } return false; @@ -868,23 +740,18 @@ inline bool tensor_is_contiguous(executorch::aten::Tensor t) { strides[i - 1] == strides[i] * sizes[i], "Tensor is not contiguous; the stride of dim %zu should be equal to " "strides[%zu] * sizes[%zu] = %zu, but found %zu", - static_cast(i - 1), - static_cast(i), - static_cast(i), - static_cast(strides[i] * sizes[i]), + static_cast(i - 1), static_cast(i), + static_cast(i), static_cast(strides[i] * sizes[i]), static_cast(strides[i - 1])); } return true; } -inline bool tensors_have_same_rank( - executorch::aten::Tensor a, - executorch::aten::Tensor b) { - ET_LOG_MSG_AND_RETURN_IF_FALSE( - a.dim() == b.dim(), - ET_TENSOR_CHECK_PREFIX__ ": rank={%zd, %zd}", - ssize_t(a.dim()), - ssize_t(b.dim())); +inline bool tensors_have_same_rank(executorch::aten::Tensor a, + executorch::aten::Tensor b) { + ET_LOG_MSG_AND_RETURN_IF_FALSE(a.dim() == b.dim(), + ET_TENSOR_CHECK_PREFIX__ ": rank={%zd, %zd}", + ssize_t(a.dim()), ssize_t(b.dim())); return true; } @@ -903,15 +770,12 @@ inline bool tensor_is_scalar(executorch::aten::Tensor t) { constexpr size_t kTensorDimensionLimit = 16; /// Returns the product of dim[0:dim), not including dim. -inline size_t getLeadingDims( - const executorch::aten::Tensor& tensor, - int64_t dim) { - ET_CHECK_MSG( - dim >= 0 && dim <= tensor.dim(), - "Ending dimension %" PRId64 - " should be in the range [0, tensor.dim() %zd].", - dim, - ssize_t(tensor.dim())); +inline size_t getLeadingDims(const executorch::aten::Tensor &tensor, + int64_t dim) { + ET_CHECK_MSG(dim >= 0 && dim <= tensor.dim(), + "Ending dimension %" PRId64 + " should be in the range [0, tensor.dim() %zd].", + dim, ssize_t(tensor.dim())); size_t dims = 1; for (size_t i = 0; i < dim; ++i) { dims *= static_cast(tensor.size(i)); @@ -920,15 +784,12 @@ inline size_t getLeadingDims( } /// Returns the product of dim[dim+1:]. -inline size_t getTrailingDims( - const executorch::aten::Tensor& tensor, - int64_t dim) { - ET_CHECK_MSG( - dim >= -1 && dim < tensor.dim(), - "Starting dimension %" PRId64 - " should be in the range [-1, tensor.dim() -1 %zd).", - dim, - ssize_t(tensor.dim())); +inline size_t getTrailingDims(const executorch::aten::Tensor &tensor, + int64_t dim) { + ET_CHECK_MSG(dim >= -1 && dim < tensor.dim(), + "Starting dimension %" PRId64 + " should be in the range [-1, tensor.dim() -1 %zd).", + dim, ssize_t(tensor.dim())); size_t dims = 1; for (size_t i = dim + 1; i < tensor.dim(); ++i) { dims *= static_cast(tensor.size(i)); @@ -946,9 +807,8 @@ inline size_t getTrailingDims( * @param[out] index The linear index to element at the specified coordinate * in the tensor. */ -inline size_t coordinateToIndex( - const executorch::aten::Tensor& tensor, - const size_t* const coordinate) { +inline size_t coordinateToIndex(const executorch::aten::Tensor &tensor, + const size_t *const coordinate) { size_t index = 0; for (int d = 0; d < tensor.dim(); ++d) { index += coordinate[d] * getTrailingDims(tensor, d); @@ -961,9 +821,9 @@ inline size_t coordinateToIndex( * coordinateToIndexWithTrailingDimsMemo, which will be faster than * repeated calls to coordinateToIndex. */ -inline void memoizeTrailingDims( - const executorch::aten::Tensor& tensor, - size_t trailing_dims_memo[kTensorDimensionLimit]) { +inline void +memoizeTrailingDims(const executorch::aten::Tensor &tensor, + size_t trailing_dims_memo[kTensorDimensionLimit]) { const auto tensorDim = tensor.dim(); size_t dims = 1; for (int ii = tensorDim - 1; ii >= 0; --ii) { @@ -978,8 +838,7 @@ inline void memoizeTrailingDims( * memoizeTrailingDims. */ inline size_t coordinateToIndexWithTrailingDimsMemo( - const executorch::aten::Tensor& tensor, - const size_t* const coordinate, + const executorch::aten::Tensor &tensor, const size_t *const coordinate, const size_t trailing_dims_memo[kTensorDimensionLimit]) { size_t index = 0; for (int d = 0; d < tensor.dim(); ++d) { @@ -999,10 +858,8 @@ inline size_t coordinateToIndexWithTrailingDimsMemo( * index. It is assumed that the array has kTensorDimensionLimit elements. * @returns void */ -inline void indexToCoordinate( - const executorch::aten::Tensor& tensor, - size_t index, - size_t* coordinate) { +inline void indexToCoordinate(const executorch::aten::Tensor &tensor, + size_t index, size_t *coordinate) { ET_CHECK(index < tensor.numel()); for (auto i = 0; i < tensor.dim(); ++i) { auto dim = tensor.dim() - 1 - i; @@ -1022,30 +879,29 @@ inline void indexToCoordinate( * integer Scalar Tensor, or the value of that Scalar Tensor could not be * represented by INT_T. */ -template < - typename INT_T, - typename std::enable_if< - std::is_integral::value && !std::is_same::value, - bool>::type = true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T* out_val) { +template ::value && + !std::is_same::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T *out_val) { if (tensor.numel() != 1) { return false; } -#define CASE_INT_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ - case executorch::aten::ScalarType::TENSOR_DTYPE: { \ - const TENSOR_CTYPE val = tensor.const_data_ptr()[0]; \ - if (val < std::numeric_limits::lowest() || \ - val > std::numeric_limits::max()) { \ - return false; \ - } \ - *out_val = static_cast(val); \ - return true; \ +#define CASE_INT_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ + case executorch::aten::ScalarType::TENSOR_DTYPE: { \ + const TENSOR_CTYPE val = tensor.const_data_ptr()[0]; \ + if (val < std::numeric_limits::lowest() || \ + val > std::numeric_limits::max()) { \ + return false; \ + } \ + *out_val = static_cast(val); \ + return true; \ } switch (tensor.scalar_type()) { ET_FORALL_INT_TYPES(CASE_INT_DTYPE); - default: - return false; + default: + return false; } #undef CASE_INT_DTYPE } @@ -1060,32 +916,30 @@ bool extract_scalar_tensor(executorch::aten::Tensor tensor, INT_T* out_val) { * floating point Scalar Tensor, or the value of that Scalar Tensor could not * be represented by FLOAT_T. */ -template < - typename FLOAT_T, - typename std::enable_if::value, bool>:: - type = true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T* out_val) { +template ::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T *out_val) { if (tensor.numel() != 1) { return false; } -#define CASE_REAL_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ - case executorch::aten::ScalarType::TENSOR_DTYPE: { \ - /* ET_FORALL_REAL_TYPES guarantees TENSOR_CTYPE is a real type. */ \ - double val = \ - static_cast(tensor.const_data_ptr()[0]); \ - if (std::isfinite(val) && \ - (val < std::numeric_limits::lowest() || \ - val > std::numeric_limits::max())) { \ - return false; \ - } \ - *out_val = static_cast(val); \ - return true; \ +#define CASE_REAL_DTYPE(TENSOR_CTYPE, TENSOR_DTYPE) \ + case executorch::aten::ScalarType::TENSOR_DTYPE: { \ + /* ET_FORALL_REAL_TYPES guarantees TENSOR_CTYPE is a real type. */ \ + double val = \ + static_cast(tensor.const_data_ptr()[0]); \ + if (std::isfinite(val) && (val < std::numeric_limits::lowest() || \ + val > std::numeric_limits::max())) { \ + return false; \ + } \ + *out_val = static_cast(val); \ + return true; \ } switch (tensor.scalar_type()) { ET_FORALL_REAL_TYPES(CASE_REAL_DTYPE); - default: - return false; + default: + return false; } #undef CASE_REAL_DTYPE } @@ -1098,11 +952,10 @@ bool extract_scalar_tensor(executorch::aten::Tensor tensor, FLOAT_T* out_val) { * @returns `true` if a value was extracted, and sets `*out_val` to that * value. `false` if a value could not be extracted, i.e. not a boolean */ -template < - typename BOOL_T, - typename std::enable_if::value, bool>::type = - true> -bool extract_scalar_tensor(executorch::aten::Tensor tensor, BOOL_T* out_val) { +template ::value, + bool>::type = true> +bool extract_scalar_tensor(executorch::aten::Tensor tensor, BOOL_T *out_val) { if (tensor.scalar_type() != executorch::aten::ScalarType::Bool) { return false; } @@ -1122,35 +975,31 @@ namespace internal { /** * Share t_src's data_ptr with t_dst. */ -ET_NODISCARD Error share_tensor_data( - const executorch::aten::Tensor& t_dst, - const executorch::aten::Tensor& t_src); +ET_NODISCARD Error share_tensor_data(const executorch::aten::Tensor &t_dst, + const executorch::aten::Tensor &t_src); /** * Copy t_src's data_ptr to t_dst. */ -ET_NODISCARD Error copy_tensor_data( - const executorch::aten::Tensor& t_dst, - const executorch::aten::Tensor& t_src); +ET_NODISCARD Error copy_tensor_data(const executorch::aten::Tensor &t_dst, + const executorch::aten::Tensor &t_src); /** * Set the data_ptr of t to buffer. */ -ET_NODISCARD Error set_tensor_data( - const executorch::aten::Tensor& t, - void* buffer, - size_t buffer_size); +ET_NODISCARD Error set_tensor_data(const executorch::aten::Tensor &t, + void *buffer, size_t buffer_size); /** * Reset tensor's data_ptr, clear all the storage for at::Tensor. */ -void reset_data_ptr(const executorch::aten::Tensor& tensor); +void reset_data_ptr(const executorch::aten::Tensor &tensor); /** * Resize tensor impl */ ET_NODISCARD Error resize_tensor_impl( - executorch::aten::TensorImpl* impl, + executorch::aten::TensorImpl *impl, executorch::aten::ArrayRef new_sizes); } // namespace internal @@ -1179,14 +1028,12 @@ ET_NODISCARD inline Error resize_tensor( * settled, will likely move to be a class method on a TensorResizer object * passed in through runtimeContext. */ -template < - typename T, - typename std::enable_if< - !std::is_same::value, - int>::type = 0> -ET_NODISCARD inline Error resize_tensor( - executorch::aten::Tensor t, - executorch::aten::ArrayRef new_sizes) { +template ::value, + int>::type = 0> +ET_NODISCARD inline Error +resize_tensor(executorch::aten::Tensor t, + executorch::aten::ArrayRef new_sizes) { // Need to cast the input array to an array of Tensor::SizesType std::array new_sizes_casted{}; @@ -1201,12 +1048,12 @@ ET_NODISCARD inline Error resize_tensor( } /// DEPRECATED: Use `resize_tensor()` instead, which can fail non-fatally. -ET_DEPRECATED inline void resize( - executorch::aten::Tensor t, - executorch::aten::ArrayRef new_sizes) { +ET_DEPRECATED inline void +resize(executorch::aten::Tensor t, + executorch::aten::ArrayRef new_sizes) { Error err = resize_tensor(t, new_sizes); - ET_CHECK_MSG( - err == Error::Ok, "Could not resize Tensor; see logs for details"); + ET_CHECK_MSG(err == Error::Ok, + "Could not resize Tensor; see logs for details"); } /** * Get dim_order of a Tensor and write it to out_dim_order. @@ -1215,10 +1062,9 @@ ET_DEPRECATED inline void resize( * dim order into it. * @param out_dim_order_size Size of the DimOrderType array. */ -ET_NODISCARD Error get_dim_order( - const executorch::aten::Tensor& tensor, - executorch::aten::DimOrderType* out_dim_order, - size_t out_dim_order_size); +ET_NODISCARD Error get_dim_order(const executorch::aten::Tensor &tensor, + executorch::aten::DimOrderType *out_dim_order, + size_t out_dim_order_size); /** * Checks whether a tensor has a valid dim order. If the dim order could not @@ -1269,9 +1115,8 @@ bool tensors_have_same_dim_order( * sizes, etc. */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b) { executorch::aten::Tensor tensor_list[2] = {a, b}; return tensors_have_same_dim_order(tensor_list); } @@ -1284,10 +1129,9 @@ inline bool tensors_have_same_dim_order( * */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b, - const executorch::aten::Tensor& c) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b, + const executorch::aten::Tensor &c) { executorch::aten::Tensor tensor_list[3] = {a, b, c}; return tensors_have_same_dim_order(tensor_list); } @@ -1300,11 +1144,10 @@ inline bool tensors_have_same_dim_order( * */ -inline bool tensors_have_same_dim_order( - const executorch::aten::Tensor& a, - const executorch::aten::Tensor& b, - const executorch::aten::Tensor& c, - const executorch::aten::Tensor& d) { +inline bool tensors_have_same_dim_order(const executorch::aten::Tensor &a, + const executorch::aten::Tensor &b, + const executorch::aten::Tensor &c, + const executorch::aten::Tensor &d) { executorch::aten::Tensor tensor_list[4] = {a, b, c, d}; return tensors_have_same_dim_order(tensor_list); } @@ -1317,10 +1160,10 @@ inline bool tensors_have_same_dim_order( * @param strides Pointer to the array of strides. * @param ndim Number of dimensions in the tensor. */ -inline size_t calculate_linear_index( - const executorch::aten::SizesType* coordinate, - const executorch::aten::StridesType* strides, - const size_t ndim) { +inline size_t +calculate_linear_index(const executorch::aten::SizesType *coordinate, + const executorch::aten::StridesType *strides, + const size_t ndim) { size_t index = 0; for (size_t i = 0; i < ndim; i++) { index += coordinate[i] * strides[i]; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h index a90c8991..09c5efca 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h @@ -17,18 +17,16 @@ namespace runtime { * A read-only buffer than can be freed. */ class FreeableBuffer final { - public: +public: // Callback signature for the function that does the freeing. - using FreeFn = void (*)(void* context, void* data, size_t size); + using FreeFn = void (*)(void *context, void *data, size_t size); /** * Creates an empty FreeableBuffer with size zero and a null data pointer. */ FreeableBuffer() - : free_fn_(nullptr), - free_fn_context_(nullptr), - data_(nullptr), - size_(0) {} + : free_fn_(nullptr), free_fn_context_(nullptr), data_(nullptr), size_(0) { + } /** * Creates a FreeableBuffer with an optional free function. @@ -42,34 +40,25 @@ class FreeableBuffer final { * @param[in] free_fn_context Opaque pointer to pass as the `context` * parameter of `free_fn`. May be nullptr. */ - FreeableBuffer( - const void* data, - size_t size, - FreeFn free_fn, - void* free_fn_context = nullptr) - : free_fn_(free_fn), - free_fn_context_(free_fn_context), - data_(data), + FreeableBuffer(const void *data, size_t size, FreeFn free_fn, + void *free_fn_context = nullptr) + : free_fn_(free_fn), free_fn_context_(free_fn_context), data_(data), size_(size) {} /** * Move ctor. Takes the ownership of the data previously owned by `rhs`, * leaving `rhs` pointing to nullptr. */ - FreeableBuffer(FreeableBuffer&& rhs) noexcept - : free_fn_(rhs.free_fn_), - free_fn_context_(rhs.free_fn_context_), - data_(rhs.data_), - size_(rhs.size_) { + FreeableBuffer(FreeableBuffer &&rhs) noexcept + : free_fn_(rhs.free_fn_), free_fn_context_(rhs.free_fn_context_), + data_(rhs.data_), size_(rhs.size_) { rhs.free_fn_ = nullptr; rhs.free_fn_context_ = nullptr; rhs.data_ = nullptr; rhs.size_ = 0; } - ~FreeableBuffer() { - Free(); - } + ~FreeableBuffer() { Free(); } /** * Frees the data if not already free. Safe to call multiple times. @@ -77,7 +66,7 @@ class FreeableBuffer final { void Free() { if (data_ != nullptr) { if (free_fn_ != nullptr) { - free_fn_(free_fn_context_, const_cast(data_), size_); + free_fn_(free_fn_context_, const_cast(data_), size_); } data_ = nullptr; size_ = 0; @@ -87,26 +76,22 @@ class FreeableBuffer final { /** * Size of the data in bytes. Returns 0 if the data has been freed. */ - size_t size() const { - return size_; - } + size_t size() const { return size_; } /** * Pointer to the data. Returns nullptr if the data has been freed. */ - const void* data() const { - return data_; - } + const void *data() const { return data_; } - private: +private: // Delete other rule-of-five methods. - FreeableBuffer(const FreeableBuffer& rhs) = delete; - FreeableBuffer& operator=(FreeableBuffer&& rhs) noexcept = delete; - FreeableBuffer& operator=(const FreeableBuffer& rhs) = delete; + FreeableBuffer(const FreeableBuffer &rhs) = delete; + FreeableBuffer &operator=(FreeableBuffer &&rhs) noexcept = delete; + FreeableBuffer &operator=(const FreeableBuffer &rhs) = delete; FreeFn free_fn_; - void* free_fn_context_; - const void* data_; + void *free_fn_context_; + const void *data_; size_t size_; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h index b5ba8b04..d894c080 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h @@ -8,13 +8,13 @@ #pragma once +#include #include #include #include #include #include #include -#include namespace executorch { namespace runtime { @@ -23,7 +23,7 @@ namespace runtime { * A group of buffers that can be used to represent a device's memory hierarchy. */ class HierarchicalAllocator final { - public: +public: /** * Constructs a new hierarchical allocator with the given array of buffers. * @@ -38,9 +38,8 @@ class HierarchicalAllocator final { /** * DEPRECATED: Use spans instead. */ - ET_DEPRECATED HierarchicalAllocator( - uint32_t n_allocators, - MemoryAllocator* allocators) + ET_DEPRECATED HierarchicalAllocator(uint32_t n_allocators, + MemoryAllocator *allocators) : buffers_(to_spans(n_allocators, allocators)) {} /** @@ -55,30 +54,22 @@ class HierarchicalAllocator final { * @returns On success, the address of the requested byte offset into the * specified buffer. On failure, a non-Ok Error. */ - ET_NODISCARD Result get_offset_address( - uint32_t memory_id, - size_t offset_bytes, - size_t size_bytes) { - ET_CHECK_OR_RETURN_ERROR( - memory_id < buffers_.size(), - InvalidArgument, - "id %" PRIu32 " >= %zu", - memory_id, - buffers_.size()); + ET_NODISCARD Result get_offset_address(uint32_t memory_id, + size_t offset_bytes, + size_t size_bytes) { + ET_CHECK_OR_RETURN_ERROR(memory_id < buffers_.size(), InvalidArgument, + "id %" PRIu32 " >= %zu", memory_id, + buffers_.size()); Span buffer = buffers_[memory_id]; ET_CHECK_OR_RETURN_ERROR( - offset_bytes + size_bytes <= buffer.size(), - MemoryAllocationFailed, + offset_bytes + size_bytes <= buffer.size(), MemoryAllocationFailed, "offset_bytes (%zu) + size_bytes (%zu) >= allocator size (%zu) " "for memory_id %" PRIu32, - offset_bytes, - size_bytes, - buffer.size(), - memory_id); + offset_bytes, size_bytes, buffer.size(), memory_id); return buffer.data() + offset_bytes; } - private: +private: // TODO(T162089316): Remove the span array and to_spans once all users move to // spans. This array is necessary to hold the pointers and sizes that were // originally provided as MemoryAllocator instances. @@ -86,14 +77,11 @@ class HierarchicalAllocator final { // NOTE: span_array_ must be declared before buffers_ so that it isn't // re-initialized to zeros after initializing buffers_. Span span_array_[kSpanArraySize]; - Span> to_spans( - uint32_t n_allocators, - MemoryAllocator* allocators) { - ET_CHECK_MSG( - n_allocators <= kSpanArraySize, - "n_allocators %" PRIu32 " > %zu", - n_allocators, - kSpanArraySize); + Span> to_spans(uint32_t n_allocators, + MemoryAllocator *allocators) { + ET_CHECK_MSG(n_allocators <= kSpanArraySize, + "n_allocators %" PRIu32 " > %zu", n_allocators, + kSpanArraySize); for (uint32_t i = 0; i < n_allocators; ++i) { span_array_[i] = Span(allocators[i].base_address(), allocators[i].size()); diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h index 5149abda..80bdd150 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h @@ -8,9 +8,9 @@ #pragma once -#include #include #include +#include #include #include @@ -38,13 +38,13 @@ namespace runtime { * allocator.allocate() to keep iterating cur_ pointer */ class MemoryAllocator { - public: +public: /** * Default alignment of memory returned by this class. Ensures that pointer * fields of structs will be aligned. Larger types like `long double` may not * be, however, depending on the toolchain and architecture. */ - static constexpr size_t kDefaultAlignment = alignof(void*); + static constexpr size_t kDefaultAlignment = alignof(void *); /** * Constructs a new memory allocator of a given `size`, starting at the @@ -55,10 +55,8 @@ class MemoryAllocator { * ownership of this buffer, so it must be valid for the lifetime of of * the MemoryAllocator. */ - MemoryAllocator(uint32_t size, uint8_t* base_address) - : begin_(base_address), - end_(base_address + size), - cur_(base_address), + MemoryAllocator(uint32_t size, uint8_t *base_address) + : begin_(base_address), end_(base_address + size), cur_(base_address), size_(size) {} /** @@ -71,7 +69,7 @@ class MemoryAllocator { * @returns Aligned pointer to the allocated memory on success. * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ - virtual void* allocate(size_t size, size_t alignment = kDefaultAlignment) { + virtual void *allocate(size_t size, size_t alignment = kDefaultAlignment) { if (!isPowerOf2(alignment)) { ET_LOG(Error, "Alignment %zu is not a power of 2", alignment); return nullptr; @@ -79,17 +77,16 @@ class MemoryAllocator { // The allocation will occupy [start, end), where the start is the next // position that's a multiple of alignment. - uint8_t* start = alignPointer(cur_, alignment); - uint8_t* end = start + size; + uint8_t *start = alignPointer(cur_, alignment); + uint8_t *end = start + size; // If the end of this allocation exceeds the end of this allocator, print // error messages and return nullptr if (end > end_) { - ET_LOG( - Error, - "Memory allocation failed: %zuB requested (adjusted for alignment), %zuB available", - static_cast(end - cur_), - static_cast(end_ - cur_)); + ET_LOG(Error, + "Memory allocation failed: %zuB requested (adjusted for " + "alignment), %zuB available", + static_cast(end - cur_), static_cast(end_ - cur_)); return nullptr; } @@ -98,7 +95,7 @@ class MemoryAllocator { // instead of (end - start) because start > cur_ if there is a misalignment EXECUTORCH_TRACK_ALLOCATION(prof_id_, end - cur_); cur_ = end; - return static_cast(start); + return static_cast(start); } /** @@ -116,9 +113,8 @@ class MemoryAllocator { * @returns Aligned pointer to the allocated memory on success. * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ - template - T* allocateInstance(size_t alignment = alignof(T)) { - return static_cast(this->allocate(sizeof(T), alignment)); + template T *allocateInstance(size_t alignment = alignof(T)) { + return static_cast(this->allocate(sizeof(T), alignment)); } /** @@ -133,42 +129,34 @@ class MemoryAllocator { * @retval nullptr Not enough memory, or `alignment` was not a power of 2. */ template - T* allocateList(size_t size, size_t alignment = alignof(T)) { + T *allocateList(size_t size, size_t alignment = alignof(T)) { // Some users of this method allocate lists of pointers, causing the next // line to expand to `sizeof(type *)`, which triggers a clang-tidy warning. // NOLINTNEXTLINE(bugprone-sizeof-expression) - return static_cast(this->allocate(size * sizeof(T), alignment)); + return static_cast(this->allocate(size * sizeof(T), alignment)); } // Returns the allocator memory's base address. - virtual uint8_t* base_address() const { - return begin_; - } + virtual uint8_t *base_address() const { return begin_; } // Returns the total size of the allocator's memory buffer. - virtual uint32_t size() const { - return size_; - } + virtual uint32_t size() const { return size_; } // Resets the current pointer to the base address. It does nothing to // the contents. - virtual void reset() { - cur_ = begin_; - } + virtual void reset() { cur_ = begin_; } - void enable_profiling(ET_UNUSED const char* name) { + void enable_profiling(ET_UNUSED const char *name) { prof_id_ = EXECUTORCH_TRACK_ALLOCATOR(name); } virtual ~MemoryAllocator() {} - protected: +protected: /** * Returns the profiler ID for this allocator. */ - int32_t prof_id() const { - return prof_id_; - } + int32_t prof_id() const { return prof_id_; } /** * Returns true if the value is an integer power of 2. @@ -180,20 +168,20 @@ class MemoryAllocator { /** * Returns the next alignment for a given pointer. */ - static uint8_t* alignPointer(void* ptr, size_t alignment) { + static uint8_t *alignPointer(void *ptr, size_t alignment) { intptr_t addr = reinterpret_cast(ptr); if ((addr & (alignment - 1)) == 0) { // Already aligned. - return reinterpret_cast(ptr); + return reinterpret_cast(ptr); } addr = (addr | (alignment - 1)) + 1; - return reinterpret_cast(addr); + return reinterpret_cast(addr); } - private: - uint8_t* const begin_; - uint8_t* const end_; - uint8_t* cur_; +private: + uint8_t *const begin_; + uint8_t *const end_; + uint8_t *cur_; uint32_t const size_; int32_t prof_id_ = -1; }; @@ -214,15 +202,15 @@ class MemoryAllocator { * }); * @endcode */ -#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ - ({ \ - void* et_try_allocate_result = memory_allocator__->allocate(nbytes__); \ - if (et_try_allocate_result == nullptr && nbytes__ > 0) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ + ({ \ + void *et_try_allocate_result = memory_allocator__->allocate(nbytes__); \ + if (et_try_allocate_result == nullptr && nbytes__ > 0) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) /** @@ -240,16 +228,16 @@ class MemoryAllocator { * { *out_err = Error::MemoryAllocationFailed; return nullopt; }); * @endcode */ -#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ - ({ \ - type__* et_try_allocate_result = \ - memory_allocator__->allocateInstance(); \ - if (et_try_allocate_result == nullptr) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ + ({ \ + type__ *et_try_allocate_result = \ + memory_allocator__->allocateInstance(); \ + if (et_try_allocate_result == nullptr) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) /** @@ -268,16 +256,16 @@ class MemoryAllocator { * }); * @endcode */ -#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ - ({ \ - type__* et_try_allocate_result = \ - memory_allocator__->allocateList(nelem__); \ - if (et_try_allocate_result == nullptr && nelem__ > 0) { \ - __VA_ARGS__ \ - /* The args must return. */ \ - ET_UNREACHABLE(); \ - } \ - et_try_allocate_result; \ +#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ + ({ \ + type__ *et_try_allocate_result = \ + memory_allocator__->allocateList(nelem__); \ + if (et_try_allocate_result == nullptr && nelem__ > 0) { \ + __VA_ARGS__ \ + /* The args must return. */ \ + ET_UNREACHABLE(); \ + } \ + et_try_allocate_result; \ }) #else // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS /** @@ -285,10 +273,8 @@ class MemoryAllocator { * is to directly allocate the memory. * e.g. memory_allocator__->allocate(nbytes__); */ -#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_OR uses statement expressions and \ +#define ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_OR uses statement expressions and \ thus is not available for use with this compiler."); /** @@ -296,10 +282,8 @@ class MemoryAllocator { * is to directly allocate the memory. * e.g. memory_allocator__->allocateInstance(); */ -#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_INSTANCE_OR uses statement \ +#define ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_INSTANCE_OR uses statement \ expressions and thus is not available for use with this compiler."); /** @@ -307,10 +291,8 @@ class MemoryAllocator { * is to directly use allocate the memory. * e.g. memory_allocator__->allocateList(nelem__); */ -#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ - static_assert( \ - false, \ - "ET_TRY_ALLOCATE_LIST_OR uses statement \ +#define ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, ...) \ + static_assert(false, "ET_TRY_ALLOCATE_LIST_OR uses statement \ expressions and thus is not available for use with this compiler."); #endif // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS @@ -326,9 +308,9 @@ class MemoryAllocator { * char* buf = ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator, bufsize); * @endcode */ -#define ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator__, nbytes__) \ - ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator__, nbytes__) \ + ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -344,9 +326,9 @@ class MemoryAllocator { * char* buf = ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator, MyType); * @endcode */ -#define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator__, type__) \ - ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator__, type__) \ + ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -363,9 +345,9 @@ class MemoryAllocator { * memory_allocator, Tensor, num_tensors); * @endcode */ -#define ET_ALLOCATE_LIST_OR_RETURN_ERROR(memory_allocator__, type__, nelem__) \ - ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, { \ - return ::executorch::runtime::Error::MemoryAllocationFailed; \ +#define ET_ALLOCATE_LIST_OR_RETURN_ERROR(memory_allocator__, type__, nelem__) \ + ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, { \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h index c1ff2508..2ae42a8e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h @@ -50,76 +50,70 @@ struct alignas(2) BFloat16 { BFloat16() = default; struct from_bits_t {}; - static constexpr from_bits_t from_bits() { - return from_bits_t(); - } + static constexpr from_bits_t from_bits() { return from_bits_t(); } constexpr BFloat16(unsigned short bits, from_bits_t) : x(bits) {} /* implicit */ BFloat16(float value) : x(internal::round_to_nearest_even(value)) {} - operator float() const { - return internal::f32_from_bits(x); - } + operator float() const { return internal::f32_from_bits(x); } }; -inline std::ostream& operator<<(std::ostream& out, const BFloat16& value) { +inline std::ostream &operator<<(std::ostream &out, const BFloat16 &value) { out << (float)value; return out; } /// Arithmetic -inline BFloat16 operator+(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator+(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) + static_cast(b); } -inline BFloat16 operator-(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator-(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) - static_cast(b); } -inline BFloat16 operator*(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator*(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) * static_cast(b); } -inline BFloat16 operator/(const BFloat16& a, const BFloat16& b) { +inline BFloat16 operator/(const BFloat16 &a, const BFloat16 &b) { return static_cast(a) / static_cast(b); } -inline BFloat16 operator-(const BFloat16& a) { - return -static_cast(a); -} +inline BFloat16 operator-(const BFloat16 &a) { return -static_cast(a); } -inline BFloat16& operator+=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator+=(BFloat16 &a, const BFloat16 &b) { a = a + b; return a; } -inline BFloat16& operator-=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator-=(BFloat16 &a, const BFloat16 &b) { a = a - b; return a; } -inline BFloat16& operator*=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator*=(BFloat16 &a, const BFloat16 &b) { a = a * b; return a; } -inline BFloat16& operator/=(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator/=(BFloat16 &a, const BFloat16 &b) { a = a / b; return a; } -inline BFloat16& operator|(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator|(BFloat16 &a, const BFloat16 &b) { a.x = a.x | b.x; return a; } -inline BFloat16& operator^(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator^(BFloat16 &a, const BFloat16 &b) { a.x = a.x ^ b.x; return a; } -inline BFloat16& operator&(BFloat16& a, const BFloat16& b) { +inline BFloat16 &operator&(BFloat16 &a, const BFloat16 &b) { a.x = a.x & b.x; return a; } @@ -152,16 +146,16 @@ inline float operator/(float a, BFloat16 b) { return a / static_cast(b); } -inline float& operator+=(float& a, const BFloat16& b) { +inline float &operator+=(float &a, const BFloat16 &b) { return a += static_cast(b); } -inline float& operator-=(float& a, const BFloat16& b) { +inline float &operator-=(float &a, const BFloat16 &b) { return a -= static_cast(b); } -inline float& operator*=(float& a, const BFloat16& b) { +inline float &operator*=(float &a, const BFloat16 &b) { return a *= static_cast(b); } -inline float& operator/=(float& a, const BFloat16& b) { +inline float &operator/=(float &a, const BFloat16 &b) { return a /= static_cast(b); } @@ -251,11 +245,11 @@ inline BFloat16 operator/(int64_t a, BFloat16 b) { // Overloading < and > operators, because std::max and std::min use them. -inline bool operator>(BFloat16& lhs, BFloat16& rhs) { +inline bool operator>(BFloat16 &lhs, BFloat16 &rhs) { return float(lhs) > float(rhs); } -inline bool operator<(BFloat16& lhs, BFloat16& rhs) { +inline bool operator<(BFloat16 &lhs, BFloat16 &rhs) { return float(lhs) < float(rhs); } @@ -273,9 +267,8 @@ using ::executorch::runtime::etensor::BFloat16; namespace std { -template <> -class numeric_limits { - public: +template <> class numeric_limits { +public: static constexpr bool is_signed = true; static constexpr bool is_specialized = true; static constexpr bool is_integer = false; @@ -303,40 +296,40 @@ class numeric_limits { numeric_limits::tinyness_before; static constexpr torch::executor::BFloat16 min() { - return torch::executor::BFloat16( - 0x0080, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x0080, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 lowest() { - return torch::executor::BFloat16( - 0xFF7F, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0xFF7F, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 max() { - return torch::executor::BFloat16( - 0x7F7F, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F7F, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 epsilon() { - return torch::executor::BFloat16( - 0x3C00, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x3C00, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 round_error() { - return torch::executor::BFloat16( - 0x3F00, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x3F00, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 infinity() { - return torch::executor::BFloat16( - 0x7F80, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F80, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 quiet_NaN() { - return torch::executor::BFloat16( - 0x7FC0, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7FC0, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 signaling_NaN() { - return torch::executor::BFloat16( - 0x7F80, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x7F80, + torch::executor::BFloat16::from_bits()); } static constexpr torch::executor::BFloat16 denorm_min() { - return torch::executor::BFloat16( - 0x0001, torch::executor::BFloat16::from_bits()); + return torch::executor::BFloat16(0x0001, + torch::executor::BFloat16::from_bits()); } }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h index 68ee77cf..3f6fd400 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h @@ -16,196 +16,164 @@ namespace std { template struct is_reduced_floating_point : std::integral_constant< - bool, - std::is_same::value || - std::is_same::value> {}; + bool, std::is_same::value || + std::is_same::value> {}; -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T acos(T a) { return std::acos(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T asin(T a) { return std::asin(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T atan(T a) { return std::atan(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T atanh(T a) { return std::atanh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T erf(T a) { return std::erf(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T erfc(T a) { return std::erfc(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T exp(T a) { return std::exp(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T expm1(T a) { return std::expm1(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline bool isfinite(T a) { return std::isfinite(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log(T a) { return std::log(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log10(T a) { return std::log10(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log1p(T a) { return std::log1p(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T log2(T a) { return std::log2(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T ceil(T a) { return std::ceil(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T cos(T a) { return std::cos(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T floor(T a) { return std::floor(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T nearbyint(T a) { return std::nearbyint(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sin(T a) { return std::sin(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T tan(T a) { return std::tan(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sinh(T a) { return std::sinh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T cosh(T a) { return std::cosh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T tanh(T a) { return std::tanh(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T trunc(T a) { return std::trunc(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T lgamma(T a) { return std::lgamma(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T sqrt(T a) { return std::sqrt(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T rsqrt(T a) { return 1.0 / std::sqrt(float(a)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T abs(T a) { return std::abs(float(a)); } #if defined(_MSC_VER) && defined(__CUDACC__) -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, double b) { return std::pow(float(a), float(b)); } #else -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, double b) { return std::pow(float(a), b); } #endif -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T pow(T a, T b) { return std::pow(float(a), float(b)); } -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T fmod(T a, T b) { return std::fmod(float(a), float(b)); } @@ -236,9 +204,8 @@ inline T fmod(T a, T b) { SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ---------------------------------------------------------------------- */ -template < - typename T, - typename std::enable_if::value, int>::type = 0> +template ::value, int>::type = 0> inline T nextafter(T from, T to) { // Reference: // https://git.musl-libc.org/cgit/musl/tree/src/math/nextafter.c diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h index e89a19e5..56ed55d4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h @@ -18,8 +18,7 @@ namespace etensor { * An implementation of complex numbers, compatible with c10/util/complex.h from * pytorch core. */ -template -struct alignas(sizeof(T) * 2) complex { +template struct alignas(sizeof(T) * 2) complex { T real_ = T(0); T imag_ = T(0); }; @@ -27,8 +26,7 @@ struct alignas(sizeof(T) * 2) complex { /** * Specialization for Half, which is not a primitive C numeric type. */ -template <> -struct alignas(4) complex { +template <> struct alignas(4) complex { Half real_; Half imag_; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h index d789df8a..7f4f447b 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h @@ -40,14 +40,10 @@ struct Device final { : type_(type), index_(index) {} /// Returns the type of device this is. Only CPU is supported. - DeviceType type() const noexcept { - return type_; - } + DeviceType type() const noexcept { return type_; } /// Returns true if the device is of CPU type. - bool is_cpu() const noexcept { - return type_ == DeviceType::CPU; - } + bool is_cpu() const noexcept { return type_ == DeviceType::CPU; } /// Returns the device index. Always 0 if specified or -1 if not provided. DeviceIndex index() const noexcept { @@ -55,7 +51,7 @@ struct Device final { return index_; } - private: +private: DeviceType type_; DeviceIndex index_ = -1; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h index fa40a807..fd48fabe 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h @@ -8,10 +8,10 @@ #pragma once -#include #include #include #include +#include #include #if defined(__GNUC__) || defined(__clang__) @@ -23,14 +23,14 @@ #endif // GNUC or clang #if defined(__GNUC__) || defined(__clang__) -#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \ +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \ defined(_M_IX86) #if defined(__AVX2__) #define X86_F16 1 #include // import conversion ops from f16cintrin.h -#endif // __AVX2__ -#endif // __x86_64__ || _M_X64 || __i386 || _M_IX86 -#endif // __GNUC__ || __clang__ +#endif // __AVX2__ +#endif // __x86_64__ || _M_X64 || __i386 || _M_IX86 +#endif // __GNUC__ || __clang__ namespace executorch { namespace runtime { @@ -49,9 +49,7 @@ struct alignas(2) Half { }; struct from_bits_t {}; - static constexpr from_bits_t from_bits() { - return from_bits_t(); - } + static constexpr from_bits_t from_bits() { return from_bits_t(); } Half() = default; @@ -171,9 +169,9 @@ inline uint32_t fp16_ieee_to_fp32_bits(uint16_t h) { * 7. Combine with the sign of the input number. */ return sign | - ((((nonsign << renorm_shift >> 3) + ((0x70 - renorm_shift) << 23)) | - inf_nan_mask) & - ~zero_mask); + ((((nonsign << renorm_shift >> 3) + ((0x70 - renorm_shift) << 23)) | + inf_nan_mask) & + ~zero_mask); } /* @@ -308,9 +306,9 @@ inline float fp16_ieee_to_fp32_value(uint16_t h) { * of the input number. */ constexpr uint32_t denormalized_cutoff = UINT32_C(1) << 27; - const uint32_t result = sign | - (two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) - : fp32_to_bits(normalized_value)); + const uint32_t result = + sign | (two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) + : fp32_to_bits(normalized_value)); return fp32_from_bits(result); #endif // not X86_F16 @@ -336,8 +334,8 @@ inline uint16_t fp16_ieee_from_fp32_value(float f) { constexpr uint32_t scale_to_zero_bits = (uint32_t)17 << 23; float scale_to_inf_val = 0, scale_to_zero_val = 0; std::memcpy(&scale_to_inf_val, &scale_to_inf_bits, sizeof(scale_to_inf_val)); - std::memcpy( - &scale_to_zero_val, &scale_to_zero_bits, sizeof(scale_to_zero_val)); + std::memcpy(&scale_to_zero_val, &scale_to_zero_bits, + sizeof(scale_to_zero_val)); const float scale_to_inf = scale_to_inf_val; const float scale_to_zero = scale_to_zero_val; @@ -378,9 +376,7 @@ inline Half::Half(float value) /// Implicit conversions #ifdef NATIVE_FP16 -inline Half::operator float() const { - return (float)y; -} +inline Half::operator float() const { return (float)y; } #else inline Half::operator float() const { return internal::fp16_ieee_to_fp32_value(x); @@ -391,92 +387,82 @@ inline Half::operator float() const { #ifdef NATIVE_FP16 -#define return_half(r) \ - do { \ - Half ret; \ - ret.y = r; \ - return ret; \ +#define return_half(r) \ + do { \ + Half ret; \ + ret.y = r; \ + return ret; \ } while (0) -inline Half operator+(const Half& a, const Half& b) { - return_half(a.y + b.y); -} +inline Half operator+(const Half &a, const Half &b) { return_half(a.y + b.y); } -inline Half operator-(const Half& a, const Half& b) { +inline Half operator-(const Half &a, const Half &b) { return_half(a.y - b.y); return static_cast(a) - static_cast(b); } -inline Half operator*(const Half& a, const Half& b) { - return_half(a.y * b.y); -} +inline Half operator*(const Half &a, const Half &b) { return_half(a.y * b.y); } -inline Half operator/(const Half& a, const Half& b) { - return_half(a.y / b.y); -} +inline Half operator/(const Half &a, const Half &b) { return_half(a.y / b.y); } -inline Half operator-(const Half& a) { - return_half(-a.y); -} +inline Half operator-(const Half &a) { return_half(-a.y); } -inline Half& operator+=(Half& a, const Half& b) { +inline Half &operator+=(Half &a, const Half &b) { a.y += b.y; return a; } -inline Half& operator-=(Half& a, const Half& b) { +inline Half &operator-=(Half &a, const Half &b) { a.y -= b.y; return a; } -inline Half& operator*=(Half& a, const Half& b) { +inline Half &operator*=(Half &a, const Half &b) { a.y *= b.y; return a; } -inline Half& operator/=(Half& a, const Half& b) { +inline Half &operator/=(Half &a, const Half &b) { a.y /= b.y; return a; } #else -inline Half operator+(const Half& a, const Half& b) { +inline Half operator+(const Half &a, const Half &b) { return static_cast(a) + static_cast(b); } -inline Half operator-(const Half& a, const Half& b) { +inline Half operator-(const Half &a, const Half &b) { return static_cast(a) - static_cast(b); } -inline Half operator*(const Half& a, const Half& b) { +inline Half operator*(const Half &a, const Half &b) { return static_cast(a) * static_cast(b); } -inline Half operator/(const Half& a, const Half& b) { +inline Half operator/(const Half &a, const Half &b) { return static_cast(a) / static_cast(b); } -inline Half operator-(const Half& a) { - return -static_cast(a); -} +inline Half operator-(const Half &a) { return -static_cast(a); } -inline Half& operator+=(Half& a, const Half& b) { +inline Half &operator+=(Half &a, const Half &b) { a = a + b; return a; } -inline Half& operator-=(Half& a, const Half& b) { +inline Half &operator-=(Half &a, const Half &b) { a = a - b; return a; } -inline Half& operator*=(Half& a, const Half& b) { +inline Half &operator*=(Half &a, const Half &b) { a = a * b; return a; } -inline Half& operator/=(Half& a, const Half& b) { +inline Half &operator/=(Half &a, const Half &b) { a = a / b; return a; } @@ -485,130 +471,66 @@ inline Half& operator/=(Half& a, const Half& b) { /// Arithmetic with floats -inline float operator+(Half a, float b) { - return static_cast(a) + b; -} -inline float operator-(Half a, float b) { - return static_cast(a) - b; -} -inline float operator*(Half a, float b) { - return static_cast(a) * b; -} -inline float operator/(Half a, float b) { - return static_cast(a) / b; -} +inline float operator+(Half a, float b) { return static_cast(a) + b; } +inline float operator-(Half a, float b) { return static_cast(a) - b; } +inline float operator*(Half a, float b) { return static_cast(a) * b; } +inline float operator/(Half a, float b) { return static_cast(a) / b; } -inline float operator+(float a, Half b) { - return a + static_cast(b); -} -inline float operator-(float a, Half b) { - return a - static_cast(b); -} -inline float operator*(float a, Half b) { - return a * static_cast(b); -} -inline float operator/(float a, Half b) { - return a / static_cast(b); -} +inline float operator+(float a, Half b) { return a + static_cast(b); } +inline float operator-(float a, Half b) { return a - static_cast(b); } +inline float operator*(float a, Half b) { return a * static_cast(b); } +inline float operator/(float a, Half b) { return a / static_cast(b); } -inline float& operator+=(float& a, const Half& b) { +inline float &operator+=(float &a, const Half &b) { return a += static_cast(b); } -inline float& operator-=(float& a, const Half& b) { +inline float &operator-=(float &a, const Half &b) { return a -= static_cast(b); } -inline float& operator*=(float& a, const Half& b) { +inline float &operator*=(float &a, const Half &b) { return a *= static_cast(b); } -inline float& operator/=(float& a, const Half& b) { +inline float &operator/=(float &a, const Half &b) { return a /= static_cast(b); } /// Arithmetic with doubles -inline double operator+(Half a, double b) { - return static_cast(a) + b; -} -inline double operator-(Half a, double b) { - return static_cast(a) - b; -} -inline double operator*(Half a, double b) { - return static_cast(a) * b; -} -inline double operator/(Half a, double b) { - return static_cast(a) / b; -} +inline double operator+(Half a, double b) { return static_cast(a) + b; } +inline double operator-(Half a, double b) { return static_cast(a) - b; } +inline double operator*(Half a, double b) { return static_cast(a) * b; } +inline double operator/(Half a, double b) { return static_cast(a) / b; } -inline double operator+(double a, Half b) { - return a + static_cast(b); -} -inline double operator-(double a, Half b) { - return a - static_cast(b); -} -inline double operator*(double a, Half b) { - return a * static_cast(b); -} -inline double operator/(double a, Half b) { - return a / static_cast(b); -} +inline double operator+(double a, Half b) { return a + static_cast(b); } +inline double operator-(double a, Half b) { return a - static_cast(b); } +inline double operator*(double a, Half b) { return a * static_cast(b); } +inline double operator/(double a, Half b) { return a / static_cast(b); } /// Arithmetic with ints #ifdef NATIVE_FP16 -inline Half operator+(Half a, int32_t b) { - return_half(a.y + b); -} -inline Half operator-(Half a, int32_t b) { - return_half(a.y - b); -} -inline Half operator*(Half a, int32_t b) { - return_half(a.y * b); -} -inline Half operator/(Half a, int32_t b) { - return_half(a.y / b); -} +inline Half operator+(Half a, int32_t b) { return_half(a.y + b); } +inline Half operator-(Half a, int32_t b) { return_half(a.y - b); } +inline Half operator*(Half a, int32_t b) { return_half(a.y * b); } +inline Half operator/(Half a, int32_t b) { return_half(a.y / b); } -inline Half operator+(int32_t a, Half b) { - return_half(a + b.y); -} -inline Half operator-(int32_t a, Half b) { - return_half(a - b.y); -} -inline Half operator*(int32_t a, Half b) { - return_half(a * b.y); -} -inline Half operator/(int32_t a, Half b) { - return_half(a / b.y); -} +inline Half operator+(int32_t a, Half b) { return_half(a + b.y); } +inline Half operator-(int32_t a, Half b) { return_half(a - b.y); } +inline Half operator*(int32_t a, Half b) { return_half(a * b.y); } +inline Half operator/(int32_t a, Half b) { return_half(a / b.y); } #else -inline Half operator+(Half a, int32_t b) { - return a + static_cast(b); -} -inline Half operator-(Half a, int32_t b) { - return a - static_cast(b); -} -inline Half operator*(Half a, int32_t b) { - return a * static_cast(b); -} -inline Half operator/(Half a, int32_t b) { - return a / static_cast(b); -} +inline Half operator+(Half a, int32_t b) { return a + static_cast(b); } +inline Half operator-(Half a, int32_t b) { return a - static_cast(b); } +inline Half operator*(Half a, int32_t b) { return a * static_cast(b); } +inline Half operator/(Half a, int32_t b) { return a / static_cast(b); } -inline Half operator+(int32_t a, Half b) { - return static_cast(a) + b; -} -inline Half operator-(int32_t a, Half b) { - return static_cast(a) - b; -} -inline Half operator*(int32_t a, Half b) { - return static_cast(a) * b; -} -inline Half operator/(int32_t a, Half b) { - return static_cast(a) / b; -} +inline Half operator+(int32_t a, Half b) { return static_cast(a) + b; } +inline Half operator-(int32_t a, Half b) { return static_cast(a) - b; } +inline Half operator*(int32_t a, Half b) { return static_cast(a) * b; } +inline Half operator/(int32_t a, Half b) { return static_cast(a) / b; } #endif @@ -616,68 +538,35 @@ inline Half operator/(int32_t a, Half b) { #ifdef NATIVE_FP16 -inline Half operator+(Half a, int64_t b) { - return_half(a.y + b); -} -inline Half operator-(Half a, int64_t b) { - return_half(a.y - b); -} -inline Half operator*(Half a, int64_t b) { - return_half(a.y * b); -} -inline Half operator/(Half a, int64_t b) { - return_half(a.y / b); -} +inline Half operator+(Half a, int64_t b) { return_half(a.y + b); } +inline Half operator-(Half a, int64_t b) { return_half(a.y - b); } +inline Half operator*(Half a, int64_t b) { return_half(a.y * b); } +inline Half operator/(Half a, int64_t b) { return_half(a.y / b); } -inline Half operator+(int64_t a, Half b) { - return_half(a + b.y); -} -inline Half operator-(int64_t a, Half b) { - return_half(a - b.y); -} -inline Half operator*(int64_t a, Half b) { - return_half(a * b.y); -} -inline Half operator/(int64_t a, Half b) { - return_half(a / b.y); -} +inline Half operator+(int64_t a, Half b) { return_half(a + b.y); } +inline Half operator-(int64_t a, Half b) { return_half(a - b.y); } +inline Half operator*(int64_t a, Half b) { return_half(a * b.y); } +inline Half operator/(int64_t a, Half b) { return_half(a / b.y); } #else -inline Half operator+(Half a, int64_t b) { - return a + static_cast(b); -} -inline Half operator-(Half a, int64_t b) { - return a - static_cast(b); -} -inline Half operator*(Half a, int64_t b) { - return a * static_cast(b); -} -inline Half operator/(Half a, int64_t b) { - return a / static_cast(b); -} +inline Half operator+(Half a, int64_t b) { return a + static_cast(b); } +inline Half operator-(Half a, int64_t b) { return a - static_cast(b); } +inline Half operator*(Half a, int64_t b) { return a * static_cast(b); } +inline Half operator/(Half a, int64_t b) { return a / static_cast(b); } -inline Half operator+(int64_t a, Half b) { - return static_cast(a) + b; -} -inline Half operator-(int64_t a, Half b) { - return static_cast(a) - b; -} -inline Half operator*(int64_t a, Half b) { - return static_cast(a) * b; -} -inline Half operator/(int64_t a, Half b) { - return static_cast(a) / b; -} +inline Half operator+(int64_t a, Half b) { return static_cast(a) + b; } +inline Half operator-(int64_t a, Half b) { return static_cast(a) - b; } +inline Half operator*(int64_t a, Half b) { return static_cast(a) * b; } +inline Half operator/(int64_t a, Half b) { return static_cast(a) / b; } #endif /// NOTE: we do not define comparisons directly and instead rely on the implicit /// conversion Half to float. -static inline std::ostream& operator<<( - std::ostream& out, - const executorch::runtime::etensor::Half& value) { +static inline std::ostream & +operator<<(std::ostream &out, const executorch::runtime::etensor::Half &value) { out << (float)value; return out; } @@ -695,9 +584,8 @@ using ::executorch::runtime::etensor::Half; namespace std { -template <> -class numeric_limits { - public: +template <> class numeric_limits { +public: static constexpr bool is_specialized = true; static constexpr bool is_signed = true; static constexpr bool is_integer = false; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h index 21fe0d39..f9df4681 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h @@ -26,9 +26,8 @@ struct nullopt_t final { constexpr nullopt_t nullopt{0}; /// Leaner optional class, subset of c10, std, and boost optional APIs. -template -class optional final { - public: +template class optional final { +public: /// The type wrapped by the optional class. using value_type = T; @@ -40,7 +39,7 @@ class optional final { : storage_(trivial_init), init_(false) {} /// Constructs an optional object that matches the state of v. - /* implicit */ optional(const optional& v) + /* implicit */ optional(const optional &v) : storage_(trivial_init), init_(v.init_) { if (init_) { new (&storage_.value_) T(v.storage_.value_); @@ -48,10 +47,10 @@ class optional final { } /// Constructs an optional object that contains the specified value. - /* implicit */ optional(const T& v) : storage_(v), init_(true) {} + /* implicit */ optional(const T &v) : storage_(v), init_(true) {} /// Constructs an optional object from v. - /* implicit */ optional(optional&& v) noexcept( + /* implicit */ optional(optional &&v) noexcept( std::is_nothrow_move_constructible::value) : storage_(trivial_init), init_(v.init_) { if (init_) { @@ -60,9 +59,9 @@ class optional final { } /// Constructs an optional object that contains the specified value. - /* implicit */ optional(T&& v) : storage_(std::forward(v)), init_(true) {} + /* implicit */ optional(T &&v) : storage_(std::forward(v)), init_(true) {} - optional& operator=(const optional& rhs) { + optional &operator=(const optional &rhs) { if (init_ && !rhs.init_) { clear(); } else if (!init_ && rhs.init_) { @@ -74,7 +73,7 @@ class optional final { return *this; } - optional& operator=(optional&& rhs) noexcept( + optional &operator=(optional &&rhs) noexcept( std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) { if (init_ && !rhs.init_) { @@ -95,43 +94,39 @@ class optional final { } } - optional& operator=(nullopt_t) noexcept { + optional &operator=(nullopt_t) noexcept { clear(); return *this; } /// Returns true if the object contains a value, false otherwise - explicit operator bool() const noexcept { - return init_; - } + explicit operator bool() const noexcept { return init_; } /// Returns true if the object contains a value, false otherwise - bool has_value() const noexcept { - return init_; - } + bool has_value() const noexcept { return init_; } /// Returns a constant reference to the contained value. Calls ET_CHECK if /// the object does not contain a value. - T const& value() const& { + T const &value() const & { ET_CHECK(init_); return contained_val(); } /// Returns a mutable reference to the contained value. Calls ET_CHECK if the /// object does not contain a value. - T& value() & { + T &value() & { ET_CHECK(init_); return contained_val(); } /// Returns an rvalue of the contained value. Calls ET_CHECK if the object /// does not contain a value. - T&& value() && { + T &&value() && { ET_CHECK(init_); return std::forward(contained_val()); } - private: +private: // Used to invoke the dummy ctor of storage_t in the initializer lists of // optional_base as default ctor is implicitly deleted because T is nontrivial struct trivial_init_t { @@ -147,25 +142,17 @@ class optional final { /// The constructed value itself, if optional::has_value_ is true. T value_; - /* implicit */ storage_t(trivial_init_t) { - dummy_ = 0; - } + /* implicit */ storage_t(trivial_init_t) { dummy_ = 0; } template - storage_t(Args&&... args) : value_(std::forward(args)...) {} + storage_t(Args &&...args) : value_(std::forward(args)...) {} ~storage_t() {} }; - const T& contained_val() const& { - return storage_.value_; - } - T&& contained_val() && { - return std::move(storage_.value_); - } - T& contained_val() & { - return storage_.value_; - } + const T &contained_val() const & { return storage_.value_; } + T &&contained_val() && { return std::move(storage_.value_); } + T &contained_val() & { return storage_.value_; } void clear() noexcept { if (init_) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h index 0922cec6..f503990e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h @@ -27,27 +27,21 @@ namespace etensor { * semantics/behavior should also match the c10 version. */ class Scalar { - public: +public: Scalar() : Scalar(int64_t(0)) {} - template < - typename T, - typename std::enable_if::value, bool>::type = true> + template ::value, + bool>::type = true> /*implicit*/ Scalar(T val) : tag(Tag::Int) { v.as_int = static_cast(val); } - /*implicit*/ Scalar(bool val) : tag(Tag::Bool) { - v.as_bool = val; - } - /*implicit*/ Scalar(double val) : tag(Tag::Double) { - v.as_double = val; - } + /*implicit*/ Scalar(bool val) : tag(Tag::Bool) { v.as_bool = val; } + /*implicit*/ Scalar(double val) : tag(Tag::Double) { v.as_double = val; } /*implicit*/ Scalar(BFloat16 val) : Scalar((double)(float)val) {} /*implicit*/ Scalar(Half val) : Scalar((double)(float)val) {} /// Returns the concrete scalar value stored within. - template - T to() const; + template T to() const; /// Returns true if the scalar is integral, false otherwise. bool isIntegral(bool includeBool) const { @@ -55,16 +49,12 @@ class Scalar { } /// Returns true if the scalar is a floating point, false otherwise. - bool isFloatingPoint() const { - return tag == Tag::Double; - } + bool isFloatingPoint() const { return tag == Tag::Double; } /// Returns true if the scalar is a boolean, false otherwise. - bool isBoolean() const { - return tag == Tag::Bool; - } + bool isBoolean() const { return tag == Tag::Bool; } - private: +private: int64_t toInt() const { if (isIntegral(/*includeBool=*/false)) { return v.as_int; @@ -99,11 +89,8 @@ class Scalar { } v; }; -#define ET_DEFINE_SCALAR_TO_METHOD(T, name) \ - template <> \ - inline T Scalar::to() const { \ - return to##name(); \ - } +#define ET_DEFINE_SCALAR_TO_METHOD(T, name) \ + template <> inline T Scalar::to() const { return to##name(); } ET_DEFINE_SCALAR_TO_METHOD(double, Double) ET_DEFINE_SCALAR_TO_METHOD(int64_t, Int) diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h index 286aee33..f91344b4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h @@ -59,30 +59,30 @@ namespace etensor { * @param _ A macro that takes two parameters: the name of a C type, and the * name of the corresponding ScalarType enumerator. */ -#define ET_FORALL_SCALAR_TYPES(_) \ - _(uint8_t, Byte) /* 0 */ \ - _(int8_t, Char) /* 1 */ \ - _(int16_t, Short) /* 2 */ \ - _(int32_t, Int) /* 3 */ \ - _(int64_t, Long) /* 4 */ \ - _(::torch::executor::Half, Half) /* 5 */ \ - _(float, Float) /* 6 */ \ - _(double, Double) /* 7 */ \ - _(::torch::executor::complex<::torch::executor::Half>, ComplexHalf) /* 8 */ \ - _(::torch::executor::complex, ComplexFloat) /* 9 */ \ - _(::torch::executor::complex, ComplexDouble) /* 10 */ \ - _(bool, Bool) /* 11 */ \ - _(::torch::executor::qint8, QInt8) /* 12 */ \ - _(::torch::executor::quint8, QUInt8) /* 13 */ \ - _(::torch::executor::qint32, QInt32) /* 14 */ \ - _(::torch::executor::BFloat16, BFloat16) /* 15 */ \ - _(::torch::executor::quint4x2, QUInt4x2) /* 16 */ \ - _(::torch::executor::quint2x4, QUInt2x4) /* 17 */ \ - _(::torch::executor::bits1x8, Bits1x8) /* 18 */ \ - _(::torch::executor::bits2x4, Bits2x4) /* 19 */ \ - _(::torch::executor::bits4x2, Bits4x2) /* 20 */ \ - _(::torch::executor::bits8, Bits8) /* 21 */ \ - _(::torch::executor::bits16, Bits16) /* 22 */ +#define ET_FORALL_SCALAR_TYPES(_) \ + _(uint8_t, Byte) /* 0 */ \ + _(int8_t, Char) /* 1 */ \ + _(int16_t, Short) /* 2 */ \ + _(int32_t, Int) /* 3 */ \ + _(int64_t, Long) /* 4 */ \ + _(::torch::executor::Half, Half) /* 5 */ \ + _(float, Float) /* 6 */ \ + _(double, Double) /* 7 */ \ + _(::torch::executor::complex<::torch::executor::Half>, ComplexHalf) /* 8 */ \ + _(::torch::executor::complex, ComplexFloat) /* 9 */ \ + _(::torch::executor::complex, ComplexDouble) /* 10 */ \ + _(bool, Bool) /* 11 */ \ + _(::torch::executor::qint8, QInt8) /* 12 */ \ + _(::torch::executor::quint8, QUInt8) /* 13 */ \ + _(::torch::executor::qint32, QInt32) /* 14 */ \ + _(::torch::executor::BFloat16, BFloat16) /* 15 */ \ + _(::torch::executor::quint4x2, QUInt4x2) /* 16 */ \ + _(::torch::executor::quint2x4, QUInt2x4) /* 17 */ \ + _(::torch::executor::bits1x8, Bits1x8) /* 18 */ \ + _(::torch::executor::bits2x4, Bits2x4) /* 19 */ \ + _(::torch::executor::bits4x2, Bits4x2) /* 20 */ \ + _(::torch::executor::bits8, Bits8) /* 21 */ \ + _(::torch::executor::bits16, Bits16) /* 22 */ /** * Data types (dtypes) that can be used as element types in ETensors. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h index 977a0f54..067ac10e 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h @@ -25,15 +25,14 @@ namespace internal { * Mostly copy pasted from the c10 implementation but modified some to remove * broader c10 dependencies */ -template -class basic_string_view final { - public: +template class basic_string_view final { +public: using value_type = CharT; - using pointer = CharT*; - using const_pointer = const CharT*; - using reference = CharT&; - using const_reference = const CharT&; - using const_iterator = const CharT*; + using pointer = CharT *; + using const_pointer = const CharT *; + using reference = CharT &; + using const_reference = const CharT &; + using const_iterator = const CharT *; using iterator = const_iterator; using size_type = std::size_t; @@ -47,21 +46,13 @@ class basic_string_view final { /* implicit */ constexpr basic_string_view(const_pointer str) : basic_string_view(str, strlen_(str)) {} - constexpr const_iterator begin() const noexcept { - return cbegin(); - } + constexpr const_iterator begin() const noexcept { return cbegin(); } - constexpr const_iterator cbegin() const noexcept { - return begin_; - } + constexpr const_iterator cbegin() const noexcept { return begin_; } - constexpr const_iterator end() const noexcept { - return cend(); - } + constexpr const_iterator end() const noexcept { return cend(); } - constexpr const_iterator cend() const noexcept { - return begin_ + size_; - } + constexpr const_iterator cend() const noexcept { return begin_ + size_; } friend constexpr const_iterator begin(basic_string_view sv) noexcept { return sv.begin(); @@ -71,40 +62,25 @@ class basic_string_view final { return sv.end(); } - constexpr const_reference operator[](size_type pos) const { - return at_(pos); - } + constexpr const_reference operator[](size_type pos) const { return at_(pos); } constexpr const_reference at(size_type pos) const { - ET_CHECK_MSG( - pos >= size_, - "string_view::operator[] or string_view::at() out of range"); + ET_CHECK_MSG(pos >= size_, + "string_view::operator[] or string_view::at() out of range"); return at_(pos); } - constexpr const_reference front() const { - return *begin_; - } + constexpr const_reference front() const { return *begin_; } - constexpr const_reference back() const { - return *(begin_ + size_ - 1); - } + constexpr const_reference back() const { return *(begin_ + size_ - 1); } - constexpr const_pointer data() const noexcept { - return begin_; - } + constexpr const_pointer data() const noexcept { return begin_; } - constexpr size_type size() const noexcept { - return size_; - } + constexpr size_type size() const noexcept { return size_; } - constexpr size_type length() const noexcept { - return size(); - } + constexpr size_type length() const noexcept { return size(); } - constexpr bool empty() const noexcept { - return size() == 0; - } + constexpr bool empty() const noexcept { return size() == 0; } void remove_prefix(size_type n) { ET_CHECK_MSG(n > size(), "basic_string_view::remove_prefix: out of range."); @@ -117,7 +93,7 @@ class basic_string_view final { size_ -= n; } - void swap(basic_string_view& sv) noexcept { + void swap(basic_string_view &sv) noexcept { auto tmp = *this; *this = sv; sv = tmp; @@ -132,10 +108,10 @@ class basic_string_view final { return copy_length; } - constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) - const { - ET_CHECK_MSG( - pos > size_, "basic_string_view::substr parameter out of bounds."); + constexpr basic_string_view substr(size_type pos = 0, + size_type count = npos) const { + ET_CHECK_MSG(pos > size_, + "basic_string_view::substr parameter out of bounds."); return substr_(pos, count); } @@ -159,25 +135,21 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (size() == 0 && rhs.size() == 0) ? 0 - : (size() == 0) ? -1 - : (rhs.size() == 0) ? 1 - : (front() < rhs.front()) ? -1 - : (front() > rhs.front()) ? 1 - : substr_(1).compare(rhs.substr_(1)); + : (size() == 0) ? -1 + : (rhs.size() == 0) ? 1 + : (front() < rhs.front()) ? -1 + : (front() > rhs.front()) ? 1 + : substr_(1).compare(rhs.substr_(1)); #endif } - constexpr int compare(size_type pos1, size_type count1, basic_string_view v) - const { + constexpr int compare(size_type pos1, size_type count1, + basic_string_view v) const { return substr(pos1, count1).compare(v); } - constexpr int compare( - size_type pos1, - size_type count1, - basic_string_view v, - size_type pos2, - size_type count2) const { + constexpr int compare(size_type pos1, size_type count1, basic_string_view v, + size_type pos2, size_type count2) const { return substr(pos1, count1).compare(v.substr(pos2, count2)); } @@ -185,52 +157,43 @@ class basic_string_view final { return compare(basic_string_view(s)); } - constexpr int compare(size_type pos1, size_type count1, const_pointer s) - const { + constexpr int compare(size_type pos1, size_type count1, + const_pointer s) const { return substr(pos1, count1).compare(basic_string_view(s)); } - constexpr int compare( - size_type pos1, - size_type count1, - const_pointer s, - size_type count2) const { + constexpr int compare(size_type pos1, size_type count1, const_pointer s, + size_type count2) const { return substr(pos1, count1).compare(basic_string_view(s, count2)); } - friend constexpr bool operator==( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator==(basic_string_view lhs, + basic_string_view rhs) noexcept { return lhs.equals_(rhs); } - friend constexpr bool operator!=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator!=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs == rhs); } - friend constexpr bool operator<( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator<(basic_string_view lhs, + basic_string_view rhs) noexcept { return lhs.compare(rhs) < 0; } - friend constexpr bool operator>=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator>=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs < rhs); } - friend constexpr bool operator>( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator>(basic_string_view lhs, + basic_string_view rhs) noexcept { return rhs < lhs; } - friend constexpr bool operator<=( - basic_string_view lhs, - basic_string_view rhs) noexcept { + friend constexpr bool operator<=(basic_string_view lhs, + basic_string_view rhs) noexcept { return !(lhs > rhs); } @@ -249,8 +212,8 @@ class basic_string_view final { constexpr bool ends_with(basic_string_view suffix) const noexcept { return (suffix.size() > size()) - ? false - : suffix.equals_(substr_(size() - suffix.size(), suffix.size())); + ? false + : suffix.equals_(substr_(size() - suffix.size(), suffix.size())); } constexpr bool ends_with(CharT suffix) const noexcept { @@ -261,8 +224,8 @@ class basic_string_view final { return ends_with(basic_string_view(suffix)); } - constexpr size_type find(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find(basic_string_view v, + size_type pos = 0) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (v.size() == 0) { @@ -281,12 +244,12 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (v.size() == 0) ? (pos <= size() ? pos : npos) - : (pos + v.size() > size()) ? npos - : (v.at_(0) == at_(pos) && - v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) - ? pos - : find(v, pos + 1); + return (v.size() == 0) ? (pos <= size() ? pos : npos) + : (pos + v.size() > size()) ? npos + : (v.at_(0) == at_(pos) && + v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) + ? pos + : find(v, pos + 1); #endif } @@ -294,8 +257,8 @@ class basic_string_view final { return find_first_if_(pos, charIsEqual_{ch}); } - constexpr size_type find(const_pointer s, size_type pos, size_type count) - const { + constexpr size_type find(const_pointer s, size_type pos, + size_type count) const { return find(basic_string_view(s, count), pos); } @@ -303,8 +266,8 @@ class basic_string_view final { return find(basic_string_view(s), pos); } - constexpr size_type rfind(basic_string_view v, size_type pos = npos) - const noexcept { + constexpr size_type rfind(basic_string_view v, + size_type pos = npos) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (v.size() == 0) { @@ -324,14 +287,14 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (v.size() == 0) ? (pos <= size() ? pos : size()) - : (v.size() > size()) ? npos - : (size() - v.size() < pos) ? rfind(v, size() - v.size()) - : (v.at_(0) == at_(pos) && - v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) - ? pos - : (pos == 0) ? npos - : rfind(v, pos - 1); + return (v.size() == 0) ? (pos <= size() ? pos : size()) + : (v.size() > size()) ? npos + : (size() - v.size() < pos) ? rfind(v, size() - v.size()) + : (v.at_(0) == at_(pos) && + v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) + ? pos + : (pos == 0) ? npos + : rfind(v, pos - 1); #endif } @@ -339,8 +302,8 @@ class basic_string_view final { return find_last_if_(pos, charIsEqual_{ch}); } - constexpr size_type rfind(const_pointer s, size_type pos, size_type count) - const { + constexpr size_type rfind(const_pointer s, size_type pos, + size_type count) const { return rfind(basic_string_view(s, count), pos); } @@ -348,18 +311,18 @@ class basic_string_view final { return rfind(basic_string_view(s), pos); } - constexpr size_type find_first_of(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find_first_of(basic_string_view v, + size_type pos = 0) const noexcept { return find_first_if_(pos, stringViewContainsChar_{v}); } - constexpr size_type find_first_of(CharT ch, size_type pos = 0) - const noexcept { + constexpr size_type find_first_of(CharT ch, + size_type pos = 0) const noexcept { return find_first_if_(pos, charIsEqual_{ch}); } - constexpr size_type - find_first_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_first_of(const_pointer s, size_type pos, + size_type count) const { return find_first_of(basic_string_view(s, count), pos); } @@ -367,68 +330,67 @@ class basic_string_view final { return find_first_of(basic_string_view(s), pos); } - constexpr size_type find_last_of(basic_string_view v, size_type pos = npos) - const noexcept { + constexpr size_type find_last_of(basic_string_view v, + size_type pos = npos) const noexcept { return find_last_if_(pos, stringViewContainsChar_{v}); } - constexpr size_type find_last_of(CharT ch, size_type pos = npos) - const noexcept { + constexpr size_type find_last_of(CharT ch, + size_type pos = npos) const noexcept { return find_last_if_(pos, charIsEqual_{ch}); } - constexpr size_type - find_last_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_last_of(const_pointer s, size_type pos, + size_type count) const { return find_last_of(basic_string_view(s, count), pos); } - constexpr size_type find_last_of(const_pointer s, size_type pos = npos) - const { + constexpr size_type find_last_of(const_pointer s, + size_type pos = npos) const { return find_last_of(basic_string_view(s), pos); } - constexpr size_type find_first_not_of(basic_string_view v, size_type pos = 0) - const noexcept { + constexpr size_type find_first_not_of(basic_string_view v, + size_type pos = 0) const noexcept { return find_first_if_(pos, stringViewDoesNotContainChar_{v}); } - constexpr size_type find_first_not_of(CharT ch, size_type pos = 0) - const noexcept { + constexpr size_type find_first_not_of(CharT ch, + size_type pos = 0) const noexcept { return find_first_if_(pos, charIsNotEqual_{ch}); } - constexpr size_type - find_first_not_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_first_not_of(const_pointer s, size_type pos, + size_type count) const { return find_first_not_of(basic_string_view(s, count), pos); } - constexpr size_type find_first_not_of(const_pointer s, size_type pos = 0) - const { + constexpr size_type find_first_not_of(const_pointer s, + size_type pos = 0) const { return find_first_not_of(basic_string_view(s), pos); } - constexpr size_type find_last_not_of( - basic_string_view v, - size_type pos = npos) const noexcept { + constexpr size_type find_last_not_of(basic_string_view v, + size_type pos = npos) const noexcept { return find_last_if_(pos, stringViewDoesNotContainChar_{v}); } - constexpr size_type find_last_not_of(CharT ch, size_type pos = npos) - const noexcept { + constexpr size_type find_last_not_of(CharT ch, + size_type pos = npos) const noexcept { return find_last_if_(pos, charIsNotEqual_{ch}); } - constexpr size_type - find_last_not_of(const_pointer s, size_type pos, size_type count) const { + constexpr size_type find_last_not_of(const_pointer s, size_type pos, + size_type count) const { return find_last_not_of(basic_string_view(s, count), pos); } - constexpr size_type find_last_not_of(const_pointer s, size_type pos = npos) - const { + constexpr size_type find_last_not_of(const_pointer s, + size_type pos = npos) const { return find_last_not_of(basic_string_view(s), pos); } - private: +private: static constexpr std::size_t min_(const std::size_t a, const std::size_t b) { return (b < a) ? b : a; } @@ -452,14 +414,14 @@ class basic_string_view final { return *(begin_ + pos); } - constexpr basic_string_view substr_(size_type pos = 0, size_type count = npos) - const { + constexpr basic_string_view substr_(size_type pos = 0, + size_type count = npos) const { return basic_string_view{begin_ + pos, min_(count, size() - pos)}; } template - constexpr size_type find_first_if_(size_type pos, Condition&& condition) - const noexcept { + constexpr size_type find_first_if_(size_type pos, + Condition &&condition) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (pos + 1 <= size()) { @@ -474,15 +436,15 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (pos + 1 > size()) ? npos - : condition(at_(pos)) - ? pos - : find_first_if_(pos + 1, std::forward(condition)); + : condition(at_(pos)) + ? pos + : find_first_if_(pos + 1, std::forward(condition)); #endif } template - constexpr size_type find_last_if_(size_type pos, Condition&& condition) - const noexcept { + constexpr size_type find_last_if_(size_type pos, + Condition &&condition) const noexcept { #if __cpp_constexpr >= 201304 // if we are in C++14, write it iteratively. This is faster. if (size() > 0) { @@ -498,12 +460,12 @@ class basic_string_view final { // if we are in C++11, we need to do it recursively because of constexpr // restrictions. return (size() == 0) ? npos - : (pos >= size()) - ? find_last_if_(size() - 1, std::forward(condition)) - : condition(at_(pos)) ? pos - : (pos == 0) - ? npos - : find_last_if_(pos - 1, std::forward(condition)); + : (pos >= size()) + ? find_last_if_(size() - 1, std::forward(condition)) + : condition(at_(pos)) ? pos + : (pos == 0) + ? npos + : find_last_if_(pos - 1, std::forward(condition)); #endif } @@ -525,10 +487,10 @@ class basic_string_view final { #else // if we are in C++11, we need to do it recursively because of constexpr // restrictions. - return (size() != rhs.size()) ? false - : (size() == 0) ? true - : (front() != rhs.front()) ? false - : (substr_(1).equals_(rhs.substr_(1))); + return (size() != rhs.size()) ? false + : (size() == 0) ? true + : (front() != rhs.front()) ? false + : (substr_(1).equals_(rhs.substr_(1))); #endif } @@ -565,9 +527,8 @@ class basic_string_view final { }; template -inline void swap( - basic_string_view& lhs, - basic_string_view& rhs) noexcept { +inline void swap(basic_string_view &lhs, + basic_string_view &rhs) noexcept { lhs.swap(rhs); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h index 775bccc1..7e9efaa4 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h @@ -27,7 +27,7 @@ namespace etensor { * types used here and how they relate to at::Tensor. */ class Tensor { - public: +public: /// The type used for elements of `sizes()`. using SizesType = TensorImpl::SizesType; /// The type used for elements of `dim_order()`. @@ -36,7 +36,7 @@ class Tensor { using StridesType = TensorImpl::StridesType; Tensor() = delete; - explicit constexpr Tensor(TensorImpl* impl) : impl_(impl) {} + explicit constexpr Tensor(TensorImpl *impl) : impl_(impl) {} /** * Returns a pointer to the underlying TensorImpl. @@ -44,7 +44,7 @@ class Tensor { * NOTE: Clients should be wary of operating on the TensorImpl * directly instead of the Tensor. It is easy to break things. */ - TensorImpl* unsafeGetTensorImpl() const { + TensorImpl *unsafeGetTensorImpl() const { // TODO(T154114015): See if we can make this api private with friends. return impl_; } @@ -55,9 +55,7 @@ class Tensor { * NOTE: Only the alive space is returned not the total capacity of the * underlying data blob. */ - size_t nbytes() const { - return impl_->nbytes(); - } + size_t nbytes() const { return impl_->nbytes(); } /** * Returns the size of the tensor at the given dimension. @@ -67,86 +65,57 @@ class Tensor { * this method more compatible with at::Tensor, and more consistent with the * rest of the methods on this class and in ETensor. */ - ssize_t size(ssize_t dim) const { - return impl_->size(dim); - } + ssize_t size(ssize_t dim) const { return impl_->size(dim); } /// Returns the tensor's number of dimensions. - ssize_t dim() const { - return impl_->dim(); - } + ssize_t dim() const { return impl_->dim(); } /// Returns the number of elements in the tensor. - ssize_t numel() const { - return impl_->numel(); - } + ssize_t numel() const { return impl_->numel(); } /// Returns the type of the elements in the tensor (int32, float, bool, etc). - ScalarType scalar_type() const { - return impl_->scalar_type(); - } + ScalarType scalar_type() const { return impl_->scalar_type(); } - inline ScalarType dtype() const { - return scalar_type(); - } + inline ScalarType dtype() const { return scalar_type(); } /// Returns the size in bytes of one element of the tensor. - ssize_t element_size() const { - return impl_->element_size(); - } + ssize_t element_size() const { return impl_->element_size(); } /// Returns the sizes of the tensor at each dimension. - const ArrayRef sizes() const { - return impl_->sizes(); - } + const ArrayRef sizes() const { return impl_->sizes(); } /// Returns the order the dimensions are laid out in memory. - const ArrayRef dim_order() const { - return impl_->dim_order(); - } + const ArrayRef dim_order() const { return impl_->dim_order(); } /// Returns the strides of the tensor at each dimension. - const ArrayRef strides() const { - return impl_->strides(); - } + const ArrayRef strides() const { return impl_->strides(); } /// Returns the mutability of the shape of the tensor. - TensorShapeDynamism shape_dynamism() const { - return impl_->shape_dynamism(); - } + TensorShapeDynamism shape_dynamism() const { return impl_->shape_dynamism(); } /// Returns a pointer of type T to the constant underlying data blob. - template - inline const T* const_data_ptr() const { + template inline const T *const_data_ptr() const { return impl_->data(); } /// Returns a pointer to the constant underlying data blob. - inline const void* const_data_ptr() const { - return impl_->data(); - } + inline const void *const_data_ptr() const { return impl_->data(); } /// Returns a pointer of type T to the mutable underlying data blob. - template - inline T* mutable_data_ptr() const { + template inline T *mutable_data_ptr() const { return impl_->mutable_data(); } /// Returns a pointer to the mutable underlying data blob. - inline void* mutable_data_ptr() const { - return impl_->mutable_data(); - } + inline void *mutable_data_ptr() const { return impl_->mutable_data(); } /// DEPRECATED: Use const_data_ptr or mutable_data_ptr instead. - template - ET_DEPRECATED inline T* data_ptr() const { + template ET_DEPRECATED inline T *data_ptr() const { return impl_->mutable_data(); } /// DEPRECATED: Use const_data_ptr or mutable_data_ptr instead. - ET_DEPRECATED inline void* data_ptr() const { - return impl_->mutable_data(); - } + ET_DEPRECATED inline void *data_ptr() const { return impl_->mutable_data(); } /** * DEPRECATED: Changes the data_ptr the tensor aliases. Does not free the @@ -154,12 +123,10 @@ class Tensor { * ptr. This api does not exist in at::Tensor so kernel developers should * avoid it. */ - ET_DEPRECATED void set_data(void* ptr) const { - impl_->set_data(ptr); - } + ET_DEPRECATED void set_data(void *ptr) const { impl_->set_data(ptr); } - private: - TensorImpl* impl_ = nullptr; +private: + TensorImpl *impl_ = nullptr; }; } // namespace etensor diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h index fd2fd124..7357fffa 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h @@ -53,7 +53,7 @@ namespace etensor { * with `#ifdef USE_ATEN_LIB`. */ class TensorImpl { - public: +public: /** * The type used for elements of `sizes()`. * @@ -100,14 +100,10 @@ class TensorImpl { * entries. * @param dynamism The mutability of the shape of the tensor. */ - TensorImpl( - ScalarType type, - ssize_t dim, - SizesType* sizes, - void* data = nullptr, - DimOrderType* dim_order = nullptr, - StridesType* strides = nullptr, - TensorShapeDynamism dynamism = TensorShapeDynamism::STATIC); + TensorImpl(ScalarType type, ssize_t dim, SizesType *sizes, + void *data = nullptr, DimOrderType *dim_order = nullptr, + StridesType *strides = nullptr, + TensorShapeDynamism dynamism = TensorShapeDynamism::STATIC); /** * Returns the size of the tensor in bytes. @@ -126,32 +122,23 @@ class TensorImpl { * rest of the methods on this class and in ETensor. */ ssize_t size(ssize_t dim) const { - ET_CHECK_MSG( - dim < dim_ && dim >= 0, - "Dimension out of range (expected to be in range of [0, %zd], but got %zd", - dim_ - 1, - dim); + ET_CHECK_MSG(dim < dim_ && dim >= 0, + "Dimension out of range (expected to be in range of [0, %zd], " + "but got %zd", + dim_ - 1, dim); return sizes_[dim]; } /// Returns the tensor's number of dimensions. - ssize_t dim() const { - return dim_; - } + ssize_t dim() const { return dim_; } /// Returns the number of elements in the tensor. - ssize_t numel() const { - return numel_; - } + ssize_t numel() const { return numel_; } /// Returns the type of the elements in the tensor (int32, float, bool, etc). - ScalarType scalar_type() const { - return type_; - } + ScalarType scalar_type() const { return type_; } - inline ScalarType dtype() const { - return scalar_type(); - } + inline ScalarType dtype() const { return scalar_type(); } /// Returns the size in bytes of one element of the tensor. ssize_t element_size() const; @@ -172,36 +159,26 @@ class TensorImpl { } /// Returns the mutability of the shape of the tensor. - TensorShapeDynamism shape_dynamism() const { - return shape_dynamism_; - } + TensorShapeDynamism shape_dynamism() const { return shape_dynamism_; } /// Returns a pointer of type T to the constant underlying data blob. - template - inline const T* data() const { - return static_cast(data()); + template inline const T *data() const { + return static_cast(data()); } /// Returns a pointer to the constant underlying data blob. - const void* data() const { - return data_; - } + const void *data() const { return data_; } /// Returns a pointer of type T to the mutable underlying data blob. - template - inline T* mutable_data() const { - return static_cast(mutable_data()); + template inline T *mutable_data() const { + return static_cast(mutable_data()); } /// Returns a pointer to the mutable underlying data blob. - void* mutable_data() const { - return data_; - } + void *mutable_data() const { return data_; } /// Sets the underlying data blob to the passed in pointer. - void set_data(void* ptr) { - data_ = ptr; - } + void set_data(void *ptr) { data_ = ptr; } /* * DEPRECATED: Use torch::executor::resize_tensor() or @@ -210,11 +187,11 @@ class TensorImpl { ET_DEPRECATED void set_sizes_contiguous(ArrayRef new_sizes) { Error err = internal_resize_contiguous(new_sizes); - ET_CHECK_MSG( - err == Error::Ok, "Could not resize Tensor; see logs for details"); + ET_CHECK_MSG(err == Error::Ok, + "Could not resize Tensor; see logs for details"); } - private: +private: // For access to internal_resize_contiguous(). friend class ::executorch::runtime::internal::TensorResizerFriend; @@ -231,20 +208,20 @@ class TensorImpl { */ ET_NODISCARD Error internal_resize_contiguous(ArrayRef new_sizes); - private: +private: // Keep fields arranged to avoid unnecessary alignment holes. /// List of sizes of each dimension in the tensor. - SizesType* sizes_; + SizesType *sizes_; /// List of the order that dimensions are laid out in memory. - DimOrderType* dim_order_; + DimOrderType *dim_order_; // TODO(T148356881): Get rid of strides from ETensor - StridesType* strides_; + StridesType *strides_; /// Pointer to underlying data blob. NOTE: Can be null. - void* data_; + void *data_; /// Tensor's number of dimensions. const ssize_t dim_; @@ -267,7 +244,7 @@ class TensorImpl { * Compute the number of elements based on the sizes of a tensor. */ ssize_t compute_numel( - const ::executorch::runtime::etensor::TensorImpl::SizesType* sizes, + const ::executorch::runtime::etensor::TensorImpl::SizesType *sizes, ssize_t dim); } // namespace etensor diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h index 7b404bca..00cc7bb8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h @@ -45,9 +45,8 @@ namespace runtime { * } * @endcode */ -template -class Result final { - public: +template class Result final { +public: /// `value_type` member for generic programming. typedef T value_type; @@ -59,17 +58,17 @@ class Result final { * a non-Ok value. */ /* implicit */ Result(Error error) - : error_(error == Error::Ok ? Error::Internal : error), - hasValue_(false) {} + : error_(error == Error::Ok ? Error::Internal : error), hasValue_(false) { + } /// Value copy constructor. - /* implicit */ Result(const T& val) : value_(val), hasValue_(true) {} + /* implicit */ Result(const T &val) : value_(val), hasValue_(true) {} /// Value move constructor. - /* implicit */ Result(T&& val) : value_(std::move(val)), hasValue_(true) {} + /* implicit */ Result(T &&val) : value_(std::move(val)), hasValue_(true) {} /// Result move constructor. - /* implicit */ Result(Result&& rhs) noexcept : hasValue_(rhs.hasValue_) { + /* implicit */ Result(Result &&rhs) noexcept : hasValue_(rhs.hasValue_) { if (hasValue_) { // Use the value type's move constructor. new (&value_) T(std::move(rhs.value_)); @@ -92,9 +91,7 @@ class Result final { * If true, it is guaranteed that `error()` will return `Error::Ok`. * If false, it is guaranteed that `error()` will not return `Error::Ok`. */ - ET_NODISCARD bool ok() const { - return hasValue_; - } + ET_NODISCARD bool ok() const { return hasValue_; } /** * Returns the error code of this Result. @@ -116,7 +113,7 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - T& get() { + T &get() { CheckOk(); return value_; } @@ -126,7 +123,7 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - const T& get() const { + const T &get() const { CheckOk(); return value_; } @@ -136,37 +133,35 @@ class Result final { * * Only legal to call if `ok()` returns true. */ - const T& operator*() const&; - T& operator*() &; + const T &operator*() const &; + T &operator*() &; /* * Returns a pointer to the Result's value. * * Only legal to call if `ok()` returns true. */ - const T* operator->() const; - T* operator->(); + const T *operator->() const; + T *operator->(); - private: +private: /** * Delete default constructor since all Results should contain a value or * error. */ Result() = delete; /// Delete copy constructor since T may not be copyable. - Result(const Result&) = delete; + Result(const Result &) = delete; /// Delete copy assignment since T may not be copyable. - Result& operator=(const Result&) = delete; + Result &operator=(const Result &) = delete; /// Delete move assignment since it's not a supported pattern to reuse Result. - Result& operator=(Result&& rhs) = delete; + Result &operator=(Result &&rhs) = delete; // Panics if ok() would return false; - void CheckOk() const { - ET_CHECK(hasValue_); - } + void CheckOk() const { ET_CHECK(hasValue_); } union { - T value_; // Used if hasValue_ is true. + T value_; // Used if hasValue_ is true. Error error_; // Used if hasValue_ is false. }; @@ -174,26 +169,22 @@ class Result final { const bool hasValue_; }; -template -const T& Result::operator*() const& { +template const T &Result::operator*() const & { CheckOk(); return value_; } -template -T& Result::operator*() & { +template T &Result::operator*() & { CheckOk(); return value_; } -template -const T* Result::operator->() const { +template const T *Result::operator->() const { CheckOk(); return &value_; } -template -T* Result::operator->() { +template T *Result::operator->() { CheckOk(); return &value_; } @@ -222,34 +213,34 @@ using ::executorch::runtime::Result; #define ET_UNWRAP(result__, ...) ET_INTERNAL_UNWRAP(result__, ##__VA_ARGS__) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP(...) \ - ET_INTERNAL_UNWRAP_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ +#define ET_INTERNAL_UNWRAP(...) \ + ET_INTERNAL_UNWRAP_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) \ (__VA_ARGS__) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_SELECT( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) \ +#define ET_INTERNAL_UNWRAP_SELECT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, \ + ...) \ ET_INTERNAL_UNWRAP_##N // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_1(result__) \ - ({ \ - auto et_result__ = (result__); \ - if (!et_result__.ok()) { \ - return et_result__.error(); \ - } \ - std::move(*et_result__); \ +#define ET_INTERNAL_UNWRAP_1(result__) \ + ({ \ + auto et_result__ = (result__); \ + if (!et_result__.ok()) { \ + return et_result__.error(); \ + } \ + std::move(*et_result__); \ }) // Internal only: Use ET_UNWRAP() instead. -#define ET_INTERNAL_UNWRAP_2(result__, message__, ...) \ - ({ \ - auto et_result__ = (result__); \ - if (!et_result__.ok()) { \ - ET_LOG(Error, message__, ##__VA_ARGS__); \ - return et_result__.error(); \ - } \ - std::move(*et_result__); \ +#define ET_INTERNAL_UNWRAP_2(result__, message__, ...) \ + ({ \ + auto et_result__ = (result__); \ + if (!et_result__.ok()) { \ + ET_LOG(Error, message__, ##__VA_ARGS__); \ + return et_result__.error(); \ + } \ + std::move(*et_result__); \ }) // Internal only: Use ET_UNWRAP() instead. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h index b671f340..903a6d27 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h @@ -32,62 +32,49 @@ namespace runtime { * This is intended to be trivially copyable, so it should be passed by * value. */ -template -class Span final { - public: - using iterator = T*; +template class Span final { +public: + using iterator = T *; using size_type = size_t; - public: +public: /// Construct an empty Span. /* implicit */ constexpr Span() noexcept : data_(nullptr), length_(0) {} /// Construct a Span from a pointer and length. - Span(T* data, size_t length) : data_(data), length_(length) { + Span(T *data, size_t length) : data_(data), length_(length) { ET_DCHECK(data_ != nullptr || length_ == 0); } /// Construct a Span from a range. - Span(T* begin, T* end) : data_(begin), length_(end - begin) {} + Span(T *begin, T *end) : data_(begin), length_(end - begin) {} /// Construct a Span from a C array. template /* implicit */ constexpr Span(T (&Arr)[N]) : data_(Arr), length_(N) {} /// @returns a pointer to the start of the underlying element buffer. - iterator begin() const noexcept { - return data_; - } + iterator begin() const noexcept { return data_; } /// @returns a pointer to the end of the underlying element buffer. - iterator end() const noexcept { - return data_ + length_; - } + iterator end() const noexcept { return data_ + length_; } /// @retval a boolean indicating if the Span is empty. - constexpr bool empty() const noexcept { - return length_ == 0; - } + constexpr bool empty() const noexcept { return length_ == 0; } /// @returns a pointer to the start of the underlying element buffer. - constexpr T* data() const noexcept { - return data_; - } + constexpr T *data() const noexcept { return data_; } /// @returns the number of elements in the Span. - constexpr size_t size() const noexcept { - return length_; - } + constexpr size_t size() const noexcept { return length_; } /// Unchecked index into the array according to the argument index. /// @returns a reference to the element at the specified index. - T& operator[](size_t index) const { - return data_[index]; - } + T &operator[](size_t index) const { return data_[index]; } - private: +private: /// The start of the array, in an external buffer. - T* data_; + T *data_; /// The number of elements. size_type length_; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h index 7dda80dd..8c329105 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h @@ -13,18 +13,18 @@ namespace executorch { namespace runtime { -#define EXECUTORCH_FORALL_TAGS(_) \ - _(None) \ - _(Tensor) \ - _(String) \ - _(Double) \ - _(Int) \ - _(Bool) \ - _(ListBool) \ - _(ListDouble) \ - _(ListInt) \ - _(ListTensor) \ - _(ListScalar) \ +#define EXECUTORCH_FORALL_TAGS(_) \ + _(None) \ + _(Tensor) \ + _(String) \ + _(Double) \ + _(Int) \ + _(Bool) \ + _(ListBool) \ + _(ListDouble) \ + _(ListInt) \ + _(ListTensor) \ + _(ListScalar) \ _(ListOptionalTensor) /** diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h index 1d3d7a6f..674d7022 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h @@ -28,7 +28,7 @@ namespace runtime { * and kernels use these provided allocators whenever possible. */ class MemoryManager final { - public: +public: /** * Constructs a new MemoryManager. * @@ -49,16 +49,13 @@ class MemoryManager final { * delegates that allocate temporary data. This allocator will be reset * after every kernel or delegate call during execution. */ - explicit MemoryManager( - MemoryAllocator* method_allocator, - HierarchicalAllocator* planned_memory = nullptr, - MemoryAllocator* temp_allocator = nullptr) - : method_allocator_(method_allocator), - planned_memory_(planned_memory), + explicit MemoryManager(MemoryAllocator *method_allocator, + HierarchicalAllocator *planned_memory = nullptr, + MemoryAllocator *temp_allocator = nullptr) + : method_allocator_(method_allocator), planned_memory_(planned_memory), temp_allocator_(temp_allocator) { - ET_CHECK_MSG( - method_allocator != temp_allocator, - "method allocator cannot be the same as temp allocator"); + ET_CHECK_MSG(method_allocator != temp_allocator, + "method allocator cannot be the same as temp allocator"); } /** @@ -71,10 +68,9 @@ class MemoryManager final { // bug that triggers a syntax error when using [[maybe_unused]] on the // first parameter of a constructor: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 - __attribute__((unused)) MemoryAllocator* constant_allocator, - HierarchicalAllocator* non_constant_allocator, - MemoryAllocator* runtime_allocator, - MemoryAllocator* temporary_allocator) + __attribute__((unused)) MemoryAllocator *constant_allocator, + HierarchicalAllocator *non_constant_allocator, + MemoryAllocator *runtime_allocator, MemoryAllocator *temporary_allocator) : MemoryManager( /*method_allocator=*/runtime_allocator, /*planned_memory=*/non_constant_allocator, @@ -85,16 +81,12 @@ class MemoryManager final { * structures while loading a Method. Must not be used after its associated * Method has been loaded. */ - MemoryAllocator* method_allocator() const { - return method_allocator_; - } + MemoryAllocator *method_allocator() const { return method_allocator_; } /** * Returns the memory-planned buffers to use for mutable tensor data. */ - HierarchicalAllocator* planned_memory() const { - return planned_memory_; - } + HierarchicalAllocator *planned_memory() const { return planned_memory_; } /** * Returns the allocator to use for allocating temporary data during kernel or @@ -103,14 +95,12 @@ class MemoryManager final { * This allocator will be reset after every kernel or delegate call during * execution. */ - MemoryAllocator* temp_allocator() const { - return temp_allocator_; - } + MemoryAllocator *temp_allocator() const { return temp_allocator_; } - private: - MemoryAllocator* method_allocator_; - HierarchicalAllocator* planned_memory_; - MemoryAllocator* temp_allocator_; +private: + MemoryAllocator *method_allocator_; + HierarchicalAllocator *planned_memory_; + MemoryAllocator *temp_allocator_; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h index 8b3330fb..06aaf5a8 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h @@ -34,35 +34,30 @@ class Program; class BackendDelegate; struct Chain; class KernelRuntimeContext; -using OpFunction = void (*)(KernelRuntimeContext&, EValue**); +using OpFunction = void (*)(KernelRuntimeContext &, EValue **); /// A list of pointers into the master values table that together compose the /// argument list for a single instruction -using InstructionArgs = Span; +using InstructionArgs = Span; /** * An executable method of an executorch program. Maps to a python method like * `forward()` on the original nn.Module. */ class Method final { - public: +public: /** * Move ctor. Takes ownership of resources previously owned by `rhs`, * and leaves `rhs` in an uninitialized state. */ - Method(Method&& rhs) noexcept - : step_state_(rhs.step_state_), - program_(rhs.program_), + Method(Method &&rhs) noexcept + : step_state_(rhs.step_state_), program_(rhs.program_), memory_manager_(rhs.memory_manager_), temp_allocator_(rhs.temp_allocator_), serialization_plan_(rhs.serialization_plan_), - event_tracer_(rhs.event_tracer_), - n_value_(rhs.n_value_), - values_(rhs.values_), - n_delegate_(rhs.n_delegate_), - delegates_(rhs.delegates_), - n_chains_(rhs.n_chains_), - chains_(rhs.chains_), - init_state_(rhs.init_state_) { + event_tracer_(rhs.event_tracer_), n_value_(rhs.n_value_), + values_(rhs.values_), n_delegate_(rhs.n_delegate_), + delegates_(rhs.delegates_), n_chains_(rhs.n_chains_), + chains_(rhs.chains_), init_state_(rhs.init_state_) { // Required: clear out fields that the dtor looks at, so that we don't free // anything twice. rhs.n_value_ = 0; @@ -100,7 +95,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error set_input(const EValue& input_evalue, size_t input_idx); + ET_NODISCARD Error set_input(const EValue &input_evalue, size_t input_idx); /** * Sets the values of all method inputs. @@ -115,7 +110,7 @@ class Method final { * @returns Error::Ok on success, non-Ok on failure. */ ET_NODISCARD Error - set_inputs(const executorch::aten::ArrayRef& input_evalues); + set_inputs(const executorch::aten::ArrayRef &input_evalues); /** * Sets the data buffer of the specified method output to the provided value. @@ -136,8 +131,8 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error - set_output_data_ptr(void* buffer, size_t size, size_t output_idx); + ET_NODISCARD Error set_output_data_ptr(void *buffer, size_t size, + size_t output_idx); /** * Copies the method's outputs into the provided array. @@ -156,7 +151,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error get_outputs(EValue* output_evalues, size_t length); + ET_NODISCARD Error get_outputs(EValue *output_evalues, size_t length); /** * Copies the method's inputs into the provided array. @@ -172,7 +167,7 @@ class Method final { * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error get_inputs(EValue* input_evalues, size_t length); + ET_NODISCARD Error get_inputs(EValue *input_evalues, size_t length); /** * Execute the method. @@ -228,27 +223,27 @@ class Method final { /** * Retrieves the output at the specified index. */ - const EValue& get_output(size_t i) const; + const EValue &get_output(size_t i) const; - EventTracer* get_event_tracer(); + EventTracer *get_event_tracer(); /// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to /// update Method inputs. - ET_DEPRECATED const EValue& get_input(size_t i) const; + ET_DEPRECATED const EValue &get_input(size_t i) const; /// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to /// update Method inputs. - ET_DEPRECATED EValue& mutable_input(size_t i); + ET_DEPRECATED EValue &mutable_input(size_t i); /// DEPRECATED: Use MethodMeta instead to access metadata, and get_output to /// retrieve Method outputs. - ET_DEPRECATED EValue& mutable_output(size_t i); + ET_DEPRECATED EValue &mutable_output(size_t i); ~Method(); - private: +private: // Delete other rule-of-five methods. - Method(const Method&) = delete; - Method& operator=(const Method&) noexcept = delete; - Method& operator=(Method&&) = delete; + Method(const Method &) = delete; + Method &operator=(const Method &) noexcept = delete; + Method &operator=(Method &&) = delete; // Let Program call load(). friend class Program; @@ -267,46 +262,33 @@ class Method final { size_t instr_idx; }; - Method( - const Program* program, - MemoryManager* memory_manager, - EventTracer* event_tracer, - MemoryAllocator* temp_allocator) - : step_state_(), - program_(program), - memory_manager_(memory_manager), - temp_allocator_(temp_allocator), - serialization_plan_(nullptr), - event_tracer_(event_tracer), - n_value_(0), - values_(nullptr), - n_delegate_(0), - delegates_(nullptr), - n_chains_(0), - chains_(nullptr), + Method(const Program *program, MemoryManager *memory_manager, + EventTracer *event_tracer, MemoryAllocator *temp_allocator) + : step_state_(), program_(program), memory_manager_(memory_manager), + temp_allocator_(temp_allocator), serialization_plan_(nullptr), + event_tracer_(event_tracer), n_value_(0), values_(nullptr), + n_delegate_(0), delegates_(nullptr), n_chains_(0), chains_(nullptr), init_state_(InitializationState::Uninitialized) {} /// Static factory used by Program. - ET_NODISCARD static Result load( - executorch_flatbuffer::ExecutionPlan* s_plan, - const Program* program, - MemoryManager* memory_manager, - EventTracer* event_tracer); + ET_NODISCARD static Result + load(executorch_flatbuffer::ExecutionPlan *s_plan, const Program *program, + MemoryManager *memory_manager, EventTracer *event_tracer); /** * Initialize the method from its serialized representation. * * @returns Error::Ok on success, non-Ok on failure. */ - ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan* s_plan); + ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan *s_plan); /// Returns true if the Method was successfully initialized. inline bool initialized() const { return init_state_ == InitializationState::Initialized; } - const EValue& get_value(size_t i) const; - EValue& mutable_value(size_t i); + const EValue &get_value(size_t i) const; + EValue &mutable_value(size_t i); size_t get_input_index(size_t i) const; size_t get_output_index(size_t i) const; @@ -314,20 +296,20 @@ class Method final { ET_NODISCARD Error execute_instruction(); StepState step_state_; - const Program* program_; - MemoryManager* memory_manager_; - MemoryAllocator* temp_allocator_; - executorch_flatbuffer::ExecutionPlan* serialization_plan_; - EventTracer* event_tracer_; + const Program *program_; + MemoryManager *memory_manager_; + MemoryAllocator *temp_allocator_; + executorch_flatbuffer::ExecutionPlan *serialization_plan_; + EventTracer *event_tracer_; size_t n_value_; - EValue* values_; + EValue *values_; size_t n_delegate_; - BackendDelegate* delegates_; + BackendDelegate *delegates_; size_t n_chains_; - Chain* chains_; + Chain *chains_; InitializationState init_state_; @@ -338,12 +320,9 @@ class Method final { */ ET_NODISCARD Error parse_values(); - ET_NODISCARD Error resolve_operator( - int32_t op_index, - OpFunction* kernels, - size_t kernel_index, - InstructionArgs args, - size_t n_args); + ET_NODISCARD Error resolve_operator(int32_t op_index, OpFunction *kernels, + size_t kernel_index, InstructionArgs args, + size_t n_args); void log_outputs(); }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h index 569b93c0..08644d20 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h @@ -29,12 +29,12 @@ namespace runtime { * TensorInfo must outlive this TensorInfo. */ class TensorInfo final { - public: +public: TensorInfo() = delete; - TensorInfo(const TensorInfo&) = default; - TensorInfo(TensorInfo&&) = default; - TensorInfo& operator=(const TensorInfo&) = default; - TensorInfo& operator=(TensorInfo&& other) = default; + TensorInfo(const TensorInfo &) = default; + TensorInfo(TensorInfo &&) = default; + TensorInfo &operator=(const TensorInfo &) = default; + TensorInfo &operator=(TensorInfo &&other) = default; ~TensorInfo() = default; /** @@ -62,15 +62,13 @@ class TensorInfo final { */ size_t nbytes() const; - private: +private: // Let MethodMeta create TensorInfo. friend class MethodMeta; - TensorInfo( - Span sizes, - Span dim_order, - executorch::aten::ScalarType scalar_type, - const bool is_memory_planned); + TensorInfo(Span sizes, Span dim_order, + executorch::aten::ScalarType scalar_type, + const bool is_memory_planned); /** * The sizes of the tensor. @@ -106,12 +104,12 @@ class TensorInfo final { * paying the initialization cost of loading the full Method. */ class MethodMeta final { - public: +public: MethodMeta() = delete; - MethodMeta(const MethodMeta&) = default; - MethodMeta(MethodMeta&&) = default; - MethodMeta& operator=(const MethodMeta&) = default; - MethodMeta& operator=(MethodMeta&& other) = default; + MethodMeta(const MethodMeta &) = default; + MethodMeta(MethodMeta &&) = default; + MethodMeta &operator=(const MethodMeta &) = default; + MethodMeta &operator=(MethodMeta &&other) = default; ~MethodMeta() = default; /** @@ -119,7 +117,7 @@ class MethodMeta final { * * @returns The method name. */ - const char* name() const; + const char *name() const; /** * Get the number of inputs to this method. @@ -199,14 +197,14 @@ class MethodMeta final { return memory_planned_buffer_size(index); } - private: +private: // Let Program create MethodMeta. friend class Program; - explicit MethodMeta(const executorch_flatbuffer::ExecutionPlan* s_plan); + explicit MethodMeta(const executorch_flatbuffer::ExecutionPlan *s_plan); /// Source of truth for method information - const executorch_flatbuffer::ExecutionPlan* s_plan_; + const executorch_flatbuffer::ExecutionPlan *s_plan_; }; } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h index f7469eb2..3c4e30ef 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h @@ -44,7 +44,7 @@ class TensorParser; * A deserialized ExecuTorch program binary. */ class Program final { - public: +public: /** * Types of validation that the Program can do before parsing the data. */ @@ -78,19 +78,17 @@ class Program final { * @param[in] verification The type of verification to do before returning * success. */ - ET_NODISCARD static Result load( - DataLoader* loader, - Verification verification = Verification::Minimal); + ET_NODISCARD static Result + load(DataLoader *loader, Verification verification = Verification::Minimal); /// DEPRECATED: Use the lowercase `load()` instead. - ET_DEPRECATED ET_NODISCARD static Result Load( - DataLoader* loader, - Verification verification = Verification::Minimal) { + ET_DEPRECATED ET_NODISCARD static Result + Load(DataLoader *loader, Verification verification = Verification::Minimal) { return load(loader, verification); } // Movable, to be compatible with Result. - Program(Program&&) noexcept = default; + Program(Program &&) noexcept = default; ~Program() = default; /** @@ -99,8 +97,8 @@ class Program final { * @param[in] nbytes the number of bytes to read from the buffer. * @return The buffer with corresponding index. */ - Result get_constant_buffer_data(size_t buffer_idx, size_t nbytes) - const; + Result get_constant_buffer_data(size_t buffer_idx, + size_t nbytes) const; /** * Returns the number of methods in the program. @@ -116,7 +114,7 @@ class Program final { * @returns The name of the requested method. The pointer is owned by the * Program, and has the same lifetime as the Program. */ - Result get_method_name(size_t method_index) const; + Result get_method_name(size_t method_index) const; /** * Loads the named method and prepares it for execution. @@ -129,17 +127,16 @@ class Program final { * * @returns The loaded method on success, or an error on failure. */ - Result load_method( - const char* method_name, - MemoryManager* memory_manager, - EventTracer* event_tracer = nullptr) const; + Result load_method(const char *method_name, + MemoryManager *memory_manager, + EventTracer *event_tracer = nullptr) const; /** * Gathers metadata for the named method. * * @param[in] method_name The name of the method to get metadata for. */ - Result method_meta(const char* method_name) const; + Result method_meta(const char *method_name) const; /** * DEPRECATED: Get the pytree encoding string for the output. Deprecated as @@ -149,8 +146,8 @@ class Program final { * * @return The pytree encoding string for the output */ - ET_DEPRECATED Result get_output_flattening_encoding( - const char* method_name = "forward") const; + ET_DEPRECATED Result + get_output_flattening_encoding(const char *method_name = "forward") const; /** * Describes the presence of an ExecuTorch program header. @@ -193,9 +190,9 @@ class Program final { * * @returns A value describing the presence of a header in the data. */ - static HeaderStatus check_header(const void* data, size_t size); + static HeaderStatus check_header(const void *data, size_t size); - private: +private: // Let some classes call these private methods. friend class BackendDelegate; friend class Executor; @@ -203,15 +200,13 @@ class Program final { friend class deserialization::TensorParser; friend class testing::ProgramTestFriend; - const executorch_flatbuffer::Program* get_internal_program() const { + const executorch_flatbuffer::Program *get_internal_program() const { return internal_program_; } // Used by Method to look up entries in the delegate data table. - Error get_backend_delegate_data( - size_t index, - const void** out_data, - size_t* out_size) const; + Error get_backend_delegate_data(size_t index, const void **out_data, + size_t *out_size) const; /** * Loads a segment by index. @@ -227,8 +222,8 @@ class Program final { * DataLoader: The Program.segment table is inconsistent, or the * data cannot be accessed. */ - ET_NODISCARD Result LoadSegment( - const DataLoader::SegmentInfo& segment_info) const; + ET_NODISCARD Result + LoadSegment(const DataLoader::SegmentInfo &segment_info) const; /** * Loads a portion of a mutable segment into the provided buffer. @@ -249,18 +244,14 @@ class Program final { * data cannot be accessed. */ ET_NODISCARD Error load_mutable_subsegment_into( - size_t mutable_data_segments_index, - size_t offset_index, - size_t size, - void* buffer) const; - - private: - Program( - DataLoader* loader, - size_t segment_base_offset, - FreeableBuffer&& program_data, - const executorch_flatbuffer::Program* internal_program, - FreeableBuffer&& constant_segment_data) + size_t mutable_data_segments_index, size_t offset_index, size_t size, + void *buffer) const; + +private: + Program(DataLoader *loader, size_t segment_base_offset, + FreeableBuffer &&program_data, + const executorch_flatbuffer::Program *internal_program, + FreeableBuffer &&constant_segment_data) : program_data_(std::move(program_data)), // Don't need the loader if there are no segments. loader_(segment_base_offset > 0 ? loader : nullptr), @@ -269,19 +260,19 @@ class Program final { constant_segment_data_(std::move(constant_segment_data)) {} // Not copyable or assignable. - Program(const Program& rhs) = delete; - Program& operator=(Program&& rhs) noexcept = delete; - Program& operator=(const Program& rhs) = delete; + Program(const Program &rhs) = delete; + Program &operator=(Program &&rhs) noexcept = delete; + Program &operator=(const Program &rhs) = delete; /// The serialized program data. Tensors will point directly into this buffer. FreeableBuffer program_data_; /// Used to load segment data. Null if there are no segments. - DataLoader* loader_; + DataLoader *loader_; /// The flatbuffer representation of the program. Must not be exposed to /// users. - const executorch_flatbuffer::Program* internal_program_; + const executorch_flatbuffer::Program *internal_program_; /// The offset to the first segment, in bytes. If zero, no segments should /// be present in internal_program_. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h index 1d860bfc..cd6e89e9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h @@ -18,31 +18,26 @@ namespace executorch { namespace runtime { namespace deserialization { -ET_NODISCARD Result parseTensor( - const Program* program, - MemoryManager* memory_manager, - const executorch_flatbuffer::Tensor* s_tensor); +ET_NODISCARD Result +parseTensor(const Program *program, MemoryManager *memory_manager, + const executorch_flatbuffer::Tensor *s_tensor); -ET_NODISCARD Result> parseTensorList( - const flatbuffers::Vector* tensor_indices, - EValue* values_, - MemoryManager* memory_manager); +ET_NODISCARD Result> +parseTensorList(const flatbuffers::Vector *tensor_indices, + EValue *values_, MemoryManager *memory_manager); // Deserializes a List of optional type. The code here is the same between all // list of optionals: list of optional Tensor, list of optional float etc, so we // just use a template to avoid boilerplate. template ET_NODISCARD Result>> -parseListOptionalType( - const flatbuffers::Vector* value_indices, - EValue* values_, - MemoryManager* memory_manager) { - auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( - memory_manager->method_allocator(), EValue*, value_indices->size()); +parseListOptionalType(const flatbuffers::Vector *value_indices, + EValue *values_, MemoryManager *memory_manager) { + auto *evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( + memory_manager->method_allocator(), EValue *, value_indices->size()); - auto* optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( - memory_manager->method_allocator(), - executorch::aten::optional, + auto *optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR( + memory_manager->method_allocator(), executorch::aten::optional, value_indices->size()); size_t output_idx = 0; @@ -92,11 +87,10 @@ parseListOptionalType( * @returns On success, the data pointer to use for the tensor. On failure, a * non-Ok Error. */ -ET_NODISCARD Result getTensorDataPtr( - const executorch_flatbuffer::Tensor* s_tensor, - const Program* program, - size_t nbytes, - HierarchicalAllocator* allocator); +ET_NODISCARD Result +getTensorDataPtr(const executorch_flatbuffer::Tensor *s_tensor, + const Program *program, size_t nbytes, + HierarchicalAllocator *allocator); } // namespace deserialization } // namespace runtime diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h index 96ad3d51..e6367da9 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h @@ -24,7 +24,7 @@ namespace runtime { * operators do not expect to receive a KernelRuntimeContext argument. */ class KernelRuntimeContext { - public: +public: /** * Construct a new kernel runtime context. * @@ -37,9 +37,8 @@ class KernelRuntimeContext { * temporary memory for the kernel. If not provided, an error will be * returned when calling allocate_temp. */ - KernelRuntimeContext( - EventTracer* event_tracer = nullptr, - MemoryAllocator* temp_allocator = nullptr) + KernelRuntimeContext(EventTracer *event_tracer = nullptr, + MemoryAllocator *temp_allocator = nullptr) : event_tracer_(event_tracer), temp_allocator_(temp_allocator) {} /** * Tells the runtime that the kernel call has failed. Prefer this over @@ -53,14 +52,10 @@ class KernelRuntimeContext { * compatible with core PyTorch ATen kernel signatures, which use exceptions * to report errors. But, ExecuTorch does not use exceptions. */ - void fail(Error error) { - failure_state_ = error; - } + void fail(Error error) { failure_state_ = error; } /// Returns the current failure state. - ET_NODISCARD Error failure_state() const { - return failure_state_; - } + ET_NODISCARD Error failure_state() const { return failure_state_; } /** * INTERNAL ONLY @@ -69,9 +64,7 @@ class KernelRuntimeContext { * logging inside the codegen layer. This is only for internal usage inside * the codegen layer and users should not be accessing this. */ - EventTracer* internal_event_tracer() { - return event_tracer_; - } + EventTracer *internal_event_tracer() { return event_tracer_; } /** * Allocates temporary memory that will be freed when the kernel returns. This @@ -85,25 +78,23 @@ class KernelRuntimeContext { * @returns A result object containing either a pointer to the allocated * memory or an error to indicate failure */ - Result allocate_temp( - size_t size, - size_t alignment = MemoryAllocator::kDefaultAlignment) { - ET_CHECK_OR_RETURN_ERROR( - temp_allocator_ != nullptr, NotFound, "No temp allocator provided"); - void* temp_memory = temp_allocator_->allocate(size, alignment); + Result + allocate_temp(size_t size, + size_t alignment = MemoryAllocator::kDefaultAlignment) { + ET_CHECK_OR_RETURN_ERROR(temp_allocator_ != nullptr, NotFound, + "No temp allocator provided"); + void *temp_memory = temp_allocator_->allocate(size, alignment); ET_CHECK_OR_RETURN_ERROR( - temp_memory != nullptr, - MemoryAllocationFailed, - "Failed to allocate temp memory. Bytes requested: %zu", - size); + temp_memory != nullptr, MemoryAllocationFailed, + "Failed to allocate temp memory. Bytes requested: %zu", size); return temp_memory; } // TODO(T147221312): Add a way to resize a tensor. - private: - EventTracer* event_tracer_ = nullptr; - MemoryAllocator* temp_allocator_ = nullptr; +private: + EventTracer *event_tracer_ = nullptr; + MemoryAllocator *temp_allocator_ = nullptr; Error failure_state_ = Error::Ok; }; diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h index e4c5d670..095a6742 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h @@ -24,26 +24,23 @@ #include #endif -#define ET_LOG_KERNEL_KEY(k) \ - ET_LOG( \ - Error, \ - "key: %s, is_fallback: %s", \ - k.data(), \ - k.is_fallback() ? "true" : "false"); -#define ET_LOG_TENSOR_META(meta_list) \ - for (const auto& meta : meta_list) { \ - ET_LOG(Error, "dtype: %d | dim order: [", int(meta.dtype_)); \ - for (int i = 0; i < meta.dim_order_.size(); i++) { \ - ET_LOG(Error, "%d,", static_cast(meta.dim_order_[i])); \ - } \ - ET_LOG(Error, "]"); \ +#define ET_LOG_KERNEL_KEY(k) \ + ET_LOG(Error, "key: %s, is_fallback: %s", k.data(), \ + k.is_fallback() ? "true" : "false"); +#define ET_LOG_TENSOR_META(meta_list) \ + for (const auto &meta : meta_list) { \ + ET_LOG(Error, "dtype: %d | dim order: [", int(meta.dtype_)); \ + for (int i = 0; i < meta.dim_order_.size(); i++) { \ + ET_LOG(Error, "%d,", static_cast(meta.dim_order_[i])); \ + } \ + ET_LOG(Error, "]"); \ } namespace executorch { namespace runtime { class KernelRuntimeContext; // Forward declaration -using OpFunction = void (*)(KernelRuntimeContext&, EValue**); +using OpFunction = void (*)(KernelRuntimeContext &, EValue **); /** * Dtype and dim order metadata for a Tensor argument to an operator. @@ -54,20 +51,17 @@ struct TensorMeta { Span dim_order_; TensorMeta() = default; - TensorMeta( - executorch::aten::ScalarType dtype, - Span order) + TensorMeta(executorch::aten::ScalarType dtype, + Span order) : dtype_(dtype), dim_order_(order) {} - bool operator==(const TensorMeta& other) const { - return this->equals(other); - } + bool operator==(const TensorMeta &other) const { return this->equals(other); } - bool operator!=(const TensorMeta& other) const { + bool operator!=(const TensorMeta &other) const { return !this->equals(other); } - bool equals(const TensorMeta& other) const { + bool equals(const TensorMeta &other) const { if (dtype_ != other.dtype_) { return false; } @@ -83,7 +77,7 @@ struct TensorMeta { } #if defined(ET_OP_REGISTRY_DEBUG) - friend std::ostream& operator<<(std::ostream& os, const TensorMeta& meta) { + friend std::ostream &operator<<(std::ostream &os, const TensorMeta &meta) { os << "dtype: " << int(meta.dtype_) << " | dim order: ["; for (int i = 0; i < meta.dim_order_.size(); i++) { os << static_cast(meta.dim_order_[i]) << ", "; @@ -121,23 +115,19 @@ struct TensorMeta { * generated from kernel yaml. */ struct KernelKey { - public: +public: KernelKey() : is_fallback_(true) {} - /* implicit */ KernelKey(const char* kernel_key_data) + /* implicit */ KernelKey(const char *kernel_key_data) : kernel_key_data_(kernel_key_data), is_fallback_(false) {} constexpr static int MAX_SIZE = 691; - bool operator==(const KernelKey& other) const { - return this->equals(other); - } + bool operator==(const KernelKey &other) const { return this->equals(other); } - bool operator!=(const KernelKey& other) const { - return !this->equals(other); - } + bool operator!=(const KernelKey &other) const { return !this->equals(other); } - bool equals(const KernelKey& other) const { + bool equals(const KernelKey &other) const { if (is_fallback_ != other.is_fallback_) { return false; } @@ -147,23 +137,19 @@ struct KernelKey { return strncmp(kernel_key_data_, other.kernel_key_data_, MAX_SIZE) == 0; } - bool is_fallback() const { - return is_fallback_; - } + bool is_fallback() const { return is_fallback_; } - const char* data() const { - return kernel_key_data_; - } + const char *data() const { return kernel_key_data_; } #if defined(ET_OP_REGISTRY_DEBUG) - friend std::ostream& operator<<(std::ostream& os, const KernelKey& key) { + friend std::ostream &operator<<(std::ostream &os, const KernelKey &key) { os << key.kernel_key_data_ << std::endl; return os; } #endif - private: - const char* kernel_key_data_ = nullptr; +private: + const char *kernel_key_data_ = nullptr; bool is_fallback_; }; @@ -174,7 +160,7 @@ struct KernelKey { * kernel may or may not live in an `Operator`. */ struct Kernel { - const char* name_; + const char *name_; // String representation of kernel key, with the same format as // KernelKey.to_string_representation() // Data is not owned by the Kernel struct. @@ -185,16 +171,16 @@ struct Kernel { * itself, we require the lifetime of the operator name to be at least as long * as the operator registry. */ - explicit Kernel(const char* name, OpFunction func) : name_(name), op_(func) {} + explicit Kernel(const char *name, OpFunction func) : name_(name), op_(func) {} - explicit Kernel(const char* name, KernelKey key, OpFunction func) + explicit Kernel(const char *name, KernelKey key, OpFunction func) : name_(name), kernel_key_(key), op_(func) {} Kernel() {} }; namespace internal { -void make_kernel_key_string(Span key, char* buf); +void make_kernel_key_string(Span key, char *buf); } // namespace internal /** @@ -202,16 +188,15 @@ void make_kernel_key_string(Span key, char* buf); * TensorMeta is empty, it means this op does not have specialized kernels, so * it checks whether it has any fallback kernels. */ -bool registry_has_op_function( - const char* name, - Span meta_list = {}); +bool registry_has_op_function(const char *name, + Span meta_list = {}); /** * Returns the operator with a given name and TensorMeta list, if present. */ -::executorch::runtime::Result get_op_function_from_registry( - const char* name, - Span meta_list = {}); +::executorch::runtime::Result +get_op_function_from_registry(const char *name, + Span meta_list = {}); /** * Returns all registered kernels. @@ -234,7 +219,7 @@ ET_NODISCARD Error register_kernels(const Span); * @retval Error::Ok always. Panics on error. This function needs to return a * non-void type to run at static initialization time. */ -ET_NODISCARD inline Error register_kernel(const Kernel& kernel) { +ET_NODISCARD inline Error register_kernel(const Kernel &kernel) { return register_kernels({&kernel, 1}); }; @@ -256,15 +241,14 @@ inline ::executorch::runtime::Error register_kernels(ArrayRef kernels) { return ::executorch::runtime::register_kernels( {kernels.data(), kernels.size()}); } -inline OpFunction getOpsFn( - const char* name, - ArrayRef meta_list = {}) { +inline OpFunction getOpsFn(const char *name, + ArrayRef meta_list = {}) { auto result = ::executorch::runtime::get_op_function_from_registry( name, {meta_list.data(), meta_list.size()}); ET_CHECK(result.ok()); // get_op_function_from_registry() logs details. return *result; } -inline bool hasOpsFn(const char* name, ArrayRef meta_list = {}) { +inline bool hasOpsFn(const char *name, ArrayRef meta_list = {}) { return ::executorch::runtime::registry_has_op_function( name, {meta_list.data(), meta_list.size()}); } diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h index 3a574334..88d67f76 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h @@ -18,12 +18,9 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_ASSERT_MESSAGE_EMIT(_format, ...) \ - ET_LOG( \ - Fatal, \ - "In function %s(), assert failed" _format, \ - ET_FUNCTION, \ - ##__VA_ARGS__) +#define ET_ASSERT_MESSAGE_EMIT(_format, ...) \ + ET_LOG(Fatal, "In function %s(), assert failed" _format, ET_FUNCTION, \ + ##__VA_ARGS__) /** * Abort the runtime if the condition is not true. @@ -33,12 +30,12 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_CHECK_MSG(_cond, _format, ...) \ - ({ \ - if ET_UNLIKELY (!(_cond)) { \ - ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \ - ::executorch::runtime::runtime_abort(); \ - } \ +#define ET_CHECK_MSG(_cond, _format, ...) \ + ({ \ + if ET_UNLIKELY (!(_cond)) { \ + ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \ + ::executorch::runtime::runtime_abort(); \ + } \ }) /** @@ -47,12 +44,12 @@ * * @param[in] _cond Condition asserted as true. */ -#define ET_CHECK(_cond) \ - ({ \ - if ET_UNLIKELY (!(_cond)) { \ - ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \ - ::executorch::runtime::runtime_abort(); \ - } \ +#define ET_CHECK(_cond) \ + ({ \ + if ET_UNLIKELY (!(_cond)) { \ + ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \ + ::executorch::runtime::runtime_abort(); \ + } \ }) #ifdef NDEBUG @@ -85,7 +82,7 @@ * @param[in] _format Printf-style message format string. * @param[in] ... Format string arguments. */ -#define ET_DCHECK_MSG(_cond, _format, ...) \ +#define ET_DCHECK_MSG(_cond, _format, ...) \ ET_CHECK_MSG(_cond, _format, ##__VA_ARGS__) /** @@ -101,10 +98,10 @@ /** * Assert that this code location is unreachable during execution. */ -#define ET_ASSERT_UNREACHABLE() \ - ({ \ - ET_CHECK_MSG(false, "Execution should not reach this point"); \ - ET_UNREACHABLE(); \ +#define ET_ASSERT_UNREACHABLE() \ + ({ \ + ET_CHECK_MSG(false, "Execution should not reach this point"); \ + ET_UNREACHABLE(); \ }) /** @@ -112,9 +109,9 @@ * * @param[in] _message Message on how to avoid this assertion error. */ -#define ET_ASSERT_UNREACHABLE_MSG(_message) \ - ({ \ - ET_CHECK_MSG( \ - false, "Execution should not reach this point. %s", _message); \ - ET_UNREACHABLE(); \ +#define ET_ASSERT_UNREACHABLE_MSG(_message) \ + ({ \ + ET_CHECK_MSG(false, "Execution should not reach this point. %s", \ + _message); \ + ET_UNREACHABLE(); \ }) diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h index b6f7fc86..bdccebd1 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h @@ -19,25 +19,25 @@ */ // https://gcc.gnu.org/projects/cxx-status.html#cxx17 -#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \ +#if !defined(__clang__) && !defined(_MSC_VER) && defined(__GNUC__) && \ __GNUC__ < 7 -#error \ +#error \ "You're trying to build ExecuTorch with a too old version of GCC. We need GCC 7 or later." #endif // https://clang.llvm.org/cxx_status.html#cxx17 #if defined(__clang__) && __clang_major__ < 5 -#error \ +#error \ "You're trying to build ExecuTorch with a too old version of Clang. We need Clang 5 or later." #endif -#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ +#if (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || \ (!defined(_MSC_VER) && __cplusplus < 201703L) #error "You need C++17 to compile ExecuTorch" #endif #if defined(_WIN32) && (defined(min) || defined(max)) -#error \ +#error \ "Macro clash with min and max -- define NOMINMAX when compiling your program on Windows" #endif @@ -69,8 +69,8 @@ #else // defined(__GNUC__) -#define ET_UNREACHABLE() \ - while (1) \ +#define ET_UNREACHABLE() \ + while (1) \ ; #endif // defined(__GNUC__) @@ -78,7 +78,7 @@ #if (__cplusplus) >= 201703L #define ET_DEPRECATED [[deprecated]] -#define ET_EXPERIMENTAL \ +#define ET_EXPERIMENTAL \ [[deprecated("This API is experimental and may change without notice.")]] #define ET_FALLTHROUGH [[fallthrough]] #define ET_NODISCARD [[nodiscard]] @@ -87,8 +87,8 @@ #else #define ET_DEPRECATED __attribute__((deprecated)) -#define ET_EXPERIMENTAL \ - __attribute__(( \ +#define ET_EXPERIMENTAL \ + __attribute__(( \ deprecated("This API is experimental and may change without notice."))) #define ET_FALLTHROUGH __attribute__((fallthrough)) #define ET_NODISCARD __attribute__((warn_unused_result)) @@ -120,7 +120,7 @@ * Annotation marking a function as printf-like, providing compiler support * for format string argument checking. */ -#define ET_PRINTFLIKE(_string_index, _va_index) \ +#define ET_PRINTFLIKE(_string_index, _va_index) \ __attribute__((format(printf, _string_index, _va_index))) /// Name of the source file without a directory string. diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h index 2b1e791b..7f95bbc0 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h @@ -95,14 +95,8 @@ et_timestamp_t get_log_timestamp(); * @param[in] args Variable argument list. */ ET_PRINTFLIKE(6, 0) -void vlogf( - LogLevel level, - et_timestamp_t timestamp, - const char* filename, - const char* function, - size_t line, - const char* format, - va_list args); +void vlogf(LogLevel level, et_timestamp_t timestamp, const char *filename, + const char *function, size_t line, const char *format, va_list args); /** * Log a string message. @@ -117,14 +111,8 @@ void vlogf( * @param[in] format Format string. */ ET_PRINTFLIKE(6, 7) -inline void logf( - LogLevel level, - et_timestamp_t timestamp, - const char* filename, - const char* function, - size_t line, - const char* format, - ...) { +inline void logf(LogLevel level, et_timestamp_t timestamp, const char *filename, + const char *function, size_t line, const char *format, ...) { #if ET_LOG_ENABLED va_list args; va_start(args, format); @@ -154,23 +142,18 @@ using ::executorch::runtime::LogLevel; * @param[in] _level Log severity level. * @param[in] _format Log message format string. */ -#define ET_LOG(_level, _format, ...) \ - ({ \ - const auto _log_level = ::executorch::runtime::LogLevel::_level; \ - if (static_cast(_log_level) >= \ - static_cast( \ - ::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \ - const auto _timestamp = \ - ::executorch::runtime::internal::get_log_timestamp(); \ - ::executorch::runtime::internal::logf( \ - _log_level, \ - _timestamp, \ - ET_SHORT_FILENAME, \ - ET_FUNCTION, \ - ET_LINE, \ - _format, \ - ##__VA_ARGS__); \ - } \ +#define ET_LOG(_level, _format, ...) \ + ({ \ + const auto _log_level = ::executorch::runtime::LogLevel::_level; \ + if (static_cast(_log_level) >= \ + static_cast( \ + ::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \ + const auto _timestamp = \ + ::executorch::runtime::internal::get_log_timestamp(); \ + ::executorch::runtime::internal::logf(_log_level, _timestamp, \ + ET_SHORT_FILENAME, ET_FUNCTION, \ + ET_LINE, _format, ##__VA_ARGS__); \ + } \ }) #else // ET_LOG_ENABLED diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h index 03cdef8e..c5cf1dd1 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h @@ -79,8 +79,8 @@ et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS; * * @retval The ratio of nanoseconds to system ticks. */ -et_tick_ratio_t et_pal_ticks_to_ns_multiplier(void) - ET_INTERNAL_PLATFORM_WEAKNESS; +et_tick_ratio_t +et_pal_ticks_to_ns_multiplier(void) ET_INTERNAL_PLATFORM_WEAKNESS; /** * Severity level of a log message. Values must map to printable 7-bit ASCII @@ -106,14 +106,10 @@ typedef enum { * @param[in] message Message string to log. * @param[in] length Message string length. */ -void et_pal_emit_log_message( - et_timestamp_t timestamp, - et_pal_log_level_t level, - const char* filename, - const char* function, - size_t line, - const char* message, - size_t length) ET_INTERNAL_PLATFORM_WEAKNESS; +void et_pal_emit_log_message(et_timestamp_t timestamp, et_pal_log_level_t level, + const char *filename, const char *function, + size_t line, const char *message, + size_t length) ET_INTERNAL_PLATFORM_WEAKNESS; /** * NOTE: Core runtime code must not call this directly. It may only be called by @@ -125,13 +121,13 @@ void et_pal_emit_log_message( * @returns the allocated memory, or nullptr on failure. Must be freed using * et_pal_free(). */ -void* et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS; +void *et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS; /** * Frees memory allocated by et_pal_allocate(). * * @param[in] ptr Pointer to memory to free. May be nullptr. */ -void et_pal_free(void* ptr) ET_INTERNAL_PLATFORM_WEAKNESS; +void et_pal_free(void *ptr) ET_INTERNAL_PLATFORM_WEAKNESS; } // extern "C" diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h index 07ffd9c3..72f69b3d 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h @@ -50,7 +50,7 @@ namespace runtime { typedef struct alignas(8) { union { - const char* name_str; + const char *name_str; char name[PROF_NAME_MAX_LEN]; }; // chain_idx == -1 is a null value, when profile event happens out of chain @@ -72,7 +72,7 @@ typedef struct alignas(8) { } prof_allocator_t; typedef struct alignas(8) { - uint8_t* prof_data; + uint8_t *prof_data; uint32_t num_bytes; uint32_t num_blocks; } prof_result_t; @@ -103,8 +103,8 @@ This is what the layout of the profiling buffer looks like. // offsets of the various sections in the profiling buffer // Total size required for profiling buffer -constexpr uint32_t prof_buf_size = sizeof(prof_header_t) + - sizeof(prof_event_t) * MAX_PROFILE_EVENTS + +constexpr uint32_t prof_buf_size = + sizeof(prof_header_t) + sizeof(prof_event_t) * MAX_PROFILE_EVENTS + sizeof(mem_prof_event_t) * MAX_MEM_PROFILE_EVENTS + sizeof(prof_allocator_t) * MEM_PROFILE_MAX_ALLOCATORS; @@ -112,7 +112,8 @@ constexpr size_t prof_header_offset = 0; constexpr size_t prof_events_offset = sizeof(prof_header_t); constexpr size_t prof_mem_alloc_info_offset = prof_events_offset + sizeof(prof_event_t) * MAX_PROFILE_EVENTS; -constexpr size_t prof_mem_alloc_events_offset = prof_mem_alloc_info_offset + +constexpr size_t prof_mem_alloc_events_offset = + prof_mem_alloc_info_offset + sizeof(prof_allocator_t) * MEM_PROFILE_MAX_ALLOCATORS; // Set the initial state for the profiler assuming we're using the @@ -121,33 +122,33 @@ void profiler_init(void); // This starts the profiling of this event and returns a token // by which this event can be referred to in the future. -uint32_t begin_profiling(const char* name); +uint32_t begin_profiling(const char *name); // End profiling event represented by token_id void end_profiling(uint32_t token_id); // Dump profiler results, return pointer to prof event array and number of // events in it. -void dump_profile_stats(prof_result_t* prof_result); +void dump_profile_stats(prof_result_t *prof_result); void reset_profile_stats(); void track_allocation(int32_t id, uint32_t size); -uint32_t track_allocator(const char* name); +uint32_t track_allocator(const char *name); -void profiling_create_block(const char* name); +void profiling_create_block(const char *name); // This class enables scope based profiling where needed. Profiling // will be started when the object is created and will end when the // object goes out of scope. class ExecutorchProfiler { - public: - explicit ExecutorchProfiler(const char* name); +public: + explicit ExecutorchProfiler(const char *name); ~ExecutorchProfiler(); - private: +private: uint32_t prof_tok; }; @@ -156,27 +157,27 @@ typedef struct { uint32_t instruction_idx; } prof_state_t; -const prof_state_t& get_profile_tls_state(); +const prof_state_t &get_profile_tls_state(); -void set_profile_tls_state(const prof_state_t& state); +void set_profile_tls_state(const prof_state_t &state); class ExecutorchProfilerInstructionScope { - public: - explicit ExecutorchProfilerInstructionScope(const prof_state_t& state); +public: + explicit ExecutorchProfilerInstructionScope(const prof_state_t &state); ~ExecutorchProfilerInstructionScope(); // ScopeGuard: non-copyable, non-movable ExecutorchProfilerInstructionScope( - const ExecutorchProfilerInstructionScope&) = delete; - ExecutorchProfilerInstructionScope& operator=( - const ExecutorchProfilerInstructionScope&) = delete; + const ExecutorchProfilerInstructionScope &) = delete; + ExecutorchProfilerInstructionScope & + operator=(const ExecutorchProfilerInstructionScope &) = delete; - ExecutorchProfilerInstructionScope(ExecutorchProfilerInstructionScope&&) = + ExecutorchProfilerInstructionScope(ExecutorchProfilerInstructionScope &&) = delete; - ExecutorchProfilerInstructionScope& operator=( - ExecutorchProfilerInstructionScope&&) = delete; + ExecutorchProfilerInstructionScope & + operator=(ExecutorchProfilerInstructionScope &&) = delete; - private: +private: prof_state_t old_state_; }; @@ -215,70 +216,72 @@ using ::executorch::runtime::track_allocator; #ifdef PROFILING_ENABLED -#define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \ +#define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \ ::executorch::runtime::profiling_create_block(name); // Convenience macros to begin and end profiling. These can be inserted // anywhere as it'll be ensured that for the prod builds these will // essentially be noops. -#define EXECUTORCH_BEGIN_PROF(name) \ +#define EXECUTORCH_BEGIN_PROF(name) \ ::executorch::runtime::begin_profiling(name); -#define EXECUTORCH_END_PROF(token_id) \ +#define EXECUTORCH_END_PROF(token_id) \ ::executorch::runtime::end_profiling(token_id); -#define EXECUTORCH_SCOPE_PROF(name) \ +#define EXECUTORCH_SCOPE_PROF(name) \ ::executorch::runtime::ExecutorchProfiler profiler(name); -#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ - ::executorch::runtime::ExecutorchProfilerInstructionScope \ +#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ + ::executorch::runtime::ExecutorchProfilerInstructionScope \ __profiler_instruction_scope({chain_idx, instruction_idx}); -#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \ +#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \ ::executorch::runtime::dump_profile_stats(prof_result); -#define EXECUTORCH_RESET_PROFILE_RESULTS() \ +#define EXECUTORCH_RESET_PROFILE_RESULTS() \ ::executorch::runtime::reset_profile_stats(); -#define EXECUTORCH_TRACK_ALLOCATOR(name) \ +#define EXECUTORCH_TRACK_ALLOCATOR(name) \ ::executorch::runtime::track_allocator(name); -#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ +#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ ::executorch::runtime::track_allocation(id, size); #else #define EXECUTORCH_PROFILE_CREATE_BLOCK(name) ({ (void)(name); }) -#define EXECUTORCH_BEGIN_PROF(name) \ - {} +#define EXECUTORCH_BEGIN_PROF(name) \ + { \ + } #define EXECUTORCH_END_PROF(token_id) ({ (void)(token_id); }) #define EXECUTORCH_SCOPE_PROF(name) ({ (void)(name); }) -#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ - ({ \ - (void)(chain_idx); \ - (void)(instruction_idx); \ +#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ + ({ \ + (void)(chain_idx); \ + (void)(instruction_idx); \ }) -#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \ +#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \ memset(prof_result_test, 0, sizeof(::executorch::runtime::prof_result_t)); -#define EXECUTORCH_RESET_PROFILE_RESULTS() \ - {} +#define EXECUTORCH_RESET_PROFILE_RESULTS() \ + { \ + } -#define EXECUTORCH_TRACK_ALLOCATOR(name) \ - ({ \ - (void)(name); \ - -1; \ +#define EXECUTORCH_TRACK_ALLOCATOR(name) \ + ({ \ + (void)(name); \ + -1; \ }) -#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ - ({ \ - (void)(id); \ - (void)(size); \ +#define EXECUTORCH_TRACK_ALLOCATION(id, size) \ + ({ \ + (void)(id); \ + (void)(size); \ }) #endif diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h index 18c6ee30..ae658507 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h @@ -22,8 +22,8 @@ #include #endif -static constexpr const char* DYNAMIC_LIBRARY_NOT_SUPPORTED = "NOT_SUPPORTED"; -static constexpr const char* DYNAMIC_LIBRARY_NOT_FOUND = "NOT_FOUND"; +static constexpr const char *DYNAMIC_LIBRARY_NOT_SUPPORTED = "NOT_SUPPORTED"; +static constexpr const char *DYNAMIC_LIBRARY_NOT_FOUND = "NOT_FOUND"; extern "C" { @@ -33,7 +33,7 @@ extern "C" { * @param[in] addr Address to the symbol we are looking for in shared libraries. * @retval The path to the shared library containing the symbol. */ -inline const char* et_pal_get_shared_library_name(const void* addr) { +inline const char *et_pal_get_shared_library_name(const void *addr) { #if defined(ET_USE_LIBDL) Dl_info info; if (dladdr(addr, &info) && info.dli_fname) { diff --git a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h index e6fe5783..59b28e30 100644 --- a/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h +++ b/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h @@ -57,7 +57,7 @@ struct ExtendedHeader { * error if size was too short, if the header was not found, or if the * header appeared to be corrupt. */ - static Result Parse(const void* data, size_t size); + static Result Parse(const void *data, size_t size); /** * The size in bytes of the Program flatbuffer data, starting from offset diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h index 293b31d8..af80cd86 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h @@ -16,15 +16,11 @@ namespace re2 { class Bitmap256 { - public: - Bitmap256() { - Clear(); - } +public: + Bitmap256() { Clear(); } // Clears all of the bits. - void Clear() { - memset(words_, 0, sizeof words_); - } + void Clear() { memset(words_, 0, sizeof words_); } // Tests the bit with index c. bool Test(int c) const { @@ -46,7 +42,7 @@ class Bitmap256 { // Returns -1 if no such bit exists. int FindNextSetBit(int c) const; - private: +private: // Finds the least significant non-zero bit in n. static int FindLSBSet(uint64_t n) { DCHECK_NE(n, 0); @@ -81,6 +77,6 @@ class Bitmap256 { uint64_t words_[4]; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_BITMAP256_H_ +#endif // RE2_BITMAP256_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h index dd618c70..b022a006 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h @@ -32,24 +32,23 @@ namespace re2 { class PrefilterTree; class FilteredRE2 { - public: +public: FilteredRE2(); explicit FilteredRE2(int min_atom_len); ~FilteredRE2(); // Not copyable. - FilteredRE2(const FilteredRE2&) = delete; - FilteredRE2& operator=(const FilteredRE2&) = delete; + FilteredRE2(const FilteredRE2 &) = delete; + FilteredRE2 &operator=(const FilteredRE2 &) = delete; // Movable. - FilteredRE2(FilteredRE2&& other); - FilteredRE2& operator=(FilteredRE2&& other); + FilteredRE2(FilteredRE2 &&other); + FilteredRE2 &operator=(FilteredRE2 &&other); // Uses RE2 constructor to create a RE2 object (re). Returns // re->error_code(). If error_code is other than NoError, then re is // deleted and not added to re2_vec_. - RE2::ErrorCode Add(const StringPiece& pattern, - const RE2::Options& options, - int* id); + RE2::ErrorCode Add(const StringPiece &pattern, const RE2::Options &options, + int *id); // Prepares the regexps added by Add for filtering. Returns a set // of strings that the caller should check for in candidate texts. @@ -57,50 +56,48 @@ class FilteredRE2 { // string matching, it should be performed in a case-insensitive // way or the search text should be lowercased first. Call after // all Add calls are done. - void Compile(std::vector* strings_to_match); + void Compile(std::vector *strings_to_match); // Returns the index of the first matching regexp. // Returns -1 on no match. Can be called prior to Compile. // Does not do any filtering: simply tries to Match the // regexps in a loop. - int SlowFirstMatch(const StringPiece& text) const; + int SlowFirstMatch(const StringPiece &text) const; // Returns the index of the first matching regexp. // Returns -1 on no match. Compile has to be called before // calling this. - int FirstMatch(const StringPiece& text, - const std::vector& atoms) const; + int FirstMatch(const StringPiece &text, const std::vector &atoms) const; // Returns the indices of all matching regexps, after first clearing // matched_regexps. - bool AllMatches(const StringPiece& text, - const std::vector& atoms, - std::vector* matching_regexps) const; + bool AllMatches(const StringPiece &text, const std::vector &atoms, + std::vector *matching_regexps) const; // Returns the indices of all potentially matching regexps after first // clearing potential_regexps. // A regexp is potentially matching if it passes the filter. // If a regexp passes the filter it may still not match. // A regexp that does not pass the filter is guaranteed to not match. - void AllPotentials(const std::vector& atoms, - std::vector* potential_regexps) const; + void AllPotentials(const std::vector &atoms, + std::vector *potential_regexps) const; // The number of regexps added. int NumRegexps() const { return static_cast(re2_vec_.size()); } // Get the individual RE2 objects. - const RE2& GetRE2(int regexpid) const { return *re2_vec_[regexpid]; } + const RE2 &GetRE2(int regexpid) const { return *re2_vec_[regexpid]; } - private: +private: // Print prefilter. void PrintPrefilter(int regexpid); // Useful for testing and debugging. - void RegexpsGivenStrings(const std::vector& matched_atoms, - std::vector* passed_regexps); + void RegexpsGivenStrings(const std::vector &matched_atoms, + std::vector *passed_regexps); // All the regexps in the FilteredRE2. - std::vector re2_vec_; + std::vector re2_vec_; // Has the FilteredRE2 been compiled using Compile() bool compiled_; @@ -109,6 +106,6 @@ class FilteredRE2 { std::unique_ptr prefilter_tree_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_FILTERED_RE2_H_ +#endif // RE2_FILTERED_RE2_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h index f234e976..267f9b16 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h @@ -10,39 +10,27 @@ namespace re2 { -template -class PODArray { - public: +template class PODArray { +public: static_assert(std::is_trivial::value && std::is_standard_layout::value, "T must be POD"); - PODArray() - : ptr_() {} + PODArray() : ptr_() {} explicit PODArray(int len) : ptr_(std::allocator().allocate(len), Deleter(len)) {} - T* data() const { - return ptr_.get(); - } + T *data() const { return ptr_.get(); } - int size() const { - return ptr_.get_deleter().len_; - } + int size() const { return ptr_.get_deleter().len_; } - T& operator[](int pos) const { - return ptr_[pos]; - } + T &operator[](int pos) const { return ptr_[pos]; } - private: +private: struct Deleter { - Deleter() - : len_(0) {} - explicit Deleter(int len) - : len_(len) {} + Deleter() : len_(0) {} + explicit Deleter(int len) : len_(len) {} - void operator()(T* ptr) const { - std::allocator().deallocate(ptr, len_); - } + void operator()(T *ptr) const { std::allocator().deallocate(ptr, len_); } int len_; }; @@ -50,6 +38,6 @@ class PODArray { std::unique_ptr ptr_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_POD_ARRAY_H_ +#endif // RE2_POD_ARRAY_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h index e149e59a..23009a2c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h @@ -13,8 +13,8 @@ #include #include -#include "util/util.h" #include "util/logging.h" +#include "util/util.h" namespace re2 { @@ -24,48 +24,48 @@ class Regexp; class Prefilter { // Instead of using Prefilter directly, use FilteredRE2; see filtered_re2.h - public: +public: enum Op { - ALL = 0, // Everything matches - NONE, // Nothing matches - ATOM, // The string atom() must match - AND, // All in subs() must match - OR, // One of subs() must match + ALL = 0, // Everything matches + NONE, // Nothing matches + ATOM, // The string atom() must match + AND, // All in subs() must match + OR, // One of subs() must match }; explicit Prefilter(Op op); ~Prefilter(); Op op() { return op_; } - const std::string& atom() const { return atom_; } + const std::string &atom() const { return atom_; } void set_unique_id(int id) { unique_id_ = id; } int unique_id() const { return unique_id_; } // The children of the Prefilter node. - std::vector* subs() { + std::vector *subs() { DCHECK(op_ == AND || op_ == OR); return subs_; } // Set the children vector. Prefilter takes ownership of subs and // subs_ will be deleted when Prefilter is deleted. - void set_subs(std::vector* subs) { subs_ = subs; } + void set_subs(std::vector *subs) { subs_ = subs; } // Given a RE2, return a Prefilter. The caller takes ownership of // the Prefilter and should deallocate it. Returns NULL if Prefilter // cannot be formed. - static Prefilter* FromRE2(const RE2* re2); + static Prefilter *FromRE2(const RE2 *re2); // Returns a readable debug string of the prefilter. std::string DebugString() const; - private: +private: // A comparator used to store exact strings. We compare by length, // then lexicographically. This ordering makes it easier to reduce the // set of strings in SimplifyStringSet. struct LengthThenLex { - bool operator()(const std::string& a, const std::string& b) const { - return (a.size() < b.size()) || (a.size() == b.size() && a < b); + bool operator()(const std::string &a, const std::string &b) const { + return (a.size() < b.size()) || (a.size() == b.size() && a < b); } }; @@ -77,39 +77,39 @@ class Prefilter { // Combines two prefilters together to create an AND. The passed // Prefilters will be part of the returned Prefilter or deleted. - static Prefilter* And(Prefilter* a, Prefilter* b); + static Prefilter *And(Prefilter *a, Prefilter *b); // Combines two prefilters together to create an OR. The passed // Prefilters will be part of the returned Prefilter or deleted. - static Prefilter* Or(Prefilter* a, Prefilter* b); + static Prefilter *Or(Prefilter *a, Prefilter *b); // Generalized And/Or - static Prefilter* AndOr(Op op, Prefilter* a, Prefilter* b); + static Prefilter *AndOr(Op op, Prefilter *a, Prefilter *b); - static Prefilter* FromRegexp(Regexp* a); + static Prefilter *FromRegexp(Regexp *a); - static Prefilter* FromString(const std::string& str); + static Prefilter *FromString(const std::string &str); - static Prefilter* OrStrings(SSet* ss); + static Prefilter *OrStrings(SSet *ss); - static Info* BuildInfo(Regexp* re); + static Info *BuildInfo(Regexp *re); - Prefilter* Simplify(); + Prefilter *Simplify(); // Removes redundant strings from the set. A string is redundant if // any of the other strings appear as a substring. The empty string // is a special case, which is ignored. - static void SimplifyStringSet(SSet* ss); + static void SimplifyStringSet(SSet *ss); // Adds the cross-product of a and b to dst. // (For each string i in a and j in b, add i+j.) - static void CrossProduct(const SSet& a, const SSet& b, SSet* dst); + static void CrossProduct(const SSet &a, const SSet &b, SSet *dst); // Kind of Prefilter. Op op_; // Sub-matches for AND or OR Prefilter. - std::vector* subs_; + std::vector *subs_; // Actual string to match in leaf node. std::string atom_; @@ -121,10 +121,10 @@ class Prefilter { // and -1 for duplicate nodes. int unique_id_; - Prefilter(const Prefilter&) = delete; - Prefilter& operator=(const Prefilter&) = delete; + Prefilter(const Prefilter &) = delete; + Prefilter &operator=(const Prefilter &) = delete; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_PREFILTER_H_ +#endif // RE2_PREFILTER_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h index 6de1c38e..586f7180 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h @@ -20,14 +20,14 @@ #include #include -#include "util/util.h" #include "re2/prefilter.h" #include "re2/sparse_array.h" +#include "util/util.h" namespace re2 { class PrefilterTree { - public: +public: PrefilterTree(); explicit PrefilterTree(int min_atom_len); ~PrefilterTree(); @@ -35,7 +35,7 @@ class PrefilterTree { // Adds the prefilter for the next regexp. Note that we assume that // Add called sequentially for all regexps. All Add calls // must precede Compile. - void Add(Prefilter* prefilter); + void Add(Prefilter *prefilter); // The Compile returns a vector of string in atom_vec. // Call this after all the prefilters are added through Add. @@ -43,30 +43,30 @@ class PrefilterTree { // The caller should use the returned set of strings to do string matching. // Each time a string matches, the corresponding index then has to be // and passed to RegexpsGivenStrings below. - void Compile(std::vector* atom_vec); + void Compile(std::vector *atom_vec); // Given the indices of the atoms that matched, returns the indexes // of regexps that should be searched. The matched_atoms should // contain all the ids of string atoms that were found to match the // content. The caller can use any string match engine to perform // this function. This function is thread safe. - void RegexpsGivenStrings(const std::vector& matched_atoms, - std::vector* regexps) const; + void RegexpsGivenStrings(const std::vector &matched_atoms, + std::vector *regexps) const; // Print debug prefilter. Also prints unique ids associated with // nodes of the prefilter of the regexp. void PrintPrefilter(int regexpid); - private: +private: typedef SparseArray IntMap; // TODO(junyer): Use std::unordered_set instead? // It should be trivial to get rid of the stringification... - typedef std::map NodeMap; + typedef std::map NodeMap; // Each unique node has a corresponding Entry that helps in // passing the matching trigger information along the tree. struct Entry { - public: + public: // How many children should match before this node triggers the // parent. For an atom and an OR node, this is 1 and for an AND // node, it is the number of unique children. @@ -86,30 +86,29 @@ class PrefilterTree { }; // Returns true if the prefilter node should be kept. - bool KeepNode(Prefilter* node) const; + bool KeepNode(Prefilter *node) const; // This function assigns unique ids to various parts of the // prefilter, by looking at if these nodes are already in the // PrefilterTree. - void AssignUniqueIds(NodeMap* nodes, std::vector* atom_vec); + void AssignUniqueIds(NodeMap *nodes, std::vector *atom_vec); // Given the matching atoms, find the regexps to be triggered. - void PropagateMatch(const std::vector& atom_ids, - IntMap* regexps) const; + void PropagateMatch(const std::vector &atom_ids, IntMap *regexps) const; // Returns the prefilter node that has the same NodeString as this // node. For the canonical node, returns node. - Prefilter* CanonicalNode(NodeMap* nodes, Prefilter* node); + Prefilter *CanonicalNode(NodeMap *nodes, Prefilter *node); // A string that uniquely identifies the node. Assumes that the // children of node has already been assigned unique ids. - std::string NodeString(Prefilter* node) const; + std::string NodeString(Prefilter *node) const; // Recursively constructs a readable prefilter string. - std::string DebugNodeString(Prefilter* node) const; + std::string DebugNodeString(Prefilter *node) const; // Used for debugging. - void PrintDebugInfo(NodeMap* nodes); + void PrintDebugInfo(NodeMap *nodes); // These are all the nodes formed by Compile. Essentially, there is // one node for each unique atom and each unique AND/OR node. @@ -120,7 +119,7 @@ class PrefilterTree { std::vector unfiltered_; // vector of Prefilter for all regexps. - std::vector prefilter_vec_; + std::vector prefilter_vec_; // Atom index in returned strings to entry id mapping. std::vector atom_index_to_id_; @@ -131,10 +130,10 @@ class PrefilterTree { // Strings less than this length are not stored as atoms. const int min_atom_len_; - PrefilterTree(const PrefilterTree&) = delete; - PrefilterTree& operator=(const PrefilterTree&) = delete; + PrefilterTree(const PrefilterTree &) = delete; + PrefilterTree &operator=(const PrefilterTree &) = delete; }; -} // namespace +} // namespace re2 -#endif // RE2_PREFILTER_TREE_H_ +#endif // RE2_PREFILTER_TREE_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h index 72c9856d..a4432a21 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h @@ -9,44 +9,45 @@ // See regexp.h for the Regexp class, which represents a regular // expression symbolically. -#include #include #include +#include #include -#include #include +#include -#include "util/util.h" -#include "util/logging.h" #include "re2/pod_array.h" #include "re2/re2.h" #include "re2/sparse_array.h" #include "re2/sparse_set.h" +#include "util/logging.h" +#include "util/util.h" namespace re2 { // Opcodes for Inst enum InstOp { - kInstAlt = 0, // choose between out_ and out1_ - kInstAltMatch, // Alt: out_ is [00-FF] and back, out1_ is match; or vice versa. - kInstByteRange, // next (possible case-folded) byte must be in [lo_, hi_] - kInstCapture, // capturing parenthesis number cap_ - kInstEmptyWidth, // empty-width special (^ $ ...); bit(s) set in empty_ - kInstMatch, // found a match! - kInstNop, // no-op; occasionally unavoidable - kInstFail, // never match; occasionally unavoidable + kInstAlt = 0, // choose between out_ and out1_ + kInstAltMatch, // Alt: out_ is [00-FF] and back, out1_ is match; or vice + // versa. + kInstByteRange, // next (possible case-folded) byte must be in [lo_, hi_] + kInstCapture, // capturing parenthesis number cap_ + kInstEmptyWidth, // empty-width special (^ $ ...); bit(s) set in empty_ + kInstMatch, // found a match! + kInstNop, // no-op; occasionally unavoidable + kInstFail, // never match; occasionally unavoidable kNumInst, }; // Bit flags for empty-width specials enum EmptyOp { - kEmptyBeginLine = 1<<0, // ^ - beginning of line - kEmptyEndLine = 1<<1, // $ - end of line - kEmptyBeginText = 1<<2, // \A - beginning of text - kEmptyEndText = 1<<3, // \z - end of text - kEmptyWordBoundary = 1<<4, // \b - word boundary - kEmptyNonWordBoundary = 1<<5, // \B - not \b - kEmptyAllFlags = (1<<6)-1, + kEmptyBeginLine = 1 << 0, // ^ - beginning of line + kEmptyEndLine = 1 << 1, // $ - end of line + kEmptyBeginText = 1 << 2, // \A - beginning of text + kEmptyEndText = 1 << 3, // \z - end of text + kEmptyWordBoundary = 1 << 4, // \b - word boundary + kEmptyNonWordBoundary = 1 << 5, // \B - not \b + kEmptyAllFlags = (1 << 6) - 1, }; class DFA; @@ -54,19 +55,19 @@ class Regexp; // Compiled form of regexp program. class Prog { - public: +public: Prog(); ~Prog(); // Single instruction in regexp program. class Inst { - public: + public: // See the assertion below for why this is so. Inst() = default; // Copyable. - Inst(const Inst&) = default; - Inst& operator=(const Inst&) = default; + Inst(const Inst &) = default; + Inst &operator=(const Inst &) = default; // Constructors per opcode void InitAlt(uint32_t out, uint32_t out1); @@ -78,20 +79,44 @@ class Prog { void InitFail(); // Getters - int id(Prog* p) { return static_cast(this - p->inst_.data()); } - InstOp opcode() { return static_cast(out_opcode_&7); } - int last() { return (out_opcode_>>3)&1; } - int out() { return out_opcode_>>4; } - int out1() { DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); return out1_; } - int cap() { DCHECK_EQ(opcode(), kInstCapture); return cap_; } - int lo() { DCHECK_EQ(opcode(), kInstByteRange); return lo_; } - int hi() { DCHECK_EQ(opcode(), kInstByteRange); return hi_; } - int foldcase() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_&1; } - int hint() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_>>1; } - int match_id() { DCHECK_EQ(opcode(), kInstMatch); return match_id_; } - EmptyOp empty() { DCHECK_EQ(opcode(), kInstEmptyWidth); return empty_; } - - bool greedy(Prog* p) { + int id(Prog *p) { return static_cast(this - p->inst_.data()); } + InstOp opcode() { return static_cast(out_opcode_ & 7); } + int last() { return (out_opcode_ >> 3) & 1; } + int out() { return out_opcode_ >> 4; } + int out1() { + DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); + return out1_; + } + int cap() { + DCHECK_EQ(opcode(), kInstCapture); + return cap_; + } + int lo() { + DCHECK_EQ(opcode(), kInstByteRange); + return lo_; + } + int hi() { + DCHECK_EQ(opcode(), kInstByteRange); + return hi_; + } + int foldcase() { + DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ & 1; + } + int hint() { + DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ >> 1; + } + int match_id() { + DCHECK_EQ(opcode(), kInstMatch); + return match_id_; + } + EmptyOp empty() { + DCHECK_EQ(opcode(), kInstEmptyWidth); + return empty_; + } + + bool greedy(Prog *p) { DCHECK_EQ(opcode(), kInstAltMatch); return p->inst(out())->opcode() == kInstByteRange || (p->inst(out())->opcode() == kInstNop && @@ -111,54 +136,53 @@ class Prog { // Maximum instruction id. // (Must fit in out_opcode_. PatchList/last steal another bit.) - static const int kMaxInst = (1<<28) - 1; + static const int kMaxInst = (1 << 28) - 1; - private: + private: void set_opcode(InstOp opcode) { - out_opcode_ = (out()<<4) | (last()<<3) | opcode; + out_opcode_ = (out() << 4) | (last() << 3) | opcode; } - void set_last() { - out_opcode_ = (out()<<4) | (1<<3) | opcode(); - } + void set_last() { out_opcode_ = (out() << 4) | (1 << 3) | opcode(); } void set_out(int out) { - out_opcode_ = (out<<4) | (last()<<3) | opcode(); + out_opcode_ = (out << 4) | (last() << 3) | opcode(); } void set_out_opcode(int out, InstOp opcode) { - out_opcode_ = (out<<4) | (last()<<3) | opcode; + out_opcode_ = (out << 4) | (last() << 3) | opcode; } - uint32_t out_opcode_; // 28 bits: out, 1 bit: last, 3 (low) bits: opcode - union { // additional instruction arguments: - uint32_t out1_; // opcode == kInstAlt - // alternate next instruction - - int32_t cap_; // opcode == kInstCapture - // Index of capture register (holds text - // position recorded by capturing parentheses). - // For \n (the submatch for the nth parentheses), - // the left parenthesis captures into register 2*n - // and the right one captures into register 2*n+1. - - int32_t match_id_; // opcode == kInstMatch - // Match ID to identify this match (for re2::Set). - - struct { // opcode == kInstByteRange - uint8_t lo_; // byte range is lo_-hi_ inclusive - uint8_t hi_; // - uint16_t hint_foldcase_; // 15 bits: hint, 1 (low) bit: foldcase - // hint to execution engines: the delta to the - // next instruction (in the current list) worth - // exploring iff this instruction matched; 0 - // means there are no remaining possibilities, - // which is most likely for character classes. - // foldcase: A-Z -> a-z before checking range. + uint32_t out_opcode_; // 28 bits: out, 1 bit: last, 3 (low) bits: opcode + union { // additional instruction arguments: + uint32_t out1_; // opcode == kInstAlt + // alternate next instruction + + int32_t cap_; // opcode == kInstCapture + // Index of capture register (holds text + // position recorded by capturing parentheses). + // For \n (the submatch for the nth parentheses), + // the left parenthesis captures into register 2*n + // and the right one captures into register 2*n+1. + + int32_t match_id_; // opcode == kInstMatch + // Match ID to identify this match (for re2::Set). + + struct { // opcode == kInstByteRange + uint8_t lo_; // byte range is lo_-hi_ inclusive + uint8_t hi_; // + uint16_t + hint_foldcase_; // 15 bits: hint, 1 (low) bit: foldcase + // hint to execution engines: the delta to the + // next instruction (in the current list) worth + // exploring iff this instruction matched; 0 + // means there are no remaining possibilities, + // which is most likely for character classes. + // foldcase: A-Z -> a-z before checking range. }; - EmptyOp empty_; // opcode == kInstEmptyWidth - // empty_ is bitwise OR of kEmpty* flags above. + EmptyOp empty_; // opcode == kInstEmptyWidth + // empty_ is bitwise OR of kEmpty* flags above. }; friend class Compiler; @@ -173,8 +197,8 @@ class Prog { // Whether to anchor the search. enum Anchor { - kUnanchored, // match anywhere - kAnchored, // match only starting at beginning of text + kUnanchored, // match anywhere + kAnchored, // match only starting at beginning of text }; // Kind of match to look for (for anchor != kFullMatch) @@ -190,10 +214,10 @@ class Prog { // the matching code can run faster if it knows to consider only // full matches. enum MatchKind { - kFirstMatch, // like Perl, PCRE - kLongestMatch, // like egrep or POSIX - kFullMatch, // match only entire text; implies anchor==kAnchored - kManyMatch // for SearchDFA, records set of matches + kFirstMatch, // like Perl, PCRE + kLongestMatch, // like egrep or POSIX + kFullMatch, // match only entire text; implies anchor==kAnchored + kManyMatch // for SearchDFA, records set of matches }; Inst *inst(int id) { return &inst_[id]; } @@ -206,7 +230,7 @@ class Prog { void set_reversed(bool reversed) { reversed_ = reversed; } int list_count() { return list_count_; } int inst_count(InstOp op) { return inst_count_[op]; } - uint16_t* list_heads() { return list_heads_.data(); } + uint16_t *list_heads() { return list_heads_.data(); } size_t bit_state_text_max_size() { return bit_state_text_max_size_; } int64_t dfa_mem() { return dfa_mem_; } void set_dfa_mem(int64_t dfa_mem) { dfa_mem_ = dfa_mem; } @@ -215,12 +239,12 @@ class Prog { bool anchor_end() { return anchor_end_; } void set_anchor_end(bool b) { anchor_end_ = b; } int bytemap_range() { return bytemap_range_; } - const uint8_t* bytemap() { return bytemap_; } + const uint8_t *bytemap() { return bytemap_; } bool can_prefix_accel() { return prefix_size_ != 0; } // Accelerates to the first likely occurrence of the prefix. // Returns a pointer to the first byte or NULL if not found. - const void* PrefixAccel(const void* data, size_t size) { + const void *PrefixAccel(const void *data, size_t size) { DCHECK(can_prefix_accel()); if (prefix_foldcase_) { return PrefixAccel_ShiftDFA(data, size); @@ -232,15 +256,15 @@ class Prog { } // Configures prefix accel using the analysis performed during compilation. - void ConfigurePrefixAccel(const std::string& prefix, bool prefix_foldcase); + void ConfigurePrefixAccel(const std::string &prefix, bool prefix_foldcase); // An implementation of prefix accel that uses prefix_dfa_ to perform // case-insensitive search. - const void* PrefixAccel_ShiftDFA(const void* data, size_t size); + const void *PrefixAccel_ShiftDFA(const void *data, size_t size); // An implementation of prefix accel that looks for prefix_front_ and // prefix_back_ to return fewer false positives than memchr(3) alone. - const void* PrefixAccel_FrontAndBack(const void* data, size_t size); + const void *PrefixAccel_FrontAndBack(const void *data, size_t size); // Returns string representation of program for debugging. std::string Dump(); @@ -249,7 +273,7 @@ class Prog { // Returns the set of kEmpty flags that are in effect at // position p within context. - static uint32_t EmptyFlags(const StringPiece& context, const char* p); + static uint32_t EmptyFlags(const StringPiece &context, const char *p); // Returns whether byte c is a word character: ASCII only. // Used by the implementation of \b and \B. @@ -259,10 +283,8 @@ class Prog { // - even if the lookahead were possible, the Progs would be huge. // This crude approximation is the same one PCRE uses. static bool IsWordChar(uint8_t c) { - return ('A' <= c && c <= 'Z') || - ('a' <= c && c <= 'z') || - ('0' <= c && c <= '9') || - c == '_'; + return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || + ('0' <= c && c <= '9') || c == '_'; } // Execution engines. They all search for the regexp (run the prog) @@ -280,9 +302,8 @@ class Prog { // match anything. Either way, match[i] == NULL. // Search using NFA: can find submatches but kind of slow. - bool SearchNFA(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchNFA(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, int nmatch); // Search using DFA: much faster than NFA but only finds // end of match and can use a lot more memory. @@ -290,9 +311,9 @@ class Prog { // If the DFA runs out of memory, sets *failed to true and returns false. // If matches != NULL and kind == kManyMatch and there is a match, // SearchDFA fills matches with the match IDs of the final matching state. - bool SearchDFA(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, StringPiece* match0, - bool* failed, SparseSet* matches); + bool SearchDFA(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match0, + bool *failed, SparseSet *matches); // The callback issued after building each DFA state with BuildEntireDFA(). // If next is null, then the memory budget has been exhausted and building @@ -301,7 +322,7 @@ class Prog { // kByteEndText. The number of the state is implied by the callback sequence: // the first callback is for state 0, the second callback is for state 1, ... // match indicates whether the state is a matching state. - using DFAStateCallback = std::function; + using DFAStateCallback = std::function; // Build the entire DFA for the given match kind. // Usually the DFA is built out incrementally, as needed, which @@ -309,7 +330,7 @@ class Prog { // If cb is not empty, it receives one callback per state built. // Returns the number of states built. // FOR TESTING OR EXPERIMENTAL PURPOSES ONLY. - int BuildEntireDFA(MatchKind kind, const DFAStateCallback& cb); + int BuildEntireDFA(MatchKind kind, const DFAStateCallback &cb); // Compute bytemap. void ComputeByteMap(); @@ -321,18 +342,18 @@ class Prog { // but much faster than NFA (competitive with PCRE) // for those expressions. bool IsOnePass(); - bool SearchOnePass(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchOnePass(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, + int nmatch); // Bit-state backtracking. Fast on small cases but uses memory // proportional to the product of the list count and the text size. bool CanBitState() { return list_heads_.data() != NULL; } - bool SearchBitState(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchBitState(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, + int nmatch); - static const int kMaxOnePassCapture = 5; // $0 through $4 + static const int kMaxOnePassCapture = 5; // $0 through $4 // Backtracking search: the gold standard against which the other // implementations are checked. FOR TESTING ONLY. @@ -340,10 +361,9 @@ class Prog { // It is also recursive, so can't use in production (will overflow stacks). // The name "Unsafe" here is supposed to be a flag that // you should not be using this function. - bool UnsafeSearchBacktrack(const StringPiece& text, - const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool UnsafeSearchBacktrack(const StringPiece &text, + const StringPiece &context, Anchor anchor, + MatchKind kind, StringPiece *match, int nmatch); // Computes range for any strings matching regexp. The min and max can in // some cases be arbitrarily precise, so the caller gets to specify the @@ -359,14 +379,14 @@ class Prog { // do not compile down to infinite repetitions. // // Returns true on success, false on error. - bool PossibleMatchRange(std::string* min, std::string* max, int maxlen); + bool PossibleMatchRange(std::string *min, std::string *max, int maxlen); // Outputs the program fanout into the given sparse array. - void Fanout(SparseArray* fanout); + void Fanout(SparseArray *fanout); // Compiles a collection of regexps to Prog. Each regexp will have // its own Match instruction recording the index in the output vector. - static Prog* CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem); + static Prog *CompileSet(Regexp *re, RE2::Anchor anchor, int64_t max_mem); // Flattens the Prog from "tree" form to "list" form. This is an in-place // operation in the sense that the old instructions are lost. @@ -375,93 +395,89 @@ class Prog { // Walks the Prog; the "successor roots" or predecessors of the reachable // instructions are marked in rootmap or predmap/predvec, respectively. // reachable and stk are preallocated scratch structures. - void MarkSuccessors(SparseArray* rootmap, - SparseArray* predmap, - std::vector>* predvec, - SparseSet* reachable, std::vector* stk); + void MarkSuccessors(SparseArray *rootmap, SparseArray *predmap, + std::vector> *predvec, + SparseSet *reachable, std::vector *stk); // Walks the Prog from the given "root" instruction; the "dominator root" // of the reachable instructions (if such exists) is marked in rootmap. // reachable and stk are preallocated scratch structures. - void MarkDominator(int root, SparseArray* rootmap, - SparseArray* predmap, - std::vector>* predvec, - SparseSet* reachable, std::vector* stk); + void MarkDominator(int root, SparseArray *rootmap, + SparseArray *predmap, + std::vector> *predvec, + SparseSet *reachable, std::vector *stk); // Walks the Prog from the given "root" instruction; the reachable // instructions are emitted in "list" form and appended to flat. // reachable and stk are preallocated scratch structures. - void EmitList(int root, SparseArray* rootmap, - std::vector* flat, - SparseSet* reachable, std::vector* stk); + void EmitList(int root, SparseArray *rootmap, std::vector *flat, + SparseSet *reachable, std::vector *stk); // Computes hints for ByteRange instructions in [begin, end). - void ComputeHints(std::vector* flat, int begin, int end); + void ComputeHints(std::vector *flat, int begin, int end); // Controls whether the DFA should bail out early if the NFA would be faster. // FOR TESTING ONLY. static void TESTING_ONLY_set_dfa_should_bail_when_slow(bool b); - private: +private: friend class Compiler; - DFA* GetDFA(MatchKind kind); - void DeleteDFA(DFA* dfa); + DFA *GetDFA(MatchKind kind); + void DeleteDFA(DFA *dfa); - bool anchor_start_; // regexp has explicit start anchor - bool anchor_end_; // regexp has explicit end anchor - bool reversed_; // whether program runs backward over input - bool did_flatten_; // has Flatten been called? - bool did_onepass_; // has IsOnePass been called? + bool anchor_start_; // regexp has explicit start anchor + bool anchor_end_; // regexp has explicit end anchor + bool reversed_; // whether program runs backward over input + bool did_flatten_; // has Flatten been called? + bool did_onepass_; // has IsOnePass been called? - int start_; // entry point for program - int start_unanchored_; // unanchored entry point for program - int size_; // number of instructions - int bytemap_range_; // bytemap_[x] < bytemap_range_ + int start_; // entry point for program + int start_unanchored_; // unanchored entry point for program + int size_; // number of instructions + int bytemap_range_; // bytemap_[x] < bytemap_range_ - bool prefix_foldcase_; // whether prefix is case-insensitive - size_t prefix_size_; // size of prefix (0 if no prefix) + bool prefix_foldcase_; // whether prefix is case-insensitive + size_t prefix_size_; // size of prefix (0 if no prefix) union { - uint64_t* prefix_dfa_; // "Shift DFA" for prefix + uint64_t *prefix_dfa_; // "Shift DFA" for prefix struct { - int prefix_front_; // first byte of prefix - int prefix_back_; // last byte of prefix + int prefix_front_; // first byte of prefix + int prefix_back_; // last byte of prefix }; }; - int list_count_; // count of lists (see above) - int inst_count_[kNumInst]; // count of instructions by opcode - PODArray list_heads_; // sparse array enumerating list heads - // not populated if size_ is overly large - size_t bit_state_text_max_size_; // upper bound (inclusive) on text.size() + int list_count_; // count of lists (see above) + int inst_count_[kNumInst]; // count of instructions by opcode + PODArray list_heads_; // sparse array enumerating list heads + // not populated if size_ is overly large + size_t bit_state_text_max_size_; // upper bound (inclusive) on text.size() - PODArray inst_; // pointer to instruction array - PODArray onepass_nodes_; // data for OnePass nodes + PODArray inst_; // pointer to instruction array + PODArray onepass_nodes_; // data for OnePass nodes - int64_t dfa_mem_; // Maximum memory for DFAs. - DFA* dfa_first_; // DFA cached for kFirstMatch/kManyMatch - DFA* dfa_longest_; // DFA cached for kLongestMatch/kFullMatch + int64_t dfa_mem_; // Maximum memory for DFAs. + DFA *dfa_first_; // DFA cached for kFirstMatch/kManyMatch + DFA *dfa_longest_; // DFA cached for kLongestMatch/kFullMatch - uint8_t bytemap_[256]; // map from input bytes to byte classes + uint8_t bytemap_[256]; // map from input bytes to byte classes std::once_flag dfa_first_once_; std::once_flag dfa_longest_once_; - Prog(const Prog&) = delete; - Prog& operator=(const Prog&) = delete; + Prog(const Prog &) = delete; + Prog &operator=(const Prog &) = delete; }; // std::string_view in MSVC has iterators that aren't just pointers and // that don't allow comparisons between different objects - not even if // those objects are views into the same string! Thus, we provide these // conversion functions for convenience. -static inline const char* BeginPtr(const StringPiece& s) { - return s.data(); -} -static inline const char* EndPtr(const StringPiece& s) { +static inline const char *BeginPtr(const StringPiece &s) { return s.data(); } +static inline const char *EndPtr(const StringPiece &s) { return s.data() + s.size(); } -} // namespace re2 +} // namespace re2 -#endif // RE2_PROG_H_ +#endif // RE2_PROG_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h index 449162a2..a6fb4416 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h @@ -202,11 +202,11 @@ // RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d)); // will leave 64 in a, b, c, and d. -#include -#include #include #include #include +#include +#include #include #include #include @@ -220,7 +220,7 @@ namespace re2 { class Prog; class Regexp; -} // namespace re2 +} // namespace re2 namespace re2 { @@ -228,7 +228,7 @@ namespace re2 { // pre-compiled regular expression. An "RE2" object is safe for // concurrent use by multiple threads. class RE2 { - public: +public: // We convert user-passed pointers into special Arg objects class Arg; class Options; @@ -243,20 +243,20 @@ class RE2 { ErrorInternal, // Parse errors - ErrorBadEscape, // bad escape sequence - ErrorBadCharClass, // bad character class - ErrorBadCharRange, // bad character class range - ErrorMissingBracket, // missing closing ] - ErrorMissingParen, // missing closing ) - ErrorUnexpectedParen, // unexpected closing ) - ErrorTrailingBackslash, // trailing \ at end of regexp - ErrorRepeatArgument, // repeat argument missing, e.g. "*" - ErrorRepeatSize, // bad repetition argument - ErrorRepeatOp, // bad repetition operator - ErrorBadPerlOp, // bad perl operator - ErrorBadUTF8, // invalid UTF-8 in regexp - ErrorBadNamedCapture, // bad named capture group - ErrorPatternTooLarge // pattern too large (compile failed) + ErrorBadEscape, // bad escape sequence + ErrorBadCharClass, // bad character class + ErrorBadCharRange, // bad character class range + ErrorMissingBracket, // missing closing ] + ErrorMissingParen, // missing closing ) + ErrorUnexpectedParen, // unexpected closing ) + ErrorTrailingBackslash, // trailing \ at end of regexp + ErrorRepeatArgument, // repeat argument missing, e.g. "*" + ErrorRepeatSize, // bad repetition argument + ErrorRepeatOp, // bad repetition operator + ErrorBadPerlOp, // bad perl operator + ErrorBadUTF8, // invalid UTF-8 in regexp + ErrorBadNamedCapture, // bad named capture group + ErrorPatternTooLarge // pattern too large (compile failed) }; // Predefined common options. @@ -267,32 +267,32 @@ class RE2 { enum CannedOptions { DefaultOptions = 0, Latin1, // treat input as Latin-1 (default UTF-8) - POSIX, // POSIX syntax, leftmost-longest match - Quiet // do not log about regexp parse errors + POSIX, // POSIX syntax, leftmost-longest match + Quiet // do not log about regexp parse errors }; // Need to have the const char* and const std::string& forms for implicit // conversions when passing string literals to FullMatch and PartialMatch. // Otherwise the StringPiece form would be sufficient. - RE2(const char* pattern); - RE2(const std::string& pattern); - RE2(const StringPiece& pattern); - RE2(const StringPiece& pattern, const Options& options); + RE2(const char *pattern); + RE2(const std::string &pattern); + RE2(const StringPiece &pattern); + RE2(const StringPiece &pattern, const Options &options); ~RE2(); // Not copyable. // RE2 objects are expensive. You should probably use std::shared_ptr // instead. If you really must copy, RE2(first.pattern(), first.options()) // effectively does so: it produces a second object that mimics the first. - RE2(const RE2&) = delete; - RE2& operator=(const RE2&) = delete; + RE2(const RE2 &) = delete; + RE2 &operator=(const RE2 &) = delete; // Not movable. // RE2 objects are thread-safe and logically immutable. You should probably // use std::unique_ptr instead. Otherwise, consider std::deque if // direct emplacement into a container is desired. If you really must move, // be prepared to submit a design document along with your feature request. - RE2(RE2&&) = delete; - RE2& operator=(RE2&&) = delete; + RE2(RE2 &&) = delete; + RE2 &operator=(RE2 &&) = delete; // Returns whether RE2 was created properly. bool ok() const { return error_code() == NoError; } @@ -300,11 +300,11 @@ class RE2 { // The string specification for this RE2. E.g. // RE2 re("ab*c?d+"); // re.pattern(); // "ab*c?d+" - const std::string& pattern() const { return *pattern_; } + const std::string &pattern() const { return *pattern_; } // If RE2 could not be created properly, returns an error string. // Else returns the empty string. - const std::string& error() const { return *error_; } + const std::string &error() const { return *error_; } // If RE2 could not be created properly, returns an error code. // Else returns RE2::NoError (== 0). @@ -312,7 +312,7 @@ class RE2 { // If RE2 could not be created properly, returns the offending // portion of the regexp. - const std::string& error_arg() const { return *error_arg_; } + const std::string &error_arg() const { return *error_arg_; } // Returns the program size, a very approximate measure of a regexp's "cost". // Larger numbers are more expensive than smaller numbers. @@ -322,13 +322,13 @@ class RE2 { // If histogram is not null, outputs the program fanout // as a histogram bucketed by powers of 2. // Returns the number of the largest non-empty bucket. - int ProgramFanout(std::vector* histogram) const; - int ReverseProgramFanout(std::vector* histogram) const; + int ProgramFanout(std::vector *histogram) const; + int ReverseProgramFanout(std::vector *histogram) const; // Returns the underlying Regexp; not for general use. // Returns entire_regexp_ so that callers don't need // to know about prefix_ and prefix_foldcase_. - re2::Regexp* Regexp() const { return entire_regexp_; } + re2::Regexp *Regexp() const { return entire_regexp_; } /***** The array-based matching interface ******/ @@ -336,29 +336,29 @@ class RE2 { // the functions whose names are the prefix before the 'N'. It is sometimes // useful to invoke them directly, but the syntax is awkward, so the 'N'-less // versions should be preferred. - static bool FullMatchN(const StringPiece& text, const RE2& re, - const Arg* const args[], int n); - static bool PartialMatchN(const StringPiece& text, const RE2& re, - const Arg* const args[], int n); - static bool ConsumeN(StringPiece* input, const RE2& re, - const Arg* const args[], int n); - static bool FindAndConsumeN(StringPiece* input, const RE2& re, - const Arg* const args[], int n); - - private: + static bool FullMatchN(const StringPiece &text, const RE2 &re, + const Arg *const args[], int n); + static bool PartialMatchN(const StringPiece &text, const RE2 &re, + const Arg *const args[], int n); + static bool ConsumeN(StringPiece *input, const RE2 &re, + const Arg *const args[], int n); + static bool FindAndConsumeN(StringPiece *input, const RE2 &re, + const Arg *const args[], int n); + +private: template - static inline bool Apply(F f, SP sp, const RE2& re) { + static inline bool Apply(F f, SP sp, const RE2 &re) { return f(sp, re, NULL, 0); } template - static inline bool Apply(F f, SP sp, const RE2& re, const A&... a) { - const Arg* const args[] = {&a...}; + static inline bool Apply(F f, SP sp, const RE2 &re, const A &...a) { + const Arg *const args[] = {&a...}; const int n = sizeof...(a); return f(sp, re, args, n); } - public: +public: // In order to allow FullMatch() et al. to be called with a varying number // of arguments of varying types, we use two layers of variadic templates. // The first layer constructs the temporary Arg objects. The second layer @@ -395,7 +395,7 @@ class RE2 { // int number; // RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number); template - static bool FullMatch(const StringPiece& text, const RE2& re, A&&... a) { + static bool FullMatch(const StringPiece &text, const RE2 &re, A &&...a) { return Apply(FullMatchN, text, re, Arg(std::forward(a))...); } @@ -411,7 +411,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool PartialMatch(const StringPiece& text, const RE2& re, A&&... a) { + static bool PartialMatch(const StringPiece &text, const RE2 &re, A &&...a) { return Apply(PartialMatchN, text, re, Arg(std::forward(a))...); } @@ -429,7 +429,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool Consume(StringPiece* input, const RE2& re, A&&... a) { + static bool Consume(StringPiece *input, const RE2 &re, A &&...a) { return Apply(ConsumeN, input, re, Arg(std::forward(a))...); } @@ -447,7 +447,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool FindAndConsume(StringPiece* input, const RE2& re, A&&... a) { + static bool FindAndConsume(StringPiece *input, const RE2 &re, A &&...a) { return Apply(FindAndConsumeN, input, re, Arg(std::forward(a))...); } @@ -464,9 +464,8 @@ class RE2 { // // Returns true if the pattern matches and a replacement occurs, // false otherwise. - static bool Replace(std::string* str, - const RE2& re, - const StringPiece& rewrite); + static bool Replace(std::string *str, const RE2 &re, + const StringPiece &rewrite); // Like Replace(), except replaces successive non-overlapping occurrences // of the pattern in the string with the rewrite. E.g. @@ -481,9 +480,8 @@ class RE2 { // replacing "ana" within "banana" makes only one replacement, not two. // // Returns the number of replacements made. - static int GlobalReplace(std::string* str, - const RE2& re, - const StringPiece& rewrite); + static int GlobalReplace(std::string *str, const RE2 &re, + const StringPiece &rewrite); // Like Replace, except that if the pattern matches, "rewrite" // is copied into "out" with substitutions. The non-matching @@ -493,10 +491,8 @@ class RE2 { // successfully; if no match occurs, the string is left unaffected. // // REQUIRES: "text" must not alias any part of "*out". - static bool Extract(const StringPiece& text, - const RE2& re, - const StringPiece& rewrite, - std::string* out); + static bool Extract(const StringPiece &text, const RE2 &re, + const StringPiece &rewrite, std::string *out); // Escapes all potentially meaningful regexp characters in // 'unquoted'. The returned string, used as a regular expression, @@ -504,7 +500,7 @@ class RE2 { // 1.5-2.0? // may become: // 1\.5\-2\.0\? - static std::string QuoteMeta(const StringPiece& unquoted); + static std::string QuoteMeta(const StringPiece &unquoted); // Computes range for any strings matching regexp. The min and max can in // some cases be arbitrarily precise, so the caller gets to specify the @@ -520,16 +516,15 @@ class RE2 { // do not compile down to infinite repetitions. // // Returns true on success, false on error. - bool PossibleMatchRange(std::string* min, std::string* max, - int maxlen) const; + bool PossibleMatchRange(std::string *min, std::string *max, int maxlen) const; // Generic matching interface // Type of match. enum Anchor { - UNANCHORED, // No anchoring - ANCHOR_START, // Anchor at start only - ANCHOR_BOTH // Anchor at start and end + UNANCHORED, // No anchoring + ANCHOR_START, // Anchor at start only + ANCHOR_BOTH // Anchor at start and end }; // Return the number of capturing subpatterns, or -1 if the @@ -541,12 +536,12 @@ class RE2 { // The map records the index of the leftmost group // with the given name. // Only valid until the re is deleted. - const std::map& NamedCapturingGroups() const; + const std::map &NamedCapturingGroups() const; // Return a map from capturing indices to names. // The map has no entries for unnamed groups. // Only valid until the re is deleted. - const std::map& CapturingGroupNames() const; + const std::map &CapturingGroupNames() const; // General matching routine. // Match against text starting at offset startpos @@ -569,12 +564,8 @@ class RE2 { // empty string, but note that on return, it will not be possible to tell // whether submatch i matched the empty string or did not match: // either way, submatch[i].data() == NULL. - bool Match(const StringPiece& text, - size_t startpos, - size_t endpos, - Anchor re_anchor, - StringPiece* submatch, - int nsubmatch) const; + bool Match(const StringPiece &text, size_t startpos, size_t endpos, + Anchor re_anchor, StringPiece *submatch, int nsubmatch) const; // Check that the given rewrite string is suitable for use with this // regular expression. It checks that: @@ -584,26 +575,23 @@ class RE2 { // '\' followed by anything other than a digit or '\'. // A true return value guarantees that Replace() and Extract() won't // fail because of a bad rewrite string. - bool CheckRewriteString(const StringPiece& rewrite, - std::string* error) const; + bool CheckRewriteString(const StringPiece &rewrite, std::string *error) const; // Returns the maximum submatch needed for the rewrite to be done by // Replace(). E.g. if rewrite == "foo \\2,\\1", returns 2. - static int MaxSubmatch(const StringPiece& rewrite); + static int MaxSubmatch(const StringPiece &rewrite); // Append the "rewrite" string, with backslash substitutions from "vec", // to string "out". // Returns true on success. This method can fail because of a malformed // rewrite string. CheckRewriteString guarantees that the rewrite will // be sucessful. - bool Rewrite(std::string* out, - const StringPiece& rewrite, - const StringPiece* vec, - int veclen) const; + bool Rewrite(std::string *out, const StringPiece &rewrite, + const StringPiece *vec, int veclen) const; // Constructor options class Options { - public: + public: // The options are (defaults in parentheses): // // utf8 (true) text and pattern are UTF-8; otherwise Latin-1 @@ -655,28 +643,16 @@ class RE2 { // If this happens too often, RE2 falls back on the NFA implementation. // For now, make the default budget something close to Code Search. - static const int kDefaultMaxMem = 8<<20; - - enum Encoding { - EncodingUTF8 = 1, - EncodingLatin1 - }; - - Options() : - max_mem_(kDefaultMaxMem), - encoding_(EncodingUTF8), - posix_syntax_(false), - longest_match_(false), - log_errors_(true), - literal_(false), - never_nl_(false), - dot_nl_(false), - never_capture_(false), - case_sensitive_(true), - perl_classes_(false), - word_boundary_(false), - one_line_(false) { - } + static const int kDefaultMaxMem = 8 << 20; + + enum Encoding { EncodingUTF8 = 1, EncodingLatin1 }; + + Options() + : max_mem_(kDefaultMaxMem), encoding_(EncodingUTF8), + posix_syntax_(false), longest_match_(false), log_errors_(true), + literal_(false), never_nl_(false), dot_nl_(false), + never_capture_(false), case_sensitive_(true), perl_classes_(false), + word_boundary_(false), one_line_(false) {} /*implicit*/ Options(CannedOptions); @@ -719,13 +695,11 @@ class RE2 { bool one_line() const { return one_line_; } void set_one_line(bool b) { one_line_ = b; } - void Copy(const Options& src) { - *this = src; - } + void Copy(const Options &src) { *this = src; } int ParseFlags() const; - private: + private: int64_t max_mem_; Encoding encoding_; bool posix_syntax_; @@ -742,55 +716,49 @@ class RE2 { }; // Returns the options set in the constructor. - const Options& options() const { return options_; } + const Options &options() const { return options_; } // Argument converters; see below. - template - static Arg CRadix(T* ptr); - template - static Arg Hex(T* ptr); - template - static Arg Octal(T* ptr); + template static Arg CRadix(T *ptr); + template static Arg Hex(T *ptr); + template static Arg Octal(T *ptr); // Controls the maximum count permitted by GlobalReplace(); -1 is unlimited. // FOR FUZZING ONLY. static void FUZZING_ONLY_set_maximum_global_replace_count(int i); - private: - void Init(const StringPiece& pattern, const Options& options); +private: + void Init(const StringPiece &pattern, const Options &options); - bool DoMatch(const StringPiece& text, - Anchor re_anchor, - size_t* consumed, - const Arg* const args[], - int n) const; + bool DoMatch(const StringPiece &text, Anchor re_anchor, size_t *consumed, + const Arg *const args[], int n) const; - re2::Prog* ReverseProg() const; + re2::Prog *ReverseProg() const; // First cache line is relatively cold fields. - const std::string* pattern_; // string regular expression - Options options_; // option flags - re2::Regexp* entire_regexp_; // parsed regular expression - re2::Regexp* suffix_regexp_; // parsed regular expression, prefix_ removed - const std::string* error_; // error indicator (or points to empty string) - const std::string* error_arg_; // fragment of regexp showing error (or ditto) + const std::string *pattern_; // string regular expression + Options options_; // option flags + re2::Regexp *entire_regexp_; // parsed regular expression + re2::Regexp *suffix_regexp_; // parsed regular expression, prefix_ removed + const std::string *error_; // error indicator (or points to empty string) + const std::string *error_arg_; // fragment of regexp showing error (or ditto) // Second cache line is relatively hot fields. // These are ordered oddly to pack everything. - int num_captures_; // number of capturing groups - ErrorCode error_code_ : 29; // error code (29 bits is more than enough) - bool longest_match_ : 1; // cached copy of options_.longest_match() - bool is_one_pass_ : 1; // can use prog_->SearchOnePass? - bool prefix_foldcase_ : 1; // prefix_ is ASCII case-insensitive - std::string prefix_; // required prefix (before suffix_regexp_) - re2::Prog* prog_; // compiled program for regexp + int num_captures_; // number of capturing groups + ErrorCode error_code_ : 29; // error code (29 bits is more than enough) + bool longest_match_ : 1; // cached copy of options_.longest_match() + bool is_one_pass_ : 1; // can use prog_->SearchOnePass? + bool prefix_foldcase_ : 1; // prefix_ is ASCII case-insensitive + std::string prefix_; // required prefix (before suffix_regexp_) + re2::Prog *prog_; // compiled program for regexp // Reverse Prog for DFA execution only - mutable re2::Prog* rprog_; + mutable re2::Prog *rprog_; // Map from capture names to indices - mutable const std::map* named_groups_; + mutable const std::map *named_groups_; // Map from capture indices to names - mutable const std::map* group_names_; + mutable const std::map *group_names_; mutable std::once_flag rprog_once_; mutable std::once_flag named_groups_once_; @@ -812,8 +780,7 @@ template <> struct Parse3ary : public std::true_type {}; template <> struct Parse3ary : public std::true_type {}; template <> struct Parse3ary : public std::true_type {}; -template -bool Parse(const char* str, size_t n, T* dest); +template bool Parse(const char *str, size_t n, T *dest); // Types for which the 4-ary Parse() function template has specializations. template struct Parse4ary : public std::false_type {}; @@ -826,101 +793,96 @@ template <> struct Parse4ary : public std::true_type {}; template <> struct Parse4ary : public std::true_type {}; template <> struct Parse4ary : public std::true_type {}; -template -bool Parse(const char* str, size_t n, T* dest, int radix); +template bool Parse(const char *str, size_t n, T *dest, int radix); -} // namespace re2_internal +} // namespace re2_internal class RE2::Arg { - private: +private: template - using CanParse3ary = typename std::enable_if< - re2_internal::Parse3ary::value, - int>::type; + using CanParse3ary = + typename std::enable_if::value, int>::type; template - using CanParse4ary = typename std::enable_if< - re2_internal::Parse4ary::value, - int>::type; + using CanParse4ary = + typename std::enable_if::value, int>::type; #if !defined(_MSC_VER) template using CanParseFrom = typename std::enable_if< std::is_member_function_pointer< - decltype(static_cast( + decltype(static_cast( &T::ParseFrom))>::value, int>::type; #endif - public: +public: Arg() : Arg(nullptr) {} Arg(std::nullptr_t ptr) : arg_(ptr), parser_(DoNothing) {} template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParse3ary) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParse3ary) {} template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParse4ary) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParse4ary) {} #if !defined(_MSC_VER) template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParseFrom) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParseFrom) {} #endif - typedef bool (*Parser)(const char* str, size_t n, void* dest); + typedef bool (*Parser)(const char *str, size_t n, void *dest); template - Arg(T* ptr, Parser parser) : arg_(ptr), parser_(parser) {} + Arg(T *ptr, Parser parser) : arg_(ptr), parser_(parser) {} - bool Parse(const char* str, size_t n) const { + bool Parse(const char *str, size_t n) const { return (*parser_)(str, n, arg_); } - private: - static bool DoNothing(const char* /*str*/, size_t /*n*/, void* /*dest*/) { +private: + static bool DoNothing(const char * /*str*/, size_t /*n*/, void * /*dest*/) { return true; } template - static bool DoParse3ary(const char* str, size_t n, void* dest) { - return re2_internal::Parse(str, n, reinterpret_cast(dest)); + static bool DoParse3ary(const char *str, size_t n, void *dest) { + return re2_internal::Parse(str, n, reinterpret_cast(dest)); } template - static bool DoParse4ary(const char* str, size_t n, void* dest) { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 10); + static bool DoParse4ary(const char *str, size_t n, void *dest) { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 10); } #if !defined(_MSC_VER) template - static bool DoParseFrom(const char* str, size_t n, void* dest) { - if (dest == NULL) return true; - return reinterpret_cast(dest)->ParseFrom(str, n); + static bool DoParseFrom(const char *str, size_t n, void *dest) { + if (dest == NULL) + return true; + return reinterpret_cast(dest)->ParseFrom(str, n); } #endif - void* arg_; - Parser parser_; + void *arg_; + Parser parser_; }; -template -inline RE2::Arg RE2::CRadix(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 0); +template inline RE2::Arg RE2::CRadix(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 0); }); } -template -inline RE2::Arg RE2::Hex(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 16); +template inline RE2::Arg RE2::Hex(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 16); }); } -template -inline RE2::Arg RE2::Octal(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 8); +template inline RE2::Arg RE2::Octal(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 8); }); } @@ -941,38 +903,38 @@ inline RE2::Arg RE2::Octal(T* ptr) { // it constructs: that's a feature, so that it can be used // for global and function static variables. class LazyRE2 { - private: +private: struct NoArg {}; - public: - typedef RE2 element_type; // support std::pointer_traits +public: + typedef RE2 element_type; // support std::pointer_traits // Constructor omitted to preserve braced initialization in C++98. // Pretend to be a pointer to Type (never NULL due to on-demand creation): - RE2& operator*() const { return *get(); } - RE2* operator->() const { return get(); } + RE2 &operator*() const { return *get(); } + RE2 *operator->() const { return get(); } // Named accessor/initializer: - RE2* get() const { + RE2 *get() const { std::call_once(once_, &LazyRE2::Init, this); return ptr_; } // All data fields must be public to support {"foo"} initialization. - const char* pattern_; + const char *pattern_; RE2::CannedOptions options_; NoArg barrier_against_excess_initializers_; - mutable RE2* ptr_; + mutable RE2 *ptr_; mutable std::once_flag once_; - private: - static void Init(const LazyRE2* lazy_re2) { +private: + static void Init(const LazyRE2 *lazy_re2) { lazy_re2->ptr_ = new RE2(lazy_re2->pattern_, lazy_re2->options_); } - void operator=(const LazyRE2&); // disallowed + void operator=(const LazyRE2 &); // disallowed }; namespace hooks { @@ -985,7 +947,8 @@ namespace hooks { // As per https://github.com/google/re2/issues/325, thread_local support in // MinGW seems to be buggy. (FWIW, Abseil folks also avoid it.) #define RE2_HAVE_THREAD_LOCAL -#if (defined(__APPLE__) && !(defined(TARGET_OS_OSX) && TARGET_OS_OSX)) || defined(__MINGW32__) +#if (defined(__APPLE__) && !(defined(TARGET_OS_OSX) && TARGET_OS_OSX)) || \ + defined(__MINGW32__) #undef RE2_HAVE_THREAD_LOCAL #endif @@ -999,7 +962,7 @@ namespace hooks { // could result in infinite mutual recursion. To discourage that possibility, // RE2 will not maintain the context pointer correctly when used in that way. #ifdef RE2_HAVE_THREAD_LOCAL -extern thread_local const RE2* context; +extern thread_local const RE2 *context; #endif struct DFAStateCacheReset { @@ -1011,21 +974,21 @@ struct DFASearchFailure { // Nothing yet... }; -#define DECLARE_HOOK(type) \ - using type##Callback = void(const type&); \ - void Set##type##Hook(type##Callback* cb); \ - type##Callback* Get##type##Hook(); +#define DECLARE_HOOK(type) \ + using type##Callback = void(const type &); \ + void Set##type##Hook(type##Callback *cb); \ + type##Callback *Get##type##Hook(); DECLARE_HOOK(DFAStateCacheReset) DECLARE_HOOK(DFASearchFailure) #undef DECLARE_HOOK -} // namespace hooks +} // namespace hooks -} // namespace re2 +} // namespace re2 -using re2::RE2; using re2::LazyRE2; +using re2::RE2; -#endif // RE2_RE2_H_ +#endif // RE2_RE2_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h index b6446f9f..61343ca3 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h @@ -18,9 +18,9 @@ // of regular expressions. // // Any operation that traverses the Regexp structures should be written -// using Regexp::Walker (see walker-inl.h), not recursively, because deeply nested -// regular expressions such as x++++++++++++++++++++... might cause recursive -// traversals to overflow the stack. +// using Regexp::Walker (see walker-inl.h), not recursively, because deeply +// nested regular expressions such as x++++++++++++++++++++... might cause +// recursive traversals to overflow the stack. // // It is the caller's responsibility to provide appropriate mutual exclusion // around manipulation of the regexps. RE2 does this. @@ -86,16 +86,16 @@ // form accessible to clients, so that client code can analyze the // parsed regular expressions. -#include -#include #include #include +#include +#include #include -#include "util/util.h" +#include "re2/stringpiece.h" #include "util/logging.h" #include "util/utf.h" -#include "re2/stringpiece.h" +#include "util/util.h" namespace re2 { @@ -173,36 +173,39 @@ enum RegexpStatusCode { kRegexpInternalError, // Parse errors - kRegexpBadEscape, // bad escape sequence - kRegexpBadCharClass, // bad character class - kRegexpBadCharRange, // bad character class range - kRegexpMissingBracket, // missing closing ] - kRegexpMissingParen, // missing closing ) - kRegexpUnexpectedParen, // unexpected closing ) - kRegexpTrailingBackslash, // at end of regexp - kRegexpRepeatArgument, // repeat argument missing, e.g. "*" - kRegexpRepeatSize, // bad repetition argument - kRegexpRepeatOp, // bad repetition operator - kRegexpBadPerlOp, // bad perl operator - kRegexpBadUTF8, // invalid UTF-8 in regexp - kRegexpBadNamedCapture, // bad named capture + kRegexpBadEscape, // bad escape sequence + kRegexpBadCharClass, // bad character class + kRegexpBadCharRange, // bad character class range + kRegexpMissingBracket, // missing closing ] + kRegexpMissingParen, // missing closing ) + kRegexpUnexpectedParen, // unexpected closing ) + kRegexpTrailingBackslash, // at end of regexp + kRegexpRepeatArgument, // repeat argument missing, e.g. "*" + kRegexpRepeatSize, // bad repetition argument + kRegexpRepeatOp, // bad repetition operator + kRegexpBadPerlOp, // bad perl operator + kRegexpBadUTF8, // invalid UTF-8 in regexp + kRegexpBadNamedCapture, // bad named capture }; // Error status for certain operations. class RegexpStatus { - public: +public: RegexpStatus() : code_(kRegexpSuccess), tmp_(NULL) {} ~RegexpStatus() { delete tmp_; } void set_code(RegexpStatusCode code) { code_ = code; } - void set_error_arg(const StringPiece& error_arg) { error_arg_ = error_arg; } - void set_tmp(std::string* tmp) { delete tmp_; tmp_ = tmp; } + void set_error_arg(const StringPiece &error_arg) { error_arg_ = error_arg; } + void set_tmp(std::string *tmp) { + delete tmp_; + tmp_ = tmp; + } RegexpStatusCode code() const { return code_; } - const StringPiece& error_arg() const { return error_arg_; } + const StringPiece &error_arg() const { return error_arg_; } bool ok() const { return code() == kRegexpSuccess; } // Copies state from status. - void Copy(const RegexpStatus& status); + void Copy(const RegexpStatus &status); // Returns text equivalent of code, e.g.: // "Bad character class" @@ -212,21 +215,21 @@ class RegexpStatus { // "Bad character class: [z-a]" std::string Text() const; - private: - RegexpStatusCode code_; // Kind of error - StringPiece error_arg_; // Piece of regexp containing syntax error. - std::string* tmp_; // Temporary storage, possibly where error_arg_ is. +private: + RegexpStatusCode code_; // Kind of error + StringPiece error_arg_; // Piece of regexp containing syntax error. + std::string *tmp_; // Temporary storage, possibly where error_arg_ is. - RegexpStatus(const RegexpStatus&) = delete; - RegexpStatus& operator=(const RegexpStatus&) = delete; + RegexpStatus(const RegexpStatus &) = delete; + RegexpStatus &operator=(const RegexpStatus &) = delete; }; // Compiled form; see prog.h class Prog; struct RuneRange { - RuneRange() : lo(0), hi(0) { } - RuneRange(int l, int h) : lo(l), hi(h) { } + RuneRange() : lo(0), hi(0) {} + RuneRange(int l, int h) : lo(l), hi(h) {} Rune lo; Rune hi; }; @@ -234,7 +237,7 @@ struct RuneRange { // Less-than on RuneRanges treats a == b if they overlap at all. // This lets us look in a set to find the range covering a particular Rune. struct RuneRangeLess { - bool operator()(const RuneRange& a, const RuneRange& b) const { + bool operator()(const RuneRange &a, const RuneRange &b) const { return a.hi < b.lo; } }; @@ -242,25 +245,25 @@ struct RuneRangeLess { class CharClassBuilder; class CharClass { - public: +public: void Delete(); - typedef RuneRange* iterator; + typedef RuneRange *iterator; iterator begin() { return ranges_; } iterator end() { return ranges_ + nranges_; } int size() { return nrunes_; } bool empty() { return nrunes_ == 0; } - bool full() { return nrunes_ == Runemax+1; } + bool full() { return nrunes_ == Runemax + 1; } bool FoldsASCII() { return folds_ascii_; } bool Contains(Rune r) const; - CharClass* Negate(); + CharClass *Negate(); - private: +private: CharClass(); // not implemented - ~CharClass(); // not implemented - static CharClass* New(size_t maxranges); + ~CharClass(); // not implemented + static CharClass *New(size_t maxranges); friend class CharClassBuilder; @@ -269,54 +272,52 @@ class CharClass { RuneRange *ranges_; int nranges_; - CharClass(const CharClass&) = delete; - CharClass& operator=(const CharClass&) = delete; + CharClass(const CharClass &) = delete; + CharClass &operator=(const CharClass &) = delete; }; class Regexp { - public: - +public: // Flags for parsing. Can be ORed together. enum ParseFlags { - NoParseFlags = 0, - FoldCase = 1<<0, // Fold case during matching (case-insensitive). - Literal = 1<<1, // Treat s as literal string instead of a regexp. - ClassNL = 1<<2, // Allow char classes like [^a-z] and \D and \s - // and [[:space:]] to match newline. - DotNL = 1<<3, // Allow . to match newline. - MatchNL = ClassNL | DotNL, - OneLine = 1<<4, // Treat ^ and $ as only matching at beginning and - // end of text, not around embedded newlines. - // (Perl's default) - Latin1 = 1<<5, // Regexp and text are in Latin1, not UTF-8. - NonGreedy = 1<<6, // Repetition operators are non-greedy by default. - PerlClasses = 1<<7, // Allow Perl character classes like \d. - PerlB = 1<<8, // Allow Perl's \b and \B. - PerlX = 1<<9, // Perl extensions: - // non-capturing parens - (?: ) - // non-greedy operators - *? +? ?? {}? - // flag edits - (?i) (?-i) (?i: ) - // i - FoldCase - // m - !OneLine - // s - DotNL - // U - NonGreedy - // line ends: \A \z - // \Q and \E to disable/enable metacharacters - // (?Pexpr) for named captures - // \C to match any single byte - UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group - // and \P{Han} for its negation. - NeverNL = 1<<11, // Never match NL, even if the regexp mentions - // it explicitly. - NeverCapture = 1<<12, // Parse all parens as non-capturing. + NoParseFlags = 0, + FoldCase = 1 << 0, // Fold case during matching (case-insensitive). + Literal = 1 << 1, // Treat s as literal string instead of a regexp. + ClassNL = 1 << 2, // Allow char classes like [^a-z] and \D and \s + // and [[:space:]] to match newline. + DotNL = 1 << 3, // Allow . to match newline. + MatchNL = ClassNL | DotNL, + OneLine = 1 << 4, // Treat ^ and $ as only matching at beginning and + // end of text, not around embedded newlines. + // (Perl's default) + Latin1 = 1 << 5, // Regexp and text are in Latin1, not UTF-8. + NonGreedy = 1 << 6, // Repetition operators are non-greedy by default. + PerlClasses = 1 << 7, // Allow Perl character classes like \d. + PerlB = 1 << 8, // Allow Perl's \b and \B. + PerlX = 1 << 9, // Perl extensions: + // non-capturing parens - (?: ) + // non-greedy operators - *? +? ?? {}? + // flag edits - (?i) (?-i) (?i: ) + // i - FoldCase + // m - !OneLine + // s - DotNL + // U - NonGreedy + // line ends: \A \z + // \Q and \E to disable/enable metacharacters + // (?Pexpr) for named captures + // \C to match any single byte + UnicodeGroups = 1 << 10, // Allow \p{Han} for Unicode Han group + // and \P{Han} for its negation. + NeverNL = 1 << 11, // Never match NL, even if the regexp mentions + // it explicitly. + NeverCapture = 1 << 12, // Parse all parens as non-capturing. // As close to Perl as we can get. - LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX | - UnicodeGroups, + LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX | UnicodeGroups, // Internal use only. - WasDollar = 1<<13, // on kRegexpEndText: was $ in regexp text - AllParseFlags = (1<<14)-1, + WasDollar = 1 << 13, // on kRegexpEndText: was $ in regexp text + AllParseFlags = (1 << 14) - 1, }; // Get. No set, Regexps are logically immutable once created. @@ -324,27 +325,54 @@ class Regexp { int nsub() { return nsub_; } bool simple() { return simple_ != 0; } ParseFlags parse_flags() { return static_cast(parse_flags_); } - int Ref(); // For testing. + int Ref(); // For testing. - Regexp** sub() { - if(nsub_ <= 1) + Regexp **sub() { + if (nsub_ <= 1) return &subone_; else return submany_; } - int min() { DCHECK_EQ(op_, kRegexpRepeat); return min_; } - int max() { DCHECK_EQ(op_, kRegexpRepeat); return max_; } - Rune rune() { DCHECK_EQ(op_, kRegexpLiteral); return rune_; } - CharClass* cc() { DCHECK_EQ(op_, kRegexpCharClass); return cc_; } - int cap() { DCHECK_EQ(op_, kRegexpCapture); return cap_; } - const std::string* name() { DCHECK_EQ(op_, kRegexpCapture); return name_; } - Rune* runes() { DCHECK_EQ(op_, kRegexpLiteralString); return runes_; } - int nrunes() { DCHECK_EQ(op_, kRegexpLiteralString); return nrunes_; } - int match_id() { DCHECK_EQ(op_, kRegexpHaveMatch); return match_id_; } + int min() { + DCHECK_EQ(op_, kRegexpRepeat); + return min_; + } + int max() { + DCHECK_EQ(op_, kRegexpRepeat); + return max_; + } + Rune rune() { + DCHECK_EQ(op_, kRegexpLiteral); + return rune_; + } + CharClass *cc() { + DCHECK_EQ(op_, kRegexpCharClass); + return cc_; + } + int cap() { + DCHECK_EQ(op_, kRegexpCapture); + return cap_; + } + const std::string *name() { + DCHECK_EQ(op_, kRegexpCapture); + return name_; + } + Rune *runes() { + DCHECK_EQ(op_, kRegexpLiteralString); + return runes_; + } + int nrunes() { + DCHECK_EQ(op_, kRegexpLiteralString); + return nrunes_; + } + int match_id() { + DCHECK_EQ(op_, kRegexpHaveMatch); + return match_id_; + } // Increments reference count, returns object as convenience. - Regexp* Incref(); + Regexp *Incref(); // Decrements reference count and deletes this object if count reaches 0. void Decref(); @@ -352,8 +380,8 @@ class Regexp { // Parses string s to produce regular expression, returned. // Caller must release return value with re->Decref(). // On failure, sets *status (if status != NULL) and returns NULL. - static Regexp* Parse(const StringPiece& s, ParseFlags flags, - RegexpStatus* status); + static Regexp *Parse(const StringPiece &s, ParseFlags flags, + RegexpStatus *status); // Returns a _new_ simplified version of the current regexp. // Does not edit the current regexp. @@ -362,15 +390,15 @@ class Regexp { // into simpler terms and all Perl/POSIX features have been // removed. The result will capture exactly the same // subexpressions the original did, unless formatted with ToString. - Regexp* Simplify(); + Regexp *Simplify(); friend class CoalesceWalker; friend class SimplifyWalker; // Parses the regexp src and then simplifies it and sets *dst to the // string representation of the simplified form. Returns true on success. // Returns false and sets *status (if status != NULL) on parse error. - static bool SimplifyRegexp(const StringPiece& src, ParseFlags flags, - std::string* dst, RegexpStatus* status); + static bool SimplifyRegexp(const StringPiece &src, ParseFlags flags, + std::string *dst, RegexpStatus *status); // Returns the number of capturing groups in the regexp. int NumCaptures(); @@ -379,12 +407,12 @@ class Regexp { // Returns a map from names to capturing group indices, // or NULL if the regexp contains no named capture groups. // The caller is responsible for deleting the map. - std::map* NamedCaptures(); + std::map *NamedCaptures(); // Returns a map from capturing group indices to capturing group // names or NULL if the regexp contains no named capture groups. The // caller is responsible for deleting the map. - std::map* CaptureNames(); + std::map *CaptureNames(); // Returns a string representation of the current regexp, // using as few parentheses as possible. @@ -393,35 +421,35 @@ class Regexp { // Convenience functions. They consume the passed reference, // so in many cases you should use, e.g., Plus(re->Incref(), flags). // They do not consume allocated arrays like subs or runes. - static Regexp* Plus(Regexp* sub, ParseFlags flags); - static Regexp* Star(Regexp* sub, ParseFlags flags); - static Regexp* Quest(Regexp* sub, ParseFlags flags); - static Regexp* Concat(Regexp** subs, int nsubs, ParseFlags flags); - static Regexp* Alternate(Regexp** subs, int nsubs, ParseFlags flags); - static Regexp* Capture(Regexp* sub, ParseFlags flags, int cap); - static Regexp* Repeat(Regexp* sub, ParseFlags flags, int min, int max); - static Regexp* NewLiteral(Rune rune, ParseFlags flags); - static Regexp* NewCharClass(CharClass* cc, ParseFlags flags); - static Regexp* LiteralString(Rune* runes, int nrunes, ParseFlags flags); - static Regexp* HaveMatch(int match_id, ParseFlags flags); + static Regexp *Plus(Regexp *sub, ParseFlags flags); + static Regexp *Star(Regexp *sub, ParseFlags flags); + static Regexp *Quest(Regexp *sub, ParseFlags flags); + static Regexp *Concat(Regexp **subs, int nsubs, ParseFlags flags); + static Regexp *Alternate(Regexp **subs, int nsubs, ParseFlags flags); + static Regexp *Capture(Regexp *sub, ParseFlags flags, int cap); + static Regexp *Repeat(Regexp *sub, ParseFlags flags, int min, int max); + static Regexp *NewLiteral(Rune rune, ParseFlags flags); + static Regexp *NewCharClass(CharClass *cc, ParseFlags flags); + static Regexp *LiteralString(Rune *runes, int nrunes, ParseFlags flags); + static Regexp *HaveMatch(int match_id, ParseFlags flags); // Like Alternate but does not factor out common prefixes. - static Regexp* AlternateNoFactor(Regexp** subs, int nsubs, ParseFlags flags); + static Regexp *AlternateNoFactor(Regexp **subs, int nsubs, ParseFlags flags); // Debugging function. Returns string format for regexp // that makes structure clear. Does NOT use regexp syntax. std::string Dump(); // Helper traversal class, defined fully in walker-inl.h. - template class Walker; + template class Walker; // Compile to Prog. See prog.h // Reverse prog expects to be run over text backward. // Construction and execution of prog will // stay within approximately max_mem bytes of memory. // If max_mem <= 0, a reasonable default is used. - Prog* CompileToProg(int64_t max_mem); - Prog* CompileToReverseProg(int64_t max_mem); + Prog *CompileToProg(int64_t max_mem); + Prog *CompileToReverseProg(int64_t max_mem); // Whether to expect this library to find exactly the same answer as PCRE // when running this regexp. Most regexps do mimic PCRE exactly, but a few @@ -439,21 +467,20 @@ class Regexp { // follows it. // Callers should expect *prefix, *foldcase and *suffix to be "zeroed" // regardless of the return value. - bool RequiredPrefix(std::string* prefix, bool* foldcase, - Regexp** suffix); + bool RequiredPrefix(std::string *prefix, bool *foldcase, Regexp **suffix); // Whether every match of this regexp must be unanchored and // begin with a non-empty fixed string (perhaps after ASCII // case-folding). If so, returns the prefix. // Callers should expect *prefix and *foldcase to be "zeroed" // regardless of the return value. - bool RequiredPrefixForAccel(std::string* prefix, bool* foldcase); + bool RequiredPrefixForAccel(std::string *prefix, bool *foldcase); // Controls the maximum repeat count permitted by the parser. // FOR FUZZING ONLY. static void FUZZING_ONLY_set_maximum_repeat_count(int i); - private: +private: // Constructor allocates vectors as appropriate for operator. explicit Regexp(RegexpOp op, ParseFlags parse_flags); @@ -467,58 +494,58 @@ class Regexp { class ParseState; friend class ParseState; - friend bool ParseCharClass(StringPiece* s, Regexp** out_re, - RegexpStatus* status); + friend bool ParseCharClass(StringPiece *s, Regexp **out_re, + RegexpStatus *status); // Helper for testing [sic]. - friend bool RegexpEqualTestingOnly(Regexp*, Regexp*); + friend bool RegexpEqualTestingOnly(Regexp *, Regexp *); // Computes whether Regexp is already simple. bool ComputeSimple(); // Constructor that generates a Star, Plus or Quest, // squashing the pair if sub is also a Star, Plus or Quest. - static Regexp* StarPlusOrQuest(RegexpOp op, Regexp* sub, ParseFlags flags); + static Regexp *StarPlusOrQuest(RegexpOp op, Regexp *sub, ParseFlags flags); // Constructor that generates a concatenation or alternation, // enforcing the limit on the number of subexpressions for // a particular Regexp. - static Regexp* ConcatOrAlternate(RegexpOp op, Regexp** subs, int nsubs, + static Regexp *ConcatOrAlternate(RegexpOp op, Regexp **subs, int nsubs, ParseFlags flags, bool can_factor); // Returns the leading string that re starts with. // The returned Rune* points into a piece of re, // so it must not be used after the caller calls re->Decref(). - static Rune* LeadingString(Regexp* re, int* nrune, ParseFlags* flags); + static Rune *LeadingString(Regexp *re, int *nrune, ParseFlags *flags); // Removes the first n leading runes from the beginning of re. // Edits re in place. - static void RemoveLeadingString(Regexp* re, int n); + static void RemoveLeadingString(Regexp *re, int n); // Returns the leading regexp in re's top-level concatenation. // The returned Regexp* points at re or a sub-expression of re, // so it must not be used after the caller calls re->Decref(). - static Regexp* LeadingRegexp(Regexp* re); + static Regexp *LeadingRegexp(Regexp *re); // Removes LeadingRegexp(re) from re and returns the remainder. // Might edit re in place. - static Regexp* RemoveLeadingRegexp(Regexp* re); + static Regexp *RemoveLeadingRegexp(Regexp *re); // Simplifies an alternation of literal strings by factoring out // common prefixes. - static int FactorAlternation(Regexp** sub, int nsub, ParseFlags flags); + static int FactorAlternation(Regexp **sub, int nsub, ParseFlags flags); friend class FactorAlternationImpl; // Is a == b? Only efficient on regexps that have not been through // Simplify yet - the expansion of a kRegexpRepeat will make this // take a long time. Do not call on such regexps, hence private. - static bool Equal(Regexp* a, Regexp* b); + static bool Equal(Regexp *a, Regexp *b); // Allocate space for n sub-regexps. void AllocSub(int n) { DCHECK(n >= 0 && static_cast(n) == n); if (n > 1) - submany_ = new Regexp*[n]; + submany_ = new Regexp *[n]; nsub_ = static_cast(n); } @@ -562,48 +589,48 @@ class Regexp { uint16_t nsub_; static const uint16_t kMaxNsub = 0xffff; union { - Regexp** submany_; // if nsub_ > 1 - Regexp* subone_; // if nsub_ == 1 + Regexp **submany_; // if nsub_ > 1 + Regexp *subone_; // if nsub_ == 1 }; // Extra space for parse and teardown stacks. - Regexp* down_; + Regexp *down_; // Arguments to operator. See description of operators above. union { - struct { // Repeat + struct { // Repeat int max_; int min_; }; - struct { // Capture + struct { // Capture int cap_; - std::string* name_; + std::string *name_; }; - struct { // LiteralString + struct { // LiteralString int nrunes_; - Rune* runes_; + Rune *runes_; }; - struct { // CharClass + struct { // CharClass // These two could be in separate union members, // but it wouldn't save any space (there are other two-word structs) // and keeping them separate avoids confusion during parsing. - CharClass* cc_; - CharClassBuilder* ccb_; + CharClass *cc_; + CharClassBuilder *ccb_; }; - Rune rune_; // Literal - int match_id_; // HaveMatch - void *the_union_[2]; // as big as any other element, for memset + Rune rune_; // Literal + int match_id_; // HaveMatch + void *the_union_[2]; // as big as any other element, for memset }; - Regexp(const Regexp&) = delete; - Regexp& operator=(const Regexp&) = delete; + Regexp(const Regexp &) = delete; + Regexp &operator=(const Regexp &) = delete; }; // Character class set: contains non-overlapping, non-abutting RuneRanges. typedef std::set RuneRangeSet; class CharClassBuilder { - public: +public: CharClassBuilder(); typedef RuneRangeSet::iterator iterator; @@ -612,46 +639,46 @@ class CharClassBuilder { int size() { return nrunes_; } bool empty() { return nrunes_ == 0; } - bool full() { return nrunes_ == Runemax+1; } + bool full() { return nrunes_ == Runemax + 1; } bool Contains(Rune r); bool FoldsASCII(); - bool AddRange(Rune lo, Rune hi); // returns whether class changed - CharClassBuilder* Copy(); - void AddCharClass(CharClassBuilder* cc); + bool AddRange(Rune lo, Rune hi); // returns whether class changed + CharClassBuilder *Copy(); + void AddCharClass(CharClassBuilder *cc); void Negate(); void RemoveAbove(Rune r); - CharClass* GetCharClass(); + CharClass *GetCharClass(); void AddRangeFlags(Rune lo, Rune hi, Regexp::ParseFlags parse_flags); - private: - static const uint32_t AlphaMask = (1<<26) - 1; - uint32_t upper_; // bitmap of A-Z - uint32_t lower_; // bitmap of a-z +private: + static const uint32_t AlphaMask = (1 << 26) - 1; + uint32_t upper_; // bitmap of A-Z + uint32_t lower_; // bitmap of a-z int nrunes_; RuneRangeSet ranges_; - CharClassBuilder(const CharClassBuilder&) = delete; - CharClassBuilder& operator=(const CharClassBuilder&) = delete; + CharClassBuilder(const CharClassBuilder &) = delete; + CharClassBuilder &operator=(const CharClassBuilder &) = delete; }; // Bitwise ops on ParseFlags produce ParseFlags. inline Regexp::ParseFlags operator|(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) | static_cast(b)); + return static_cast(static_cast(a) | + static_cast(b)); } inline Regexp::ParseFlags operator^(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) ^ static_cast(b)); + return static_cast(static_cast(a) ^ + static_cast(b)); } inline Regexp::ParseFlags operator&(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) & static_cast(b)); + return static_cast(static_cast(a) & + static_cast(b)); } inline Regexp::ParseFlags operator~(Regexp::ParseFlags a) { @@ -660,6 +687,6 @@ inline Regexp::ParseFlags operator~(Regexp::ParseFlags a) { ~static_cast(a) & static_cast(Regexp::AllParseFlags)); } -} // namespace re2 +} // namespace re2 -#endif // RE2_REGEXP_H_ +#endif // RE2_REGEXP_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h index 8d64f30c..19741ebf 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h @@ -15,34 +15,34 @@ namespace re2 { class Prog; class Regexp; -} // namespace re2 +} // namespace re2 namespace re2 { // An RE2::Set represents a collection of regexps that can // be searched for simultaneously. class RE2::Set { - public: +public: enum ErrorKind { kNoError = 0, - kNotCompiled, // The set is not compiled. - kOutOfMemory, // The DFA ran out of memory. - kInconsistent, // The result is inconsistent. This should never happen. + kNotCompiled, // The set is not compiled. + kOutOfMemory, // The DFA ran out of memory. + kInconsistent, // The result is inconsistent. This should never happen. }; struct ErrorInfo { ErrorKind kind; }; - Set(const RE2::Options& options, RE2::Anchor anchor); + Set(const RE2::Options &options, RE2::Anchor anchor); ~Set(); // Not copyable. - Set(const Set&) = delete; - Set& operator=(const Set&) = delete; + Set(const Set &) = delete; + Set &operator=(const Set &) = delete; // Movable. - Set(Set&& other); - Set& operator=(Set&& other); + Set(Set &&other); + Set &operator=(Set &&other); // Adds pattern to the set using the options passed to the constructor. // Returns the index that will identify the regexp in the output of Match(), @@ -50,7 +50,7 @@ class RE2::Set { // Indices are assigned in sequential order starting from 0. // Errors do not increment the index; if error is not NULL, *error will hold // the error message from the parser. - int Add(const StringPiece& pattern, std::string* error); + int Add(const StringPiece &pattern, std::string *error); // Compiles the set in preparation for matching. // Returns false if the compiler runs out of memory. @@ -61,16 +61,16 @@ class RE2::Set { // Returns true if text matches at least one of the regexps in the set. // Fills v (if not NULL) with the indices of the matching regexps. // Callers must not expect v to be sorted. - bool Match(const StringPiece& text, std::vector* v) const; + bool Match(const StringPiece &text, std::vector *v) const; // As above, but populates error_info (if not NULL) when none of the regexps // in the set matched. This can inform callers when DFA execution fails, for // example, because they might wish to handle that case differently. - bool Match(const StringPiece& text, std::vector* v, - ErrorInfo* error_info) const; + bool Match(const StringPiece &text, std::vector *v, + ErrorInfo *error_info) const; - private: - typedef std::pair Elem; +private: + typedef std::pair Elem; RE2::Options options_; RE2::Anchor anchor_; @@ -80,6 +80,6 @@ class RE2::Set { std::unique_ptr prog_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_SET_H_ +#endif // RE2_SET_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h index 09ffe086..5580aa26 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h @@ -106,9 +106,8 @@ namespace re2 { -template -class SparseArray { - public: +template class SparseArray { +public: SparseArray(); explicit SparseArray(int max_size); ~SparseArray(); @@ -116,39 +115,27 @@ class SparseArray { // IndexValue pairs: exposed in SparseArray::iterator. class IndexValue; - typedef IndexValue* iterator; - typedef const IndexValue* const_iterator; + typedef IndexValue *iterator; + typedef const IndexValue *const_iterator; - SparseArray(const SparseArray& src); - SparseArray(SparseArray&& src); + SparseArray(const SparseArray &src); + SparseArray(SparseArray &&src); - SparseArray& operator=(const SparseArray& src); - SparseArray& operator=(SparseArray&& src); + SparseArray &operator=(const SparseArray &src); + SparseArray &operator=(SparseArray &&src); // Return the number of entries in the array. - int size() const { - return size_; - } + int size() const { return size_; } // Indicate whether the array is empty. - int empty() const { - return size_ == 0; - } + int empty() const { return size_ == 0; } // Iterate over the array. - iterator begin() { - return dense_.data(); - } - iterator end() { - return dense_.data() + size_; - } + iterator begin() { return dense_.data(); } + iterator end() { return dense_.data() + size_; } - const_iterator begin() const { - return dense_.data(); - } - const_iterator end() const { - return dense_.data() + size_; - } + const_iterator begin() const { return dense_.data(); } + const_iterator end() const { return dense_.data() + size_; } // Change the maximum size of the array. // Invalidates all iterators. @@ -164,9 +151,7 @@ class SparseArray { } // Clear the array. - void clear() { - size_ = 0; - } + void clear() { size_ = 0; } // Check whether index i is in the array. bool has_index(int i) const; @@ -175,39 +160,35 @@ class SparseArray { // Can sort the sparse array so that future iterations // will visit indices in increasing order using // std::sort(arr.begin(), arr.end(), arr.less); - static bool less(const IndexValue& a, const IndexValue& b); + static bool less(const IndexValue &a, const IndexValue &b); - public: +public: // Set the value at index i to v. - iterator set(int i, const Value& v) { - return SetInternal(true, i, v); - } + iterator set(int i, const Value &v) { return SetInternal(true, i, v); } // Set the value at new index i to v. // Fast but unsafe: only use if has_index(i) is false. - iterator set_new(int i, const Value& v) { - return SetInternal(false, i, v); - } + iterator set_new(int i, const Value &v) { return SetInternal(false, i, v); } // Set the value at index i to v. // Fast but unsafe: only use if has_index(i) is true. - iterator set_existing(int i, const Value& v) { + iterator set_existing(int i, const Value &v) { return SetExistingInternal(i, v); } // Get the value at index i. // Fast but unsafe: only use if has_index(i) is true. - Value& get_existing(int i) { + Value &get_existing(int i) { assert(has_index(i)); return dense_[sparse_[i]].value_; } - const Value& get_existing(int i) const { + const Value &get_existing(int i) const { assert(has_index(i)); return dense_[sparse_[i]].value_; } - private: - iterator SetInternal(bool allow_existing, int i, const Value& v) { +private: + iterator SetInternal(bool allow_existing, int i, const Value &v) { DebugCheckInvariants(); if (static_cast(i) >= static_cast(max_size())) { assert(false && "illegal index"); @@ -226,7 +207,7 @@ class SparseArray { return SetExistingInternal(i, v); } - iterator SetExistingInternal(int i, const Value& v) { + iterator SetExistingInternal(int i, const Value &v) { DebugCheckInvariants(); assert(has_index(i)); dense_[sparse_[i]].value_ = v; @@ -262,28 +243,24 @@ class SparseArray { PODArray dense_; }; -template -SparseArray::SparseArray() = default; +template SparseArray::SparseArray() = default; -template -SparseArray::SparseArray(const SparseArray& src) - : size_(src.size_), - sparse_(src.max_size()), - dense_(src.max_size()) { +template +SparseArray::SparseArray(const SparseArray &src) + : size_(src.size_), sparse_(src.max_size()), dense_(src.max_size()) { std::copy_n(src.sparse_.data(), src.max_size(), sparse_.data()); std::copy_n(src.dense_.data(), src.max_size(), dense_.data()); } -template -SparseArray::SparseArray(SparseArray&& src) - : size_(src.size_), - sparse_(std::move(src.sparse_)), +template +SparseArray::SparseArray(SparseArray &&src) + : size_(src.size_), sparse_(std::move(src.sparse_)), dense_(std::move(src.dense_)) { src.size_ = 0; } -template -SparseArray& SparseArray::operator=(const SparseArray& src) { +template +SparseArray &SparseArray::operator=(const SparseArray &src) { // Construct these first for exception safety. PODArray a(src.max_size()); PODArray b(src.max_size()); @@ -296,8 +273,8 @@ SparseArray& SparseArray::operator=(const SparseArray& src) { return *this; } -template -SparseArray& SparseArray::operator=(SparseArray&& src) { +template +SparseArray &SparseArray::operator=(SparseArray &&src) { size_ = src.size_; sparse_ = std::move(src.sparse_); dense_ = std::move(src.dense_); @@ -306,14 +283,13 @@ SparseArray& SparseArray::operator=(SparseArray&& src) { } // IndexValue pairs: exposed in SparseArray::iterator. -template -class SparseArray::IndexValue { - public: +template class SparseArray::IndexValue { +public: int index() const { return index_; } - Value& value() { return value_; } - const Value& value() const { return value_; } + Value &value() { return value_; } + const Value &value() const { return value_; } - private: +private: friend class SparseArray; int index_; Value value_; @@ -321,8 +297,7 @@ class SparseArray::IndexValue { // Change the maximum size of the array. // Invalidates all iterators. -template -void SparseArray::resize(int new_max_size) { +template void SparseArray::resize(int new_max_size) { DebugCheckInvariants(); if (new_max_size > max_size()) { const int old_max_size = max_size(); @@ -345,8 +320,7 @@ void SparseArray::resize(int new_max_size) { } // Check whether index i is in the array. -template -bool SparseArray::has_index(int i) const { +template bool SparseArray::has_index(int i) const { assert(i >= 0); assert(i < max_size()); if (static_cast(i) >= static_cast(max_size())) { @@ -357,8 +331,7 @@ bool SparseArray::has_index(int i) const { dense_[sparse_[i]].index_ == i; } -template -void SparseArray::create_index(int i) { +template void SparseArray::create_index(int i) { assert(!has_index(i)); assert(size_ < max_size()); sparse_[i] = size_; @@ -366,27 +339,29 @@ void SparseArray::create_index(int i) { size_++; } -template SparseArray::SparseArray(int max_size) : - sparse_(max_size), dense_(max_size) { +template +SparseArray::SparseArray(int max_size) + : sparse_(max_size), dense_(max_size) { MaybeInitializeMemory(size_, max_size); DebugCheckInvariants(); } -template SparseArray::~SparseArray() { +template SparseArray::~SparseArray() { DebugCheckInvariants(); } -template void SparseArray::DebugCheckInvariants() const { +template +void SparseArray::DebugCheckInvariants() const { assert(0 <= size_); assert(size_ <= max_size()); } // Comparison function for sorting. -template bool SparseArray::less(const IndexValue& a, - const IndexValue& b) { +template +bool SparseArray::less(const IndexValue &a, const IndexValue &b) { return a.index_ < b.index_; } -} // namespace re2 +} // namespace re2 -#endif // RE2_SPARSE_ARRAY_H_ +#endif // RE2_SPARSE_ARRAY_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h index 06ed88d8..1e9c2f10 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h @@ -65,40 +65,27 @@ namespace re2 { -template -class SparseSetT { - public: +template class SparseSetT { +public: SparseSetT(); explicit SparseSetT(int max_size); ~SparseSetT(); - typedef int* iterator; - typedef const int* const_iterator; + typedef int *iterator; + typedef const int *const_iterator; // Return the number of entries in the set. - int size() const { - return size_; - } + int size() const { return size_; } // Indicate whether the set is empty. - int empty() const { - return size_ == 0; - } + int empty() const { return size_ == 0; } // Iterate over the set. - iterator begin() { - return dense_.data(); - } - iterator end() { - return dense_.data() + size_; - } + iterator begin() { return dense_.data(); } + iterator end() { return dense_.data() + size_; } - const_iterator begin() const { - return dense_.data(); - } - const_iterator end() const { - return dense_.data() + size_; - } + const_iterator begin() const { return dense_.data(); } + const_iterator end() const { return dense_.data() + size_; } // Change the maximum size of the set. // Invalidates all iterators. @@ -114,9 +101,7 @@ class SparseSetT { } // Clear the set. - void clear() { - size_ = 0; - } + void clear() { size_ = 0; } // Check whether index i is in the set. bool contains(int i) const; @@ -127,19 +112,15 @@ class SparseSetT { // std::sort(arr.begin(), arr.end(), arr.less); static bool less(int a, int b); - public: +public: // Insert index i into the set. - iterator insert(int i) { - return InsertInternal(true, i); - } + iterator insert(int i) { return InsertInternal(true, i); } // Insert index i into the set. // Fast but unsafe: only use if contains(i) is false. - iterator insert_new(int i) { - return InsertInternal(false, i); - } + iterator insert_new(int i) { return InsertInternal(false, i); } - private: +private: iterator InsertInternal(bool allow_existing, int i) { DebugCheckInvariants(); if (static_cast(i) >= static_cast(max_size())) { @@ -187,13 +168,11 @@ class SparseSetT { PODArray dense_; }; -template -SparseSetT::SparseSetT() = default; +template SparseSetT::SparseSetT() = default; // Change the maximum size of the set. // Invalidates all iterators. -template -void SparseSetT::resize(int new_max_size) { +template void SparseSetT::resize(int new_max_size) { DebugCheckInvariants(); if (new_max_size > max_size()) { const int old_max_size = max_size(); @@ -216,20 +195,17 @@ void SparseSetT::resize(int new_max_size) { } // Check whether index i is in the set. -template -bool SparseSetT::contains(int i) const { +template bool SparseSetT::contains(int i) const { assert(i >= 0); assert(i < max_size()); if (static_cast(i) >= static_cast(max_size())) { return false; } // Unsigned comparison avoids checking sparse_[i] < 0. - return (uint32_t)sparse_[i] < (uint32_t)size_ && - dense_[sparse_[i]] == i; + return (uint32_t)sparse_[i] < (uint32_t)size_ && dense_[sparse_[i]] == i; } -template -void SparseSetT::create_index(int i) { +template void SparseSetT::create_index(int i) { assert(!contains(i)); assert(size_ < max_size()); sparse_[i] = size_; @@ -237,28 +213,29 @@ void SparseSetT::create_index(int i) { size_++; } -template SparseSetT::SparseSetT(int max_size) : - sparse_(max_size), dense_(max_size) { +template +SparseSetT::SparseSetT(int max_size) + : sparse_(max_size), dense_(max_size) { MaybeInitializeMemory(size_, max_size); DebugCheckInvariants(); } -template SparseSetT::~SparseSetT() { +template SparseSetT::~SparseSetT() { DebugCheckInvariants(); } -template void SparseSetT::DebugCheckInvariants() const { +template void SparseSetT::DebugCheckInvariants() const { assert(0 <= size_); assert(size_ <= max_size()); } // Comparison function for sorting. -template bool SparseSetT::less(int a, int b) { +template bool SparseSetT::less(int a, int b) { return a < b; } typedef SparseSetT SparseSet; -} // namespace re2 +} // namespace re2 -#endif // RE2_SPARSE_SET_H_ +#endif // RE2_SPARSE_SET_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h index b9d66614..31b6dd0b 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h @@ -19,11 +19,11 @@ // // Arghh! I wish C++ literals were "string". -#include -#include #include #include #include +#include +#include #include #ifdef __cpp_lib_string_view #include @@ -32,14 +32,14 @@ namespace re2 { class StringPiece { - public: +public: typedef std::char_traits traits_type; typedef char value_type; - typedef char* pointer; - typedef const char* const_pointer; - typedef char& reference; - typedef const char& const_reference; - typedef const char* const_iterator; + typedef char *pointer; + typedef const char *const_pointer; + typedef char &reference; + typedef const char &const_reference; + typedef const char *const_iterator; typedef const_iterator iterator; typedef std::reverse_iterator const_reverse_iterator; typedef const_reverse_iterator reverse_iterator; @@ -50,27 +50,22 @@ class StringPiece { // We provide non-explicit singleton constructors so users can pass // in a "const char*" or a "string" wherever a "StringPiece" is // expected. - StringPiece() - : data_(NULL), size_(0) {} + StringPiece() : data_(NULL), size_(0) {} #ifdef __cpp_lib_string_view - StringPiece(const std::string_view& str) + StringPiece(const std::string_view &str) : data_(str.data()), size_(str.size()) {} #endif - StringPiece(const std::string& str) - : data_(str.data()), size_(str.size()) {} - StringPiece(const char* str) + StringPiece(const std::string &str) : data_(str.data()), size_(str.size()) {} + StringPiece(const char *str) : data_(str), size_(str == NULL ? 0 : strlen(str)) {} - StringPiece(const char* str, size_type len) - : data_(str), size_(len) {} + StringPiece(const char *str, size_type len) : data_(str), size_(len) {} const_iterator begin() const { return data_; } const_iterator end() const { return data_ + size_; } const_reverse_iterator rbegin() const { return const_reverse_iterator(data_ + size_); } - const_reverse_iterator rend() const { - return const_reverse_iterator(data_); - } + const_reverse_iterator rend() const { return const_reverse_iterator(data_); } size_type size() const { return size_; } size_type length() const { return size_; } @@ -84,16 +79,14 @@ class StringPiece { size_ -= n; } - void remove_suffix(size_type n) { - size_ -= n; - } + void remove_suffix(size_type n) { size_ -= n; } - void set(const char* str) { + void set(const char *str) { data_ = str; size_ = str == NULL ? 0 : strlen(str); } - void set(const char* str, size_type len) { + void set(const char *str, size_type len) { data_ = str; size_ = len; } @@ -101,7 +94,8 @@ class StringPiece { #ifdef __cpp_lib_string_view // Converts to `std::basic_string_view`. operator std::basic_string_view() const { - if (!data_) return {}; + if (!data_) + return {}; return std::basic_string_view(data_, size_); } #endif @@ -109,105 +103,103 @@ class StringPiece { // Converts to `std::basic_string`. template explicit operator std::basic_string() const { - if (!data_) return {}; + if (!data_) + return {}; return std::basic_string(data_, size_); } - std::string as_string() const { - return std::string(data_, size_); - } + std::string as_string() const { return std::string(data_, size_); } // We also define ToString() here, since many other string-like // interfaces name the routine that converts to a C++ string // "ToString", and it's confusing to have the method that does that // for a StringPiece be called "as_string()". We also leave the // "as_string()" method defined here for existing code. - std::string ToString() const { - return std::string(data_, size_); - } + std::string ToString() const { return std::string(data_, size_); } - void CopyToString(std::string* target) const { - target->assign(data_, size_); - } + void CopyToString(std::string *target) const { target->assign(data_, size_); } - void AppendToString(std::string* target) const { + void AppendToString(std::string *target) const { target->append(data_, size_); } - size_type copy(char* buf, size_type n, size_type pos = 0) const; + size_type copy(char *buf, size_type n, size_type pos = 0) const; StringPiece substr(size_type pos = 0, size_type n = npos) const; - int compare(const StringPiece& x) const { + int compare(const StringPiece &x) const { size_type min_size = std::min(size(), x.size()); if (min_size > 0) { int r = memcmp(data(), x.data(), min_size); - if (r < 0) return -1; - if (r > 0) return 1; + if (r < 0) + return -1; + if (r > 0) + return 1; } - if (size() < x.size()) return -1; - if (size() > x.size()) return 1; + if (size() < x.size()) + return -1; + if (size() > x.size()) + return 1; return 0; } // Does "this" start with "x"? - bool starts_with(const StringPiece& x) const { + bool starts_with(const StringPiece &x) const { return x.empty() || (size() >= x.size() && memcmp(data(), x.data(), x.size()) == 0); } // Does "this" end with "x"? - bool ends_with(const StringPiece& x) const { + bool ends_with(const StringPiece &x) const { return x.empty() || (size() >= x.size() && memcmp(data() + (size() - x.size()), x.data(), x.size()) == 0); } - bool contains(const StringPiece& s) const { - return find(s) != npos; - } + bool contains(const StringPiece &s) const { return find(s) != npos; } - size_type find(const StringPiece& s, size_type pos = 0) const; + size_type find(const StringPiece &s, size_type pos = 0) const; size_type find(char c, size_type pos = 0) const; - size_type rfind(const StringPiece& s, size_type pos = npos) const; + size_type rfind(const StringPiece &s, size_type pos = npos) const; size_type rfind(char c, size_type pos = npos) const; - private: +private: const_pointer data_; size_type size_; }; -inline bool operator==(const StringPiece& x, const StringPiece& y) { +inline bool operator==(const StringPiece &x, const StringPiece &y) { StringPiece::size_type len = x.size(); - if (len != y.size()) return false; + if (len != y.size()) + return false; return x.data() == y.data() || len == 0 || memcmp(x.data(), y.data(), len) == 0; } -inline bool operator!=(const StringPiece& x, const StringPiece& y) { +inline bool operator!=(const StringPiece &x, const StringPiece &y) { return !(x == y); } -inline bool operator<(const StringPiece& x, const StringPiece& y) { +inline bool operator<(const StringPiece &x, const StringPiece &y) { StringPiece::size_type min_size = std::min(x.size(), y.size()); int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size); return (r < 0) || (r == 0 && x.size() < y.size()); } -inline bool operator>(const StringPiece& x, const StringPiece& y) { +inline bool operator>(const StringPiece &x, const StringPiece &y) { return y < x; } -inline bool operator<=(const StringPiece& x, const StringPiece& y) { +inline bool operator<=(const StringPiece &x, const StringPiece &y) { return !(x > y); } -inline bool operator>=(const StringPiece& x, const StringPiece& y) { +inline bool operator>=(const StringPiece &x, const StringPiece &y) { return !(x < y); } // Allow StringPiece to be logged. -std::ostream& operator<<(std::ostream& o, const StringPiece& p); +std::ostream &operator<<(std::ostream &o, const StringPiece &p); -} // namespace re2 +} // namespace re2 -#endif // RE2_STRINGPIECE_H_ +#endif // RE2_STRINGPIECE_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h index 8bdbb42f..742d770a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h @@ -41,15 +41,15 @@ #include -#include "util/util.h" #include "util/utf.h" +#include "util/util.h" namespace re2 { enum { EvenOdd = 1, OddEven = -1, - EvenOddSkip = 1<<30, + EvenOddSkip = 1 << 30, OddEvenSkip, }; @@ -68,11 +68,11 @@ extern const int num_unicode_tolower; // Returns the CaseFold* in the tables that contains rune. // If rune is not in the tables, returns the first CaseFold* after rune. // If rune is larger than any value in the tables, returns NULL. -extern const CaseFold* LookupCaseFold(const CaseFold*, int, Rune rune); +extern const CaseFold *LookupCaseFold(const CaseFold *, int, Rune rune); // Returns the result of applying the fold f to the rune r. extern Rune ApplyFold(const CaseFold *f, Rune r); -} // namespace re2 +} // namespace re2 -#endif // RE2_UNICODE_CASEFOLD_H_ +#endif // RE2_UNICODE_CASEFOLD_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h index 75f55daa..839ed6f3 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h @@ -20,27 +20,24 @@ #include -#include "util/util.h" #include "util/utf.h" +#include "util/util.h" namespace re2 { -struct URange16 -{ +struct URange16 { uint16_t lo; uint16_t hi; }; -struct URange32 -{ +struct URange32 { Rune lo; Rune hi; }; -struct UGroup -{ +struct UGroup { const char *name; - int sign; // +1 for [abc], -1 for [^abc] + int sign; // +1 for [abc], -1 for [^abc] const URange16 *r16; int nr16; const URange32 *r32; @@ -62,6 +59,6 @@ extern const int num_posix_groups; extern const UGroup perl_groups[]; extern const int num_perl_groups; -} // namespace re2 +} // namespace re2 -#endif // RE2_UNICODE_GROUPS_H_ +#endif // RE2_UNICODE_GROUPS_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h index 4d064a09..43e25015 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h @@ -15,15 +15,15 @@ #include -#include "util/logging.h" #include "re2/regexp.h" +#include "util/logging.h" namespace re2 { -template struct WalkState; +template struct WalkState; -template class Regexp::Walker { - public: +template class Regexp::Walker { +public: Walker(); virtual ~Walker(); @@ -36,7 +36,7 @@ template class Regexp::Walker { // into the children. Instead it behaves as though the return // value from PreVisit is the return value from PostVisit. // The default PreVisit returns parent_arg. - virtual T PreVisit(Regexp* re, T parent_arg, bool* stop); + virtual T PreVisit(Regexp *re, T parent_arg, bool *stop); // Virtual method called after visiting re's children. // The pre_arg is the T that PreVisit returned. @@ -47,8 +47,8 @@ template class Regexp::Walker { // PostVisit passes ownership of its return value // to its caller. // The default PostVisit simply returns pre_arg. - virtual T PostVisit(Regexp* re, T parent_arg, T pre_arg, - T* child_args, int nchild_args); + virtual T PostVisit(Regexp *re, T parent_arg, T pre_arg, T *child_args, + int nchild_args); // Virtual method called to copy a T, // when Walk notices that more than one child is the same re. @@ -62,12 +62,12 @@ template class Regexp::Walker { // This function is (hopefully) only called by // WalkExponential, but must be implemented by all clients, // just in case. - virtual T ShortVisit(Regexp* re, T parent_arg) = 0; + virtual T ShortVisit(Regexp *re, T parent_arg) = 0; // Walks over a regular expression. // Top_arg is passed as parent_arg to PreVisit and PostVisit of re. // Returns the T returned by PostVisit on re. - T Walk(Regexp* re, T top_arg); + T Walk(Regexp *re, T top_arg); // Like Walk, but doesn't use Copy. This can lead to // exponential runtimes on cross-linked Regexps like the @@ -77,7 +77,7 @@ template class Regexp::Walker { // If the walk *is* cut off early, ShortVisit(re) // will be called on regexps that cannot be fully // visited rather than calling PreVisit/PostVisit. - T WalkExponential(Regexp* re, T top_arg, int max_visits); + T WalkExponential(Regexp *re, T top_arg, int max_visits); // Clears the stack. Should never be necessary, since // Walk always enters and exits with an empty stack. @@ -87,64 +87,52 @@ template class Regexp::Walker { // Returns whether walk was cut off. bool stopped_early() { return stopped_early_; } - private: +private: // Walk state for the entire traversal. std::stack> stack_; bool stopped_early_; int max_visits_; - T WalkInternal(Regexp* re, T top_arg, bool use_copy); + T WalkInternal(Regexp *re, T top_arg, bool use_copy); - Walker(const Walker&) = delete; - Walker& operator=(const Walker&) = delete; + Walker(const Walker &) = delete; + Walker &operator=(const Walker &) = delete; }; -template T Regexp::Walker::PreVisit(Regexp* re, - T parent_arg, - bool* stop) { +template +T Regexp::Walker::PreVisit(Regexp *re, T parent_arg, bool *stop) { return parent_arg; } -template T Regexp::Walker::PostVisit(Regexp* re, - T parent_arg, - T pre_arg, - T* child_args, - int nchild_args) { +template +T Regexp::Walker::PostVisit(Regexp *re, T parent_arg, T pre_arg, + T *child_args, int nchild_args) { return pre_arg; } -template T Regexp::Walker::Copy(T arg) { - return arg; -} +template T Regexp::Walker::Copy(T arg) { return arg; } // State about a single level in the traversal. -template struct WalkState { - WalkState(Regexp* re, T parent) - : re(re), - n(-1), - parent_arg(parent), - child_args(NULL) { } - - Regexp* re; // The regexp - int n; // The index of the next child to process; -1 means need to PreVisit - T parent_arg; // Accumulated arguments. +template struct WalkState { + WalkState(Regexp *re, T parent) + : re(re), n(-1), parent_arg(parent), child_args(NULL) {} + + Regexp *re; // The regexp + int n; // The index of the next child to process; -1 means need to PreVisit + T parent_arg; // Accumulated arguments. T pre_arg; - T child_arg; // One-element buffer for child_args. - T* child_args; + T child_arg; // One-element buffer for child_args. + T *child_args; }; -template Regexp::Walker::Walker() { - stopped_early_ = false; -} +template Regexp::Walker::Walker() { stopped_early_ = false; } -template Regexp::Walker::~Walker() { - Reset(); -} +template Regexp::Walker::~Walker() { Reset(); } // Clears the stack. Should never be necessary, since // Walk always enters and exits with an empty stack. // Logs DFATAL if stack is not already clear. -template void Regexp::Walker::Reset() { +template void Regexp::Walker::Reset() { if (!stack_.empty()) { LOG(DFATAL) << "Stack not empty."; while (!stack_.empty()) { @@ -155,8 +143,8 @@ template void Regexp::Walker::Reset() { } } -template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, - bool use_copy) { +template +T Regexp::Walker::WalkInternal(Regexp *re, T top_arg, bool use_copy) { Reset(); if (re == NULL) { @@ -166,51 +154,51 @@ template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, stack_.push(WalkState(re, top_arg)); - WalkState* s; + WalkState *s; for (;;) { T t; s = &stack_.top(); re = s->re; switch (s->n) { - case -1: { - if (--max_visits_ < 0) { - stopped_early_ = true; - t = ShortVisit(re, s->parent_arg); - break; - } - bool stop = false; - s->pre_arg = PreVisit(re, s->parent_arg, &stop); - if (stop) { - t = s->pre_arg; - break; - } - s->n = 0; - s->child_args = NULL; - if (re->nsub_ == 1) - s->child_args = &s->child_arg; - else if (re->nsub_ > 1) - s->child_args = new T[re->nsub_]; - FALLTHROUGH_INTENDED; + case -1: { + if (--max_visits_ < 0) { + stopped_early_ = true; + t = ShortVisit(re, s->parent_arg); + break; + } + bool stop = false; + s->pre_arg = PreVisit(re, s->parent_arg, &stop); + if (stop) { + t = s->pre_arg; + break; } - default: { - if (re->nsub_ > 0) { - Regexp** sub = re->sub(); - if (s->n < re->nsub_) { - if (use_copy && s->n > 0 && sub[s->n - 1] == sub[s->n]) { - s->child_args[s->n] = Copy(s->child_args[s->n - 1]); - s->n++; - } else { - stack_.push(WalkState(sub[s->n], s->pre_arg)); - } - continue; + s->n = 0; + s->child_args = NULL; + if (re->nsub_ == 1) + s->child_args = &s->child_arg; + else if (re->nsub_ > 1) + s->child_args = new T[re->nsub_]; + FALLTHROUGH_INTENDED; + } + default: { + if (re->nsub_ > 0) { + Regexp **sub = re->sub(); + if (s->n < re->nsub_) { + if (use_copy && s->n > 0 && sub[s->n - 1] == sub[s->n]) { + s->child_args[s->n] = Copy(s->child_args[s->n - 1]); + s->n++; + } else { + stack_.push(WalkState(sub[s->n], s->pre_arg)); } + continue; } - - t = PostVisit(re, s->parent_arg, s->pre_arg, s->child_args, s->n); - if (re->nsub_ > 1) - delete[] s->child_args; - break; } + + t = PostVisit(re, s->parent_arg, s->pre_arg, s->child_args, s->n); + if (re->nsub_ > 1) + delete[] s->child_args; + break; + } } // We've finished stack_.top(). @@ -227,7 +215,7 @@ template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, } } -template T Regexp::Walker::Walk(Regexp* re, T top_arg) { +template T Regexp::Walker::Walk(Regexp *re, T top_arg) { // Without the exponential walking behavior, // this budget should be more than enough for any // regexp, and yet not enough to get us in trouble @@ -236,12 +224,12 @@ template T Regexp::Walker::Walk(Regexp* re, T top_arg) { return WalkInternal(re, top_arg, true); } -template T Regexp::Walker::WalkExponential(Regexp* re, T top_arg, - int max_visits) { +template +T Regexp::Walker::WalkExponential(Regexp *re, T top_arg, int max_visits) { max_visits_ = max_visits; return WalkInternal(re, top_arg, false); } -} // namespace re2 +} // namespace re2 -#endif // RE2_WALKER_INL_H_ +#endif // RE2_WALKER_INL_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h index 293b31d8..af80cd86 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h @@ -16,15 +16,11 @@ namespace re2 { class Bitmap256 { - public: - Bitmap256() { - Clear(); - } +public: + Bitmap256() { Clear(); } // Clears all of the bits. - void Clear() { - memset(words_, 0, sizeof words_); - } + void Clear() { memset(words_, 0, sizeof words_); } // Tests the bit with index c. bool Test(int c) const { @@ -46,7 +42,7 @@ class Bitmap256 { // Returns -1 if no such bit exists. int FindNextSetBit(int c) const; - private: +private: // Finds the least significant non-zero bit in n. static int FindLSBSet(uint64_t n) { DCHECK_NE(n, 0); @@ -81,6 +77,6 @@ class Bitmap256 { uint64_t words_[4]; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_BITMAP256_H_ +#endif // RE2_BITMAP256_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h index dd618c70..b022a006 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h @@ -32,24 +32,23 @@ namespace re2 { class PrefilterTree; class FilteredRE2 { - public: +public: FilteredRE2(); explicit FilteredRE2(int min_atom_len); ~FilteredRE2(); // Not copyable. - FilteredRE2(const FilteredRE2&) = delete; - FilteredRE2& operator=(const FilteredRE2&) = delete; + FilteredRE2(const FilteredRE2 &) = delete; + FilteredRE2 &operator=(const FilteredRE2 &) = delete; // Movable. - FilteredRE2(FilteredRE2&& other); - FilteredRE2& operator=(FilteredRE2&& other); + FilteredRE2(FilteredRE2 &&other); + FilteredRE2 &operator=(FilteredRE2 &&other); // Uses RE2 constructor to create a RE2 object (re). Returns // re->error_code(). If error_code is other than NoError, then re is // deleted and not added to re2_vec_. - RE2::ErrorCode Add(const StringPiece& pattern, - const RE2::Options& options, - int* id); + RE2::ErrorCode Add(const StringPiece &pattern, const RE2::Options &options, + int *id); // Prepares the regexps added by Add for filtering. Returns a set // of strings that the caller should check for in candidate texts. @@ -57,50 +56,48 @@ class FilteredRE2 { // string matching, it should be performed in a case-insensitive // way or the search text should be lowercased first. Call after // all Add calls are done. - void Compile(std::vector* strings_to_match); + void Compile(std::vector *strings_to_match); // Returns the index of the first matching regexp. // Returns -1 on no match. Can be called prior to Compile. // Does not do any filtering: simply tries to Match the // regexps in a loop. - int SlowFirstMatch(const StringPiece& text) const; + int SlowFirstMatch(const StringPiece &text) const; // Returns the index of the first matching regexp. // Returns -1 on no match. Compile has to be called before // calling this. - int FirstMatch(const StringPiece& text, - const std::vector& atoms) const; + int FirstMatch(const StringPiece &text, const std::vector &atoms) const; // Returns the indices of all matching regexps, after first clearing // matched_regexps. - bool AllMatches(const StringPiece& text, - const std::vector& atoms, - std::vector* matching_regexps) const; + bool AllMatches(const StringPiece &text, const std::vector &atoms, + std::vector *matching_regexps) const; // Returns the indices of all potentially matching regexps after first // clearing potential_regexps. // A regexp is potentially matching if it passes the filter. // If a regexp passes the filter it may still not match. // A regexp that does not pass the filter is guaranteed to not match. - void AllPotentials(const std::vector& atoms, - std::vector* potential_regexps) const; + void AllPotentials(const std::vector &atoms, + std::vector *potential_regexps) const; // The number of regexps added. int NumRegexps() const { return static_cast(re2_vec_.size()); } // Get the individual RE2 objects. - const RE2& GetRE2(int regexpid) const { return *re2_vec_[regexpid]; } + const RE2 &GetRE2(int regexpid) const { return *re2_vec_[regexpid]; } - private: +private: // Print prefilter. void PrintPrefilter(int regexpid); // Useful for testing and debugging. - void RegexpsGivenStrings(const std::vector& matched_atoms, - std::vector* passed_regexps); + void RegexpsGivenStrings(const std::vector &matched_atoms, + std::vector *passed_regexps); // All the regexps in the FilteredRE2. - std::vector re2_vec_; + std::vector re2_vec_; // Has the FilteredRE2 been compiled using Compile() bool compiled_; @@ -109,6 +106,6 @@ class FilteredRE2 { std::unique_ptr prefilter_tree_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_FILTERED_RE2_H_ +#endif // RE2_FILTERED_RE2_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h index f234e976..267f9b16 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h @@ -10,39 +10,27 @@ namespace re2 { -template -class PODArray { - public: +template class PODArray { +public: static_assert(std::is_trivial::value && std::is_standard_layout::value, "T must be POD"); - PODArray() - : ptr_() {} + PODArray() : ptr_() {} explicit PODArray(int len) : ptr_(std::allocator().allocate(len), Deleter(len)) {} - T* data() const { - return ptr_.get(); - } + T *data() const { return ptr_.get(); } - int size() const { - return ptr_.get_deleter().len_; - } + int size() const { return ptr_.get_deleter().len_; } - T& operator[](int pos) const { - return ptr_[pos]; - } + T &operator[](int pos) const { return ptr_[pos]; } - private: +private: struct Deleter { - Deleter() - : len_(0) {} - explicit Deleter(int len) - : len_(len) {} + Deleter() : len_(0) {} + explicit Deleter(int len) : len_(len) {} - void operator()(T* ptr) const { - std::allocator().deallocate(ptr, len_); - } + void operator()(T *ptr) const { std::allocator().deallocate(ptr, len_); } int len_; }; @@ -50,6 +38,6 @@ class PODArray { std::unique_ptr ptr_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_POD_ARRAY_H_ +#endif // RE2_POD_ARRAY_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h index e149e59a..23009a2c 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h @@ -13,8 +13,8 @@ #include #include -#include "util/util.h" #include "util/logging.h" +#include "util/util.h" namespace re2 { @@ -24,48 +24,48 @@ class Regexp; class Prefilter { // Instead of using Prefilter directly, use FilteredRE2; see filtered_re2.h - public: +public: enum Op { - ALL = 0, // Everything matches - NONE, // Nothing matches - ATOM, // The string atom() must match - AND, // All in subs() must match - OR, // One of subs() must match + ALL = 0, // Everything matches + NONE, // Nothing matches + ATOM, // The string atom() must match + AND, // All in subs() must match + OR, // One of subs() must match }; explicit Prefilter(Op op); ~Prefilter(); Op op() { return op_; } - const std::string& atom() const { return atom_; } + const std::string &atom() const { return atom_; } void set_unique_id(int id) { unique_id_ = id; } int unique_id() const { return unique_id_; } // The children of the Prefilter node. - std::vector* subs() { + std::vector *subs() { DCHECK(op_ == AND || op_ == OR); return subs_; } // Set the children vector. Prefilter takes ownership of subs and // subs_ will be deleted when Prefilter is deleted. - void set_subs(std::vector* subs) { subs_ = subs; } + void set_subs(std::vector *subs) { subs_ = subs; } // Given a RE2, return a Prefilter. The caller takes ownership of // the Prefilter and should deallocate it. Returns NULL if Prefilter // cannot be formed. - static Prefilter* FromRE2(const RE2* re2); + static Prefilter *FromRE2(const RE2 *re2); // Returns a readable debug string of the prefilter. std::string DebugString() const; - private: +private: // A comparator used to store exact strings. We compare by length, // then lexicographically. This ordering makes it easier to reduce the // set of strings in SimplifyStringSet. struct LengthThenLex { - bool operator()(const std::string& a, const std::string& b) const { - return (a.size() < b.size()) || (a.size() == b.size() && a < b); + bool operator()(const std::string &a, const std::string &b) const { + return (a.size() < b.size()) || (a.size() == b.size() && a < b); } }; @@ -77,39 +77,39 @@ class Prefilter { // Combines two prefilters together to create an AND. The passed // Prefilters will be part of the returned Prefilter or deleted. - static Prefilter* And(Prefilter* a, Prefilter* b); + static Prefilter *And(Prefilter *a, Prefilter *b); // Combines two prefilters together to create an OR. The passed // Prefilters will be part of the returned Prefilter or deleted. - static Prefilter* Or(Prefilter* a, Prefilter* b); + static Prefilter *Or(Prefilter *a, Prefilter *b); // Generalized And/Or - static Prefilter* AndOr(Op op, Prefilter* a, Prefilter* b); + static Prefilter *AndOr(Op op, Prefilter *a, Prefilter *b); - static Prefilter* FromRegexp(Regexp* a); + static Prefilter *FromRegexp(Regexp *a); - static Prefilter* FromString(const std::string& str); + static Prefilter *FromString(const std::string &str); - static Prefilter* OrStrings(SSet* ss); + static Prefilter *OrStrings(SSet *ss); - static Info* BuildInfo(Regexp* re); + static Info *BuildInfo(Regexp *re); - Prefilter* Simplify(); + Prefilter *Simplify(); // Removes redundant strings from the set. A string is redundant if // any of the other strings appear as a substring. The empty string // is a special case, which is ignored. - static void SimplifyStringSet(SSet* ss); + static void SimplifyStringSet(SSet *ss); // Adds the cross-product of a and b to dst. // (For each string i in a and j in b, add i+j.) - static void CrossProduct(const SSet& a, const SSet& b, SSet* dst); + static void CrossProduct(const SSet &a, const SSet &b, SSet *dst); // Kind of Prefilter. Op op_; // Sub-matches for AND or OR Prefilter. - std::vector* subs_; + std::vector *subs_; // Actual string to match in leaf node. std::string atom_; @@ -121,10 +121,10 @@ class Prefilter { // and -1 for duplicate nodes. int unique_id_; - Prefilter(const Prefilter&) = delete; - Prefilter& operator=(const Prefilter&) = delete; + Prefilter(const Prefilter &) = delete; + Prefilter &operator=(const Prefilter &) = delete; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_PREFILTER_H_ +#endif // RE2_PREFILTER_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h index 6de1c38e..586f7180 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h @@ -20,14 +20,14 @@ #include #include -#include "util/util.h" #include "re2/prefilter.h" #include "re2/sparse_array.h" +#include "util/util.h" namespace re2 { class PrefilterTree { - public: +public: PrefilterTree(); explicit PrefilterTree(int min_atom_len); ~PrefilterTree(); @@ -35,7 +35,7 @@ class PrefilterTree { // Adds the prefilter for the next regexp. Note that we assume that // Add called sequentially for all regexps. All Add calls // must precede Compile. - void Add(Prefilter* prefilter); + void Add(Prefilter *prefilter); // The Compile returns a vector of string in atom_vec. // Call this after all the prefilters are added through Add. @@ -43,30 +43,30 @@ class PrefilterTree { // The caller should use the returned set of strings to do string matching. // Each time a string matches, the corresponding index then has to be // and passed to RegexpsGivenStrings below. - void Compile(std::vector* atom_vec); + void Compile(std::vector *atom_vec); // Given the indices of the atoms that matched, returns the indexes // of regexps that should be searched. The matched_atoms should // contain all the ids of string atoms that were found to match the // content. The caller can use any string match engine to perform // this function. This function is thread safe. - void RegexpsGivenStrings(const std::vector& matched_atoms, - std::vector* regexps) const; + void RegexpsGivenStrings(const std::vector &matched_atoms, + std::vector *regexps) const; // Print debug prefilter. Also prints unique ids associated with // nodes of the prefilter of the regexp. void PrintPrefilter(int regexpid); - private: +private: typedef SparseArray IntMap; // TODO(junyer): Use std::unordered_set instead? // It should be trivial to get rid of the stringification... - typedef std::map NodeMap; + typedef std::map NodeMap; // Each unique node has a corresponding Entry that helps in // passing the matching trigger information along the tree. struct Entry { - public: + public: // How many children should match before this node triggers the // parent. For an atom and an OR node, this is 1 and for an AND // node, it is the number of unique children. @@ -86,30 +86,29 @@ class PrefilterTree { }; // Returns true if the prefilter node should be kept. - bool KeepNode(Prefilter* node) const; + bool KeepNode(Prefilter *node) const; // This function assigns unique ids to various parts of the // prefilter, by looking at if these nodes are already in the // PrefilterTree. - void AssignUniqueIds(NodeMap* nodes, std::vector* atom_vec); + void AssignUniqueIds(NodeMap *nodes, std::vector *atom_vec); // Given the matching atoms, find the regexps to be triggered. - void PropagateMatch(const std::vector& atom_ids, - IntMap* regexps) const; + void PropagateMatch(const std::vector &atom_ids, IntMap *regexps) const; // Returns the prefilter node that has the same NodeString as this // node. For the canonical node, returns node. - Prefilter* CanonicalNode(NodeMap* nodes, Prefilter* node); + Prefilter *CanonicalNode(NodeMap *nodes, Prefilter *node); // A string that uniquely identifies the node. Assumes that the // children of node has already been assigned unique ids. - std::string NodeString(Prefilter* node) const; + std::string NodeString(Prefilter *node) const; // Recursively constructs a readable prefilter string. - std::string DebugNodeString(Prefilter* node) const; + std::string DebugNodeString(Prefilter *node) const; // Used for debugging. - void PrintDebugInfo(NodeMap* nodes); + void PrintDebugInfo(NodeMap *nodes); // These are all the nodes formed by Compile. Essentially, there is // one node for each unique atom and each unique AND/OR node. @@ -120,7 +119,7 @@ class PrefilterTree { std::vector unfiltered_; // vector of Prefilter for all regexps. - std::vector prefilter_vec_; + std::vector prefilter_vec_; // Atom index in returned strings to entry id mapping. std::vector atom_index_to_id_; @@ -131,10 +130,10 @@ class PrefilterTree { // Strings less than this length are not stored as atoms. const int min_atom_len_; - PrefilterTree(const PrefilterTree&) = delete; - PrefilterTree& operator=(const PrefilterTree&) = delete; + PrefilterTree(const PrefilterTree &) = delete; + PrefilterTree &operator=(const PrefilterTree &) = delete; }; -} // namespace +} // namespace re2 -#endif // RE2_PREFILTER_TREE_H_ +#endif // RE2_PREFILTER_TREE_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h index 72c9856d..a4432a21 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h @@ -9,44 +9,45 @@ // See regexp.h for the Regexp class, which represents a regular // expression symbolically. -#include #include #include +#include #include -#include #include +#include -#include "util/util.h" -#include "util/logging.h" #include "re2/pod_array.h" #include "re2/re2.h" #include "re2/sparse_array.h" #include "re2/sparse_set.h" +#include "util/logging.h" +#include "util/util.h" namespace re2 { // Opcodes for Inst enum InstOp { - kInstAlt = 0, // choose between out_ and out1_ - kInstAltMatch, // Alt: out_ is [00-FF] and back, out1_ is match; or vice versa. - kInstByteRange, // next (possible case-folded) byte must be in [lo_, hi_] - kInstCapture, // capturing parenthesis number cap_ - kInstEmptyWidth, // empty-width special (^ $ ...); bit(s) set in empty_ - kInstMatch, // found a match! - kInstNop, // no-op; occasionally unavoidable - kInstFail, // never match; occasionally unavoidable + kInstAlt = 0, // choose between out_ and out1_ + kInstAltMatch, // Alt: out_ is [00-FF] and back, out1_ is match; or vice + // versa. + kInstByteRange, // next (possible case-folded) byte must be in [lo_, hi_] + kInstCapture, // capturing parenthesis number cap_ + kInstEmptyWidth, // empty-width special (^ $ ...); bit(s) set in empty_ + kInstMatch, // found a match! + kInstNop, // no-op; occasionally unavoidable + kInstFail, // never match; occasionally unavoidable kNumInst, }; // Bit flags for empty-width specials enum EmptyOp { - kEmptyBeginLine = 1<<0, // ^ - beginning of line - kEmptyEndLine = 1<<1, // $ - end of line - kEmptyBeginText = 1<<2, // \A - beginning of text - kEmptyEndText = 1<<3, // \z - end of text - kEmptyWordBoundary = 1<<4, // \b - word boundary - kEmptyNonWordBoundary = 1<<5, // \B - not \b - kEmptyAllFlags = (1<<6)-1, + kEmptyBeginLine = 1 << 0, // ^ - beginning of line + kEmptyEndLine = 1 << 1, // $ - end of line + kEmptyBeginText = 1 << 2, // \A - beginning of text + kEmptyEndText = 1 << 3, // \z - end of text + kEmptyWordBoundary = 1 << 4, // \b - word boundary + kEmptyNonWordBoundary = 1 << 5, // \B - not \b + kEmptyAllFlags = (1 << 6) - 1, }; class DFA; @@ -54,19 +55,19 @@ class Regexp; // Compiled form of regexp program. class Prog { - public: +public: Prog(); ~Prog(); // Single instruction in regexp program. class Inst { - public: + public: // See the assertion below for why this is so. Inst() = default; // Copyable. - Inst(const Inst&) = default; - Inst& operator=(const Inst&) = default; + Inst(const Inst &) = default; + Inst &operator=(const Inst &) = default; // Constructors per opcode void InitAlt(uint32_t out, uint32_t out1); @@ -78,20 +79,44 @@ class Prog { void InitFail(); // Getters - int id(Prog* p) { return static_cast(this - p->inst_.data()); } - InstOp opcode() { return static_cast(out_opcode_&7); } - int last() { return (out_opcode_>>3)&1; } - int out() { return out_opcode_>>4; } - int out1() { DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); return out1_; } - int cap() { DCHECK_EQ(opcode(), kInstCapture); return cap_; } - int lo() { DCHECK_EQ(opcode(), kInstByteRange); return lo_; } - int hi() { DCHECK_EQ(opcode(), kInstByteRange); return hi_; } - int foldcase() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_&1; } - int hint() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_>>1; } - int match_id() { DCHECK_EQ(opcode(), kInstMatch); return match_id_; } - EmptyOp empty() { DCHECK_EQ(opcode(), kInstEmptyWidth); return empty_; } - - bool greedy(Prog* p) { + int id(Prog *p) { return static_cast(this - p->inst_.data()); } + InstOp opcode() { return static_cast(out_opcode_ & 7); } + int last() { return (out_opcode_ >> 3) & 1; } + int out() { return out_opcode_ >> 4; } + int out1() { + DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); + return out1_; + } + int cap() { + DCHECK_EQ(opcode(), kInstCapture); + return cap_; + } + int lo() { + DCHECK_EQ(opcode(), kInstByteRange); + return lo_; + } + int hi() { + DCHECK_EQ(opcode(), kInstByteRange); + return hi_; + } + int foldcase() { + DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ & 1; + } + int hint() { + DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ >> 1; + } + int match_id() { + DCHECK_EQ(opcode(), kInstMatch); + return match_id_; + } + EmptyOp empty() { + DCHECK_EQ(opcode(), kInstEmptyWidth); + return empty_; + } + + bool greedy(Prog *p) { DCHECK_EQ(opcode(), kInstAltMatch); return p->inst(out())->opcode() == kInstByteRange || (p->inst(out())->opcode() == kInstNop && @@ -111,54 +136,53 @@ class Prog { // Maximum instruction id. // (Must fit in out_opcode_. PatchList/last steal another bit.) - static const int kMaxInst = (1<<28) - 1; + static const int kMaxInst = (1 << 28) - 1; - private: + private: void set_opcode(InstOp opcode) { - out_opcode_ = (out()<<4) | (last()<<3) | opcode; + out_opcode_ = (out() << 4) | (last() << 3) | opcode; } - void set_last() { - out_opcode_ = (out()<<4) | (1<<3) | opcode(); - } + void set_last() { out_opcode_ = (out() << 4) | (1 << 3) | opcode(); } void set_out(int out) { - out_opcode_ = (out<<4) | (last()<<3) | opcode(); + out_opcode_ = (out << 4) | (last() << 3) | opcode(); } void set_out_opcode(int out, InstOp opcode) { - out_opcode_ = (out<<4) | (last()<<3) | opcode; + out_opcode_ = (out << 4) | (last() << 3) | opcode; } - uint32_t out_opcode_; // 28 bits: out, 1 bit: last, 3 (low) bits: opcode - union { // additional instruction arguments: - uint32_t out1_; // opcode == kInstAlt - // alternate next instruction - - int32_t cap_; // opcode == kInstCapture - // Index of capture register (holds text - // position recorded by capturing parentheses). - // For \n (the submatch for the nth parentheses), - // the left parenthesis captures into register 2*n - // and the right one captures into register 2*n+1. - - int32_t match_id_; // opcode == kInstMatch - // Match ID to identify this match (for re2::Set). - - struct { // opcode == kInstByteRange - uint8_t lo_; // byte range is lo_-hi_ inclusive - uint8_t hi_; // - uint16_t hint_foldcase_; // 15 bits: hint, 1 (low) bit: foldcase - // hint to execution engines: the delta to the - // next instruction (in the current list) worth - // exploring iff this instruction matched; 0 - // means there are no remaining possibilities, - // which is most likely for character classes. - // foldcase: A-Z -> a-z before checking range. + uint32_t out_opcode_; // 28 bits: out, 1 bit: last, 3 (low) bits: opcode + union { // additional instruction arguments: + uint32_t out1_; // opcode == kInstAlt + // alternate next instruction + + int32_t cap_; // opcode == kInstCapture + // Index of capture register (holds text + // position recorded by capturing parentheses). + // For \n (the submatch for the nth parentheses), + // the left parenthesis captures into register 2*n + // and the right one captures into register 2*n+1. + + int32_t match_id_; // opcode == kInstMatch + // Match ID to identify this match (for re2::Set). + + struct { // opcode == kInstByteRange + uint8_t lo_; // byte range is lo_-hi_ inclusive + uint8_t hi_; // + uint16_t + hint_foldcase_; // 15 bits: hint, 1 (low) bit: foldcase + // hint to execution engines: the delta to the + // next instruction (in the current list) worth + // exploring iff this instruction matched; 0 + // means there are no remaining possibilities, + // which is most likely for character classes. + // foldcase: A-Z -> a-z before checking range. }; - EmptyOp empty_; // opcode == kInstEmptyWidth - // empty_ is bitwise OR of kEmpty* flags above. + EmptyOp empty_; // opcode == kInstEmptyWidth + // empty_ is bitwise OR of kEmpty* flags above. }; friend class Compiler; @@ -173,8 +197,8 @@ class Prog { // Whether to anchor the search. enum Anchor { - kUnanchored, // match anywhere - kAnchored, // match only starting at beginning of text + kUnanchored, // match anywhere + kAnchored, // match only starting at beginning of text }; // Kind of match to look for (for anchor != kFullMatch) @@ -190,10 +214,10 @@ class Prog { // the matching code can run faster if it knows to consider only // full matches. enum MatchKind { - kFirstMatch, // like Perl, PCRE - kLongestMatch, // like egrep or POSIX - kFullMatch, // match only entire text; implies anchor==kAnchored - kManyMatch // for SearchDFA, records set of matches + kFirstMatch, // like Perl, PCRE + kLongestMatch, // like egrep or POSIX + kFullMatch, // match only entire text; implies anchor==kAnchored + kManyMatch // for SearchDFA, records set of matches }; Inst *inst(int id) { return &inst_[id]; } @@ -206,7 +230,7 @@ class Prog { void set_reversed(bool reversed) { reversed_ = reversed; } int list_count() { return list_count_; } int inst_count(InstOp op) { return inst_count_[op]; } - uint16_t* list_heads() { return list_heads_.data(); } + uint16_t *list_heads() { return list_heads_.data(); } size_t bit_state_text_max_size() { return bit_state_text_max_size_; } int64_t dfa_mem() { return dfa_mem_; } void set_dfa_mem(int64_t dfa_mem) { dfa_mem_ = dfa_mem; } @@ -215,12 +239,12 @@ class Prog { bool anchor_end() { return anchor_end_; } void set_anchor_end(bool b) { anchor_end_ = b; } int bytemap_range() { return bytemap_range_; } - const uint8_t* bytemap() { return bytemap_; } + const uint8_t *bytemap() { return bytemap_; } bool can_prefix_accel() { return prefix_size_ != 0; } // Accelerates to the first likely occurrence of the prefix. // Returns a pointer to the first byte or NULL if not found. - const void* PrefixAccel(const void* data, size_t size) { + const void *PrefixAccel(const void *data, size_t size) { DCHECK(can_prefix_accel()); if (prefix_foldcase_) { return PrefixAccel_ShiftDFA(data, size); @@ -232,15 +256,15 @@ class Prog { } // Configures prefix accel using the analysis performed during compilation. - void ConfigurePrefixAccel(const std::string& prefix, bool prefix_foldcase); + void ConfigurePrefixAccel(const std::string &prefix, bool prefix_foldcase); // An implementation of prefix accel that uses prefix_dfa_ to perform // case-insensitive search. - const void* PrefixAccel_ShiftDFA(const void* data, size_t size); + const void *PrefixAccel_ShiftDFA(const void *data, size_t size); // An implementation of prefix accel that looks for prefix_front_ and // prefix_back_ to return fewer false positives than memchr(3) alone. - const void* PrefixAccel_FrontAndBack(const void* data, size_t size); + const void *PrefixAccel_FrontAndBack(const void *data, size_t size); // Returns string representation of program for debugging. std::string Dump(); @@ -249,7 +273,7 @@ class Prog { // Returns the set of kEmpty flags that are in effect at // position p within context. - static uint32_t EmptyFlags(const StringPiece& context, const char* p); + static uint32_t EmptyFlags(const StringPiece &context, const char *p); // Returns whether byte c is a word character: ASCII only. // Used by the implementation of \b and \B. @@ -259,10 +283,8 @@ class Prog { // - even if the lookahead were possible, the Progs would be huge. // This crude approximation is the same one PCRE uses. static bool IsWordChar(uint8_t c) { - return ('A' <= c && c <= 'Z') || - ('a' <= c && c <= 'z') || - ('0' <= c && c <= '9') || - c == '_'; + return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || + ('0' <= c && c <= '9') || c == '_'; } // Execution engines. They all search for the regexp (run the prog) @@ -280,9 +302,8 @@ class Prog { // match anything. Either way, match[i] == NULL. // Search using NFA: can find submatches but kind of slow. - bool SearchNFA(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchNFA(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, int nmatch); // Search using DFA: much faster than NFA but only finds // end of match and can use a lot more memory. @@ -290,9 +311,9 @@ class Prog { // If the DFA runs out of memory, sets *failed to true and returns false. // If matches != NULL and kind == kManyMatch and there is a match, // SearchDFA fills matches with the match IDs of the final matching state. - bool SearchDFA(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, StringPiece* match0, - bool* failed, SparseSet* matches); + bool SearchDFA(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match0, + bool *failed, SparseSet *matches); // The callback issued after building each DFA state with BuildEntireDFA(). // If next is null, then the memory budget has been exhausted and building @@ -301,7 +322,7 @@ class Prog { // kByteEndText. The number of the state is implied by the callback sequence: // the first callback is for state 0, the second callback is for state 1, ... // match indicates whether the state is a matching state. - using DFAStateCallback = std::function; + using DFAStateCallback = std::function; // Build the entire DFA for the given match kind. // Usually the DFA is built out incrementally, as needed, which @@ -309,7 +330,7 @@ class Prog { // If cb is not empty, it receives one callback per state built. // Returns the number of states built. // FOR TESTING OR EXPERIMENTAL PURPOSES ONLY. - int BuildEntireDFA(MatchKind kind, const DFAStateCallback& cb); + int BuildEntireDFA(MatchKind kind, const DFAStateCallback &cb); // Compute bytemap. void ComputeByteMap(); @@ -321,18 +342,18 @@ class Prog { // but much faster than NFA (competitive with PCRE) // for those expressions. bool IsOnePass(); - bool SearchOnePass(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchOnePass(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, + int nmatch); // Bit-state backtracking. Fast on small cases but uses memory // proportional to the product of the list count and the text size. bool CanBitState() { return list_heads_.data() != NULL; } - bool SearchBitState(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool SearchBitState(const StringPiece &text, const StringPiece &context, + Anchor anchor, MatchKind kind, StringPiece *match, + int nmatch); - static const int kMaxOnePassCapture = 5; // $0 through $4 + static const int kMaxOnePassCapture = 5; // $0 through $4 // Backtracking search: the gold standard against which the other // implementations are checked. FOR TESTING ONLY. @@ -340,10 +361,9 @@ class Prog { // It is also recursive, so can't use in production (will overflow stacks). // The name "Unsafe" here is supposed to be a flag that // you should not be using this function. - bool UnsafeSearchBacktrack(const StringPiece& text, - const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match, int nmatch); + bool UnsafeSearchBacktrack(const StringPiece &text, + const StringPiece &context, Anchor anchor, + MatchKind kind, StringPiece *match, int nmatch); // Computes range for any strings matching regexp. The min and max can in // some cases be arbitrarily precise, so the caller gets to specify the @@ -359,14 +379,14 @@ class Prog { // do not compile down to infinite repetitions. // // Returns true on success, false on error. - bool PossibleMatchRange(std::string* min, std::string* max, int maxlen); + bool PossibleMatchRange(std::string *min, std::string *max, int maxlen); // Outputs the program fanout into the given sparse array. - void Fanout(SparseArray* fanout); + void Fanout(SparseArray *fanout); // Compiles a collection of regexps to Prog. Each regexp will have // its own Match instruction recording the index in the output vector. - static Prog* CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem); + static Prog *CompileSet(Regexp *re, RE2::Anchor anchor, int64_t max_mem); // Flattens the Prog from "tree" form to "list" form. This is an in-place // operation in the sense that the old instructions are lost. @@ -375,93 +395,89 @@ class Prog { // Walks the Prog; the "successor roots" or predecessors of the reachable // instructions are marked in rootmap or predmap/predvec, respectively. // reachable and stk are preallocated scratch structures. - void MarkSuccessors(SparseArray* rootmap, - SparseArray* predmap, - std::vector>* predvec, - SparseSet* reachable, std::vector* stk); + void MarkSuccessors(SparseArray *rootmap, SparseArray *predmap, + std::vector> *predvec, + SparseSet *reachable, std::vector *stk); // Walks the Prog from the given "root" instruction; the "dominator root" // of the reachable instructions (if such exists) is marked in rootmap. // reachable and stk are preallocated scratch structures. - void MarkDominator(int root, SparseArray* rootmap, - SparseArray* predmap, - std::vector>* predvec, - SparseSet* reachable, std::vector* stk); + void MarkDominator(int root, SparseArray *rootmap, + SparseArray *predmap, + std::vector> *predvec, + SparseSet *reachable, std::vector *stk); // Walks the Prog from the given "root" instruction; the reachable // instructions are emitted in "list" form and appended to flat. // reachable and stk are preallocated scratch structures. - void EmitList(int root, SparseArray* rootmap, - std::vector* flat, - SparseSet* reachable, std::vector* stk); + void EmitList(int root, SparseArray *rootmap, std::vector *flat, + SparseSet *reachable, std::vector *stk); // Computes hints for ByteRange instructions in [begin, end). - void ComputeHints(std::vector* flat, int begin, int end); + void ComputeHints(std::vector *flat, int begin, int end); // Controls whether the DFA should bail out early if the NFA would be faster. // FOR TESTING ONLY. static void TESTING_ONLY_set_dfa_should_bail_when_slow(bool b); - private: +private: friend class Compiler; - DFA* GetDFA(MatchKind kind); - void DeleteDFA(DFA* dfa); + DFA *GetDFA(MatchKind kind); + void DeleteDFA(DFA *dfa); - bool anchor_start_; // regexp has explicit start anchor - bool anchor_end_; // regexp has explicit end anchor - bool reversed_; // whether program runs backward over input - bool did_flatten_; // has Flatten been called? - bool did_onepass_; // has IsOnePass been called? + bool anchor_start_; // regexp has explicit start anchor + bool anchor_end_; // regexp has explicit end anchor + bool reversed_; // whether program runs backward over input + bool did_flatten_; // has Flatten been called? + bool did_onepass_; // has IsOnePass been called? - int start_; // entry point for program - int start_unanchored_; // unanchored entry point for program - int size_; // number of instructions - int bytemap_range_; // bytemap_[x] < bytemap_range_ + int start_; // entry point for program + int start_unanchored_; // unanchored entry point for program + int size_; // number of instructions + int bytemap_range_; // bytemap_[x] < bytemap_range_ - bool prefix_foldcase_; // whether prefix is case-insensitive - size_t prefix_size_; // size of prefix (0 if no prefix) + bool prefix_foldcase_; // whether prefix is case-insensitive + size_t prefix_size_; // size of prefix (0 if no prefix) union { - uint64_t* prefix_dfa_; // "Shift DFA" for prefix + uint64_t *prefix_dfa_; // "Shift DFA" for prefix struct { - int prefix_front_; // first byte of prefix - int prefix_back_; // last byte of prefix + int prefix_front_; // first byte of prefix + int prefix_back_; // last byte of prefix }; }; - int list_count_; // count of lists (see above) - int inst_count_[kNumInst]; // count of instructions by opcode - PODArray list_heads_; // sparse array enumerating list heads - // not populated if size_ is overly large - size_t bit_state_text_max_size_; // upper bound (inclusive) on text.size() + int list_count_; // count of lists (see above) + int inst_count_[kNumInst]; // count of instructions by opcode + PODArray list_heads_; // sparse array enumerating list heads + // not populated if size_ is overly large + size_t bit_state_text_max_size_; // upper bound (inclusive) on text.size() - PODArray inst_; // pointer to instruction array - PODArray onepass_nodes_; // data for OnePass nodes + PODArray inst_; // pointer to instruction array + PODArray onepass_nodes_; // data for OnePass nodes - int64_t dfa_mem_; // Maximum memory for DFAs. - DFA* dfa_first_; // DFA cached for kFirstMatch/kManyMatch - DFA* dfa_longest_; // DFA cached for kLongestMatch/kFullMatch + int64_t dfa_mem_; // Maximum memory for DFAs. + DFA *dfa_first_; // DFA cached for kFirstMatch/kManyMatch + DFA *dfa_longest_; // DFA cached for kLongestMatch/kFullMatch - uint8_t bytemap_[256]; // map from input bytes to byte classes + uint8_t bytemap_[256]; // map from input bytes to byte classes std::once_flag dfa_first_once_; std::once_flag dfa_longest_once_; - Prog(const Prog&) = delete; - Prog& operator=(const Prog&) = delete; + Prog(const Prog &) = delete; + Prog &operator=(const Prog &) = delete; }; // std::string_view in MSVC has iterators that aren't just pointers and // that don't allow comparisons between different objects - not even if // those objects are views into the same string! Thus, we provide these // conversion functions for convenience. -static inline const char* BeginPtr(const StringPiece& s) { - return s.data(); -} -static inline const char* EndPtr(const StringPiece& s) { +static inline const char *BeginPtr(const StringPiece &s) { return s.data(); } +static inline const char *EndPtr(const StringPiece &s) { return s.data() + s.size(); } -} // namespace re2 +} // namespace re2 -#endif // RE2_PROG_H_ +#endif // RE2_PROG_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h index 449162a2..a6fb4416 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h @@ -202,11 +202,11 @@ // RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d)); // will leave 64 in a, b, c, and d. -#include -#include #include #include #include +#include +#include #include #include #include @@ -220,7 +220,7 @@ namespace re2 { class Prog; class Regexp; -} // namespace re2 +} // namespace re2 namespace re2 { @@ -228,7 +228,7 @@ namespace re2 { // pre-compiled regular expression. An "RE2" object is safe for // concurrent use by multiple threads. class RE2 { - public: +public: // We convert user-passed pointers into special Arg objects class Arg; class Options; @@ -243,20 +243,20 @@ class RE2 { ErrorInternal, // Parse errors - ErrorBadEscape, // bad escape sequence - ErrorBadCharClass, // bad character class - ErrorBadCharRange, // bad character class range - ErrorMissingBracket, // missing closing ] - ErrorMissingParen, // missing closing ) - ErrorUnexpectedParen, // unexpected closing ) - ErrorTrailingBackslash, // trailing \ at end of regexp - ErrorRepeatArgument, // repeat argument missing, e.g. "*" - ErrorRepeatSize, // bad repetition argument - ErrorRepeatOp, // bad repetition operator - ErrorBadPerlOp, // bad perl operator - ErrorBadUTF8, // invalid UTF-8 in regexp - ErrorBadNamedCapture, // bad named capture group - ErrorPatternTooLarge // pattern too large (compile failed) + ErrorBadEscape, // bad escape sequence + ErrorBadCharClass, // bad character class + ErrorBadCharRange, // bad character class range + ErrorMissingBracket, // missing closing ] + ErrorMissingParen, // missing closing ) + ErrorUnexpectedParen, // unexpected closing ) + ErrorTrailingBackslash, // trailing \ at end of regexp + ErrorRepeatArgument, // repeat argument missing, e.g. "*" + ErrorRepeatSize, // bad repetition argument + ErrorRepeatOp, // bad repetition operator + ErrorBadPerlOp, // bad perl operator + ErrorBadUTF8, // invalid UTF-8 in regexp + ErrorBadNamedCapture, // bad named capture group + ErrorPatternTooLarge // pattern too large (compile failed) }; // Predefined common options. @@ -267,32 +267,32 @@ class RE2 { enum CannedOptions { DefaultOptions = 0, Latin1, // treat input as Latin-1 (default UTF-8) - POSIX, // POSIX syntax, leftmost-longest match - Quiet // do not log about regexp parse errors + POSIX, // POSIX syntax, leftmost-longest match + Quiet // do not log about regexp parse errors }; // Need to have the const char* and const std::string& forms for implicit // conversions when passing string literals to FullMatch and PartialMatch. // Otherwise the StringPiece form would be sufficient. - RE2(const char* pattern); - RE2(const std::string& pattern); - RE2(const StringPiece& pattern); - RE2(const StringPiece& pattern, const Options& options); + RE2(const char *pattern); + RE2(const std::string &pattern); + RE2(const StringPiece &pattern); + RE2(const StringPiece &pattern, const Options &options); ~RE2(); // Not copyable. // RE2 objects are expensive. You should probably use std::shared_ptr // instead. If you really must copy, RE2(first.pattern(), first.options()) // effectively does so: it produces a second object that mimics the first. - RE2(const RE2&) = delete; - RE2& operator=(const RE2&) = delete; + RE2(const RE2 &) = delete; + RE2 &operator=(const RE2 &) = delete; // Not movable. // RE2 objects are thread-safe and logically immutable. You should probably // use std::unique_ptr instead. Otherwise, consider std::deque if // direct emplacement into a container is desired. If you really must move, // be prepared to submit a design document along with your feature request. - RE2(RE2&&) = delete; - RE2& operator=(RE2&&) = delete; + RE2(RE2 &&) = delete; + RE2 &operator=(RE2 &&) = delete; // Returns whether RE2 was created properly. bool ok() const { return error_code() == NoError; } @@ -300,11 +300,11 @@ class RE2 { // The string specification for this RE2. E.g. // RE2 re("ab*c?d+"); // re.pattern(); // "ab*c?d+" - const std::string& pattern() const { return *pattern_; } + const std::string &pattern() const { return *pattern_; } // If RE2 could not be created properly, returns an error string. // Else returns the empty string. - const std::string& error() const { return *error_; } + const std::string &error() const { return *error_; } // If RE2 could not be created properly, returns an error code. // Else returns RE2::NoError (== 0). @@ -312,7 +312,7 @@ class RE2 { // If RE2 could not be created properly, returns the offending // portion of the regexp. - const std::string& error_arg() const { return *error_arg_; } + const std::string &error_arg() const { return *error_arg_; } // Returns the program size, a very approximate measure of a regexp's "cost". // Larger numbers are more expensive than smaller numbers. @@ -322,13 +322,13 @@ class RE2 { // If histogram is not null, outputs the program fanout // as a histogram bucketed by powers of 2. // Returns the number of the largest non-empty bucket. - int ProgramFanout(std::vector* histogram) const; - int ReverseProgramFanout(std::vector* histogram) const; + int ProgramFanout(std::vector *histogram) const; + int ReverseProgramFanout(std::vector *histogram) const; // Returns the underlying Regexp; not for general use. // Returns entire_regexp_ so that callers don't need // to know about prefix_ and prefix_foldcase_. - re2::Regexp* Regexp() const { return entire_regexp_; } + re2::Regexp *Regexp() const { return entire_regexp_; } /***** The array-based matching interface ******/ @@ -336,29 +336,29 @@ class RE2 { // the functions whose names are the prefix before the 'N'. It is sometimes // useful to invoke them directly, but the syntax is awkward, so the 'N'-less // versions should be preferred. - static bool FullMatchN(const StringPiece& text, const RE2& re, - const Arg* const args[], int n); - static bool PartialMatchN(const StringPiece& text, const RE2& re, - const Arg* const args[], int n); - static bool ConsumeN(StringPiece* input, const RE2& re, - const Arg* const args[], int n); - static bool FindAndConsumeN(StringPiece* input, const RE2& re, - const Arg* const args[], int n); - - private: + static bool FullMatchN(const StringPiece &text, const RE2 &re, + const Arg *const args[], int n); + static bool PartialMatchN(const StringPiece &text, const RE2 &re, + const Arg *const args[], int n); + static bool ConsumeN(StringPiece *input, const RE2 &re, + const Arg *const args[], int n); + static bool FindAndConsumeN(StringPiece *input, const RE2 &re, + const Arg *const args[], int n); + +private: template - static inline bool Apply(F f, SP sp, const RE2& re) { + static inline bool Apply(F f, SP sp, const RE2 &re) { return f(sp, re, NULL, 0); } template - static inline bool Apply(F f, SP sp, const RE2& re, const A&... a) { - const Arg* const args[] = {&a...}; + static inline bool Apply(F f, SP sp, const RE2 &re, const A &...a) { + const Arg *const args[] = {&a...}; const int n = sizeof...(a); return f(sp, re, args, n); } - public: +public: // In order to allow FullMatch() et al. to be called with a varying number // of arguments of varying types, we use two layers of variadic templates. // The first layer constructs the temporary Arg objects. The second layer @@ -395,7 +395,7 @@ class RE2 { // int number; // RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number); template - static bool FullMatch(const StringPiece& text, const RE2& re, A&&... a) { + static bool FullMatch(const StringPiece &text, const RE2 &re, A &&...a) { return Apply(FullMatchN, text, re, Arg(std::forward(a))...); } @@ -411,7 +411,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool PartialMatch(const StringPiece& text, const RE2& re, A&&... a) { + static bool PartialMatch(const StringPiece &text, const RE2 &re, A &&...a) { return Apply(PartialMatchN, text, re, Arg(std::forward(a))...); } @@ -429,7 +429,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool Consume(StringPiece* input, const RE2& re, A&&... a) { + static bool Consume(StringPiece *input, const RE2 &re, A &&...a) { return Apply(ConsumeN, input, re, Arg(std::forward(a))...); } @@ -447,7 +447,7 @@ class RE2 { // number of sub-patterns, the "i"th captured sub-pattern is // ignored. template - static bool FindAndConsume(StringPiece* input, const RE2& re, A&&... a) { + static bool FindAndConsume(StringPiece *input, const RE2 &re, A &&...a) { return Apply(FindAndConsumeN, input, re, Arg(std::forward(a))...); } @@ -464,9 +464,8 @@ class RE2 { // // Returns true if the pattern matches and a replacement occurs, // false otherwise. - static bool Replace(std::string* str, - const RE2& re, - const StringPiece& rewrite); + static bool Replace(std::string *str, const RE2 &re, + const StringPiece &rewrite); // Like Replace(), except replaces successive non-overlapping occurrences // of the pattern in the string with the rewrite. E.g. @@ -481,9 +480,8 @@ class RE2 { // replacing "ana" within "banana" makes only one replacement, not two. // // Returns the number of replacements made. - static int GlobalReplace(std::string* str, - const RE2& re, - const StringPiece& rewrite); + static int GlobalReplace(std::string *str, const RE2 &re, + const StringPiece &rewrite); // Like Replace, except that if the pattern matches, "rewrite" // is copied into "out" with substitutions. The non-matching @@ -493,10 +491,8 @@ class RE2 { // successfully; if no match occurs, the string is left unaffected. // // REQUIRES: "text" must not alias any part of "*out". - static bool Extract(const StringPiece& text, - const RE2& re, - const StringPiece& rewrite, - std::string* out); + static bool Extract(const StringPiece &text, const RE2 &re, + const StringPiece &rewrite, std::string *out); // Escapes all potentially meaningful regexp characters in // 'unquoted'. The returned string, used as a regular expression, @@ -504,7 +500,7 @@ class RE2 { // 1.5-2.0? // may become: // 1\.5\-2\.0\? - static std::string QuoteMeta(const StringPiece& unquoted); + static std::string QuoteMeta(const StringPiece &unquoted); // Computes range for any strings matching regexp. The min and max can in // some cases be arbitrarily precise, so the caller gets to specify the @@ -520,16 +516,15 @@ class RE2 { // do not compile down to infinite repetitions. // // Returns true on success, false on error. - bool PossibleMatchRange(std::string* min, std::string* max, - int maxlen) const; + bool PossibleMatchRange(std::string *min, std::string *max, int maxlen) const; // Generic matching interface // Type of match. enum Anchor { - UNANCHORED, // No anchoring - ANCHOR_START, // Anchor at start only - ANCHOR_BOTH // Anchor at start and end + UNANCHORED, // No anchoring + ANCHOR_START, // Anchor at start only + ANCHOR_BOTH // Anchor at start and end }; // Return the number of capturing subpatterns, or -1 if the @@ -541,12 +536,12 @@ class RE2 { // The map records the index of the leftmost group // with the given name. // Only valid until the re is deleted. - const std::map& NamedCapturingGroups() const; + const std::map &NamedCapturingGroups() const; // Return a map from capturing indices to names. // The map has no entries for unnamed groups. // Only valid until the re is deleted. - const std::map& CapturingGroupNames() const; + const std::map &CapturingGroupNames() const; // General matching routine. // Match against text starting at offset startpos @@ -569,12 +564,8 @@ class RE2 { // empty string, but note that on return, it will not be possible to tell // whether submatch i matched the empty string or did not match: // either way, submatch[i].data() == NULL. - bool Match(const StringPiece& text, - size_t startpos, - size_t endpos, - Anchor re_anchor, - StringPiece* submatch, - int nsubmatch) const; + bool Match(const StringPiece &text, size_t startpos, size_t endpos, + Anchor re_anchor, StringPiece *submatch, int nsubmatch) const; // Check that the given rewrite string is suitable for use with this // regular expression. It checks that: @@ -584,26 +575,23 @@ class RE2 { // '\' followed by anything other than a digit or '\'. // A true return value guarantees that Replace() and Extract() won't // fail because of a bad rewrite string. - bool CheckRewriteString(const StringPiece& rewrite, - std::string* error) const; + bool CheckRewriteString(const StringPiece &rewrite, std::string *error) const; // Returns the maximum submatch needed for the rewrite to be done by // Replace(). E.g. if rewrite == "foo \\2,\\1", returns 2. - static int MaxSubmatch(const StringPiece& rewrite); + static int MaxSubmatch(const StringPiece &rewrite); // Append the "rewrite" string, with backslash substitutions from "vec", // to string "out". // Returns true on success. This method can fail because of a malformed // rewrite string. CheckRewriteString guarantees that the rewrite will // be sucessful. - bool Rewrite(std::string* out, - const StringPiece& rewrite, - const StringPiece* vec, - int veclen) const; + bool Rewrite(std::string *out, const StringPiece &rewrite, + const StringPiece *vec, int veclen) const; // Constructor options class Options { - public: + public: // The options are (defaults in parentheses): // // utf8 (true) text and pattern are UTF-8; otherwise Latin-1 @@ -655,28 +643,16 @@ class RE2 { // If this happens too often, RE2 falls back on the NFA implementation. // For now, make the default budget something close to Code Search. - static const int kDefaultMaxMem = 8<<20; - - enum Encoding { - EncodingUTF8 = 1, - EncodingLatin1 - }; - - Options() : - max_mem_(kDefaultMaxMem), - encoding_(EncodingUTF8), - posix_syntax_(false), - longest_match_(false), - log_errors_(true), - literal_(false), - never_nl_(false), - dot_nl_(false), - never_capture_(false), - case_sensitive_(true), - perl_classes_(false), - word_boundary_(false), - one_line_(false) { - } + static const int kDefaultMaxMem = 8 << 20; + + enum Encoding { EncodingUTF8 = 1, EncodingLatin1 }; + + Options() + : max_mem_(kDefaultMaxMem), encoding_(EncodingUTF8), + posix_syntax_(false), longest_match_(false), log_errors_(true), + literal_(false), never_nl_(false), dot_nl_(false), + never_capture_(false), case_sensitive_(true), perl_classes_(false), + word_boundary_(false), one_line_(false) {} /*implicit*/ Options(CannedOptions); @@ -719,13 +695,11 @@ class RE2 { bool one_line() const { return one_line_; } void set_one_line(bool b) { one_line_ = b; } - void Copy(const Options& src) { - *this = src; - } + void Copy(const Options &src) { *this = src; } int ParseFlags() const; - private: + private: int64_t max_mem_; Encoding encoding_; bool posix_syntax_; @@ -742,55 +716,49 @@ class RE2 { }; // Returns the options set in the constructor. - const Options& options() const { return options_; } + const Options &options() const { return options_; } // Argument converters; see below. - template - static Arg CRadix(T* ptr); - template - static Arg Hex(T* ptr); - template - static Arg Octal(T* ptr); + template static Arg CRadix(T *ptr); + template static Arg Hex(T *ptr); + template static Arg Octal(T *ptr); // Controls the maximum count permitted by GlobalReplace(); -1 is unlimited. // FOR FUZZING ONLY. static void FUZZING_ONLY_set_maximum_global_replace_count(int i); - private: - void Init(const StringPiece& pattern, const Options& options); +private: + void Init(const StringPiece &pattern, const Options &options); - bool DoMatch(const StringPiece& text, - Anchor re_anchor, - size_t* consumed, - const Arg* const args[], - int n) const; + bool DoMatch(const StringPiece &text, Anchor re_anchor, size_t *consumed, + const Arg *const args[], int n) const; - re2::Prog* ReverseProg() const; + re2::Prog *ReverseProg() const; // First cache line is relatively cold fields. - const std::string* pattern_; // string regular expression - Options options_; // option flags - re2::Regexp* entire_regexp_; // parsed regular expression - re2::Regexp* suffix_regexp_; // parsed regular expression, prefix_ removed - const std::string* error_; // error indicator (or points to empty string) - const std::string* error_arg_; // fragment of regexp showing error (or ditto) + const std::string *pattern_; // string regular expression + Options options_; // option flags + re2::Regexp *entire_regexp_; // parsed regular expression + re2::Regexp *suffix_regexp_; // parsed regular expression, prefix_ removed + const std::string *error_; // error indicator (or points to empty string) + const std::string *error_arg_; // fragment of regexp showing error (or ditto) // Second cache line is relatively hot fields. // These are ordered oddly to pack everything. - int num_captures_; // number of capturing groups - ErrorCode error_code_ : 29; // error code (29 bits is more than enough) - bool longest_match_ : 1; // cached copy of options_.longest_match() - bool is_one_pass_ : 1; // can use prog_->SearchOnePass? - bool prefix_foldcase_ : 1; // prefix_ is ASCII case-insensitive - std::string prefix_; // required prefix (before suffix_regexp_) - re2::Prog* prog_; // compiled program for regexp + int num_captures_; // number of capturing groups + ErrorCode error_code_ : 29; // error code (29 bits is more than enough) + bool longest_match_ : 1; // cached copy of options_.longest_match() + bool is_one_pass_ : 1; // can use prog_->SearchOnePass? + bool prefix_foldcase_ : 1; // prefix_ is ASCII case-insensitive + std::string prefix_; // required prefix (before suffix_regexp_) + re2::Prog *prog_; // compiled program for regexp // Reverse Prog for DFA execution only - mutable re2::Prog* rprog_; + mutable re2::Prog *rprog_; // Map from capture names to indices - mutable const std::map* named_groups_; + mutable const std::map *named_groups_; // Map from capture indices to names - mutable const std::map* group_names_; + mutable const std::map *group_names_; mutable std::once_flag rprog_once_; mutable std::once_flag named_groups_once_; @@ -812,8 +780,7 @@ template <> struct Parse3ary : public std::true_type {}; template <> struct Parse3ary : public std::true_type {}; template <> struct Parse3ary : public std::true_type {}; -template -bool Parse(const char* str, size_t n, T* dest); +template bool Parse(const char *str, size_t n, T *dest); // Types for which the 4-ary Parse() function template has specializations. template struct Parse4ary : public std::false_type {}; @@ -826,101 +793,96 @@ template <> struct Parse4ary : public std::true_type {}; template <> struct Parse4ary : public std::true_type {}; template <> struct Parse4ary : public std::true_type {}; -template -bool Parse(const char* str, size_t n, T* dest, int radix); +template bool Parse(const char *str, size_t n, T *dest, int radix); -} // namespace re2_internal +} // namespace re2_internal class RE2::Arg { - private: +private: template - using CanParse3ary = typename std::enable_if< - re2_internal::Parse3ary::value, - int>::type; + using CanParse3ary = + typename std::enable_if::value, int>::type; template - using CanParse4ary = typename std::enable_if< - re2_internal::Parse4ary::value, - int>::type; + using CanParse4ary = + typename std::enable_if::value, int>::type; #if !defined(_MSC_VER) template using CanParseFrom = typename std::enable_if< std::is_member_function_pointer< - decltype(static_cast( + decltype(static_cast( &T::ParseFrom))>::value, int>::type; #endif - public: +public: Arg() : Arg(nullptr) {} Arg(std::nullptr_t ptr) : arg_(ptr), parser_(DoNothing) {} template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParse3ary) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParse3ary) {} template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParse4ary) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParse4ary) {} #if !defined(_MSC_VER) template = 0> - Arg(T* ptr) : arg_(ptr), parser_(DoParseFrom) {} + Arg(T *ptr) : arg_(ptr), parser_(DoParseFrom) {} #endif - typedef bool (*Parser)(const char* str, size_t n, void* dest); + typedef bool (*Parser)(const char *str, size_t n, void *dest); template - Arg(T* ptr, Parser parser) : arg_(ptr), parser_(parser) {} + Arg(T *ptr, Parser parser) : arg_(ptr), parser_(parser) {} - bool Parse(const char* str, size_t n) const { + bool Parse(const char *str, size_t n) const { return (*parser_)(str, n, arg_); } - private: - static bool DoNothing(const char* /*str*/, size_t /*n*/, void* /*dest*/) { +private: + static bool DoNothing(const char * /*str*/, size_t /*n*/, void * /*dest*/) { return true; } template - static bool DoParse3ary(const char* str, size_t n, void* dest) { - return re2_internal::Parse(str, n, reinterpret_cast(dest)); + static bool DoParse3ary(const char *str, size_t n, void *dest) { + return re2_internal::Parse(str, n, reinterpret_cast(dest)); } template - static bool DoParse4ary(const char* str, size_t n, void* dest) { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 10); + static bool DoParse4ary(const char *str, size_t n, void *dest) { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 10); } #if !defined(_MSC_VER) template - static bool DoParseFrom(const char* str, size_t n, void* dest) { - if (dest == NULL) return true; - return reinterpret_cast(dest)->ParseFrom(str, n); + static bool DoParseFrom(const char *str, size_t n, void *dest) { + if (dest == NULL) + return true; + return reinterpret_cast(dest)->ParseFrom(str, n); } #endif - void* arg_; - Parser parser_; + void *arg_; + Parser parser_; }; -template -inline RE2::Arg RE2::CRadix(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 0); +template inline RE2::Arg RE2::CRadix(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 0); }); } -template -inline RE2::Arg RE2::Hex(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 16); +template inline RE2::Arg RE2::Hex(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 16); }); } -template -inline RE2::Arg RE2::Octal(T* ptr) { - return RE2::Arg(ptr, [](const char* str, size_t n, void* dest) -> bool { - return re2_internal::Parse(str, n, reinterpret_cast(dest), 8); +template inline RE2::Arg RE2::Octal(T *ptr) { + return RE2::Arg(ptr, [](const char *str, size_t n, void *dest) -> bool { + return re2_internal::Parse(str, n, reinterpret_cast(dest), 8); }); } @@ -941,38 +903,38 @@ inline RE2::Arg RE2::Octal(T* ptr) { // it constructs: that's a feature, so that it can be used // for global and function static variables. class LazyRE2 { - private: +private: struct NoArg {}; - public: - typedef RE2 element_type; // support std::pointer_traits +public: + typedef RE2 element_type; // support std::pointer_traits // Constructor omitted to preserve braced initialization in C++98. // Pretend to be a pointer to Type (never NULL due to on-demand creation): - RE2& operator*() const { return *get(); } - RE2* operator->() const { return get(); } + RE2 &operator*() const { return *get(); } + RE2 *operator->() const { return get(); } // Named accessor/initializer: - RE2* get() const { + RE2 *get() const { std::call_once(once_, &LazyRE2::Init, this); return ptr_; } // All data fields must be public to support {"foo"} initialization. - const char* pattern_; + const char *pattern_; RE2::CannedOptions options_; NoArg barrier_against_excess_initializers_; - mutable RE2* ptr_; + mutable RE2 *ptr_; mutable std::once_flag once_; - private: - static void Init(const LazyRE2* lazy_re2) { +private: + static void Init(const LazyRE2 *lazy_re2) { lazy_re2->ptr_ = new RE2(lazy_re2->pattern_, lazy_re2->options_); } - void operator=(const LazyRE2&); // disallowed + void operator=(const LazyRE2 &); // disallowed }; namespace hooks { @@ -985,7 +947,8 @@ namespace hooks { // As per https://github.com/google/re2/issues/325, thread_local support in // MinGW seems to be buggy. (FWIW, Abseil folks also avoid it.) #define RE2_HAVE_THREAD_LOCAL -#if (defined(__APPLE__) && !(defined(TARGET_OS_OSX) && TARGET_OS_OSX)) || defined(__MINGW32__) +#if (defined(__APPLE__) && !(defined(TARGET_OS_OSX) && TARGET_OS_OSX)) || \ + defined(__MINGW32__) #undef RE2_HAVE_THREAD_LOCAL #endif @@ -999,7 +962,7 @@ namespace hooks { // could result in infinite mutual recursion. To discourage that possibility, // RE2 will not maintain the context pointer correctly when used in that way. #ifdef RE2_HAVE_THREAD_LOCAL -extern thread_local const RE2* context; +extern thread_local const RE2 *context; #endif struct DFAStateCacheReset { @@ -1011,21 +974,21 @@ struct DFASearchFailure { // Nothing yet... }; -#define DECLARE_HOOK(type) \ - using type##Callback = void(const type&); \ - void Set##type##Hook(type##Callback* cb); \ - type##Callback* Get##type##Hook(); +#define DECLARE_HOOK(type) \ + using type##Callback = void(const type &); \ + void Set##type##Hook(type##Callback *cb); \ + type##Callback *Get##type##Hook(); DECLARE_HOOK(DFAStateCacheReset) DECLARE_HOOK(DFASearchFailure) #undef DECLARE_HOOK -} // namespace hooks +} // namespace hooks -} // namespace re2 +} // namespace re2 -using re2::RE2; using re2::LazyRE2; +using re2::RE2; -#endif // RE2_RE2_H_ +#endif // RE2_RE2_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h index b6446f9f..61343ca3 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h @@ -18,9 +18,9 @@ // of regular expressions. // // Any operation that traverses the Regexp structures should be written -// using Regexp::Walker (see walker-inl.h), not recursively, because deeply nested -// regular expressions such as x++++++++++++++++++++... might cause recursive -// traversals to overflow the stack. +// using Regexp::Walker (see walker-inl.h), not recursively, because deeply +// nested regular expressions such as x++++++++++++++++++++... might cause +// recursive traversals to overflow the stack. // // It is the caller's responsibility to provide appropriate mutual exclusion // around manipulation of the regexps. RE2 does this. @@ -86,16 +86,16 @@ // form accessible to clients, so that client code can analyze the // parsed regular expressions. -#include -#include #include #include +#include +#include #include -#include "util/util.h" +#include "re2/stringpiece.h" #include "util/logging.h" #include "util/utf.h" -#include "re2/stringpiece.h" +#include "util/util.h" namespace re2 { @@ -173,36 +173,39 @@ enum RegexpStatusCode { kRegexpInternalError, // Parse errors - kRegexpBadEscape, // bad escape sequence - kRegexpBadCharClass, // bad character class - kRegexpBadCharRange, // bad character class range - kRegexpMissingBracket, // missing closing ] - kRegexpMissingParen, // missing closing ) - kRegexpUnexpectedParen, // unexpected closing ) - kRegexpTrailingBackslash, // at end of regexp - kRegexpRepeatArgument, // repeat argument missing, e.g. "*" - kRegexpRepeatSize, // bad repetition argument - kRegexpRepeatOp, // bad repetition operator - kRegexpBadPerlOp, // bad perl operator - kRegexpBadUTF8, // invalid UTF-8 in regexp - kRegexpBadNamedCapture, // bad named capture + kRegexpBadEscape, // bad escape sequence + kRegexpBadCharClass, // bad character class + kRegexpBadCharRange, // bad character class range + kRegexpMissingBracket, // missing closing ] + kRegexpMissingParen, // missing closing ) + kRegexpUnexpectedParen, // unexpected closing ) + kRegexpTrailingBackslash, // at end of regexp + kRegexpRepeatArgument, // repeat argument missing, e.g. "*" + kRegexpRepeatSize, // bad repetition argument + kRegexpRepeatOp, // bad repetition operator + kRegexpBadPerlOp, // bad perl operator + kRegexpBadUTF8, // invalid UTF-8 in regexp + kRegexpBadNamedCapture, // bad named capture }; // Error status for certain operations. class RegexpStatus { - public: +public: RegexpStatus() : code_(kRegexpSuccess), tmp_(NULL) {} ~RegexpStatus() { delete tmp_; } void set_code(RegexpStatusCode code) { code_ = code; } - void set_error_arg(const StringPiece& error_arg) { error_arg_ = error_arg; } - void set_tmp(std::string* tmp) { delete tmp_; tmp_ = tmp; } + void set_error_arg(const StringPiece &error_arg) { error_arg_ = error_arg; } + void set_tmp(std::string *tmp) { + delete tmp_; + tmp_ = tmp; + } RegexpStatusCode code() const { return code_; } - const StringPiece& error_arg() const { return error_arg_; } + const StringPiece &error_arg() const { return error_arg_; } bool ok() const { return code() == kRegexpSuccess; } // Copies state from status. - void Copy(const RegexpStatus& status); + void Copy(const RegexpStatus &status); // Returns text equivalent of code, e.g.: // "Bad character class" @@ -212,21 +215,21 @@ class RegexpStatus { // "Bad character class: [z-a]" std::string Text() const; - private: - RegexpStatusCode code_; // Kind of error - StringPiece error_arg_; // Piece of regexp containing syntax error. - std::string* tmp_; // Temporary storage, possibly where error_arg_ is. +private: + RegexpStatusCode code_; // Kind of error + StringPiece error_arg_; // Piece of regexp containing syntax error. + std::string *tmp_; // Temporary storage, possibly where error_arg_ is. - RegexpStatus(const RegexpStatus&) = delete; - RegexpStatus& operator=(const RegexpStatus&) = delete; + RegexpStatus(const RegexpStatus &) = delete; + RegexpStatus &operator=(const RegexpStatus &) = delete; }; // Compiled form; see prog.h class Prog; struct RuneRange { - RuneRange() : lo(0), hi(0) { } - RuneRange(int l, int h) : lo(l), hi(h) { } + RuneRange() : lo(0), hi(0) {} + RuneRange(int l, int h) : lo(l), hi(h) {} Rune lo; Rune hi; }; @@ -234,7 +237,7 @@ struct RuneRange { // Less-than on RuneRanges treats a == b if they overlap at all. // This lets us look in a set to find the range covering a particular Rune. struct RuneRangeLess { - bool operator()(const RuneRange& a, const RuneRange& b) const { + bool operator()(const RuneRange &a, const RuneRange &b) const { return a.hi < b.lo; } }; @@ -242,25 +245,25 @@ struct RuneRangeLess { class CharClassBuilder; class CharClass { - public: +public: void Delete(); - typedef RuneRange* iterator; + typedef RuneRange *iterator; iterator begin() { return ranges_; } iterator end() { return ranges_ + nranges_; } int size() { return nrunes_; } bool empty() { return nrunes_ == 0; } - bool full() { return nrunes_ == Runemax+1; } + bool full() { return nrunes_ == Runemax + 1; } bool FoldsASCII() { return folds_ascii_; } bool Contains(Rune r) const; - CharClass* Negate(); + CharClass *Negate(); - private: +private: CharClass(); // not implemented - ~CharClass(); // not implemented - static CharClass* New(size_t maxranges); + ~CharClass(); // not implemented + static CharClass *New(size_t maxranges); friend class CharClassBuilder; @@ -269,54 +272,52 @@ class CharClass { RuneRange *ranges_; int nranges_; - CharClass(const CharClass&) = delete; - CharClass& operator=(const CharClass&) = delete; + CharClass(const CharClass &) = delete; + CharClass &operator=(const CharClass &) = delete; }; class Regexp { - public: - +public: // Flags for parsing. Can be ORed together. enum ParseFlags { - NoParseFlags = 0, - FoldCase = 1<<0, // Fold case during matching (case-insensitive). - Literal = 1<<1, // Treat s as literal string instead of a regexp. - ClassNL = 1<<2, // Allow char classes like [^a-z] and \D and \s - // and [[:space:]] to match newline. - DotNL = 1<<3, // Allow . to match newline. - MatchNL = ClassNL | DotNL, - OneLine = 1<<4, // Treat ^ and $ as only matching at beginning and - // end of text, not around embedded newlines. - // (Perl's default) - Latin1 = 1<<5, // Regexp and text are in Latin1, not UTF-8. - NonGreedy = 1<<6, // Repetition operators are non-greedy by default. - PerlClasses = 1<<7, // Allow Perl character classes like \d. - PerlB = 1<<8, // Allow Perl's \b and \B. - PerlX = 1<<9, // Perl extensions: - // non-capturing parens - (?: ) - // non-greedy operators - *? +? ?? {}? - // flag edits - (?i) (?-i) (?i: ) - // i - FoldCase - // m - !OneLine - // s - DotNL - // U - NonGreedy - // line ends: \A \z - // \Q and \E to disable/enable metacharacters - // (?Pexpr) for named captures - // \C to match any single byte - UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group - // and \P{Han} for its negation. - NeverNL = 1<<11, // Never match NL, even if the regexp mentions - // it explicitly. - NeverCapture = 1<<12, // Parse all parens as non-capturing. + NoParseFlags = 0, + FoldCase = 1 << 0, // Fold case during matching (case-insensitive). + Literal = 1 << 1, // Treat s as literal string instead of a regexp. + ClassNL = 1 << 2, // Allow char classes like [^a-z] and \D and \s + // and [[:space:]] to match newline. + DotNL = 1 << 3, // Allow . to match newline. + MatchNL = ClassNL | DotNL, + OneLine = 1 << 4, // Treat ^ and $ as only matching at beginning and + // end of text, not around embedded newlines. + // (Perl's default) + Latin1 = 1 << 5, // Regexp and text are in Latin1, not UTF-8. + NonGreedy = 1 << 6, // Repetition operators are non-greedy by default. + PerlClasses = 1 << 7, // Allow Perl character classes like \d. + PerlB = 1 << 8, // Allow Perl's \b and \B. + PerlX = 1 << 9, // Perl extensions: + // non-capturing parens - (?: ) + // non-greedy operators - *? +? ?? {}? + // flag edits - (?i) (?-i) (?i: ) + // i - FoldCase + // m - !OneLine + // s - DotNL + // U - NonGreedy + // line ends: \A \z + // \Q and \E to disable/enable metacharacters + // (?Pexpr) for named captures + // \C to match any single byte + UnicodeGroups = 1 << 10, // Allow \p{Han} for Unicode Han group + // and \P{Han} for its negation. + NeverNL = 1 << 11, // Never match NL, even if the regexp mentions + // it explicitly. + NeverCapture = 1 << 12, // Parse all parens as non-capturing. // As close to Perl as we can get. - LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX | - UnicodeGroups, + LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX | UnicodeGroups, // Internal use only. - WasDollar = 1<<13, // on kRegexpEndText: was $ in regexp text - AllParseFlags = (1<<14)-1, + WasDollar = 1 << 13, // on kRegexpEndText: was $ in regexp text + AllParseFlags = (1 << 14) - 1, }; // Get. No set, Regexps are logically immutable once created. @@ -324,27 +325,54 @@ class Regexp { int nsub() { return nsub_; } bool simple() { return simple_ != 0; } ParseFlags parse_flags() { return static_cast(parse_flags_); } - int Ref(); // For testing. + int Ref(); // For testing. - Regexp** sub() { - if(nsub_ <= 1) + Regexp **sub() { + if (nsub_ <= 1) return &subone_; else return submany_; } - int min() { DCHECK_EQ(op_, kRegexpRepeat); return min_; } - int max() { DCHECK_EQ(op_, kRegexpRepeat); return max_; } - Rune rune() { DCHECK_EQ(op_, kRegexpLiteral); return rune_; } - CharClass* cc() { DCHECK_EQ(op_, kRegexpCharClass); return cc_; } - int cap() { DCHECK_EQ(op_, kRegexpCapture); return cap_; } - const std::string* name() { DCHECK_EQ(op_, kRegexpCapture); return name_; } - Rune* runes() { DCHECK_EQ(op_, kRegexpLiteralString); return runes_; } - int nrunes() { DCHECK_EQ(op_, kRegexpLiteralString); return nrunes_; } - int match_id() { DCHECK_EQ(op_, kRegexpHaveMatch); return match_id_; } + int min() { + DCHECK_EQ(op_, kRegexpRepeat); + return min_; + } + int max() { + DCHECK_EQ(op_, kRegexpRepeat); + return max_; + } + Rune rune() { + DCHECK_EQ(op_, kRegexpLiteral); + return rune_; + } + CharClass *cc() { + DCHECK_EQ(op_, kRegexpCharClass); + return cc_; + } + int cap() { + DCHECK_EQ(op_, kRegexpCapture); + return cap_; + } + const std::string *name() { + DCHECK_EQ(op_, kRegexpCapture); + return name_; + } + Rune *runes() { + DCHECK_EQ(op_, kRegexpLiteralString); + return runes_; + } + int nrunes() { + DCHECK_EQ(op_, kRegexpLiteralString); + return nrunes_; + } + int match_id() { + DCHECK_EQ(op_, kRegexpHaveMatch); + return match_id_; + } // Increments reference count, returns object as convenience. - Regexp* Incref(); + Regexp *Incref(); // Decrements reference count and deletes this object if count reaches 0. void Decref(); @@ -352,8 +380,8 @@ class Regexp { // Parses string s to produce regular expression, returned. // Caller must release return value with re->Decref(). // On failure, sets *status (if status != NULL) and returns NULL. - static Regexp* Parse(const StringPiece& s, ParseFlags flags, - RegexpStatus* status); + static Regexp *Parse(const StringPiece &s, ParseFlags flags, + RegexpStatus *status); // Returns a _new_ simplified version of the current regexp. // Does not edit the current regexp. @@ -362,15 +390,15 @@ class Regexp { // into simpler terms and all Perl/POSIX features have been // removed. The result will capture exactly the same // subexpressions the original did, unless formatted with ToString. - Regexp* Simplify(); + Regexp *Simplify(); friend class CoalesceWalker; friend class SimplifyWalker; // Parses the regexp src and then simplifies it and sets *dst to the // string representation of the simplified form. Returns true on success. // Returns false and sets *status (if status != NULL) on parse error. - static bool SimplifyRegexp(const StringPiece& src, ParseFlags flags, - std::string* dst, RegexpStatus* status); + static bool SimplifyRegexp(const StringPiece &src, ParseFlags flags, + std::string *dst, RegexpStatus *status); // Returns the number of capturing groups in the regexp. int NumCaptures(); @@ -379,12 +407,12 @@ class Regexp { // Returns a map from names to capturing group indices, // or NULL if the regexp contains no named capture groups. // The caller is responsible for deleting the map. - std::map* NamedCaptures(); + std::map *NamedCaptures(); // Returns a map from capturing group indices to capturing group // names or NULL if the regexp contains no named capture groups. The // caller is responsible for deleting the map. - std::map* CaptureNames(); + std::map *CaptureNames(); // Returns a string representation of the current regexp, // using as few parentheses as possible. @@ -393,35 +421,35 @@ class Regexp { // Convenience functions. They consume the passed reference, // so in many cases you should use, e.g., Plus(re->Incref(), flags). // They do not consume allocated arrays like subs or runes. - static Regexp* Plus(Regexp* sub, ParseFlags flags); - static Regexp* Star(Regexp* sub, ParseFlags flags); - static Regexp* Quest(Regexp* sub, ParseFlags flags); - static Regexp* Concat(Regexp** subs, int nsubs, ParseFlags flags); - static Regexp* Alternate(Regexp** subs, int nsubs, ParseFlags flags); - static Regexp* Capture(Regexp* sub, ParseFlags flags, int cap); - static Regexp* Repeat(Regexp* sub, ParseFlags flags, int min, int max); - static Regexp* NewLiteral(Rune rune, ParseFlags flags); - static Regexp* NewCharClass(CharClass* cc, ParseFlags flags); - static Regexp* LiteralString(Rune* runes, int nrunes, ParseFlags flags); - static Regexp* HaveMatch(int match_id, ParseFlags flags); + static Regexp *Plus(Regexp *sub, ParseFlags flags); + static Regexp *Star(Regexp *sub, ParseFlags flags); + static Regexp *Quest(Regexp *sub, ParseFlags flags); + static Regexp *Concat(Regexp **subs, int nsubs, ParseFlags flags); + static Regexp *Alternate(Regexp **subs, int nsubs, ParseFlags flags); + static Regexp *Capture(Regexp *sub, ParseFlags flags, int cap); + static Regexp *Repeat(Regexp *sub, ParseFlags flags, int min, int max); + static Regexp *NewLiteral(Rune rune, ParseFlags flags); + static Regexp *NewCharClass(CharClass *cc, ParseFlags flags); + static Regexp *LiteralString(Rune *runes, int nrunes, ParseFlags flags); + static Regexp *HaveMatch(int match_id, ParseFlags flags); // Like Alternate but does not factor out common prefixes. - static Regexp* AlternateNoFactor(Regexp** subs, int nsubs, ParseFlags flags); + static Regexp *AlternateNoFactor(Regexp **subs, int nsubs, ParseFlags flags); // Debugging function. Returns string format for regexp // that makes structure clear. Does NOT use regexp syntax. std::string Dump(); // Helper traversal class, defined fully in walker-inl.h. - template class Walker; + template class Walker; // Compile to Prog. See prog.h // Reverse prog expects to be run over text backward. // Construction and execution of prog will // stay within approximately max_mem bytes of memory. // If max_mem <= 0, a reasonable default is used. - Prog* CompileToProg(int64_t max_mem); - Prog* CompileToReverseProg(int64_t max_mem); + Prog *CompileToProg(int64_t max_mem); + Prog *CompileToReverseProg(int64_t max_mem); // Whether to expect this library to find exactly the same answer as PCRE // when running this regexp. Most regexps do mimic PCRE exactly, but a few @@ -439,21 +467,20 @@ class Regexp { // follows it. // Callers should expect *prefix, *foldcase and *suffix to be "zeroed" // regardless of the return value. - bool RequiredPrefix(std::string* prefix, bool* foldcase, - Regexp** suffix); + bool RequiredPrefix(std::string *prefix, bool *foldcase, Regexp **suffix); // Whether every match of this regexp must be unanchored and // begin with a non-empty fixed string (perhaps after ASCII // case-folding). If so, returns the prefix. // Callers should expect *prefix and *foldcase to be "zeroed" // regardless of the return value. - bool RequiredPrefixForAccel(std::string* prefix, bool* foldcase); + bool RequiredPrefixForAccel(std::string *prefix, bool *foldcase); // Controls the maximum repeat count permitted by the parser. // FOR FUZZING ONLY. static void FUZZING_ONLY_set_maximum_repeat_count(int i); - private: +private: // Constructor allocates vectors as appropriate for operator. explicit Regexp(RegexpOp op, ParseFlags parse_flags); @@ -467,58 +494,58 @@ class Regexp { class ParseState; friend class ParseState; - friend bool ParseCharClass(StringPiece* s, Regexp** out_re, - RegexpStatus* status); + friend bool ParseCharClass(StringPiece *s, Regexp **out_re, + RegexpStatus *status); // Helper for testing [sic]. - friend bool RegexpEqualTestingOnly(Regexp*, Regexp*); + friend bool RegexpEqualTestingOnly(Regexp *, Regexp *); // Computes whether Regexp is already simple. bool ComputeSimple(); // Constructor that generates a Star, Plus or Quest, // squashing the pair if sub is also a Star, Plus or Quest. - static Regexp* StarPlusOrQuest(RegexpOp op, Regexp* sub, ParseFlags flags); + static Regexp *StarPlusOrQuest(RegexpOp op, Regexp *sub, ParseFlags flags); // Constructor that generates a concatenation or alternation, // enforcing the limit on the number of subexpressions for // a particular Regexp. - static Regexp* ConcatOrAlternate(RegexpOp op, Regexp** subs, int nsubs, + static Regexp *ConcatOrAlternate(RegexpOp op, Regexp **subs, int nsubs, ParseFlags flags, bool can_factor); // Returns the leading string that re starts with. // The returned Rune* points into a piece of re, // so it must not be used after the caller calls re->Decref(). - static Rune* LeadingString(Regexp* re, int* nrune, ParseFlags* flags); + static Rune *LeadingString(Regexp *re, int *nrune, ParseFlags *flags); // Removes the first n leading runes from the beginning of re. // Edits re in place. - static void RemoveLeadingString(Regexp* re, int n); + static void RemoveLeadingString(Regexp *re, int n); // Returns the leading regexp in re's top-level concatenation. // The returned Regexp* points at re or a sub-expression of re, // so it must not be used after the caller calls re->Decref(). - static Regexp* LeadingRegexp(Regexp* re); + static Regexp *LeadingRegexp(Regexp *re); // Removes LeadingRegexp(re) from re and returns the remainder. // Might edit re in place. - static Regexp* RemoveLeadingRegexp(Regexp* re); + static Regexp *RemoveLeadingRegexp(Regexp *re); // Simplifies an alternation of literal strings by factoring out // common prefixes. - static int FactorAlternation(Regexp** sub, int nsub, ParseFlags flags); + static int FactorAlternation(Regexp **sub, int nsub, ParseFlags flags); friend class FactorAlternationImpl; // Is a == b? Only efficient on regexps that have not been through // Simplify yet - the expansion of a kRegexpRepeat will make this // take a long time. Do not call on such regexps, hence private. - static bool Equal(Regexp* a, Regexp* b); + static bool Equal(Regexp *a, Regexp *b); // Allocate space for n sub-regexps. void AllocSub(int n) { DCHECK(n >= 0 && static_cast(n) == n); if (n > 1) - submany_ = new Regexp*[n]; + submany_ = new Regexp *[n]; nsub_ = static_cast(n); } @@ -562,48 +589,48 @@ class Regexp { uint16_t nsub_; static const uint16_t kMaxNsub = 0xffff; union { - Regexp** submany_; // if nsub_ > 1 - Regexp* subone_; // if nsub_ == 1 + Regexp **submany_; // if nsub_ > 1 + Regexp *subone_; // if nsub_ == 1 }; // Extra space for parse and teardown stacks. - Regexp* down_; + Regexp *down_; // Arguments to operator. See description of operators above. union { - struct { // Repeat + struct { // Repeat int max_; int min_; }; - struct { // Capture + struct { // Capture int cap_; - std::string* name_; + std::string *name_; }; - struct { // LiteralString + struct { // LiteralString int nrunes_; - Rune* runes_; + Rune *runes_; }; - struct { // CharClass + struct { // CharClass // These two could be in separate union members, // but it wouldn't save any space (there are other two-word structs) // and keeping them separate avoids confusion during parsing. - CharClass* cc_; - CharClassBuilder* ccb_; + CharClass *cc_; + CharClassBuilder *ccb_; }; - Rune rune_; // Literal - int match_id_; // HaveMatch - void *the_union_[2]; // as big as any other element, for memset + Rune rune_; // Literal + int match_id_; // HaveMatch + void *the_union_[2]; // as big as any other element, for memset }; - Regexp(const Regexp&) = delete; - Regexp& operator=(const Regexp&) = delete; + Regexp(const Regexp &) = delete; + Regexp &operator=(const Regexp &) = delete; }; // Character class set: contains non-overlapping, non-abutting RuneRanges. typedef std::set RuneRangeSet; class CharClassBuilder { - public: +public: CharClassBuilder(); typedef RuneRangeSet::iterator iterator; @@ -612,46 +639,46 @@ class CharClassBuilder { int size() { return nrunes_; } bool empty() { return nrunes_ == 0; } - bool full() { return nrunes_ == Runemax+1; } + bool full() { return nrunes_ == Runemax + 1; } bool Contains(Rune r); bool FoldsASCII(); - bool AddRange(Rune lo, Rune hi); // returns whether class changed - CharClassBuilder* Copy(); - void AddCharClass(CharClassBuilder* cc); + bool AddRange(Rune lo, Rune hi); // returns whether class changed + CharClassBuilder *Copy(); + void AddCharClass(CharClassBuilder *cc); void Negate(); void RemoveAbove(Rune r); - CharClass* GetCharClass(); + CharClass *GetCharClass(); void AddRangeFlags(Rune lo, Rune hi, Regexp::ParseFlags parse_flags); - private: - static const uint32_t AlphaMask = (1<<26) - 1; - uint32_t upper_; // bitmap of A-Z - uint32_t lower_; // bitmap of a-z +private: + static const uint32_t AlphaMask = (1 << 26) - 1; + uint32_t upper_; // bitmap of A-Z + uint32_t lower_; // bitmap of a-z int nrunes_; RuneRangeSet ranges_; - CharClassBuilder(const CharClassBuilder&) = delete; - CharClassBuilder& operator=(const CharClassBuilder&) = delete; + CharClassBuilder(const CharClassBuilder &) = delete; + CharClassBuilder &operator=(const CharClassBuilder &) = delete; }; // Bitwise ops on ParseFlags produce ParseFlags. inline Regexp::ParseFlags operator|(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) | static_cast(b)); + return static_cast(static_cast(a) | + static_cast(b)); } inline Regexp::ParseFlags operator^(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) ^ static_cast(b)); + return static_cast(static_cast(a) ^ + static_cast(b)); } inline Regexp::ParseFlags operator&(Regexp::ParseFlags a, Regexp::ParseFlags b) { - return static_cast( - static_cast(a) & static_cast(b)); + return static_cast(static_cast(a) & + static_cast(b)); } inline Regexp::ParseFlags operator~(Regexp::ParseFlags a) { @@ -660,6 +687,6 @@ inline Regexp::ParseFlags operator~(Regexp::ParseFlags a) { ~static_cast(a) & static_cast(Regexp::AllParseFlags)); } -} // namespace re2 +} // namespace re2 -#endif // RE2_REGEXP_H_ +#endif // RE2_REGEXP_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h index 8d64f30c..19741ebf 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h @@ -15,34 +15,34 @@ namespace re2 { class Prog; class Regexp; -} // namespace re2 +} // namespace re2 namespace re2 { // An RE2::Set represents a collection of regexps that can // be searched for simultaneously. class RE2::Set { - public: +public: enum ErrorKind { kNoError = 0, - kNotCompiled, // The set is not compiled. - kOutOfMemory, // The DFA ran out of memory. - kInconsistent, // The result is inconsistent. This should never happen. + kNotCompiled, // The set is not compiled. + kOutOfMemory, // The DFA ran out of memory. + kInconsistent, // The result is inconsistent. This should never happen. }; struct ErrorInfo { ErrorKind kind; }; - Set(const RE2::Options& options, RE2::Anchor anchor); + Set(const RE2::Options &options, RE2::Anchor anchor); ~Set(); // Not copyable. - Set(const Set&) = delete; - Set& operator=(const Set&) = delete; + Set(const Set &) = delete; + Set &operator=(const Set &) = delete; // Movable. - Set(Set&& other); - Set& operator=(Set&& other); + Set(Set &&other); + Set &operator=(Set &&other); // Adds pattern to the set using the options passed to the constructor. // Returns the index that will identify the regexp in the output of Match(), @@ -50,7 +50,7 @@ class RE2::Set { // Indices are assigned in sequential order starting from 0. // Errors do not increment the index; if error is not NULL, *error will hold // the error message from the parser. - int Add(const StringPiece& pattern, std::string* error); + int Add(const StringPiece &pattern, std::string *error); // Compiles the set in preparation for matching. // Returns false if the compiler runs out of memory. @@ -61,16 +61,16 @@ class RE2::Set { // Returns true if text matches at least one of the regexps in the set. // Fills v (if not NULL) with the indices of the matching regexps. // Callers must not expect v to be sorted. - bool Match(const StringPiece& text, std::vector* v) const; + bool Match(const StringPiece &text, std::vector *v) const; // As above, but populates error_info (if not NULL) when none of the regexps // in the set matched. This can inform callers when DFA execution fails, for // example, because they might wish to handle that case differently. - bool Match(const StringPiece& text, std::vector* v, - ErrorInfo* error_info) const; + bool Match(const StringPiece &text, std::vector *v, + ErrorInfo *error_info) const; - private: - typedef std::pair Elem; +private: + typedef std::pair Elem; RE2::Options options_; RE2::Anchor anchor_; @@ -80,6 +80,6 @@ class RE2::Set { std::unique_ptr prog_; }; -} // namespace re2 +} // namespace re2 -#endif // RE2_SET_H_ +#endif // RE2_SET_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h index 09ffe086..5580aa26 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h @@ -106,9 +106,8 @@ namespace re2 { -template -class SparseArray { - public: +template class SparseArray { +public: SparseArray(); explicit SparseArray(int max_size); ~SparseArray(); @@ -116,39 +115,27 @@ class SparseArray { // IndexValue pairs: exposed in SparseArray::iterator. class IndexValue; - typedef IndexValue* iterator; - typedef const IndexValue* const_iterator; + typedef IndexValue *iterator; + typedef const IndexValue *const_iterator; - SparseArray(const SparseArray& src); - SparseArray(SparseArray&& src); + SparseArray(const SparseArray &src); + SparseArray(SparseArray &&src); - SparseArray& operator=(const SparseArray& src); - SparseArray& operator=(SparseArray&& src); + SparseArray &operator=(const SparseArray &src); + SparseArray &operator=(SparseArray &&src); // Return the number of entries in the array. - int size() const { - return size_; - } + int size() const { return size_; } // Indicate whether the array is empty. - int empty() const { - return size_ == 0; - } + int empty() const { return size_ == 0; } // Iterate over the array. - iterator begin() { - return dense_.data(); - } - iterator end() { - return dense_.data() + size_; - } + iterator begin() { return dense_.data(); } + iterator end() { return dense_.data() + size_; } - const_iterator begin() const { - return dense_.data(); - } - const_iterator end() const { - return dense_.data() + size_; - } + const_iterator begin() const { return dense_.data(); } + const_iterator end() const { return dense_.data() + size_; } // Change the maximum size of the array. // Invalidates all iterators. @@ -164,9 +151,7 @@ class SparseArray { } // Clear the array. - void clear() { - size_ = 0; - } + void clear() { size_ = 0; } // Check whether index i is in the array. bool has_index(int i) const; @@ -175,39 +160,35 @@ class SparseArray { // Can sort the sparse array so that future iterations // will visit indices in increasing order using // std::sort(arr.begin(), arr.end(), arr.less); - static bool less(const IndexValue& a, const IndexValue& b); + static bool less(const IndexValue &a, const IndexValue &b); - public: +public: // Set the value at index i to v. - iterator set(int i, const Value& v) { - return SetInternal(true, i, v); - } + iterator set(int i, const Value &v) { return SetInternal(true, i, v); } // Set the value at new index i to v. // Fast but unsafe: only use if has_index(i) is false. - iterator set_new(int i, const Value& v) { - return SetInternal(false, i, v); - } + iterator set_new(int i, const Value &v) { return SetInternal(false, i, v); } // Set the value at index i to v. // Fast but unsafe: only use if has_index(i) is true. - iterator set_existing(int i, const Value& v) { + iterator set_existing(int i, const Value &v) { return SetExistingInternal(i, v); } // Get the value at index i. // Fast but unsafe: only use if has_index(i) is true. - Value& get_existing(int i) { + Value &get_existing(int i) { assert(has_index(i)); return dense_[sparse_[i]].value_; } - const Value& get_existing(int i) const { + const Value &get_existing(int i) const { assert(has_index(i)); return dense_[sparse_[i]].value_; } - private: - iterator SetInternal(bool allow_existing, int i, const Value& v) { +private: + iterator SetInternal(bool allow_existing, int i, const Value &v) { DebugCheckInvariants(); if (static_cast(i) >= static_cast(max_size())) { assert(false && "illegal index"); @@ -226,7 +207,7 @@ class SparseArray { return SetExistingInternal(i, v); } - iterator SetExistingInternal(int i, const Value& v) { + iterator SetExistingInternal(int i, const Value &v) { DebugCheckInvariants(); assert(has_index(i)); dense_[sparse_[i]].value_ = v; @@ -262,28 +243,24 @@ class SparseArray { PODArray dense_; }; -template -SparseArray::SparseArray() = default; +template SparseArray::SparseArray() = default; -template -SparseArray::SparseArray(const SparseArray& src) - : size_(src.size_), - sparse_(src.max_size()), - dense_(src.max_size()) { +template +SparseArray::SparseArray(const SparseArray &src) + : size_(src.size_), sparse_(src.max_size()), dense_(src.max_size()) { std::copy_n(src.sparse_.data(), src.max_size(), sparse_.data()); std::copy_n(src.dense_.data(), src.max_size(), dense_.data()); } -template -SparseArray::SparseArray(SparseArray&& src) - : size_(src.size_), - sparse_(std::move(src.sparse_)), +template +SparseArray::SparseArray(SparseArray &&src) + : size_(src.size_), sparse_(std::move(src.sparse_)), dense_(std::move(src.dense_)) { src.size_ = 0; } -template -SparseArray& SparseArray::operator=(const SparseArray& src) { +template +SparseArray &SparseArray::operator=(const SparseArray &src) { // Construct these first for exception safety. PODArray a(src.max_size()); PODArray b(src.max_size()); @@ -296,8 +273,8 @@ SparseArray& SparseArray::operator=(const SparseArray& src) { return *this; } -template -SparseArray& SparseArray::operator=(SparseArray&& src) { +template +SparseArray &SparseArray::operator=(SparseArray &&src) { size_ = src.size_; sparse_ = std::move(src.sparse_); dense_ = std::move(src.dense_); @@ -306,14 +283,13 @@ SparseArray& SparseArray::operator=(SparseArray&& src) { } // IndexValue pairs: exposed in SparseArray::iterator. -template -class SparseArray::IndexValue { - public: +template class SparseArray::IndexValue { +public: int index() const { return index_; } - Value& value() { return value_; } - const Value& value() const { return value_; } + Value &value() { return value_; } + const Value &value() const { return value_; } - private: +private: friend class SparseArray; int index_; Value value_; @@ -321,8 +297,7 @@ class SparseArray::IndexValue { // Change the maximum size of the array. // Invalidates all iterators. -template -void SparseArray::resize(int new_max_size) { +template void SparseArray::resize(int new_max_size) { DebugCheckInvariants(); if (new_max_size > max_size()) { const int old_max_size = max_size(); @@ -345,8 +320,7 @@ void SparseArray::resize(int new_max_size) { } // Check whether index i is in the array. -template -bool SparseArray::has_index(int i) const { +template bool SparseArray::has_index(int i) const { assert(i >= 0); assert(i < max_size()); if (static_cast(i) >= static_cast(max_size())) { @@ -357,8 +331,7 @@ bool SparseArray::has_index(int i) const { dense_[sparse_[i]].index_ == i; } -template -void SparseArray::create_index(int i) { +template void SparseArray::create_index(int i) { assert(!has_index(i)); assert(size_ < max_size()); sparse_[i] = size_; @@ -366,27 +339,29 @@ void SparseArray::create_index(int i) { size_++; } -template SparseArray::SparseArray(int max_size) : - sparse_(max_size), dense_(max_size) { +template +SparseArray::SparseArray(int max_size) + : sparse_(max_size), dense_(max_size) { MaybeInitializeMemory(size_, max_size); DebugCheckInvariants(); } -template SparseArray::~SparseArray() { +template SparseArray::~SparseArray() { DebugCheckInvariants(); } -template void SparseArray::DebugCheckInvariants() const { +template +void SparseArray::DebugCheckInvariants() const { assert(0 <= size_); assert(size_ <= max_size()); } // Comparison function for sorting. -template bool SparseArray::less(const IndexValue& a, - const IndexValue& b) { +template +bool SparseArray::less(const IndexValue &a, const IndexValue &b) { return a.index_ < b.index_; } -} // namespace re2 +} // namespace re2 -#endif // RE2_SPARSE_ARRAY_H_ +#endif // RE2_SPARSE_ARRAY_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h index 06ed88d8..1e9c2f10 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h @@ -65,40 +65,27 @@ namespace re2 { -template -class SparseSetT { - public: +template class SparseSetT { +public: SparseSetT(); explicit SparseSetT(int max_size); ~SparseSetT(); - typedef int* iterator; - typedef const int* const_iterator; + typedef int *iterator; + typedef const int *const_iterator; // Return the number of entries in the set. - int size() const { - return size_; - } + int size() const { return size_; } // Indicate whether the set is empty. - int empty() const { - return size_ == 0; - } + int empty() const { return size_ == 0; } // Iterate over the set. - iterator begin() { - return dense_.data(); - } - iterator end() { - return dense_.data() + size_; - } + iterator begin() { return dense_.data(); } + iterator end() { return dense_.data() + size_; } - const_iterator begin() const { - return dense_.data(); - } - const_iterator end() const { - return dense_.data() + size_; - } + const_iterator begin() const { return dense_.data(); } + const_iterator end() const { return dense_.data() + size_; } // Change the maximum size of the set. // Invalidates all iterators. @@ -114,9 +101,7 @@ class SparseSetT { } // Clear the set. - void clear() { - size_ = 0; - } + void clear() { size_ = 0; } // Check whether index i is in the set. bool contains(int i) const; @@ -127,19 +112,15 @@ class SparseSetT { // std::sort(arr.begin(), arr.end(), arr.less); static bool less(int a, int b); - public: +public: // Insert index i into the set. - iterator insert(int i) { - return InsertInternal(true, i); - } + iterator insert(int i) { return InsertInternal(true, i); } // Insert index i into the set. // Fast but unsafe: only use if contains(i) is false. - iterator insert_new(int i) { - return InsertInternal(false, i); - } + iterator insert_new(int i) { return InsertInternal(false, i); } - private: +private: iterator InsertInternal(bool allow_existing, int i) { DebugCheckInvariants(); if (static_cast(i) >= static_cast(max_size())) { @@ -187,13 +168,11 @@ class SparseSetT { PODArray dense_; }; -template -SparseSetT::SparseSetT() = default; +template SparseSetT::SparseSetT() = default; // Change the maximum size of the set. // Invalidates all iterators. -template -void SparseSetT::resize(int new_max_size) { +template void SparseSetT::resize(int new_max_size) { DebugCheckInvariants(); if (new_max_size > max_size()) { const int old_max_size = max_size(); @@ -216,20 +195,17 @@ void SparseSetT::resize(int new_max_size) { } // Check whether index i is in the set. -template -bool SparseSetT::contains(int i) const { +template bool SparseSetT::contains(int i) const { assert(i >= 0); assert(i < max_size()); if (static_cast(i) >= static_cast(max_size())) { return false; } // Unsigned comparison avoids checking sparse_[i] < 0. - return (uint32_t)sparse_[i] < (uint32_t)size_ && - dense_[sparse_[i]] == i; + return (uint32_t)sparse_[i] < (uint32_t)size_ && dense_[sparse_[i]] == i; } -template -void SparseSetT::create_index(int i) { +template void SparseSetT::create_index(int i) { assert(!contains(i)); assert(size_ < max_size()); sparse_[i] = size_; @@ -237,28 +213,29 @@ void SparseSetT::create_index(int i) { size_++; } -template SparseSetT::SparseSetT(int max_size) : - sparse_(max_size), dense_(max_size) { +template +SparseSetT::SparseSetT(int max_size) + : sparse_(max_size), dense_(max_size) { MaybeInitializeMemory(size_, max_size); DebugCheckInvariants(); } -template SparseSetT::~SparseSetT() { +template SparseSetT::~SparseSetT() { DebugCheckInvariants(); } -template void SparseSetT::DebugCheckInvariants() const { +template void SparseSetT::DebugCheckInvariants() const { assert(0 <= size_); assert(size_ <= max_size()); } // Comparison function for sorting. -template bool SparseSetT::less(int a, int b) { +template bool SparseSetT::less(int a, int b) { return a < b; } typedef SparseSetT SparseSet; -} // namespace re2 +} // namespace re2 -#endif // RE2_SPARSE_SET_H_ +#endif // RE2_SPARSE_SET_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h index b9d66614..31b6dd0b 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h @@ -19,11 +19,11 @@ // // Arghh! I wish C++ literals were "string". -#include -#include #include #include #include +#include +#include #include #ifdef __cpp_lib_string_view #include @@ -32,14 +32,14 @@ namespace re2 { class StringPiece { - public: +public: typedef std::char_traits traits_type; typedef char value_type; - typedef char* pointer; - typedef const char* const_pointer; - typedef char& reference; - typedef const char& const_reference; - typedef const char* const_iterator; + typedef char *pointer; + typedef const char *const_pointer; + typedef char &reference; + typedef const char &const_reference; + typedef const char *const_iterator; typedef const_iterator iterator; typedef std::reverse_iterator const_reverse_iterator; typedef const_reverse_iterator reverse_iterator; @@ -50,27 +50,22 @@ class StringPiece { // We provide non-explicit singleton constructors so users can pass // in a "const char*" or a "string" wherever a "StringPiece" is // expected. - StringPiece() - : data_(NULL), size_(0) {} + StringPiece() : data_(NULL), size_(0) {} #ifdef __cpp_lib_string_view - StringPiece(const std::string_view& str) + StringPiece(const std::string_view &str) : data_(str.data()), size_(str.size()) {} #endif - StringPiece(const std::string& str) - : data_(str.data()), size_(str.size()) {} - StringPiece(const char* str) + StringPiece(const std::string &str) : data_(str.data()), size_(str.size()) {} + StringPiece(const char *str) : data_(str), size_(str == NULL ? 0 : strlen(str)) {} - StringPiece(const char* str, size_type len) - : data_(str), size_(len) {} + StringPiece(const char *str, size_type len) : data_(str), size_(len) {} const_iterator begin() const { return data_; } const_iterator end() const { return data_ + size_; } const_reverse_iterator rbegin() const { return const_reverse_iterator(data_ + size_); } - const_reverse_iterator rend() const { - return const_reverse_iterator(data_); - } + const_reverse_iterator rend() const { return const_reverse_iterator(data_); } size_type size() const { return size_; } size_type length() const { return size_; } @@ -84,16 +79,14 @@ class StringPiece { size_ -= n; } - void remove_suffix(size_type n) { - size_ -= n; - } + void remove_suffix(size_type n) { size_ -= n; } - void set(const char* str) { + void set(const char *str) { data_ = str; size_ = str == NULL ? 0 : strlen(str); } - void set(const char* str, size_type len) { + void set(const char *str, size_type len) { data_ = str; size_ = len; } @@ -101,7 +94,8 @@ class StringPiece { #ifdef __cpp_lib_string_view // Converts to `std::basic_string_view`. operator std::basic_string_view() const { - if (!data_) return {}; + if (!data_) + return {}; return std::basic_string_view(data_, size_); } #endif @@ -109,105 +103,103 @@ class StringPiece { // Converts to `std::basic_string`. template explicit operator std::basic_string() const { - if (!data_) return {}; + if (!data_) + return {}; return std::basic_string(data_, size_); } - std::string as_string() const { - return std::string(data_, size_); - } + std::string as_string() const { return std::string(data_, size_); } // We also define ToString() here, since many other string-like // interfaces name the routine that converts to a C++ string // "ToString", and it's confusing to have the method that does that // for a StringPiece be called "as_string()". We also leave the // "as_string()" method defined here for existing code. - std::string ToString() const { - return std::string(data_, size_); - } + std::string ToString() const { return std::string(data_, size_); } - void CopyToString(std::string* target) const { - target->assign(data_, size_); - } + void CopyToString(std::string *target) const { target->assign(data_, size_); } - void AppendToString(std::string* target) const { + void AppendToString(std::string *target) const { target->append(data_, size_); } - size_type copy(char* buf, size_type n, size_type pos = 0) const; + size_type copy(char *buf, size_type n, size_type pos = 0) const; StringPiece substr(size_type pos = 0, size_type n = npos) const; - int compare(const StringPiece& x) const { + int compare(const StringPiece &x) const { size_type min_size = std::min(size(), x.size()); if (min_size > 0) { int r = memcmp(data(), x.data(), min_size); - if (r < 0) return -1; - if (r > 0) return 1; + if (r < 0) + return -1; + if (r > 0) + return 1; } - if (size() < x.size()) return -1; - if (size() > x.size()) return 1; + if (size() < x.size()) + return -1; + if (size() > x.size()) + return 1; return 0; } // Does "this" start with "x"? - bool starts_with(const StringPiece& x) const { + bool starts_with(const StringPiece &x) const { return x.empty() || (size() >= x.size() && memcmp(data(), x.data(), x.size()) == 0); } // Does "this" end with "x"? - bool ends_with(const StringPiece& x) const { + bool ends_with(const StringPiece &x) const { return x.empty() || (size() >= x.size() && memcmp(data() + (size() - x.size()), x.data(), x.size()) == 0); } - bool contains(const StringPiece& s) const { - return find(s) != npos; - } + bool contains(const StringPiece &s) const { return find(s) != npos; } - size_type find(const StringPiece& s, size_type pos = 0) const; + size_type find(const StringPiece &s, size_type pos = 0) const; size_type find(char c, size_type pos = 0) const; - size_type rfind(const StringPiece& s, size_type pos = npos) const; + size_type rfind(const StringPiece &s, size_type pos = npos) const; size_type rfind(char c, size_type pos = npos) const; - private: +private: const_pointer data_; size_type size_; }; -inline bool operator==(const StringPiece& x, const StringPiece& y) { +inline bool operator==(const StringPiece &x, const StringPiece &y) { StringPiece::size_type len = x.size(); - if (len != y.size()) return false; + if (len != y.size()) + return false; return x.data() == y.data() || len == 0 || memcmp(x.data(), y.data(), len) == 0; } -inline bool operator!=(const StringPiece& x, const StringPiece& y) { +inline bool operator!=(const StringPiece &x, const StringPiece &y) { return !(x == y); } -inline bool operator<(const StringPiece& x, const StringPiece& y) { +inline bool operator<(const StringPiece &x, const StringPiece &y) { StringPiece::size_type min_size = std::min(x.size(), y.size()); int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size); return (r < 0) || (r == 0 && x.size() < y.size()); } -inline bool operator>(const StringPiece& x, const StringPiece& y) { +inline bool operator>(const StringPiece &x, const StringPiece &y) { return y < x; } -inline bool operator<=(const StringPiece& x, const StringPiece& y) { +inline bool operator<=(const StringPiece &x, const StringPiece &y) { return !(x > y); } -inline bool operator>=(const StringPiece& x, const StringPiece& y) { +inline bool operator>=(const StringPiece &x, const StringPiece &y) { return !(x < y); } // Allow StringPiece to be logged. -std::ostream& operator<<(std::ostream& o, const StringPiece& p); +std::ostream &operator<<(std::ostream &o, const StringPiece &p); -} // namespace re2 +} // namespace re2 -#endif // RE2_STRINGPIECE_H_ +#endif // RE2_STRINGPIECE_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h index 8bdbb42f..742d770a 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h @@ -41,15 +41,15 @@ #include -#include "util/util.h" #include "util/utf.h" +#include "util/util.h" namespace re2 { enum { EvenOdd = 1, OddEven = -1, - EvenOddSkip = 1<<30, + EvenOddSkip = 1 << 30, OddEvenSkip, }; @@ -68,11 +68,11 @@ extern const int num_unicode_tolower; // Returns the CaseFold* in the tables that contains rune. // If rune is not in the tables, returns the first CaseFold* after rune. // If rune is larger than any value in the tables, returns NULL. -extern const CaseFold* LookupCaseFold(const CaseFold*, int, Rune rune); +extern const CaseFold *LookupCaseFold(const CaseFold *, int, Rune rune); // Returns the result of applying the fold f to the rune r. extern Rune ApplyFold(const CaseFold *f, Rune r); -} // namespace re2 +} // namespace re2 -#endif // RE2_UNICODE_CASEFOLD_H_ +#endif // RE2_UNICODE_CASEFOLD_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h index 75f55daa..839ed6f3 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h @@ -20,27 +20,24 @@ #include -#include "util/util.h" #include "util/utf.h" +#include "util/util.h" namespace re2 { -struct URange16 -{ +struct URange16 { uint16_t lo; uint16_t hi; }; -struct URange32 -{ +struct URange32 { Rune lo; Rune hi; }; -struct UGroup -{ +struct UGroup { const char *name; - int sign; // +1 for [abc], -1 for [^abc] + int sign; // +1 for [abc], -1 for [^abc] const URange16 *r16; int nr16; const URange32 *r32; @@ -62,6 +59,6 @@ extern const int num_posix_groups; extern const UGroup perl_groups[]; extern const int num_perl_groups; -} // namespace re2 +} // namespace re2 -#endif // RE2_UNICODE_GROUPS_H_ +#endif // RE2_UNICODE_GROUPS_H_ diff --git a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h index 4d064a09..43e25015 100644 --- a/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h +++ b/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h @@ -15,15 +15,15 @@ #include -#include "util/logging.h" #include "re2/regexp.h" +#include "util/logging.h" namespace re2 { -template struct WalkState; +template struct WalkState; -template class Regexp::Walker { - public: +template class Regexp::Walker { +public: Walker(); virtual ~Walker(); @@ -36,7 +36,7 @@ template class Regexp::Walker { // into the children. Instead it behaves as though the return // value from PreVisit is the return value from PostVisit. // The default PreVisit returns parent_arg. - virtual T PreVisit(Regexp* re, T parent_arg, bool* stop); + virtual T PreVisit(Regexp *re, T parent_arg, bool *stop); // Virtual method called after visiting re's children. // The pre_arg is the T that PreVisit returned. @@ -47,8 +47,8 @@ template class Regexp::Walker { // PostVisit passes ownership of its return value // to its caller. // The default PostVisit simply returns pre_arg. - virtual T PostVisit(Regexp* re, T parent_arg, T pre_arg, - T* child_args, int nchild_args); + virtual T PostVisit(Regexp *re, T parent_arg, T pre_arg, T *child_args, + int nchild_args); // Virtual method called to copy a T, // when Walk notices that more than one child is the same re. @@ -62,12 +62,12 @@ template class Regexp::Walker { // This function is (hopefully) only called by // WalkExponential, but must be implemented by all clients, // just in case. - virtual T ShortVisit(Regexp* re, T parent_arg) = 0; + virtual T ShortVisit(Regexp *re, T parent_arg) = 0; // Walks over a regular expression. // Top_arg is passed as parent_arg to PreVisit and PostVisit of re. // Returns the T returned by PostVisit on re. - T Walk(Regexp* re, T top_arg); + T Walk(Regexp *re, T top_arg); // Like Walk, but doesn't use Copy. This can lead to // exponential runtimes on cross-linked Regexps like the @@ -77,7 +77,7 @@ template class Regexp::Walker { // If the walk *is* cut off early, ShortVisit(re) // will be called on regexps that cannot be fully // visited rather than calling PreVisit/PostVisit. - T WalkExponential(Regexp* re, T top_arg, int max_visits); + T WalkExponential(Regexp *re, T top_arg, int max_visits); // Clears the stack. Should never be necessary, since // Walk always enters and exits with an empty stack. @@ -87,64 +87,52 @@ template class Regexp::Walker { // Returns whether walk was cut off. bool stopped_early() { return stopped_early_; } - private: +private: // Walk state for the entire traversal. std::stack> stack_; bool stopped_early_; int max_visits_; - T WalkInternal(Regexp* re, T top_arg, bool use_copy); + T WalkInternal(Regexp *re, T top_arg, bool use_copy); - Walker(const Walker&) = delete; - Walker& operator=(const Walker&) = delete; + Walker(const Walker &) = delete; + Walker &operator=(const Walker &) = delete; }; -template T Regexp::Walker::PreVisit(Regexp* re, - T parent_arg, - bool* stop) { +template +T Regexp::Walker::PreVisit(Regexp *re, T parent_arg, bool *stop) { return parent_arg; } -template T Regexp::Walker::PostVisit(Regexp* re, - T parent_arg, - T pre_arg, - T* child_args, - int nchild_args) { +template +T Regexp::Walker::PostVisit(Regexp *re, T parent_arg, T pre_arg, + T *child_args, int nchild_args) { return pre_arg; } -template T Regexp::Walker::Copy(T arg) { - return arg; -} +template T Regexp::Walker::Copy(T arg) { return arg; } // State about a single level in the traversal. -template struct WalkState { - WalkState(Regexp* re, T parent) - : re(re), - n(-1), - parent_arg(parent), - child_args(NULL) { } - - Regexp* re; // The regexp - int n; // The index of the next child to process; -1 means need to PreVisit - T parent_arg; // Accumulated arguments. +template struct WalkState { + WalkState(Regexp *re, T parent) + : re(re), n(-1), parent_arg(parent), child_args(NULL) {} + + Regexp *re; // The regexp + int n; // The index of the next child to process; -1 means need to PreVisit + T parent_arg; // Accumulated arguments. T pre_arg; - T child_arg; // One-element buffer for child_args. - T* child_args; + T child_arg; // One-element buffer for child_args. + T *child_args; }; -template Regexp::Walker::Walker() { - stopped_early_ = false; -} +template Regexp::Walker::Walker() { stopped_early_ = false; } -template Regexp::Walker::~Walker() { - Reset(); -} +template Regexp::Walker::~Walker() { Reset(); } // Clears the stack. Should never be necessary, since // Walk always enters and exits with an empty stack. // Logs DFATAL if stack is not already clear. -template void Regexp::Walker::Reset() { +template void Regexp::Walker::Reset() { if (!stack_.empty()) { LOG(DFATAL) << "Stack not empty."; while (!stack_.empty()) { @@ -155,8 +143,8 @@ template void Regexp::Walker::Reset() { } } -template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, - bool use_copy) { +template +T Regexp::Walker::WalkInternal(Regexp *re, T top_arg, bool use_copy) { Reset(); if (re == NULL) { @@ -166,51 +154,51 @@ template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, stack_.push(WalkState(re, top_arg)); - WalkState* s; + WalkState *s; for (;;) { T t; s = &stack_.top(); re = s->re; switch (s->n) { - case -1: { - if (--max_visits_ < 0) { - stopped_early_ = true; - t = ShortVisit(re, s->parent_arg); - break; - } - bool stop = false; - s->pre_arg = PreVisit(re, s->parent_arg, &stop); - if (stop) { - t = s->pre_arg; - break; - } - s->n = 0; - s->child_args = NULL; - if (re->nsub_ == 1) - s->child_args = &s->child_arg; - else if (re->nsub_ > 1) - s->child_args = new T[re->nsub_]; - FALLTHROUGH_INTENDED; + case -1: { + if (--max_visits_ < 0) { + stopped_early_ = true; + t = ShortVisit(re, s->parent_arg); + break; + } + bool stop = false; + s->pre_arg = PreVisit(re, s->parent_arg, &stop); + if (stop) { + t = s->pre_arg; + break; } - default: { - if (re->nsub_ > 0) { - Regexp** sub = re->sub(); - if (s->n < re->nsub_) { - if (use_copy && s->n > 0 && sub[s->n - 1] == sub[s->n]) { - s->child_args[s->n] = Copy(s->child_args[s->n - 1]); - s->n++; - } else { - stack_.push(WalkState(sub[s->n], s->pre_arg)); - } - continue; + s->n = 0; + s->child_args = NULL; + if (re->nsub_ == 1) + s->child_args = &s->child_arg; + else if (re->nsub_ > 1) + s->child_args = new T[re->nsub_]; + FALLTHROUGH_INTENDED; + } + default: { + if (re->nsub_ > 0) { + Regexp **sub = re->sub(); + if (s->n < re->nsub_) { + if (use_copy && s->n > 0 && sub[s->n - 1] == sub[s->n]) { + s->child_args[s->n] = Copy(s->child_args[s->n - 1]); + s->n++; + } else { + stack_.push(WalkState(sub[s->n], s->pre_arg)); } + continue; } - - t = PostVisit(re, s->parent_arg, s->pre_arg, s->child_args, s->n); - if (re->nsub_ > 1) - delete[] s->child_args; - break; } + + t = PostVisit(re, s->parent_arg, s->pre_arg, s->child_args, s->n); + if (re->nsub_ > 1) + delete[] s->child_args; + break; + } } // We've finished stack_.top(). @@ -227,7 +215,7 @@ template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, } } -template T Regexp::Walker::Walk(Regexp* re, T top_arg) { +template T Regexp::Walker::Walk(Regexp *re, T top_arg) { // Without the exponential walking behavior, // this budget should be more than enough for any // regexp, and yet not enough to get us in trouble @@ -236,12 +224,12 @@ template T Regexp::Walker::Walk(Regexp* re, T top_arg) { return WalkInternal(re, top_arg, true); } -template T Regexp::Walker::WalkExponential(Regexp* re, T top_arg, - int max_visits) { +template +T Regexp::Walker::WalkExponential(Regexp *re, T top_arg, int max_visits) { max_visits_ = max_visits; return WalkInternal(re, top_arg, false); } -} // namespace re2 +} // namespace re2 -#endif // RE2_WALKER_INL_H_ +#endif // RE2_WALKER_INL_H_ From c922e54587f24448d6b8f4edaa1522f2490fd04b Mon Sep 17 00:00:00 2001 From: jakmro Date: Fri, 7 Mar 2025 18:50:38 +0100 Subject: [PATCH 3/6] Fix ktlint-detected issues --- .../swmansion/rnexecutorch/SpeechToText.kt | 4 +- .../rnexecutorch/models/StyleTransferModel.kt | 2 +- .../objectDetection/SSDLiteLargeModel.kt | 8 ++-- .../models/speechToText/BaseS2TModule.kt | 4 +- .../models/speechToText/Moonshine.kt | 4 +- .../models/speechToText/Whisper.kt | 4 +- .../rnexecutorch/utils/ImageProcessor.kt | 2 +- .../utils/ProgressResponseBody.kt | 48 ------------------- 8 files changed, 14 insertions(+), 62 deletions(-) delete mode 100644 android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt diff --git a/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt b/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt index 151fc856..1895ce5a 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt @@ -57,10 +57,10 @@ class SpeechToText( promise: Promise, ) { val encoding = writableArrayToEValue(this.speechToTextModule.encode(waveform)) - val generatedTokens = mutableListOf(this.speechToTextModule.START_TOKEN) + val generatedTokens = mutableListOf(this.speechToTextModule.startToken) var lastToken = 0 Thread { - while (lastToken != this.speechToTextModule.EOS_TOKEN) { + while (lastToken != this.speechToTextModule.eosToken) { // TODO uncomment, for now // lastToken = this.speechToTextModule.decode(generatedTokens, encoding) emitOnToken(lastToken.toDouble()) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt index 4e652dc5..387241c9 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/StyleTransferModel.kt @@ -29,7 +29,7 @@ class StyleTransferModel( override fun postprocess(output: Array): Mat { val tensor = output[0].toTensor() val modelShape = getModelImageSize() - val result = ImageProcessor.EValueToMat(tensor.dataAsFloatArray, modelShape.width.toInt(), modelShape.height.toInt()) + val result = ImageProcessor.eValueToMat(tensor.dataAsFloatArray, modelShape.width.toInt(), modelShape.height.toInt()) Imgproc.resize(result, result, originalSize) return result } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt index 3969dfa3..209af026 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt @@ -12,8 +12,8 @@ import org.opencv.core.Size import org.opencv.imgproc.Imgproc import org.pytorch.executorch.EValue -const val detectionScoreThreshold = .7f -const val iouThreshold = .55f +const val DETECTION_SCORE_THRESHOLD = .7f +const val IOU_THRESHOLD = .55f class SSDLiteLargeModel( reactApplicationContext: ReactApplicationContext, @@ -52,7 +52,7 @@ class SSDLiteLargeModel( val detections: MutableList = mutableListOf() for (idx in 0 until numel.toInt()) { val score = scores[idx] - if (score < detectionScoreThreshold) { + if (score < DETECTION_SCORE_THRESHOLD) { continue } val bbox = @@ -68,7 +68,7 @@ class SSDLiteLargeModel( ) } - val detectionsPostNms = nms(detections, iouThreshold) + val detectionsPostNms = nms(detections, IOU_THRESHOLD) return detectionsPostNms.toTypedArray() } } diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt index 79788c3e..1b4abd1d 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt @@ -7,8 +7,8 @@ import com.swmansion.rnexecutorch.models.BaseModel abstract class BaseS2TModule { lateinit var encoder: BaseModel lateinit var decoder: BaseS2TDecoder - abstract var START_TOKEN: Int - abstract var EOS_TOKEN: Int + abstract var startToken: Int + abstract var eosToken: Int fun encode(input: ReadableArray): WritableArray = this.encoder.runModel(input) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt index 87550f69..a77b71a8 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt @@ -3,8 +3,8 @@ package com.swmansion.rnexecutorch.models.speechtotext import com.facebook.react.bridge.ReadableArray class Moonshine : BaseS2TModule() { - override var START_TOKEN = 1 - override var EOS_TOKEN = 2 + override var startToken = 1 + override var eosToken = 2 override fun decode( prevTokens: ReadableArray, diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt index af07ea8c..4208601a 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt @@ -3,8 +3,8 @@ package com.swmansion.rnexecutorch.models.speechtotext import com.facebook.react.bridge.ReadableArray class Whisper : BaseS2TModule() { - override var START_TOKEN = 50257 - override var EOS_TOKEN = 50256 + override var startToken = 50257 + override var eosToken = 50256 override fun decode( prevTokens: ReadableArray, diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt index e26a6244..b8b262e7 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt @@ -72,7 +72,7 @@ class ImageProcessor { ) } - fun EValueToMat( + fun eValueToMat( array: FloatArray, width: Int, height: Int, diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt deleted file mode 100644 index a5ff5679..00000000 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ProgressResponseBody.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.swmansion.rnexecutorch.utils - -import okhttp3.MediaType -import okhttp3.ResponseBody -import okio.* -import java.io.IOException - -class ProgressResponseBody( - private val responseBody: ResponseBody, - private val progressListener: ProgressListener, -) : ResponseBody() { - interface ProgressListener { - fun onProgress( - bytesRead: Long, - contentLength: Long, - done: Boolean, - ) - } - - private var bufferedSource: BufferedSource? = null - - override fun contentType(): MediaType? = responseBody.contentType() - - override fun contentLength(): Long = responseBody.contentLength() - - override fun source(): BufferedSource { - if (bufferedSource == null) { - bufferedSource = source(responseBody.source()).buffer() - } - return bufferedSource!! - } - - private fun source(source: Source): Source = - object : ForwardingSource(source) { - var totalBytesRead = 0L - - @Throws(IOException::class) - override fun read( - sink: Buffer, - byteCount: Long, - ): Long { - val bytesRead = super.read(sink, byteCount) - totalBytesRead += if (bytesRead != -1L) bytesRead else 0 - progressListener.onProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1L) - return bytesRead - } - } -} From ce6948bbbfa3f00631af767073b12b4006fb839b Mon Sep 17 00:00:00 2001 From: jakmro Date: Fri, 7 Mar 2025 18:55:23 +0100 Subject: [PATCH 4/6] Remove src/decoders/ pattern ignoring --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9da10ebb..44fbe804 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "example": "yarn workspace react-native-executorch-example", "test": "jest", "typecheck": "tsc", - "lint": "eslint \"**/*.{js,ts,tsx}\" --ignore-pattern src/decoders/", + "lint": "eslint \"**/*.{js,ts,tsx}\"", "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", "prepare": "bob build", "release": "release-it" From 537c369c9530c809ec23954326e89fedaba4686e Mon Sep 17 00:00:00 2001 From: jakmro Date: Fri, 7 Mar 2025 19:12:15 +0100 Subject: [PATCH 5/6] Fix linting warnings --- examples/speech-to-text/screens/SpeechToTextScreen.tsx | 6 +++--- src/controllers/SpeechToTextController.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/speech-to-text/screens/SpeechToTextScreen.tsx b/examples/speech-to-text/screens/SpeechToTextScreen.tsx index f9cfcb82..1dc44ace 100644 --- a/examples/speech-to-text/screens/SpeechToTextScreen.tsx +++ b/examples/speech-to-text/screens/SpeechToTextScreen.tsx @@ -13,7 +13,7 @@ import { Buffer } from 'buffer'; import DeviceInfo from 'react-native-device-info'; import InputPrompt from '../components/TextInputModal'; -const options = { +const audioStreamOptions = { sampleRate: 16000, channels: 1, bitsPerSample: 16, @@ -35,7 +35,7 @@ const float32ArrayFromPCMBinaryBuffer = (b64EncodedBuffer: string) => { for (let i = 0; i < int16Array.length; i++) { float32Array[i] = Math.max( -1, - Math.min(1, (int16Array[i] / options.bufferSize) * 8) + Math.min(1, (int16Array[i] / audioStreamOptions.bufferSize) * 8) ); } return float32Array; @@ -69,7 +69,7 @@ export const SpeechToTextScreen = () => { audioBuffer.current = []; } else { setIsRecording(true); - startStreamingAudio(options, onChunk); + startStreamingAudio(audioStreamOptions, onChunk); } }; diff --git a/src/controllers/SpeechToTextController.ts b/src/controllers/SpeechToTextController.ts index 20cf0f0f..815fbff7 100644 --- a/src/controllers/SpeechToTextController.ts +++ b/src/controllers/SpeechToTextController.ts @@ -249,7 +249,7 @@ export class SpeechToTextController { this.decodedTranscribeCallback(prevseq); } } - if (this.chunks.length == 1) { + if (this.chunks.length === 1) { final_seq = seq; this.sequence = final_seq; this.decodedTranscribeCallback(final_seq); From f37be10cf93a9d2b521e849c308da4265f8da34b Mon Sep 17 00:00:00 2001 From: jakmro Date: Fri, 7 Mar 2025 19:26:29 +0100 Subject: [PATCH 6/6] Fix linting errors related to styling --- .../screens/SpeechToTextScreen.tsx | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/examples/speech-to-text/screens/SpeechToTextScreen.tsx b/examples/speech-to-text/screens/SpeechToTextScreen.tsx index 1dc44ace..bd54bc30 100644 --- a/examples/speech-to-text/screens/SpeechToTextScreen.tsx +++ b/examples/speech-to-text/screens/SpeechToTextScreen.tsx @@ -90,13 +90,7 @@ export const SpeechToTextScreen = () => { {downloadProgress !== 1 ? ( - + {`Downloading model: ${(Number(downloadProgress.toFixed(4)) * 100).toFixed(2)}%`} @@ -106,11 +100,7 @@ export const SpeechToTextScreen = () => { style={ sequence ? styles.transcriptionText - : { - ...styles.transcriptionText, - color: 'gray', - textAlign: 'center', - } + : [styles.transcriptionText, styles.textGreyCenter] } > {sequence || @@ -121,7 +111,7 @@ export const SpeechToTextScreen = () => { )} {error && ( {`${error}`} )} { { if (!audioUrl) { @@ -162,7 +148,7 @@ export const SpeechToTextScreen = () => { } }} > - + {'TRANSCRIBE FROM URL'} @@ -172,20 +158,17 @@ export const SpeechToTextScreen = () => { + zRXW @@ -194,11 +177,7 @@ export const SpeechToTextScreen = () => { {DeviceInfo.isEmulatorSync() && ( recording does not work on emulator @@ -286,4 +265,30 @@ const styles = StyleSheet.create({ color: 'white', fontWeight: '600', }, + textGreyCenter: { + color: 'gray', + textAlign: 'center', + }, + redText: { + color: 'red', + }, + borderGrey: { + borderColor: 'grey', + }, + backgroundGrey: { + backgroundColor: 'grey', + }, + font13: { + fontSize: 13, + }, + borderRed: { + borderColor: 'rgb(240, 63, 50)', + }, + backgroundRed: { + backgroundColor: 'rgb(240, 63, 50)', + }, + emulatorWarning: { + color: 'rgb(254, 148, 141)', + fontSize: 11, + }, });