-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[FEA] Add Java bindings for multi-output and reusable AST JIT execution #23828
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
Open
thirtiseven
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
thirtiseven:ast-jit-multi-output-literal-jni
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa0963c
Add Java bindings for multi-output AST JIT
thirtiseven e37a829
refator to new api
thirtiseven 41a0eb5
Merge remote-tracking branch 'origin/main' into ast-jit-multi-output-…
thirtiseven 6ac19c8
Fix transform program scalar literal ownership
thirtiseven 983fc16
Add Java bindings for reusable AST JIT programs
thirtiseven d77f4cc
Document and test reusable AST JIT programs
thirtiseven 1fb6066
Merge branch 'main' into ast-jit-multi-output-literal-jni
thirtiseven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
java/src/main/java/ai/rapids/cudf/ast/AstJitProgram.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package ai.rapids.cudf.ast; | ||
|
|
||
| import ai.rapids.cudf.MemoryCleaner; | ||
| import ai.rapids.cudf.NativeDepsLoader; | ||
| import ai.rapids.cudf.Table; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A reusable AST JIT program specialized to an input schema. | ||
| * Construction lowers the expressions and retrieves their JIT kernel. Subsequent calls reuse that | ||
| * kernel with tables whose referenced columns have compatible types and nullability. | ||
| * Callers must ensure that {@link #close()} does not overlap with {@link #computeTable(Table)}. | ||
| */ | ||
| public final class AstJitProgram implements AutoCloseable { | ||
| static { | ||
| NativeDepsLoader.loadNativeDeps(); | ||
| } | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(AstJitProgram.class); | ||
|
|
||
| private static final class AstJitProgramCleaner extends MemoryCleaner.Cleaner { | ||
| private long nativeHandle; | ||
|
|
||
| AstJitProgramCleaner(long nativeHandle) { | ||
| this.nativeHandle = nativeHandle; | ||
| } | ||
|
|
||
| @Override | ||
| protected synchronized boolean cleanImpl(boolean logErrorIfNotClean) { | ||
| long origAddress = nativeHandle; | ||
| boolean neededCleanup = nativeHandle != 0; | ||
| if (neededCleanup) { | ||
| try { | ||
| destroy(nativeHandle); | ||
| } finally { | ||
| nativeHandle = 0; | ||
| } | ||
| if (logErrorIfNotClean) { | ||
| log.error("AN AST JIT PROGRAM WAS LEAKED (ID: " + | ||
| id + " " + Long.toHexString(origAddress)); | ||
| } | ||
| } | ||
| return neededCleanup; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isClean() { | ||
| return nativeHandle == 0; | ||
| } | ||
| } | ||
|
|
||
| private final AstJitProgramCleaner cleaner; | ||
| private boolean isClosed = false; | ||
|
|
||
| private AstJitProgram(long nativeHandle) { | ||
| cleaner = new AstJitProgramCleaner(nativeHandle); | ||
| MemoryCleaner.register(this, cleaner); | ||
| cleaner.addRef(); | ||
| } | ||
|
|
||
| /** | ||
| * Compile a reusable program from one or more JIT-compiled expressions. | ||
| * The schema table and expressions are inspected during construction but are not retained. The | ||
| * returned program owns any literal values required by later evaluations. | ||
| * | ||
| * @param schemaTable table whose referenced column schema is used to compile the program | ||
| * @param expressions non-empty JIT-compiled expressions in output order | ||
| * @return a reusable AST JIT program | ||
| * @throws NullPointerException if the table, expression array, or an expression is null | ||
| * @throws IllegalArgumentException if no expressions are provided or an expression was not | ||
| * produced by {@link AstExpression#compileJit()} | ||
| * @throws IllegalStateException if the table or an expression is closed | ||
| * @throws ai.rapids.cudf.CudfException if JIT compilation fails | ||
| */ | ||
| public static AstJitProgram compile(Table schemaTable, CompiledExpression... expressions) { | ||
| Objects.requireNonNull(schemaTable, "schemaTable"); | ||
| Objects.requireNonNull(expressions, "expressions"); | ||
| if (expressions.length == 0) { | ||
| throw new IllegalArgumentException("At least one expression is required"); | ||
| } | ||
|
|
||
| long tableHandle = schemaTable.getNativeView(); | ||
| if (tableHandle == 0) { | ||
| throw new IllegalStateException("Table is closed"); | ||
| } | ||
|
|
||
| CompiledExpression[] expressionRefs = expressions.clone(); | ||
| long[] nativeHandles = CompiledExpression.getJitNativeHandles(expressionRefs); | ||
| long programHandle; | ||
| try { | ||
| programHandle = create(nativeHandles, tableHandle); | ||
| } finally { | ||
| CompiledExpression.reachabilityFence(schemaTable); | ||
| CompiledExpression.reachabilityFence(expressionRefs); | ||
| } | ||
| return new AstJitProgram(programHandle); | ||
| } | ||
|
|
||
| /** | ||
| * Evaluate this program on a table with a compatible referenced-column schema. | ||
| * The row count and unreferenced columns may differ from the schema table used at compilation. | ||
| * Calling {@link #close()} while an evaluation is in progress is unsupported. | ||
| * | ||
| * @param table input table for expression evaluation | ||
| * @return table containing the program outputs in expression order | ||
| * @throws NullPointerException if the table is null | ||
| * @throws IllegalStateException if the program or table is closed | ||
| * @throws ai.rapids.cudf.CudfException if the referenced-column schema is incompatible or | ||
| * evaluation fails | ||
| */ | ||
| public Table computeTable(Table table) { | ||
| Objects.requireNonNull(table, "table"); | ||
| long programHandle = cleaner.nativeHandle; | ||
| if (programHandle == 0) { | ||
| throw new IllegalStateException("AST JIT program is closed"); | ||
| } | ||
| long tableHandle = table.getNativeView(); | ||
| if (tableHandle == 0) { | ||
| throw new IllegalStateException("Table is closed"); | ||
| } | ||
|
|
||
| long[] result; | ||
| try { | ||
| result = computeTableNative(programHandle, tableHandle); | ||
| } finally { | ||
| CompiledExpression.reachabilityFence(this); | ||
| CompiledExpression.reachabilityFence(table); | ||
| } | ||
| return new Table(result); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void close() { | ||
| cleaner.delRef(); | ||
| if (isClosed) { | ||
| cleaner.logRefCountDebug("double free " + this); | ||
| throw new IllegalStateException("Close called too many times " + this); | ||
| } | ||
| cleaner.clean(false); | ||
| isClosed = true; | ||
| } | ||
|
|
||
| private static native long create(long[] astHandles, long tableHandle); | ||
| private static native long[] computeTableNative(long programHandle, long tableHandle); | ||
| private static native void destroy(long handle); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.