Aligned allocation for faster SIMD
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Funcionalidade
- Clareza
- Precisa de esclarecimento
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- csharp
- Domínio
- performance
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C#
- Estrelas
- 8.1k
- Forks
- 913
- Merge médio
- 1d 30min
- PRs com merge (30d)
- 29
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de SixLabors/ImageSharp
-
needs triage
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 50/100
SixLabors/ImageSharp#3273 ·
Mantenedores costumam responder em até 1 dia
-
formats:exr
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
SixLabors/ImageSharp#3116 · 2 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
JpegImageFormatDetector IsJfif and IsExif checks are not needed as IsJpeg is always true for valid JPEG files.Talvez já em andamento @EnesKartal assumiu há 5 dias. Abertaneeds triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 52/100
SixLabors/ImageSharp#2805 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
CR2: System.NotSupportedException: Missing SOI marker offset for tiff with old jpeg compressionAbertaneeds triage
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
SixLabors/ImageSharp#2665 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
test-bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
SixLabors/ImageSharp#2158 · 6 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
Todas as issues de SixLabors/ImageSharp
Issues semelhantes
-
agentic-workflows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
dotnet/maui#40788 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
erkamyaman/rust-anything#943 ·
Mantenedores costumam responder em até 1 dia
-
priority:P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
SixLabors/ImageSharp.Drawing#438 · 1 comentário ·
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100