Skip to content

Commit

Permalink
Wrapper for vendor-specific ONNXIFI libraries (onnx#1154)
Browse files Browse the repository at this point in the history
Add a library (onnxifi.dll/libonnxifi.so/libonnxifi.dylib), which finds and load ONNXIFI implementations in the system, and exposes all their backends under a single interface.
With this library, applications can just use

  onnxifi_load(ONNXIFI_LOADER_FLAG_VERSION_1_0, NULL, &library);

and get all ONNXIFI backends in the system.

The libraries are searched in the following directories:
- GNU/Linux: /usr/lib
- macOS: /opt/onnx/lib
- Windows: system directory (usually C:\Windows\System32)
- Default location can be overriden with CMake configuration-time variable ONNXIFI_SEARCH_DIR

Vendor-specific libraries must follow the rules below to be successfully found:
- Library filename must be onnxifi-${suffix}.dll (Windows), libonnxifi-${suffix}.dylib (Mac), or libonnxifi-${suffix}.so (Linux and other OSes)
  • Loading branch information
Maratyszcza authored and bddppq committed Aug 29, 2018
1 parent 79027b3 commit 780dcbc
Show file tree
Hide file tree
Showing 2 changed files with 1,005 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,29 @@ endif()
target_include_directories(onnxifi_loader PUBLIC onnx)
target_include_directories(onnxifi_loader PUBLIC ${ONNX_ROOT})

# ---[ ONNXIFI wrapper
add_library(onnxifi_wrapper MODULE onnx/onnxifi_wrapper.c)
set_target_properties(onnxifi_wrapper PROPERTIES
C_STANDARD 99
C_EXTENSIONS NO
OUTPUT_NAME "onnxifi"
POSITION_INDEPENDENT_CODE YES)
target_link_libraries(onnxifi_wrapper PRIVATE onnxifi_loader onnxifi)
if(DEFINED ONNXIFI_SEARCH_DIR)
target_compile_definitions(onnxifi_wrapper PRIVATE "ONNXIFI_SEARCH_DIR=\"${ONNXIFI_SEARCH_DIR}\"")
endif()
if(WIN32)
if(MSVC)
target_compile_definitions(onnxifi_wrapper PRIVATE "ONNXIFI_PUBLIC=__declspec(dllexport)")
else()
target_compile_definitions(onnxifi_wrapper PRIVATE "ONNXIFI_PUBLIC=__attribute__((__dllexport__))")
endif()
endif()
if(APPLE)
# By default CMake would use .so suffix on Mac
set_target_properties(onnxifi_wrapper PROPERTIES SUFFIX ".dylib")
endif()

# ---[ ONNXIFI dummy backend
add_library(onnxifi_dummy SHARED onnx/onnxifi_dummy.c)
target_link_libraries(onnxifi_dummy PUBLIC onnxifi ${CMAKE_DL_LIBS})
Expand Down
Loading

0 comments on commit 780dcbc

Please sign in to comment.