-
Notifications
You must be signed in to change notification settings - Fork 710
Add onnxruntime as wasi-nn backend #4485
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
dongsheng28849455
wants to merge
10
commits into
bytecodealliance:main
Choose a base branch
from
dongsheng28849455:feature/support_onnx_for_wasi-nn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56b6195
Add onnxruntime as wasi-nn backend
dongsheng28849455 6cab94c
follow up some review comments
dongsheng28849455 c866d05
clang-format
dongsheng28849455 4b50341
remove global context
dongsheng28849455 801eb2b
put checks under the lock
dongsheng28849455 cd3cb6c
use WASM_ENABLE_WASI_EPHEMERAL_NN
dongsheng28849455 38e9d2b
tensor type will not support legacy wasi-nn abi
dongsheng28849455 fa6c3a3
using the CMake config file
dongsheng28849455 0c164b6
Manually set the imported target with name space
dongsheng28849455 c70e22e
follow up comments
dongsheng28849455 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2025 Sony Semiconductor Solutions Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
# Find ONNX Runtime library | ||
# | ||
# This module defines the following variables: | ||
# | ||
# :: | ||
# | ||
# onnxruntime_FOUND - True if onnxruntime is found | ||
# onnxruntime_INCLUDE_DIRS - Include directories for onnxruntime | ||
# onnxruntime_LIBRARIES - List of libraries for onnxruntime | ||
# onnxruntime_VERSION - Version of onnxruntime | ||
# | ||
# :: | ||
# | ||
# Example usage: | ||
# | ||
# find_package(onnxruntime) | ||
# if(onnxruntime_FOUND) | ||
# target_link_libraries(app onnxruntime) | ||
# endif() | ||
|
||
# First try to find ONNX Runtime using the CMake config file | ||
# FIXME: This is a temporary workaround for ONNX Runtime's broken CMake config on Linux. | ||
# See https://github.com/microsoft/onnxruntime/issues/25279 | ||
# Once the upstream issue is fixed, this conditional can be safely removed. | ||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
find_package(onnxruntime CONFIG QUIET) | ||
if(onnxruntime_FOUND) | ||
return() | ||
endif() | ||
endif() | ||
|
||
# If not found via CMake config, try to find manually | ||
find_path(onnxruntime_INCLUDE_DIR | ||
NAMES onnxruntime_c_api.h | ||
PATHS | ||
/usr/include | ||
/usr/local/include | ||
/opt/onnxruntime/include | ||
$ENV{ONNXRUNTIME_ROOT}/include | ||
${CMAKE_CURRENT_LIST_DIR}/../../../../.. | ||
) | ||
|
||
find_library(onnxruntime_LIBRARY | ||
NAMES onnxruntime | ||
PATHS | ||
/usr/lib | ||
/usr/local/lib | ||
/opt/onnxruntime/lib | ||
$ENV{ONNXRUNTIME_ROOT}/lib | ||
${CMAKE_CURRENT_LIST_DIR}/../../../../.. | ||
) | ||
|
||
# Try to determine version from header file | ||
if(onnxruntime_INCLUDE_DIR) | ||
file(STRINGS "${onnxruntime_INCLUDE_DIR}/onnxruntime_c_api.h" onnxruntime_version_str | ||
REGEX "^#define[\t ]+ORT_API_VERSION[\t ]+[0-9]+") | ||
|
||
if(onnxruntime_version_str) | ||
string(REGEX REPLACE "^#define[\t ]+ORT_API_VERSION[\t ]+([0-9]+)" "\\1" | ||
onnxruntime_VERSION "${onnxruntime_version_str}") | ||
endif() | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(onnxruntime | ||
REQUIRED_VARS onnxruntime_LIBRARY onnxruntime_INCLUDE_DIR | ||
VERSION_VAR onnxruntime_VERSION | ||
) | ||
|
||
if(onnxruntime_FOUND) | ||
set(onnxruntime_LIBRARIES ${onnxruntime_LIBRARY}) | ||
set(onnxruntime_INCLUDE_DIRS ${onnxruntime_INCLUDE_DIR}) | ||
|
||
if(NOT TARGET onnxruntime::onnxruntime) | ||
add_library(onnxruntime::onnxruntime UNKNOWN IMPORTED) | ||
set_target_properties(onnxruntime::onnxruntime PROPERTIES | ||
IMPORTED_LOCATION "${onnxruntime_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_INCLUDE_DIRS}" | ||
) | ||
endif() | ||
endif() | ||
|
||
mark_as_advanced(onnxruntime_INCLUDE_DIR onnxruntime_LIBRARY) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.