daily
This commit is contained in:
@@ -25,15 +25,9 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* _source = enumeration._source;
|
||||
private int _indexCount = 0;
|
||||
private int _indexCount = -1;
|
||||
private readonly int _stride = enumeration.PrimStride;
|
||||
private readonly long _bound = (long)enumeration.PrimSize * enumeration.PrimStride;
|
||||
private long _index = (long)enumeration.PrimOffset * enumeration.PrimStride;
|
||||
@@ -230,7 +230,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
private readonly int _end = segment._size;
|
||||
|
||||
private int _indexCount = 0;
|
||||
private int _indexCount = -1;
|
||||
private readonly long _bound = (long)segment._size * segment._stride;
|
||||
private long _index = (long)segment._offset * segment._stride;
|
||||
private readonly MatrixSegment<T> _segment = segment;
|
||||
|
||||
@@ -45,24 +45,61 @@ namespace StgSharp.Mathematics.Numeric
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
Matrix<float> ans = Matrix<float>.FromDefault(left.ColumnLength, left.RowLength);
|
||||
if (left.KernelColumnLength * left.KernelRowLength <= 1024)
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 1024)
|
||||
{
|
||||
MatrixParallelPool pool = MatrixParallel.LeadParallel();
|
||||
if (!pool.TryRentIndividualHandle(out MatrixParallelWrap.Handle? handle)) { }
|
||||
MatrixSegmentEnumeration<float>.Enumerator leftEnum = left.GetColumnEnumeration().GetEnumerator();
|
||||
MatrixSegmentEnumeration<float>.Enumerator rightEnum = right.GetColumnEnumeration().GetEnumerator();
|
||||
MatrixSegmentEnumeration<float>.Enumerator ansEnum = ans.GetColumnEnumeration().GetEnumerator();
|
||||
|
||||
for (int i = 0; i < left.KernelColumnLength; i++)
|
||||
if (!pool.TryRentIndividualHandle(out MatrixParallelWrap.Handle? handle))
|
||||
{
|
||||
MatrixSegment<float>.Enumerator leftColumEnum = leftEnum.Current.GetEnumerator();
|
||||
MatrixSegment<float>.Enumerator rightColumEnum = rightEnum.Current.GetEnumerator();
|
||||
MatrixSegment<float>.Enumerator ansColumEnum = ansEnum.Current.GetEnumerator();
|
||||
/*
|
||||
* wait
|
||||
*/
|
||||
}
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
for (int i = 0; i < count; i++) {
|
||||
NativeIntrinsic.Intrinsic.f32_add(leftPtr + i, rightPtr + i, ansPtr + i);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
Stack<MatrixParallelWrap> taskGroup = MatrixParallel.PublicTask(left.GetColumnEnumeration(), right.GetColumnEnumeration(), ans.GetColumnEnumeration(),
|
||||
(delegate*<MatrixKernel<float>*, MatrixKernel<float>*, MatrixKernel<float>*, void>)NativeIntrinsic.Intrinsic.f32_add);
|
||||
/*
|
||||
* run parallel
|
||||
*/
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static unsafe Matrix<float> Sub(Matrix<float> left, Matrix<float> right)
|
||||
{
|
||||
if (left.ColumnLength != right.ColumnLength || left.RowLength != right.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
Matrix<float> ans = Matrix<float>.FromDefault(left.ColumnLength, left.RowLength);
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
if (count <= 1024)
|
||||
{
|
||||
MatrixParallelPool pool = MatrixParallel.LeadParallel();
|
||||
if (!pool.TryRentIndividualHandle(out MatrixParallelWrap.Handle? handle))
|
||||
{
|
||||
/*
|
||||
* wait
|
||||
*/
|
||||
}
|
||||
MatrixKernel<float>* leftPtr = left.Buffer;
|
||||
MatrixKernel<float>* rightPtr = right.Buffer;
|
||||
MatrixKernel<float>* ansPtr = ans.Buffer;
|
||||
for (int i = 0; i < count; i++) {
|
||||
NativeIntrinsic.Intrinsic.f32_sub(leftPtr + i, rightPtr + i, ansPtr + i);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
Stack<MatrixParallelWrap> taskGroup = MatrixParallel.PublicTask(left.GetColumnEnumeration(), right.GetColumnEnumeration(), ans.GetColumnEnumeration(),
|
||||
(delegate*<MatrixKernel<float>*, MatrixKernel<float>*, MatrixKernel<float>*, void>)NativeIntrinsic.Intrinsic.f32_sub);
|
||||
/*
|
||||
* run parallel
|
||||
*/
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user