last day (14 days later) » 

3:07 PM
1
Q: What is the benefits of using vaddss instead of addss in scalar matrix addition?

Facked DeveloperI have implemented scalar matrix addition kernel. #include <stdio.h> #include <time.h> //#include <x86intrin.h> //loops and iterations: #define N 128 #define M N #define NUM_LOOP 1000000 float __attribute__(( aligned(32))) A[N][M], __attribute__(( aligned(32))) B[N][M], __a...

 
To answer the title question (I can't fully parse the last part of the body): GCC does what you said only when compiling at -O1. When targeting systems with AVX is always a good idea to use the VEX versions of the legacy SSE instructions.
 
@MargaretBloom, no gcc -O2 I added to the question. targeting is OK but I'm comparing pure AVX and SSE not AVX-256 with AVX-128.
 
@MargaretBloom, vectorization is enabled at by -ftree-loop-vectorize which is enabled by -O3 but not -O2. This will even vectorized with -O1 -ftree-loop-vectorize
 
I edited the question and make the code compilable.
 
vaddps x,x,mem does not require mem to be aligned whereas addps x,mem does (x is a SIMD register (xmm,ymm, or zmm). That's one advantage of vex encoding.
 
3:07 PM
@Zboson, Yes, you are right but memory is aligned. 16 boundary for SSE and 32 boundary for AVX
 
@Zboson Honestly I can't understand the point. I'd have expected the OP to use -O3 when profiling (no need to nitpick on the, admittedly wrong, "only" part of my observation, IMO). To OP: I don't understand you either: "The speed up of -mavx over msse4.2 is 2.7x." seems to be contradicted by "Scalar-SSE is 2.7x faster than Scalar-AVX", further you explicitly asked GCC to generate VEX versions (GCC depresses SSEx instructions when -mavx is used. It generates new AVX instructions or AVX equivalence for all SSEx instructions when needed.) and I gave you a link explaining the rationale.
 
@MargaretBloom, I agree I don't get the point. The OPs claims are confusing and the update seems contradictory. I don't see any good reason in this case the scalar SSE or AVX code would make a significant difference. I can't reproduce the OPs results so far with GCC 6.2, Ubuntu 16.10, Skylake. I thought maybe the OP was seeing this.
 
@Zboson, "The speed up of -mavx over -msse4.2 is 2.7x." it's for scalar program wich is compiled with these flags. I made a mistake in UPDATE part just edited it
 
It makes no sense -O2 -msse4.2 should have about the same speed as -O2 mavx. In fact, so far the the first case is about 10% faster. I have no idea why the AVX version would be 2.7x faster. I don't observe this.
Can you add __asm__ __volatile__ ( "vzeroupper" : : : ); right after main and test again?
 
gcc -O2 msse4.2: The best time: 0.000024 sec in 406490 repetition for 128X128 matrix and gcc -O2 -mavx: The best time: 0.000009 sec in 1000001 repetition for 128X128 matrix was added to the question body
@zboson, I just added asm and tested the results did not change.
 
3:07 PM
I am out nearly out of ideas. The only thing left I can think of is if clock_gettime was leaving the upper half of an AVX register dirty. You could try __asm__ __volatile__ ( "vzeroupper" : : : ); after each call to clock_gettime(). I doubt this is the problem though.
 
@Zboson, yes that was the point. I tested again and you are completely right. thanks. -msse4.2 got 8 ns and -mavx got 9 ns.
 
You mean that solved the problem? What version of Linux Mint are you running. What Kernel. What version of glibc?
 
@Zboson, yes you can write the answer and I will accept it. the problem was not about avx and sse. Linux mint 18, kernel 4.4.0-53
 
What does ldd --version report?
 
ldd (Ubuntu GLIBC 2.23-0ubuntu5) 2.23
should I use __asm__ __volatile__ ( "vzeroupper" : : : ); after each clock_gettime? this point will kill me. I have 200 variable in my research paper. and if it changes. I want to die.
 
3:07 PM
I don't know the best solution. What about upgrading your Linux version? I don't have the problem on my Skylake system with Ubuntu 16.10. and glibc 2.24.
 
I don't know. I can't right now I should publish the paper. How should I address this problem?!!!!
could I upgrade from update manager and all my applications and library not change?
 
What version of Linux Mint are you running? Maybe you can update that?
 
I use Linux mint 18 Sarah. I think I can but the problem is I will lose all my results and tomorrow is my papers deadline.
 
BTW, the latest version of mint is 18.1. I have no idea if 18.1 will fix your problem. I think it still uses glibc 2.23. I don't use mint anymore because it's based on Ubuntu LTS so it's often old.
 
Yes, You are right. I used to run ubuntu on my laptop. I bought this new laptop and thought it might be a better idea to run a new OS. I liked Linux mint because I had no idea. I might change it to ubuntu 17.4 when it released.
 

last day (14 days later) »