From db4a44d423d80d08a3bc06b5c6379103032d5788 Mon Sep 17 00:00:00 2001 From: Apollo3zehn Date: Wed, 20 Sep 2023 11:37:49 +0200 Subject: [PATCH] Reverse multithreading changes, there was no bug --- CHANGELOG.md | 5 ++ src/Nexus/Services/ProcessingService.cs | 108 ++++++------------------ version.json | 2 +- 3 files changed, 31 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb075e7a..ddfbc13c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v2.0.0-beta.18 - 2023-09-20 + +### Bugs fixed: +- Reverse multithreading changes, there was no bug luckily + ## v2.0.0-beta.17 - 2023-09-18 ### Bugs fixed: diff --git a/src/Nexus/Services/ProcessingService.cs b/src/Nexus/Services/ProcessingService.cs index f4505922..912b422e 100644 --- a/src/Nexus/Services/ProcessingService.cs +++ b/src/Nexus/Services/ProcessingService.cs @@ -135,13 +135,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -168,14 +162,7 @@ private void ApplyAggregationFunction( { var sin = sinBuffer.Span; var cos = cosBuffer.Span; - - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var length = chunkData.Length; var isHighQuality = (length / (double)blockSize) >= _nanThreshold; @@ -208,13 +195,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -230,13 +211,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -252,13 +227,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -274,13 +243,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -296,13 +259,7 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; - + var chunkData = GetNaNFreeData(data.Slice(x * blockSize, blockSize)).Span; var isHighQuality = (chunkData.Length / (double)blockSize) >= _nanThreshold; if (isHighQuality) @@ -335,13 +292,9 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - status: status.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; + data.Slice(x * blockSize, blockSize), + status.Slice(x * blockSize, blockSize)).Span; var targetBufferSpan = targetBuffer.Span; var length = chunkData.Length; @@ -375,13 +328,9 @@ private void ApplyAggregationFunction( Parallel.For(0, targetBuffer.Length, x => { - using var nanFreeDataOwner = MemoryPool.Shared.Rent(blockSize); - var nanFreeData = nanFreeDataOwner.Memory; - - var chunkData = GetNaNFreeData( - source: data.Slice(x * blockSize, blockSize), - status: status.Slice(x * blockSize, blockSize), - target: nanFreeData).Span; + var chunkData = GetNaNFreeData(data + .Slice(x * blockSize, blockSize), status + .Slice(x * blockSize, blockSize)).Span; var length = chunkData.Length; var isHighQuality = (length / (double)blockSize) >= _nanThreshold; @@ -410,50 +359,43 @@ private void ApplyAggregationFunction( } } - private static Memory GetNaNFreeData( - ReadOnlyMemory source, - ReadOnlyMemory status, - Memory target) where T : unmanaged + private static Memory GetNaNFreeData(Memory data, ReadOnlyMemory status) where T : unmanaged { var targetLength = 0; - var sourceLength = source.Length; - var sourceSpan = source.Span; - var targetSpan = target.Span; - var statusSpan = status.Span; + var sourceLength = data.Length; + var spanData = data.Span; + var spanStatus = status.Span; for (int i = 0; i < sourceLength; i++) { - if (statusSpan[i] == 1) + if (spanStatus[i] == 1) { - targetSpan[targetLength] = sourceSpan[i]; + spanData[targetLength] = spanData[i]; targetLength++; } } - return target[..targetLength]; + return data[..targetLength]; } - private static Memory GetNaNFreeData( - ReadOnlyMemory source, - Memory target) + private static Memory GetNaNFreeData(Memory data) { var targetLength = 0; - var sourceLength = source.Length; - var sourceSpan = source.Span; - var targetSpan = target.Span; + var sourceLength = data.Length; + var spanData = data.Span; for (int i = 0; i < sourceLength; i++) { - var value = sourceSpan[i]; + var value = spanData[i]; if (!double.IsNaN(value)) { - targetSpan[targetLength] = value; + spanData[targetLength] = value; targetLength++; } } - return target[..targetLength]; + return data[..targetLength]; } // TODO: vectorize diff --git a/version.json b/version.json index 275cdb3c..03bd1c49 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "version": "2.0.0", - "suffix": "beta.17" + "suffix": "beta.18" } \ No newline at end of file