Skip to content

Make B-spline evaluation allocation-free and usable on CUDA - #110

Open
asinghvi17 wants to merge 2 commits into
SciML:mainfrom
asinghvi17:gpu-compat
Open

asinghvi17 wants to merge 2 commits into
SciML:mainfrom
asinghvi17:gpu-compat

Conversation

@asinghvi17

@asinghvi17 asinghvi17 commented Nov 12, 2026 •

Copy link
Copy Markdown

🤖 Automated comment from an AI agent running as @asinghvi17 — not written or reviewed by Anshul.

Makes B-spline evaluation work inside CUDA kernels and broadcasts, and makes scalar CPU evaluation allocation-free (was ~5 KB per call).

  • The degree is now a type parameter of BSplineInterpolationDimension, and NDInterpolation stores its concrete dimension tuple type, so mixed degrees stay type-stable.
  • prod(f, 1:N_in) becomes a product over an ntuple, which avoids an InvalidIRError on GPU.
  • adapt_structure skips knot validation.

Public constructors and call signatures are unchanged. Code that spells out every type parameter of these types needs updating.

The GPU test group now covers 1D–3D cubic B-splines and partials up to order 3 on CuArray{Float64}. GPU results are within 23 ulps of the CPU. The difference comes from FMA contraction: a CPU reference using fma at the same two places matches bitwise. Tested on an RTX A5000.

Implements the degree-as-type-parameter proposal in #37 and adds the GPU tests asked for in #23. The GPU group was a # TODO until now, so GPU CI was not exercising anything.

🤖 Generated with Claude Code

https://claude.ai/code/session_014mFQHtrhbkjCL96BmvXjDA


🤖 Posted by an AI agent — harness: Claude 2.1.316 · model: claude-opus-5-5
Conversation: factory head hd_c55d7e33 on m_4242afb3ce622d22c2c40d9e9baf1f9a (no session URL)

- Make the B-spline degree a type parameter of BSplineInterpolationDimension
  (the `degree` field is kept), so the basis function tuples have a static
  length. Scalar evaluation no longer allocates and compiles for the GPU.
- Store the interpolation dimension tuple type in NDInterpolation, so that
  dimensions with different degrees stay concretely typed, and use `map`
  over the dimensions where they can differ in type.
- Replace `prod(f, 1:N_in)` with a product over an `ntuple`, avoiding the
  dynamic empty-range branch that fails GPU compilation.
- Skip the knot validation in `adapt_structure`, which only moves data that
  was validated on construction (and may not be readable from the host).
- Add CUDA tests (evaluation and partial derivatives up to 3rd order for 1D,
  2D and 3D cubic B-splines) and a CPU zero-allocation test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com>
Harness: claude
Model: claude-opus-5-5
Factory-Task: 215cd073-3a5b-404f-b97c-153676cf404c
Agent-Harness: Claude 2.1.301
Agent-Model: claude-opus-5-5
Agent-Session: factory task 215cd073-3a5b-404f-b97c-153676cf404c on m_3e9b2709b53bf4c4dade6cc909217625 (no session URL)
@asinghvi17
asinghvi17 marked this pull request as ready for review November 12, 2026 01:27
GPU: one testset per dimension, each comparing values and partials of
order 1, mixed order 2 and order 3 against the CPU, including one
out-of-range point. CPU: a single zero-allocation testset over uniform
and mixed degree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com>
Harness: claude
Model: claude-opus-5-5
Factory-Task: 2114a827-9ca7-4bd5-8c44-bed4e0d9e6fb
Agent-Harness: Claude 2.1.301
Agent-Model: claude-opus-5-5
Agent-Session: factory task 2114a827-9ca7-4bd5-8c44-bed4e0d9e6fb on m_3e9b2709b53bf4c4dade6cc909217625 (no session URL)
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI v0.164.0 / gpt-6.1-sol), reviewer session 01a1cd75-4808-7891-b323-2ac139839ab8, reviewed head 1c28d74

  • Verdict: MERGE
  • Risk assessment: medium-low (ML3: measured allocation/performance improvement in scalar B-spline evaluation; independent numerical and GPU scalar checks pass)
  • Round / slot: 2 / 1

This is a blind code-only review by a session other than the PR author's, copied below from the reviewer's report with only the grading metadata removed. The posting agent did not re-run the reviewer's commands. A MERGE verdict is advice; merging is left to the maintainers.

CI: CI unreadable; review only; merge gates unchanged
Session: 01a1cd75-4808-7891-b323-2ac139839ab8

Risk

medium-low (ML3: measured allocation/performance improvement in scalar B-spline evaluation; independent numerical and GPU scalar checks pass)

Blocking findings

None.

  • Verdict: MERGE
  • Round: 2
  • Blocking priorities: none
  • Deferred P2 issues: none

Non-blocking findings

  • test/gpu/test_gpu.jl:40 — Confirmed limitation outside the new scalar GPU coverage: cached B-spline eval_grid and eval_unstructured fail on both revisions. At this head, uniform and mixed-degree cases raise InvalidIRError, including allocations through NDInterpolation reconstruction/validation; the base fails with This function is not intended for use on the CPU. Automatic NURBS cache adaptation also fails on both revisions; weights remain host arrays at the head. These are not demonstrated regressions. Add separate follow-up coverage and fixes for these GPU interfaces; the passing scalar tests do not establish their support.

What I ran

  • Reviewer: Codex, model gpt-6.1-sol. Blind checkout/diff review; no PR body, comments, prior reviews, or author risk rating read. Root AGENTS.md and CLAUDE.md are absent. Read the supplied instructions and canonical risk criteria.
  • Exported the requested TMPDIR, preserved JULIA_DEPOT_PATH, and ran against git archive copies under ../scratch/. The original checkout remains clean. Julia commands used four threads/precompile tasks and memory-capped scopes.
  • julia --version: 1.13.2. No tracked Julia interpreter pin, Manifest, Python project, or uv.lock exists. uv run --locked python --version: Python 3.15.0, with warning that --locked has no effect outside a project; this does not establish a locked project Python environment. Julia tests used the repository's Project/test environments resolved in scratch.
  • GROUP=Core julia --project=../scratch/head -e 'using Pkg; Pkg.test()': 2,201 passed (Extrapolation 1,485; Interpolations 210; Derivatives 444; DataInterpolations 28; Interface 34).
  • CUDA_VISIBLE_DEVICES=0 GROUP=GPU julia --project=../scratch/head -e 'using Pkg; Pkg.test()': 12 passed, no skips. CUDA 6.4.2, KernelAbstractions 0.9.46. Checked GPU memory/process occupancy before using card 0, an NVIDIA RTX PRO 6000 Blackwell Max-Q. CUDA.functional() == true; minimal CUDA smoke test sum(CUDA.ones(Float32, 16)) == 16.0 passed.
  • julia --project=../scratch/head ../scratch/probes.jl: 538 passed. Independent 256-bit recursive B-spline reference: 462 checks over Float32/Float64, degrees 0/1/2/3/5, nonuniform/repeated knots, endpoints, extrapolation, and derivatives through degree+1. Another 72 analytic mixed-degree scalar/grid/unstructured checks and four constructor/adaptation checks passed. Numerical bounds derive from source precision and absolute reference-term sums.
  • julia --project=../scratch/{base,head} ../scratch/allocations.jl, separately for each revision: the same four zero-allocation assertions fail on base, pass on head. Base d41d499767c99a5232db1a112fb083f6f4f092ba allocates 5,072 bytes for degree (3,3) and 15,776 bytes for (1,2,3), for both tested derivative tuples; head allocates zero. Warmed 20,000-call value loops measured 0.0499→0.00109 seconds and 0.1265→0.00154 seconds, respectively; shared-machine timings are indicative.
  • julia --project=../scratch/gpu-probe-env ../scratch/gpu_scalar_probes.jl: 48 analytic scalar GPU checks passed, covering Float32/Float64, mixed degrees including zero, all extrapolation modes, boundary/outside points, and derivatives beyond degree. Two linear/constant GPU adaptation checks passed; one automatic NURBS cache case errored.
  • gpu_probes.jl: 48 scalar checks passed; 96 cached GPU checks errored. Ran gpu_cached_mwe.jl and gpu_nurbs_mwe.jl against both base and head with identical dependency manifests apart from the package path. Both revisions fail the corresponding cached/NURBS GPU operations, as recorded above. Probe processes completed; caught exceptions were explicitly reported as failures.
  • git diff --check origin/main...HEAD: passed. Final git status --porcelain=v1: empty.

What I did not verify

  • Live CI, PR discussion/claims, author rating, or any earlier review; no GitHub writes.
  • Julia 1.10/1.12/prerelease/32-bit, other GPU architectures, QA, Extensions, documentation builds, formatter, or spelling checks.
  • General GPU cached/NURBS support: the probes above fail. No regression was established for those existing unsupported paths.

🤖 Posted by an AI agent — harness: Claude Code 2.1.322 · model: claude-sonnet-5-5
Conversation: local session 3878b54e-28f2-4a01-a176-a8f5468d1997 (no session URL)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants