Tensor<T> slice pinning starts at the parent array instead of the slice
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Comienza con src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs, centrándote en GetPinnableReference() y GetPinnedHandle() para tensores segmentados. Ejecuta primero la reproducción basada en archivo TensorSlicePinning.cs y, después, verifica que el pinning comienza en el desplazamiento lógico del segmento y devuelve [11,12,21,22] con código de salida 0.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
A contiguous Tensor<long> slice returns different values through its pinning APIs than through its indexer or tensor span. With System.Numerics.Tensors 10.0.9, GetPinnableReference() and GetPinnedHandle() start at the parent array rather than the beginning of the slice.
Scenario
I'm prototyping a .NET ONNX text-embedding pipeline. I want to use tensors through preprocessing, inference, and postprocessing, including passing contiguous slices to native inference without another data copy.
The shape is correct, but the pointer addresses the wrong part of the data. That means a native consumer can receive different inputs without a shape error. The repro below removes ONNX and the rest of my application. It only needs System.Numerics.Tensors.
Parent [3,2] Logical slice [2,2], starting at [1,0]
[91,92] excluded
[11,12] [11,12] <- expected pointer start
[21,22] [21,22]
Observed pointer starts at 91, not 11.
Configuration
- Windows x64
- .NET SDK 10.0.401
- Runtime .NET 10.0.12
- NuGet
System.Numerics.Tensors10.0.9 - JIT,
net10.0; NativeAOT explicitly disabled
Reproduction Steps
You can find the runnable file-based app and captured output in this gist. The complete code is also included below.
Save the following as TensorSlicePinning.cs in a new directory outside a repository. File-based apps inherit project settings from parent directories.
#:package [email protected]
#:property TargetFramework=net10.0
#:property AllowUnsafeBlocks=true
#:property PublishAot=false
using System.Numerics.Tensors;
long[] values = [91, 92, 11, 12, 21, 22];
long[] expected = [11, 12, 21, 22];
var parent = Tensor.Create(values, [3, 2]);
var slice = parent.Slice([1, 0]);
Console.WriteLine($"Runtime: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"Shape: [{string.Join(",", slice.Lengths.ToArray())}]; strides: [{string.Join(",", slice.Strides.ToArray())}]");
Console.WriteLine($"Expected slice: [{string.Join(",", expected)}]");
Console.WriteLine($"Indexer first: {slice[0, 0]}");
Console.WriteLine($"Tensor span: [{string.Join(",", slice.AsTensorSpan().GetSpan([0, 0], 4).ToArray())}]");
Console.WriteLine($"Flattened: [{string.Join(",", slice.ToArray())}]");
Console.WriteLine($"Parent GetPinnableReference: {parent.GetPinnableReference()} (expected 91)");
long referenceFirst = slice.GetPinnableReference();
Console.WriteLine($"Slice GetPinnableReference: {referenceFirst} (expected 11)");
unsafe
{
using var handle = slice.GetPinnedHandle();
long[] pinned = new ReadOnlySpan<long>(handle.Pointer, 4).ToArray();
Console.WriteLine($"Slice GetPinnedHandle: [{string.Join(",", pinned)}] (expected [{string.Join(",", expected)}])");
bool matches = slice[0, 0] == 11 && slice.ToArray().SequenceEqual(expected)
&& slice.AsTensorSpan().GetSpan([0, 0], 4).SequenceEqual(expected)
&& referenceFirst == 11 && pinned.SequenceEqual(expected);
Console.WriteLine(matches ? "PASS" : "FAIL: pinning does not start at the logical slice offset.");
return matches ? 0 : 1;
}
dotnet run --file .\TensorSlicePinning.cs
Actual behavior
Compilation succeeds. Running the app produces the following output and exits with code 1:
Runtime: .NET 10.0.12
Shape: [2,2]; strides: [2,1]
Expected slice: [11,12,21,22]
Indexer first: 11
Tensor span: [11,12,21,22]
Flattened: [11,12,21,22]
Parent GetPinnableReference: 91 (expected 91)
Slice GetPinnableReference: 91 (expected 11)
Slice GetPinnedHandle: [91,92,11,12] (expected [11,12,21,22])
FAIL: pinning does not start at the logical slice offset.
Expected behavior
The reference and pointer should start at 11, the first element of the slice. Reading four elements should return [11,12,21,22], matching the indexer and tensor span. The app should exit with code 0.
| Observation | Expected | Actual |
|---|---|---|
| Slice indexer, first element | 11 |
11 |
| Tensor-span and enumerated values | [11,12,21,22] |
[11,12,21,22] |
Slice GetPinnableReference() |
11 |
91 |
Four values through slice GetPinnedHandle() |
[11,12,21,22] |
[91,92,11,12] |
| Process exit code | 0 |
1 |
Other information
All pointer reads happen while the MemoryHandle is alive and stay within the allocated six-element array.
In the 10.0.9 source, Slice records _start, but GetPinnableReference() appears to return the array's first element without applying that offset. GetPinnedHandle() uses that reference. This looks related to the behavior above.
I've reproduced this on the configuration listed above. I haven't checked other versions or platforms.
- Lenguaje dominante
- C#
- Estrellas
- 18.4k
- Forks
- 5.7k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 647
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/runtime
-
[mono] Native memory leak on the first invoke of every open-instance delegate to a virtual methodAbiertoarea-VM-meta-mono untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/runtime#136284 · 6 reacciones ·
Los mantenedores suelen responder en 1 día
-
Several MemoryExtensions.LastIndexOfAnyExcept overloads incorrectly document "first occurrence"Posiblemente ocupada @ehsan-raoufi la tomó hace 3 días. Abiertoarea-System.Memory untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 83/100
dotnet/runtime#136282 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
MemoryExtensions.LastIndexOf ignores a custom comparer for bitwise-equatable element typesPosiblemente ocupada @aw0lid la tomó hace 4 días. Abiertoarea-System.Runtime untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
dotnet/runtime#136281 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
area-System.IO.Compression untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
dotnet/runtime#136215 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-CodeGen-coreclr untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
dotnet/runtime#135849 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/runtime
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
enhancement no-stack-trace
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
greenshot/greenshot#1618 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
squad/utforming status/triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Altinn/altinn-studio#21565 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Tyrrrz/YoutubeDownloader#912 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día