diff --git a/.github/workflows/build-android-llm-example.yml b/.github/workflows/build-android-llm-example.yml index be65210e5b..9f73811d30 100644 --- a/.github/workflows/build-android-llm-example.yml +++ b/.github/workflows/build-android-llm-example.yml @@ -45,6 +45,10 @@ jobs: distribution: 'zulu' java-version: 17 cache: 'gradle' + - name: Setup Android NDK + uses: nttld/setup-ndk@v1 + with: + ndk-version: r27b - name: Install root dependencies run: yarn install --immutable - name: Install Expo CLI diff --git a/packages/react-native-executorch/android/CMakeLists.txt b/packages/react-native-executorch/android/CMakeLists.txt index ddc7ab4126..b3af702e52 100644 --- a/packages/react-native-executorch/android/CMakeLists.txt +++ b/packages/react-native-executorch/android/CMakeLists.txt @@ -21,7 +21,7 @@ string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED") set(ANDROID_CPP_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp") set(COMMON_CPP_DIR "${CMAKE_SOURCE_DIR}/../common") set(LIBS_DIR "${CMAKE_SOURCE_DIR}/../third-party/android/libs") -set(TOKENIZERS_DIR "${CMAKE_SOURCE_DIR}/../third-party/include/executorch/extension/llm/tokenizers/include") +set(TOKENIZERS_DIR "${CMAKE_SOURCE_DIR}/../third-party/include") set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../third-party/include") # Treat third-party headers as system headers to suppress deprecation warnings diff --git a/packages/react-native-executorch/android/libs/classes.jar b/packages/react-native-executorch/android/libs/classes.jar index 3b00d51231..be5ec2ee7f 100644 Binary files a/packages/react-native-executorch/android/libs/classes.jar and b/packages/react-native-executorch/android/libs/classes.jar differ diff --git a/packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt b/packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt index d7bd1fa870..025775e93c 100644 --- a/packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt +++ b/packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt @@ -38,30 +38,106 @@ set(RN_VERSION_LINK_LIBRARIES # ------- Executorch ------- +# libexecutorch.so is the thin JNI wrapper (JNI_OnLoad + ASR entry points). +# It has a hard NEEDED dependency on libqnn_executorch_backend.so, so both must be bundled. +# All other runtime symbols are statically linked from executorch-static/*.a below. add_library(executorch SHARED IMPORTED) - set_target_properties(executorch PROPERTIES IMPORTED_LOCATION "${LIBS_DIR}/executorch/${ANDROID_ABI}/libexecutorch.so") -if(ANDROID_ABI STREQUAL "arm64-v8a") - target_compile_definitions(react-native-executorch PRIVATE ARCH_ARM64) +set(EXECUTORCH_STATIC_DIR "${LIBS_DIR}/executorch-static/${ANDROID_ABI}") - # ------- pthreadpool ------- - add_library(pthreadpool SHARED IMPORTED) +# Libs that use static constructors for kernel/backend registration — must use --whole-archive +# so registrations are not stripped by the linker. +set(EXECUTORCH_WHOLE_ARCHIVE_LIBS + "${EXECUTORCH_STATIC_DIR}/liboptimized_native_cpu_ops_lib.a" + "${EXECUTORCH_STATIC_DIR}/libxnnpack_backend.a" + "${EXECUTORCH_STATIC_DIR}/libvulkan_backend.a" + "${EXECUTORCH_STATIC_DIR}/libexecutorch.a" +) + +# Libs linked normally — only pull in symbols that are referenced. +# Do NOT include libs whose symbols are already compiled by this project +# (e.g. libextension_llm_runner, libextension_llm_sampler, libportable_kernels +# overlap with common/runner/*.cpp). +set(EXECUTORCH_STATIC_LIBS + "${EXECUTORCH_STATIC_DIR}/libexecutorch_core.a" + "${EXECUTORCH_STATIC_DIR}/libextension_module.a" + "${EXECUTORCH_STATIC_DIR}/libextension_tensor.a" + "${EXECUTORCH_STATIC_DIR}/libextension_threadpool.a" + "${EXECUTORCH_STATIC_DIR}/libextension_data_loader.a" + "${EXECUTORCH_STATIC_DIR}/libextension_runner_util.a" + "${EXECUTORCH_STATIC_DIR}/libtokenizers.a" + "${EXECUTORCH_STATIC_DIR}/libsentencepiece.a" + "${EXECUTORCH_STATIC_DIR}/libportable_kernels.a" + "${EXECUTORCH_STATIC_DIR}/liboptimized_kernels.a" + "${EXECUTORCH_STATIC_DIR}/libXNNPACK.a" + "${EXECUTORCH_STATIC_DIR}/libxnnpack-microkernels-prod.a" + "${EXECUTORCH_STATIC_DIR}/libre2.a" + "${EXECUTORCH_STATIC_DIR}/libcpublas.a" + "${EXECUTORCH_STATIC_DIR}/libeigen_blas.a" + "${EXECUTORCH_STATIC_DIR}/libpthreadpool.a" + "${EXECUTORCH_STATIC_DIR}/libextension_flat_tensor.a" + "${EXECUTORCH_STATIC_DIR}/libextension_named_data_map.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_message.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_globals.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_log_sink_set.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_format.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_check_op.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_conditions.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_nullguard.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_internal_proto.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_globals.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_entry.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_sink.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_initialize.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_log_flags.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_str_format_internal.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_strings.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_strings_internal.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_base.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_raw_logging_internal.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_spinlock_wait.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_synchronization.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_symbolize.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_stacktrace.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_int128.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_time.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_time_zone.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_throw_delegate.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_status.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_statusor.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_malloc_internal.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_raw_hash_set.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_hash.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_kernel_timeout_internal.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_examine_stack.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_strerror.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_city.a" + "${EXECUTORCH_STATIC_DIR}/libabsl_low_level_hash.a" +) - set_target_properties(pthreadpool PROPERTIES - IMPORTED_LOCATION "${LIBS_DIR}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so") +if(ANDROID_ABI STREQUAL "arm64-v8a") + target_compile_definitions(react-native-executorch PRIVATE ARCH_ARM64) # ------- cpuinfo ------- add_library(cpuinfo SHARED IMPORTED) - set_target_properties(cpuinfo PROPERTIES IMPORTED_LOCATION "${LIBS_DIR}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so") + + # ------- QNN backend ------- + add_library(qnn_executorch_backend SHARED IMPORTED) + set_target_properties(qnn_executorch_backend PROPERTIES + IMPORTED_LOCATION "${LIBS_DIR}/executorch/${ANDROID_ABI}/libqnn_executorch_backend.so") + set(EXECUTORCH_LIBS - "pthreadpool" "cpuinfo" + "qnn_executorch_backend" ) + + # kleidiai is ARM-only (Kleidi AI acceleration library) + list(APPEND EXECUTORCH_STATIC_LIBS "${EXECUTORCH_STATIC_DIR}/libkleidiai.a") endif() # ------- OpenCV ------- @@ -103,7 +179,12 @@ target_link_libraries( ${OPENCV_LIBS} ${OPENCV_THIRD_PARTY_LIBS} ${PHONEMIS_LIBS} + -Wl,--whole-archive + ${EXECUTORCH_WHOLE_ARCHIVE_LIBS} + -Wl,--no-whole-archive + ${EXECUTORCH_STATIC_LIBS} executorch ${EXECUTORCH_LIBS} + vulkan z ) diff --git a/packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt b/packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt index acc43c0a9e..ee818e33c9 100644 --- a/packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt +++ b/packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt @@ -50,6 +50,11 @@ class ETInstaller( init { try { System.loadLibrary("executorch") + try { + System.loadLibrary("qnn_executorch_backend") + } catch (e: UnsatisfiedLinkError) { + // QNN backend not available on this device (non-Qualcomm hardware) + } System.loadLibrary("react-native-executorch") val jsCallInvokerHolder = reactContext.jsCallInvokerHolder as CallInvokerHolderImpl mHybridData = initHybrid(reactContext.javaScriptContextHolder!!.get(), jsCallInvokerHolder) diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtp.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtp.so new file mode 100755 index 0000000000..6960e00e41 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtp.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpNetRunExtensions.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpNetRunExtensions.so new file mode 100755 index 0000000000..509a0ac6ec Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpNetRunExtensions.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Skel.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Skel.so new file mode 100755 index 0000000000..54161b4ab1 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Skel.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Stub.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Stub.so new file mode 100755 index 0000000000..92d682fe5c Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV68Stub.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Skel.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Skel.so new file mode 100755 index 0000000000..c46d72a452 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Skel.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Stub.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Stub.so new file mode 100755 index 0000000000..7dbcc8d813 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV69Stub.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Skel.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Skel.so new file mode 100755 index 0000000000..9bd64bba0b Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Skel.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Stub.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Stub.so new file mode 100755 index 0000000000..2a3a16c177 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV73Stub.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Skel.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Skel.so new file mode 100755 index 0000000000..cd910cb6da Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Skel.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Stub.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Stub.so new file mode 100755 index 0000000000..4f8207b68b Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV75Stub.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Skel.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Skel.so new file mode 100755 index 0000000000..e42b5a5e09 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Skel.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Stub.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Stub.so new file mode 100755 index 0000000000..eecf0e1fec Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnHtpV79Stub.so differ diff --git a/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnSystem.so b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnSystem.so new file mode 100755 index 0000000000..fde6732d44 Binary files /dev/null and b/packages/react-native-executorch/android/src/main/jniLibs/arm64-v8a/libQnnSystem.so differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libXNNPACK.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libXNNPACK.a new file mode 100644 index 0000000000..c50fd9f021 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libXNNPACK.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_base.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_base.a new file mode 100644 index 0000000000..8fdd5b2c87 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_base.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_city.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_city.a new file mode 100644 index 0000000000..6f4de67855 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_city.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_examine_stack.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_examine_stack.a new file mode 100644 index 0000000000..c09eb61f29 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_examine_stack.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_hash.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_hash.a new file mode 100644 index 0000000000..90f6e59b1b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_hash.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_int128.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_int128.a new file mode 100644 index 0000000000..d707229d4b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_int128.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_kernel_timeout_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_kernel_timeout_internal.a new file mode 100644 index 0000000000..82f8b4e2b3 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_kernel_timeout_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_entry.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_entry.a new file mode 100644 index 0000000000..490535a343 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_entry.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_flags.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_flags.a new file mode 100644 index 0000000000..34a084956b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_flags.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_globals.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_globals.a new file mode 100644 index 0000000000..0347e31f05 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_globals.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_initialize.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_initialize.a new file mode 100644 index 0000000000..2973bace28 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_initialize.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_check_op.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_check_op.a new file mode 100644 index 0000000000..a3a2094ce7 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_check_op.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_conditions.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_conditions.a new file mode 100644 index 0000000000..a6949d9d37 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_conditions.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_format.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_format.a new file mode 100644 index 0000000000..2dd0eee64b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_format.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_globals.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_globals.a new file mode 100644 index 0000000000..b7e1fcd0e0 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_globals.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_log_sink_set.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_log_sink_set.a new file mode 100644 index 0000000000..33bd242223 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_log_sink_set.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_message.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_message.a new file mode 100644 index 0000000000..9610cfc8dd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_message.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_nullguard.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_nullguard.a new file mode 100644 index 0000000000..f483024056 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_nullguard.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_proto.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_proto.a new file mode 100644 index 0000000000..cc122d3041 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_internal_proto.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_sink.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_sink.a new file mode 100644 index 0000000000..25365bdacc Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_log_sink.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_low_level_hash.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_low_level_hash.a new file mode 100644 index 0000000000..ec155dfc9b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_low_level_hash.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_malloc_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_malloc_internal.a new file mode 100644 index 0000000000..7932c8e023 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_malloc_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_hash_set.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_hash_set.a new file mode 100644 index 0000000000..6eba4f8309 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_hash_set.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_logging_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_logging_internal.a new file mode 100644 index 0000000000..47bac85497 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_raw_logging_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_spinlock_wait.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_spinlock_wait.a new file mode 100644 index 0000000000..d26b818e60 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_spinlock_wait.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_stacktrace.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_stacktrace.a new file mode 100644 index 0000000000..5b9b86f6bd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_stacktrace.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_status.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_status.a new file mode 100644 index 0000000000..91325128bd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_status.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_statusor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_statusor.a new file mode 100644 index 0000000000..32e9ed3dff Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_statusor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_str_format_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_str_format_internal.a new file mode 100644 index 0000000000..1bcdab8d1a Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_str_format_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strerror.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strerror.a new file mode 100644 index 0000000000..f9a83d0304 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strerror.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings.a new file mode 100644 index 0000000000..816ce3a0cd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings_internal.a new file mode 100644 index 0000000000..08ed6f6db4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_strings_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_symbolize.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_symbolize.a new file mode 100644 index 0000000000..fa7d22903c Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_symbolize.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_synchronization.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_synchronization.a new file mode 100644 index 0000000000..acf2c4688f Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_synchronization.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_throw_delegate.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_throw_delegate.a new file mode 100644 index 0000000000..9f2b9d13ba Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_throw_delegate.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time.a new file mode 100644 index 0000000000..1901cbcf3c Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time_zone.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time_zone.a new file mode 100644 index 0000000000..d43a496cfd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libabsl_time_zone.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libcpublas.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libcpublas.a new file mode 100644 index 0000000000..60d7617828 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libcpublas.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libeigen_blas.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libeigen_blas.a new file mode 100644 index 0000000000..9295a353b0 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libeigen_blas.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch.a new file mode 100644 index 0000000000..660f0b950d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch_core.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch_core.a new file mode 100644 index 0000000000..ceae4b5ba9 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libexecutorch_core.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_data_loader.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_data_loader.a new file mode 100644 index 0000000000..a246268e6c Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_data_loader.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_flat_tensor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_flat_tensor.a new file mode 100644 index 0000000000..2a95ba38c1 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_flat_tensor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_runner.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_runner.a new file mode 100644 index 0000000000..c021632601 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_runner.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_sampler.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_sampler.a new file mode 100644 index 0000000000..b8b3f771c1 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_llm_sampler.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_module.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_module.a new file mode 100644 index 0000000000..910a00d49a Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_module.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_named_data_map.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_named_data_map.a new file mode 100644 index 0000000000..1e91bd7849 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_named_data_map.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_runner_util.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_runner_util.a new file mode 100644 index 0000000000..5bdf2aaf59 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_runner_util.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_tensor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_tensor.a new file mode 100644 index 0000000000..724f8eccbb Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_tensor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_threadpool.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_threadpool.a new file mode 100644 index 0000000000..dddbfa1a7a Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libextension_threadpool.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libkleidiai.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libkleidiai.a new file mode 100644 index 0000000000..15fff3647c Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libkleidiai.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_kernels.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_kernels.a new file mode 100644 index 0000000000..5613ed316f Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_kernels.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_native_cpu_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_native_cpu_ops_lib.a new file mode 100644 index 0000000000..1fcd7de5a4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_native_cpu_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_ops_lib.a new file mode 100644 index 0000000000..cc7e645b0b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/liboptimized_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_kernels.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_kernels.a new file mode 100644 index 0000000000..81d3b0ae8d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_kernels.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_ops_lib.a new file mode 100644 index 0000000000..e552b364f3 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libportable_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libpthreadpool.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libpthreadpool.a new file mode 100644 index 0000000000..47f8e00d6a Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libpthreadpool.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libre2.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libre2.a new file mode 100644 index 0000000000..d4d6dd021b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libre2.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libsentencepiece.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libsentencepiece.a new file mode 100644 index 0000000000..1e84f9d8f2 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libsentencepiece.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libtokenizers.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libtokenizers.a new file mode 100644 index 0000000000..3925cf1228 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libtokenizers.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libvulkan_backend.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libvulkan_backend.a new file mode 100644 index 0000000000..f9e5b3a13b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libvulkan_backend.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack-microkernels-prod.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack-microkernels-prod.a new file mode 100644 index 0000000000..bf5036cbf8 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack-microkernels-prod.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack_backend.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack_backend.a new file mode 100644 index 0000000000..e3078e7eb7 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/arm64-v8a/libxnnpack_backend.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libXNNPACK.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libXNNPACK.a new file mode 100644 index 0000000000..d643aa35cf Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libXNNPACK.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_base.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_base.a new file mode 100644 index 0000000000..b0ec046c5b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_base.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_city.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_city.a new file mode 100644 index 0000000000..8af5cbe39d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_city.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_examine_stack.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_examine_stack.a new file mode 100644 index 0000000000..6e1f5bd40b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_examine_stack.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_hash.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_hash.a new file mode 100644 index 0000000000..386721dc2f Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_hash.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_int128.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_int128.a new file mode 100644 index 0000000000..a54d6e06f3 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_int128.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_kernel_timeout_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_kernel_timeout_internal.a new file mode 100644 index 0000000000..5184fea57e Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_kernel_timeout_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_entry.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_entry.a new file mode 100644 index 0000000000..4e5ebb9aa4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_entry.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_flags.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_flags.a new file mode 100644 index 0000000000..420305f0e4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_flags.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_globals.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_globals.a new file mode 100644 index 0000000000..3df6413c66 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_globals.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_initialize.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_initialize.a new file mode 100644 index 0000000000..dbf89c2a7e Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_initialize.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_check_op.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_check_op.a new file mode 100644 index 0000000000..fdcad30a4d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_check_op.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_conditions.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_conditions.a new file mode 100644 index 0000000000..afb0346a09 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_conditions.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_format.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_format.a new file mode 100644 index 0000000000..29a0aeac92 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_format.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_globals.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_globals.a new file mode 100644 index 0000000000..9149dd91ef Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_globals.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_log_sink_set.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_log_sink_set.a new file mode 100644 index 0000000000..3345291503 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_log_sink_set.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_message.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_message.a new file mode 100644 index 0000000000..cc7a4af211 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_message.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_nullguard.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_nullguard.a new file mode 100644 index 0000000000..d71717b789 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_nullguard.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_proto.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_proto.a new file mode 100644 index 0000000000..2a9ce1eab0 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_internal_proto.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_sink.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_sink.a new file mode 100644 index 0000000000..71f0db5351 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_log_sink.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_low_level_hash.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_low_level_hash.a new file mode 100644 index 0000000000..f2ba772a15 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_low_level_hash.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_malloc_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_malloc_internal.a new file mode 100644 index 0000000000..0fceb2d03b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_malloc_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_hash_set.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_hash_set.a new file mode 100644 index 0000000000..0cf1bace9d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_hash_set.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_logging_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_logging_internal.a new file mode 100644 index 0000000000..b2850bfbe6 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_raw_logging_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_spinlock_wait.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_spinlock_wait.a new file mode 100644 index 0000000000..ebe9fba3bd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_spinlock_wait.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_stacktrace.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_stacktrace.a new file mode 100644 index 0000000000..718369531c Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_stacktrace.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_status.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_status.a new file mode 100644 index 0000000000..9e4e324e45 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_status.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_statusor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_statusor.a new file mode 100644 index 0000000000..ada09b0776 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_statusor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_str_format_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_str_format_internal.a new file mode 100644 index 0000000000..8e138c70e2 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_str_format_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strerror.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strerror.a new file mode 100644 index 0000000000..07a7018d20 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strerror.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings.a new file mode 100644 index 0000000000..4220068b97 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings_internal.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings_internal.a new file mode 100644 index 0000000000..5e5f4b91a4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_strings_internal.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_symbolize.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_symbolize.a new file mode 100644 index 0000000000..bc329e1c13 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_symbolize.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_synchronization.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_synchronization.a new file mode 100644 index 0000000000..bb1871a842 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_synchronization.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_throw_delegate.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_throw_delegate.a new file mode 100644 index 0000000000..d153c31a0d Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_throw_delegate.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time.a new file mode 100644 index 0000000000..d889a481e8 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time_zone.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time_zone.a new file mode 100644 index 0000000000..b34e472ea6 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libabsl_time_zone.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libcpublas.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libcpublas.a new file mode 100644 index 0000000000..073fd536f8 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libcpublas.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libeigen_blas.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libeigen_blas.a new file mode 100644 index 0000000000..7bc41848b0 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libeigen_blas.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch.a new file mode 100644 index 0000000000..97188b01cf Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch_core.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch_core.a new file mode 100644 index 0000000000..f0f4249129 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libexecutorch_core.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_data_loader.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_data_loader.a new file mode 100644 index 0000000000..f05ebdf6d7 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_data_loader.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_flat_tensor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_flat_tensor.a new file mode 100644 index 0000000000..547fe2d6ae Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_flat_tensor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_llm_sampler.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_llm_sampler.a new file mode 100644 index 0000000000..a31ec434b5 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_llm_sampler.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_module.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_module.a new file mode 100644 index 0000000000..40bf7e8f65 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_module.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_named_data_map.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_named_data_map.a new file mode 100644 index 0000000000..119fa0a7f9 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_named_data_map.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_runner_util.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_runner_util.a new file mode 100644 index 0000000000..ced9b5bce9 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_runner_util.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_tensor.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_tensor.a new file mode 100644 index 0000000000..6e85d8d2dd Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_tensor.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_threadpool.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_threadpool.a new file mode 100644 index 0000000000..8c6fe5aaa4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libextension_threadpool.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_kernels.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_kernels.a new file mode 100644 index 0000000000..a0fcd1675b Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_kernels.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_native_cpu_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_native_cpu_ops_lib.a new file mode 100644 index 0000000000..6d189492e8 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_native_cpu_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_ops_lib.a new file mode 100644 index 0000000000..de8336a5c5 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/liboptimized_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_kernels.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_kernels.a new file mode 100644 index 0000000000..d102b82767 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_kernels.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_ops_lib.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_ops_lib.a new file mode 100644 index 0000000000..f4c90a71eb Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libportable_ops_lib.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libpthreadpool.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libpthreadpool.a new file mode 100644 index 0000000000..eda8f783eb Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libpthreadpool.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libre2.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libre2.a new file mode 100644 index 0000000000..1e0ff6b346 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libre2.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libsentencepiece.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libsentencepiece.a new file mode 100644 index 0000000000..1b3d41a92a Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libsentencepiece.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libtokenizers.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libtokenizers.a new file mode 100644 index 0000000000..6e20c20b92 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libtokenizers.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libvulkan_backend.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libvulkan_backend.a new file mode 100644 index 0000000000..9910a88443 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libvulkan_backend.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack-microkernels-prod.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack-microkernels-prod.a new file mode 100644 index 0000000000..6e6d5d74d4 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack-microkernels-prod.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack_backend.a b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack_backend.a new file mode 100644 index 0000000000..febd8707c6 Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch-static/x86_64/libxnnpack_backend.a differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so b/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so index 413f42448e..2bc6effa55 100644 Binary files a/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so and b/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libqnn_executorch_backend.so b/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libqnn_executorch_backend.so new file mode 100755 index 0000000000..aa43260d9f Binary files /dev/null and b/packages/react-native-executorch/third-party/android/libs/executorch/arm64-v8a/libqnn_executorch_backend.so differ diff --git a/packages/react-native-executorch/third-party/android/libs/executorch/x86_64/libexecutorch.so b/packages/react-native-executorch/third-party/android/libs/executorch/x86_64/libexecutorch.so index c96d61aa68..a38036d63a 100644 Binary files a/packages/react-native-executorch/third-party/android/libs/executorch/x86_64/libexecutorch.so and b/packages/react-native-executorch/third-party/android/libs/executorch/x86_64/libexecutorch.so differ diff --git a/packages/react-native-executorch/third-party/include/cpuinfo.h b/packages/react-native-executorch/third-party/include/cpuinfo.h new file mode 100644 index 0000000000..5efecb3a7d --- /dev/null +++ b/packages/react-native-executorch/third-party/include/cpuinfo.h @@ -0,0 +1,2363 @@ +#pragma once +#ifndef CPUINFO_H +#define CPUINFO_H + +#ifndef __cplusplus +#include +#endif + +#ifdef __APPLE__ +#include +#endif + +#include + +/* Identify architecture and define corresponding macro */ + +#if defined(__i386__) || defined(__i486__) || defined(__i586__) || \ + defined(__i686__) || defined(_M_IX86) +#define CPUINFO_ARCH_X86 1 +#endif + +#if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || \ + defined(_M_AMD64) +#define CPUINFO_ARCH_X86_64 1 +#endif + +#if defined(__arm__) || defined(_M_ARM) +#define CPUINFO_ARCH_ARM 1 +#endif + +#if defined(__aarch64__) || defined(_M_ARM64) +#define CPUINFO_ARCH_ARM64 1 +#endif + +#if defined(__PPC64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) +#define CPUINFO_ARCH_PPC64 1 +#endif + +#if defined(__asmjs__) +#define CPUINFO_ARCH_ASMJS 1 +#endif + +#if defined(__wasm__) +#if defined(__wasm_simd128__) +#define CPUINFO_ARCH_WASMSIMD 1 +#else +#define CPUINFO_ARCH_WASM 1 +#endif +#endif + +#if defined(__riscv) +#if (__riscv_xlen == 32) +#define CPUINFO_ARCH_RISCV32 1 +#elif (__riscv_xlen == 64) +#define CPUINFO_ARCH_RISCV64 1 +#endif +#endif + +/* Define other architecture-specific macros as 0 */ + +#ifndef CPUINFO_ARCH_X86 +#define CPUINFO_ARCH_X86 0 +#endif + +#ifndef CPUINFO_ARCH_X86_64 +#define CPUINFO_ARCH_X86_64 0 +#endif + +#ifndef CPUINFO_ARCH_ARM +#define CPUINFO_ARCH_ARM 0 +#endif + +#ifndef CPUINFO_ARCH_ARM64 +#define CPUINFO_ARCH_ARM64 0 +#endif + +#ifndef CPUINFO_ARCH_PPC64 +#define CPUINFO_ARCH_PPC64 0 +#endif + +#ifndef CPUINFO_ARCH_ASMJS +#define CPUINFO_ARCH_ASMJS 0 +#endif + +#ifndef CPUINFO_ARCH_WASM +#define CPUINFO_ARCH_WASM 0 +#endif + +#ifndef CPUINFO_ARCH_WASMSIMD +#define CPUINFO_ARCH_WASMSIMD 0 +#endif + +#ifndef CPUINFO_ARCH_RISCV32 +#define CPUINFO_ARCH_RISCV32 0 +#endif + +#ifndef CPUINFO_ARCH_RISCV64 +#define CPUINFO_ARCH_RISCV64 0 +#endif + +#if CPUINFO_ARCH_X86 && defined(_MSC_VER) +#define CPUINFO_ABI __cdecl +#elif CPUINFO_ARCH_X86 && defined(__GNUC__) +#define CPUINFO_ABI __attribute__((__cdecl__)) +#else +#define CPUINFO_ABI +#endif + +#define CPUINFO_CACHE_UNIFIED 0x00000001 +#define CPUINFO_CACHE_INCLUSIVE 0x00000002 +#define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004 + +struct cpuinfo_cache { + /** Cache size in bytes */ + uint32_t size; + /** Number of ways of associativity */ + uint32_t associativity; + /** Number of sets */ + uint32_t sets; + /** Number of partitions */ + uint32_t partitions; + /** Line size in bytes */ + uint32_t line_size; + /** + * Binary characteristics of the cache (unified cache, inclusive cache, + * cache with complex indexing). + * + * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE, + * CPUINFO_CACHE_COMPLEX_INDEXING + */ + uint32_t flags; + /** Index of the first logical processor that shares this cache */ + uint32_t processor_start; + /** Number of logical processors that share this cache */ + uint32_t processor_count; +}; + +struct cpuinfo_trace_cache { + uint32_t uops; + uint32_t associativity; +}; + +#define CPUINFO_PAGE_SIZE_4KB 0x1000 +#define CPUINFO_PAGE_SIZE_1MB 0x100000 +#define CPUINFO_PAGE_SIZE_2MB 0x200000 +#define CPUINFO_PAGE_SIZE_4MB 0x400000 +#define CPUINFO_PAGE_SIZE_16MB 0x1000000 +#define CPUINFO_PAGE_SIZE_1GB 0x40000000 + +struct cpuinfo_tlb { + uint32_t entries; + uint32_t associativity; + uint64_t pages; +}; + +/** Vendor of processor core design */ +enum cpuinfo_vendor { + /** Processor vendor is not known to the library, or the library failed + to get vendor information from the OS. */ + cpuinfo_vendor_unknown = 0, + + /* Active vendors of modern CPUs */ + + /** + * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor + * microarchitectures. + * + * Sold its ARM design subsidiary in 2006. The last ARM processor design + * was released in 2004. + */ + cpuinfo_vendor_intel = 1, + /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor + microarchitectures. */ + cpuinfo_vendor_amd = 2, + /** ARM Holdings plc. Vendor of ARM and ARM64 processor + microarchitectures. */ + cpuinfo_vendor_arm = 3, + /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor + microarchitectures. */ + cpuinfo_vendor_qualcomm = 4, + /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */ + cpuinfo_vendor_apple = 5, + /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor + microarchitectures. */ + cpuinfo_vendor_samsung = 6, + /** Nvidia Corporation. Vendor of ARM64-compatible processor + microarchitectures. */ + cpuinfo_vendor_nvidia = 7, + /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures. + */ + cpuinfo_vendor_mips = 8, + /** International Business Machines Corporation. Vendor of PowerPC + processor microarchitectures. */ + cpuinfo_vendor_ibm = 9, + /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures. + */ + cpuinfo_vendor_ingenic = 10, + /** + * VIA Technologies, Inc. Vendor of x86 and x86-64 processor + * microarchitectures. + * + * Processors are designed by Centaur Technology, a subsidiary of VIA + * Technologies. + */ + cpuinfo_vendor_via = 11, + /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */ + cpuinfo_vendor_cavium = 12, + /** Broadcom, Inc. Vendor of ARM processor microarchitectures. */ + cpuinfo_vendor_broadcom = 13, + /** Applied Micro Circuits Corporation (APM). Vendor of ARM64 processor + microarchitectures. */ + cpuinfo_vendor_apm = 14, + /** + * Huawei Technologies Co., Ltd. Vendor of ARM64 processor + * microarchitectures. + * + * Processors are designed by HiSilicon, a subsidiary of Huawei. + */ + cpuinfo_vendor_huawei = 15, + /** + * Hygon (Chengdu Haiguang Integrated Circuit Design Co., Ltd), Vendor + * of x86-64 processor microarchitectures. + * + * Processors are variants of AMD cores. + */ + cpuinfo_vendor_hygon = 16, + /** SiFive, Inc. Vendor of RISC-V processor microarchitectures. */ + cpuinfo_vendor_sifive = 17, + + /* Active vendors of embedded CPUs */ + + /** Texas Instruments Inc. Vendor of ARM processor microarchitectures. + */ + cpuinfo_vendor_texas_instruments = 30, + /** Marvell Technology Group Ltd. Vendor of ARM processor + * microarchitectures. + */ + cpuinfo_vendor_marvell = 31, + /** RDC Semiconductor Co., Ltd. Vendor of x86 processor + microarchitectures. */ + cpuinfo_vendor_rdc = 32, + /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */ + cpuinfo_vendor_dmp = 33, + /** Motorola, Inc. Vendor of PowerPC and ARM processor + microarchitectures. */ + cpuinfo_vendor_motorola = 34, + + /* Defunct CPU vendors */ + + /** + * Transmeta Corporation. Vendor of x86 processor microarchitectures. + * + * Now defunct. The last processor design was released in 2004. + * Transmeta processors implemented VLIW ISA and used binary translation + * to execute x86 code. + */ + cpuinfo_vendor_transmeta = 50, + /** + * Cyrix Corporation. Vendor of x86 processor microarchitectures. + * + * Now defunct. The last processor design was released in 1996. + */ + cpuinfo_vendor_cyrix = 51, + /** + * Rise Technology. Vendor of x86 processor microarchitectures. + * + * Now defunct. The last processor design was released in 1999. + */ + cpuinfo_vendor_rise = 52, + /** + * National Semiconductor. Vendor of x86 processor microarchitectures. + * + * Sold its x86 design subsidiary in 1999. The last processor design was + * released in 1998. + */ + cpuinfo_vendor_nsc = 53, + /** + * Silicon Integrated Systems. Vendor of x86 processor + * microarchitectures. + * + * Sold its x86 design subsidiary in 2001. The last processor design was + * released in 2001. + */ + cpuinfo_vendor_sis = 54, + /** + * NexGen. Vendor of x86 processor microarchitectures. + * + * Now defunct. The last processor design was released in 1994. + * NexGen designed the first x86 microarchitecture which decomposed x86 + * instructions into simple microoperations. + */ + cpuinfo_vendor_nexgen = 55, + /** + * United Microelectronics Corporation. Vendor of x86 processor + * microarchitectures. + * + * Ceased x86 in the early 1990s. The last processor design was released + * in 1991. Designed U5C and U5D processors. Both are 486 level. + */ + cpuinfo_vendor_umc = 56, + /** + * Digital Equipment Corporation. Vendor of ARM processor + * microarchitecture. + * + * Sold its ARM designs in 1997. The last processor design was released + * in 1997. + */ + cpuinfo_vendor_dec = 57, +}; + +/** + * Processor microarchitecture + * + * Processors with different microarchitectures often have different instruction + * performance characteristics, and may have dramatically different pipeline + * organization. + */ +enum cpuinfo_uarch { + /** Microarchitecture is unknown, or the library failed to get + information about the microarchitecture from OS */ + cpuinfo_uarch_unknown = 0, + + /** Pentium and Pentium MMX microarchitecture. */ + cpuinfo_uarch_p5 = 0x00100100, + /** Intel Quark microarchitecture. */ + cpuinfo_uarch_quark = 0x00100101, + + /** Pentium Pro, Pentium II, and Pentium III. */ + cpuinfo_uarch_p6 = 0x00100200, + /** Pentium M. */ + cpuinfo_uarch_dothan = 0x00100201, + /** Intel Core microarchitecture. */ + cpuinfo_uarch_yonah = 0x00100202, + /** Intel Core 2 microarchitecture on 65 nm process. */ + cpuinfo_uarch_conroe = 0x00100203, + /** Intel Core 2 microarchitecture on 45 nm process. */ + cpuinfo_uarch_penryn = 0x00100204, + /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st + gen). */ + cpuinfo_uarch_nehalem = 0x00100205, + /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */ + cpuinfo_uarch_sandy_bridge = 0x00100206, + /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */ + cpuinfo_uarch_ivy_bridge = 0x00100207, + /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */ + cpuinfo_uarch_haswell = 0x00100208, + /** Intel Broadwell microarchitecture. */ + cpuinfo_uarch_broadwell = 0x00100209, + /** Intel Sky Lake microarchitecture (14 nm, including + Kaby/Coffee/Whiskey/Amber/Comet/Cascade/Cooper Lake). */ + cpuinfo_uarch_sky_lake = 0x0010020A, + /** DEPRECATED (Intel Kaby Lake microarchitecture). */ + cpuinfo_uarch_kaby_lake = 0x0010020A, + /** Intel Palm Cove microarchitecture (10 nm, Cannon Lake). */ + cpuinfo_uarch_palm_cove = 0x0010020B, + /** Intel Sunny Cove microarchitecture (10 nm, Ice Lake). */ + cpuinfo_uarch_sunny_cove = 0x0010020C, + /** Intel Willow Cove microarchitecture (10 nm, Tiger Lake). */ + cpuinfo_uarch_willow_cove = 0x0010020D, + + /** Pentium 4 with Willamette, Northwood, or Foster cores. */ + cpuinfo_uarch_willamette = 0x00100300, + /** Pentium 4 with Prescott and later cores. */ + cpuinfo_uarch_prescott = 0x00100301, + + /** Intel Atom on 45 nm process. */ + cpuinfo_uarch_bonnell = 0x00100400, + /** Intel Atom on 32 nm process. */ + cpuinfo_uarch_saltwell = 0x00100401, + /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */ + cpuinfo_uarch_silvermont = 0x00100402, + /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */ + cpuinfo_uarch_airmont = 0x00100403, + /** Intel Goldmont microarchitecture (Denverton, Apollo Lake). */ + cpuinfo_uarch_goldmont = 0x00100404, + /** Intel Goldmont Plus microarchitecture (Gemini Lake). */ + cpuinfo_uarch_goldmont_plus = 0x00100405, + /** Intel Airmont microarchitecture (10 nm out-of-order Atom). */ + cpuinfo_uarch_tremont = 0x00100406, + /** Intel Gracemont microarchitecture (AlderLake N). */ + cpuinfo_uarch_gracemont = 0x00100407, + /** Intel Crestmont microarchitecture (Sierra Forest). */ + cpuinfo_uarch_crestmont = 0x00100408, + /** Intel Darkmont microarchitecture (e-core used in Clearwater Forest). */ + cpuinfo_uarch_darkmont = 0x00100409, + + /** Intel Knights Ferry HPC boards. */ + cpuinfo_uarch_knights_ferry = 0x00100500, + /** Intel Knights Corner HPC boards (aka Xeon Phi). */ + cpuinfo_uarch_knights_corner = 0x00100501, + /** Intel Knights Landing microarchitecture (second-gen MIC). */ + cpuinfo_uarch_knights_landing = 0x00100502, + /** Intel Knights Hill microarchitecture (third-gen MIC). */ + cpuinfo_uarch_knights_hill = 0x00100503, + /** Intel Knights Mill Xeon Phi. */ + cpuinfo_uarch_knights_mill = 0x00100504, + + /** Intel/Marvell XScale series. */ + cpuinfo_uarch_xscale = 0x00100600, + + /** AMD K5. */ + cpuinfo_uarch_k5 = 0x00200100, + /** AMD K6 and alike. */ + cpuinfo_uarch_k6 = 0x00200101, + /** AMD Athlon and Duron. */ + cpuinfo_uarch_k7 = 0x00200102, + /** AMD Athlon 64, Opteron 64. */ + cpuinfo_uarch_k8 = 0x00200103, + /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */ + cpuinfo_uarch_k10 = 0x00200104, + /** + * AMD Bulldozer microarchitecture + * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs. + */ + cpuinfo_uarch_bulldozer = 0x00200105, + /** + * AMD Piledriver microarchitecture + * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu + * Dhabi Opteron CPUs. + */ + cpuinfo_uarch_piledriver = 0x00200106, + /** AMD Steamroller microarchitecture (Kaveri APUs). */ + cpuinfo_uarch_steamroller = 0x00200107, + /** AMD Excavator microarchitecture (Carizzo APUs). */ + cpuinfo_uarch_excavator = 0x00200108, + /** AMD Zen microarchitecture (12/14 nm Ryzen and EPYC CPUs). */ + cpuinfo_uarch_zen = 0x00200109, + /** AMD Zen 2 microarchitecture (7 nm Ryzen and EPYC CPUs). */ + cpuinfo_uarch_zen2 = 0x0020010A, + /** AMD Zen 3 microarchitecture. */ + cpuinfo_uarch_zen3 = 0x0020010B, + /** AMD Zen 4 microarchitecture. */ + cpuinfo_uarch_zen4 = 0x0020010C, + /** AMD Zen 5 microarchitecture. */ + cpuinfo_uarch_zen5 = 0x0020010D, + + /** NSC Geode and AMD Geode GX and LX. */ + cpuinfo_uarch_geode = 0x00200200, + /** AMD Bobcat mobile microarchitecture. */ + cpuinfo_uarch_bobcat = 0x00200201, + /** AMD Jaguar mobile microarchitecture. */ + cpuinfo_uarch_jaguar = 0x00200202, + /** AMD Puma mobile microarchitecture. */ + cpuinfo_uarch_puma = 0x00200203, + + /** ARM7 series. */ + cpuinfo_uarch_arm7 = 0x00300100, + /** ARM9 series. */ + cpuinfo_uarch_arm9 = 0x00300101, + /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */ + cpuinfo_uarch_arm11 = 0x00300102, + + /** ARM Cortex-A5. */ + cpuinfo_uarch_cortex_a5 = 0x00300205, + /** ARM Cortex-A7. */ + cpuinfo_uarch_cortex_a7 = 0x00300207, + /** ARM Cortex-A8. */ + cpuinfo_uarch_cortex_a8 = 0x00300208, + /** ARM Cortex-A9. */ + cpuinfo_uarch_cortex_a9 = 0x00300209, + /** ARM Cortex-A12. */ + cpuinfo_uarch_cortex_a12 = 0x00300212, + /** ARM Cortex-A15. */ + cpuinfo_uarch_cortex_a15 = 0x00300215, + /** ARM Cortex-A17. */ + cpuinfo_uarch_cortex_a17 = 0x00300217, + + /** ARM Cortex-A32. */ + cpuinfo_uarch_cortex_a32 = 0x00300332, + /** ARM Cortex-A35. */ + cpuinfo_uarch_cortex_a35 = 0x00300335, + /** ARM Cortex-A53. */ + cpuinfo_uarch_cortex_a53 = 0x00300353, + /** ARM Cortex-A55 revision 0 (restricted dual-issue capabilities + compared to revision 1+). */ + cpuinfo_uarch_cortex_a55r0 = 0x00300354, + /** ARM Cortex-A55. */ + cpuinfo_uarch_cortex_a55 = 0x00300355, + /** ARM Cortex-A57. */ + cpuinfo_uarch_cortex_a57 = 0x00300357, + /** ARM Cortex-A65. */ + cpuinfo_uarch_cortex_a65 = 0x00300365, + /** ARM Cortex-A72. */ + cpuinfo_uarch_cortex_a72 = 0x00300372, + /** ARM Cortex-A73. */ + cpuinfo_uarch_cortex_a73 = 0x00300373, + /** ARM Cortex-A75. */ + cpuinfo_uarch_cortex_a75 = 0x00300375, + /** ARM Cortex-A76. */ + cpuinfo_uarch_cortex_a76 = 0x00300376, + /** ARM Cortex-A77. */ + cpuinfo_uarch_cortex_a77 = 0x00300377, + /** ARM Cortex-A78. */ + cpuinfo_uarch_cortex_a78 = 0x00300378, + + /** ARM Neoverse N1. */ + cpuinfo_uarch_neoverse_n1 = 0x00300400, + /** ARM Neoverse E1. */ + cpuinfo_uarch_neoverse_e1 = 0x00300401, + /** ARM Neoverse V1. */ + cpuinfo_uarch_neoverse_v1 = 0x00300402, + /** ARM Neoverse N2. */ + cpuinfo_uarch_neoverse_n2 = 0x00300403, + /** ARM Neoverse V2. */ + cpuinfo_uarch_neoverse_v2 = 0x00300404, + + /** ARM Cortex-X1. */ + cpuinfo_uarch_cortex_x1 = 0x00300501, + /** ARM Cortex-X2. */ + cpuinfo_uarch_cortex_x2 = 0x00300502, + /** ARM Cortex-X3. */ + cpuinfo_uarch_cortex_x3 = 0x00300503, + /** ARM Cortex-X4. */ + cpuinfo_uarch_cortex_x4 = 0x00300504, + + /** ARM Cortex-A510. */ + cpuinfo_uarch_cortex_a510 = 0x00300551, + /** ARM Cortex-A520. */ + cpuinfo_uarch_cortex_a520 = 0x00300552, + /** ARM Cortex-A710. */ + cpuinfo_uarch_cortex_a710 = 0x00300571, + /** ARM Cortex-A715. */ + cpuinfo_uarch_cortex_a715 = 0x00300572, + /** ARM Cortex-A720. */ + cpuinfo_uarch_cortex_a720 = 0x00300573, + + /** Qualcomm Scorpion. */ + cpuinfo_uarch_scorpion = 0x00400100, + /** Qualcomm Krait. */ + cpuinfo_uarch_krait = 0x00400101, + /** Qualcomm Kryo. */ + cpuinfo_uarch_kryo = 0x00400102, + /** Qualcomm Falkor. */ + cpuinfo_uarch_falkor = 0x00400103, + /** Qualcomm Saphira. */ + cpuinfo_uarch_saphira = 0x00400104, + /** Qualcomm Oryon. */ + cpuinfo_uarch_oryon = 0x00400105, + + /** Nvidia Denver. */ + cpuinfo_uarch_denver = 0x00500100, + /** Nvidia Denver 2. */ + cpuinfo_uarch_denver2 = 0x00500101, + /** Nvidia Carmel. */ + cpuinfo_uarch_carmel = 0x00500102, + + /** Samsung Exynos M1 (Exynos 8890 big cores). */ + cpuinfo_uarch_exynos_m1 = 0x00600100, + /** Samsung Exynos M2 (Exynos 8895 big cores). */ + cpuinfo_uarch_exynos_m2 = 0x00600101, + /** Samsung Exynos M3 (Exynos 9810 big cores). */ + cpuinfo_uarch_exynos_m3 = 0x00600102, + /** Samsung Exynos M4 (Exynos 9820 big cores). */ + cpuinfo_uarch_exynos_m4 = 0x00600103, + /** Samsung Exynos M5 (Exynos 9830 big cores). */ + cpuinfo_uarch_exynos_m5 = 0x00600104, + + /* Deprecated synonym for Cortex-A76 */ + cpuinfo_uarch_cortex_a76ae = 0x00300376, + /* Deprecated names for Exynos. */ + cpuinfo_uarch_mongoose_m1 = 0x00600100, + cpuinfo_uarch_mongoose_m2 = 0x00600101, + cpuinfo_uarch_meerkat_m3 = 0x00600102, + cpuinfo_uarch_meerkat_m4 = 0x00600103, + + /** Apple A6 and A6X processors. */ + cpuinfo_uarch_swift = 0x00700100, + /** Apple A7 processor. */ + cpuinfo_uarch_cyclone = 0x00700101, + /** Apple A8 and A8X processor. */ + cpuinfo_uarch_typhoon = 0x00700102, + /** Apple A9 and A9X processor. */ + cpuinfo_uarch_twister = 0x00700103, + /** Apple A10 and A10X processor. */ + cpuinfo_uarch_hurricane = 0x00700104, + /** Apple A11 processor (big cores). */ + cpuinfo_uarch_monsoon = 0x00700105, + /** Apple A11 processor (little cores). */ + cpuinfo_uarch_mistral = 0x00700106, + /** Apple A12 processor (big cores). */ + cpuinfo_uarch_vortex = 0x00700107, + /** Apple A12 processor (little cores). */ + cpuinfo_uarch_tempest = 0x00700108, + /** Apple A13 processor (big cores). */ + cpuinfo_uarch_lightning = 0x00700109, + /** Apple A13 processor (little cores). */ + cpuinfo_uarch_thunder = 0x0070010A, + /** Apple A14 / M1 processor (big cores). */ + cpuinfo_uarch_firestorm = 0x0070010B, + /** Apple A14 / M1 processor (little cores). */ + cpuinfo_uarch_icestorm = 0x0070010C, + /** Apple A15 / M2 processor (big cores). */ + cpuinfo_uarch_avalanche = 0x0070010D, + /** Apple A15 / M2 processor (little cores). */ + cpuinfo_uarch_blizzard = 0x0070010E, + /** Apple A16 processor (big cores). */ + cpuinfo_uarch_everest = 0x00700200, + /** Apple A16 processor (little cores). */ + cpuinfo_uarch_sawtooth = 0x00700201, + /** Apple A17 processor (big cores). */ + cpuinfo_uarch_coll_everest = 0x00700202, + /** Apple A17 processor (little cores). */ + cpuinfo_uarch_coll_sawtooth = 0x00700203, + /** Apple A18 processor (big cores). */ + cpuinfo_uarch_tupai_everest = 0x00700204, + /** Apple A18 processor (little cores). */ + cpuinfo_uarch_tupai_sawtooth = 0x00700205, + /** Apple A18 pro processor (big cores). */ + cpuinfo_uarch_tahiti_everest = 0x00700206, + /** Apple A18 pro processor (little cores). */ + cpuinfo_uarch_tahiti_sawtooth = 0x00700207, + + /** Cavium ThunderX. */ + cpuinfo_uarch_thunderx = 0x00800100, + /** Cavium ThunderX2 (originally Broadcom Vulkan). */ + cpuinfo_uarch_thunderx2 = 0x00800200, + + /** Marvell PJ4. */ + cpuinfo_uarch_pj4 = 0x00900100, + + /** Broadcom Brahma B15. */ + cpuinfo_uarch_brahma_b15 = 0x00A00100, + /** Broadcom Brahma B53. */ + cpuinfo_uarch_brahma_b53 = 0x00A00101, + + /** Applied Micro X-Gene. */ + cpuinfo_uarch_xgene = 0x00B00100, + + /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */ + cpuinfo_uarch_dhyana = 0x01000100, + + /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */ + cpuinfo_uarch_taishan_v110 = 0x00C00100, +}; + +struct cpuinfo_processor { + /** SMT (hyperthread) ID within a core */ + uint32_t smt_id; + /** Core containing this logical processor */ + const struct cpuinfo_core *core; + /** Cluster of cores containing this logical processor */ + const struct cpuinfo_cluster *cluster; + /** Physical package containing this logical processor */ + const struct cpuinfo_package *package; +#if defined(__linux__) + /** + * Linux-specific ID for the logical processor: + * - Linux kernel exposes information about this logical processor in + * /sys/devices/system/cpu/cpu/ + * - Bit in the cpu_set_t identifies this logical processor + */ + int linux_id; +#endif +#if defined(_WIN32) || defined(__CYGWIN__) + /** Windows-specific ID for the group containing the logical processor. + */ + uint16_t windows_group_id; + /** + * Windows-specific ID of the logical processor within its group: + * - Bit in the KAFFINITY mask identifies this + * logical processor within its group. + */ + uint16_t windows_processor_id; +#endif +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + /** APIC ID (unique x86-specific ID of the logical processor) */ + uint32_t apic_id; +#endif + struct { + /** Level 1 instruction cache */ + const struct cpuinfo_cache *l1i; + /** Level 1 data cache */ + const struct cpuinfo_cache *l1d; + /** Level 2 unified or data cache */ + const struct cpuinfo_cache *l2; + /** Level 3 unified or data cache */ + const struct cpuinfo_cache *l3; + /** Level 4 unified or data cache */ + const struct cpuinfo_cache *l4; + } cache; +}; + +struct cpuinfo_core { + /** Index of the first logical processor on this core. */ + uint32_t processor_start; + /** Number of logical processors on this core */ + uint32_t processor_count; + /** Core ID within a package */ + uint32_t core_id; + /** Cluster containing this core */ + const struct cpuinfo_cluster *cluster; + /** Physical package containing this core. */ + const struct cpuinfo_package *package; + /** Vendor of the CPU microarchitecture for this core */ + enum cpuinfo_vendor vendor; + /** CPU microarchitecture for this core */ + enum cpuinfo_uarch uarch; +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + /** Value of CPUID leaf 1 EAX register for this core */ + uint32_t cpuid; +#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + /** Value of Main ID Register (MIDR) for this core */ + uint32_t midr; +#endif + /** Clock rate (non-Turbo) of the core, in Hz */ + uint64_t frequency; +}; + +struct cpuinfo_cluster { + /** Index of the first logical processor in the cluster */ + uint32_t processor_start; + /** Number of logical processors in the cluster */ + uint32_t processor_count; + /** Index of the first core in the cluster */ + uint32_t core_start; + /** Number of cores on the cluster */ + uint32_t core_count; + /** Cluster ID within a package */ + uint32_t cluster_id; + /** Physical package containing the cluster */ + const struct cpuinfo_package *package; + /** CPU microarchitecture vendor of the cores in the cluster */ + enum cpuinfo_vendor vendor; + /** CPU microarchitecture of the cores in the cluster */ + enum cpuinfo_uarch uarch; +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + /** Value of CPUID leaf 1 EAX register of the cores in the cluster */ + uint32_t cpuid; +#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + /** Value of Main ID Register (MIDR) of the cores in the cluster */ + uint32_t midr; +#endif + /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */ + uint64_t frequency; +}; + +#define CPUINFO_PACKAGE_NAME_MAX 48 + +struct cpuinfo_package { + /** SoC or processor chip model name */ + char name[CPUINFO_PACKAGE_NAME_MAX]; + /** Index of the first logical processor on this physical package */ + uint32_t processor_start; + /** Number of logical processors on this physical package */ + uint32_t processor_count; + /** Index of the first core on this physical package */ + uint32_t core_start; + /** Number of cores on this physical package */ + uint32_t core_count; + /** Index of the first cluster of cores on this physical package */ + uint32_t cluster_start; + /** Number of clusters of cores on this physical package */ + uint32_t cluster_count; +}; + +struct cpuinfo_uarch_info { + /** Type of CPU microarchitecture */ + enum cpuinfo_uarch uarch; +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + /** Value of CPUID leaf 1 EAX register for the microarchitecture */ + uint32_t cpuid; +#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + /** Value of Main ID Register (MIDR) for the microarchitecture */ + uint32_t midr; +#endif + /** Number of logical processors with the microarchitecture */ + uint32_t processor_count; + /** Number of cores with the microarchitecture */ + uint32_t core_count; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +bool CPUINFO_ABI cpuinfo_initialize(void); + +void CPUINFO_ABI cpuinfo_deinitialize(void); + +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 +/* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions + * instead. */ +struct cpuinfo_x86_isa { +#if CPUINFO_ARCH_X86 + bool rdtsc; +#endif + bool rdtscp; + bool rdpid; + bool sysenter; +#if CPUINFO_ARCH_X86 + bool syscall; +#endif + bool msr; + bool clzero; + bool clflush; + bool clflushopt; + bool mwait; + bool mwaitx; +#if CPUINFO_ARCH_X86 + bool emmx; +#endif + bool fxsave; + bool xsave; +#if CPUINFO_ARCH_X86 + bool fpu; + bool mmx; + bool mmx_plus; +#endif + bool three_d_now; + bool three_d_now_plus; +#if CPUINFO_ARCH_X86 + bool three_d_now_geode; +#endif + bool prefetch; + bool prefetchw; + bool prefetchwt1; +#if CPUINFO_ARCH_X86 + bool daz; + bool sse; + bool sse2; +#endif + bool sse3; + bool ssse3; + bool sse4_1; + bool sse4_2; + bool sse4a; + bool misaligned_sse; + bool avx; + bool avxvnni; + bool fma3; + bool fma4; + bool xop; + bool f16c; + bool avx2; + bool avx512f; + bool avx512pf; + bool avx512er; + bool avx512cd; + bool avx512dq; + bool avx512bw; + bool avx512vl; + bool avx512ifma; + bool avx512vbmi; + bool avx512vbmi2; + bool avx512bitalg; + bool avx512vpopcntdq; + bool avx512vnni; + bool avx512bf16; + bool avx512fp16; + bool avx512vp2intersect; + bool avx512_4vnniw; + bool avx512_4fmaps; + bool avx10_1; + bool avx10_2; + bool amx_bf16; + bool amx_tile; + bool amx_int8; + bool amx_fp16; + bool avx_vnni_int8; + bool avx_vnni_int16; + bool avx_ne_convert; + bool hle; + bool rtm; + bool xtest; + bool mpx; +#if CPUINFO_ARCH_X86 + bool cmov; + bool cmpxchg8b; +#endif + bool cmpxchg16b; + bool clwb; + bool movbe; +#if CPUINFO_ARCH_X86_64 + bool lahf_sahf; +#endif + bool fs_gs_base; + bool lzcnt; + bool popcnt; + bool tbm; + bool bmi; + bool bmi2; + bool adx; + bool aes; + bool vaes; + bool pclmulqdq; + bool vpclmulqdq; + bool gfni; + bool rdrand; + bool rdseed; + bool sha; + bool rng; + bool ace; + bool ace2; + bool phe; + bool pmm; + bool lwp; +}; + +extern struct cpuinfo_x86_isa cpuinfo_isa; +#endif + +static inline bool cpuinfo_has_x86_rdtsc(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.rdtsc; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_rdtscp(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.rdtscp; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_rdpid(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.rdpid; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_clzero(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.clzero; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_mwait(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.mwait; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_mwaitx(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.mwaitx; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_fxsave(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.fxsave; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_xsave(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.xsave; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_fpu(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.fpu; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_mmx(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.mmx; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_mmx_plus(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.mmx_plus; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_3dnow(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.three_d_now; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_3dnow_plus(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.three_d_now_plus; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_3dnow_geode(void) { +#if CPUINFO_ARCH_X86_64 + return false; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return false; +#else + return cpuinfo_isa.three_d_now_geode; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_prefetch(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.prefetch; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_prefetchw(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.prefetchw; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_prefetchwt1(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.prefetchwt1; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_daz(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.daz; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.sse; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse2(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.sse2; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse3(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.sse3; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_ssse3(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.ssse3; +#endif +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse4_1(void) { +#if CPUINFO_ARCH_X86_64 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.sse4_1; +#endif +#elif CPUINFO_ARCH_X86 + return cpuinfo_isa.sse4_1; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse4_2(void) { +#if CPUINFO_ARCH_X86_64 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.sse4_2; +#endif +#elif CPUINFO_ARCH_X86 + return cpuinfo_isa.sse4_2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sse4a(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.sse4a; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_misaligned_sse(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.misaligned_sse; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avxvnni(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avxvnni; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_fma3(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.fma3; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_fma4(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.fma4; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_xop(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.xop; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_f16c(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.f16c; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx2(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512f(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512f; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512pf(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512pf; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512er(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512er; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512cd(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512cd; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512dq(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512dq; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512bw(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512bw; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vl(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vl; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512ifma(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512ifma; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vbmi(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vbmi; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vbmi2(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vbmi2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512bitalg(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512bitalg; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vpopcntdq; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vnni(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vnni; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512bf16(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512bf16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512fp16(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512fp16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512vp2intersect(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512vp2intersect; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512_4vnniw(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512_4vnniw; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx512_4fmaps(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx512_4fmaps; +#else + return false; +#endif +} + +/* [NOTE] Intel Advanced Matrix Extensions (AMX) detection + * + * I. AMX is a new extensions to the x86 ISA to work on matrices, consists of + * 1) 2-dimentional registers (tiles), hold sub-matrices from larger matrices + * in memory 2) Accelerator called Tile Matrix Multiply (TMUL), contains + * instructions operating on tiles + * + * II. Platforms that supports AMX: + * +-----------------+-----+----------+----------+----------+----------+ + * | Platforms | Gen | amx-bf16 | amx-tile | amx-int8 | amx-fp16 | + * +-----------------+-----+----------+----------+----------+----------+ + * | Sapphire Rapids | 4th | YES | YES | YES | NO | + * +-----------------+-----+----------+----------+----------+----------+ + * | Emerald Rapids | 5th | YES | YES | YES | NO | + * +-----------------+-----+----------+----------+----------+----------+ + * | Granite Rapids | 6th | YES | YES | YES | YES | + * +-----------------+-----+----------+----------+----------+----------+ + * + * Reference: https://www.intel.com/content/www/us/en/products/docs + * /accelerator-engines/advanced-matrix-extensions/overview.html + */ +static inline bool cpuinfo_has_x86_amx_bf16(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.amx_bf16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_amx_tile(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.amx_tile; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_amx_int8(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.amx_int8; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_amx_fp16(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.amx_fp16; +#else + return false; +#endif +} + +/* + * Intel AVX Vector Neural Network Instructions (VNNI) INT8 + * Supported Platfroms: Sierra Forest, Arrow Lake, Lunar Lake + */ +static inline bool cpuinfo_has_x86_avx_vnni_int8(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx_vnni_int8; +#else + return false; +#endif +} + +/* + * Intel AVX Vector Neural Network Instructions (VNNI) INT16 + * Supported Platfroms: Arrow Lake, Lunar Lake + */ +static inline bool cpuinfo_has_x86_avx_vnni_int16(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx_vnni_int16; +#else + return false; +#endif +} + +/* + * A new set of instructions, which can convert low precision floating point + * like BF16/FP16 to high precision floating point FP32, as well as convert FP32 + * elements to BF16. This instruction allows the platform to have improved AI + * capabilities and better compatibility. + * + * Supported Platforms: Sierra Forest, Arrow Lake, Lunar Lake + */ +static inline bool cpuinfo_has_x86_avx_ne_convert(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx_ne_convert; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx10_1(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx10_1; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_avx10_2(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.avx10_2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_hle(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.hle; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_rtm(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.rtm; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_xtest(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.xtest; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_mpx(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.mpx; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_cmov(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 + return cpuinfo_isa.cmov; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_cmpxchg8b(void) { +#if CPUINFO_ARCH_X86_64 + return true; +#elif CPUINFO_ARCH_X86 + return cpuinfo_isa.cmpxchg8b; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_cmpxchg16b(void) { +#if CPUINFO_ARCH_X86_64 + return cpuinfo_isa.cmpxchg16b; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_clwb(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.clwb; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_movbe(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.movbe; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_lahf_sahf(void) { +#if CPUINFO_ARCH_X86 + return true; +#elif CPUINFO_ARCH_X86_64 + return cpuinfo_isa.lahf_sahf; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_lzcnt(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.lzcnt; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_popcnt(void) { +#if CPUINFO_ARCH_X86_64 +#if defined(__ANDROID__) + return true; +#else + return cpuinfo_isa.popcnt; +#endif +#elif CPUINFO_ARCH_X86 + return cpuinfo_isa.popcnt; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_tbm(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.tbm; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_bmi(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.bmi; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_bmi2(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.bmi2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_adx(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.adx; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_aes(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.aes; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_vaes(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.vaes; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_pclmulqdq(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.pclmulqdq; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_vpclmulqdq(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.vpclmulqdq; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_gfni(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.gfni; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_rdrand(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.rdrand; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_rdseed(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.rdseed; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_x86_sha(void) { +#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 + return cpuinfo_isa.sha; +#else + return false; +#endif +} + +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 +/* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions + * instead. */ +struct cpuinfo_arm_isa { +#if CPUINFO_ARCH_ARM + bool thumb; + bool thumb2; + bool thumbee; + bool jazelle; + bool armv5e; + bool armv6; + bool armv6k; + bool armv7; + bool armv7mp; + bool armv8; + bool idiv; + + bool vfpv2; + bool vfpv3; + bool d32; + bool fp16; + bool fma; + + bool wmmx; + bool wmmx2; + bool neon; +#endif +#if CPUINFO_ARCH_ARM64 + bool atomics; + bool bf16; + bool sve; + bool sve2; + bool i8mm; + bool sme; + bool sme2; + bool sme2p1; + bool sme_i16i32; + bool sme_bi32i32; + bool sme_b16b16; + bool sme_f16f16; + uint32_t svelen; + uint32_t smelen; +#endif + bool rdm; + bool fp16arith; + bool dot; + bool jscvt; + bool fcma; + bool fhm; + + bool aes; + bool sha1; + bool sha2; + bool pmull; + bool crc32; +}; + +extern struct cpuinfo_arm_isa cpuinfo_isa; +#endif + +static inline bool cpuinfo_has_arm_thumb(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.thumb; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_thumb2(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.thumb2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v5e(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.armv5e; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v6(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.armv6; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v6k(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.armv6k; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v7(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.armv7; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v7mp(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.armv7mp; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_v8(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.armv8; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_idiv(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.idiv; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv2(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv3(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv3_d32(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv3_fp16(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv4(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_vfpv4_d32(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_fp16_arith(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.fp16arith; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_bf16(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.bf16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_wmmx(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.wmmx; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_wmmx2(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.wmmx2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.neon; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_fp16(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.neon && cpuinfo_isa.fp16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_fma(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.neon && cpuinfo_isa.fma; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_v8(void) { +#if CPUINFO_ARCH_ARM64 + return true; +#elif CPUINFO_ARCH_ARM + return cpuinfo_isa.neon && cpuinfo_isa.armv8; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_atomics(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.atomics; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_rdm(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.rdm; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_fp16_arith(void) { +#if CPUINFO_ARCH_ARM + return cpuinfo_isa.neon && cpuinfo_isa.fp16arith; +#elif CPUINFO_ARCH_ARM64 + return cpuinfo_isa.fp16arith; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_fhm(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.fhm; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_dot(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.dot; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_neon_bf16(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.bf16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_jscvt(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.jscvt; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_fcma(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.fcma; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_i8mm(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.i8mm; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_aes(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.aes; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sha1(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sha1; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sha2(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sha2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_pmull(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.pmull; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_crc32(void) { +#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 + return cpuinfo_isa.crc32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sve(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sve; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sve_bf16(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sve && cpuinfo_isa.bf16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sve2(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sve2; +#else + return false; +#endif +} + +// Function to get the max SVE vector length on ARM CPU's which support SVE. +static inline uint32_t cpuinfo_get_max_arm_sve_length(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.svelen * 8; // bytes * 8 = bit length(vector length) +#else + return 0; +#endif +} + +// Function to get the max SME vector length on ARM CPU's which support SME. +static inline uint32_t cpuinfo_get_max_arm_sme_length(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.smelen * 8; // bytes * 8 = bit length(vector length) +#else + return 0; +#endif +} + +static inline bool cpuinfo_has_arm_sme(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme2(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme2; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme2p1(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme2p1; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme_i16i32(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme_i16i32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme_bi32i32(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme_bi32i32; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme_b16b16(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme_b16b16; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_arm_sme_f16f16(void) { +#if CPUINFO_ARCH_ARM64 + return cpuinfo_isa.sme_f16f16; +#else + return false; +#endif +} + +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 +/* This structure is not a part of stable API. Use cpuinfo_has_riscv_* functions + * instead. */ +struct cpuinfo_riscv_isa { + /** + * Keep fields in line with the canonical order as defined by + * Section 27.11 Subset Naming Convention. + */ + /* RV32I/64I/128I Base ISA. */ + bool i; +#if CPUINFO_ARCH_RISCV32 + /* RV32E Base ISA. */ + bool e; +#endif + /* Integer Multiply/Divide Extension. */ + bool m; + /* Atomic Extension. */ + bool a; + /* Single-Precision Floating-Point Extension. */ + bool f; + /* Double-Precision Floating-Point Extension. */ + bool d; + /* Compressed Extension. */ + bool c; + /* Vector Extension. */ + bool v; +}; + +extern struct cpuinfo_riscv_isa cpuinfo_isa; +#endif + +static inline bool cpuinfo_has_riscv_i(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.i; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_e(void) { +#if CPUINFO_ARCH_RISCV32 + return cpuinfo_isa.e; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_m(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.m; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_a(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.a; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_f(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.f; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_d(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.d; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_g(void) { + // The 'G' extension is simply shorthand for 'IMAFD'. + return cpuinfo_has_riscv_i() && cpuinfo_has_riscv_m() && + cpuinfo_has_riscv_a() && cpuinfo_has_riscv_f() && + cpuinfo_has_riscv_d(); +} + +static inline bool cpuinfo_has_riscv_c(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.c; +#else + return false; +#endif +} + +static inline bool cpuinfo_has_riscv_v(void) { +#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64 + return cpuinfo_isa.v; +#else + return false; +#endif +} + +const struct cpuinfo_processor *CPUINFO_ABI cpuinfo_get_processors(void); +const struct cpuinfo_core *CPUINFO_ABI cpuinfo_get_cores(void); +const struct cpuinfo_cluster *CPUINFO_ABI cpuinfo_get_clusters(void); +const struct cpuinfo_package *CPUINFO_ABI cpuinfo_get_packages(void); +const struct cpuinfo_uarch_info *CPUINFO_ABI cpuinfo_get_uarchs(void); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l1i_caches(void); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l1d_caches(void); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l2_caches(void); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l3_caches(void); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l4_caches(void); + +const struct cpuinfo_processor *CPUINFO_ABI +cpuinfo_get_processor(uint32_t index); +const struct cpuinfo_core *CPUINFO_ABI cpuinfo_get_core(uint32_t index); +const struct cpuinfo_cluster *CPUINFO_ABI cpuinfo_get_cluster(uint32_t index); +const struct cpuinfo_package *CPUINFO_ABI cpuinfo_get_package(uint32_t index); +const struct cpuinfo_uarch_info *CPUINFO_ABI cpuinfo_get_uarch(uint32_t index); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index); +const struct cpuinfo_cache *CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index); + +uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void); +uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void); + +/** + * Returns upper bound on cache size. + */ +uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void); + +/** + * Identify the logical processor that executes the current thread. + * + * There is no guarantee that the thread will stay on the same logical processor + * for any time. Callers should treat the result as only a hint, and be prepared + * to handle NULL return value. + */ +const struct cpuinfo_processor *CPUINFO_ABI cpuinfo_get_current_processor(void); + +/** + * Identify the core that executes the current thread. + * + * There is no guarantee that the thread will stay on the same core for any + * time. Callers should treat the result as only a hint, and be prepared to + * handle NULL return value. + */ +const struct cpuinfo_core *CPUINFO_ABI cpuinfo_get_current_core(void); + +/** + * Identify the microarchitecture index of the core that executes the current + * thread. If the system does not support such identification, the function + * returns 0. + * + * There is no guarantee that the thread will stay on the same type of core for + * any time. Callers should treat the result as only a hint. + */ +uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void); + +/** + * Identify the microarchitecture index of the core that executes the current + * thread. If the system does not support such identification, the function + * returns the user-specified default value. + * + * There is no guarantee that the thread will stay on the same type of core for + * any time. Callers should treat the result as only a hint. + */ +uint32_t CPUINFO_ABI +cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* CPUINFO_H */ diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorch.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorch.h deleted file mode 100644 index 3a12a5ddba..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorch.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchError.h" -#import "ExecuTorchLog.h" -#import "ExecuTorchModule.h" -#import "ExecuTorchTensor.h" -#import "ExecuTorchValue.h" diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchError.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchError.h deleted file mode 100644 index ea857d150b..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchError.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -FOUNDATION_EXPORT NSErrorDomain const - ExecuTorchErrorDomain NS_SWIFT_NAME(ErrorDomain); - -/** - * Enum to define the error codes. - * Values can be a subset, but must numerically match exactly those defined in - * runtime/core/error.h - */ -typedef NS_ERROR_ENUM(ExecuTorchErrorDomain, ExecuTorchErrorCode){ - // System errors. - ExecuTorchErrorCodeOk = 0, - ExecuTorchErrorCodeInternal = 1, - ExecuTorchErrorCodeInvalidState = 2, - ExecuTorchErrorCodeEndOfMethod = 3, - - // Logical errors. - ExecuTorchErrorCodeNotSupported = 16, - ExecuTorchErrorCodeNotImplemented = 17, - ExecuTorchErrorCodeInvalidArgument = 18, - ExecuTorchErrorCodeInvalidType = 19, - ExecuTorchErrorCodeOperatorMissing = 20, - - // Registration errors. - ExecuTorchErrorCodeRegistrationExceedingMaxKernels = 21, - ExecuTorchErrorCodeRegistrationAlreadyRegistered = 22, - - // Resource errors. - ExecuTorchErrorCodeNotFound = 32, - ExecuTorchErrorCodeMemoryAllocationFailed = 33, - ExecuTorchErrorCodeAccessFailed = 34, - ExecuTorchErrorCodeInvalidProgram = 35, - ExecuTorchErrorCodeInvalidExternalData = 36, - ExecuTorchErrorCodeOutOfResources = 37, - - // Delegate errors. - ExecuTorchErrorCodeDelegateInvalidCompatibility = 48, - ExecuTorchErrorCodeDelegateMemoryAllocationFailed = 49, - ExecuTorchErrorCodeDelegateInvalidHandle = 50, -} NS_SWIFT_NAME(ErrorCode); - -/** - * Returns a brief error description for the given error code. - * - * @param code An ExecuTorchErrorCode value representing the error code. - * @return An NSString containing the error description. - */ -FOUNDATION_EXPORT -NS_RETURNS_RETAINED -NSString *ExecuTorchErrorDescription(ExecuTorchErrorCode code) - NS_SWIFT_NAME(ErrorDescription(_:)); - -/** - * Create an NSError in the ExecuTorch domain for the given code. - * - * @param code The ExecuTorchErrorCode to wrap. - * @return An NSError with ExecuTorchErrorDomain, the specified code, and a - * localized description. - */ -FOUNDATION_EXPORT -NS_RETURNS_RETAINED -NSError *ExecuTorchErrorWithCode(ExecuTorchErrorCode code) - NS_SWIFT_NAME(Error(code:)); - -/** - * Create an NSError in the ExecuTorch domain for the given code. - * - * @param code The ExecuTorchErrorCode to wrap. - * @param description Additional error description. - * @return An NSError with ExecuTorchErrorDomain, the specified code, and a - * localized description. - */ -FOUNDATION_EXPORT -NS_RETURNS_RETAINED -NSError *ExecuTorchErrorWithCodeAndDescription(ExecuTorchErrorCode code, - NSString *__nullable description) - NS_SWIFT_NAME(Error(code:description:)); - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h deleted file mode 100644 index cef90617a1..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchLLMConfig.h" -#import "ExecuTorchLLMError.h" -#import "ExecuTorchLLMMultimodalRunner.h" -#import "ExecuTorchLLMTextRunner.h" diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h deleted file mode 100644 index 5ecc9a0f00..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - A configuration object for text generation. - - This class wraps the underlying C++ GenerationConfig so that default - values and future fields remain a single source of truth in C++. -*/ -NS_SWIFT_NAME(Config) -__attribute__((deprecated("This API is experimental."))) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLLMConfig : NSObject - -/** Whether to echo the input prompt in the output. */ -@property(nonatomic, getter=isEchoEnabled) BOOL echoEnabled; - -/** Maximum number of new tokens to generate. */ -@property(nonatomic) NSInteger maximumNewTokens; - -/** Whether this is a warmup run. */ -@property(nonatomic, getter=isWarming) BOOL warming; - -/** Maximum total sequence length. */ -@property(nonatomic) NSInteger sequenceLength; - -/** Temperature for sampling. */ -@property(nonatomic) double temperature; - -/** Number of BOS tokens to add. */ -@property(nonatomic) NSInteger bosCount; - -/** Number of EOS tokens to add. */ -@property(nonatomic) NSInteger eosCount; - -/** - Initializes a configuration and invokes the block to mutate it. - - @param block A block that receives the newly initialized configuration. - @return An initialized ExecuTorchLLMConfig instance. -*/ -- (instancetype)initWithBlock:(NS_NOESCAPE void (^)(ExecuTorchLLMConfig *))block - NS_SWIFT_NAME(init(_:)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h deleted file mode 100644 index 3363f901b4..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -FOUNDATION_EXPORT NSErrorDomain const - ExecuTorchLLMErrorDomain NS_SWIFT_NAME(ErrorDomain); - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h deleted file mode 100644 index 9e2ec5da26..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchLLMConfig.h" - -NS_ASSUME_NONNULL_BEGIN - -/** - Types of multimodal inputs supported by the ExecuTorch LLM APIs. - Must be in sync with the C++ enum in llm/runner/multimodal_input.h -*/ -typedef NS_ENUM(NSInteger, ExecuTorchLLMMultimodalInputType) { - ExecuTorchLLMMultimodalInputTypeText, - ExecuTorchLLMMultimodalInputTypeImage, - ExecuTorchLLMMultimodalInputTypeAudio, - ExecuTorchLLMMultimodalInputTypeUnsupported, -} NS_SWIFT_NAME(MultimodalInputType); - -/** - A container for image inputs used with multimodal generation APIs. -*/ -NS_SWIFT_NAME(Image) -__attribute__((deprecated("This API is experimental."))) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLLMImage : NSObject - -/** - Initializes an image container with the provided data and dimensions. - - @param data Raw image bytes. - @param width Image width in pixels. - @param height Image height in pixels. - @param channels Number of channels. - @return An initialized ExecuTorchLLMImage instance. -*/ -- (instancetype)initWithData:(NSData *)data - width:(NSInteger)width - height:(NSInteger)height - channels:(NSInteger)channels NS_DESIGNATED_INITIALIZER; - -- (instancetype)initWithFloatData:(NSData *)data - width:(NSInteger)width - height:(NSInteger)height - channels:(NSInteger)channels NS_DESIGNATED_INITIALIZER; - -@property(nonatomic, readonly) NSData *data; - -@property(nonatomic, readonly) NSInteger width; - -@property(nonatomic, readonly) NSInteger height; - -@property(nonatomic, readonly) NSInteger channels; - -@property(nonatomic, readonly) BOOL isFloat; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -/** - A container for pre-processed audio features. -*/ -NS_SWIFT_NAME(Audio) -__attribute__((deprecated("This API is experimental."))) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLLMAudio : NSObject - -/** - Initializes an audio features container with the provided data and shape. - - @param data Feature buffer. - @param batchSize Batch dimension size. - @param bins Number of frequency bins. - @param frames Number of time frames. - @return An initialized ExecuTorchLLMAudio instance. -*/ -- (instancetype)initWithData:(NSData *)data - batchSize:(NSInteger)batchSize - bins:(NSInteger)bins - frames:(NSInteger)frames NS_DESIGNATED_INITIALIZER; - -- (instancetype)initWithFloatData:(NSData *)data - batchSize:(NSInteger)batchSize - bins:(NSInteger)bins - frames:(NSInteger)frames NS_DESIGNATED_INITIALIZER; - -@property(nonatomic, readonly) NSData *data; - -@property(nonatomic, readonly) NSInteger batchSize; - -@property(nonatomic, readonly) NSInteger bins; - -@property(nonatomic, readonly) NSInteger frames; - -@property(nonatomic, readonly) BOOL isFloat; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -/** - A tagged container for a single multimodal input item used by - multimodal generation APIs. -*/ -NS_SWIFT_NAME(MultimodalInput) -__attribute__((deprecated("This API is experimental."))) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLLMMultimodalInput : NSObject - -/** - Creates a text input. - - @param text The UTF-8 text to provide as input. - @return A retained ExecuTorchLLMMultimodalInput instance of type Text. -*/ -+ (instancetype)inputWithText:(NSString *)text - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - Creates an image input. - - @param image The image payload to provide as input. - @return A retained ExecuTorchLLMMultimodalInput instance of type Image. -*/ -+ (instancetype)inputWithImage:(ExecuTorchLLMImage *)image - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - Creates an audio-features input. - - @param audio The pre-processed audio features to provide as input. - @return A retained ExecuTorchLLMMultimodalInput instance of type Audio. -*/ -+ (instancetype)inputWithAudio:(ExecuTorchLLMAudio *)audio - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -@property(nonatomic, readonly) ExecuTorchLLMMultimodalInputType type; - -@property(nonatomic, readonly, nullable) NSString *text; - -@property(nonatomic, readonly, nullable) ExecuTorchLLMImage *image; - -@property(nonatomic, readonly, nullable) ExecuTorchLLMAudio *audio; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -/** - A wrapper class for the C++ llm::MultimodalRunner that provides - Objective-C APIs to load models, manage tokenization, accept mixed - input modalities, generate text sequences, and stop the runner. -*/ -NS_SWIFT_NAME(MultimodalRunner) -__attribute__((deprecated("This API is experimental."))) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLLMMultimodalRunner : NSObject - -/** - Initializes a multimodal LLM runner with the given model and tokenizer paths. - - @param modelPath File system path to the serialized model. - @param tokenizerPath File system path to the tokenizer data. - @return An initialized ExecuTorchLLMMultimodalRunner instance. -*/ -- (instancetype)initWithModelPath:(NSString *)modelPath - tokenizerPath:(NSString *)tokenizerPath - NS_DESIGNATED_INITIALIZER; - -/** - Checks whether the underlying model has been successfully loaded. - - @return YES if the model is loaded, NO otherwise. -*/ -- (BOOL)isLoaded; - -/** - Loads the model into memory, returning an error if loading fails. - - @param error On failure, populated with an NSError explaining the issue. - @return YES if loading succeeds, NO if an error occurred. -*/ -- (BOOL)loadWithError:(NSError **)error; - -/** - Generates text given a list of multimodal inputs. A default configuration - is created and passed to the configuration block for in-place mutation. - - The token callback, if provided, is invoked for each generated token. - - @param inputs An ordered array of multimodal inputs. - @param config A configuration object. - @param callback A block called with each generated token as an NSString. - @param error On failure, populated with an NSError explaining the issue. - @return YES if generation completes successfully, NO if an error occurred. -*/ -- (BOOL)generateWithInputs:(NSArray *)inputs - config:(ExecuTorchLLMConfig *)config - tokenCallback:(nullable void (^)(NSString *))callback - error:(NSError **)error - NS_SWIFT_NAME(generate(_:_:tokenCallback:)); - -/** - Stop producing new tokens and terminate the current generation process. -*/ -- (void)stop; - -/** - Remove the prefilled tokens from the KV cache and reset the start position - to 0. It also clears the stats for previous runs. -*/ -- (void)reset; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h deleted file mode 100644 index 6b1159fd54..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchLLMConfig.h" - -NS_ASSUME_NONNULL_BEGIN - -/** - A wrapper class for the C++ llm::TextLLMRunner that provides - Objective-C APIs to load models, manage tokenization with custom - special tokens, generate text sequences, and stop the runner. -*/ -NS_SWIFT_NAME(TextRunner) -__attribute__((deprecated("This API is experimental."))) -@interface ExecuTorchLLMTextRunner : NSObject - -/** - Initializes a text LLM runner with the given model and tokenizer paths, - and a list of special tokens to include in the tokenizer. - - @param modelPath File system path to the serialized model. - @param tokenizerPath File system path to the tokenizer data. - @return An initialized ExecuTorchLLMTextRunner instance. -*/ -- (instancetype)initWithModelPath:(NSString *)modelPath - tokenizerPath:(NSString *)tokenizerPath; - -/** - Initializes a text LLM runner with the given model and tokenizer paths, - and a list of special tokens to include in the tokenizer. - - @param modelPath File system path to the serialized model. - @param tokenizerPath File system path to the tokenizer data. - @param specialTokens An array of NSString special tokens to use during - tokenization. - @return An initialized ExecuTorchLLMTextRunner instance. -*/ -- (instancetype)initWithModelPath:(NSString *)modelPath - tokenizerPath:(NSString *)tokenizerPath - specialTokens:(NSArray *)specialTokens - NS_DESIGNATED_INITIALIZER; - -/** - Checks whether the underlying model has been successfully loaded. - - @return YES if the model is loaded, NO otherwise. -*/ -- (BOOL)isLoaded; - -/** - Loads the model into memory, returning an error if loading fails. - - @param error On failure, populated with an NSError explaining the issue. - @return YES if loading succeeds, NO if an error occurred. -*/ -- (BOOL)loadWithError:(NSError **)error; - -/** - Generates text given an input prompt. A default configuration - is created and passed to the configuration block for in-place mutation. - - The token callback, if provided, is invoked for each generated token. - - @param prompt The initial text prompt to generate from. - @param config A configuration object. - @param callback A block called with each generated token as an NSString. - @param error On failure, populated with an NSError explaining the issue. - @return YES if generation completes successfully, NO if an error occurred. -*/ -- (BOOL)generateWithPrompt:(NSString *)prompt - config:(ExecuTorchLLMConfig *)config - tokenCallback:(nullable void (^)(NSString *token))callback - error:(NSError **)error - NS_SWIFT_NAME(generate(_:_:tokenCallback:)); - -/** - Stop producing new tokens and terminate the current generation process. -*/ -- (void)stop; - -/** - Remove the prefilled tokens from the KV cache and reset the start position - to 0. It also clears the stats for previous runs. -*/ -- (void)reset; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/module.modulemap b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/module.modulemap deleted file mode 100644 index 1d7a0e77aa..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLLM/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module ExecuTorchLLM { - umbrella header "ExecuTorchLLM.h" - export * -} diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLog.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLog.h deleted file mode 100644 index 17d9f33961..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchLog.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Defines log levels with specific character codes representing each level. - */ -typedef NS_ENUM(NSInteger, ExecuTorchLogLevel) { - ExecuTorchLogLevelDebug = 'D', - ExecuTorchLogLevelInfo = 'I', - ExecuTorchLogLevelError = 'E', - ExecuTorchLogLevelFatal = 'F', - ExecuTorchLogLevelUnknown = '?' -} NS_SWIFT_NAME(LogLevel); - -/** - * A protocol defining the requirements for a log sink to receive log messages. - */ -NS_SWIFT_NAME(LogSink) -@protocol ExecuTorchLogSink - -/** - * Logs a message with the specified additional info. - * - * @param level The log level of the message. - * @param timestamp The timestamp of the log message since ExecuTorch PAL start. - * @param filename The name of the file generating the log message. - * @param line The line number in the file where the log message was generated. - * @param message The log message text. - */ -- (void)logWithLevel:(ExecuTorchLogLevel)level - timestamp:(NSTimeInterval)timestamp - filename:(NSString *)filename - line:(NSUInteger)line - message:(NSString *)message - NS_SWIFT_NAME(log(level:timestamp:filename:line:message:)); - -@end - -/** - * A singleton class for managing log sinks and dispatching log messages. - */ -NS_SWIFT_NAME(Log) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchLog : NSObject - -/// The shared singleton log instance. -@property(class, readonly) ExecuTorchLog *sharedLog; - -/** - * Adds a log sink to receive log messages. - * - * @param sink The log sink to add. - */ -- (void)addSink:(id)sink NS_SWIFT_NAME(add(sink:)); - -/** - * Removes a previously added log sink. - * - * @param sink The log sink to remove. - */ -- (void)removeSink:(id)sink NS_SWIFT_NAME(remove(sink:)); - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchModule.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchModule.h deleted file mode 100644 index 823e5cf5cb..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchModule.h +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchValue.h" - -NS_ASSUME_NONNULL_BEGIN - -/** - * Holds the static metadata for a single tensor: its shape, layout, - * element type, whether its memory was pre-planned by the runtime, - * and its debug name. - */ -NS_SWIFT_NAME(TensorMetadata) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchTensorMetadata : NSObject - -/** The size of each dimension. */ -@property(nonatomic, readonly) NSArray *shape NS_REFINED_FOR_SWIFT; - -/** The order in which dimensions are laid out. */ -@property(nonatomic, readonly) - NSArray *dimensionOrder NS_REFINED_FOR_SWIFT; - -/** The scalar type of each element in the tensor. */ -@property(nonatomic, readonly) ExecuTorchDataType dataType; - -/** YES if the runtime pre-allocated memory for this tensor. */ -@property(nonatomic, readonly) BOOL isMemoryPlanned; - -/** The (optional) user-visible name of this tensor (may be empty) */ -@property(nonatomic, readonly) NSString *name; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -/** - * Encapsulates all of the metadata for a loaded method: its name, - * how many inputs/outputs/attributes it has, per-argument tags, - * per-tensor metadata, buffer sizes, backends, and instruction count. - */ -NS_SWIFT_NAME(MethodMetadata) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchMethodMetadata : NSObject - -/** The method’s name. */ -@property(nonatomic, readonly) NSString *name; - -/** An array of ExecuTorchValueTag raw values, one per declared input. */ -@property(nonatomic, readonly) - NSArray *inputValueTags NS_REFINED_FOR_SWIFT; - -/** An array of ExecuTorchValueTag raw values, one per declared output. */ -@property(nonatomic, readonly) - NSArray *outputValueTags NS_REFINED_FOR_SWIFT; - -/** - * Mapping from input-index to TensorMetadata. - * Only present for those indices whose tag == .tensor - */ -@property(nonatomic, readonly) - NSDictionary *inputTensorMetadata - NS_REFINED_FOR_SWIFT; - -/** - * Mapping from output-index to TensorMetadata. - * Only present for those indices whose tag == .tensor - */ -@property(nonatomic, readonly) - NSDictionary *outputTensorMetadata - NS_REFINED_FOR_SWIFT; - -/** A list of attribute TensorsMetadata. */ -@property(nonatomic, readonly) - NSArray *attributeTensorMetadata; - -/** A list of memory-planned buffer sizes. */ -@property(nonatomic, readonly) - NSArray *memoryPlannedBufferSizes NS_REFINED_FOR_SWIFT; - -/** Names of all backends this method can run on. */ -@property(nonatomic, readonly) NSArray *backendNames; - -/** Total number of low-level instructions in this method’s body. */ -@property(nonatomic, readonly) NSInteger instructionCount; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -/** - * Enum to define loading behavior. - * Values can be a subset, but must numerically match exactly those defined in - * extension/module/module.h - */ -typedef NS_ENUM(NSInteger, ExecuTorchModuleLoadMode) { - ExecuTorchModuleLoadModeFile = 0, - ExecuTorchModuleLoadModeMmap, - ExecuTorchModuleLoadModeMmapUseMlock, - ExecuTorchModuleLoadModeMmapUseMlockIgnoreErrors, -} NS_SWIFT_NAME(ModuleLoadMode); - -/** - * Enum to define the verification level used when loading a module. - * Values can be a subset, but must numerically match exactly those defined in - * runtime/executor/program.h - */ -typedef NS_ENUM(uint8_t, ExecuTorchVerification) { - ExecuTorchVerificationMinimal, - ExecuTorchVerificationInternalConsistency, -} NS_SWIFT_NAME(ModuleVerification); - -/** - * Represents a module that encapsulates an ExecuTorch program. - * This class is a facade for loading programs and executing methods within - * them. - */ -NS_SWIFT_NAME(Module) -@interface ExecuTorchModule : NSObject - -/** - * Initializes a module with a file path, data path and a specified load mode. - * - * @param filePath A string representing the path to the ExecuTorch program - * file. - * @param dataFilePaths A list of strings representing paths to .ptd files with - * external tensors and external data. - * @param loadMode A value from ExecuTorchModuleLoadMode that determines the - * file loading behavior. - * @return An initialized ExecuTorchModule instance. - */ -- (instancetype)initWithFilePath:(NSString *)filePath - dataFilePaths:(NSArray *)dataFilePaths - loadMode:(ExecuTorchModuleLoadMode)loadMode - NS_DESIGNATED_INITIALIZER; - -/** - * Initializes a module with a file path, data path and a specified load mode. - * - * @param filePath A string representing the path to the ExecuTorch program - * file. - * @param dataFilePaths A list of strings representing paths to .ptd files with - * external tensors and external data. - * @return An initialized ExecuTorchModule instance. - */ -- (instancetype)initWithFilePath:(NSString *)filePath - dataFilePaths:(NSArray *)dataFilePaths; - -/** - * Initializes a module with a file path and a specified load mode. - * - * @param filePath A string representing the path to the ExecuTorch program - * file. - * @param loadMode A value from ExecuTorchModuleLoadMode that determines the - * file loading behavior. - * @return An initialized ExecuTorchModule instance. - */ -- (instancetype)initWithFilePath:(NSString *)filePath - loadMode:(ExecuTorchModuleLoadMode)loadMode; - -/** - * Initializes a module with a file path using the default load mode (File - * mode). - * - * @param filePath A string representing the path to the ExecuTorch program - * file. - * @return An initialized ExecuTorchModule instance. - */ -- (instancetype)initWithFilePath:(NSString *)filePath; - -/** - * Loads the module’s program using the specified verification level. - * - * @param verification The verification level to apply when loading the program. - * @param error A pointer to an NSError pointer that will be set if an error - * occurs. - * @return YES if the program was successfully loaded; otherwise, NO. - */ -- (BOOL)loadWithVerification:(ExecuTorchVerification)verification - error:(NSError **)error; - -/** - * Loads the module’s program using minimal verification. - * - * This is a convenience overload that defaults the verification level to - * Minimal. - * - * @param error A pointer to an NSError pointer that will be set if an error - * occurs. - * @return YES if the program was successfully loaded; otherwise, NO. - */ -- (BOOL)load:(NSError **)error; - -/** - * Checks if the module is loaded. - * - * @return YES if the module's program is loaded; otherwise, NO. - */ -- (BOOL)isLoaded; - -/** - * Loads a specific method from the program. - * - * @param methodName A string representing the name of the method to load. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return YES if the method was successfully loaded; otherwise, NO. - */ -- (BOOL)loadMethod:(NSString *)methodName - error:(NSError **)error NS_SWIFT_NAME(load(_:)); - -/** - * Checks if a specific method is loaded. - * - * @param methodName A string representing the method name. - * @return YES if the method is loaded; otherwise, NO. - */ -- (BOOL)isMethodLoaded:(NSString *)methodName NS_SWIFT_NAME(isLoaded(_:)); - -/** - * Unloads a method and releases its native resources and planned buffers. - * - * @param methodName The method to unload. - * @return YES if the method was unloaded; NO if it was not loaded at all. - */ -- (BOOL)unloadMethod:(NSString *)methodName NS_SWIFT_NAME(unload(_:)); - -/** - * Retrieves the set of method names available in the loaded program. - * - * The method names are returned as an unordered set of strings. The program and - * methods are loaded as needed. - * - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An unordered set of method names, or nil in case of an error. - */ -- (nullable NSSet *)methodNames:(NSError **)error - NS_RETURNS_RETAINED; - -/** - * Retrieves full metadata for a particular method in the loaded module. - * - * This includes the method’s name, input/output value tags, tensor shapes - * and layouts, buffer sizes, backend support list, and instruction count. - * - * @param methodName A string representing the method name. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An ExecuTorchMethodMetadata object on success, or nil if the method - * isn’t found or a load error occurred. - */ -- (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName - error:(NSError **)error - NS_RETURNS_RETAINED; - -/** - * Executes a specific method with the provided input values. - * - * The method is loaded on demand if not already loaded. - * - * @param methodName A string representing the method name. - * @param values An NSArray of ExecuTorchValue objects representing the inputs. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *) - executeMethod:(NSString *)methodName - withInputs:(NSArray *)values - error:(NSError **)error NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Executes a specific method with the provided single input value. - * - * The method is loaded on demand if not already loaded. - * - * @param methodName A string representing the method name. - * @param value An ExecuTorchValue object representing the input. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)executeMethod:(NSString *)methodName - withInput:(ExecuTorchValue *)value - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes a specific method with no input values. - * - * The method is loaded on demand if not already loaded. - * - * @param methodName A string representing the method name. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)executeMethod:(NSString *)methodName - error:(NSError **)error - NS_SWIFT_NAME(execute(_:)) NS_RETURNS_RETAINED; - -/** - * Executes a specific method with the provided input tensors. - * - * The method is loaded on demand if not already loaded. - * - * @param methodName A string representing the method name. - * @param tensors An NSArray of ExecuTorchTensor objects representing the - * inputs. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *) - executeMethod:(NSString *)methodName - withTensors:(NSArray *)tensors - error:(NSError **)error NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes a specific method with the provided single input tensor. - * - * The method is loaded on demand if not already loaded. - * - * @param methodName A string representing the method name. - * @param tensor An ExecuTorchTensor object representing the input. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)executeMethod:(NSString *)methodName - withTensor: - (ExecuTorchTensor *)tensor - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes the "forward" method with the provided input values. - * - * This is a convenience method that calls the executeMethod with "forward" as - * the method name. - * - * @param values An NSArray of ExecuTorchValue objects representing the inputs. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *) - forwardWithInputs:(NSArray *)values - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes the "forward" method with the provided single input value. - * - * This is a convenience method that calls the executeMethod with "forward" as - * the method name. - * - * @param value An ExecuTorchValue object representing the input. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)forwardWithInput: - (ExecuTorchValue *)value - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes the "forward" method with no inputs. - * - * This is a convenience method that calls the executeMethod with "forward" as - * the method name. - * - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)forward:(NSError **)error - NS_RETURNS_RETAINED; - -/** - * Executes the "forward" method with the provided input tensors. - * - * This is a convenience method that calls the executeMethod with "forward" as - * the method name. - * - * @param tensors An NSArray of ExecuTorchTensor objects representing the - * inputs. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *) - forwardWithTensors:(NSArray *)tensors - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Executes the "forward" method with the provided single input tensor. - * - * This is a convenience method that calls the executeMethod with "forward" as - * the method name. - * - * @param tensor An ExecuTorchTensor object representing the input. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return An NSArray of ExecuTorchValue objects representing the outputs, or - * nil in case of an error. - */ -- (nullable NSArray *)forwardWithTensor: - (ExecuTorchTensor *)tensor - error:(NSError **)error - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Sets a single input value for the "forward" method at index 0. - * - * @param value The input value. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInput:(ExecuTorchValue *)value - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets a single input value for the "forward" method at the specified index. - * - * @param value The input value. - * @param index Zero-based input index. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInput:(ExecuTorchValue *)value - atIndex:(NSInteger)index - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets a single input value for the specified method at index 0. - * - * @param value The input value. - * @param methodName The method name. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInput:(ExecuTorchValue *)value - forMethod:(NSString *)methodName - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets a single input value for the specified method at the given index. - * - * The module retains the provided value to keep its backing storage alive - * until the value is overwritten or the module is deallocated. - * - * @param value The input value. - * @param methodName The method name. - * @param index Zero-based input index. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInput:(ExecuTorchValue *)value - forMethod:(NSString *)methodName - atIndex:(NSInteger)index - error:(NSError **)error NS_REFINED_FOR_SWIFT; - -/** - * Sets all input values for the "forward" method. - * - * The number and types of values must match the method’s declared inputs. - * - * @param values The input values, one per declared input. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInputs:(NSArray *)values - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets all input values for the specified method. - * - * The module retains the provided values to keep their backing storage alive - * until the values are overwritten or the module is deallocated. - * - * @param values The input values, one per declared input. - * @param methodName The method name. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setInputs:(NSArray *)values - forMethod:(NSString *)methodName - error:(NSError **)error NS_REFINED_FOR_SWIFT; - -/** - * Sets the output buffer for the "forward" method at index 0. - * - * Only tensor outputs are supported. The provided value must wrap a tensor - * compatible with the method’s output slot. - * - * @param value The output buffer (must wrap a tensor). - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setOutput:(ExecuTorchValue *)value - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets the output buffer for the "forward" method at the specified index. - * - * Only tensor outputs are supported. The provided value must wrap a tensor - * compatible with the method’s output slot. - * - * @param value The output buffer (must wrap a tensor). - * @param index Zero-based output index. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setOutput:(ExecuTorchValue *)value - atIndex:(NSInteger)index - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets the output buffer for the specified method at index 0. - * - * Only tensor outputs are supported. The provided value must wrap a tensor - * compatible with the method’s output slot. - * - * @param value The output buffer (must wrap a tensor). - * @param methodName The method name. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setOutput:(ExecuTorchValue *)value - forMethod:(NSString *)methodName - error:(NSError **)error NS_SWIFT_UNAVAILABLE(""); - -/** - * Sets the output buffer for the specified method at the given index. - * - * The module retains the provided value to keep its backing storage alive - * until the value is overwritten or the module is deallocated. - * Only tensor outputs are supported. - * - * @param value The output buffer (must wrap a tensor). - * @param methodName The method name. - * @param index Zero-based output index. - * @param error On failure, set to an NSError describing the issue. - * @return YES on success; NO otherwise. - */ -- (BOOL)setOutput:(ExecuTorchValue *)value - forMethod:(NSString *)methodName - atIndex:(NSInteger)index - error:(NSError **)error NS_REFINED_FOR_SWIFT; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchTensor.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchTensor.h deleted file mode 100644 index 6f4ab4bdce..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchTensor.h +++ /dev/null @@ -1,1461 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Enum to define the data type of a Tensor. - * Values can be a subset, but must numerically match exactly those defined in - * runtime/core/portable_type/scalar_type.h - */ -typedef NS_ENUM(int8_t, ExecuTorchDataType) { - ExecuTorchDataTypeByte, - ExecuTorchDataTypeChar, - ExecuTorchDataTypeShort, - ExecuTorchDataTypeInt, - ExecuTorchDataTypeLong, - ExecuTorchDataTypeHalf, - ExecuTorchDataTypeFloat, - ExecuTorchDataTypeDouble, - ExecuTorchDataTypeComplexHalf, - ExecuTorchDataTypeComplexFloat, - ExecuTorchDataTypeComplexDouble, - ExecuTorchDataTypeBool, - ExecuTorchDataTypeQInt8, - ExecuTorchDataTypeQUInt8, - ExecuTorchDataTypeQInt32, - ExecuTorchDataTypeBFloat16, - ExecuTorchDataTypeQUInt4x2, - ExecuTorchDataTypeQUInt2x4, - ExecuTorchDataTypeBits1x8, - ExecuTorchDataTypeBits2x4, - ExecuTorchDataTypeBits4x2, - ExecuTorchDataTypeBits8, - ExecuTorchDataTypeBits16, - ExecuTorchDataTypeFloat8_e5m2, - ExecuTorchDataTypeFloat8_e4m3fn, - ExecuTorchDataTypeFloat8_e5m2fnuz, - ExecuTorchDataTypeFloat8_e4m3fnuz, - ExecuTorchDataTypeUInt16, - ExecuTorchDataTypeUInt32, - ExecuTorchDataTypeUInt64, - ExecuTorchDataTypeUndefined, - ExecuTorchDataTypeNumOptions, -} NS_SWIFT_NAME(DataType); - -/** - * Enum to define the shape dynamism of a Tensor. - * Values can be a subset, but must numerically match exactly those defined in - * runtime/core/tensor_shape_dynamism.h - */ -typedef NS_ENUM(uint8_t, ExecuTorchShapeDynamism) { - ExecuTorchShapeDynamismStatic, - ExecuTorchShapeDynamismDynamicBound, - ExecuTorchShapeDynamismDynamicUnbound, -} NS_SWIFT_NAME(ShapeDynamism); - -/** - * Returns the size in bytes of the specified data type. - * - * @param dataType An ExecuTorchDataType value representing the tensor's element - * type. - * @return An NSInteger indicating the size in bytes. - */ -FOUNDATION_EXPORT -NSInteger ExecuTorchSizeOfDataType(ExecuTorchDataType dataType) - NS_SWIFT_NAME(size(ofDataType:)); - -/** - * Computes the total number of elements in a tensor based on its shape. - * - * @param shape An NSArray of NSNumber objects, where each element represents a - * dimension size. - * @return An NSInteger equal to the product of the sizes of all dimensions. - */ -FOUNDATION_EXPORT -NSInteger -ExecuTorchElementCountOfShape(NSArray *shape) NS_REFINED_FOR_SWIFT; - -/** - * A tensor class for ExecuTorch operations. - * - * This class encapsulates a native TensorPtr instance and provides a variety of - * initializers and utility methods to work with tensor data. - */ -NS_SWIFT_NAME(AnyTensor) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchTensor : NSObject - -/** - * Pointer to the underlying native TensorPtr instance. - * - * @return A raw pointer to the native TensorPtr held by this Tensor class. - */ -@property(nonatomic, readonly) void *nativeInstance NS_SWIFT_UNAVAILABLE(""); - -/** - * The data type of the tensor. - * - * @return An ExecuTorchDataType value representing the tensor's element type. - */ -@property(nonatomic, readonly) ExecuTorchDataType dataType; - -/** - * The shape of the tensor. - * - * @return An NSArray of NSNumber objects representing the size of each - * dimension. - */ -@property(nonatomic, readonly) NSArray *shape NS_REFINED_FOR_SWIFT; - -/** - * The order of dimensions in the tensor. - * - * @return An NSArray of NSNumber objects representing the tensor’s dimension - * order. - */ -@property(nonatomic, readonly) - NSArray *dimensionOrder NS_REFINED_FOR_SWIFT; - -/** - * The strides of the tensor. - * - * @return An NSArray of NSNumber objects representing the step sizes for each - * dimension. - */ -@property(nonatomic, readonly) - NSArray *strides NS_REFINED_FOR_SWIFT; - -/** - * The dynamism of the tensor's shape. - * - * @return An ExecuTorchShapeDynamism value indicating whether the tensor shape - * is static or dynamic. - */ -@property(nonatomic, readonly) ExecuTorchShapeDynamism shapeDynamism; - -/** - * The total number of elements in the tensor. - * - * @return An NSInteger representing the total element count. - */ -@property(nonatomic, readonly) NSInteger count NS_REFINED_FOR_SWIFT; - -/** - * Initializes a tensor with a native TensorPtr instance. - * - * @param nativeInstance A pointer to a native TensorPtr instance. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithNativeInstance:(void *)nativeInstance - NS_DESIGNATED_INITIALIZER NS_SWIFT_UNAVAILABLE(""); - -/** - * Creates a new tensor that shares the underlying data storage with the - * given tensor, with metadata overrides. An empty array for - * a parameter signifies that it should be inherited or derived. - * - * @param otherTensor The tensor instance to create a view of. - * @param shape An override for the tensor's shape. - * @param dimensionOrder An override for the tensor's dimension order. - * @param strides An override for the tensor's strides. - * @return A new ExecuTorchTensor instance that shares data with otherTensor. - */ -- (instancetype)initWithTensor:(ExecuTorchTensor *)otherTensor - shape:(NSArray *)shape - dimensionOrder:(NSArray *)dimensionOrder - strides:(NSArray *)strides - NS_REFINED_FOR_SWIFT; - -/** - * Creates a new tensor that shares the underlying data storage with the - * given tensor, with an overridden shape. - * - * @param otherTensor The tensor instance to create a view of. - * @param shape An override for the tensor's shape. - * @return A new ExecuTorchTensor instance that shares data with otherTensor. - */ -- (instancetype)initWithTensor:(ExecuTorchTensor *)otherTensor - shape:(NSArray *)shape - NS_SWIFT_UNAVAILABLE(""); - -/** - * Creates a new tensor that shares the underlying data storage with the - * given tensor. This new tensor is a view and does not own the data. - * - * @param otherTensor The tensor instance to create a view of. - * @return A new ExecuTorchTensor instance that shares data with otherTensor. - */ -- (instancetype)initWithTensor:(ExecuTorchTensor *)otherTensor - NS_SWIFT_UNAVAILABLE(""); - -/** - * Creates a deep copy of the tensor. - * The new tensor will have its own copy of the data. - * - * @return A new ExecuTorchTensor instance that is a duplicate of the current - * tensor. - */ -- (instancetype)copy; - -/** - * Creates a deep copy of the tensor, potentially casting to a new data type. - * The new tensor will have its own copy of the data. - * - * @param dataType The desired data type for the new tensor. - * @return A new ExecuTorchTensor instance that is a duplicate (and possibly -casted) of the current tensor. -*/ -- (instancetype)copyToDataType:(ExecuTorchDataType)dataType - NS_SWIFT_NAME(copy(to:)); - -/** - * Executes a block with a pointer to the tensor's immutable byte data. - * - * @param handler A block that receives: - * - a pointer to the data, - * - the total number of elements, - * - and the data type. - */ -- (void)bytesWithHandler: - (NS_NOESCAPE void (^)(const void *pointer, NSInteger count, - ExecuTorchDataType dataType))handler - NS_SWIFT_NAME(bytes(_:)); - -/** - * Executes a block with a pointer to the tensor's mutable byte data. - * - * @param handler A block that receives: - * - a mutable pointer to the data, - * - the total number of elements, - * - and the data type. - */ -- (void)mutableBytesWithHandler: - (NS_NOESCAPE void (^)(void *pointer, NSInteger count, - ExecuTorchDataType dataType))handler - NS_SWIFT_NAME(mutableBytes(_:)); - -/** - * Resizes the tensor to a new shape. - * - * @param shape An NSArray of NSNumber objects representing the desired new - * shape. - * @param error A pointer to an NSError pointer that is set if an error occurs. - * @return YES if the tensor was successfully resized; otherwise, NO. - */ -- (BOOL)resizeToShape:(NSArray *)shape - error:(NSError **)error NS_REFINED_FOR_SWIFT; - -/** - * Determines whether the current tensor is equal to another tensor. - * - * @param other Another ExecuTorchTensor instance to compare against. - * @return YES if the tensors have the same data type, shape, dimension order, - * strides, and underlying data; otherwise, NO. - */ -- (BOOL)isEqualToTensor:(nullable ExecuTorchTensor *)other NS_REFINED_FOR_SWIFT; - -+ (instancetype)new NS_UNAVAILABLE; -- (instancetype)init NS_UNAVAILABLE; - -@end - -#pragma mark - BytesNoCopy Category - -@interface ExecuTorchTensor (BytesNoCopy) - -/** - * Initializes a tensor without copying the provided data. - * - * @param pointer A pointer to the data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating whether the - * shape is static or dynamic. - * @return An initialized ExecuTorchTensor instance using the provided data - * buffer. - */ -- (instancetype)initWithBytesNoCopy:(void *)pointer - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT; - -/** - * Initializes a tensor without copying data using dynamic bound shape (default - * strides and dimension order). - * - * @param pointer A pointer to the data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithBytesNoCopy:(void *)pointer - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor without copying data, with an explicit shape dynamism. - * - * @param pointer A pointer to the data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithBytesNoCopy:(void *)pointer - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor without copying data, specifying only the shape and data - * type. - * - * @param pointer A pointer to the data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithBytesNoCopy:(void *)pointer - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -@end - -#pragma mark - Bytes Category - -@interface ExecuTorchTensor (Bytes) - -/** - * Initializes a tensor by copying bytes from the provided pointer. - * - * @param pointer A pointer to the source data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance with its own copy of the - * data. - */ -- (instancetype)initWithBytes:(const void *)pointer - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT; - -/** - * Initializes a tensor by copying bytes from the provided pointer with dynamic - * bound shape. - * - * @param pointer A pointer to the source data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance with its own copy of the - * data. - */ -- (instancetype)initWithBytes:(const void *)pointer - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor by copying bytes from the provided pointer, specifying - * shape, data type, and explicit shape dynamism. - * - * @param pointer A pointer to the source data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance with its own copy of the - * data. - */ -- (instancetype)initWithBytes:(const void *)pointer - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor by copying bytes from the provided pointer, specifying - * only the shape and data type. - * - * @param pointer A pointer to the source data buffer. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance with its own copy of the - * data. - */ -- (instancetype)initWithBytes:(const void *)pointer - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -@end - -#pragma mark - Data Category - -@interface ExecuTorchTensor (Data) - -/** - * Initializes a tensor using an NSData object. The tensor will hold a - * strong reference to the NSData object to manage the lifetime of the - * underlying data buffer, which is not copied. - * - * @param data An NSData object containing the tensor data. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance using the provided data. - */ -- (instancetype)initWithData:(NSData *)data - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT; - -/** - * Initializes a tensor using an NSData object as the underlying data buffer - * with dynamic bound shape. - * - * @param data An NSData object containing the tensor data. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param strides An NSArray of NSNumber objects representing the tensor's - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance using the provided data. - */ -- (instancetype)initWithData:(NSData *)data - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor using an NSData object as the underlying data buffer, - * specifying shape, data type, and explicit shape dynamism. - * - * @param data An NSData object containing the tensor data. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance using the provided data. - */ -- (instancetype)initWithData:(NSData *)data - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor using an NSData object as the underlying data buffer, - * specifying only the shape and data type. - * - * @param data An NSData object containing the tensor data. - * @param shape An NSArray of NSNumber objects representing the tensor's shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance using the provided data. - */ -- (instancetype)initWithData:(NSData *)data - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -@end - -#pragma mark - Scalars Category - -@interface ExecuTorchTensor (Scalars) - -/** - * Initializes a tensor with an array of scalar values and full tensor - * properties. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @param strides An NSArray of NSNumber objects representing the tensor - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance containing the provided - * scalar values. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, specifying shape, - * strides, dimension order, and data type, using a default dynamic bound shape - * for shape dynamism. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @param strides An NSArray of NSNumber objects representing the tensor - * strides. - * @param dimensionOrder An NSArray of NSNumber objects indicating the order of - * dimensions. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance containing the scalar - * values. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - strides:(NSArray *)strides - dimensionOrder:(NSArray *)dimensionOrder - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, specifying the desired - * shape, data type, and explicit shape dynamism. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values and a specified shape, - * using a default dynamic bound shape for shape dynamism. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, specifying the tensor - * data type and explicit shape dynamism. The shape is deduced from the count of - * the scalar array. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance with the shape deduced from - * the scalar count. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, specifying the tensor - * data type. The shape is deduced from the count of the scalar array. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance with the shape deduced from - * the scalar count. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, a specified shape and - * explicit shape dynamism. The data type is automatically deduced from the - * first element of the array. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @param shapeDynamism An ExecuTorchShapeDynamism value indicating the shape - * dynamism. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values and a specified shape. - * The data type is automatically deduced from the first element of the array. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @param shape An NSArray of NSNumber objects representing the desired tensor - * shape. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - shape:(NSArray *)shape - NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an array of scalar values, automatically deducing - * the tensor shape and data type. - * - * @param scalars An NSArray of NSNumber objects representing the scalar values. - * @return An initialized ExecuTorchTensor instance with shape and data type - * deduced. - */ -- (instancetype)initWithScalars:(NSArray *)scalars - NS_SWIFT_UNAVAILABLE(""); - -@end - -@interface ExecuTorchTensor (Scalar) - -/** - * Initializes a tensor with a single scalar value and a specified data type. - * - * @param scalar An NSNumber representing the scalar value. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return An initialized ExecuTorchTensor instance representing the scalar. - */ -- (instancetype)initWithScalar:(NSNumber *)scalar - dataType:(ExecuTorchDataType)dataType - NS_REFINED_FOR_SWIFT; - -/** - * Initializes a tensor with a single scalar value, automatically deducing its - * data type. - * - * @param scalar An NSNumber representing the scalar value. - * @return An initialized ExecuTorchTensor instance representing the scalar. - */ -- (instancetype)initWithScalar:(NSNumber *)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a byte scalar value. - * - * @param scalar A uint8_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithByte:(uint8_t)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a char scalar value. - * - * @param scalar An int8_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithChar:(int8_t)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a short scalar value. - * - * @param scalar An int16_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithShort:(int16_t)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with an int scalar value. - * - * @param scalar An int32_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithInt:(int32_t)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a long scalar value. - * - * @param scalar An int64_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithLong:(int64_t)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a float scalar value. - * - * @param scalar A float value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithFloat:(float)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a double scalar value. - * - * @param scalar A double value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithDouble:(double)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a boolean scalar value. - * - * @param scalar A BOOL value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithBool:(BOOL)scalar NS_SWIFT_UNAVAILABLE(""); - -/** - * Initializes a tensor with a uint16 scalar value. - * - * @param scalar A uint16_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithUInt16:(uint16_t)scalar NS_SWIFT_NAME(init(_:)); - -/** - * Initializes a tensor with a uint32 scalar value. - * - * @param scalar A uint32_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithUInt32:(uint32_t)scalar NS_SWIFT_NAME(init(_:)); - -/** - * Initializes a tensor with a uint64 scalar value. - * - * @param scalar A uint64_t value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithUInt64:(uint64_t)scalar NS_SWIFT_NAME(init(_:)); - -/** - * Initializes a tensor with an NSInteger scalar value. - * - * @param scalar An NSInteger value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithInteger:(NSInteger)scalar NS_SWIFT_NAME(init(_:)); - -/** - * Initializes a tensor with an NSUInteger scalar value. - * - * @param scalar An NSUInteger value. - * @return An initialized ExecuTorchTensor instance. - */ -- (instancetype)initWithUnsignedInteger:(NSUInteger)scalar - NS_SWIFT_NAME(init(_:)); - -@end - -#pragma mark - Empty Category - -@interface ExecuTorchTensor (Empty) - -/** - * Creates an empty tensor with the specified shape, strides, data type, and - * shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param strides An NSArray of NSNumber objects representing the desired - * strides. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new, empty ExecuTorchTensor instance. - */ -+ (instancetype)emptyTensorWithShape:(NSArray *)shape - strides:(NSArray *)strides - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates an empty tensor with the specified shape, data type, and shape - * dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new, empty ExecuTorchTensor instance. - */ -+ (instancetype)emptyTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates an empty tensor with the specified shape and data type, using dynamic - * bound shape. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new, empty ExecuTorchTensor instance. - */ -+ (instancetype)emptyTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates an empty tensor similar to the given tensor, with the specified data - * type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new, empty ExecuTorchTensor instance with the same shape as the - * provided tensor. - */ -+ (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates an empty tensor similar to the given tensor, with the specified data - * type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new, empty ExecuTorchTensor instance with the same shape as the - * provided tensor. - */ -+ (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates an empty tensor similar to the given tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @return A new, empty ExecuTorchTensor instance with the same properties as - * the provided tensor. - */ -+ (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - Full Category - -@interface ExecuTorchTensor (Full) - -/** - * Creates a tensor filled with the specified scalar value, with full - * specification of shape, strides, data type, and shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param scalar An NSNumber representing the value to fill the tensor. - * @param strides An NSArray of NSNumber objects representing the desired - * strides. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorWithShape:(NSArray *)shape - scalar:(NSNumber *)scalar - strides:(NSArray *)strides - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with the specified scalar value, with the given - * shape, data type, and shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param scalar An NSNumber representing the value to fill the tensor. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorWithShape:(NSArray *)shape - scalar:(NSNumber *)scalar - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with the specified scalar value, with the given shape - * and data type, using dynamic bound shape for strides and dimension order. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param scalar An NSNumber representing the value to fill the tensor. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorWithShape:(NSArray *)shape - scalar:(NSNumber *)scalar - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with the specified scalar value, similar to an - * existing tensor, with the given data type and shape dynamism. - * - * @param tensr An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param scalar An NSNumber representing the value to fill the tensor. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr - scalar:(NSNumber *)scalar - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with the specified scalar value, similar to an - * existing tensor, with the given data type. - * - * @param tensr An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param scalar An NSNumber representing the value to fill the tensor. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr - scalar:(NSNumber *)scalar - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with the specified scalar value, similar to an - * existing tensor. - * - * @param tensr An existing ExecuTorchTensor instance. - * @param scalar An NSNumber representing the value to fill the tensor. - * @return A new ExecuTorchTensor instance filled with the scalar value. - */ -+ (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr - scalar:(NSNumber *)scalar - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - Ones Category - -@interface ExecuTorchTensor (Ones) - -/** - * Creates a tensor filled with ones, with the specified shape, data type, and - * shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with ones. - */ -+ (instancetype)onesTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with ones, with the specified shape and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with ones. - */ -+ (instancetype)onesTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with ones similar to an existing tensor, with the - * specified data type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with ones. - */ -+ (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with ones similar to an existing tensor, with the - * specified data type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new ExecuTorchTensor instance filled with ones. - */ -+ (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with ones similar to an existing tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @return A new ExecuTorchTensor instance filled with ones. - */ -+ (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - Zeros Category - -@interface ExecuTorchTensor (Zeros) - -/** - * Creates a tensor filled with zeros, with the specified shape, data type, and - * shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with zeros. - */ -+ (instancetype)zerosTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with zeros, with the specified shape and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with zeros. - */ -+ (instancetype)zerosTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with zeros similar to an existing tensor, with the - * specified data type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with zeros. - */ -+ (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with zeros similar to an existing tensor, with the - * specified data type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new ExecuTorchTensor instance filled with zeros. - */ -+ (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor filled with zeros similar to an existing tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @return A new ExecuTorchTensor instance filled with zeros. - */ -+ (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - Random Category - -@interface ExecuTorchTensor (Random) - -/** - * Creates a tensor with random values, with full specification of shape, - * strides, data type, and shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param strides An NSArray of NSNumber objects representing the desired - * strides. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorWithShape:(NSArray *)shape - strides:(NSArray *)strides - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values, with the specified shape and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values, with the specified shape (using dynamic - * bound shape) and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values similar to an existing tensor, with the - * specified data type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values similar to an existing tensor, with the - * specified data type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values similar to an existing tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @return A new ExecuTorchTensor instance filled with random values. - */ -+ (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - RandomNormal Category - -@interface ExecuTorchTensor (RandomNormal) - -/** - * Creates a tensor with random values drawn from a normal distribution, - * with full specification of shape, strides, data type, and shape dynamism. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param strides An NSArray of NSNumber objects representing the desired - * strides. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorWithShape:(NSArray *)shape - strides:(NSArray *)strides - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values drawn from a normal distribution, - * with the specified shape and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random values drawn from a normal distribution, - * with the specified shape (using dynamic bound shape) and data type. - * - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorWithShape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random normal values similar to an existing tensor, - * with the specified data type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random normal values similar to an existing tensor, - * with the specified data type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param dataType An ExecuTorchDataType value specifying the desired element - * type. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random normal values similar to an existing tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @return A new ExecuTorchTensor instance filled with values from a normal - * distribution. - */ -+ (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -#pragma mark - RandomInteger Category - -@interface ExecuTorchTensor (RandomInteger) - -/** - * Creates a tensor with random integer values in the specified range, - * with full specification of shape, strides, data type, and shape dynamism. - * - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param strides An NSArray of NSNumber objects representing the desired - * strides. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorWithLow:(NSInteger)low - high:(NSInteger)high - shape:(NSArray *)shape - strides:(NSArray *)strides - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random integer values in the specified range, - * with the given shape and data type. - * - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorWithLow:(NSInteger)low - high:(NSInteger)high - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random integer values in the specified range, - * with the given shape (using dynamic bound shape) and data type. - * - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @param shape An NSArray of NSNumber objects representing the desired shape. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorWithLow:(NSInteger)low - high:(NSInteger)high - shape:(NSArray *)shape - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random integer values in the specified range, similar - * to an existing tensor, with the given data type and shape dynamism. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the - * shape is static or dynamic. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor - low:(NSInteger)low - high:(NSInteger)high - dataType:(ExecuTorchDataType)dataType - shapeDynamism: - (ExecuTorchShapeDynamism)shapeDynamism - NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random integer values in the specified range, similar - * to an existing tensor, with the given data type. - * - * @param tensor An existing ExecuTorchTensor instance whose shape and strides - * are used. - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @param dataType An ExecuTorchDataType value specifying the element type. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor - low:(NSInteger)low - high:(NSInteger)high - dataType:(ExecuTorchDataType)dataType - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -/** - * Creates a tensor with random integer values in the specified range, similar - * to an existing tensor. - * - * @param tensor An existing ExecuTorchTensor instance. - * @param low An NSInteger specifying the inclusive lower bound of random - * values. - * @param high An NSInteger specifying the exclusive upper bound of random - * values. - * @return A new ExecuTorchTensor instance filled with random integer values. - */ -+ (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor - low:(NSInteger)low - high:(NSInteger)high - NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchValue.h b/packages/react-native-executorch/third-party/include/executorch/ExecuTorchValue.h deleted file mode 100644 index aeaabcdd45..0000000000 --- a/packages/react-native-executorch/third-party/include/executorch/ExecuTorchValue.h +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "ExecuTorchTensor.h" - -NS_ASSUME_NONNULL_BEGIN - -/** - * Enum to define the dynamic type of a Value. - * Values can be a subset, but must numerically match exactly those defined in - * runtime/core/tag.h - */ -typedef NS_ENUM(uint32_t, ExecuTorchValueTag) { - ExecuTorchValueTagNone, - ExecuTorchValueTagTensor, - ExecuTorchValueTagString, - ExecuTorchValueTagDouble, - ExecuTorchValueTagInteger, - ExecuTorchValueTagBoolean, -} NS_SWIFT_NAME(ValueTag); - -typedef NSNumber * - ExecuTorchScalarValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(ScalarValue); -typedef NSString * - ExecuTorchStringValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(StringValue); -typedef BOOL ExecuTorchBooleanValue NS_SWIFT_NAME(BoolValue); -typedef NSInteger - ExecuTorchIntegerValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(IntegerValue); -typedef double - ExecuTorchDoubleValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(DoubleValue); -typedef float - ExecuTorchFloatValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(FloatValue); - -/** - * A dynamic value type used by ExecuTorch. - * - * ExecuTorchValue encapsulates a value that may be of various types such as - * a tensor or a scalar. The value’s type is indicated by its tag. - */ -NS_SWIFT_NAME(Value) -__attribute__((objc_subclassing_restricted)) -@interface ExecuTorchValue : NSObject - -/** - * The tag that indicates the dynamic type of the value. - * - * @return An ExecuTorchValueTag value. - */ -@property(nonatomic, readonly) ExecuTorchValueTag tag; - -/** - * The tensor value if the tag is ExecuTorchValueTagTensor. - * - * @return A Tensor instance or nil. - */ -@property(nullable, nonatomic, readonly) - ExecuTorchTensor *tensorValue NS_REFINED_FOR_SWIFT; - -/** - * The string value if the tag is ExecuTorchValueTagString. - * - * @return An NSString instance or nil. - */ -@property(nullable, nonatomic, readonly) - ExecuTorchStringValue stringValue NS_SWIFT_NAME(string); - -/** - * The scalar value if the tag is boolean, integer or double. - * - * @return A scalar value or nil. - */ -@property(nullable, nonatomic, readonly) - ExecuTorchScalarValue scalarValue NS_SWIFT_NAME(scalar); - -/** - * The boolean value if the tag is ExecuTorchValueTagBoolean. - * - * @return A BOOL representing the boolean value. - */ -@property(nonatomic, readonly) - ExecuTorchBooleanValue boolValue NS_SWIFT_NAME(boolean); - -/** - * The integer value if the tag is ExecuTorchValueTagInteger. - * - * @return An NSInteger representing the integer value. - */ -@property(nonatomic, readonly) - ExecuTorchIntegerValue intValue NS_SWIFT_NAME(integer); - -/** - * The double value if the tag is ExecuTorchValueTagDouble. - * - * @return A double representing the double value. - */ -@property(nonatomic, readonly) - ExecuTorchDoubleValue doubleValue NS_SWIFT_NAME(double); - -/** - * The float value if the tag is ExecuTorchValueTagDouble. - * - * @return An float representing the float value. - */ -@property(nonatomic, readonly) - ExecuTorchFloatValue floatValue NS_SWIFT_NAME(float); - -/** - * Returns YES if the value is of type None. - * - * @return A BOOL indicating whether the value is None. - */ -@property(nonatomic, readonly) BOOL isNone; - -/** - * Returns YES if the value is a Tensor. - * - * @return A BOOL indicating whether the value is a Tensor. - */ -@property(nonatomic, readonly) BOOL isTensor; - -/** - * Returns YES if the value is a string. - * - * @return A BOOL indicating whether the value is a string. - */ -@property(nonatomic, readonly) BOOL isString; - -/** - * Returns YES if the value is a scalar (boolean, integer or double). - * - * @return A BOOL indicating whether the value is a scalar. - */ -@property(nonatomic, readonly) BOOL isScalar; - -/** - * Returns YES if the value is a boolean. - * - * @return A BOOL indicating whether the value is a boolean. - */ -@property(nonatomic, readonly) BOOL isBoolean; - -/** - * Returns YES if the value is an integer. - * - * @return A BOOL indicating whether the value is an integer. - */ -@property(nonatomic, readonly) BOOL isInteger; - -/** - * Returns YES if the value is a double. - * - * @return A BOOL indicating whether the value is a double. - */ -@property(nonatomic, readonly) BOOL isDouble; - -/** - * Returns YES if the value's tag is Double. - * - * Note: Since float values are stored with a Double tag, this property will - * also be YES for values created from floats. - * - * @return A BOOL indicating whether the value is a float. - */ -@property(nonatomic, readonly) BOOL isFloat; - -/** - * Creates an instance encapsulating a Tensor. - * - * @param value An ExecuTorchTensor instance. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagTensor. - */ -+ (instancetype)valueWithTensor:(ExecuTorchTensor *)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating a string. - * - * @param value A string. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagString. - */ -+ (instancetype)valueWithString:(ExecuTorchStringValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating a boolean. - * - * @param value A boolean. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagBoolean. - */ -+ (instancetype)valueWithBoolean:(ExecuTorchBooleanValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating an integer. - * - * @param value An integer. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagInteger. - */ -+ (instancetype)valueWithInteger:(ExecuTorchIntegerValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating a double value. - * - * @param value A double value. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagDouble. - */ -+ (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating a float value. - * - * Note: The underlying value will be stored with a tag of - * ExecuTorchValueTagDouble, as there is no distinct float tag. - * - * @param value A float value. - * @return A new ExecuTorchValue instance with a tag of - * ExecuTorchValueTagDouble. - */ -+ (instancetype)valueWithFloat:(ExecuTorchFloatValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Creates an instance encapsulating a scalar value. - * - * The value's tag will be set according to the type encoding of the - * ExecuTorchScalarValue. - * - * @param value An ExecuTorchScalarValue. - * @return A new ExecuTorchValue instance with the appropriate tag. - */ -+ (instancetype)valueWithScalar:(ExecuTorchScalarValue)value - NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED; - -/** - * Returns a copy of the value. - * - * @return A new ExecuTorchValue instance that is a duplicate of the current - * value. - */ -- (instancetype)copy; - -/** - * Determines whether the current Value is equal to another Value. - * - * @param other Another ExecuTorchValue instance to compare against. - * @return YES if the values have the same tag and equal underlying values; - * otherwise, NO. - */ -- (BOOL)isEqualToValue:(nullable ExecuTorchValue *)other; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/asr/runner/runner.h b/packages/react-native-executorch/third-party/include/executorch/extension/asr/runner/runner.h new file mode 100644 index 0000000000..d07ef2dfa2 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/asr/runner/runner.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace executorch::extension::asr { + +using ::executorch::extension::Module; +using ::executorch::extension::llm::get_eos_ids; +using ::executorch::extension::llm::load_tokenizer; +using ::executorch::extension::llm::print_report; +using ::executorch::extension::llm::Sampler; +using ::executorch::extension::llm::Stats; +using ::executorch::runtime::Error; +using ::executorch::runtime::Result; + +/** + * Configuration for the ASR transcription loop. + * + * max_new_tokens controls the number of tokens generated after the prompt. + * Temperature controls the randomness of the output. + */ +struct ET_EXPERIMENTAL AsrTranscribeConfig { + int64_t max_new_tokens = 128; + std::unordered_set eos_token_ids = {}; + float temperature = 0.0f; + int64_t decoder_start_token_id = 0; +}; + +/** + * Runner that owns a ASR model encoder + decoder pair exported as a single + * ExecuTorch module. A good example is Whisper + * (https://huggingface.co/openai/whisper-small) + * + * The module is expected to expose two callable methods: + * - "encoder": processes precomputed audio features into encoder states. + * - "text_decoder": consumes the decoder input ids, encoder output and cache + * positions to autoregressively generate logits. + */ +class ET_EXPERIMENTAL AsrRunner { +public: + AsrRunner(const std::string &module_path, + std::optional data_path, + const std::string &tokenizer_path); + + /** + * Returns true when the module and tokenizer are ready for inference. + */ + bool is_loaded() const; + + /** + * Loads the module, validates required methods and initialises tokenizer. + */ + ::executorch::runtime::Error load(); + + /** + * Executes an end-to-end transcription cycle. + * + * @param preprocessed_features Audio features tensor of shape [batch, time, + * features] already processed by a preprocessor module. Typically produced + * by an audio feature extractor (e.g., mel-spectrogram computation). + * @param config Controls generation length and termination criteria. + * @param token_callback Optional functor invoked for each decoded piece of + * text emitted during generation. + * + * @returns Result containing the final decoder token ids (including the seed + * prompt and generated tokens), or an error. + */ + ::executorch::runtime::Result> + transcribe(::executorch::extension::TensorPtr preprocessed_features, + AsrTranscribeConfig config = {}, + std::function token_callback = {}); + +private: + ::executorch::runtime::Error load_tokenizer(); + inline const std::unordered_set &eos_token_ids() const { + return eos_token_ids_; + } + + std::string module_path_; + std::string data_path_; + std::string tokenizer_path_; + + std::unique_ptr module_; + std::unique_ptr<::tokenizers::Tokenizer> tokenizer_; + std::unordered_set eos_token_ids_; + + bool encoder_method_loaded_ = false; + bool decoder_method_loaded_ = false; + bool sampler_method_loaded_ = false; + bool sampler_method_present_ = false; + + Stats stats_; +}; + +} // namespace executorch::extension::asr diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/data_loader/buffer_data_loader.h b/packages/react-native-executorch/third-party/include/executorch/extension/data_loader/buffer_data_loader.h index 47f20301e6..38322aff43 100644 --- a/packages/react-native-executorch/third-party/include/executorch/extension/data_loader/buffer_data_loader.h +++ b/packages/react-native-executorch/third-party/include/executorch/extension/data_loader/buffer_data_loader.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include @@ -33,7 +34,9 @@ class BufferDataLoader final : public executorch::runtime::DataLoader { executorch::runtime::Result load(size_t offset, size_t size, ET_UNUSED const DataLoader::SegmentInfo &segment_info) const override { - ET_CHECK_OR_RETURN_ERROR(offset + size <= size_, InvalidArgument, + size_t total_size; + bool overflow = c10::add_overflows(offset, size, &total_size); + ET_CHECK_OR_RETURN_ERROR(!overflow && total_size <= size_, InvalidArgument, "offset %zu + size %zu > size_ %zu", offset, size, size_); return executorch::runtime::FreeableBuffer(data_ + offset, size, diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/audio.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/audio.h new file mode 100644 index 0000000000..5c8986465d --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/audio.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// A simple audio struct. + +#pragma once +#include +#include +#include +#include + +#include + +namespace executorch { +namespace extension { +namespace llm { + +/** + * Audio inputs as a raw audio tensor, for use when the audio processing + * into a mel spectrogram is baked into the audio encoder with torch.export. + */ +struct ET_EXPERIMENTAL RawAudio { + std::vector data; + int32_t batch_size; + int32_t n_channels; // For mono, use n_channels = 1. + int32_t n_samples; +}; + +/** + * Pre-processed audio inputs, ready to feed directly into an audio encoder. + * + * The data can be either uint8_t or float. If the audio has gone through a Mel + * transform, we expect the data type to be float (i.e., std::vector), as + * Mel spectrograms are typically represented as floating point values. For raw + * or quantized audio, uint8_t may be used instead. + */ +class ET_EXPERIMENTAL Audio final { +public: + // Default constructor + Audio() : batch_size_(0), n_bins_(0), n_frames_(0) {} + + // Constructor for uint8_t data + Audio(std::vector &&data, int32_t batch_size, int32_t n_bins, + int32_t n_frames) + : data_(std::move(data)), batch_size_(batch_size), n_bins_(n_bins), + n_frames_(n_frames) { + ET_CHECK_MSG( + data_.index() == 0 && + std::get>(data_).size() == + static_cast(batch_size * n_bins * n_frames), + "data.size() (%zu) does not match batch_size * n_bins * n_frames (%d)", + std::get>(data_).size(), + batch_size * n_bins * n_frames); + } + + // Constructor for float data + Audio(std::vector &&data, int32_t batch_size, int32_t n_bins, + int32_t n_frames) + : data_(std::move(data)), batch_size_(batch_size), n_bins_(n_bins), + n_frames_(n_frames) { + ET_CHECK_MSG( + data_.index() == 1 && + std::get>(data_).size() == + static_cast(batch_size * n_bins * n_frames), + "data.size() (%zu) does not match batch_size * n_bins * n_frames (%d)", + std::get>(data_).size(), + batch_size * n_bins * n_frames); + } + + // Type checkers + bool is_uint8() const { + return std::holds_alternative>(data_); + } + + bool is_float() const { + return std::holds_alternative>(data_); + } + + // Data access + const std::vector &get_uint8_data() const & { + return std::get>(data_); + } + + std::vector &get_uint8_data() & { + return std::get>(data_); + } + + const std::vector &get_float_data() const & { + return std::get>(data_); + } + + std::vector &get_float_data() & { + return std::get>(data_); + } + + int32_t get_batch_size() const { return batch_size_; } + int32_t get_n_bins() const { return n_bins_; } + int32_t get_n_frames() const { return n_frames_; } + /** + * Convert the audio data to a TensorPtr, with optional batch dimension. + * The tensor will have shape (batch_size, n_bins, n_frames) or (1, + * batch_size, n_bins, n_frames) if with_batch is true. + */ + executorch::runtime::Result + toTensor(bool with_batch = false) const { + std::vector sizes = { + get_batch_size(), get_n_bins(), get_n_frames()}; + if (with_batch) { + sizes.insert(sizes.begin(), 1); + } + if (is_float()) { + return executorch::extension::from_blob( + const_cast(get_float_data().data()), sizes, + ::executorch::aten::ScalarType::Float); + } else if (is_uint8()) { + return executorch::extension::from_blob( + const_cast(get_uint8_data().data()), sizes, + ::executorch::aten::ScalarType::Byte); + } + ET_LOG(Error, "Shouldn't reach here, audio data is not initialized with " + "uint8_t or float vector."); + return ::executorch::runtime::Error::NotSupported; + } + +private: + // Members + std::variant, std::vector> data_; + int32_t batch_size_; + int32_t n_bins_; + int32_t n_frames_; +}; + +} // namespace llm +} // namespace extension +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::extension::llm::Audio; +} // namespace executor +} // namespace torch diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/constants.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/constants.h new file mode 100644 index 0000000000..d7b3607775 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/constants.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once +// constants for LLM runtime +namespace executorch::extension::llm { + +// Runtime metadata key constants +inline constexpr auto kEnableDynamicShape = "enable_dynamic_shape"; +inline constexpr auto kBosId = "get_bos_id"; +inline constexpr auto kEosIds = "get_eos_ids"; +inline constexpr auto kMaxSeqLen = "get_max_seq_len"; +inline constexpr auto kMaxContextLen = "get_max_context_len"; +inline constexpr auto kVocabSize = "get_vocab_size"; +inline constexpr auto kUseKVCache = "use_kv_cache"; +inline constexpr auto kUseSDPAWithKVCache = "use_sdpa_with_kv_cache"; + +// Multimodal method name conventions +inline constexpr auto kVisionEncoderMethod = "vision_encoder"; +inline constexpr auto kAudioEncoderMethod = "audio_encoder"; +inline constexpr auto kTokenEmbeddingMethod = "token_embedding"; +inline constexpr auto kTextModelMethod = "text_decoder"; + +} // namespace executorch::extension::llm diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image.h new file mode 100644 index 0000000000..31a9bb695e --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// A simple image struct. + +#pragma once +#include +#include +#include +#include +#include + +#include +#include + +namespace executorch { +namespace extension { +namespace llm { + +class ET_EXPERIMENTAL Image { +public: + // Default constructor + Image() : width_(0), height_(0), channels_(0) {} + + // Constructor for uint8_t data + Image(std::vector &&data, int32_t width, int32_t height, + int32_t channels) + : data_(std::move(data)), width_(width), height_(height), + channels_(channels) {} + + // Constructor for float data + Image(std::vector &&data, int32_t width, int32_t height, + int32_t channels) + : data_(std::move(data)), width_(width), height_(height), + channels_(channels) {} + + // Getters + int32_t width() const { return width_; } + int32_t height() const { return height_; } + int32_t channels() const { return channels_; } + + // Data access + bool is_uint8() const { + return std::holds_alternative>(data_); + } + + bool is_float() const { + return std::holds_alternative>(data_); + } + + const std::vector &get_uint8_data() const & { + return std::get>(data_); + } + + std::vector &get_uint8_data() & { + return std::get>(data_); + } + + const std::vector &get_float_data() const & { + return std::get>(data_); + } + + std::vector &get_float_data() & { + return std::get>(data_); + } + + executorch::runtime::Result + toTensor(bool with_batch = false) const { + // Note: This creates a 3D tensor (CHW). The model might expect a 4D + // tensor (NCHW). The caller should handle reshaping if needed. + std::vector sizes = {channels(), height(), + width()}; + if (with_batch) { + sizes.insert(sizes.begin(), 1); + } + if (is_float()) { + return executorch::extension::from_blob( + const_cast(get_float_data().data()), sizes, + ::executorch::aten::ScalarType::Float); + } else if (is_uint8()) { + return executorch::extension::from_blob( + const_cast(get_uint8_data().data()), sizes, + ::executorch::aten::ScalarType::Byte); + } + ET_LOG(Error, + "Image data is not initialized with uint8_t or float vector."); + return ::executorch::runtime::Error::NotSupported; + } + +private: + // Assuming NCHW format + std::variant, std::vector> data_; + int32_t width_; + int32_t height_; + int32_t channels_; +}; + +} // namespace llm +} // namespace extension +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::extension::llm::Image; +} // namespace executor +} // namespace torch diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image_prefiller.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image_prefiller.h new file mode 100644 index 0000000000..9b1b0d3492 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/image_prefiller.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Given a image tensor, prefill the KV cache of a multimodal LLM. + +#pragma once + +#include +#include +#include + +namespace executorch { +namespace extension { +namespace llm { + +// Assuming kv cache and parallel prefill are enabled. +class ET_EXPERIMENTAL ImagePrefiller { +public: + explicit ImagePrefiller(::executorch::extension::Module *module) + : module_(module) {} + + /** + * Prefill an LLM Module with the given image input. + * @param image The image input to the multimodal LLM. + * @param start_pos The starting position in KV cache of the input in the LLM. + * It's passed as reference and will be updated inside this function. + * @return The next token of the LLM Module after prefill. + */ + virtual ::executorch::runtime::Result + prefill(Image &image, int64_t &start_pos) = 0; + + virtual ::executorch::runtime::Error load() = 0; + virtual bool is_method_loaded() = 0; + + virtual ~ImagePrefiller() = default; + +protected: + Module *module_; +}; + +} // namespace llm +} // namespace extension +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::extension::llm::ImagePrefiller; +} // namespace executor +} // namespace torch diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/io_manager/io_manager.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/io_manager/io_manager.h new file mode 100644 index 0000000000..47377e9390 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/io_manager/io_manager.h @@ -0,0 +1,240 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace executorch { +namespace extension { +namespace llm { + +/** + * @brief Base class for managing input/output operations for LLM inference. + * + * IOManager provides an interface for handling the input preparation and + * output processing for both prefill and decode phases of LLM inference. + * Derived classes must implement the virtual methods to provide specific IO + * management functionality. + */ +class ET_EXPERIMENTAL IOManager { +public: + /** + * @brief Construct an IOManager bound to a Module. + * + * @param module The Module used for querying method metadata and execution. + */ + explicit IOManager(ET_MODULE_NAMESPACE::Module &module) : module_(module) {} + + /** + * @brief Virtual destructor to allow proper cleanup in derived classes. + */ + virtual ~IOManager() = default; + + /** + * @brief Load the IO manager with method metadata for prefill and + * decode operations. + * + * @param prefill_method The prefill method to initialize with. + * @param decode_method The decode method to initialize with. + */ + ET_NODISCARD virtual runtime::Error load(const std::string &prefill_method, + const std::string &decode_method) { + (void)prefill_method; + (void)decode_method; + return runtime::Error::Ok; + } + + /** + * @brief Load the IO manager using the default method names. + * + * Uses "forward" for both prefill and decode. + * + * @return Error code. + */ + ET_NODISCARD runtime::Error load() { return load("forward", "forward"); } + + /** + * @brief Reset the IO manager state. + * + * @param prefill_method The prefill method to reset with. + * @param decode_method The decode method to reset with. + */ + ET_NODISCARD virtual runtime::Error reset(const std::string &prefill_method, + const std::string &decode_method) { + (void)prefill_method; + (void)decode_method; + return runtime::Error::Ok; + } + + /** + * @brief Reset the IO manager state using the default method names. + * + * Uses "forward" for both prefill and decode. + * + * @return Error code. + */ + ET_NODISCARD runtime::Error reset() { return reset("forward", "forward"); } + + /** + * @brief Prepare inputs for the prefill phase of LLM inference. + * + * @param input The input tensor containing token IDs. + * @param start_pos The tensor containing the starting position of the current + * input within the context. + * @param prefill_method The prefill method to prepare inputs for. + * @return std::vector Vector of prepared inputs + * for the prefill method. + */ + virtual runtime::Result> + prepare_prefill(const TensorPtr &input, const TensorPtr &start_pos, + const std::string &prefill_method) { + auto method_meta = module_.method_meta(prefill_method); + if (!method_meta.ok()) { + return method_meta.error(); + } + if (method_meta->num_inputs() != 2) { + ET_LOG(Error, + "Expected 2 inputs for prefill method, got %zu. Likely the model " + "takes the caches or mask as an argument which this IOManager " + "does not support.", + method_meta->num_inputs()); + return runtime::Error::InvalidState; + } + // Cpu IO Manager supports dynamic shapes for prefill, so no work to be done + // here. + return std::vector{input, start_pos}; + } + + /** + * @brief Prepare inputs for the prefill phase using the default method name. + * + * Uses "forward" as the prefill method. + * + * @param input The input tensor containing token IDs. + * @param start_pos The tensor containing the starting position. + * @return Vector of prepared inputs for the prefill method. + */ + runtime::Result> + prepare_prefill(const TensorPtr &input, const TensorPtr &start_pos) { + return prepare_prefill(input, start_pos, "forward"); + } + + /** + * @brief Prepare inputs for the decode phase of LLM inference. + * + * @param input The input tensor containing token IDs. + * @param start_pos The tensor containing the starting position of the current + * input within the context. + * @param decode_method The decode method to prepare inputs for. + * @return std::vector Vector of prepared inputs + * for the decode method. + */ + virtual runtime::Result> + prepare_decode(const TensorPtr &input, const TensorPtr &start_pos, + const std::string &decode_method) { + auto method_meta = module_.method_meta(decode_method); + if (!method_meta.ok()) { + return method_meta.error(); + } + if (method_meta->num_inputs() != 2) { + ET_LOG(Error, + "Expected 2 inputs for decode method, got %zu. Likely the model " + "takes the caches or mask as an argument which this IOManager " + "does not support.", + method_meta->num_inputs()); + return runtime::Error::InvalidState; + } + // Cpu IO Manager supports dynamic shapes for prefill, so no work to be done + // here. + return std::vector{input, start_pos}; + } + + /** + * @brief Prepare inputs for the decode phase using the default method name. + * + * Uses "forward" as the decode method. + * + * @param input The input tensor containing token IDs. + * @param start_pos The tensor containing the starting position. + * @return Vector of prepared inputs for the decode method. + */ + runtime::Result> + prepare_decode(const TensorPtr &input, const TensorPtr &start_pos) { + return prepare_decode(input, start_pos, "forward"); + } + + /** + * @brief Process and update internal state with outputs from the prefill + * phase. + * + * @param prefill_method The prefill method to update with outputs. + * @param model_outputs Vector of outputs from the prefill method execution. + */ + ET_NODISCARD virtual runtime::Error + update_prefill(const std::vector &model_outputs, + const std::string &prefill_method) { + (void)model_outputs; + (void)prefill_method; + // No post inference work to do. + return runtime::Error::Ok; + } + + /** + * @brief Process outputs from the prefill phase using the default method. + * + * Uses "forward" as the prefill method. + * + * @param model_outputs Vector of outputs from the prefill execution. + * @return Error code. + */ + ET_NODISCARD runtime::Error + update_prefill(const std::vector &model_outputs) { + return update_prefill(model_outputs, "forward"); + } + + /** + * @brief Process and update internal state with outputs from the decode + * phase. + * + * @param decode_method The decode method to update with outputs. + * @param model_outputs Vector of outputs from the decode method execution. + */ + ET_NODISCARD virtual runtime::Error + update_decode(const std::vector &model_outputs, + const std::string &decode_method) { + (void)model_outputs; + (void)decode_method; + // No post inference work to do. + return runtime::Error::Ok; + } + + /** + * @brief Process outputs from the decode phase using the default method. + * + * Uses "forward" as the decode method. + * + * @param model_outputs Vector of outputs from the decode execution. + * @return Error code. + */ + ET_NODISCARD runtime::Error + update_decode(const std::vector &model_outputs) { + return update_decode(model_outputs, "forward"); + } + +private: + /** + * @brief Reference to the Module used for method metadata and execution. + */ + ET_MODULE_NAMESPACE::Module &module_; +}; + +} // namespace llm +} // namespace extension +} // namespace executorch diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/irunner.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/irunner.h new file mode 100644 index 0000000000..6e1a5c23d6 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/irunner.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Interface for text generation runners. + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace executorch { +namespace extension { +namespace llm { + +class MultimodalInput; // Forward declaration + +// Configuration struct for generation parameters, fields should be sorted in +// alphabetic order +struct GenerationConfig { + // Whether to echo the input prompt in the output + bool echo = true; + + // Whether to ignore EOS token and continue generating until max_new_tokens + bool ignore_eos = false; + + // Maximum number of new tokens to generate + // If the max_context_len metadata that's serialized in the .pte file exists, + // then the number of prompt tokens + max_new_tokens won't exceed + // max_context_len. If this field is -1, it means we will rely on + // max_context_len metadata and seq_len value. Check resolve_max_new_tokens + // for details. + int32_t max_new_tokens = -1; + + // Whether this is a warmup run (affects perf benchmarking) + bool warming = false; + + // Maximum number of total tokens + // If the .pte file contains the max_context_len metadata, it will override + // this value if it's smaller. If this field is -1, we will use the + // max_context_len metadata directly. Check resolve_max_new_tokens for + // details. + int32_t seq_len = -1; + + // Temperature for sampling (higher = more random) + float temperature = 0.8f; + + // Number of eos and bos to add to the prompt + int32_t num_bos = 0; + int32_t num_eos = 0; + + /** + * Resolve the maximum number of new tokens to generate based on constraints. + * + * This method calculates the maximum number of new tokens that can be + * generated considering both seq_len and max_new_tokens constraints, as well + * as the model's maximum context length and the number of tokens in the + * prompt. + * + * @param max_context_len The maximum context length supported by the model + * @param num_prompt_tokens The number of tokens in the input prompt + * @return The resolved maximum number of new tokens to generate + */ + int32_t resolve_max_new_tokens(int32_t max_context_len, + int32_t num_prompt_tokens) const { + int32_t result; + + if (seq_len == -1 && max_new_tokens == -1) { + // Both are -1, use max context len minus prompt tokens + result = max_context_len - num_prompt_tokens; + } else if (seq_len == -1 && max_new_tokens != -1) { + // Only max_new_tokens is specified + result = std::min(max_new_tokens, max_context_len - num_prompt_tokens); + } else if (seq_len != -1 && max_new_tokens == -1) { + // Only seq_len is specified + result = std::min(seq_len, max_context_len) - num_prompt_tokens; + } else { + // Both are specified + result = std::min(std::min(seq_len, max_context_len) - num_prompt_tokens, + max_new_tokens); + } + + // Ensure result is not negative + return std::max(0, result); + } +}; + +// Base interface for LLM runners +class ET_EXPERIMENTAL IRunner { +public: + virtual ~IRunner() = default; + + /** + * Check if the runner is loaded and ready for inference. + * + * @return true if the runner is loaded, false otherwise + */ + virtual bool is_loaded() const = 0; + + /** + * Load the model and prepare for inference. + * + * @return Error::Ok if successful, an error otherwise + */ + virtual runtime::Error load() = 0; + + /** + * Generate text based on the provided prompt and generation config. + * + * @param prompt The input prompt to generate from + * @param config Generation configuration parameters + * @param token_callback Callback function called for each generated token + * @param stats_callback Callback function for generation statistics + * @return Error::Ok if successful, an error otherwise + */ + virtual runtime::Error + generate(const std::string &prompt, const GenerationConfig &config, + std::function token_callback, + std::function stats_callback) = 0; + + /** + * Prefill multimodal inputs into the KV cache without generating. + * + * @param inputs A vector of MultimodalInput objects (text, tokens, images, + * audio) + * @param num_bos Number of BOS tokens to prepend during encoding + * @param num_eos Number of EOS tokens to append during encoding + * @return The next token predicted after prefill, or an error + */ + virtual runtime::Result + prefill(const std::vector &inputs, int32_t num_bos = 0, + int32_t num_eos = 0) { + return runtime::Error::NotSupported; + } + + /** + * Stop the generation process. + */ + virtual void stop() = 0; + + /** + * Force remove prefilled tokens and reset KV cache start position + * + * This method removes the prefilled tokens from the KV cache and resets the + * start position to 0. + */ + virtual void reset() = 0; +}; + +} // namespace llm +} // namespace extension +} // namespace executorch diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/llm_runner_helper.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/llm_runner_helper.h new file mode 100644 index 0000000000..8365c1840a --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/llm_runner_helper.h @@ -0,0 +1,158 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Helper utilities for creating and configuring LLM runners + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace executorch::extension::llm { + +// Forward declarations +class TextLLMRunner; +class MultimodalRunner; + +/** + * @brief Loads a tokenizer from the specified path + * + * This function creates and initializes a tokenizer from a file, with options + * to customize special tokens and regex patterns. It tries different tokenizer + * types in order: HF JSON, TikToken, SentencePiece, and BPE. + * + * @param tokenizer_path Path to the tokenizer file + * @param special_tokens Optional list of special tokens to add to the tokenizer + * @param pattern Optional regex pattern for tokenization + * @param bos_token_index Index of the beginning-of-sequence token + * @param eos_token_index Index of the end-of-sequence token + * @return std::unique_ptr Initialized tokenizer + * instance, or nullptr on failure + */ +ET_EXPERIMENTAL std::unique_ptr load_tokenizer( + const std::string &tokenizer_path, + std::unique_ptr> special_tokens = nullptr, + std::optional pattern = std::nullopt, + size_t bos_token_index = 0, size_t eos_token_index = 1); + +/** + * @brief Gets LLM metadata from the model and tokenizer + * + * This function extracts metadata from the model such as vocabulary size, + * context length, and other configuration parameters. It reads metadata + * methods from the model and combines them with tokenizer information. + * + * @param tokenizer Initialized tokenizer instance + * @param module The model module + * @return Result> Metadata key-value + * pairs on success, or Error::InvalidArgument if required metadata (e.g., + * kMaxSeqLen) is missing from the model + */ +ET_EXPERIMENTAL ::executorch::runtime::Result< + std::unordered_map> +get_llm_metadata(tokenizers::Tokenizer *tokenizer, Module *module); + +/** + * @brief Gets EOS token IDs from the model and tokenizer + * + * This function extracts the end-of-sequence token IDs from the model. + * It first tries to get EOS IDs from the model's metadata, falling back + * to the tokenizer's default EOS token. + * + * @param tokenizer Initialized tokenizer instance + * @param module The model module + * @return std::unordered_set Set of EOS token IDs + */ +ET_EXPERIMENTAL std::unordered_set +get_eos_ids(tokenizers::Tokenizer *tokenizer, Module *module); + +/** + * @brief Creates a TextLLMRunner instance with dependency injection + * + * This factory function creates and initializes a TextLLMRunner with all + * necessary components for text generation using the specified model and + * tokenizer. + * + * @param model_path Path to the model file + * @param tokenizer Initialized tokenizer instance + * @param data_path Optional path to additional data required by the model + * @param temperature Optional temperature parameter for controlling randomness + * (deprecated) + * @param method_name Name of the method to execute in the model + * @param load_mode Loading strategy for the model file. Defaults to + * MmapUseMlockIgnoreErrors which uses mmap to avoid loading the entire + * model into RAM and attempts to pin pages with mlock for lower inference + * latency, gracefully falling back to standard mmap if mlock is unavailable. + * @return std::unique_ptr Initialized TextLLMRunner instance, or + * nullptr on failure + */ +ET_EXPERIMENTAL std::unique_ptr create_text_llm_runner( + const std::string &model_path, + std::unique_ptr<::tokenizers::Tokenizer> tokenizer, + std::optional data_path, float temperature = -1.0f, + const std::string &method_name = "forward", + Module::LoadMode load_mode = Module::LoadMode::MmapUseMlockIgnoreErrors); + +/** + * @brief Creates a TextLLMRunner instance with dependency injection + * + * This factory function creates and initializes a TextLLMRunner with all + * necessary components for text generation using the specified model and + * tokenizer. + * + * @param model_path Path to the model file + * @param tokenizer Initialized tokenizer instance + * @param data_files Vector of paths to additional data required by the model + * @param temperature Optional temperature parameter for controlling randomness + * (deprecated) + * @param event_tracer Optional event tracer for profiling + * @param method_name Name of the method to execute in the model + * @param load_mode Loading strategy for the model file. Defaults to + * MmapUseMlockIgnoreErrors which uses mmap to avoid loading the entire + * model into RAM and attempts to pin pages with mlock for lower inference + * latency, gracefully falling back to standard mmap if mlock is unavailable. + * @return std::unique_ptr Initialized TextLLMRunner instance, or + * nullptr on failure + */ +ET_EXPERIMENTAL std::unique_ptr create_text_llm_runner( + const std::string &model_path, + std::unique_ptr<::tokenizers::Tokenizer> tokenizer, + std::vector data_files = {}, float temperature = -1.0f, + std::unique_ptr<::executorch::runtime::EventTracer> event_tracer = nullptr, + const std::string &method_name = "forward", + Module::LoadMode load_mode = Module::LoadMode::MmapUseMlockIgnoreErrors); + +/** + * @brief Creates a MultimodalRunner instance with dependency injection + * + * This factory function creates and initializes a MultimodalRunner with all + * necessary components for multimodal text generation. + * + * @param model_path Path to the model file + * @param tokenizer Initialized tokenizer instance + * @param data_path Optional path to additional .ptd required by the model + * @return std::unique_ptr Initialized MultimodalRunner + * instance, or nullptr on failure + */ +ET_EXPERIMENTAL std::unique_ptr create_multimodal_runner( + const std::string &model_path, + std::unique_ptr<::tokenizers::Tokenizer> tokenizer, + std::optional data_path = std::nullopt, + Module::LoadMode load_mode = Module::LoadMode::File); + +} // namespace executorch::extension::llm diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_decoder_runner.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_decoder_runner.h new file mode 100644 index 0000000000..de4fcc7495 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_decoder_runner.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once + +#include +#include + +namespace executorch::extension::llm { + +class ET_EXPERIMENTAL MultimodalDecoderRunner + : public executorch::extension::llm::TextDecoderRunner { +public: + explicit MultimodalDecoderRunner(Module *module, IOManager *io_manager) + : TextDecoderRunner(module, io_manager) {} + + /** + * Step the LLM Decoder with the given tokens and start position. + * @param tokens The tokens to the LLM. + * @param start_pos The start position of the tokens. + * @return The logits tensor. + */ + inline executorch::runtime::Result + step(executorch::extension::TensorPtr &tokens, int64_t start_pos) override { + // run token embedding + auto token_embedding_result = + module_->execute(kTokenEmbeddingMethod, tokens); + if (!token_embedding_result.ok()) { + return token_embedding_result.error(); + } + auto token_embedding_outputs = std::move(*token_embedding_result); + + // Return the logits tensor + return decode(token_embedding_outputs[0], start_pos); + } + + /** + * Decode the embeddings to logits. + * @param embeddings The embeddings tensor. + * @param start_pos The start position of the embeddings. + * @return The logits tensor. + */ + inline executorch::runtime::Result + decode(const runtime::EValue &embeddings, int64_t start_pos) { + auto start_pos_tensor = ::executorch::extension::from_blob( + &start_pos, {1}, executorch::aten::ScalarType::Long); + // run text model + auto outputs_result = + module_->execute(kTextModelMethod, {embeddings, start_pos_tensor}); + if (!outputs_result.ok()) { + return outputs_result.error(); + } + auto outputs_res = std::move(*outputs_result); + + ET_CHECK_MSG(outputs_res.size() == 1, + "More then one output returned from executing LLM."); + ET_CHECK_MSG(outputs_res[0].isTensor(), + "Non Tensor Output returned from executing LLM"); + + // Return the logits tensor + return outputs_res[0].toTensor(); + } + + /** + * Load the Module for text decode purpose. + * @return The error code. + */ + inline executorch::runtime::Error load() override { + if (is_method_loaded()) { + return executorch::runtime::Error::Ok; + } + ET_CHECK_OK_OR_RETURN_ERROR(module_->load_method(kTokenEmbeddingMethod)); + ET_CHECK_OK_OR_RETURN_ERROR(module_->load_method(kTextModelMethod)); + return executorch::runtime::Error::Ok; + } + + /** + * Check if the required methods in the Module is loaded. + * @return True if the Module is loaded, false otherwise. + */ + inline bool is_method_loaded() override { + executorch::runtime::Result> methods_res = + module_->method_names(); + if (methods_res.error() != executorch::runtime::Error::Ok) { + ET_CHECK_MSG(false, "Failed to get method names"); + } + std::unordered_set methods = methods_res.get(); + bool methods_exist = methods.find(kTokenEmbeddingMethod) != methods.end() && + methods.find(kTextModelMethod) != methods.end(); + if (!methods_exist) { + for (const auto &method : methods) { + ET_LOG(Error, "Method: %s", method.c_str()); + } + ET_CHECK_MSG(methods_exist, + "Missing required methods (%s, %s) in the model", + kTokenEmbeddingMethod, kTextModelMethod); + } + bool methods_loaded = module_->is_method_loaded(kTokenEmbeddingMethod) && + module_->is_method_loaded(kTextModelMethod); + return methods_loaded; + } +}; + +} // namespace executorch::extension::llm diff --git a/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_input.h b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_input.h new file mode 100644 index 0000000000..e0e58d3bb5 --- /dev/null +++ b/packages/react-native-executorch/third-party/include/executorch/extension/llm/runner/multimodal_input.h @@ -0,0 +1,384 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +// @lint-ignore-every CLANGTIDY facebook-hte-Deprecated +// A generic multimodal input class that can hold either image or text data. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace executorch::extension::llm { + +/** + * A generic class to hold either image, text, or audio data for multimodal + * inputs. This allows the generate() API to take a std::vector of these objects + * instead of separate image, text, and audio parameters. + */ +class ET_EXPERIMENTAL MultimodalInput { +public: + /// Type of multimodal input data + enum class Type { + TEXT, ///< Text string input + TOKENS, ///< Tokenizer encoded input (vector of token IDs) + IMAGE, ///< Processed image input + AUDIO, ///< Processed audio input + RAW_AUDIO, ///< Raw unprocessed audio input (straight from audio file) + UNSUPPORTED ///< Unsupported input type + }; + + /** + * Return a human-readable name for a MultimodalInput::Type. + * Preferred for logging and debugging; returns string literals. + */ + static constexpr const char *TypeName(Type t) noexcept { + switch (t) { + case Type::TEXT: + return "text"; + case Type::TOKENS: + return "tokens"; + case Type::IMAGE: + return "image"; + case Type::AUDIO: + return "audio"; + case Type::RAW_AUDIO: + return "raw_audio"; + default: + return "unknown"; + } + } + + /** Convenience wrapper that returns a std::string. */ + static inline std::string TypeToString(Type t) { return TypeName(t); } + + // Constructors + explicit MultimodalInput(const std::string &text) : data_(text) {} + explicit MultimodalInput(std::string &&text) : data_(std::move(text)) {} + explicit MultimodalInput(const std::vector &tokens) + : data_(tokens) {} + explicit MultimodalInput(std::vector &&tokens) + : data_(std::move(tokens)) {} + explicit MultimodalInput(const Image &image) : data_(image) {} + explicit MultimodalInput(Image &&image) : data_(std::move(image)) {} + explicit MultimodalInput(const Audio &audio) : data_(audio) {} + explicit MultimodalInput(Audio &&audio) : data_(std::move(audio)) {} + explicit MultimodalInput(const RawAudio &raw_audio) : data_(raw_audio) {} + explicit MultimodalInput(RawAudio &&raw_audio) + : data_(std::move(raw_audio)) {} + + // Copy constructor and assignment + MultimodalInput(const MultimodalInput &other) = default; + MultimodalInput &operator=(const MultimodalInput &other) = default; + + // Move constructor and assignment + MultimodalInput(MultimodalInput &&other) noexcept = default; + MultimodalInput &operator=(MultimodalInput &&other) noexcept = default; + + // Destructor + ~MultimodalInput() = default; + + /** + * Check if this input contains text data. + * @return true if this input contains text, false otherwise. + */ + bool is_text() const noexcept { + return std::holds_alternative(data_); + } + + /** + * Check if this input contains pre-tokenized data. + */ + bool is_tokens() const noexcept { + return std::holds_alternative>(data_); + } + + /** + * Check if this input contains image data. + * @return true if this input contains an image, false otherwise. + */ + bool is_image() const noexcept { + return std::holds_alternative(data_); + } + + /** + * Check if this input contains audio data. + * @return true if this input contains audio, false otherwise. + */ + bool is_audio() const noexcept { + return std::holds_alternative