back to matrix, simplified thread init
This commit is contained in:
@@ -48,7 +48,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public unsafe partial class MatrixParallelThread : IDisposable
|
||||
{
|
||||
|
||||
private IntPtr* _context;
|
||||
private IntrinsicContext* _context;
|
||||
private volatile bool _disposed, _isRetireRequested = false;
|
||||
private readonly ManualResetEventSlim _resetEvent;
|
||||
private readonly Thread _managedThread;
|
||||
@@ -69,15 +69,15 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
internal ManualResetEventSlim? LeaderEvent { get; set; }
|
||||
|
||||
internal bool IsSingle { get; set; }
|
||||
internal ref readonly IntrinsicContext Intrinsic => ref (*_context);
|
||||
|
||||
internal IntrinsicContext Intrinsic { get; private set; }
|
||||
internal bool IsSingle { get; set; }
|
||||
|
||||
internal MatrixParallelWrap BindedWrap { get; set; }
|
||||
|
||||
internal MatrixThreadState State { get; set; }
|
||||
internal MatrixThreadState State { get; private set; }
|
||||
|
||||
internal SIMDID Simd { get; set; }
|
||||
internal SIMDID Simd { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -116,9 +116,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
SetThreadAffinity(PoolId);
|
||||
_ = Thread.Yield();
|
||||
SIMDID feature = new(GetSimdId());
|
||||
int index = MatrixParallel.GetContext(feature);
|
||||
Intrinsic = new IntrinsicContext();
|
||||
if (index > 0) { }
|
||||
IntrinsicContext* contextPtr = stackalloc IntrinsicContext[1];
|
||||
LoadIntrinsicFunction(contextPtr, feature.Mask);
|
||||
_context = contextPtr;
|
||||
State = MatrixThreadState.Ready;
|
||||
while (true)
|
||||
{
|
||||
@@ -162,17 +162,24 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
#pragma warning disable CA5393
|
||||
[LibraryImport(Native.LibName, EntryPoint = "sn_get_simd_level_local")]
|
||||
[UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
internal static partial ulong GetSimdId();
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "sn_set_thread_affinity")]
|
||||
[UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
internal static partial void SetThreadAffinity(
|
||||
int coreId
|
||||
);
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static unsafe partial void LoadIntrinsicFunction(
|
||||
IntrinsicContext* context,
|
||||
ulong id
|
||||
);
|
||||
#pragma warning restore CA5393
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user