find solution to combinition of predictor and queue
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallelQueue"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -27,7 +27,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using StgSharp.Mathematics.Internal;
|
||||
using StgSharp.Mathematics.Numeric.Runtime;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -42,8 +42,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
internal unsafe class MatrixParallelQueue
|
||||
{
|
||||
|
||||
// TODO 为各种不同的计算策略设计专门的预测器,以适配L4
|
||||
|
||||
private static ConcurrentStack<MatrixParallelQueue> _recycle = [];
|
||||
private MatrixParallelTask* _package;
|
||||
private ulong _cursor;
|
||||
@@ -53,9 +51,14 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
public MatrixParallelTask* Package => _package;
|
||||
|
||||
public MatrixElementType ElementType { get; private set; }
|
||||
|
||||
public MatrixIntrinsicHandle Handle { get; private set; }
|
||||
|
||||
public static MatrixParallelQueue Rent(
|
||||
MatrixParallelTask* pack
|
||||
)
|
||||
MatrixElementType elementType,
|
||||
MatrixIntrinsicHandle handle,
|
||||
MatrixParallelTask* pack)
|
||||
{
|
||||
if (!_recycle.TryPop(out MatrixParallelQueue? queue)) {
|
||||
queue = new MatrixParallelQueue();
|
||||
@@ -63,23 +66,21 @@ namespace StgSharp.Mathematics.Numeric
|
||||
queue._package = pack;
|
||||
queue._maxCount = ((ulong)pack->CommonX) * ((ulong)pack->CommonY);
|
||||
queue._cursor = 0;
|
||||
queue.ElementType = elementType;
|
||||
queue.Handle = handle;
|
||||
return queue;
|
||||
}
|
||||
|
||||
public static void Return(
|
||||
MatrixParallelQueue queue
|
||||
)
|
||||
public static void Return(MatrixParallelQueue queue)
|
||||
{
|
||||
_recycle.Push(queue);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (ulong count, ulong offset) Steal(
|
||||
ulong request
|
||||
)
|
||||
public bool Steal(MatrixParallelTask* task)
|
||||
{
|
||||
ulong cursor = Interlocked.Add(ref _cursor, request) - request;
|
||||
return (Math.Min(request, Math.Max(0, _maxCount - cursor)), cursor);
|
||||
// TODO 使用提取的内容填充task
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user