matrix mul matrix is full function
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixKernel"
|
||||
// Project: StgSharp
|
||||
@@ -37,6 +41,9 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
public unsafe struct MatrixKernel
|
||||
{
|
||||
|
||||
@@ -44,6 +51,7 @@ namespace StgSharp.HighPerformance
|
||||
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T : unmanaged, INumber<T>
|
||||
@@ -52,6 +60,11 @@ namespace StgSharp.HighPerformance
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T: unmanaged, INumber<T>
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T : unmanaged, INumber<T>
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
{
|
||||
|
||||
private T c0r0;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixPanel"
|
||||
// Project: StgSharp
|
||||
@@ -30,9 +34,13 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
using StgSharp.Internal;
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
using StgSharp.Internal;
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -40,6 +48,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
public unsafe struct MatrixPanel
|
||||
{
|
||||
@@ -174,102 +183,138 @@ namespace StgSharp.HighPerformance
|
||||
#pragma warning disable CA1000
|
||||
|
||||
public interface IMatrixPanel<T> : IDisposable where T : unmanaged,INumber<T>
|
||||
=======
|
||||
public unsafe struct MatrixPanel
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
{
|
||||
|
||||
ref T this[int column, int row] { get; }
|
||||
public const int AlignmentBytes = 64;
|
||||
|
||||
static abstract int MaxElementCount { get; }
|
||||
private byte Head;
|
||||
|
||||
static abstract int ElementSideLength { get; }
|
||||
// Allocate aligned memory for one panel; caller must free via Destroy.
|
||||
public static unsafe MatrixPanel<T>* Create<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (MatrixPanel<T>*)NativeMemory.AlignedAlloc(Size<T>(), AlignmentBytes);
|
||||
}
|
||||
|
||||
static abstract nuint Size { get; }
|
||||
public static unsafe void Destroy<T>(MatrixPanel<T>* panel) where T : unmanaged, INumber<T>
|
||||
{
|
||||
NativeMemory.AlignedFree(panel);
|
||||
}
|
||||
|
||||
void Dispose();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Span<T> Elements<T>(ref T head) where T : unmanaged, INumber<T>
|
||||
{
|
||||
void* p = Unsafe.AsPointer(ref head);
|
||||
return new Span<T>(p, MaxElementCount<T>());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ElementSideLength<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return Math.Max(8, AlignmentBytes / sizeof(T));
|
||||
}
|
||||
|
||||
// View an existing pointer; caller guarantees lifetime/alignment.
|
||||
public static unsafe MatrixPanel<T>* FromPointer<T>(void* ptr)
|
||||
where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (MatrixPanel<T>*)Align64(ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int MaxElementCount<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
int side = ElementSideLength<T>();
|
||||
return side * side;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static nuint Size<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (nuint)(MaxElementCount<T>() * sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of 4x4 kernels that fit in a panel for the given ISA and element T.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static int KernelCapacity<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
int perSide = KernelSideCount<T>();
|
||||
return perSide * perSide;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many 4x4 kernels fit along a single panel dimension for the given ISA.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static int KernelSideCount<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return NativeIntrinsic.IntrinsicLevel switch
|
||||
{
|
||||
IntrinsicLevel.SSE => KernelSideCountSse<T>(),
|
||||
IntrinsicLevel.AVX2 => KernelSideCountAvx2<T>(),
|
||||
IntrinsicLevel.AVX512 => KernelSideCountAvx512<T>(),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static unsafe nuint Align64(void* p) => ((nuint)p + (AlignmentBytes - 1)) & ~(nuint)(AlignmentBytes - 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountAvx2<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 8;
|
||||
int lanes = 32 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountAvx512<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 8;
|
||||
int lanes = 64 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountSse<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 4;
|
||||
int lanes = 16 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buffer for SSE targeted matrix panel, size of a panel is 4x4 elements, and no smaller than
|
||||
/// 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixPanelSSE<T> : IMatrixPanel<T> where T : unmanaged, INumber<T>
|
||||
// Single POD-style panel: ZMM-compatible size. Alignment handled by allocator, not by the struct.
|
||||
public unsafe struct MatrixPanel<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private T element;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixPanelSSE() { }
|
||||
internal T Head; // first element of the panel buffer
|
||||
|
||||
public ref T this[int column, int row]
|
||||
{
|
||||
get
|
||||
{
|
||||
int index = row * ElementSideLength + column;
|
||||
return ref Unsafe.Add(ref element, index);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref Unsafe.Add(ref Head, row * MatrixPanel.ElementSideLength<T>() + column);
|
||||
}
|
||||
|
||||
public static int ElementSideLength
|
||||
public Span<T> Elements
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = int.Max(4, 16 / sizeof(T));
|
||||
|
||||
public static int MaxElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = ElementSideLength * ElementSideLength;
|
||||
|
||||
public static unsafe nuint Size { get; } = (nuint)(MaxElementCount * sizeof(T));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ChunkCount() => (ElementSideLength + LanesPerVector() - 1) / LanesPerVector();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixPanelSSE<T>* Create()
|
||||
{
|
||||
MatrixPanelSSE<T>* kernel = (MatrixPanelSSE<T>*)NativeMemory.AlignedAlloc(Size, 16);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixPanelSSE<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixPanelSSE<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref M128 GetVectorChunk(int column, int chunk)
|
||||
{
|
||||
int lanes = LanesPerVector();
|
||||
int rowStart = chunk * lanes;
|
||||
ref T colBase = ref this[column, 0];
|
||||
return ref Unsafe.As<T, M128>(ref Unsafe.Add(ref colBase, rowStart));
|
||||
}
|
||||
|
||||
// SIMD access helpers (column-major)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int LanesPerVector() => 16 / sizeof(T);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVectorChunk(int column, int chunk, in M128 value)
|
||||
{
|
||||
GetVectorChunk(column, chunk) = value;
|
||||
get => MatrixPanel.Elements(ref Head);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// <summary>
|
||||
/// Buffer for AVX targeted matrix panel, size of a panel is 4x4 elements, and no smaller than
|
||||
/// 16 bytes.
|
||||
@@ -436,3 +481,5 @@ namespace StgSharp.HighPerformance
|
||||
}
|
||||
}
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IntrinsicContext"
|
||||
// Project: StgSharp
|
||||
@@ -44,7 +44,8 @@ namespace StgSharp.Internal.Intrinsic
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, ScalarPacket*, long, void> f32_buffer_scalar_mul; //f32_buffer_s_m
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, long, void> f32_buffer_sub; //f32_kernel_sub
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void> f32_buffer_transpose; //f32_kernel_transpose
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, int, int, int, int, void> f32_build_panel; //f32_build_panel
|
||||
public delegate* unmanaged[Cdecl]<MatrixPanel*, MatrixKernel*, int, int, int, int, void> f32_build_panel; //f32_build_panel
|
||||
public delegate* unmanaged[Cdecl]<MatrixPanel*, void> f32_clear_panel;
|
||||
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> f32_normalize_3; //f32_normalize_3
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, void> f32_panel_fma; //f32_panel_fma
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, int, int, int, int, void> f32_store_panel; //f32_store_panel
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace StgSharp.Internal
|
||||
{
|
||||
case 0:
|
||||
|
||||
// Dialogue.PostError(new PlatformNotSupportedException("No SIMD instructions supported on current hardware platform"));
|
||||
Dialogue.PostError(new PlatformNotSupportedException("No SIMD instructions supported on current hardware platform"));
|
||||
Environment.Exit(-1);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -26,9 +26,17 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
<<<<<<< HEAD
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
=======
|
||||
using StgSharp.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -37,6 +45,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public partial class MatrixCompute
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
private static unsafe void ComputeFmaPanelF32(
|
||||
MatrixKernel* left,
|
||||
MatrixKernel* right,
|
||||
@@ -48,6 +57,47 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int row = scalar->Data<int>(1);
|
||||
int k =
|
||||
|
||||
=======
|
||||
internal static unsafe void ComputeFmaPanelF32(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize;
|
||||
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
||||
MatrixKernel* rightBuffer = (MatrixKernel*)p->Right;
|
||||
MatrixKernel* ansBuffer = (MatrixKernel*)p->Answer;
|
||||
MatrixPanel<float>* leftPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* rightPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* ansPanel = MatrixPanel.Create<float>();
|
||||
ref long offsetRef = ref Unsafe.As<int, long>(ref p->PrimTileOffset);
|
||||
ref long lengthRef = ref Unsafe.As<int, long>(ref p->PrimCount);
|
||||
int ansWidth = p-> AnsPrimOffset;
|
||||
int ansHeight = p->AnsSecOffset;
|
||||
int commonK = p->LeftPrimOffset;
|
||||
int blocksPerRow = ansWidth / size;
|
||||
|
||||
for (long c = offsetRef; c < offsetRef + lengthRef; c++)
|
||||
{
|
||||
int i = (int)(c / blocksPerRow) * size;
|
||||
int j = (int)(c % blocksPerRow) * size;
|
||||
NativeIntrinsic.Intrinsic.f32_clear_panel((MatrixPanel*)ansPanel);
|
||||
for (int k = 0; k < commonK; k += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixPanel*)leftPanel, leftBuffer, commonK,
|
||||
ansHeight, k, i);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixPanel*)rightPanel, rightBuffer, ansWidth,
|
||||
commonK, j, k);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_panel_fma((MatrixPanel*)leftPanel, (MatrixPanel*)rightPanel, (MatrixPanel*)ansPanel);
|
||||
}
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_store_panel((MatrixPanel*)ansPanel, ansBuffer, ansWidth,
|
||||
ansHeight, j, i);
|
||||
}
|
||||
MatrixPanel.Destroy(leftPanel);
|
||||
MatrixPanel.Destroy(rightPanel);
|
||||
MatrixPanel.Destroy(ansPanel);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,362 +0,0 @@
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute.Basic"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
<<<<<<< HEAD
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
public static partial class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe void Add(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
=======
|
||||
public static class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe Matrix<float> Add(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
{
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
left.RowLength != right.RowLength ||
|
||||
left.ColumnLength != ans.ColumnLength ||
|
||||
left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = (nint)left.Buffer;
|
||||
package->Right = (nint)right.Buffer;
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
<<<<<<< HEAD
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
=======
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_add;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
}
|
||||
|
||||
public static unsafe void Fill(Matrix<float> ans, float value)
|
||||
{
|
||||
long count = (long)ans.KernelColumnLength * ans.KernelRowLength;
|
||||
ScalarPacket* scalar = MatrixParallelFactory.CreateScalarPacket();
|
||||
scalar->Data<float>(0) = value;
|
||||
if (count <= 256)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_fill(ans.Buffer, scalar, count);
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_fill(ans.Buffer, scalar, count);
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_fill;
|
||||
package->Scalar = scalar;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
MatrixParallelFactory.Release(scalar);
|
||||
taskGroup.Dispose();
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public static unsafe void Mul(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
{
|
||||
// For matrix multiplication (left: MxK) * (right: KxN) => ans: MxN
|
||||
// ColumnLength = number of columns (N), RowLength = number of rows (M)
|
||||
if (left.ColumnLength != right.RowLength ||
|
||||
ans.ColumnLength != right.ColumnLength ||
|
||||
ans.RowLength != left.RowLength)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = null;
|
||||
if (count > 256) {
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
MatrixPanel<float>* leftPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* rightPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* ansPanel = MatrixPanel.Create<float>();
|
||||
int size = MatrixPanel.KernelSideCount<float>();
|
||||
for (int i = 0; i < left.RowLength; i += size)
|
||||
{
|
||||
for (int j = 0; j < right.ColumnLength; j += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic.f32_clear_panel((MatrixPanel*)ansPanel);
|
||||
for (int k = 0; k < left.ColumnLength; k += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixKernel*)left.Buffer,
|
||||
(MatrixPanel*)leftPanel,
|
||||
left.ColumnLength, left.RowLength, i,
|
||||
k);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixKernel*)right.Buffer,
|
||||
(MatrixPanel*)rightPanel,
|
||||
right.ColumnLength, right.RowLength, k,
|
||||
j);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_panel_fma((MatrixPanel*)leftPanel,
|
||||
(MatrixPanel*)rightPanel,
|
||||
(MatrixPanel*)ansPanel);
|
||||
}
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_store_panel((MatrixKernel*)ans.Buffer,
|
||||
(MatrixPanel*)ansPanel, ans.ColumnLength,
|
||||
ans.RowLength, i, j);
|
||||
}
|
||||
}
|
||||
MatrixPanel.Destroy(leftPanel);
|
||||
MatrixPanel.Destroy(rightPanel);
|
||||
MatrixPanel.Destroy(ansPanel);
|
||||
if (count > 256) {
|
||||
MatrixParallel.ReturnParallelResources(ref pool!);
|
||||
}
|
||||
return;
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Right = (nint)left.Buffer;
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
=======
|
||||
public static unsafe Matrix<float> Mul(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
{
|
||||
if (left.RowLength != right.ColumnLength ||
|
||||
left.RowLength != ans.RowLength ||
|
||||
right.ColumnLength != ans.ColumnLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe Matrix<float> Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
{
|
||||
if (left.ColumnLength != ans.ColumnLength || left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
ScalarPacket* scalar = MatrixParallelFactory.CreateScalarPacket();
|
||||
scalar->Data<float>(0) = right;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Right = (nint)left.Buffer;
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->Scalar = scalar;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
MatrixParallelFactory.Release(scalar);
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Sub(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
=======
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static unsafe Matrix<float> Sub(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
{
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
left.RowLength != right.RowLength ||
|
||||
left.ColumnLength != ans.ColumnLength ||
|
||||
left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = (nint)left.Buffer;
|
||||
package->Right = (nint)right.Buffer;
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_sub;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,16 @@
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute"
|
||||
// Project: StgSharp
|
||||
@@ -25,13 +37,476 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
<<<<<<< HEAD
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
=======
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.AccessControl;
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
public static partial class MatrixCompute { }
|
||||
=======
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
public static partial class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe void Add(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
=======
|
||||
public static class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe Matrix<float> Add(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
public static partial class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe void Add(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
{
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
left.RowLength != right.RowLength ||
|
||||
left.ColumnLength != ans.ColumnLength ||
|
||||
left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = (nint)left.Buffer;
|
||||
package->Right = (nint)right.Buffer;
|
||||
package->Answer = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
=======
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
========
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_add;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
}
|
||||
|
||||
public static unsafe void Fill(Matrix<float> ans, float value)
|
||||
{
|
||||
long count = (long)ans.KernelColumnLength * ans.KernelRowLength;
|
||||
ScalarPacket* scalar = MatrixParallelFactory.CreateScalarPacket();
|
||||
scalar->Data<float>(0) = value;
|
||||
if (count <= 256)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_fill(ans.Buffer, scalar, count);
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_fill(ans.Buffer, scalar, count);
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Answer = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_fill;
|
||||
package->Scalar = scalar;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
MatrixParallelFactory.Release(scalar);
|
||||
taskGroup.Dispose();
|
||||
}
|
||||
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
public static unsafe void Mul(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
{
|
||||
// For matrix multiplication (left: MxK) * (right: KxN) => ans: MxN
|
||||
// ColumnLength = number of columns (N), RowLength = number of rows (M)
|
||||
if (left.ColumnLength != right.RowLength ||
|
||||
ans.ColumnLength != right.ColumnLength ||
|
||||
ans.RowLength != left.RowLength)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = null;
|
||||
if (count > 256) {
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
MatrixPanel<float>* leftPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* rightPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* ansPanel = MatrixPanel.Create<float>();
|
||||
int size = MatrixPanel.KernelSideCount<float>();
|
||||
for (int i = 0; i < left.RowLength; i += size)
|
||||
{
|
||||
for (int j = 0; j < right.ColumnLength; j += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic.f32_clear_panel((MatrixPanel*)ansPanel);
|
||||
for (int k = 0; k < left.ColumnLength; k += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixKernel*)left.Buffer,
|
||||
(MatrixPanel*)leftPanel,
|
||||
left.ColumnLength, left.RowLength, i,
|
||||
k);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixKernel*)right.Buffer,
|
||||
(MatrixPanel*)rightPanel,
|
||||
right.ColumnLength, right.RowLength, k,
|
||||
j);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_panel_fma((MatrixPanel*)leftPanel,
|
||||
(MatrixPanel*)rightPanel,
|
||||
(MatrixPanel*)ansPanel);
|
||||
}
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_store_panel((MatrixKernel*)ans.Buffer,
|
||||
(MatrixPanel*)ansPanel, ans.ColumnLength,
|
||||
ans.RowLength, i, j);
|
||||
}
|
||||
}
|
||||
MatrixPanel.Destroy(leftPanel);
|
||||
MatrixPanel.Destroy(rightPanel);
|
||||
MatrixPanel.Destroy(ansPanel);
|
||||
if (count > 256) {
|
||||
MatrixParallel.ReturnParallelResources(ref pool!);
|
||||
}
|
||||
return;
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Right = (nint)left.Buffer;
|
||||
package->Result = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
=======
|
||||
public static unsafe Matrix<float> Mul(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
========
|
||||
public static unsafe void Mul(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
{
|
||||
// For matrix multiplication (left: MxK) * (right: KxN) => ans: MxN
|
||||
// ColumnLength = number of columns (N), RowLength = number of rows (M)
|
||||
if (left.ColumnLength != right.RowLength ||
|
||||
ans.ColumnLength != right.ColumnLength ||
|
||||
ans.RowLength != left.RowLength)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
int size = MatrixPanel.KernelSideCount<float>();
|
||||
if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = null;
|
||||
if (count > 256) {
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
MatrixPanel<float>* leftPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* rightPanel = MatrixPanel.Create<float>();
|
||||
MatrixPanel<float>* ansPanel = MatrixPanel.Create<float>();
|
||||
for (int i = 0; i < ans.KernelRowLength; i += size)
|
||||
{
|
||||
for (int j = 0; j < ans.KernelColumnLength; j += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic.f32_clear_panel((MatrixPanel*)ansPanel);
|
||||
|
||||
// Console.WriteLine($"{i}{j}");
|
||||
for (int k = 0; k < left.KernelColumnLength; k += size)
|
||||
{
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixPanel*)leftPanel,
|
||||
(MatrixKernel*)left.Buffer,
|
||||
left.KernelColumnLength,
|
||||
left.KernelRowLength, i, k);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_build_panel((MatrixPanel*)rightPanel,
|
||||
(MatrixKernel*)right.Buffer,
|
||||
right.KernelColumnLength,
|
||||
right.KernelRowLength, k, j);
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_panel_fma((MatrixPanel*)leftPanel,
|
||||
(MatrixPanel*)rightPanel,
|
||||
(MatrixPanel*)ansPanel);
|
||||
}
|
||||
NativeIntrinsic.Intrinsic
|
||||
.f32_store_panel((MatrixPanel*)ansPanel,
|
||||
(MatrixKernel*)ans.Buffer,
|
||||
ans.KernelColumnLength, ans.KernelRowLength,
|
||||
i, j);
|
||||
}
|
||||
}
|
||||
MatrixPanel.Destroy(leftPanel);
|
||||
MatrixPanel.Destroy(rightPanel);
|
||||
MatrixPanel.Destroy(ansPanel);
|
||||
if (count > 256) {
|
||||
MatrixParallel.ReturnParallelResources(ref pool!);
|
||||
}
|
||||
return;
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = (nint)left.Buffer;
|
||||
package->Right = (nint)right.Buffer;
|
||||
package->Answer = (nint)ans.Buffer;
|
||||
package->AnsPrimOffset = ans.KernelRowLength;
|
||||
package->AnsSecOffset = ans.KernelColumnLength;
|
||||
package->LeftPrimOffset = left.KernelColumnLength;
|
||||
package->PrimCount = ans.KernelColumnLength / size;
|
||||
package->SecCount = ans.KernelRowLength / size;
|
||||
package->ElementSize = size;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationSpecial.SEQ_FMA);
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
public static unsafe Matrix<float> Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
public static unsafe void Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
{
|
||||
if (left.ColumnLength != ans.ColumnLength || left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
ScalarPacket* scalar = MatrixParallelFactory.CreateScalarPacket();
|
||||
scalar->Data<float>(0) = right;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Right = (nint)left.Buffer;
|
||||
package->Answer = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->Scalar = scalar;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_scalar_mul;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
MatrixParallelFactory.Release(scalar);
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Sub(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
=======
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static unsafe Matrix<float> Sub(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Sub(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
{
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
left.RowLength != right.RowLength ||
|
||||
left.ColumnLength != ans.ColumnLength ||
|
||||
left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 256)
|
||||
{
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
NativeIntrinsic.Intrinsic.f32_buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
}
|
||||
MatrixParallelTaskPackage* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = (nint)left.Buffer;
|
||||
package->Right = (nint)right.Buffer;
|
||||
package->Answer = (nint)ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_buffer_sub;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
taskGroup.Dispose();
|
||||
<<<<<<<< HEAD:StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
=======
|
||||
return ans;
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
========
|
||||
return;
|
||||
>>>>>>>> stgsharp-dev/giga:StgSharp.Mathematics/Numeric/MatrixCompute.cs
|
||||
}
|
||||
|
||||
}
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixComputeModel"
|
||||
// Project: StgSharp
|
||||
@@ -46,17 +50,31 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
((delegate* unmanaged[Cdecl]<void*, void*, void*, long, void>)p->ComputeHandle)((void*)(p->Left + offset),
|
||||
(void*)(p->Right + offset),
|
||||
(void*)(p->Result + offset),
|
||||
(void*)(p->Answer + offset),
|
||||
count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void BufferComputeBinaryScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
long offset = Unsafe.As<int, long>(ref p->PrimTileOffset) * size;
|
||||
ScalarPacket* scalar = p->Scalar;
|
||||
((delegate* unmanaged[Cdecl]<void*, void*, void*,ScalarPacket*, long, void>)p->ComputeHandle)((void*)(p->Left + offset),
|
||||
(void*)(p->Right + offset),
|
||||
(void*)(p->Answer + offset),
|
||||
scalar,
|
||||
count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void BufferComputeNoOperatorScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
long offset = Unsafe.As<int, long>(ref p->PrimTileOffset) * size;
|
||||
((delegate* unmanaged[Cdecl]<void*, ScalarPacket*,long, void>)p->ComputeHandle)((void*)(p->Result + offset),
|
||||
((delegate* unmanaged[Cdecl]<void*, ScalarPacket*,long, void>)p->ComputeHandle)((void*)(p->Answer + offset),
|
||||
p->Scalar, count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
@@ -68,7 +86,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
long offset = Unsafe.As<int, long>(ref p->PrimTileOffset) * size;
|
||||
|
||||
((delegate* unmanaged[Cdecl]<void*, void*, long, void>)p->ComputeHandle)((void*)(p->Right + offset),
|
||||
(void*)(p->Result + offset),
|
||||
(void*)(p->Answer + offset),
|
||||
count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
@@ -79,6 +97,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
long offset = Unsafe.As<int, long>(ref p->PrimTileOffset) * size;
|
||||
((delegate* unmanaged[Cdecl]< void*, void*, ScalarPacket*, long, void>)p->ComputeHandle)((void*)(p->Right + offset),
|
||||
<<<<<<< HEAD
|
||||
(void*)(p->Result + offset),
|
||||
<<<<<<< HEAD
|
||||
p->Scalar,
|
||||
@@ -95,53 +114,25 @@ namespace StgSharp.Mathematics.Numeric
|
||||
=======
|
||||
internal static unsafe void Compute_Binary(MatrixParallelTaskPackage* p)
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
(void*)(p->Answer + offset),
|
||||
p->Scalar,
|
||||
count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void SpecialBufferCompute(MatrixParallelTaskPackage* p)
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
{
|
||||
int eSize = p->ElementSize;
|
||||
|
||||
// base pointer to matrix kernels
|
||||
nint l = p->Left, r = p->Right, a = p->Result;
|
||||
long
|
||||
|
||||
// set beginning value to counters for primary offsets
|
||||
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
lLimit = pCount - p->LeftPrimOffset,
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void> op =
|
||||
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void>)p->ComputeHandle;
|
||||
for (long i = p->PrimTileOffset % pCount; i < pCount; i++)
|
||||
switch ((MatrixOperationSpecial)p->ComputeMode.ParameterStyle)
|
||||
{
|
||||
// update primary counters
|
||||
// if reaches edge, reset to zero
|
||||
lCount = i < lLimit ? lCount + p->LeftPrimStride : 0;
|
||||
rCount = i < rLimit ? rCount + p->RightPrimStride : 0;
|
||||
aCount = i < rLimit ? aCount + p->ResultPrimStride : 0;
|
||||
|
||||
// get kernel column pointers
|
||||
nint left = l + (nint)(lCount * eSize);
|
||||
nint right = r + (nint)(rCount * eSize);
|
||||
nint ans = a + (nint)(aCount * eSize);
|
||||
long
|
||||
lc = (long)p->LeftSecOffset * p->LeftSecStride,
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
ll = sCount - p->LeftSecOffset,
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
for (long j = p->SecTileOffset % sCount; j < sCount; j++)
|
||||
{
|
||||
lc = j < ll ? lc + p->LeftSecStride : 0;
|
||||
rc = j < rl ? rc + p->RightSecStride : 0;
|
||||
ac = j < al ? ac + p->ResultSecStride : 0;
|
||||
op(left + (nint)lc, right + (nint)rc, ans + (nint)ac);
|
||||
}
|
||||
case MatrixOperationSpecial.SEQ_FMA:
|
||||
MatrixCompute.ComputeFmaPanelF32(p);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
@@ -297,6 +288,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
}
|
||||
}
|
||||
MatrixParallelFactory.Release(p);
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallel.Publish"
|
||||
// Project: StgSharp
|
||||
@@ -51,18 +51,15 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelTaskPackage* nonGeneric = package;
|
||||
switch (nonGeneric->ComputeMode.OperationStyle)
|
||||
{
|
||||
case MatrixOperationStyle.PANEL_OP:
|
||||
throw new NotImplementedException();
|
||||
case MatrixOperationStyle.BUFFER_OP:
|
||||
case MatrixIndexStyle.BUFFER_INDEX:
|
||||
return ScheduleBufferTask(nonGeneric);
|
||||
case MatrixOperationStyle.KERNEL_OP:
|
||||
return ScheduleKernelTask(nonGeneric);
|
||||
default:
|
||||
throw new InvalidOperationException($"Unknown mode {nonGeneric->ComputeMode.OperationStyle}.");
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe MatrixParallelHandle ScheduleBufferTask(MatrixParallelTaskPackage* package)
|
||||
private static unsafe MatrixParallelHandle ScheduleBufferTask(
|
||||
MatrixParallelTaskPackage* package)
|
||||
{
|
||||
int primCount = package->PrimCount;
|
||||
int secCount = package->SecCount;
|
||||
@@ -113,79 +110,5 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return handle;
|
||||
}
|
||||
|
||||
private static unsafe MatrixParallelHandle ScheduleKernelTask(MatrixParallelTaskPackage* package)
|
||||
{
|
||||
int primCount = package->PrimCount;
|
||||
int secCount = package->SecCount;
|
||||
int tileWidth = (1024 / secCount) + 1;
|
||||
int tileCount = (primCount + tileWidth - 1) / tileWidth;
|
||||
|
||||
MatrixParallelThread[] pool = LeadParallel(tileCount);
|
||||
/*
|
||||
if (pool.Length == 0)
|
||||
{
|
||||
// no need
|
||||
// LeadParallel has contained capacity check
|
||||
}
|
||||
/**/
|
||||
MatrixParallelHandle handle = new MatrixParallelHandle(pool);
|
||||
if (handle.Wraps.Length == 1)
|
||||
{
|
||||
handle.Wraps[0].WrapTask.Enqueue((nint)package);
|
||||
return handle;
|
||||
}
|
||||
int threadCount = pool.Length;
|
||||
int tilePerThreadLess = tileCount / threadCount; // tiles per thread without extra slice
|
||||
int columnAfterBaseTile = tileCount % threadCount * tileWidth; // tile sliced into columns
|
||||
int extraColumnPerThread = columnAfterBaseTile / threadCount;
|
||||
int extraColumnCount = columnAfterBaseTile % threadCount; // columns to be sliced
|
||||
|
||||
int total = primCount;
|
||||
MatrixParallelTaskPackage* current = package;
|
||||
foreach (MatrixParallelWrap wrap in handle.Wraps)
|
||||
{
|
||||
bool hasSlice = columnAfterBaseTile > 0;
|
||||
bool isLargeSlice = extraColumnCount > 0;
|
||||
|
||||
// _count tiles for wrap
|
||||
int wrapWidth = wrap!.WrapTaskCapacity/**/;
|
||||
int columnFromSlicingCount = (hasSlice ? extraColumnPerThread : 0) * wrapWidth;
|
||||
int baseColumn = wrapWidth * tilePerThreadLess * tileWidth;
|
||||
int columnInWrap = baseColumn + columnFromSlicingCount + (isLargeSlice ? 1 : 0);
|
||||
|
||||
// set tasks
|
||||
if (columnInWrap == 0)
|
||||
{
|
||||
#if DEBUG
|
||||
throw new InvalidOperationException("Zero tasks published.");
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// update current task
|
||||
current->PrimColumnCountInTile = columnInWrap;
|
||||
current->SecColumnCountInTile = current->SecCount;
|
||||
current->SecTileOffset = 0;
|
||||
|
||||
// remove tiles _count
|
||||
extraColumnCount--;
|
||||
columnAfterBaseTile -= columnFromSlicingCount;
|
||||
total -= columnInWrap;
|
||||
|
||||
// set to wrap and push
|
||||
wrap.WrapTask.Enqueue((nint)current);
|
||||
|
||||
if (total <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current = MatrixParallelFactory.FromExistPackage(current);
|
||||
current->PrimTileOffset += columnInWrap;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallel"
|
||||
// Project: StgSharp
|
||||
@@ -32,6 +36,7 @@
|
||||
using StgSharp.Collections;
|
||||
using System;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -42,10 +47,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public static class MatrixParallel
|
||||
=======
|
||||
using System.Collections.Concurrent;
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
@@ -113,7 +120,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
=======
|
||||
}
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
}
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallelTaskPackage"
|
||||
// Project: StgSharp
|
||||
@@ -52,12 +52,17 @@ namespace StgSharp.Mathematics.Numeric
|
||||
* matrix_op_mode;
|
||||
*/
|
||||
|
||||
public enum MatrixOperationStyle : short
|
||||
public enum MatrixOperationSpecial : short
|
||||
{
|
||||
|
||||
PANEL_OP = 1,
|
||||
BUFFER_OP = 2,
|
||||
KERNEL_OP = 3,
|
||||
SEQ_FMA = -1,
|
||||
|
||||
}
|
||||
|
||||
public enum MatrixIndexStyle : short
|
||||
{
|
||||
|
||||
BUFFER_INDEX = 1,
|
||||
|
||||
}
|
||||
|
||||
@@ -73,11 +78,15 @@ namespace StgSharp.Mathematics.Numeric
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MatrixOpMode(MatrixOperationStyle style, MatrixOperationParam paramLayout)
|
||||
public struct MatrixOpMode(MatrixIndexStyle style, MatrixOperationParam paramLayout)
|
||||
{
|
||||
|
||||
public MatrixIndexStyle OperationStyle = style;
|
||||
|
||||
public MatrixOperationParam ParameterStyle = paramLayout;
|
||||
public MatrixOperationStyle OperationStyle = style;
|
||||
|
||||
public MatrixOpMode(MatrixIndexStyle style, MatrixOperationSpecial paramLayout)
|
||||
: this(style, (MatrixOperationParam)paramLayout) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -86,9 +95,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy(MatrixParallelTaskPackage* source, MatrixParallelTaskPackage* target)
|
||||
public static unsafe void Copy(
|
||||
MatrixParallelTaskPackage* source,
|
||||
MatrixParallelTaskPackage* target)
|
||||
{
|
||||
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage), sizeof(MatrixParallelTaskPackage));
|
||||
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage),
|
||||
sizeof(MatrixParallelTaskPackage));
|
||||
}
|
||||
|
||||
#region source
|
||||
@@ -102,7 +114,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
#region ans
|
||||
|
||||
// Group 2: Result kernel base address + reserved
|
||||
[FieldOffset(16)] public IntPtr Result; // 8
|
||||
[FieldOffset(16)] public IntPtr Answer; // 8
|
||||
[FieldOffset(24)] public int ElementSize;
|
||||
[FieldOffset(28)] public int ReservedPtr0; // 4 (extension/reserved)
|
||||
|
||||
@@ -128,10 +140,10 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
#region ans enum
|
||||
|
||||
[FieldOffset(64)]public int ResultPrimOffset; // 4
|
||||
[FieldOffset(68)]public int ResultPrimStride; // 4
|
||||
[FieldOffset(72)]public int ResultSecOffset; // 4
|
||||
[FieldOffset(76)] public int ResultSecStride; // 4
|
||||
[FieldOffset(64)]public int AnsPrimOffset; // 4
|
||||
[FieldOffset(68)]public int AnsPrimStride; // 4
|
||||
[FieldOffset(72)]public int AnsSecOffset; // 4
|
||||
[FieldOffset(76)] public int AnsSecStride; // 4
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallelThread"
|
||||
// Project: StgSharp
|
||||
@@ -89,11 +93,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
while (taskQueue.TryDequeue(out nint handle))
|
||||
{
|
||||
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)handle;
|
||||
if ((short)p->ComputeMode.ParameterStyle < 0) {
|
||||
MatrixComputeModel.SpecialBufferCompute(p);
|
||||
}
|
||||
switch (p->ComputeMode.OperationStyle)
|
||||
{
|
||||
case MatrixOperationStyle.PANEL_OP:
|
||||
break;
|
||||
case MatrixOperationStyle.BUFFER_OP:
|
||||
case MatrixIndexStyle.BUFFER_INDEX:
|
||||
switch (p->ComputeMode.ParameterStyle)
|
||||
{
|
||||
case MatrixOperationParam.RIGHT_ANS_PARAM:
|
||||
@@ -106,6 +111,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixComputeModel.BufferComputeUnaryScalar(p);
|
||||
break;
|
||||
case MatrixOperationParam.LEFT_RIGHT_ANS_SCALAR_PARAM:
|
||||
MatrixComputeModel.BufferComputeBinaryScalar(p);
|
||||
break;
|
||||
case MatrixOperationParam.ANS_SCALAR_PARAM:
|
||||
MatrixComputeModel.BufferComputeNoOperatorScalar(p);
|
||||
@@ -114,6 +120,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
break;
|
||||
}
|
||||
break;
|
||||
<<<<<<< HEAD
|
||||
case MatrixOperationStyle.KERNEL_OP:
|
||||
switch (p->ComputeMode.ParameterStyle)
|
||||
{
|
||||
@@ -146,6 +153,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
break;
|
||||
}
|
||||
break;
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -417,6 +426,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
private static extern IntPtr GetCurrentThread();
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
private static extern nuint SetThreadAffinityMask(
|
||||
IntPtr hThread,
|
||||
@@ -424,6 +434,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
=======
|
||||
private static extern nuint SetThreadAffinityMask(IntPtr hThread, nuint dwThreadAffinityMask);
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
private static extern nuint SetThreadAffinityMask(
|
||||
IntPtr hThread,
|
||||
nuint dwThreadAffinityMask);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
[LibraryImport("kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallelWrap"
|
||||
// Project: StgSharp
|
||||
@@ -104,18 +104,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
while (tasks.TryDequeue(out nint handle))
|
||||
{
|
||||
MatrixParallelTaskPackage* task = (MatrixParallelTaskPackage*)handle;
|
||||
switch (task->ComputeMode.OperationStyle)
|
||||
if ((int)task->ComputeMode.OperationStyle > 0)
|
||||
{
|
||||
case MatrixOperationStyle.PANEL_OP:
|
||||
break;
|
||||
case MatrixOperationStyle.BUFFER_OP:
|
||||
PublishBufferTaskToWorkers(task);
|
||||
break;
|
||||
case MatrixOperationStyle.KERNEL_OP:
|
||||
PublishBufferTaskToWorkers(task);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
PublishBufferTaskToWorkers(task);
|
||||
} else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,73 +163,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
// Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
private void PublishKernelTaskToWorkers(MatrixParallelTaskPackage* package)
|
||||
{
|
||||
int primCount = package->PrimCount;
|
||||
int secCount = package->SecCount;
|
||||
ReadOnlySpan<MatrixParallelThread> pool = Threads;
|
||||
|
||||
if (pool.Length == 1)
|
||||
{
|
||||
pool[0].Tasks.Enqueue((nint)package);
|
||||
return;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
/*
|
||||
int threadCount = pool.Length;
|
||||
int tilePerThreadLess = tileCount / threadCount; // tiles per thread without extra slice
|
||||
int columnAfterBaseTile = tileCount % threadCount * tileWidth; // tile sliced into columns
|
||||
int extraColumnPerThread = columnAfterBaseTile / threadCount;
|
||||
int extraColumnCount = columnAfterBaseTile % threadCount; // columns to be sliced
|
||||
|
||||
int total = primCount;
|
||||
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(threadCount);
|
||||
MatrixParallelTaskPackageNonGeneric* current = package;
|
||||
foreach (MatrixParallelWrap wrap in pool.Wraps)
|
||||
{
|
||||
bool hasSlice = columnAfterBaseTile > 0;
|
||||
bool isLargeSlice = extraColumnCount > 0;
|
||||
|
||||
// _count tiles for wrap
|
||||
int wrapWidth = wrap!.WrapTaskCapacity;
|
||||
int columnFromSlicingCount = (hasSlice ? extraColumnPerThread : 0) * wrapWidth;
|
||||
int baseColumn = wrapWidth * tilePerThreadLess * tileWidth;
|
||||
int columnInWrap = baseColumn + columnFromSlicingCount + (isLargeSlice ? 1 : 0);
|
||||
|
||||
// set tasks
|
||||
if (columnInWrap == 0)
|
||||
{
|
||||
#if DEBUG
|
||||
throw new InvalidOperationException("Zero tasks published.");
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// update current task
|
||||
current->PrimColumnCountInTile = columnInWrap;
|
||||
current->SecColumnCountInTile = current->SecCount;
|
||||
current->SecTileOffset = 0;
|
||||
|
||||
// remove tiles _count
|
||||
extraColumnCount--;
|
||||
columnAfterBaseTile -= columnFromSlicingCount;
|
||||
total -= columnInWrap;
|
||||
|
||||
// set to wrap and push
|
||||
wrap.WrapTask = current;
|
||||
|
||||
if (total <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current = MatrixParallelFactory.FromExistPackage(current);
|
||||
current->PrimTileOffset += columnInWrap;
|
||||
}
|
||||
/**/
|
||||
return;
|
||||
}
|
||||
|
||||
#region wrap task
|
||||
|
||||
internal unsafe Queue<nint> WrapTask { get; set; } = [];
|
||||
|
||||
@@ -141,12 +141,18 @@ typedef void(SN_DECL *PNL_PROC_RAS)(mat_panel *right, mat_panel *ans, scalar_pac
|
||||
|
||||
#define PNL_PROC(T_type, T_arch, T_op_name) T_type##_pnl_##T_op_name##_##T_arch
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
#define DECLARE_PNL_PROC_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, \
|
||||
T_op_name)(MAT_PANEL_##T_arch##(T_type) *restrict ans)
|
||||
=======
|
||||
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
#define DECLARE_PNL_PROC_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, \
|
||||
T_op_name)(MAT_PANEL_##T_arch##(T_type) *restrict ans)
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, \
|
||||
T_op_name)(MAT_PANEL_##T_arch##(T_type) const *left, \
|
||||
@@ -230,6 +236,9 @@ DECLARE_BUF_PROC_ANS_SCALAR(float, 512, fill);
|
||||
#pragma region fma
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_PNL_PROC_ANS(float, sse, clear);
|
||||
DECLARE_PNL_PROC_ANS(float, avx, clear);
|
||||
DECLARE_PNL_PROC_ANS(float, 512, clear);
|
||||
@@ -238,10 +247,13 @@ DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, sse, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx_fma, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, 512, fma);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, sse, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx, fma);
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -283,10 +295,14 @@ typedef struct sn_intrinsic {
|
||||
BUF_PROC_LRA f32_buffer_sub;
|
||||
KER_PROC_RA f32_buffer_transpose;
|
||||
PANEL_PROC f32_build_panel;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
PANEL_PROC f32_clear_panel;
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
PANEL_PROC f32_clear_panel;
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
VECTORNORMALIZEPROC f32_normalize_3;
|
||||
PNL_PROC_LRA f32_panel_fma;
|
||||
PANEL_PROC f32_store_panel;
|
||||
|
||||
@@ -110,14 +110,15 @@ extern __declspec(align(64)) sn_zero_kernel_u64 SN_ZERO_KERNEL;
|
||||
MAT_KERNEL(element) const *const matrix, int col_length, int row_length, \
|
||||
int col_index, int row_index)
|
||||
#define DECLARE_STORE_PANEL(arch, element) \
|
||||
INTERNAL void SN_DECL STORE_PANEL(arch, element)(MAT_KERNEL(element) *restrict matrix, \
|
||||
MAT_PANEL_##arch(element) \
|
||||
INTERNAL void SN_DECL STORE_PANEL(arch, element)(MAT_PANEL_##arch(element) \
|
||||
const *const panel, \
|
||||
MAT_KERNEL(element) *restrict matrix, \
|
||||
int col_length, int row_length, \
|
||||
int col_index, int row_index)
|
||||
|
||||
/* Declarations for AVX float variant */
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
DECLARE_BUILD_PANEL(sse, float);
|
||||
DECLARE_BUILD_PANEL(avx, float);
|
||||
DECLARE_BUILD_PANEL(512, float);
|
||||
@@ -125,8 +126,17 @@ DECLARE_STORE_PANEL(sse, float);
|
||||
DECLARE_STORE_PANEL(avx, float);
|
||||
DECLARE_STORE_PANEL(512, float);
|
||||
=======
|
||||
=======
|
||||
DECLARE_BUILD_PANEL(sse, float);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_BUILD_PANEL(avx, float);
|
||||
DECLARE_BUILD_PANEL(512, float);
|
||||
DECLARE_STORE_PANEL(sse, float);
|
||||
DECLARE_STORE_PANEL(avx, float);
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
DECLARE_STORE_PANEL(512, float);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
#endif /* SN_MATKERNEL */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "StgSharpNative.h"
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_PNL_PROC_ANS(float, sse, clear)
|
||||
{
|
||||
register __m128 zero = _mm_setzero_ps();
|
||||
@@ -13,15 +16,22 @@ DECLARE_PNL_PROC_ANS(float, sse, clear)
|
||||
DECLARE_PNL_PROC_ANS(float, avx, clear)
|
||||
{
|
||||
register __m256 zero = _mm256_setzero_ps();
|
||||
<<<<<<< HEAD
|
||||
PANEL_COL_VEC((*ans), 0, 0) = zero;
|
||||
PANEL_COL_VEC((*ans), 1, 0) = zero;
|
||||
PANEL_COL_VEC((*ans), 2, 0) = zero;
|
||||
PANEL_COL_VEC((*ans), 3, 0) = zero;
|
||||
=======
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
PANEL_COL_VEC((*ans), i, 0) = zero;
|
||||
}
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
}
|
||||
|
||||
DECLARE_PNL_PROC_ANS(float, 512, clear)
|
||||
{
|
||||
register __m512 zero = _mm512_setzero_ps();
|
||||
<<<<<<< HEAD
|
||||
PANEL_COL_VEC((*ans), 0, 0) = zero;
|
||||
PANEL_COL_VEC((*ans), 1, 0) = zero;
|
||||
PANEL_COL_VEC((*ans), 2, 0) = zero;
|
||||
@@ -30,6 +40,13 @@ DECLARE_PNL_PROC_ANS(float, 512, clear)
|
||||
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
PANEL_COL_VEC((*ans), i, 0) = zero;
|
||||
}
|
||||
}
|
||||
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// Matrix transpose implementations
|
||||
DECLARE_KER_PROC_RIGHT_ANS(float, sse, transpose)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,9 @@ DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, sse, fma)
|
||||
// ans = left * right + ans
|
||||
// right is not transposed
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx_fma, fma)
|
||||
{
|
||||
static const __m256i idx0 = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
@@ -98,8 +101,11 @@ DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx_fma, fma)
|
||||
|
||||
// ans = left * right + ans
|
||||
// right is not transposed
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx, fma)
|
||||
{
|
||||
static const __m256i idx0 = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
@@ -8,16 +8,16 @@ DECLARE_BUILD_PANEL(avx, float)
|
||||
const int has_right = (col_index + 1) < col_length;
|
||||
const int has_bottom = (row_index + 1) < row_length;
|
||||
|
||||
const MAT_KERNEL(float) *const k_lt = matrix + (col_index * row_length + row_index);
|
||||
const MAT_KERNEL(float) *const k_lt = matrix + (row_index * col_length + col_index);
|
||||
const MAT_KERNEL(float) *const k_rt =
|
||||
has_right ? (matrix + ((col_index + 1) * row_length + row_index)) :
|
||||
has_right ? (matrix + (row_index * col_length + (col_index + 1))) :
|
||||
(const MAT_KERNEL(float) *)&SN_ZERO_KERNEL;
|
||||
const MAT_KERNEL(float) *const k_lb =
|
||||
has_bottom ? (matrix + (col_index * row_length + (row_index + 1))) :
|
||||
has_bottom ? (matrix + ((row_index + 1) * col_length + col_index)) :
|
||||
(const MAT_KERNEL(float) *)&SN_ZERO_KERNEL;
|
||||
const MAT_KERNEL(float) *const k_rb =
|
||||
(has_right && has_bottom) ?
|
||||
(matrix + ((col_index + 1) * row_length + (row_index + 1))) :
|
||||
(matrix + ((row_index + 1) * col_length + (col_index + 1))) :
|
||||
(const MAT_KERNEL(float) *)&SN_ZERO_KERNEL;
|
||||
|
||||
register __m128 top128, bot128;
|
||||
@@ -41,11 +41,18 @@ DECLARE_BUILD_PANEL(avx, float)
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
DECLARE_BUILD_PANEL(sse, float)
|
||||
{
|
||||
/* Single kernel -> 4 columns, each is one __m128 column vector. */
|
||||
const MAT_KERNEL(float) *src = matrix + (col_index * row_length + row_index);
|
||||
=======
|
||||
DECLARE_BUILD_PANEL(sse, float)
|
||||
{
|
||||
/* Single kernel -> 4 columns, each is one __m128 column vector. */
|
||||
const MAT_KERNEL(float) *src = matrix + (row_index * col_length + col_index);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
for (int pc = 0; pc < 4; ++pc) {
|
||||
PANEL_COL_VEC((*panel), pc, 0) = src->xmm[pc];
|
||||
@@ -55,22 +62,35 @@ DECLARE_BUILD_PANEL(sse, float)
|
||||
DECLARE_BUILD_PANEL(512, float)
|
||||
{
|
||||
const MAT_KERNEL(float) *const zero = (const MAT_KERNEL(float) *)&SN_ZERO_KERNEL;
|
||||
<<<<<<< HEAD
|
||||
const MAT_KERNEL(float) *k[4][4];
|
||||
=======
|
||||
const MAT_KERNEL(float) * k[4][4];
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
for (int kc = 0; kc < 4; ++kc) {
|
||||
for (int kr = 0; kr < 4; ++kr) {
|
||||
const int col = col_index + kc;
|
||||
const int row = row_index + kr;
|
||||
k[kc][kr] = (col < col_length && row < row_length) ?
|
||||
<<<<<<< HEAD
|
||||
(matrix + (col * row_length + row)) :
|
||||
=======
|
||||
(matrix + (row * col_length + col)) :
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
zero;
|
||||
}
|
||||
}
|
||||
|
||||
/* Each panel column corresponds to a kernel column (0..3) within a block col (0..3). */
|
||||
for (int pc = 0; pc < 16; ++pc) {
|
||||
<<<<<<< HEAD
|
||||
const int blk_col = pc >> 2; /* which kernel column block (0..3) */
|
||||
const int kc_col = pc & 3; /* column inside a 4x4 kernel */
|
||||
=======
|
||||
const int blk_col = pc >> 2; /* which kernel column block (0..3) */
|
||||
const int kc_col = pc & 3; /* column inside a 4x4 kernel */
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
const __m128 r0 = k[blk_col][0]->xmm[kc_col];
|
||||
const __m128 r1 = k[blk_col][1]->xmm[kc_col];
|
||||
@@ -87,8 +107,11 @@ DECLARE_BUILD_PANEL(512, float)
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
DECLARE_STORE_PANEL(avx, float)
|
||||
{
|
||||
const int Q = 8; /* fixed for AVX float panel */
|
||||
@@ -100,19 +123,19 @@ DECLARE_STORE_PANEL(avx, float)
|
||||
const int has_bottom = (row_index + 1) < row_length;
|
||||
|
||||
MAT_KERNEL(float) *const k_lt = (col_index < col_length && row_index < row_length) ?
|
||||
(matrix + (col_index * row_length + row_index)) :
|
||||
(matrix + (row_index * col_length + col_index)) :
|
||||
&zero;
|
||||
MAT_KERNEL(float) *const k_rt =
|
||||
has_right && (row_index < row_length) ?
|
||||
(matrix + ((col_index + 1) * row_length + row_index)) :
|
||||
(matrix + (row_index * col_length + (col_index + 1))) :
|
||||
&zero;
|
||||
MAT_KERNEL(float) *const k_lb =
|
||||
has_bottom && (col_index < col_length) ?
|
||||
(matrix + (col_index * row_length + (row_index + 1))) :
|
||||
(matrix + ((row_index + 1) * col_length + col_index)) :
|
||||
&zero;
|
||||
MAT_KERNEL(float) *const k_rb =
|
||||
(has_right && has_bottom) ?
|
||||
(matrix + ((col_index + 1) * row_length + (row_index + 1))) :
|
||||
(matrix + ((row_index + 1) * col_length + (col_index + 1))) :
|
||||
&zero;
|
||||
|
||||
register __m128 top128, bot128;
|
||||
@@ -145,10 +168,17 @@ DECLARE_STORE_PANEL(avx, float)
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
|
||||
DECLARE_STORE_PANEL(sse, float)
|
||||
{
|
||||
MAT_KERNEL(float) *dst = matrix + (col_index * row_length + row_index);
|
||||
=======
|
||||
|
||||
DECLARE_STORE_PANEL(sse, float)
|
||||
{
|
||||
MAT_KERNEL(float) *dst = matrix + (row_index * col_length + col_index);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
for (int pc = 0; pc < 4; ++pc) {
|
||||
const __m128 col = PANEL_COL_VEC((*panel), pc, 0);
|
||||
@@ -159,21 +189,34 @@ DECLARE_STORE_PANEL(sse, float)
|
||||
DECLARE_STORE_PANEL(512, float)
|
||||
{
|
||||
MAT_KERNEL(float) zero;
|
||||
<<<<<<< HEAD
|
||||
MAT_KERNEL(float) *k[4][4];
|
||||
=======
|
||||
MAT_KERNEL(float) * k[4][4];
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
for (int kc = 0; kc < 4; ++kc) {
|
||||
for (int kr = 0; kr < 4; ++kr) {
|
||||
const int col = col_index + kc;
|
||||
const int row = row_index + kr;
|
||||
k[kc][kr] = (col < col_length && row < row_length) ?
|
||||
<<<<<<< HEAD
|
||||
(matrix + (col * row_length + row)) :
|
||||
=======
|
||||
(matrix + (row * col_length + col)) :
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
&zero;
|
||||
}
|
||||
}
|
||||
|
||||
for (int pc = 0; pc < 16; ++pc) {
|
||||
<<<<<<< HEAD
|
||||
const int blk_col = pc >> 2; /* which kernel column block (0..3) */
|
||||
const int kc_col = pc & 3; /* column inside a 4x4 kernel */
|
||||
=======
|
||||
const int blk_col = pc >> 2; /* which kernel column block (0..3) */
|
||||
const int kc_col = pc & 3; /* column inside a 4x4 kernel */
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
const __m512 col = PANEL_COL_VEC((*panel), pc, 0);
|
||||
|
||||
@@ -191,5 +234,8 @@ DECLARE_STORE_PANEL(512, float)
|
||||
k[blk_col][3]->xmm[kc_col] = r3;
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
+116
-116
@@ -4,120 +4,120 @@
|
||||
|
||||
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table)
|
||||
{
|
||||
table->glfwCreateCursor = glfwCreateCursor;
|
||||
table->glfwCreateStandardCursor = glfwCreateStandardCursor;
|
||||
table->glfwCreateWindow = glfwCreateWindow;
|
||||
table->glfwDefaultWindowHints = glfwDefaultWindowHints;
|
||||
table->glfwDestroyCursor = glfwDestroyCursor;
|
||||
table->glfwDestroyWindow = glfwDestroyWindow;
|
||||
table->glfwExtensionSupported = glfwExtensionSupported;
|
||||
table->glfwFocusWindow = glfwFocusWindow;
|
||||
table->glfwGetClipboardString = glfwGetClipboardString;
|
||||
table->glfwGetCurrentContext = glfwGetCurrentContext;
|
||||
table->glfwGetCursorPos = glfwGetCursorPos;
|
||||
table->glfwGetError = glfwGetError;
|
||||
table->glfwGetFrameBufferSize = glfwGetFramebufferSize;
|
||||
table->glfwGetGamepadName = glfwGetGamepadName;
|
||||
table->glfwGetGamepadState = glfwGetGamepadState;
|
||||
table->glfwGetGammaRamp = glfwGetGammaRamp;
|
||||
table->glfwGetInputMode = glfwGetInputMode;
|
||||
table->glfwGetJoystickAxes = glfwGetJoystickAxes;
|
||||
table->glfwGetJoystickButtons = glfwGetJoystickButtons;
|
||||
table->glfwGetJoystickGUID = glfwGetJoystickGUID;
|
||||
table->glfwGetJoystickHats = glfwGetJoystickHats;
|
||||
table->glfwGetJoystickName = glfwGetJoystickName;
|
||||
table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer;
|
||||
table->glfwGetKey = glfwGetKey;
|
||||
table->glfwGetKeyName = glfwGetKeyName;
|
||||
table->glfwGetKeyScancode = glfwGetKeyScancode;
|
||||
table->glfwGetMonitorContentScale = glfwGetMonitorContentScale;
|
||||
table->glfwGetMonitorName = glfwGetMonitorName;
|
||||
table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize;
|
||||
table->glfwGetMonitorPos = glfwGetMonitorPos;
|
||||
table->glfwGetMonitors = glfwGetMonitors;
|
||||
table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer;
|
||||
table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea;
|
||||
table->glfwGetMouseButton = glfwGetMouseButton;
|
||||
table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor;
|
||||
table->glfwGetProcAddress = glfwGetProcAddress;
|
||||
table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions;
|
||||
table->glfwGetTime = glfwGetTime;
|
||||
table->glfwGetTimerFrequency = glfwGetTimerFrequency;
|
||||
table->glfwGetTimerValue = glfwGetTimerValue;
|
||||
table->glfwGetVersion = glfwGetVersion;
|
||||
table->glfwGetVersionString = glfwGetVersionString;
|
||||
table->glfwGetVideoMode = glfwGetVideoMode;
|
||||
table->glfwGetVideoModes = glfwGetVideoModes;
|
||||
table->glfwGetWindowAttrib = glfwGetWindowAttrib;
|
||||
table->glfwGetWindowContentScale = glfwGetWindowContentScale;
|
||||
table->glfwGetWindowFrameSize = glfwGetWindowFrameSize;
|
||||
table->glfwGetWindowMonitor = glfwGetWindowMonitor;
|
||||
table->glfwGetWindowOpacity = glfwGetWindowOpacity;
|
||||
table->glfwGetWindowPos = glfwGetWindowPos;
|
||||
table->glfwGetWindowSize = glfwGetWindowSize;
|
||||
table->glfwGetWindowUserPointer = glfwGetWindowUserPointer;
|
||||
table->glfwHideWindow = glfwHideWindow;
|
||||
table->glfwIconifyWindow = glfwIconifyWindow;
|
||||
table->glfwInit = glfwInit;
|
||||
table->glfwInitHint = glfwInitHint;
|
||||
table->glfwJoystickIsGamePad = glfwJoystickIsGamepad;
|
||||
table->glfwJoystickPresent = glfwJoystickPresent;
|
||||
table->glfwMakeContextCurrent = glfwMakeContextCurrent;
|
||||
table->glfwMaximizeWindow = glfwMaximizeWindow;
|
||||
table->glfwPollEvents = glfwPollEvents;
|
||||
table->glfwPostEmptyEvent = glfwPostEmptyEvent;
|
||||
table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported;
|
||||
table->glfwRequestWindowAttention = glfwRequestWindowAttention;
|
||||
table->glfwRestoreWindow = glfwRestoreWindow;
|
||||
table->glfwSetCharCallback = glfwSetCharCallback;
|
||||
table->glfwSetCharModsCallback = glfwSetCharModsCallback;
|
||||
table->glfwSetClipboardString = glfwSetClipboardString;
|
||||
table->glfwSetCursor = glfwSetCursor;
|
||||
table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback;
|
||||
table->glfwSetCursorPos = glfwSetCursorPos;
|
||||
table->glfwSetCursorPosCallback = glfwSetCursorPosCallback;
|
||||
table->glfwSetDropCallback = glfwSetDropCallback;
|
||||
table->glfwSetErrorCallback = glfwSetErrorCallback;
|
||||
table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback;
|
||||
table->glfwSetGamma = glfwSetGamma;
|
||||
table->glfwSetGammaRamp = glfwSetGammaRamp;
|
||||
table->glfwSetInputMode = glfwSetInputMode;
|
||||
table->glfwSetJoystickCallback = glfwSetJoystickCallback;
|
||||
table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer;
|
||||
table->glfwSetKeyCallback = glfwSetKeyCallback;
|
||||
table->glfwSetMonitorCallback = glfwSetMonitorCallback;
|
||||
table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer;
|
||||
table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback;
|
||||
table->glfwSetScrollCallback = glfwSetScrollCallback;
|
||||
table->glfwSetTime = glfwSetTime;
|
||||
table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio;
|
||||
table->glfwSetWindowAttrib = glfwSetWindowAttrib;
|
||||
table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback;
|
||||
table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback;
|
||||
table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback;
|
||||
table->glfwSetWindowIcon = glfwSetWindowIcon;
|
||||
table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback;
|
||||
table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback;
|
||||
table->glfwSetWindowMonitor = glfwSetWindowMonitor;
|
||||
table->glfwSetWindowOpacity = glfwSetWindowOpacity;
|
||||
table->glfwSetWindowPos = glfwSetWindowPos;
|
||||
table->glfwSetWindowPosCallback = glfwSetWindowPosCallback;
|
||||
table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback;
|
||||
table->glfwSetWindowShouldClose = glfwSetWindowShouldClose;
|
||||
table->glfwSetWindowSize = glfwSetWindowSize;
|
||||
table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback;
|
||||
table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits;
|
||||
table->glfwSetWindowTitle = glfwSetWindowTitle;
|
||||
table->glfwSetWindowUserPointer = glfwSetWindowUserPointer;
|
||||
table->glfwShowWindow = glfwShowWindow;
|
||||
table->glfwSwapBuffers = glfwSwapBuffers;
|
||||
table->glfwSwapInterval = glfwSwapInterval;
|
||||
table->glfwTerminate = glfwTerminate;
|
||||
table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings;
|
||||
table->glfwVulkanSupported = glfwVulkanSupported;
|
||||
table->glfwWaitEvents = glfwWaitEvents;
|
||||
table->glfwWaitEventsTimeout = glfwWaitEventsTimeout;
|
||||
table->glfwWindowHint = glfwWindowHint;
|
||||
table->glfwWindowHintString = glfwWindowHintString;
|
||||
table->glfwWindowShouldClose = glfwWindowShouldClose;
|
||||
table->glfwCreateCursor = glfwCreateCursor;
|
||||
table->glfwCreateStandardCursor = glfwCreateStandardCursor;
|
||||
table->glfwCreateWindow = glfwCreateWindow;
|
||||
table->glfwDefaultWindowHints = glfwDefaultWindowHints;
|
||||
table->glfwDestroyCursor = glfwDestroyCursor;
|
||||
table->glfwDestroyWindow = glfwDestroyWindow;
|
||||
table->glfwExtensionSupported = glfwExtensionSupported;
|
||||
table->glfwFocusWindow = glfwFocusWindow;
|
||||
table->glfwGetClipboardString = glfwGetClipboardString;
|
||||
table->glfwGetCurrentContext = glfwGetCurrentContext;
|
||||
table->glfwGetCursorPos = glfwGetCursorPos;
|
||||
table->glfwGetError = glfwGetError;
|
||||
table->glfwGetFrameBufferSize = glfwGetFramebufferSize;
|
||||
table->glfwGetGamepadName = glfwGetGamepadName;
|
||||
table->glfwGetGamepadState = glfwGetGamepadState;
|
||||
table->glfwGetGammaRamp = glfwGetGammaRamp;
|
||||
table->glfwGetInputMode = glfwGetInputMode;
|
||||
table->glfwGetJoystickAxes = glfwGetJoystickAxes;
|
||||
table->glfwGetJoystickButtons = glfwGetJoystickButtons;
|
||||
table->glfwGetJoystickGUID = glfwGetJoystickGUID;
|
||||
table->glfwGetJoystickHats = glfwGetJoystickHats;
|
||||
table->glfwGetJoystickName = glfwGetJoystickName;
|
||||
table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer;
|
||||
table->glfwGetKey = glfwGetKey;
|
||||
table->glfwGetKeyName = glfwGetKeyName;
|
||||
table->glfwGetKeyScancode = glfwGetKeyScancode;
|
||||
table->glfwGetMonitorContentScale = glfwGetMonitorContentScale;
|
||||
table->glfwGetMonitorName = glfwGetMonitorName;
|
||||
table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize;
|
||||
table->glfwGetMonitorPos = glfwGetMonitorPos;
|
||||
table->glfwGetMonitors = glfwGetMonitors;
|
||||
table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer;
|
||||
table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea;
|
||||
table->glfwGetMouseButton = glfwGetMouseButton;
|
||||
table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor;
|
||||
table->glfwGetProcAddress = glfwGetProcAddress;
|
||||
table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions;
|
||||
table->glfwGetTime = glfwGetTime;
|
||||
table->glfwGetTimerFrequency = glfwGetTimerFrequency;
|
||||
table->glfwGetTimerValue = glfwGetTimerValue;
|
||||
table->glfwGetVersion = glfwGetVersion;
|
||||
table->glfwGetVersionString = glfwGetVersionString;
|
||||
table->glfwGetVideoMode = glfwGetVideoMode;
|
||||
table->glfwGetVideoModes = glfwGetVideoModes;
|
||||
table->glfwGetWindowAttrib = glfwGetWindowAttrib;
|
||||
table->glfwGetWindowContentScale = glfwGetWindowContentScale;
|
||||
table->glfwGetWindowFrameSize = glfwGetWindowFrameSize;
|
||||
table->glfwGetWindowMonitor = glfwGetWindowMonitor;
|
||||
table->glfwGetWindowOpacity = glfwGetWindowOpacity;
|
||||
table->glfwGetWindowPos = glfwGetWindowPos;
|
||||
table->glfwGetWindowSize = glfwGetWindowSize;
|
||||
table->glfwGetWindowUserPointer = glfwGetWindowUserPointer;
|
||||
table->glfwHideWindow = glfwHideWindow;
|
||||
table->glfwIconifyWindow = glfwIconifyWindow;
|
||||
table->glfwInit = glfwInit;
|
||||
table->glfwInitHint = glfwInitHint;
|
||||
table->glfwJoystickIsGamePad = glfwJoystickIsGamepad;
|
||||
table->glfwJoystickPresent = glfwJoystickPresent;
|
||||
table->glfwMakeContextCurrent = glfwMakeContextCurrent;
|
||||
table->glfwMaximizeWindow = glfwMaximizeWindow;
|
||||
table->glfwPollEvents = glfwPollEvents;
|
||||
table->glfwPostEmptyEvent = glfwPostEmptyEvent;
|
||||
table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported;
|
||||
table->glfwRequestWindowAttention = glfwRequestWindowAttention;
|
||||
table->glfwRestoreWindow = glfwRestoreWindow;
|
||||
table->glfwSetCharCallback = glfwSetCharCallback;
|
||||
table->glfwSetCharModsCallback = glfwSetCharModsCallback;
|
||||
table->glfwSetClipboardString = glfwSetClipboardString;
|
||||
table->glfwSetCursor = glfwSetCursor;
|
||||
table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback;
|
||||
table->glfwSetCursorPos = glfwSetCursorPos;
|
||||
table->glfwSetCursorPosCallback = glfwSetCursorPosCallback;
|
||||
table->glfwSetDropCallback = glfwSetDropCallback;
|
||||
table->glfwSetErrorCallback = glfwSetErrorCallback;
|
||||
table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback;
|
||||
table->glfwSetGamma = glfwSetGamma;
|
||||
table->glfwSetGammaRamp = glfwSetGammaRamp;
|
||||
table->glfwSetInputMode = glfwSetInputMode;
|
||||
table->glfwSetJoystickCallback = glfwSetJoystickCallback;
|
||||
table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer;
|
||||
table->glfwSetKeyCallback = glfwSetKeyCallback;
|
||||
table->glfwSetMonitorCallback = glfwSetMonitorCallback;
|
||||
table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer;
|
||||
table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback;
|
||||
table->glfwSetScrollCallback = glfwSetScrollCallback;
|
||||
table->glfwSetTime = glfwSetTime;
|
||||
table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio;
|
||||
table->glfwSetWindowAttrib = glfwSetWindowAttrib;
|
||||
table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback;
|
||||
table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback;
|
||||
table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback;
|
||||
table->glfwSetWindowIcon = glfwSetWindowIcon;
|
||||
table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback;
|
||||
table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback;
|
||||
table->glfwSetWindowMonitor = glfwSetWindowMonitor;
|
||||
table->glfwSetWindowOpacity = glfwSetWindowOpacity;
|
||||
table->glfwSetWindowPos = glfwSetWindowPos;
|
||||
table->glfwSetWindowPosCallback = glfwSetWindowPosCallback;
|
||||
table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback;
|
||||
table->glfwSetWindowShouldClose = glfwSetWindowShouldClose;
|
||||
table->glfwSetWindowSize = glfwSetWindowSize;
|
||||
table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback;
|
||||
table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits;
|
||||
table->glfwSetWindowTitle = glfwSetWindowTitle;
|
||||
table->glfwSetWindowUserPointer = glfwSetWindowUserPointer;
|
||||
table->glfwShowWindow = glfwShowWindow;
|
||||
table->glfwSwapBuffers = glfwSwapBuffers;
|
||||
table->glfwSwapInterval = glfwSwapInterval;
|
||||
table->glfwTerminate = glfwTerminate;
|
||||
table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings;
|
||||
table->glfwVulkanSupported = glfwVulkanSupported;
|
||||
table->glfwWaitEvents = glfwWaitEvents;
|
||||
table->glfwWaitEventsTimeout = glfwWaitEventsTimeout;
|
||||
table->glfwWindowHint = glfwWindowHint;
|
||||
table->glfwWindowHintString = glfwWindowHintString;
|
||||
table->glfwWindowShouldClose = glfwWindowShouldClose;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ void load_intrinsic_sse(sn_intrinsic *context)
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
context->index_pair = index_pair_sse;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
context->f32_clear_panel = PNL_PROC(float, sse, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(sse, float);
|
||||
@@ -74,6 +75,13 @@ void load_intrinsic_sse(sn_intrinsic *context)
|
||||
context->f32_buffer_add = BUF_PROC(float, sse, add);
|
||||
context->f32_panel_fma = KER_PROC(float, sse, fma);
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
context->f32_store_panel = STORE_PANEL(sse, float);
|
||||
context->f32_clear_panel = PNL_PROC(float, sse, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(sse, float);
|
||||
context->f32_buffer_add = BUF_PROC(float, sse, add);
|
||||
context->f32_panel_fma = PNL_PROC(float, sse, fma);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
context->f32_buffer_fill = BUF_PROC(float, sse, fill);
|
||||
context->variant = BUF_PROC(float, sse, scalar_mul);
|
||||
context->f32_buffer_sub = BUF_PROC(float, sse, sub);
|
||||
@@ -87,6 +95,7 @@ void load_intrinsic_avx(sn_intrinsic *context)
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
context->index_pair = index_pair_sse;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
context->f32_clear_panel = PNL_PROC(float, avx, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(avx, float);
|
||||
@@ -96,6 +105,13 @@ void load_intrinsic_avx(sn_intrinsic *context)
|
||||
context->f32_buffer_add = BUF_PROC(float, avx, add);
|
||||
context->f32_panel_fma = KER_PROC(float, sse, fma);
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
context->f32_store_panel = STORE_PANEL(avx, float);
|
||||
context->f32_clear_panel = PNL_PROC(float, avx, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(avx, float);
|
||||
context->f32_buffer_add = BUF_PROC(float, avx, add);
|
||||
context->f32_panel_fma = PNL_PROC(float, avx, fma);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
context->f32_buffer_fill = BUF_PROC(float, avx, fill);
|
||||
context->variant = BUF_PROC(float, avx, scalar_mul);
|
||||
context->f32_buffer_sub = BUF_PROC(float, avx, sub);
|
||||
@@ -109,6 +125,7 @@ void load_intrinsic_512(sn_intrinsic *context)
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
context->index_pair = index_pair_sse;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
context->f32_clear_panel = PNL_PROC(float, sse, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(512, float);
|
||||
@@ -118,6 +135,13 @@ void load_intrinsic_512(sn_intrinsic *context)
|
||||
context->f32_buffer_add = BUF_PROC(float, 512, add);
|
||||
context->f32_panel_fma = KER_PROC(float, sse, fma);
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
context->f32_store_panel = STORE_PANEL(512, float);
|
||||
context->f32_clear_panel = PNL_PROC(float, 512, clear);
|
||||
context->f32_build_panel = BUILD_PANEL(512, float);
|
||||
context->f32_buffer_add = BUF_PROC(float, 512, add);
|
||||
context->f32_panel_fma = PNL_PROC(float, 512, fma);
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
context->f32_buffer_fill = BUF_PROC(float, 512, fill);
|
||||
context->variant = BUF_PROC(float, 512, scalar_mul);
|
||||
context->f32_buffer_sub = BUF_PROC(float, 512, sub);
|
||||
|
||||
@@ -15,7 +15,7 @@ INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
for (; ptr < end; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr++) {
|
||||
for (; ptr < end; ptr++) {
|
||||
hash = _mm_crc32_u16(hash, *ptr);
|
||||
}
|
||||
} else {
|
||||
@@ -30,10 +30,10 @@ INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
hash = _mm_crc32_u8(hash, hash64);
|
||||
hash = _mm_crc32_u8(hash, hash64 >> 32);
|
||||
for (; ptr < last_32; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash,*(uint32_t *)ptr);
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr += 2) {
|
||||
hash = _mm_crc32_u8(hash,*ptr);
|
||||
hash = _mm_crc32_u8(hash, *ptr);
|
||||
}
|
||||
}
|
||||
hash ^= hash >> 16;
|
||||
|
||||
@@ -15,7 +15,8 @@ INTERNAL void FORCEINLINE SN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans)
|
||||
INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 _double = _mm256_set_m128(vector[0], vector[0]);
|
||||
__m256 tmp = _mm256_dp_ps(transpose->ymm[0], _double, 0B11110001);
|
||||
@@ -25,7 +26,8 @@ INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 cons
|
||||
_mm256_permutevar8x32_ps(tmp, _mm256_loadu_epi32(avxdot_indices)));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans)
|
||||
INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
ans[0] = _mm_dp_ps(transpose->xmm[0], vector[0], 0B11110001);
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->xmm[1], vector[0], 0B11110001),
|
||||
@@ -44,24 +46,22 @@ INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 cons
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector, __m128 *ans)
|
||||
INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 temp = transpose->ymm[0];
|
||||
__m256 vector_stream = _mm256_set_m128(vector[1], vector[0]);
|
||||
|
||||
__m256 result = _mm256_dp_ps(temp, vector_stream, 0B11110001);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(
|
||||
result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010);
|
||||
|
||||
temp = transpose->ymm[1];
|
||||
result = _mm256_blend_ps(
|
||||
result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(
|
||||
result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000);
|
||||
|
||||
ans[0] = _mm256_castps256_ps128(result);
|
||||
ans[1] = _mm256_extractf128_ps(result, 1);
|
||||
ans[1] = _mm_shuffle_ps(ans[1], ans[1], _MM_SHUFFLE(2, 3, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
+19
-46
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Program"
|
||||
// Project: StgSharp
|
||||
@@ -53,71 +53,44 @@ namespace StgSharp
|
||||
|
||||
|
||||
// HlsfStressTest.Run();
|
||||
/*
|
||||
/**/
|
||||
HybridLayerSegregatedFitAllocator hlsf;
|
||||
unchecked {
|
||||
hlsf = new((nuint)(64 * (ulong)10000 * 10000));
|
||||
}
|
||||
Matrix<float> m = Matrix.FromHlsf<float>(1000, 1000, hlsf);
|
||||
Matrix<float> m = Matrix.FromHlsf<float>(400, 400, hlsf);
|
||||
MatrixCompute.Fill(m, 1.0f);
|
||||
Matrix<float> n = Matrix.FromHlsf<float>(400, 400, hlsf);
|
||||
MatrixCompute.Fill(n, 1.0f);
|
||||
Matrix<float> p = Matrix.FromHlsf<float>(400, 400, hlsf);
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Matrix<float> n = Matrix.FromHlsf<float>(1000, 1000, hlsf);
|
||||
MatrixCompute.Fill(n, 0.0f);
|
||||
for (int i = 0; i < 5; i++)
|
||||
// MatrixCompute.Fill(p, 0.0f);
|
||||
/*
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
MatrixCompute.Add(n, m, n);
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
MatrixCompute.Add(n, m, n);
|
||||
|
||||
// Console.WriteLine($"{i} {j}");
|
||||
for (int k = 0; k < 5; k++) {
|
||||
Console.Write($"{n[j, k]:0.0E+00} \t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine($"{i}");
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
MatrixCompute.Mul(n, 12, n);
|
||||
/**/
|
||||
MatrixCompute.Mul(n, m, p);
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
for (int j = 0; j < 20; j++) {
|
||||
Console.Write($"{n[i, j]:0.0E+00} \t");
|
||||
Console.Write($"{p[i, j]:0.0E+00} \t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
/**/
|
||||
|
||||
// --- Logarithmic time sequence test: print seconds at each emitted span ---
|
||||
|
||||
// Configure a simple sequence:
|
||||
// initial slice = 0.5s, total = 5s, growth multiplier = 2, min slice = 0.75s
|
||||
TimeSequence seq =
|
||||
/**/
|
||||
TimeSequence.CreateLogarithmic(initialSliceSeconds:0.5, totalSeconds:5.0,
|
||||
growthMultiplier:2.0, minSliceSeconds:0.75);
|
||||
/*
|
||||
TimeSequence.CreateLinear(5, 1);
|
||||
/**/
|
||||
|
||||
// Bind to default time source provider.
|
||||
TimeSpanProvider provider = new TimeSpanProvider(seq, TimeSpanProvider.DefaultProvider);
|
||||
|
||||
// Print the second mark when a span is emitted.
|
||||
provider.TimeSpanRefreshed += (s, e) => {
|
||||
// CurrentSecond is PreviousFrameTick / Frequency
|
||||
Console.WriteLine($"span @ {provider.CurrentSecond:0.000}s");
|
||||
};
|
||||
|
||||
// Start the time source and wait until sequence ends.
|
||||
TimeSpanProvider.DefaultProvider.StartProvidingTime();
|
||||
|
||||
while (!provider.IsEnded) {
|
||||
provider.WaitNextSpan();
|
||||
}
|
||||
|
||||
TimeSpanProvider.DefaultProvider.StopProvidingTime();
|
||||
|
||||
// end of log-time sequence test
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
public const uint GL_ACTIVE_SUBROUTINES = 0x8DE5
|
||||
public const uint GL_ACTIVE_SUBROUTINE_UNIFORMS = 0x8DE6
|
||||
public const uint GL_MAX_SUBROUTINES = 0x8DE7
|
||||
public const uint GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS = 0x8DE8
|
||||
public const uint GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS = 0x8E47
|
||||
public const uint GL_ACTIVE_SUBROUTINE_MAX_LENGTH = 0x8E48
|
||||
public const uint GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH = 0x8E49
|
||||
public const uint GL_NUM_COMPATIBLE_SUBROUTINES = 0x8E4A
|
||||
public const uint GL_COMPATIBLE_SUBROUTINES = 0x8E4B
|
||||
Reference in New Issue
Block a user