NVIDIA / NVIDIA/cudf

[FEA] Replace the CUDA and PTX UDF parsers with explicit dispatch and direct linking

Open
#23,566 0 comments 0 reactions 1 assignee Claimed by @lamarrr View on GitHub
feature request libcudf
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Is your feature request related to a problem? Please describe.**

cuDF currently rewrites CUDA and PTX UDFs with custom text parsers before compiling them.

The CUDA parser removes comments, finds the first opening parenthesis, and renames the preceding
token as the UDF entry point. Because it does not perform C++ semantic analysis, it cannot reliably
select a function when the source contains helper functions, templates, macros, or declarations
from included headers.

The PTX parser is substantially more complex. It parses a PTX function, maps register types to CUDA
types and inline-assembly constraints, and converts PTX instructions into inline PTX embedded in
generated CUDA source. This approach:

- Duplicates part of the PTX grammar and ABI in cuDF.
- Can mis-handle instruction operands, parameter layouts, or register constraints.
- Must be updated when PTX syntax or semantics evolve.
- Still invokes the CUDA C++ frontend even though the input is already PTX.
- Can produce architecture-specific failures that are difficult to diagnose.

**Describe the solution you'd like**

Remove both custom UDF parsers after explicit UDF entry-point selection is available:

- Require CUDA UDF callers to provide an invocation expression or explicit entry point. Compile the
supplied source and headers without discovering or renaming a function.
- Pass PTX UDF fragments directly to `nvJitLink` through RTCX instead of translating PTX into
inline CUDA.
- Generate a small, typed dispatcher only when cuDF must adapt its kernel entry ABI to the selected
UDF symbol.
- Let `nvJitLink` diagnose unresolved symbols, duplicate definitions, unsupported PTX, and ABI
mismatches.
- Remove `ptx_parser`, `parse_single_function_ptx`, and `parse_single_function_cuda` after all
callers use explicit dispatch.
- Add coverage for multiple functions, helper functions, templates, external headers, overloaded
names, and PTX generated for every supported GPU architecture.
- Document any compatibility or deprecation period required for existing UDF callers.

**Describe alternatives you've considered**

- Continue extending the custom PTX parser. This retains a large maintenance surface and cannot
delegate validation and optimization to NVIDIA's linker.
- Replace the text parser with a full CUDA or Clang frontend. This would add a large dependency and
duplicate work already performed by NVRTC and `nvJitLink`.
- Keep generating CUDA wrappers around PTX. This preserves the extra frontend compilation step and
the fragile PTX-to-inline-assembly conversion.

**Additional context**

- Current implementation:
[`cpp/src/jit/parser.cpp`](https://github.com/rapidsai/cudf/blob/main/cpp/src/jit/parser.cpp)
- A PTX operand mismatch surfaced as an architecture-specific failure in
[#21597](https://github.com/rapidsai/cudf/pull/21597).
- [#22496](https://github.com/rapidsai/cudf/issues/22496) lists replacing the PTX parser with proper
PTX linking as follow-up work.
- [#23548](https://github.com/rapidsai/cudf/pull/23548) Implements a prototype of this proposal

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.