-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-51243][CORE][ML] Configurable allow native BLAS #49986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,11 @@ | |
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-tags_${scala.binary.version}</artifactId> | ||
</dependency> | ||
<dependency> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still a bit worried about the dependency change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dep change can be eliminated if logging is unnecessary. |
||
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-common-utils_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- | ||
This spark-tags test-dep is needed even though it isn't used in this module, otherwise testing-cmds that exclude | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,13 @@ package org.apache.spark.mllib.linalg | |
|
||
import dev.ludovic.netlib.arpack.{ARPACK => NetlibARPACK, JavaARPACK => NetlibJavaARPACK, NativeARPACK => NetlibNativeARPACK} | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.util.SparkEnvUtils | ||
|
||
/** | ||
* ARPACK routines for MLlib's vectors and matrices. | ||
*/ | ||
private[spark] object ARPACK extends Serializable { | ||
private[spark] object ARPACK extends Serializable with Logging { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should I move |
||
|
||
@transient private var _javaARPACK: NetlibARPACK = _ | ||
@transient private var _nativeARPACK: NetlibARPACK = _ | ||
|
@@ -36,8 +39,12 @@ private[spark] object ARPACK extends Serializable { | |
|
||
private[spark] def nativeARPACK: NetlibARPACK = { | ||
if (_nativeARPACK == null) { | ||
_nativeARPACK = | ||
_nativeARPACK = if (SparkEnvUtils.allowNativeBlas) { | ||
try { NetlibNativeARPACK.getInstance } catch { case _: Throwable => javaARPACK } | ||
} else { | ||
logInfo("Disable native ARPACK because netlib.allowNativeBlas is false.") | ||
javaARPACK | ||
} | ||
} | ||
_nativeARPACK | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,44 +17,14 @@ | |
|
||
package org.apache.spark.mllib.linalg | ||
|
||
import dev.ludovic.netlib.blas.{BLAS => NetlibBLAS, JavaBLAS => NetlibJavaBLAS, NativeBLAS => NetlibNativeBLAS} | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.ml.linalg.BLAS.{getBLAS, nativeBLAS} | ||
|
||
/** | ||
* BLAS routines for MLlib's vectors and matrices. | ||
*/ | ||
private[spark] object BLAS extends Serializable with Logging { | ||
|
||
@transient private var _javaBLAS: NetlibBLAS = _ | ||
@transient private var _nativeBLAS: NetlibBLAS = _ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the duplicated instance creation and call |
||
private val nativeL1Threshold: Int = 256 | ||
|
||
// For level-1 function dspmv, use javaBLAS for better performance. | ||
private[spark] def javaBLAS: NetlibBLAS = { | ||
if (_javaBLAS == null) { | ||
_javaBLAS = NetlibJavaBLAS.getInstance | ||
} | ||
_javaBLAS | ||
} | ||
|
||
// For level-3 routines, we use the native BLAS. | ||
private[spark] def nativeBLAS: NetlibBLAS = { | ||
if (_nativeBLAS == null) { | ||
_nativeBLAS = | ||
try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS } | ||
} | ||
_nativeBLAS | ||
} | ||
|
||
private[spark] def getBLAS(vectorSize: Int): NetlibBLAS = { | ||
if (vectorSize < nativeL1Threshold) { | ||
javaBLAS | ||
} else { | ||
nativeBLAS | ||
} | ||
} | ||
|
||
/** | ||
* y += a * x | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libopenblas-base
is removed in Debian 12 and Ubuntu 24.04,libopenblas-dev
should be used instead.https://github.com/luhenry/netlib/blob/6835050840ead1a724e2f305875c92d7cc21f834/.github/workflows/build-and-test.yml#L31
also
update-alternatives --config libblas.so.3
does not work, and it's variant in different CPU-arch OS.Given it already allows using
-Ddev.ludovic.netlib.lapack.nativeLib=...
to choose the native libraries, I would suggest eliminating how to usealternatives
to manage the OS default library in our docs.