Skip to content

Pacowong/wasm static library #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,44 @@ jobs:
- store_artifacts:
path: /Users/distiller/project/onnxruntime_xcframework.zip
destination: onnxruntime_xcframework.zip

build-and-test-wasm:
macos:
xcode: << pipeline.parameters.xcode-version >>
resource_class: << pipeline.parameters.macos-resource-class >>

shell: /bin/bash --login -o pipefail

steps:
- run:
name: check Xcode version and Python 3
command: |
/usr/bin/xcodebuild -version
python3 --version
python --version
which python3
echo $CIRCLE_WORKING_DIRECTORY
- checkout
- run:
name: create directory to store the library
command: |
mkdir -p $HOME/onnxlibrary/macabi_release_v20230327_2320
- run:
name: install tools for build
command: |
brew install cmake
pip install -r ${CIRCLE_WORKING_DIRECTORY}/requirements-dev.txt
- run:
name: build static wasm library
command: |
export PYTHONPATH=${CIRCLE_WORKING_DIRECTORY}/tools/python:$PYTHONPATH
bash ${CIRCLE_WORKING_DIRECTORY}/build.sh --build_wasm_static_lib --enable_wasm_simd --enable_wasm_threads

workflows:
version: 2
build-and-test-xcframework:
jobs:
- build-and-test-xcframework
build-and-test-wasm:
jobs:
- build-and-test-wasm
14 changes: 9 additions & 5 deletions onnxruntime/core/providers/coreml/model/model.mm
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ void ProfileComputePlan(NSURL* compileUrl, MLModelConfiguration* config) {
#define HAS_COREMLOPTIMIZATIONHINT 0
#endif

API_AVAILABLE_COREML8
API_AVAILABLE(macos(14.4), ios(17.4), tvos(17.4), watchos(10.4))
void ConfigureOptimizationHints(MLModelConfiguration* config, const CoreMLOptions& coreml_options) {
if (@available(macOS 14.4, iOS 17.4, *)) {
#if HAS_COREMLOPTIMIZATIONHINT
MLOptimizationHints* optimizationHints = [[MLOptimizationHints alloc] init];
if (coreml_options.UseStrategy("FastPrediction")) {
Expand All @@ -383,6 +384,7 @@ void ConfigureOptimizationHints(MLModelConfiguration* config, const CoreMLOption
// not set
}
#endif
}
}

Status CompileOrReadCachedModel(NSURL* modelUrl, const CoreMLOptions& coreml_options,
Expand Down Expand Up @@ -547,10 +549,12 @@ Status Predict(const std::unordered_map<std::string, OnnxTensorData>& inputs,
}

// Set the specialization strategy to FastPrediction for macOS 10.15+
if (HAS_COREML8_OR_LATER) {
ConfigureOptimizationHints(config, coreml_options_);
} else {
LOGS(logger_, WARNING) << "iOS 17.4+/macOS 14.4+ or later is required to ConfigureOptimizationHints";
if (@available(macOS 14.4, iOS 17.4, *)) {
if (HAS_COREML8_OR_LATER) {
ConfigureOptimizationHints(config, coreml_options_);
} else {
LOGS(logger_, WARNING) << "iOS 17.4+/macOS 14.4+ or later is required to ConfigureOptimizationHints";
}
}

if (coreml_options_.ProfileComputePlan()) {
Expand Down
20 changes: 18 additions & 2 deletions onnxruntime/test/wasm/test_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@
#include "core/session/onnxruntime_cxx_api.h"

TEST(WebAssemblyTest, test) {
Ort::Env ort_env;
auto numInterOpsThreads = 4;
auto numIntraOpsThreads = 4;
// OrtThreadingOptions *threadingOptions;
// Ort::SessionOptions sessionOptions;
// sessionOptions.DisablePerSessionThreads();
// Ort::Env ort_env(threadingOptions, ORT_LOGGING_LEVEL_WARNING, "test");

OrtEnv* environment;
OrtThreadingOptions* envOpts = nullptr;
Ort::GetApi().CreateThreadingOptions(&envOpts);
Ort::GetApi().SetGlobalIntraOpNumThreads(envOpts, numIntraOpsThreads);
Ort::GetApi().SetGlobalInterOpNumThreads(envOpts, numInterOpsThreads);
Ort::GetApi().SetGlobalSpinControl(envOpts, 1);
Ort::GetApi().CreateEnvWithGlobalThreadPools(ORT_LOGGING_LEVEL_WARNING, "test", envOpts, &environment);
Ort::Env ort_env = Ort::Env(environment);

// Ort::Env ort_env;
Ort::Session session{ort_env, "testdata/mul_1.onnx", Ort::SessionOptions{nullptr}};
auto memory_info = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU);

Expand Down Expand Up @@ -39,4 +55,4 @@ TEST(WebAssemblyTest, test) {
for (size_t i = 0; i != total_len; ++i) {
ASSERT_EQ(expected_data[i], result[i]);
}
}
}
Loading