Aligned allocation for faster SIMD
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- csharp
- Bereich
- performance
Rechercherichtung
Start with the proposed AllocationOptions.AlignedPinned design and the array-pool, pinned-array, and Marshal.Alloc alternatives described here. Review the linked runtime issues for constraints and determine whether a safe allocation strategy and ownership/freeing behavior can be specified; done means the alignment API and GC/lifetime trade-offs have a decided implementation scope.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
Intel's optimization manual places strong emphasis on the importance of alignment of memory addresses SIMD registers are stored/loaded from. Significant performance penalties occur when loads/stores are crossing (64 byte) cache line boundaries.
Managed (array pool) arrays give us no guarantees on the alignment of the &arrray[0] base address, which means that all ImageSharp SIMD code suffers from these penalties globally.
Idea
dotnet/runtime#27146 initially proposed a mechanism to control the alignment of objects on the pinned heap, but that feature did not get into the final implementation.
Considering that the earliest release where runtime support might be available is .NET 6.0, and it won't be available in erlier releases anyways, I'm proposing a library-specific solution:
- Introduce
AllocationOptions.AlignedPinned - When the flag is set, return pinned or umanaged buffers with a "hacked" base address (idea taken from https://github.com/dotnet/runtime/issues/33244#issuecomment-595848832):
IntPtr baseAddress = GetBaseAddressOfPinnedArrayOrAllocateUnmanagedBuffer();
// Align the pointer
IntPtr alignedAddress = (IntPtr)((nint)(baseAddress + sizeof(IntPtr) + (alignment - 1)) & ~(alignment - 1));
// Store the pointer to the memory baseAddress to free right before the aligned pointer
*(((IntPtr*)alignedAddress) - 1) = baseAddress;
return AlignedBuffer(alignedAddress);
The question I can't figure out
I want to make sure there are no unwanted side-effects for the GC. What buffers should we use with this trick, considering that the (mid to large) buffers we want to align will be always temporary? Note that max lifetime of these buffers is the run of an image codec or a processing operation, pinned allocations will be typically bound to these kind of big, expensive operations and won't happen within individual primitive steps.
- Should we just pin the arrays of our pool?
- Or use
Marshal.Alloc? - Should we prefer to use the Pinned Heap when it's available?
@tannergooding @saucecontrol any thoughts/concerns?
Trying to also summon @benaadams if it's not too impolite.
- Vorherrschende Sprache
- C#
- Sterne
- 8.1k
- Forks
- 913
- Ø Merge
- 1 T. 30 Min.
- Gemergte PRs (30 T.)
- 29
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SixLabors/ImageSharp
-
needs triage
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 50/100
SixLabors/ImageSharp#3273 ·
Maintainer antworten meist innerhalb von 1 Tag
-
formats:exr
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
SixLabors/ImageSharp#3116 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
JpegImageFormatDetector IsJfif and IsExif checks are not needed as IsJpeg is always true for valid JPEG files.Evtl. vergeben @EnesKartal hat das vor 5 Tagen übernommen. Offenneeds triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 52/100
SixLabors/ImageSharp#2805 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
CR2: System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compressionOffenneeds triage
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
SixLabors/ImageSharp#2665 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
test-bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
SixLabors/ImageSharp#2158 · 6 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in SixLabors/ImageSharp
Ähnliche Issues
-
agentic-workflows
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
dotnet/maui#40788 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
erkamyaman/rust-anything#943 ·
Maintainer antworten meist innerhalb von 1 Tag
-
priority:P2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
SixLabors/ImageSharp.Drawing#438 · 1 Kommentar ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100