HLSF use long as aloloc size
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="IBidirectionalDictionary"
|
// file="IBidirectionalDictionary"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -32,9 +32,7 @@ namespace StgSharp.Collections
|
|||||||
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
|
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
|
||||||
{
|
{
|
||||||
|
|
||||||
TFirst this[
|
TFirst this[TSecond key] { get; set; }
|
||||||
TSecond key
|
|
||||||
] { get; set; }
|
|
||||||
|
|
||||||
ICollection<TFirst> FirstIndex { get; }
|
ICollection<TFirst> FirstIndex { get; }
|
||||||
|
|
||||||
@@ -55,9 +53,7 @@ namespace StgSharp.Collections
|
|||||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||||
/// the specified key; otherwise, false.
|
/// the specified key; otherwise, false.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
bool Contains(
|
bool Contains(TSecond key);
|
||||||
TSecond key
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||||
@@ -70,23 +66,16 @@ namespace StgSharp.Collections
|
|||||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||||
/// the specified key; otherwise, false.
|
/// the specified key; otherwise, false.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
bool Contains(
|
bool Contains(TFirst key);
|
||||||
TFirst key
|
|
||||||
);
|
|
||||||
|
|
||||||
bool TryGetValue(
|
bool TryGetValue(TSecond key, out TFirst value);
|
||||||
TSecond key,
|
|
||||||
out TFirst value
|
|
||||||
);
|
|
||||||
|
|
||||||
#pragma warning disable CA1033
|
#pragma warning disable CA1033
|
||||||
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
|
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
|
||||||
|
|
||||||
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
|
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
|
||||||
|
|
||||||
bool IDictionary<TFirst, TSecond>.ContainsKey(
|
bool IDictionary<TFirst, TSecond>.ContainsKey(TFirst key)
|
||||||
TFirst key
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return Contains(key);
|
return Contains(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="HLSFAllocationHandle"
|
// file="HLSFAllocationHandle"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -40,9 +40,9 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
{
|
{
|
||||||
|
|
||||||
internal readonly Allocator.Entry* EntryHandle;
|
internal readonly Allocator.Entry* EntryHandle;
|
||||||
public readonly uint AllocSize;
|
public readonly long AllocSize;
|
||||||
|
|
||||||
internal HybridLayerSegregatedFitAllocationHandle(Allocator.Entry* handle, uint s)
|
internal HybridLayerSegregatedFitAllocationHandle(Allocator.Entry* handle, long s)
|
||||||
{
|
{
|
||||||
EntryHandle = handle;
|
EntryHandle = handle;
|
||||||
Pointer = (byte*)handle->Position;
|
Pointer = (byte*)handle->Position;
|
||||||
@@ -56,7 +56,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>(index, AllocSize);
|
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, AllocSize);
|
||||||
return ref Pointer[index];
|
return ref Pointer[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="HLSFAllocator.Alloc"
|
// file="HLSFAllocator.Alloc"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,10 +26,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics.Tracing;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using hlsfHandle = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
using hlsfHandle = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||||
|
|
||||||
namespace StgSharp.HighPerformance.Memory
|
namespace StgSharp.HighPerformance.Memory
|
||||||
@@ -37,9 +34,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
public unsafe partial class HybridLayerSegregatedFitAllocator
|
public unsafe partial class HybridLayerSegregatedFitAllocator
|
||||||
{
|
{
|
||||||
|
|
||||||
public hlsfHandle Alloc(
|
public hlsfHandle Alloc(long size)
|
||||||
uint size
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (size > _maxSize) {
|
if (size > _maxSize) {
|
||||||
throw new InvalidOperationException("Requested size exceeds maximum allocatable size.");
|
throw new InvalidOperationException("Requested size exceeds maximum allocatable size.");
|
||||||
@@ -96,10 +91,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
/// <param name="sizeToSlice">
|
/// <param name="sizeToSlice">
|
||||||
///
|
///
|
||||||
/// </param>
|
/// </param>
|
||||||
private void SliceMemory(
|
private void SliceMemory(Entry* e, long sizeToSlice)
|
||||||
Entry* e,
|
|
||||||
long sizeToSlice
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
Entry* next = e;
|
Entry* next = e;
|
||||||
long remain = sizeToSlice; // remained size to slice
|
long remain = sizeToSlice; // remained size to slice
|
||||||
@@ -197,9 +189,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// True if allocation succeeded
|
/// True if allocation succeeded
|
||||||
/// </returns>
|
/// </returns>
|
||||||
private bool TryAllocateNew32MBBlock(
|
private bool TryAllocateNew32MBBlock(out Entry* handle)
|
||||||
out Entry* handle
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
nuint pos = _spareMemory->Position;
|
nuint pos = _spareMemory->Position;
|
||||||
long remain = _spareMemory->Size;
|
long remain = _spareMemory->Size;
|
||||||
@@ -229,11 +219,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper method for allocation - converts BucketNode to Entry
|
/// Helper method for allocation - converts BucketNode to Entry
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool TryPopLevelForAllocation(
|
private bool TryPopLevelForAllocation(int levelIndex, int sizeIndex, out Entry* entry)
|
||||||
int levelIndex,
|
|
||||||
int sizeIndex,
|
|
||||||
out Entry* entry
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (TryPopLevel(levelIndex, sizeIndex, out BucketNode* bucketNode))
|
if (TryPopLevel(levelIndex, sizeIndex, out BucketNode* bucketNode))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="HLSFAllocator.Level"
|
// file="HLSFAllocator.Level"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -40,42 +40,19 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
|
|
||||||
private const int MaxLevel = 9;
|
private const int MaxLevel = 9;
|
||||||
|
|
||||||
private int[] _levelSizeArray = [
|
private int[] _levelSizeArray = [ 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216 ];
|
||||||
64,
|
|
||||||
256,
|
|
||||||
1024,
|
|
||||||
4096,
|
|
||||||
16384,
|
|
||||||
65536,
|
|
||||||
262144,
|
|
||||||
1048576,
|
|
||||||
4194304,
|
|
||||||
16777216
|
|
||||||
];
|
|
||||||
|
|
||||||
public int AlignOfLevel(
|
public int AlignOfLevel(int bucketLevel)
|
||||||
int bucketLevel
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int blockSize = _levelSizeArray[bucketLevel];
|
int blockSize = _levelSizeArray[bucketLevel];
|
||||||
return int.Min(blockSize, _align);
|
return int.Min(blockSize, _align);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int GetLevelFromSize(
|
private static int GetLevelFromSize(long size)
|
||||||
long size
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GetLevelFromSize((uint)size);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
private static int GetLevelFromSize(
|
|
||||||
uint size
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Level sizes: [64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216]
|
* Level sizes: [64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, ......]
|
||||||
* Pattern: 64 * 4^level = 2^6 * 2^(2*level) = 2^(6+2*level)
|
* Pattern: 64 * 4^level = 2^6 * 2^(2*level) = 2^(6+2*level)
|
||||||
*
|
*
|
||||||
* For size S, we need: 2^(6+2*level) >= S
|
* For size S, we need: 2^(6+2*level) >= S
|
||||||
@@ -83,9 +60,9 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
* Therefore: level >= (log2(S) - 6) / 2
|
* Therefore: level >= (log2(S) - 6) / 2
|
||||||
*
|
*
|
||||||
* We use hardware LZCNT instruction via BitOperations.LeadingZeroCount
|
* We use hardware LZCNT instruction via BitOperations.LeadingZeroCount
|
||||||
* log2(S) = 31 - LeadingZeroCount(S) for 32-bit values
|
* log2(S) = 63 - LeadingZeroCount(S) for 64-bit values
|
||||||
*/
|
*/
|
||||||
int log2Size = 31 - BitOperations.LeadingZeroCount(size);
|
int log2Size = 63 - BitOperations.LeadingZeroCount((ulong)size);
|
||||||
|
|
||||||
// Calculate level: level = max(0, (log2Size - 6) / 2)
|
// Calculate level: level = max(0, (log2Size - 6) / 2)
|
||||||
int level = Math.Max(0, (log2Size - 6) / 2);
|
int level = Math.Max(0, (log2Size - 6) / 2);
|
||||||
@@ -94,6 +71,12 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private static int GetLevelFromSize(uint size)
|
||||||
|
{
|
||||||
|
return GetLevelFromSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CommonMemoryAlign : int
|
public enum CommonMemoryAlign : int
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="HLSFAllocator"
|
// file="HLSFAllocator"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -41,16 +41,14 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
|
|
||||||
// _spareMemory is also the beginning position of allocator
|
// _spareMemory is also the beginning position of allocator
|
||||||
private Entry *_spareMemory;
|
private Entry *_spareMemory;
|
||||||
private readonly byte *m_Buffer;
|
private readonly byte* m_Buffer;
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
private readonly int _align;
|
private readonly int _align;
|
||||||
|
private readonly long _maxSize;
|
||||||
private readonly nuint _size;
|
private readonly nuint _size;
|
||||||
private readonly SlabAllocator<Entry> _entries;
|
private readonly SlabAllocator<Entry> _entries;
|
||||||
private readonly uint _maxSize;
|
|
||||||
|
|
||||||
public HybridLayerSegregatedFitAllocator(
|
public HybridLayerSegregatedFitAllocator(nuint byteSize)
|
||||||
nuint byteSize
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (byteSize < 64) {
|
if (byteSize < 64) {
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
@@ -72,13 +70,10 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
_maxSize = 32U * 1024U * 1024U;
|
_maxSize = 32U * 1024U * 1024U;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HybridLayerSegregatedFitAllocator(
|
public HybridLayerSegregatedFitAllocator(nuint byteSize, uint maxBlockSize)
|
||||||
nuint byteSize,
|
|
||||||
uint maxBlockSize
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
_entries = SlabAllocator<Entry>.Create(64, SlabBufferLayout.Chunked, false);
|
_entries = SlabAllocator<Entry>.Create(64, SlabBufferLayout.Chunked, false);
|
||||||
m_Buffer = (byte *)NativeMemory.AlignedAlloc(byteSize, (nuint)16);
|
m_Buffer = (byte *)NativeMemory.AlignedAlloc(byteSize, 16);
|
||||||
_align = 16;
|
_align = 16;
|
||||||
_size = byteSize;
|
_size = byteSize;
|
||||||
|
|
||||||
@@ -92,7 +87,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
int levelCountOrigin = _levelSizeArray.Length;
|
int levelCountOrigin = _levelSizeArray.Length;
|
||||||
int levelCount = GetLevelFromSize(maxBlockSize) + 1;
|
int levelCount = GetLevelFromSize(maxBlockSize) + 1;
|
||||||
Array.Resize(ref _levelSizeArray, levelCount);
|
Array.Resize(ref _levelSizeArray, levelCount);
|
||||||
_bucketHeads = new BucketNode *[levelCount * 3 + 1];
|
_bucketHeads = new BucketNode *[(levelCount * 3) + 1];
|
||||||
int size = _levelSizeArray[^1];
|
int size = _levelSizeArray[^1];
|
||||||
for (int i = levelCountOrigin; i < levelCount; i++)
|
for (int i = levelCountOrigin; i < levelCount; i++)
|
||||||
{
|
{
|
||||||
@@ -102,10 +97,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
_maxSize = maxBlockSize;
|
_maxSize = maxBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HybridLayerSegregatedFitAllocator(
|
public HybridLayerSegregatedFitAllocator(nuint byteSize, int align)
|
||||||
nuint byteSize,
|
|
||||||
int align
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (align < 16 || (align & (align - 1)) != 0) {
|
if (align < 16 || (align & (align - 1)) != 0) {
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
@@ -128,18 +120,14 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
_maxSize = 32U * 1024U * 1024U;
|
_maxSize = 32U * 1024U * 1024U;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HybridLayerSegregatedFitAllocator(
|
public HybridLayerSegregatedFitAllocator(nuint byteSize, int align, long maxBlockSize)
|
||||||
nuint byteSize,
|
|
||||||
int align,
|
|
||||||
uint maxBlockSize
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (align < 16 || (align & (align - 1)) != 0) {
|
if (align < 16 || (align & (align - 1)) != 0) {
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
"Alignment must be a power of two and at least 16 bytes.");
|
"Alignment must be a power of two and at least 16 bytes.");
|
||||||
}
|
}
|
||||||
_entries = SlabAllocator<Entry>.Create(64, SlabBufferLayout.Chunked, false);
|
_entries = SlabAllocator<Entry>.Create(64, SlabBufferLayout.Chunked, false);
|
||||||
m_Buffer = (byte *)NativeMemory.AlignedAlloc(byteSize, (nuint)align);
|
m_Buffer = (byte*)NativeMemory.AlignedAlloc(byteSize, (nuint)align);
|
||||||
_align = align;
|
_align = align;
|
||||||
_size = byteSize;
|
_size = byteSize;
|
||||||
|
|
||||||
@@ -169,9 +157,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(
|
protected virtual void Dispose(bool disposing)
|
||||||
bool disposing
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (!disposedValue)
|
if (!disposedValue)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix.Create"
|
// file="Matrix.Create"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -72,15 +72,12 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
};
|
};
|
||||||
|
|
||||||
long requiredBytes = kernelCount * MatrixKernel<T>.Size;
|
long requiredBytes = kernelCount * MatrixKernel<T>.Size;
|
||||||
if (requiredBytes <= 0 || requiredBytes > uint.MaxValue) {
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(requiredBytes, nameof(requiredBytes));
|
||||||
throw new ArgumentOutOfRangeException(nameof(requiredBytes), "Requested matrix exceeds allocator capacity.");
|
|
||||||
}
|
|
||||||
|
|
||||||
HybridLayerSegregatedFitAllocationHandle handle = allocator.Alloc((uint)requiredBytes);
|
HybridLayerSegregatedFitAllocationHandle handle = allocator.Alloc((uint)requiredBytes);
|
||||||
MatrixStorageHLSF<T> storage = new MatrixStorageHLSF<T>(allocator, handle);
|
MatrixStorageHLSF<T> storage = new MatrixStorageHLSF<T>(allocator, handle);
|
||||||
|
|
||||||
Matrix<T> matrix = new Matrix<T>(MatrixKernelBoarder.Create(layout), new MatrixSize(columnLength,
|
Matrix<T> matrix = new Matrix<T>(MatrixKernelBoarder.Create(layout), new MatrixSize(columnLength, rowLength,
|
||||||
rowLength,
|
|
||||||
kernelColumns,
|
kernelColumns,
|
||||||
kernelRows), storage);
|
kernelRows), storage);
|
||||||
|
|
||||||
|
|||||||
+12
-13
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixTest"
|
// file="MatrixTest"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -42,7 +42,9 @@ namespace StgSharp
|
|||||||
internal static partial class Program
|
internal static partial class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
private static int sideLength = 20;
|
private const long size = 1024L * 1024L * 1024L * 4L;
|
||||||
|
|
||||||
|
private static int sideLength = 1000;
|
||||||
|
|
||||||
internal static unsafe void TestMatrix(
|
internal static unsafe void TestMatrix(
|
||||||
)
|
)
|
||||||
@@ -51,16 +53,13 @@ namespace StgSharp
|
|||||||
/**/
|
/**/
|
||||||
HybridLayerSegregatedFitAllocator hlsf;
|
HybridLayerSegregatedFitAllocator hlsf;
|
||||||
unchecked {
|
unchecked {
|
||||||
hlsf = new((nuint)(4 * (ulong)1024 * 1024 * 1024), 32, 1024U * 1024U * 256U);
|
hlsf = new((nuint)size, 32, size);
|
||||||
}
|
}
|
||||||
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
||||||
hlsf);
|
|
||||||
MatrixCompute.Fill(m, 1.0f);
|
MatrixCompute.Fill(m, 1.0f);
|
||||||
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
||||||
hlsf);
|
|
||||||
MatrixCompute.Fill(n, 1.0f);
|
MatrixCompute.Fill(n, 1.0f);
|
||||||
Matrix<T> p = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
Matrix<T> p = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
||||||
hlsf);
|
|
||||||
MatrixCompute.Fill(p, 0.0f);
|
MatrixCompute.Fill(p, 0.0f);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -88,9 +87,9 @@ namespace StgSharp
|
|||||||
|
|
||||||
// value = T.Abs(value) < 1e-6 ? 0 : value;
|
// value = T.Abs(value) < 1e-6 ? 0 : value;
|
||||||
|
|
||||||
Console.Write($"{p.GetElementOffset(j,i)}{extra}");
|
// Console.Write($"{p.GetElementOffset(j,i)}{extra}");
|
||||||
|
|
||||||
// Console.Write($"{value:000}{extra}");
|
Console.Write($"{value:000}{extra}");
|
||||||
}
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-14
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Program"
|
// file="Program"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -39,25 +39,20 @@ namespace StgSharp
|
|||||||
|
|
||||||
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||||
|
|
||||||
internal static unsafe void Main(
|
internal static unsafe void Main(string[] args)
|
||||||
string[] args
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
World.Initialize()
|
World.Initialize().UseModule<NumericalModule>().UseModule<GraphicModule>().InitializeModule();
|
||||||
.UseModule<NumericalModule>()
|
|
||||||
.UseModule<GraphicModule>()
|
|
||||||
.InitializeModule();
|
|
||||||
|
|
||||||
TestRegexAnalyse.Run();
|
// TestRegexAnalyse.Run();
|
||||||
|
|
||||||
// HlsfStressTest.Run();
|
// HlsfStressTest.Run();
|
||||||
|
|
||||||
// TestMatrix();
|
TestMatrix();
|
||||||
|
|
||||||
|
|
||||||
// --- Logarithmic time sequence test: print seconds at each emitted span ---
|
/*
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -67,7 +62,8 @@ namespace StgSharp
|
|||||||
World.WriteLog($"{ex}", LogType.Error);
|
World.WriteLog($"{ex}", LogType.Error);
|
||||||
Dialogue.PostError(ex);
|
Dialogue.PostError(ex);
|
||||||
/**/
|
/**/
|
||||||
World.Terminate(-1);
|
|
||||||
|
// World.Terminate(-1);
|
||||||
/**/
|
/**/
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="TestRegexAnalyse"
|
// file="TestRegexAnalyse"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -39,10 +39,10 @@ namespace StgSharp
|
|||||||
{
|
{
|
||||||
|
|
||||||
private static string[] regexSource = [
|
private static string[] regexSource = [
|
||||||
@"http|https",
|
@"http|https|ftp|ftps",
|
||||||
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
|
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
|
||||||
@"get_name|get_value|get_type|set_name|set_value|set_type"
|
@"get_name|get_value|get_type|set_name|set_value|set_type",
|
||||||
];
|
@"helix|hello|help|hero|hers|her" ];
|
||||||
|
|
||||||
public static void Run()
|
public static void Run()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user