Skip to content

Commit

Permalink
Merge commit 'db4a44d423d80d08a3bc06b5c6379103032d5788'
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Sep 20, 2023
2 parents 8770399 + db4a44d commit 2f1b1c3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 84 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
108 changes: 25 additions & 83 deletions src/Nexus/Services/ProcessingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand All @@ -168,14 +162,7 @@ private void ApplyAggregationFunction(
{
var sin = sinBuffer.Span;
var cos = cosBuffer.Span;

using var nanFreeDataOwner = MemoryPool<double>.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;

Expand Down Expand Up @@ -208,13 +195,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand All @@ -230,13 +211,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand All @@ -252,13 +227,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand All @@ -274,13 +243,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand All @@ -296,13 +259,7 @@ private void ApplyAggregationFunction(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<double>.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)
Expand Down Expand Up @@ -335,13 +292,9 @@ private void ApplyAggregationFunction<T>(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<T>.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;
Expand Down Expand Up @@ -375,13 +328,9 @@ private void ApplyAggregationFunction<T>(

Parallel.For(0, targetBuffer.Length, x =>
{
using var nanFreeDataOwner = MemoryPool<T>.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;
Expand Down Expand Up @@ -410,50 +359,43 @@ private void ApplyAggregationFunction<T>(
}
}

private static Memory<T> GetNaNFreeData<T>(
ReadOnlyMemory<T> source,
ReadOnlyMemory<byte> status,
Memory<T> target) where T : unmanaged
private static Memory<T> GetNaNFreeData<T>(Memory<T> data, ReadOnlyMemory<byte> 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<double> GetNaNFreeData(
ReadOnlyMemory<double> source,
Memory<double> target)
private static Memory<double> GetNaNFreeData(Memory<double> 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
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "2.0.0",
"suffix": "beta.17"
"suffix": "beta.18"
}

0 comments on commit 2f1b1c3

Please sign in to comment.