Skip to main content

Same tensor values, different storage contract

Updated 2 min readMarkdown

Two logical tensors can have the same shape and values while requiring different address calculations. In this authored CPU model, both inputs are [[1,2,3],[4,5,6]]. The operation doubles each element into a packed output.

One storage list is [1,2,3,4,5,6] with element strides [3,1]. The other is [1,4,2,5,3,6] with strides [1,2], the layout of a transposed packed 3x2 base. Both logical shapes are 2x3 and both offsets are zero.

A reader that assumes packed addresses returns [[2,4,6],[8,10,12]] for the first and [[2,8,4],[10,6,12]] for the second. Every access is in bounds. Both output sums are 42. The elementwise answer is still wrong in the second case, which is why a reduction alone does not validate this operation.

From the underlying storage base, the index is:

offset + row * row_stride + column * column_stride

The full proof retains five matched layouts: packed, transpose-derived, stepped slice, packed with offset 2, and stepped slice with offset 1. The aware reader matches all five. A packed-only reader starting at the correct first element matches the two packed cases. A different faulty reader that uses strides but forgets the storage-base offset fails the two offset cases.

The pointer distinction matters. PyTorch documents storage_offset in elements, while data_ptr addresses the tensor's first element. Do not add the storage offset twice. A contiguous view can have a nonzero offset.

PyTorch's stride and view documentation explain these layout properties. NVIDIA's CUDA Runtime API 13.5 memory documentation describes a different unit: cudaMallocPitch returns a row pitch in bytes, potentially including padding. Byte pitches and element strides are not interchangeable.

An operator can support the declared layouts, reject unsupported ones, or explicitly pack a copy before a restricted path. The proof's repack control preserves every logical output, without measuring copy cost. contiguous() can return an already contiguous input unchanged; it is not a promise to reset its storage offset.

One original stdlib invocation retained five layouts, fifteen reader results and fifteen passing controls. The MIT package contains all storage lists, addresses, outputs and mismatch positions. No PyTorch, CUDA or actual kernel was executed. This positive-stride, nonoverlapping integer read model does not establish a real vulnerability, prevalence, GPU performance or general memory safety.

Read the full Nodus note and download the proof.

About the author

No comments yet. Be the first to comment.