Skip to content

TensorView/DiffTensorView bypasses interop buffer on non-CUDA backends #823

Description

@jhelferty-nv

(Noticed by coderabbit in PR #781)

In NativeTorchTensorMarshall::write_torch_tensor_fields() and the DiffTensorView path in write_shader_cursor_pre_dispatch(), when offsets.is_tensorview is true, the code writes info.data_ptr (a CUDA device pointer from the PyTorch tensor) directly into the TensorViewData struct via shader_object->set_data(). This bypasses the interop buffer copy path that exists for non-CUDA backends (Vulkan/D3D12).

On Vulkan/D3D12, CUDA device addresses are not valid — the interop buffer mechanism exists specifically to copy data between PyTorch's CUDA memory and a shared buffer accessible to the non-CUDA device. The TensorView path skips this entirely, which would result in invalid device addresses being bound to the shader.

This was introduced in #775 ("Add DiffTensorView and TensorView support in slangpy"). The relevant code is in slangpytorchtensor.cpp:

  • write_torch_tensor_fields(): the if (offsets.is_tensorview) early-return at ~line 491
  • write_shader_cursor_pre_dispatch(): the else if (m_cached_binding_info.primal.is_tensorview) branch at ~line 417

Both paths call populate_tensorview_data() which embeds info.data_ptr directly, then write via set_data() without creating an interop buffer.

Possible fix: Either guard TensorView paths to error on non-CUDA backends, or extend the interop buffer mechanism to support TensorView bindings (copy to interop buffer, then write the interop buffer's device address into the TensorViewData struct).

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions