Aligned allocation for faster SIMD
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- Calme
- Stack technique
- csharp
- Domaine
- performance
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- C#
- Étoiles
- 8.1k
- Forks
- 913
- Merge moyen
- 1 j 30 min
- PR mergées (30 j)
- 29
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de SixLabors/ImageSharp
-
needs triage
Difficulté 4/5 3-5 jours Accessibilité débutants 50/100
SixLabors/ImageSharp#3273 ·
Les mainteneurs répondent en général sous 1 jour
-
formats:exr
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
SixLabors/ImageSharp#3116 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
JpegImageFormatDetector IsJfif and IsExif checks are not needed as IsJpeg is always true for valid JPEG files.Peut-être pris @EnesKartal l’a pris il y a 5 jours. Ouverteneeds triage
Difficulté 2/5 1-3 heures Accessibilité débutants 52/100
SixLabors/ImageSharp#2805 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
CR2: System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compressionOuverteneeds triage
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
SixLabors/ImageSharp#2665 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
test-bug
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
SixLabors/ImageSharp#2158 · 6 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de SixLabors/ImageSharp
Issues similaires
-
agentic-workflows
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
dotnet/maui#40788 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 92/100
erkamyaman/rust-anything#943 ·
Les mainteneurs répondent en général sous 1 jour
-
priority:P2
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
SixLabors/ImageSharp.Drawing#438 · 1 commentaire ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100