KEMBAR78
Vectorize a few more conversions in TensorPrimitives.ConvertXx by stephentoub · Pull Request #103820 · dotnet/runtime · GitHub
Skip to content

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jun 21, 2024

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics.Tensors;

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

[MemoryDiagnoser]
public class Tests
{
    private byte[] _bytes;
    private float[] _floats;

    [GlobalSetup]
    public void Setup()
    {
        _bytes = new byte[1024];
        new Random(42).NextBytes(_bytes);
        _floats = new float[_bytes.Length];
    }

    [Benchmark]
    public void Convert() => TensorPrimitives.ConvertTruncating<byte, float>(_bytes, _floats);
}

On my laptop with AVX512...

Before:

Method Mean
Convert 1.429 us

After:

Method Mean
Convert 46.59 ns

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics-tensors
See info in area-owners.md if you want to be subscribed.

…ors/netcore/Common/TensorPrimitives.IUnaryOneToFourOperator.cs

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants