Commit Graph

192 Commits

Author SHA1 Message Date
c9aa3819a0 Merge branch 'main' of https://git.personalnas.com/Misaki/Misaki.HighPerformance 2026-05-05 16:20:26 +09:00
aed4df9ebf Improve FreeList alignment, error handling, and GGX SPMD
- Increased BlockHeader size, added blockStart, and improved alignment logic in FreeList allocator.
- Changed _MIN_BLOCK_SIZE to 32 and consolidated to a single implementation.
- Updated allocation and free logic for correct pointer alignment and header management.
- MemoryUtility now throws OutOfMemoryException on allocation failure.
- Optimized GGXMipGenerationBenchmark SPMD output with MaskScatter and minor math/cleanup improvements.
- Cleaned up Program.cs and enabled global/test initialization.
- Bumped assembly version to 1.6.19.
2026-05-05 16:19:52 +09:00
53bdf79eee Update README.md 2026-05-04 06:49:26 +00:00
155d7b0fbd SPMD API overhaul: gather/scatter, job & packaging updates
- ISPMDLane: add MaskGather, MaskStore, Scatter, MaskScatter; update MaskLoad/Gather signatures for hardware parity
- WideLane/ScalarLane: implement new methods with HW/fallback logic
- MathV: gather/mask-gather now delegate to lane methods
- Vector2/3/4: add CompressStore, Scatter, MaskScatter
- SPMD jobs/tests/README: migrate to new APIs for correctness
- Use Unsafe.BitCast instead of Unsafe.As/AsRef
- Add SPMDUtility for gather index extraction
- Job system: add ICustomJob<TSelf>, ScheduleCustom overload
- FreeList concurrency obsolete; always thread-safe
- NuGet: include LICENSE/README, set license/readme in .csproj
- Docs: update SPMD usage, clarify safety notes
- Minor: doc fixes, CompressStore test improvements
2026-05-04 13:56:49 +09:00
99fcbec753 Refactor SPMD jobs for true vectorized/masked execution
- Change IJobSPMD.Execute to (indices, mask, ctx) signature for all arities, enabling proper vectorized/masked SPMD execution.
- Update all SPMD job wrappers, extension methods, and test jobs to use new interface.
- Add AVX2 gather/masked gather support to MathV.GatherVector2/3/4 and related methods; use [ConstantExpected] byte scale.
- Improve gather/select logic, pointer arithmetic, and overloads for ref/int* index access.
- Refactor GGXMipGenerationBenchmark and jobs for SPMD, with per-mip-level vectorized jobs and improved memory access.
- Clean up code, fix naming, update comments, and bump version to 1.3.6.
2026-05-03 23:32:04 +09:00
4ffb41e210 add LICENSE 2026-05-03 17:11:08 +09:00
9e9339de3c fixed the issue that job can't schedule correctly when have a invalid dependency. 2026-05-03 16:25:47 +09:00
fe8362e029 Add custom job scheduling and dependency combiners
- Introduce `CombinedDependenciesJob` for efficient dependency handling and memory management
- Add `ScheduleCustom<T>` for user-defined job execution/free logic
- Refactor `JobInfo` and `JobDataPool<T>` for safer resource management and custom function support
- Improve SPMD extension type constraint formatting
- Update SPMD project content path and increment assembly versions
- Add unit tests for combined dependencies and custom jobs
- Remove `[Timeout]` from tests to prevent spurious failures
- Add TODO for future `WideLane` optimizations
- Replace legacy .sln with .slnx for better solution structure
2026-05-03 15:17:19 +09:00
997aab299c fixed the problem that job may leak when it's a long running job. 2026-05-02 22:18:19 +09:00
f8edb8ce4c add safety check tp preferLocal 2026-05-02 22:00:56 +09:00
54d0941e62 fixe the locking issue in job scheduler 2026-05-02 21:58:12 +09:00
7bf63c0521 fixed multiple dependencies problem 2026-05-02 21:52:02 +09:00
b801e70f62 add safty check for preferLocal 2026-05-02 21:31:32 +09:00
a048305ebf fixed bug in MarkJobComplete 2026-05-02 20:56:29 +09:00
15d129f29c fixed the issue that multiple dependencies and introduce deadlock. 2026-05-02 20:31:05 +09:00
edfa6d69f0 add timout to test 2026-05-02 20:11:18 +09:00
0af4f987df fallback to bounded freelist 2026-05-02 19:36:18 +09:00
6f2bf18eb4 Change Thread.SpinWait(1) to SpinWait 2026-05-02 19:17:47 +09:00
b15e8359cf reverse the change to freelist 2026-05-02 19:06:58 +09:00
403690ad49 change freelist back 2026-05-02 18:54:14 +09:00
a593139581 temp fallback to old freelist 2026-05-02 18:40:30 +09:00
6f24a0aefa feat(job): fixed the deadlock issue in job system. 2026-05-02 18:37:30 +09:00
1b22b2a308 add more timeout 2026-05-02 18:14:33 +09:00
254cfa5c43 added timeout 2026-05-02 18:10:08 +09:00
1807559487 add runsettings 2026-05-02 18:03:25 +09:00
b0220a2350 feat: implement multi-threaded JobScheduler with worker threads and dependency management 2026-05-02 17:53:45 +09:00
0265a386ba Refactor thread cache management in allocators
Refactored thread-local stack allocator in AllocationManager to use ThreadLocalStackPool, removing global stack pointer arrays and locks. In FreeList, replaced fixed-size cache array and maxConcurrencyLevel with a dynamic linked-list system using SharedState and CacheReclaimer for thread cache lifecycle management. Block headers now store cache pointers instead of indices. Updated allocation/free logic and tests accordingly. Bumped assembly version to 3.1.3.
2026-05-02 16:47:50 +09:00
d6b4074281 Refactor collections to use 'scoped in T' parameters
Updated Add/Remove/Enqueue/Push/etc. methods in core unsafe collections to accept parameters as 'scoped in T' for improved performance and safety. Bumped assembly versions in both csproj files.
2026-05-02 13:52:45 +09:00
eb01e557d5 Relax SPMD job constraints, improve safety and docs
Removed unmanaged struct requirement from SPMD job wrappers and extension methods, allowing managed types. Updated all wrappers and extension methods to require only the interface constraint. Refactored SPMD test jobs to use safe ref-based Store overloads. Improved README and docs with clearer debug/mimalloc instructions and a better SPMD example. Cleaned up Program.cs by removing obsolete experimental code. Enhanced math precision in GGXMipGenerationBenchmark. Updated T4 template to generate new constraints and APIs.
2026-05-01 12:39:37 +09:00
18a181f57a Add AllBitsSet, refactor WideLane, improve math paths
- Add static AllBitsSet property to ISPMDLane and implement in ScalarLane and WideLane
- Refactor WideLane shuffle table pointers and update usages
- Improve pointer safety and mask handling in CompressStore, Gather, and MaskLoad
- Enhance Sin, Cos, SinCos with fast-math and hardware fallback
- Add Newton-Raphson refinement for reciprocal/sqrt when not fast-math
- Optimize MathV.Vector vector loading (struct init, pointer ops)
- Update project file: version 1.3.4, content packaging, AOT settings
- Minor code cleanup and naming consistency fixes
2026-05-01 12:19:58 +09:00
5b4832a886 Refactor SIMD gather, tighten constraints, doc & test opts
- Require TLane : unmanaged, ISPMDLane for stricter type safety and direct memory ops
- Refactor GatherVectorN and WideLane<T>.Gather to use Unsafe.SkipInit and direct assignment, removing stackalloc and TLane.Load for better SIMD performance
- Use Vector.Sum in WideLane<T>.ReduceAdd
- Add/improve XML docs for ReduceAdd/ReduceMax/ReduceMin
- Update test project for AOT, AVX2, speed optimization, and disable reflection
- Tweak GGXMipGenerationBenchmark and Program.cs for improved benchmarking and output
2026-04-30 16:02:18 +09:00
90461cd0ca Add SPMD lane reductions, gather, and SinCos API changes
- Added MaskLoad, Gather, and reduction methods (ReduceAdd, ReduceMax, ReduceMin) to ISPMDLane<TSelf, TNumber> with XML docs
- Changed SinCos to use out parameters instead of tuple return
- Implemented reductions in ScalarLane and WideLane (loop-based, TODO: SIMD)
- Added GetUnsafePtr to ISPMDLane
- Extended MathV to support Sin, Cos, SinCos, Tan, Asin, Acos, Atan, Atan2 for Vector2/3/4
- Improved WideLane.Sequence to use best vector type
- Updated GGX mip generation for new SinCos signature
- Bumped version to 1.3.2
- Enabled PNG dumping in GGX benchmark
2026-04-29 13:26:02 +09:00
b4535eff00 Refactor GGXMipGenerationJobSPMD for SPMD support
Replaced struct with generic SPMD version for SIMD, added type aliases (commented), optimized RadicalInverse_VdC, and adjusted SampleEquirectangularMap for better performance and code separation.
2026-04-29 01:35:12 +09:00
0acaf00767 Refactor trigonometric funcs, optimize GGX benchmark
- Replaced SIMD-based Sin/Cos/SinCos in WideLane with generic polynomial approximations for hardware independence.
- Updated ScalarLane Cast to use CreateTruncating.
- Applied AggressiveOptimization to key GGX methods; improved luma calculation and radical inverse LUT handling.
- Enhanced GGX benchmark setup, cleanup, and timing logic.
- Bumped project version to 1.3.1.
2026-04-28 22:17:59 +09:00
1074f9836e Update versions, cleanup Jobs csproj, remove Wrapper<T>
Updated AssemblyVersion in Jobs and LowLevel projects. Cleaned up Jobs csproj by removing unused properties, project reference, and content file inclusion. Deleted the Wrapper<T> disposable struct wrapper from Ptr.cs.
2026-04-27 13:09:24 +09:00
8ce7fddd32 Relax job constraints, add ref type support, misc fixes
Relaxed generic constraints for job scheduling/execution to allow reference types (removed struct requirement). Updated IJob, IJobParallelFor, and IJobParallel extension methods to support both value and reference types, introducing RunRef for struct-specific overloads. Adjusted JobExecutor and JobScheduler to match new constraints. Bumped assembly version to 3.1.1. Added Value property to Wrapper<T> for ref access and inlined Get(). Changed GGXMipGenerationJob sample count to linear roughness. Removed unused usings in JobInfo.cs.
2026-04-27 12:54:29 +09:00
9f7507ba71 Refactor SPMD lane abstraction and add gather support
- Rename ISPMD interfaces to ISPMDLane for clarity
- Add gather and mask load methods to ISPMDLane, implement for ScalarLane and WideLane
- Add GetUnsafePtr() for direct pointer access
- Update MathV and vector types to use new interface and gather methods
- Update SPMD job interfaces and implementations to ISPMDLane
- Improve hash codes, range checks, and safety checks in vector types
- Update codegen templates for new interface/methods
- Refactor SPMD jobs to use gather methods for efficient vectorized access
2026-04-25 11:50:51 +09:00
cfd01eb9b6 Refactor SPMD job system, add GGX mipmap benchmark
- Replace IJobSPMD with T4-generated, multi-type SPMD job interfaces and wrappers (up to 8 numeric types)
- Extend ISPMD with Cast/BitCast; implement for ScalarLane and WideLane (SIMD-aware)
- Add unary minus, scalar-lane, and lane-scalar operators to Vector2/3/4; improve Select methods
- WideLane now partial with T4-generated Cast/BitCast (SIMD conversions)
- SPMD job Execute now requires unmanaged TLane; update all usages and benchmarks
- Add GGXMipGenerationBenchmark with vectorized and scalar paths, SkiaSharp output
- Update project files: add generated code, SkiaSharp, bump version to 1.3.0
- Misc: fix formatting, method signatures, FreeList logic
2026-04-25 01:50:06 +09:00
a704cb19ec refactor(jobs, allocator): optimize queues & dependencies
Major refactor of job system and memory allocator:
- Replaced threadIndex with preferLocal for scheduling
- Switched local queues to SPMCQueue for better performance
- Introduced lock-free JobEdge pool for dependencies
- Removed remainingBatches; use ref counting for completion
- Updated all scheduling APIs and tests to new model
- Optimized FreeList struct sizes and block management
- Added allocation benchmarks
- Disabled OwnershipTransferAnalyzer temporarily
- Bumped assembly versions
2026-04-22 13:51:14 +09:00
b7d61488bb Refactor job system to use type-safe pooled job data
Replaces unsafe pointer-based job data with JobDataPool<T> and ConcurrentSlotMap<T> for safer, type-safe management. JobInfo now references job data by (dataID, dataGeneration). JobExecutor and JobScheduler updated to use the new pool-based approach, requiring T : struct. Removed FreeList and pointer logic. WorkerThread now uses reference counting to prevent use-after-free. Updated all scheduling APIs and benchmarks to match new signatures. Improved documentation and inlining. Bumped assembly version to 3.0.0 due to breaking changes.
2026-04-21 17:22:20 +09:00
f4bbef0be3 Refactor job scheduler API, allocation, and benchmarks
- Removed IJobScheduler interface; merged logic into JobScheduler
- Changed scheduling APIs to accept multiple dependencies (ReadOnlySpan)
- Moved WaitItem classes to JobScheduler.cs and updated types
- Updated JobExecutionContext to use JobScheduler and added docs
- Renamed AllocationManagerInitOpts to AllocationManagerDesc (required props)
- Added thread-safe TotalAllocatedMemory property to AllocationManager
- Refactored Integer to Data in benchmarks; updated usage
- Updated tests and improved documentation throughout
2026-04-21 11:21:16 +09:00
13802ca6c8 Job system priorities, async waits, parallel map/queue
Major refactor:
- Add job priority tiers and async wait APIs to IJobScheduler
- Implement priority-based job queues and scheduling logic
- Introduce UnsafeParallelHashMap and refactor UnsafeParallelQueue
- Refactor UnsafeSlotMap to chunked storage for scalability
- Update SlotMap/ConcurrentSlotMap for consistency and perf
- Add new benchmarks and unit tests for parallel collections
- Misc: add MemoryUtility.AlignUp, version bumps, test improvements, bug fixes
2026-04-18 11:26:08 +09:00
d5616daa05 Refactor JobExecutionContext, add scheduler state support
- Refactored JobExecutionContext to use init-only properties and added State and SelfHandle for richer context.
- Updated JobInfo field layout for clarity and memory alignment.
- JobScheduler now accepts and exposes an optional state object, passed to each job context.
- Improved memory management by using _freeList for allocations and disposal.
- WorkerThread and benchmarks updated to use new JobExecutionContext pattern.
- Bumped version to 1.6.1 and performed minor code cleanup.
2026-04-17 19:49:42 +09:00
ebee3bb7fb feat(jobs): add IJobScheduler interface and job scheduling improvements\n\nIntroduce IJobScheduler interface and enhance JobScheduler, WorkerThread, JobInfo and related collections. Add ConcurrentSlotMap tests and codegen generator updates.\n\nSee changed files for details. 2026-04-17 16:08:20 +09:00
123aa69a35 feat(allocator): replace static fields with properties
The `AllocationHandle` struct has been updated to replace
`public static readonly` fields with `public static` properties
using lambda expressions. The `Temp`, `FreeList`, and `Persistent`
fields are now properties, dynamically retrieving values from
their respective allocators. This change improves flexibility
and ensures the properties reflect the current state of the
underlying allocators.
2026-04-13 01:19:19 +09:00
490025bfc1 fixed the memory pool problem 2026-04-13 00:29:20 +09:00
4647cd4b95 Fixed the memory access violation in AllocationManager 2026-04-13 00:10:21 +09:00
6f7f70a739 fixed thr bug that empty job can't finish correctly 2026-04-12 22:33:04 +09:00
2ccc19092c change to ctx.ThreadIndex 2026-04-12 22:21:33 +09:00
8b7f773d29 feat(JobScheduler): improve dependency handling logic
Updated `JobScheduler` to enhance dependency tracking by counting valid dependencies upfront and dynamically adjusting counts using `Interlocked` operations. Improved job enqueueing logic to ensure jobs are only enqueued when all dependencies are met.

Replaced `Interlocked.Increment` with `Interlocked.Add` for batch updates to `_totalJobCount`, improving performance. Adjusted `VirtualStack` cleanup to use the correct size variable for memory deallocation.

Simplified `JobDispatchingJob` API by removing `ctx.ThreadIndex` parameter. Updated `TestJobSystem` to pass job handles as dependencies for proper execution order.

Incremented assembly version to 1.5.9 to reflect these changes.
2026-04-12 22:09:28 +09:00