Skip to content

Commit 3f23f5f

Browse files
committed
[JNI] Fixed the native library loading.
1 parent 32be4c2 commit 3f23f5f

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

modules/jni/src/main/scala/org/platanios/tensorflow/jni/TensorFlow.scala

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ package org.platanios.tensorflow.jni
1717

1818
import com.typesafe.scalalogging.Logger
1919
import org.slf4j.LoggerFactory
20+
2021
import java.io.{IOException, InputStream}
21-
import java.nio.file.{Files, LinkOption, Path, Paths, StandardCopyOption}
22+
import java.nio.file.{Files, Path, StandardCopyOption}
2223

2324
import scala.io.{Codec, Source}
24-
import scala.jdk.CollectionConverters._
2525

2626
/**
2727
* @author Emmanouil Antonios Platanios
@@ -41,22 +41,15 @@ object TensorFlow {
4141
/** TensorFlow ops library name. */
4242
private val OPS_LIB_NAME: String = "tensorflow_ops"
4343

44-
/** Current platform operating system. */
45-
private val os = {
44+
/** Current platform. */
45+
private val platform = {
4646
val name = System.getProperty("os.name").toLowerCase
4747
if (name.contains("linux")) "linux"
4848
else if (name.contains("os x") || name.contains("darwin")) "darwin"
4949
else if (name.contains("windows")) "windows"
5050
else name.replaceAll("\\s", "")
5151
}
5252

53-
/** Current platform architecture. */
54-
private val architecture = {
55-
val arch = System.getProperty("os.arch").toLowerCase
56-
if (arch == "amd64") "x86_64"
57-
else arch
58-
}
59-
6053
/** Loads the TensorFlow JNI bindings library along with the TensorFlow native library, if provided as a resource. */
6154
def load(): Unit = this synchronized {
6255
// If either:
@@ -83,7 +76,7 @@ object TensorFlow {
8376
}
8477
if (jniPaths.isEmpty) {
8578
throw new UnsatisfiedLinkError(
86-
s"Cannot find the TensorFlow JNI bindings for OS: $os, and architecture: $architecture. See " +
79+
s"Cannot find the TensorFlow JNI bindings for platform: $platform. See " +
8780
"https://github.com/eaplatanios/tensorflow_scala/tree/master/README.md for possible solutions " +
8881
"(such as building the library from source).")
8982
}
@@ -118,7 +111,7 @@ object TensorFlow {
118111
/** Maps the provided library name to a set of filenames, similar to [[System.mapLibraryName]], but considering all
119112
* combinations of `dylib` and `so` extensions, along with versioning for TensorFlow 2.x. */
120113
private def mapLibraryName(lib: String): Seq[String] = {
121-
if (os == "windows") {
114+
if (platform == "windows") {
122115
Seq(s"$lib.dll", s"$lib.lib")
123116
} else if (lib == JNI_LIB_NAME || lib == OPS_LIB_NAME) {
124117
Seq(s"lib$lib.so")
@@ -139,7 +132,7 @@ object TensorFlow {
139132
if (lib == LIB_NAME || lib == LIB_FRAMEWORK_NAME) {
140133
mapLibraryName(lib).map(name => (name, name))
141134
} else {
142-
mapLibraryName(lib).map(name => (name, s"native/$os-$architecture/$name"))
135+
mapLibraryName(lib).map(name => (name, s"native/$platform/$name"))
143136
}
144137
}
145138

0 commit comments

Comments
 (0)