Skip to content

Import tensors and add methods to sbox#6450

Open
ArtisticRoomba wants to merge 5 commits intospace-wizards:masterfrom
ArtisticRoomba:atmos/tensors
Open

Import tensors and add methods to sbox#6450
ArtisticRoomba wants to merge 5 commits intospace-wizards:masterfrom
ArtisticRoomba:atmos/tensors

Conversation

@ArtisticRoomba
Copy link
Member

CC @moonheart08

This PR adds System.Numerics.Tensors to the RT project and adds some methods to the sandbox.

In general, Tensors is a much better way to take advantage of SIMD intrinsics on hardware without coding all of the methods ourselves (I felt really silly adding AVX512 impls to all of our current NumericsHelpers methods).

Useful for Atmospherics in SS14.

Microbenchmarks shows improvement, but of course it doesn't paint a full picture:

Details

BenchmarkDotNet v0.15.8, Linux Gentoo Linux
AMD Ryzen 9 7900X 4.03GHz, 1 CPU, 24 logical and 12 physical cores
.NET SDK 10.0.101
  [Host]     : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v4
  Job-JMDAGQ : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v4

Toolchain=.NET 10.0  

Method N Mean Error StdDev Code Size Allocated
BenchNumericsHelpers 32 3.110 ns 0.0624 ns 0.0521 ns 637 B -
BenchNumericsHelpers 128 10.249 ns 0.0312 ns 0.0244 ns 637 B -
BenchNumericsHelpers 256 12.450 ns 0.1919 ns 0.1701 ns 637 B -
BenchNumericsHelpers 512 25.505 ns 0.3755 ns 0.3513 ns 637 B -
BenchNumericsHelpers 1024 53.923 ns 0.8464 ns 0.7918 ns 637 B -
BenchNumericsHelpers 2048 90.217 ns 0.9333 ns 0.8273 ns 637 B -
BenchNumericsHelpers 4096 594.813 ns 5.8739 ns 5.4944 ns 637 B -
BenchNumericsHelpers 8192 623.864 ns 6.7247 ns 6.2903 ns 676 B -
BenchNumericsHelpers 16384 1,300.781 ns 9.5156 ns 8.4353 ns 676 B -
BenchTensor 32 3.574 ns 0.0217 ns 0.0193 ns 1,367 B -
BenchTensor 128 9.457 ns 0.1164 ns 0.1089 ns 1,374 B -
BenchTensor 256 15.379 ns 0.1173 ns 0.1040 ns 1,369 B -
BenchTensor 512 26.599 ns 0.1916 ns 0.1792 ns 1,369 B -
BenchTensor 1024 47.837 ns 0.1911 ns 0.1596 ns 1,369 B -
BenchTensor 2048 91.371 ns 0.7019 ns 0.6222 ns 1,369 B -
BenchTensor 4096 304.175 ns 1.8590 ns 1.7389 ns 1,369 B -
BenchTensor 8192 652.692 ns 5.9393 ns 5.5556 ns 1,369 B -
BenchTensor 16384 1,198.696 ns 16.3505 ns 15.2943 ns 1,369 B -

And the emitted assembly seems to show that AVX-512 instructions are being used in BenchTensor compared to AVX-256 instructions in BenchNumericsHelpers.

also nuke spans as tey're too much to review rn
Comment on lines +654 to +655
NIndex: { All: True }
NRange: { All: True }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are from Systems.Buffers, while they're in the numerics tensors assembly this works based on namespace.

Additionally, no consuming APIs are provided, so these shouldn't be either.

Comment on lines +645 to +652
Tensor:
Methods:
- "System.Numerics.Tensors.Tensor`1<!!0> Create<>(!!0[])"
- "System.Numerics.Tensors.Tensor`1<!!0> Create<>(!!0[], System.ReadOnlySpan`1<nint>)"
- "System.Numerics.Tensors.Tensor`1<!!0> Create<>(!!0[], System.ReadOnlySpan`1<nint>, System.ReadOnlySpan`1<nint>)"
- "System.Numerics.Tensors.Tensor`1<!!0> Create<>(!!0[], int, System.ReadOnlySpan`1<nint>, System.ReadOnlySpan`1<nint>)"
Tensor`1:
Methods: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No APIs are provided that can consume this type, so it shouldn't be provided.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, attempting to create a simple tensor using Tensor.Create(); will cause a sandbox violation:

Access to type not allowed: [System.Numerics.Tensors]System.Numerics.Tensors.Tensor`1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, attempting to create a simple tensor using Tensor.Create(); will cause a sandbox violation:

Access to type not allowed: [System.Numerics.Tensors]System.Numerics.Tensors.Tensor`1

Okay but you can't use the Tensor, so why allow Tensor.Create either?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, I see what you mean now. Genius me.

Comment on lines +32 to +34
_tensorA = Tensor.Create(_inputA);
_tensorB = Tensor.Create(_inputB);
_tensorOutput = Tensor.Create(_output);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants