Re: performance issues with SIMD function

2023-11-04 Thread Guillaume Piolat via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Can anyone help me to understand what I am missing?



Your loop is likely dominated by sin() calls, And the rest of the 
loop isn't complicated enough to outperform the compiler.


What you could do is use the intrinsics to implement a _mm_sin_ps 
that makes 4x sines at once, then you'll see an improvement at 
scale.


Re: performance issues with SIMD function

2023-11-04 Thread Bogdan via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:32:08 UTC, Sergey wrote:

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not 
see any performance improvements from the non-SIMD 
implementation. The SIMD version is a little bit slower even 
with LDC2 and --o3. Can anyone help me to understand what I am 
missing?


Thanks!
Bogdan


In your SIMD algorithm has not so many gain from using SIMD. 
The length of the loop is the same.
Also probably compiler applying some optimizations in regular 
versions, that doing almost the same.


I think it was from the way I was running the benchmark:

```d
  
  auto begin = Clock.currTime;
  foreach (i; 0..100_000) {
res1 = areaMeters(polygon);
  }
  writeln("No SIMD ", Clock.currTime - begin);

  
  begin = Clock.currTime;
  foreach (i; 0..100_000) {
res2 = areaMetersSimd2(polygon);
  }
  writeln("SIMD", Clock.currTime - begin);

```

gives me:
```
  No SIMD 1 sec, 80 ms, 765 μs, and 1 hnsec
  SIMD1 sec, 120 ms, 765 μs, and 1 hnsec
```


```d
  
  auto begin = Clock.currTime;
  res1 = areaMeters(polygon);
  writeln("No SIMD ", Clock.currTime - begin);

  
  begin = Clock.currTime;
  res2 = areaMetersSimd2(polygon);
  writeln("SIMD", Clock.currTime - begin);

```


gives me:
```
  No SIMD 19 μs and 3 hnsecs
  SIMD16 μs and 8 hnsecs
```






Re: performance issues with SIMD function

2023-11-03 Thread Sergey via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not see 
any performance improvements from the non-SIMD implementation. 
The SIMD version is a little bit slower even with LDC2 and 
--o3. Can anyone help me to understand what I am missing?


Thanks!
Bogdan


In your SIMD algorithm has not so many gain from using SIMD. The 
length of the loop is the same.
Also probably compiler applying some optimizations in regular 
versions, that doing almost the same.


Re: performance issues with SIMD function

2023-11-03 Thread Imperatorn via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:17:43 UTC, Imperatorn wrote:

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not 
see any performance improvements from the non-SIMD 
implementation. The SIMD version is a little bit slower even 
with LDC2 and --o3. Can anyone help me to understand what I am 
missing?


[...]


Did you try using std.vector or __vector first?


Typo, I mean those in core.simd or ldc.simd


Re: performance issues with SIMD function

2023-11-03 Thread Imperatorn via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not see 
any performance improvements from the non-SIMD implementation. 
The SIMD version is a little bit slower even with LDC2 and 
--o3. Can anyone help me to understand what I am missing?


[...]


Did you try using std.vector or __vector first?