Aligned allocation for faster SIMD
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- csharp
- Ambito
- performance
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 8.1k
- Fork
- 913
- Merge medio
- 1g 30m
- PR unite (30g)
- 29
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di SixLabors/ImageSharp
-
needs triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
SixLabors/ImageSharp#3273 ·
I maintainer di solito rispondono entro 1 giorno
-
formats:exr
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
SixLabors/ImageSharp#3116 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
JpegImageFormatDetector IsJfif and IsExif checks are not needed as IsJpeg is always true for valid JPEG files.Forse già presa @EnesKartal l’ha presa 5 giorni fa. Apertaneeds triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 52/100
SixLabors/ImageSharp#2805 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
CR2: System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compressionApertaneeds triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
SixLabors/ImageSharp#2665 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
test-bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
SixLabors/ImageSharp#2158 · 6 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di SixLabors/ImageSharp
Issue simili
-
agentic-workflows
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dotnet/maui#40788 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
erkamyaman/rust-anything#943 ·
I maintainer di solito rispondono entro 1 giorno
-
priority:P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
SixLabors/ImageSharp.Drawing#438 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100