-
Notifications
You must be signed in to change notification settings - Fork 184
[Java] Bindings, tests and benchmarks for RMM pooled memory #1453
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
Changes from 4 commits
4d7dc53
8cec4dc
6dd2fa7
d74f38e
bd8670a
fc7b55c
ed92aa9
34cb780
6900dfe
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.nvidia.cuvs; | ||
|
|
||
| import com.nvidia.cuvs.spi.CuVSProvider; | ||
|
|
||
| import java.util.concurrent.*; | ||
| import java.util.function.Supplier; | ||
|
|
||
| class Utils { | ||
|
|
||
| @FunctionalInterface | ||
| interface TestFunction { | ||
| void apply() throws Throwable; | ||
| } | ||
|
|
||
| static void runConcurrently(boolean usePooledMemory, int nThreads, TestFunction testFunction) | ||
| throws ExecutionException, InterruptedException, TimeoutException { | ||
| try (ExecutorService parallelExecutor = Executors.newFixedThreadPool(nThreads)) { | ||
| if (usePooledMemory) { | ||
| CuVSProvider.provider().enableRMMPooledMemory(10, 60); | ||
| } | ||
| var futures = new CompletableFuture[nThreads]; | ||
| for (int j = 0; j < nThreads; j++) { | ||
| futures[j] = CompletableFuture.runAsync(() -> { | ||
| try { | ||
| testFunction.apply(); | ||
| } catch (Throwable e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }, parallelExecutor); | ||
| } | ||
|
|
||
| CompletableFuture.allOf(futures) | ||
| .exceptionally(Utils::fail) | ||
| .get(2000, TimeUnit.SECONDS); | ||
| } finally { | ||
| if (usePooledMemory) { | ||
| CuVSProvider.provider().resetRMMPooledMemory(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static Throwable unwrap(Throwable t) { | ||
| var root = t; | ||
| while (root.getCause() != null) { | ||
| root = root.getCause(); | ||
| } | ||
| return root; | ||
| } | ||
|
|
||
| private static Void fail(Throwable t) { | ||
| throw new AssertionError("Exception while executing: " + unwrap(t)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeTrue; | ||
|
|
||
| import com.nvidia.cuvs.spi.CuVSProvider; | ||
| import java.io.*; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
@@ -14,6 +15,7 @@ | |
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.function.LongToIntFunction; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
|
|
@@ -22,6 +24,12 @@ public class BruteForceAndSearchIT extends CuVSTestCase { | |
| @Before | ||
| public void setup() { | ||
| assumeTrue("not supported on " + System.getProperty("os.name"), isLinuxAmd64()); | ||
| CuVSProvider.provider().enableRMMPooledMemory(10, 60); | ||
|
Contributor
Author
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. Temporary to work around #1454
Contributor
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. Given that #1454 has been merged, we could consider removing this at a later date. |
||
| } | ||
|
|
||
| @After | ||
| public void cleanup() { | ||
| CuVSProvider.provider().resetRMMPooledMemory(); | ||
| } | ||
|
|
||
| // Sample data and query | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,11 @@ | |
| import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeTrue; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.RandomizedRunner; | ||
| import com.nvidia.cuvs.spi.CuVSProvider; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.util.BitSet; | ||
| import java.util.List; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
@@ -26,6 +28,12 @@ public void setup() { | |
| assumeTrue(isLinuxAmd64()); | ||
| initializeRandom(); | ||
| log.trace("Random context initialized for test."); | ||
| CuVSProvider.provider().enableRMMPooledMemory(10, 60); | ||
|
Contributor
Author
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. Temporary to work around #1454 |
||
| } | ||
|
|
||
| @After | ||
| public void cleanup() { | ||
| CuVSProvider.provider().resetRMMPooledMemory(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
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.
Need to include the copyright header here.
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.
Let me see if that change helps.