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

[API Proposal]: Extend System.Numerics.Tensors.TensorPrimitives with primitive types other than float #93474

Open
asmirnov82 opened this issue Oct 13, 2023 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics.Tensors
Milestone

Comments

@asmirnov82
Copy link

asmirnov82 commented Oct 13, 2023

Background and motivation

With the implementation of #89639 a new non-generic static API for the main arithmetic and conversion operators was added into the System.Numerics.Tensors namespace. This API provides hardware accelerated math on Span<float> type of data. While float is very often used in AI, other primitive types are also widely used in many areas (for example for data wrangling). Microsoft.Data.Analysis is one of the packages that will benefit from the hardware accelerated math for other primitive types.

API Proposal

  1. Extend basic element-wise Arithmetic from existing API to support double, sbyte , byte , short , ushort , int , uint , long and ulong types.

Methods affected:

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Abs(ReadOnlySpan<float> x, Span<float> destination);

    public static void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Add(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Divide(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Divide(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static float Max(ReadOnlySpan<float> value);
    public static float Min(ReadOnlySpan<float> value);

    public static void Multiply(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Multiply(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Negate(ReadOnlySpan<float> values, Span<float> destination);

    public static void Subtract(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Subtract(ReadOnlySpan<float> x, float y, Span<float> destination);
}
  1. Add reverse method for non commutative operations where one of the operands is scalar.

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Divide(float x, ReadOnlySpan<float> y, Span<float> destination);

     public static void Subtract(float x, ReadOnlySpan<float> y, Span<float> destination);
}
  1. Add new operations for hardware accelerated comparison:

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Equals(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static bool EqualsAll(ReadOnlySpan<float> x, ReadOnlySpan<float> y);
    public static bool EqualsAny(ReadOnlySpan<float> x, ReadOnlySpan<float> y);

    public static void GreaterThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void GreaterThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static void LessThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void LessThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
}

API Usage

The same as for the existing API proposed in #89639

Alternative Designs

No response

Risks

No response

@asmirnov82 asmirnov82 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 13, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 13, 2023
@ghost
Copy link

ghost commented Oct 13, 2023

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

Issue Details

Background and motivation

With the implementation of #89639 a new non-generic static API for the main arithmetic and conversion operators was added into the System.Numerics.Tensors namespace. This API provides hardware accelerated math on Span<float> type of data. While float is very often used in AI, other primitive types are also widely used in many areas (for example for data wrangling). Microsoft.Data.Analysis is one of the packages that will benefit from the hardware accelerated math for other primitive types.

API Proposal

  1. Extend basic element-wise Arithmetic from existing API to support double, sbyte , byte , short , ushort , int , uint , long and ulong types.

Methods affected:

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Abs(ReadOnlySpan<float> x, Span<float> destination);

    public static void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Add(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Divide(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Divide(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static float Max(ReadOnlySpan<float> value);
    public static float Min(ReadOnlySpan<float> value);

    public static void Multiply(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Multiply(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Negate(ReadOnlySpan<float> values, Span<float> destination);

    public static void Subtract(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Subtract(ReadOnlySpan<float> x, float y, Span<float> destination);
}
  1. Add reverse method for non commutative operation where one of the operand is scalar.

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Divide(float x, ReadOnlySpan<float> y, Span<float> destination);

     public static void Subtract(float x, ReadOnlySpan<float> y, Span<float> destination);
}
  1. Add new operations for hardware accelerated comparison:

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Equals(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static bool EqualsAll(ReadOnlySpan<float> x, ReadOnlySpan<float> y);
    public static bool EqualsAny(ReadOnlySpan<float> x, ReadOnlySpan<float> y);

    public static void GreaterThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void GreaterThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static void LessThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void LessThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
}

API Usage

The same as for the existing API proposed in #89639

Alternative Designs

No response

Risks

No response

Author: asmirnov82
Assignees: -
Labels:

api-suggestion, area-System.Numerics

Milestone: -

@ghost
Copy link

ghost commented Oct 13, 2023

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

Issue Details

Background and motivation

With the implementation of #89639 a new non-generic static API for the main arithmetic and conversion operators was added into the System.Numerics.Tensors namespace. This API provides hardware accelerated math on Span<float> type of data. While float is very often used in AI, other primitive types are also widely used in many areas (for example for data wrangling). Microsoft.Data.Analysis is one of the packages that will benefit from the hardware accelerated math for other primitive types.

API Proposal

  1. Extend basic element-wise Arithmetic from existing API to support double, sbyte , byte , short , ushort , int , uint , long and ulong types.

Methods affected:

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Abs(ReadOnlySpan<float> x, Span<float> destination);

    public static void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Add(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Divide(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Divide(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static float Max(ReadOnlySpan<float> value);
    public static float Min(ReadOnlySpan<float> value);

    public static void Multiply(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Multiply(ReadOnlySpan<float> x, float y, Span<float> destination);

    public static void Negate(ReadOnlySpan<float> values, Span<float> destination);

    public static void Subtract(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination);
    public static void Subtract(ReadOnlySpan<float> x, float y, Span<float> destination);
}
  1. Add reverse method for non commutative operation where one of the operand is scalar.

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Divide(float x, ReadOnlySpan<float> y, Span<float> destination);

     public static void Subtract(float x, ReadOnlySpan<float> y, Span<float> destination);
}
  1. Add new operations for hardware accelerated comparison:

New methods (for all primitive types):

namespace System.Numerics.Tensors;

public static partial class TensorPrimitives
{
    public static void Equals(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static bool EqualsAll(ReadOnlySpan<float> x, ReadOnlySpan<float> y);
    public static bool EqualsAny(ReadOnlySpan<float> x, ReadOnlySpan<float> y);

    public static void GreaterThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void GreaterThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);

    public static void LessThan(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
    public static void LessThanOrEqual(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<bool> destination);
}

API Usage

The same as for the existing API proposed in #89639

Alternative Designs

No response

Risks

No response

Author: asmirnov82
Assignees: -
Labels:

api-suggestion, area-System.Numerics.Tensors, untriaged

Milestone: -

@stephentoub
Copy link
Member

See #93286.

@stephentoub
Copy link
Member

stephentoub commented Jan 14, 2024

(1) is handled via the added generic overloads.

(2) is implemented via #96451.

@tannergooding, do we want (3)? (generic rather than float-specific)

@stephentoub stephentoub added this to the Future milestone Jul 19, 2024
@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics.Tensors
Projects
None yet
Development

No branches or pull requests

4 participants