Skip to content

Device dispatch keys on one tensor and never checks the others agree (mixed-device segfault) #16

Description

@balbasty

The hub dispatches each op on a single operand's device.device_type and forwards all tensors to that backend: distance.cpp keys on loc (:55,77,98,118), pushpull.cpp on out (:30-34), and identically posdef.cpp, resize.cpp, restrict.cpp, splinc.cpp, reg_field.cpp, reg_flow.cpp.

If operands disagree — e.g. out on CPU but inp/grid on CUDA (or vice-versa) — the wrong backend runs and reads a device pointer as host memory (or vice-versa) → segfault / silent garbage. Nothing upstream guards it (the Python wrappers don't either).

Fix: add a shared require_same_device(ref, others…) helper (compare device_typeanddevice_id) and call it at the top of every public entry, listing that function's tensors; throw std::invalid_argument on mismatch. Also throw a clear "not built with CUDA" error when a CUDA operand is seen but !FF_WITH_CUDA (instead of silently falling to the CPU branch or "unsupported device").

Verifiable on CPU: construct two DLTensors with different device.device_type and assert the throw (no GPU needed — it's the pre-dispatch guard).

Found in the cross-repo audit.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions