Daily update on 20250921-173333 by Nitload Youmu. Additional Message : New design of matrix enumeration, capable for parallel task publication.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -32,6 +32,8 @@ using StgSharp.HighPerformance;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
||||
|
||||
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||
@@ -135,55 +137,77 @@ namespace StgSharp.Mathematics
|
||||
|
||||
public readonly unsafe ref struct MatrixSegmentEnumeration<T>(
|
||||
MatrixKernel<T>* source,
|
||||
int stride,
|
||||
int size,
|
||||
int primStride,
|
||||
int primSize,
|
||||
int secondaryStride,
|
||||
int secondarySize)
|
||||
int secondarySize,
|
||||
int primOffset = 0,
|
||||
int secondaryOffset = 0)
|
||||
where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* _source = source;
|
||||
private readonly int _secondarySize = secondarySize;
|
||||
private readonly int _secondaryStride = secondaryStride;
|
||||
internal readonly int SecondaryStride = secondaryStride;
|
||||
internal readonly int PrimOffset = primOffset;
|
||||
|
||||
private readonly int _size = size;
|
||||
private readonly int _stride = stride;
|
||||
internal readonly int PrimSize = primSize;
|
||||
internal readonly int PrimStride = primStride;
|
||||
internal readonly int SecondaryOffset = secondaryOffset;
|
||||
internal readonly int SecondarySize = secondarySize;
|
||||
|
||||
public Enumerator<T> GetEnumerator()
|
||||
internal readonly MatrixKernel<T>* Source
|
||||
{
|
||||
return new Enumerator<T>(in this);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source;
|
||||
}
|
||||
|
||||
public ref struct Enumerator<T>(in MatrixSegmentEnumeration<T> enumeration) where T: unmanaged, INumber<T>
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(in this);
|
||||
}
|
||||
|
||||
public ref struct Enumerator(in MatrixSegmentEnumeration<T> enumeration)
|
||||
{
|
||||
|
||||
private MatrixKernel<T>* _current = enumeration._source - enumeration._stride;
|
||||
private readonly MatrixKernel<T>* _end = enumeration._source + enumeration._size;
|
||||
private readonly int _secondarySize = enumeration._secondarySize;
|
||||
private readonly int _secondaryStride = enumeration._secondaryStride;
|
||||
private readonly int _stride = enumeration._stride;
|
||||
private readonly MatrixKernel<T>* _source = enumeration._source;
|
||||
private int _indexCount = 0;
|
||||
private readonly int _stride = enumeration.PrimStride;
|
||||
private readonly long _bound = (long)enumeration.PrimSize * enumeration.PrimStride;
|
||||
private long _index = (long)enumeration.PrimOffset * enumeration.PrimStride;
|
||||
|
||||
private readonly MatrixSegmentEnumeration<T> _enumeration;
|
||||
|
||||
public readonly MatrixSegment<T> Current
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new(_current, _secondarySize, _secondaryStride);
|
||||
get => new(
|
||||
_source + _index,
|
||||
_enumeration.SecondarySize,
|
||||
_enumeration.SecondaryStride,
|
||||
_enumeration.PrimOffset);
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
_current += _stride;
|
||||
return _current < _end;
|
||||
_indexCount++;
|
||||
_index += _stride;
|
||||
if (_index >= _bound) {
|
||||
_index = 0;
|
||||
}
|
||||
return _indexCount >= _enumeration.PrimSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public readonly unsafe ref struct MatrixSegment<T>(MatrixKernel<T>* source, int size, int stride)
|
||||
public readonly unsafe ref struct MatrixSegment<T>(MatrixKernel<T>* source, int size, int stride, int offset)
|
||||
where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* _source = source;
|
||||
private readonly int _offset = offset;
|
||||
private readonly int _secondarySize = size;
|
||||
private readonly int _size = size;
|
||||
private readonly int _stride = stride;
|
||||
|
||||
@@ -198,29 +222,37 @@ namespace StgSharp.Mathematics
|
||||
}
|
||||
}
|
||||
|
||||
public Enumerator<T> GetEnumerator()
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator<T>(_source, _size, _stride);
|
||||
return new Enumerator(in this);
|
||||
}
|
||||
|
||||
public ref struct Enumerator<T>(MatrixKernel<T>* source, int count, int stride) where T: unmanaged, INumber<T>
|
||||
public ref struct Enumerator(in MatrixSegment<T> segment)
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* _end = source + (count * stride);
|
||||
private readonly int _stride = stride;
|
||||
private readonly int _end = segment._size;
|
||||
|
||||
public MatrixKernel<T>* Current
|
||||
private int _indexCount = 0;
|
||||
private readonly long _bound = (long)segment._size * segment._stride;
|
||||
private long _index = (long)segment._offset * segment._stride;
|
||||
private readonly MatrixSegment<T> _segment = segment;
|
||||
|
||||
public readonly MatrixKernel<T>* Current
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private set;
|
||||
} = source - stride;
|
||||
get => _segment._source + _index;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
Current += _stride;
|
||||
return Current < _end;
|
||||
_index += _segment._stride;
|
||||
_indexCount++;
|
||||
if (_index >= _bound) {
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
return _indexCount < _end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user