Skip to content

Commit 265f798

Browse files
committed
[SPARK-51243][CORE][ML] Configurable allow native BLAS
1 parent e1f7851 commit 265f798

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ class SparkContext(config: SparkConf) extends Logging {
432432

433433
SparkContext.supplementJavaModuleOptions(_conf)
434434
SparkContext.supplementJavaIPv6Options(_conf)
435+
SparkContext.supplementBlasOptions(_conf)
435436

436437
_driverLogger = DriverLogger(_conf)
437438

@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
34363437
supplement(DRIVER_JAVA_OPTIONS)
34373438
supplement(EXECUTOR_JAVA_OPTIONS)
34383439
}
3440+
3441+
private def supplementCustomOptions(conf: SparkConf): Unit = {
3442+
conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
3443+
def supplement(key: OptionalConfigEntry[String]): Unit = {
3444+
val v = conf.get(key) match {
3445+
case Some(opts) => s"-Dspark.ml.allowNativeBlas=$allowNativeBlas $opts"
3446+
case None => s"-Dspark.ml.allowNativeBlas=$allowNativeBlas"
3447+
}
3448+
conf.set(key.key, v)
3449+
}
3450+
supplement(DRIVER_JAVA_OPTIONS)
3451+
supplement(EXECUTOR_JAVA_OPTIONS)
3452+
}
3453+
}
34393454
}
34403455

34413456
/**

launcher/src/main/java/org/apache/spark/launcher/SparkSubmitCommandBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ private List<String> buildSparkSubmitCommand(Map<String, String> env)
332332
config.get(SparkLauncher.DRIVER_EXTRA_LIBRARY_PATH));
333333
}
334334

335+
if (config.containsKey("spark.ml.allowNativeBlas")) {
336+
String preferNativeBlas = config.get("spark.ml.allowNativeBlas");
337+
addOptionString(cmd, "-Dspark.ml.allowNativeBlas=" + preferNativeBlas);
338+
}
339+
335340
// SPARK-36796: Always add some JVM runtime default options to submit command
336341
addOptionString(cmd, JavaModuleOptions.defaultModuleOptions());
337342
addOptionString(cmd, "-Dderby.connection.requireAuthentication=false");

mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ private[spark] object BLAS extends Serializable {
3939
// For level-3 routines, we use the native BLAS.
4040
private[spark] def nativeBLAS: NetlibBLAS = {
4141
if (_nativeBLAS == null) {
42-
_nativeBLAS =
43-
try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS }
42+
_nativeBLAS = System.getProperty("spark.ml.allowNativeBlas", "true") match {
43+
case "true" =>
44+
try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS }
45+
case _ => javaBLAS
46+
}
4447
}
4548
_nativeBLAS
4649
}

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,10 @@ private[spark] class Client(
10491049

10501050
javaOpts += s"-Djava.net.preferIPv6Addresses=${Utils.preferIPv6}"
10511051

1052+
sparkConf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
1053+
javaOpts += s"-Dspark.ml.allowNativeBlas=$allowNativeBlas"
1054+
}
1055+
10521056
// SPARK-37106: To start AM with Java 17, `JavaModuleOptions.defaultModuleOptions`
10531057
// is added by default.
10541058
javaOpts += JavaModuleOptions.defaultModuleOptions()

0 commit comments

Comments
 (0)