mat
This commit is contained in:
@@ -49,7 +49,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
|
||||
private IntrinsicContext* _context;
|
||||
private volatile bool _disposed, _isRetireRequested = false;
|
||||
private MatrixParallelTask* _currentTask;
|
||||
private volatile bool _disposed, _isRetireRequested ;
|
||||
private readonly ManualResetEventSlim _resetEvent;
|
||||
private readonly Thread _managedThread;
|
||||
|
||||
@@ -67,8 +68,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
public ThreadPriority AfterWork { get; set; }
|
||||
|
||||
internal ManualResetEventSlim? LeaderEvent { get; set; }
|
||||
|
||||
internal ref readonly IntrinsicContext Intrinsic => ref (*_context);
|
||||
|
||||
internal bool IsSingle { get; set; }
|
||||
@@ -91,6 +90,16 @@ namespace StgSharp.Mathematics.Numeric
|
||||
_resetEvent.Set();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void SetSingleThreadTask(
|
||||
ref MatrixParallelTask task
|
||||
)
|
||||
{
|
||||
if (IsSingle) {
|
||||
*_currentTask = task;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
@@ -117,6 +126,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
_ = Thread.Yield();
|
||||
SIMDID feature = new(GetSimdId());
|
||||
IntrinsicContext* contextPtr = stackalloc IntrinsicContext[1];
|
||||
MatrixParallelTask* taskPtr = stackalloc MatrixParallelTask[4];
|
||||
LoadIntrinsicFunction(contextPtr, feature.Mask);
|
||||
_context = contextPtr;
|
||||
State = MatrixThreadState.Ready;
|
||||
@@ -134,11 +144,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
_managedThread.Priority = ThreadPriority.Highest;
|
||||
if (IsSingle)
|
||||
{
|
||||
// TODO 将外部线程绑定到当前线程上,并执行任务包
|
||||
MatrixParallelTask* outer = _currentTask;
|
||||
IsSingle = false;
|
||||
} else
|
||||
{
|
||||
MatrixParallelQueue taskQueue = BindedWrap.TaskQueue;
|
||||
MatrixParallelTask* p = taskQueue.BaseTask;
|
||||
/*
|
||||
if (0 > (int)p ->ComputeHandle) {
|
||||
SpecialBufferCompute(p);
|
||||
@@ -162,19 +172,19 @@ 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)])]
|
||||
[UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static unsafe partial void LoadIntrinsicFunction(
|
||||
IntrinsicContext* context,
|
||||
|
||||
Reference in New Issue
Block a user