Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
acdc066
v2-SNAPSHOT
luhenry Apr 26, 2021
eced8ea
Add JNI-based wrapper for BLAS
luhenry Apr 27, 2021
ef0a7b3
Print which implementation is currently running for benchmark
luhenry Apr 27, 2021
f7bc7e1
Add JDK17 profile, just in case.
luhenry Apr 27, 2021
676339b
Try JNIBLAS before ForeignLinkerBLAS
luhenry Apr 27, 2021
c46b546
Use Fortran symbols directly
luhenry Apr 28, 2021
2b8e251
Remove leftover debug comments
luhenry Apr 28, 2021
7e3300e
Rename dev.ludovic.netlib.blas.VectorizedBLAS to dev.ludovic.netlib.b…
luhenry Apr 28, 2021
f2eb51d
fixup! Rename dev.ludovic.netlib.blas.VectorizedBLAS to dev.ludovic.n…
luhenry Apr 28, 2021
ebeb566
Remove com.github.fommil from BLAS fully and WIP for LAPACK
luhenry Apr 27, 2021
6e230fd
Make sure critical JNI regions don't contain unecessary JNI calls
luhenry Apr 28, 2021
ea4672f
Do better error handling + Load org.netlib.util.*W types
luhenry Apr 28, 2021
d023607
Base implementation for LAPACK + Implement calls used by Spark
luhenry Apr 28, 2021
0d6cea6
Add native implementation for benchmarking JDK 8 and 11
luhenry Apr 28, 2021
f9cc171
Allow manual trigger of the workflow
luhenry Apr 28, 2021
7ab7051
Merge branch 'master' into jni-wrappers
luhenry Apr 28, 2021
9d2fc41
Relax the compiler warnings for now
luhenry Apr 28, 2021
e03e6e5
Fix installed dependencies
luhenry Apr 28, 2021
3eaf0d9
Implement some more BLAS calls in JNIBLAS
luhenry Apr 29, 2021
48fe143
Fix bound condition check
luhenry Apr 30, 2021
0b25182
Add code coverage information
luhenry Apr 30, 2021
f09c81f
Add scaffolding for JNIARPACK
luhenry Apr 30, 2021
96d15fe
Make sure license is consistent across all files
luhenry Apr 30, 2021
28d0d80
There might be cases where we want to make a release on a SNAPSHOT tag
luhenry Apr 30, 2021
4514d49
Add scaffolding for all ARPACK, BLAS, and LAPACK routines
luhenry Apr 30, 2021
c5eea70
Fix surefire:test
luhenry Apr 30, 2021
adab598
Add missing libarpack2-dev dependency on CI
luhenry Apr 30, 2021
7717097
Cache M2 repository to speed up CI
luhenry Apr 30, 2021
07c8a89
Relax caching across JDK versions
luhenry Apr 30, 2021
e72474b
Implement all BLAS routines for JNIBLAS
luhenry Apr 30, 2021
006f21c
Add generator for JNI
luhenry May 1, 2021
1cc5e62
Compiler complains that __ret may be uninitialized
luhenry May 2, 2021
44221fe
Generate function for NotImplemented + Reduce whitespace noise
luhenry May 2, 2021
768a473
Remove -Wno-unused-function and -Wno-unused-parameter warnings
luhenry May 2, 2021
9c29b6d
Generate the totality of jni.c for BLAS, ARPACK, and LAPACK
luhenry May 2, 2021
98e4284
Add null and index checks for double/float arrays
luhenry May 3, 2021
de18317
Cache more often
luhenry May 3, 2021
85c6e10
Use full name of library for dev.ludovic.netlib.{blas,lapack,arpack}.…
luhenry May 3, 2021
383a831
Skip unimplemented tests
luhenry May 3, 2021
74b43c7
Wrap calls to Objects.requireNonNull for consistency with checkIndex
luhenry May 3, 2021
c11fe1a
Add {BLAS,LAPACK,ARPACK}.getInstance helpers
luhenry May 3, 2021
f37fa20
Rename _*_offset parameters to offset*
luhenry May 3, 2021
2a960f9
Remove unused test resources and methods
luhenry May 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add JNI-based wrapper for BLAS
  • Loading branch information
luhenry committed Apr 27, 2021
commit eced8ea4743a9736d5c4a74b4d867ec392bf654c
8 changes: 8 additions & 0 deletions blas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ information or have any questions.
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions blas/src/main/java/dev/ludovic/netlib/NativeBLAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static NativeBLAS getInstance() {
} catch (Throwable t) {
Logger.getLogger(NativeBLAS.class.getName()).warning("Failed to load implementation from:dev.ludovic.netlib.blas.ForeignLinkerBLAS");
}
try {
return dev.ludovic.netlib.blas.JNIBLAS.getInstance();
} catch (Throwable t) {
Logger.getLogger(NativeBLAS.class.getName()).warning("Failed to load implementation from:dev.ludovic.netlib.blas.JNIBLAS");
}
throw new RuntimeException("Unable to load native implementation");
}
}
200 changes: 200 additions & 0 deletions blas/src/main/java/dev/ludovic/netlib/blas/JNIBLAS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
* Copyright 2020, 2021, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.blas;

import java.io.InputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermissions;

public final class JNIBLAS extends AbstractBLAS implements dev.ludovic.netlib.NativeBLAS {

private static final JNIBLAS instance = new JNIBLAS();

protected JNIBLAS() {
String osName = System.getProperty("os.name");
if (osName == null || osName.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}
String osArch = System.getProperty("os.arch");
if (osArch == null || osArch.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}

Path temp;
try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(
String.format("resources/native/%s-%s/libnetlibblasjni.so", osName, osArch))) {
assert resource != null;
Files.copy(resource, temp = Files.createTempFile("libnetlibblasjni.so", "",
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---"))),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException("Unable to load native implementation", e);
}

System.load(temp.toString());
}

public static dev.ludovic.netlib.NativeBLAS getInstance() {
return instance;
}

protected native double dasumK(int n, double[] x, int offsetx, int incx);

protected native float sasumK(int n, float[] x, int offsetx, int incx);

protected native void daxpyK(int n, double alpha, double[] x, int offsetx, int incx, double[] y, int offsety, int incy);

protected native void saxpyK(int n, float alpha, float[] x, int offsetx, int incx, float[] y, int offsety, int incy);

protected native void dcopyK(int n, double[] x, int offsetx, int incx, double[] y, int offsety, int incy);

protected native void scopyK(int n, float[] x, int offsetx, int incx, float[] y, int offsety, int incy);

protected native double ddotK(int n, double[] x, int offsetx, int incx, double[] y, int offsety, int incy);

protected native float sdotK(int n, float[] x, int offsetx, int incx, float[] y, int offsety, int incy);

protected native float sdsdotK(int n, float sb, float[] sx, int offsetsx, int incsx, float[] sy, int offsetsy, int incsy);

protected native void dgbmvK(String trans, int m, int n, int kl, int ku, double alpha, double[] a, int offseta, int lda, double[] x, int offsetx, int incx, double beta, double[] y, int offsety, int incy);

protected native void sgbmvK(String trans, int m, int n, int kl, int ku, float alpha, float[] a, int offseta, int lda, float[] x, int offsetx, int incx, float beta, float[] y, int offsety, int incy);

protected native void dgemmK(String transa, String transb, int m, int n, int k, double alpha, double[] a, int offseta, int lda, double[] b, int offsetb, int ldb, double beta, double[] c, int offsetc, int ldc);

protected native void sgemmK(String transa, String transb, int m, int n, int k, float alpha, float[] a, int offseta, int lda, float[] b, int offsetb, int ldb, float beta, float[] c, int offsetc, int ldc);

protected native void dgemvK(String trans, int m, int n, double alpha, double[] a, int offseta, int lda, double[] x, int offsetx, int incx, double beta, double[] y, int offsety, int incy);

protected native void sgemvK(String trans, int m, int n, float alpha, float[] a, int offseta, int lda, float[] x, int offsetx, int incx, float beta, float[] y, int offsety, int incy);

protected native void dgerK(int m, int n, double alpha, double[] x, int offsetx, int incx, double[] y, int offsety, int incy, double[] a, int offseta, int lda);

protected native void sgerK(int m, int n, float alpha, float[] x, int offsetx, int incx, float[] y, int offsety, int incy, float[] a, int offseta, int lda);

protected native double dnrm2K(int n, double[] x, int offsetx, int incx);

protected native float snrm2K(int n, float[] x, int offsetx, int incx);

protected native void drotK(int n, double[] dx, int offsetdx, int incx, double[] dy, int offsetdy, int incy, double c, double s);

protected native void srotK(int n, float[] sx, int offsetsx, int incx, float[] sy, int offsetsy, int incy, float c, float s);

protected native void drotmK(int n, double[] dx, int offsetdx, int incx, double[] dy, int offsetdy, int incy, double[] dparam, int offsetdparam);

protected native void srotmK(int n, float[] sx, int offsetsx, int incx, float[] sy, int offsetsy, int incy, float[] sparam, int offsetsparam);

protected native void drotmgK(org.netlib.util.doubleW dd1, org.netlib.util.doubleW dd2, org.netlib.util.doubleW dx1, double dy1, double[] dparam, int offsetdparam);

protected native void srotmgK(org.netlib.util.floatW sd1, org.netlib.util.floatW sd2, org.netlib.util.floatW sx1, float sy1, float[] sparam, int offsetsparam);

protected native void dsbmvK(String uplo, int n, int k, double alpha, double[] a, int offseta, int lda, double[] x, int offsetx, int incx, double beta, double[] y, int offsety, int incy);

protected native void ssbmvK(String uplo, int n, int k, float alpha, float[] a, int offseta, int lda, float[] x, int offsetx, int incx, float beta, float[] y, int offsety, int incy);

protected native void dscalK(int n, double alpha, double[] x, int offsetx, int incx);

protected native void sscalK(int n, float alpha, float[] x, int offsetx, int incx);

protected native void dspmvK(String uplo, int n, double alpha, double[] a, int offseta, double[] x, int offsetx, int incx, double beta, double[] y, int offsety, int incy);

protected native void sspmvK(String uplo, int n, float alpha, float[] a, int offseta, float[] x, int offsetx, int incx, float beta, float[] y, int offsety, int incy);

protected native void dsprK(String uplo, int n, double alpha, double[] x, int offsetx, int incx, double[] a, int offseta);

protected native void ssprK(String uplo, int n, float alpha, float[] x, int offsetx, int incx, float[] a, int offseta);

protected native void dspr2K(String uplo, int n, double alpha, double[] x, int offsetx, int incx, double[] y, int offsety, int incy, double[] a, int offseta);

protected native void sspr2K(String uplo, int n, float alpha, float[] x, int offsetx, int incx, float[] y, int offsety, int incy, float[] a, int offseta);

protected native void dswapK(int n, double[] x, int offsetx, int incx, double[] y, int offsety, int incy);

protected native void sswapK(int n, float[] x, int offsetx, int incx, float[] y, int offsety, int incy);

protected native void dsymmK(String side, String uplo, int m, int n, double alpha, double[] a, int offseta, int lda, double[] b, int offsetb, int ldb, double beta, double[] c, int offsetc, int ldc);

protected native void ssymmK(String side, String uplo, int m, int n, float alpha, float[] a, int offseta, int lda, float[] b, int offsetb, int ldb, float beta, float[] c, int offsetc, int ldc);

protected native void dsymvK(String uplo, int n, double alpha, double[] a, int offseta, int lda, double[] x, int offsetx, int incx, double beta, double[] y, int offsety, int incy);

protected native void ssymvK(String uplo, int n, float alpha, float[] a, int offseta, int lda, float[] x, int offsetx, int incx, float beta, float[] y, int offsety, int incy);

protected native void dsyrK(String uplo, int n, double alpha, double[] x, int offsetx, int incx, double[] a, int offseta, int lda);

protected native void ssyrK(String uplo, int n, float alpha, float[] x, int offsetx, int incx, float[] a, int offseta, int lda);

protected native void dsyr2K(String uplo, int n, double alpha, double[] x, int offsetx, int incx, double[] y, int offsety, int incy, double[] a, int offseta, int lda);

protected native void ssyr2K(String uplo, int n, float alpha, float[] x, int offsetx, int incx, float[] y, int offsety, int incy, float[] a, int offseta, int lda);

protected native void dsyr2kK(String uplo, String trans, int n, int k, double alpha, double[] a, int offseta, int lda, double[] b, int offsetb, int ldb, double beta, double[] c, int offsetc, int ldc);

protected native void ssyr2kK(String uplo, String trans, int n, int k, float alpha, float[] a, int offseta, int lda, float[] b, int offsetb, int ldb, float beta, float[] c, int offsetc, int ldc);

protected native void dsyrkK(String uplo, String trans, int n, int k, double alpha, double[] a, int offseta, int lda, double beta, double[] c, int offsetc, int ldc);

protected native void ssyrkK(String uplo, String trans, int n, int k, float alpha, float[] a, int offseta, int lda, float beta, float[] c, int offsetc, int ldc);

protected native void dtbmvK(String uplo, String trans, String diag, int n, int k, double[] a, int offseta, int lda, double[] x, int offsetx, int incx);

protected native void stbmvK(String uplo, String trans, String diag, int n, int k, float[] a, int offseta, int lda, float[] x, int offsetx, int incx);

protected native void dtbsvK(String uplo, String trans, String diag, int n, int k, double[] a, int offseta, int lda, double[] x, int offsetx, int incx);

protected native void stbsvK(String uplo, String trans, String diag, int n, int k, float[] a, int offseta, int lda, float[] x, int offsetx, int incx);

protected native void dtpmvK(String uplo, String trans, String diag, int n, double[] a, int offseta, double[] x, int offsetx, int incx);

protected native void stpmvK(String uplo, String trans, String diag, int n, float[] a, int offseta, float[] x, int offsetx, int incx);

protected native void dtpsvK(String uplo, String trans, String diag, int n, double[] a, int offseta, double[] x, int offsetx, int incx);

protected native void stpsvK(String uplo, String trans, String diag, int n, float[] a, int offseta, float[] x, int offsetx, int incx);

protected native void dtrmmK(String side, String uplo, String transa, String diag, int m, int n, double alpha, double[] a, int offseta, int lda, double[] b, int offsetb, int ldb);

protected native void strmmK(String side, String uplo, String transa, String diag, int m, int n, float alpha, float[] a, int offseta, int lda, float[] b, int offsetb, int ldb);

protected native void dtrmvK(String uplo, String trans, String diag, int n, double[] a, int offseta, int lda, double[] x, int offsetx, int incx);

protected native void strmvK(String uplo, String trans, String diag, int n, float[] a, int offseta, int lda, float[] x, int offsetx, int incx);

protected native void dtrsmK(String side, String uplo, String transa, String diag, int m, int n, double alpha, double[] a, int offseta, int lda, double[] b, int offsetb, int ldb);

protected native void strsmK(String side, String uplo, String transa, String diag, int m, int n, float alpha, float[] a, int offseta, int lda, float[] b, int offsetb, int ldb);

protected native void dtrsvK(String uplo, String trans, String diag, int n, double[] a, int offseta, int lda, double[] x, int offsetx, int incx);

protected native void strsvK(String uplo, String trans, String diag, int n, float[] a, int offseta, int lda, float[] x, int offsetx, int incx);

protected native int idamaxK(int n, double[] dx, int offsetdx, int incdx);

protected native int isamaxK(int n, float[] sx, int offsetsx, int incx);
}
33 changes: 33 additions & 0 deletions blas/src/main/native/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020, 2021, Ludovic Henry
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Please contact [email protected] or visit ludovic.dev if you need additional
# information or have any questions.

$(OBJDIR) $(dir $(OUTPUT)):
mkdir -p $@

$(INPUTS:%.c=$(OBJDIR)/%.o): $(OBJDIR)/%.o: %.c | $(OBJDIR)
$(CC) $(CCFLAGS) -o $@ $<

$(OUTPUT): $(INPUTS:%.c=$(OBJDIR)/%.o) | $(dir $(OUTPUT))
$(LD) $(LDFLAGS) -o $@ $^

all: $(OUTPUT)
Loading