Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize a few more conversions in TensorPrimitives.ConvertXx #103820

Merged
merged 2 commits into from
Jun 24, 2024

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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants