Skip to content

[MLIR] Scaffold MLIR based UDF backend - #22766

Merged
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
brandon-b-miller:mlir/pr1-plumbing
Jun 16, 2026
Merged

[MLIR] Scaffold MLIR based UDF backend#22766
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
brandon-b-miller:mlir/pr1-plumbing

Conversation

@brandon-b-miller

Copy link
Copy Markdown
Contributor

This PR adds initial scaffolding for a rewrite of the UDF numba-cuda extension backend using numba-cuda-mlir.

There's no conda packages yet, so this PR leaves updating the dep on the conda side as a todo. Xref NVIDIA/numba-cuda-mlir#97

@brandon-b-miller
brandon-b-miller requested review from a team as code owners June 3, 2026 14:28
@github-actions github-actions Bot added the Python Affects Python cuDF API. label Jun 3, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jun 3, 2026
@brandon-b-miller brandon-b-miller added feature request New feature or request non-breaking Non-breaking change numba Numba issue labels Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b2d3c1a1-4c11-42f6-aed5-537035a24b29

📥 Commits

Reviewing files that changed from the base of the PR and between 7f73bb4 and a5f1f75.

📒 Files selected for processing (2)
  • dependencies.yaml
  • python/cudf/pyproject.toml
✅ Files skipped from review due to trivial changes (1)
  • python/cudf/pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • dependencies.yaml

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Added numba-cuda-mlir>=0.3.0 to runtime dependencies, including CUDA-version-specific variants.
    • Updated packaging notes around how this requirement is handled.
  • Tests
    • Added pytest coverage to ensure the MLIR backend namespace is importable when available.
  • Documentation
    • Introduced module-level docstring/headers for the MLIR backend namespace.

Walkthrough

This PR adds numba-cuda-mlir>=0.3.0 as a runtime dependency across build configuration and project metadata, establishes the cudf.core.udf.mlir_backend package namespace, and introduces a basic plumbing test to verify the module is correctly structured and available when the dependency is present.

Changes

numba-cuda-mlir dependency and MLIR backend package

Layer / File(s) Summary
Dependency infrastructure for numba-cuda-mlir
python/cudf/pyproject.toml, dependencies.yaml, conda/recipes/cudf/recipe.yaml
Declare numba-cuda-mlir>=0.3.0 in pyproject dependencies; define depends_on_numba_cuda_mlir in dependencies.yaml with CUDA 12/13 suffixed variant selectors and wire into global and target-specific build matrix includes; document conda recipe transition with TODO comment.
MLIR backend package namespace and plumbing test
python/cudf/cudf/core/udf/mlir_backend/__init__.py, python/cudf/cudf/tests/private_objects/mlir_backend/__init__.py, python/cudf/cudf/tests/private_objects/mlir_backend/test_plumbing.py
Create the cudf.core.udf.mlir_backend package with SPDX header and module docstring; add test package structure; introduce test_plumbing.py that conditionally runs when numba_cuda_mlir is importable, verifying the MLIR backend module is accessible and intentionally empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

improvement

Suggested reviewers

  • gforsyth
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[MLIR] Scaffold MLIR based UDF backend' accurately and specifically describes the main change—adding initial scaffolding for a MLIR-based UDF backend.
Description check ✅ Passed The description directly explains the PR's purpose: adding scaffolding for a UDF numba-cuda extension backend rewrite using numba-cuda-mlir, with context about conda package availability.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@bdice bdice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we start work on a conda recipe? I'd like to land that before merging.

"""`cudf.utils._numba` should default `CUDA_ENABLE_NRT` to False on import."""
import cudf.utils._numba # noqa: F401 -- import for its side effect

assert numba_config.CUDA_ENABLE_NRT is False, (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert numba_config.CUDA_ENABLE_NRT is False, (
assert not numba_config.CUDA_ENABLE_NRT, (

Comment on lines +31 to +34
assert numba_config.CUDA_ENABLE_NRT is False
with nrt_enabled():
assert numba_config.CUDA_ENABLE_NRT is True
assert numba_config.CUDA_ENABLE_NRT is False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply in various places below, too. (This assumes numba_config.CUDA_ENABLE_NRT is boolean and does not take on states like None.)

Suggested change
assert numba_config.CUDA_ENABLE_NRT is False
with nrt_enabled():
assert numba_config.CUDA_ENABLE_NRT is True
assert numba_config.CUDA_ENABLE_NRT is False
assert not numba_config.CUDA_ENABLE_NRT
with nrt_enabled():
assert numba_config.CUDA_ENABLE_NRT
assert not numba_config.CUDA_ENABLE_NRT

Comment thread python/cudf/cudf/utils/_numba.py Outdated
# per-kernel for UDFs whose data model declares an NRT meminfo (e.g. string
# returns), and restores it afterwards. Setting the global default to False
# avoids linking NRT into kernels that don't need it.
numba_config.CUDA_ENABLE_NRT = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think importing cudf should not change the state of this global config. Instead, we should use a context manager to enable it as needed and restore to the prior global state (regardless of whether it was True or False) when outside of cuDF usage of NRT.

@brandon-b-miller

Copy link
Copy Markdown
Contributor Author

Failing cuda 12.2 jobs require NVIDIA/numba-cuda-mlir#102 to be released. We can skip cuda 12.2 for now or wait.

@vyasr vyasr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this is super minimal now, so just adding the MLIR dep. That's fine for the moment, we can add things as they become available. If we're going to get a CUDA 12.2 supporting release from numba-cuda-mlir then let's wait on that to resolve the currently failing test.

@brandon-b-miller

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit ff34bdb into NVIDIA:main Jun 16, 2026
136 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jun 16, 2026
rapids-bot Bot pushed a commit that referenced this pull request Jun 30, 2026
Add a basic MLIR based `MaskedType` and the ability to express the creation of one inside a `numba-cuda-mlir` kernel. 

Part of the MLIR UDF backend stack. Depends on #22766 (plumbing). Adds the MaskedType extension type: parameterized value type, the Masked(value, valid) constructor, the .value / .valid accessors, and the LLVM struct data model. Numeric/boolean value types only. Stacked on: #22766. Tests under tests/private_objects/mlir_backend/.

Authors:
  - https://github.com/brandon-b-miller

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #22884
vyasr added a commit that referenced this pull request Jul 6, 2026
Part of the MLIR UDF backend stack. Depends on #22766 (plumbing). Adds
NA handling for MaskedType: NAType + cudf.NA typeof, MaskedType / NAType
unify, `m is NA` / `m is not NA`, and the NA / scalar / Masked->Masked
casts used for branch unification.

Unification covers expressions in the target code like the following
where `x` is `MaskedType`.
```
if x is cudf.NA:
    return x
else:
    return 42
```

42 is a scalar here so the unification code kicks in and types the
overall expression as returning MaskedType, and upcasts the 42 to
Masked(42, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Non-breaking change numba Numba issue Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants