zhztheplayer commented on code in PR #10774:
URL: 
https://github.com/apache/incubator-gluten/pull/10774#discussion_r2372468041


##########
backends-velox/src/main/scala/org/apache/gluten/utils/SharedLibraryLoaderUtils.scala:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.utils
+
+import org.apache.gluten.config.GlutenConfig._
+import org.apache.gluten.exception.GlutenException
+import org.apache.gluten.jni.JniLibLoader
+import org.apache.gluten.spi.SharedLibraryLoader
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.internal.SparkConfigUtil._
+
+import java.io.FileInputStream
+import java.util.{Properties, ServiceLoader}
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
+
+object SharedLibraryLoaderUtils {
+  private def isMacOS: Boolean = {
+    val osName = System.getProperty("os.name")
+    osName.startsWith("Mac OS X") || osName.startsWith("macOS")
+  }
+
+  def load(conf: SparkConf, jni: JniLibLoader): Unit = {
+    val shouldLoad = conf.get(GLUTEN_LOAD_LIB_FROM_JAR)
+    if (!shouldLoad) {
+      return
+    }
+
+    val (osName, osVersion) = conf.get(GLUTEN_LOAD_LIB_OS) match {
+      case Some(os) =>
+        (
+          os,
+          conf
+            .get(GLUTEN_LOAD_LIB_OS_VERSION)
+            .getOrElse(
+              throw new GlutenException(
+                s"${GLUTEN_LOAD_LIB_OS_VERSION.key} must be specified when 
specifies the " +
+                  s"${GLUTEN_LOAD_LIB_OS.key}")))
+      case None if isMacOS =>
+        (System.getProperty("os.name"), System.getProperty("os.version"))
+      case None =>
+        val props = new Properties()
+        val in = new FileInputStream("/etc/os-release")
+        props.load(in)
+        (props.getProperty("NAME"), props.getProperty("VERSION"))
+    }
+
+    val loaders = ServiceLoader
+      .load(classOf[SharedLibraryLoader])
+      .asScala
+      .filter(loader => loader.accepts(osName, osVersion))

Review Comment:
   For example, if user adds their own loader implementation of CentOS 9, does 
the code ensure their implementation is chosen over the built-in 
`SharedLibraryLoaderCentos9`?
   
   Can we add a simple priority API to `SharedLibraryLoader`, so the loading 
process is more deterministic?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to