From dda221501b979703cf6a2b22503bbfc38653a8d5 Mon Sep 17 00:00:00 2001 From: Ryan Hill Date: Thu, 6 May 2021 18:26:45 -0700 Subject: [PATCH] Fix build error --- .../main/java/ai/onnxruntime/OnnxRuntime.java | 16 ++++++++++++---- onnxruntime/test/framework/session_state_test.cc | 14 ++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/java/src/main/java/ai/onnxruntime/OnnxRuntime.java b/java/src/main/java/ai/onnxruntime/OnnxRuntime.java index bee63f566d..2b5b5d9e0c 100644 --- a/java/src/main/java/ai/onnxruntime/OnnxRuntime.java +++ b/java/src/main/java/ai/onnxruntime/OnnxRuntime.java @@ -36,6 +36,11 @@ final class OnnxRuntime { /** The short name of the ONNX runtime JNI shared library */ static final String ONNXRUNTIME_JNI_LIBRARY_NAME = "onnxruntime4j_jni"; + /** The short name of the ONNX runtime shared provider library */ + static final String ONNXRUNTIME_LIBRARY_SHARED_NAME = "onnxruntime_providers_shared"; + /** The short name of the ONNX runtime cuda provider library */ + static final String ONNXRUNTIME_LIBRARY_CUDA_NAME = "onnxruntime_providers_cuda"; + private static final String OS_ARCH_STR = initOsArch(); private static boolean loaded = false; @@ -93,8 +98,10 @@ final class OnnxRuntime { } Path tempDirectory = isAndroid() ? null : Files.createTempDirectory("onnxruntime-java"); try { - load(tempDirectory, ONNXRUNTIME_LIBRARY_NAME); - load(tempDirectory, ONNXRUNTIME_JNI_LIBRARY_NAME); + load(tempDirectory, ONNXRUNTIME_LIBRARY_SHARED_NAME, false); + load(tempDirectory, ONNXRUNTIME_LIBRARY_CUDA_NAME, false); + load(tempDirectory, ONNXRUNTIME_LIBRARY_NAME, true); + load(tempDirectory, ONNXRUNTIME_JNI_LIBRARY_NAME, true); ortApiHandle = initialiseAPIBase(ORT_API_VERSION_7); providers = initialiseProviders(ortApiHandle); loaded = true; @@ -138,7 +145,7 @@ final class OnnxRuntime { * @param library The bare name of the library. * @throws IOException If the file failed to read or write. */ - private static void load(Path tempDirectory, String library) throws IOException { + private static void load(Path tempDirectory, String library, boolean system_load) throws IOException { // On Android, we simply use System.loadLibrary if (isAndroid()) { System.loadLibrary("onnxruntime4j_jni"); @@ -201,7 +208,8 @@ final class OnnxRuntime { os.write(buffer, 0, readBytes); } } - System.load(tempFile.getAbsolutePath()); + if (system_load) + System.load(tempFile.getAbsolutePath()); logger.log(Level.FINE, "Loaded native library '" + library + "' from resource path"); } } finally { diff --git a/onnxruntime/test/framework/session_state_test.cc b/onnxruntime/test/framework/session_state_test.cc index 42bd593b61..689dd94d19 100644 --- a/onnxruntime/test/framework/session_state_test.cc +++ b/onnxruntime/test/framework/session_state_test.cc @@ -19,10 +19,9 @@ #include "core/util/thread_utils.h" #include "gtest/gtest.h" #include "test/test_environment.h" +#include "test/util/include/default_providers.h" -#ifdef USE_CUDA -#include "core/providers/cuda/cuda_execution_provider.h" -#elif USE_ROCM +#ifdef USE_ROCM #include "core/providers/rocm/rocm_execution_provider.h" #endif @@ -189,8 +188,7 @@ static void TestCPUNodePlacement(const std::basic_string& model_uri, ExecutionProviders execution_providers; #if defined(USE_CUDA) - CUDAExecutionProviderInfo cuda_epi; - ASSERT_STATUS_OK(execution_providers.Add(onnxruntime::kCudaExecutionProvider, std::make_unique(cuda_epi))); + ASSERT_STATUS_OK(execution_providers.Add(onnxruntime::kCudaExecutionProvider, DefaultCudaExecutionProvider())); #elif defined(USE_ROCM) ROCMExecutionProviderInfo rocm_epi; ASSERT_STATUS_OK(execution_providers.Add(onnxruntime::kRocmExecutionProvider, std::make_unique(rocm_epi))); @@ -248,9 +246,9 @@ TEST(SessionStateTest, CPUPlacementTest3) { TestCPUNodePlacement(ORT_TSTR("testdata/cpu_fallback_pattern_3.onnx"), expected_cpu_nodes, expected_gpu_nodes); } TEST(SessionStateTest, CPUPlacementTest4) { - // Currently, the behaviour is different for RocM and CUDA EP as Rocm EP is missing a valid kernel - // for ReduceSum for int64 type. This causes the backward trace in GetCpuPreferredNodes to stop - // earlier. The expected values can be modified to match CUDA once the RocM EP kernel is updated + // Currently, the behaviour is different for RocM and CUDA EP as Rocm EP is missing a valid kernel + // for ReduceSum for int64 type. This causes the backward trace in GetCpuPreferredNodes to stop + // earlier. The expected values can be modified to match CUDA once the RocM EP kernel is updated #if defined(USE_CUDA) std::unordered_set expected_cpu_nodes = {"range", "reduce", "const1"}; std::unordered_set expected_gpu_nodes = {"size0", "expand"};