From 905c7c4da9ec32374468ac1d2ab6248c84d3ce23 Mon Sep 17 00:00:00 2001 From: Wenbing Li Date: Fri, 10 Jun 2022 15:59:13 -0700 Subject: [PATCH] enable the extensions custom build for java and android --- cmake/external/extensions.cmake | 3 ++- .../main/native/ai_onnxruntime_OrtSession_SessionOptions.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/external/extensions.cmake b/cmake/external/extensions.cmake index 470172abefa4c..7bd8aeafbbaa2 100644 --- a/cmake/external/extensions.cmake +++ b/cmake/external/extensions.cmake @@ -23,7 +23,8 @@ endif() # when onnxruntime-extensions is not a subdirectory of onnxruntime, # output binary directory must be explicitly specified. -add_subdirectory(${onnxruntime_EXTENSIONS_PATH} ${onnxruntime_EXTENSIONS_PATH}/_subbuild EXCLUDE_FROM_ALL) +# and the output binary path is the same as CMake FetchContent pattern +add_subdirectory(${onnxruntime_EXTENSIONS_PATH} ${CMAKE_BINARY_DIR}/_deps/extensions-subbuild EXCLUDE_FROM_ALL) # target library or executable are defined in CMakeLists.txt of onnxruntime-extensions target_include_directories(ocos_operators PRIVATE ${RE2_INCLUDE_DIR} external/json/include) diff --git a/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c b/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c index ab129bb0eb840..edaad23e873e9 100644 --- a/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c +++ b/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c @@ -117,6 +117,10 @@ JNIEXPORT jlong JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_creat OrtSessionOptions* opts; checkOrtStatus(jniEnv,api,api->CreateSessionOptions(&opts)); checkOrtStatus(jniEnv,api,api->SetInterOpNumThreads(opts, 1)); +#ifdef ENABLE_EXTENSION_CUSTOM_OPS + // including all custom ops from onnxruntime-extensions + checkOrtStatus(jniEnv,api,api->EnableOrtCustomOps(opts)); +#endif // Commented out due to constant OpenMP warning as this API is invalid when running with OpenMP. // Not sure how to detect that from within the C API though. //checkOrtStatus(jniEnv,api,api->SetIntraOpNumThreads(opts, 1));