diff --git a/kmath-noa/build.gradle.kts b/kmath-noa/build.gradle.kts index c4b244ec5..3a51a2e0b 100644 --- a/kmath-noa/build.gradle.kts +++ b/kmath-noa/build.gradle.kts @@ -42,8 +42,10 @@ val generateJNIHeader by tasks.registering { doLast { exec { workingDir(projectDir.resolve("src/main/java/space/kscience/kmath/noa")) - commandLine("$javaHome/bin/javac", "-h", - projectDir.resolve("src/main/resources") , "JNoa.java") + commandLine( + "$javaHome/bin/javac", "-h", + projectDir.resolve("src/main/resources"), "JNoa.java" + ) } } } @@ -78,12 +80,17 @@ val downloadTorch by tasks.registering(Download::class) { overwrite(false) } -val downloadJNoa by tasks.registering(Download::class) { +fun downloadJNoaHelper(update: Boolean) = tasks.registering(Download::class) { src("https://github.com/grinisrit/noa/archive/refs/heads/kmath.zip") dest(File("$thirdPartyDir/jnoa", "kmath.zip")) - overwrite(false) + overwrite(update) } +val downloadJNoa by downloadJNoaHelper(false) + +val reDownloadJNoa by downloadJNoaHelper(true) + + val extractCMake by tasks.registering(Copy::class) { dependsOn(downloadCMake) from(tarTree(resources.gzip(downloadCMake.get().dest))) @@ -144,7 +151,7 @@ val configureCpp by tasks.registering { "-DJAVA_HOME=$javaHome", "-DBUILD_NOA_KMATH=ON", "-DCMAKE_BUILD_TYPE=Release", - "-DBUILD_NOA_CUDA=${if(!cudaFound) "ON" else "OFF"}", + "-DBUILD_NOA_CUDA=${if (!cudaFound) "ON" else "OFF"}", "-DBUILD_NOA_TESTS=OFF", "-DBUILD_NOA_BENCHMARKS=OFF", "-DINSTALL_NOA=OFF" diff --git a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java index b54b0e8c8..eda41e5ae 100644 --- a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java +++ b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java @@ -20,5 +20,6 @@ public class JNoa { } } + public static native void testException(); public static native boolean cudaIsAvailable(); } diff --git a/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h b/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h index 5554402ad..ef6ef9f92 100644 --- a/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h +++ b/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h @@ -7,6 +7,14 @@ #ifdef __cplusplus extern "C" { #endif +/* + * Class: space_kscience_kmath_noa_JNoa + * Method: testException + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_space_kscience_kmath_noa_JNoa_testException + (JNIEnv *, jclass); + /* * Class: space_kscience_kmath_noa_JNoa * Method: cudaIsAvailable diff --git a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt index 96aa2cd9d..663a558a3 100644 --- a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt +++ b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt @@ -10,12 +10,16 @@ import kotlin.test.Test class TestUtils { @Test - fun testExceptions() { + fun throwingExceptions() { try { - println(cudaAvailable()) + JNoa.testException() } catch(e:NoaException) { - println(e) - println("ALL GOOD") + println("Caught NoaException in JVM\n:$e") } } + + @Test + fun cudaSupport() { + println("CUDA support available: ${cudaAvailable()}") + } } \ No newline at end of file