Skip to content

[MLIR] MaskedType: core type, constructor, accessors - #22884

Merged
rapids-bot[bot] merged 20 commits into
mainfrom
mlir/pr2-masked
Jun 30, 2026
Merged

[MLIR] MaskedType: core type, constructor, accessors#22884
rapids-bot[bot] merged 20 commits into
mainfrom
mlir/pr2-masked

Conversation

@brandon-b-miller

@brandon-b-miller brandon-b-miller commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

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/.

@copy-pr-bot

copy-pr-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Python Affects Python cuDF API. label Jun 14, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jun 14, 2026
@brandon-b-miller
brandon-b-miller marked this pull request as ready for review June 22, 2026 18:32
@brandon-b-miller
brandon-b-miller requested a review from a team as a code owner June 22, 2026 18:32
@brandon-b-miller
brandon-b-miller requested review from bdice and vyasr June 22, 2026 18:32
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds MLIR backend support for MaskedType in cuDF UDFs through new typing and lowering modules, plus pytest coverage for constructor and attribute behavior.

Changes

MaskedType MLIR backend

Layer / File(s) Summary
MaskedType definition and typing registration
python/cudf/cudf/core/udf/mlir_backend/masked_typing.py, python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_typing.py
MaskedType is defined as a Numba type parameterized by an inner value_type, with types.Literal unwrapping and types.Poison fallback for unsupported inner types. _register() installs a MaskedConstructor ConcreteTemplate for Masked(value, valid) signatures and a MaskedTypeAttrs resolver that maps .value to the inner type and .valid to types.boolean. Tests cover repr, equality, hash, unliteralization, poison-wrapping, and supported-type set contents.
LLVM data model and constructor/getattr lowering
python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py, python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py
_pack_masked builds the {value, valid} LLVM struct via an undefined value and two field inserts. _register() attaches an identified StructType data model to MaskedType, lowers the Masked(value, valid) constructor by coercing arguments and calling _pack_masked, and lowers .value/.valid getattr by extracting the corresponding struct field and converting to the destination MLIR type. Tests exercise literal-True, literal-False, and runtime valid flags across integer, float, and boolean dtypes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

numba

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.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 clearly summarizes the main MLIR change: MaskedType plus its constructor and accessors.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the new MaskedType support and tests.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mlir/pr2-masked

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

Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_typing.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_typing.py

@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.

Generally makes sense. I still don't fully grasp what goes in the lowering file and what goes in the typing file, it seems to me like some aspects of type definitions in the typing file are still relevant for lowering (e.g. the constructor signatures), could you explain the division a bit more?

Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py Outdated
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py Outdated
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py Outdated
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_typing.py Outdated
@brandon-b-miller

Copy link
Copy Markdown
Contributor Author

Generally makes sense. I still don't fully grasp what goes in the lowering file and what goes in the typing file, it seems to me like some aspects of type definitions in the typing file are still relevant for lowering (e.g. the constructor signatures), could you explain the division a bit more?

@vyasr the split maps to the two phase compilation pipeline used by numba (typing/lowering). The typing phase's only job is to determine, for every expression in the UDF, what the resuling type is. This phase emits no code, it just annotates every variable and result with a type. MaskedType is a new type, and at start theres no expressions at all known to numba that result in an instance of it. Much of the code in typing.py adds the very first expression one can write that results in such an instance - in this case, that expression is when you write Masked(val, valid) in the code under cuda.jit, this shall yield a MaskedType whose value_type is the same as the scalar value passed to its ctor. Stuff that defines typing for expressions like this belongs in the typing file.

The lowering phase only triggers when typing for the whole blob completes successfully. Its job is to actually emit the code that computes the value. Since this might be dependent on what the input types for that expression actually are, the author needs a registration in the lowering file that associates a procedure for computing that value with a valid set of input types. For lower_masked_constructor, the process is not much more than "load both operands, then put them into a struct that has a member for each". These implementation functions that use the MLIR python bindings to write MLIR belong in the lowering file.

@brandon-b-miller brandon-b-miller added feature request New feature or request non-breaking Non-breaking change labels Jun 24, 2026

@mroeschke mroeschke 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.

Overall looks good. Just a few last comments

Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py Outdated
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_typing.py
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated

@mroeschke mroeschke 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.

One comment and the failing typing checks otherwise LGTM. (Feel free to use # type: ignores if the typing is difficult)

Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated

@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.

Very close. I have a few smaller requests then we can merge.

Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_typing.py
Comment thread python/cudf/cudf/core/udf/mlir_backend/masked_lowering.py Outdated
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_typing.py Outdated
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated
Comment thread python/cudf/cudf/tests/private_objects/mlir_backend/test_masked_lowering.py Outdated
# AttributeError is unconditional -- so skip the MLIR backend tests on numpy < 2
# instead of erroring at collection.
# TODO: remove once a numba-cuda-mlir release > 0.4.0 supports numpy < 2.0.
if np.lib.NumpyVersion(np.__version__) < "2.0.0":

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.

Just FYI, #22962 appears close to merging and will raise the NumPy minimum version to 2.0 which should allow you to remove this (likely in a follow up)

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.

Let's do this in #22885

@vyasr

vyasr commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot
rapids-bot Bot merged commit fcb3913 into main Jun 30, 2026
125 of 126 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jun 30, 2026
@brandon-b-miller
brandon-b-miller deleted the mlir/pr2-masked branch July 1, 2026 00:50
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 Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants