Vector Class Discussion

 
thread Optimization of Code Path at Run Time - Royi - 2018-02-18
last replythread Optimization of Code Path at Run Time - Agner - 2018-02-18
last replythread Optimization of Code Path at Run Time - Royi - 2018-02-18
last reply Optimization of Code Path at Run Time - Agner - 2018-02-19
 
Optimization of Code Path at Run Time
Author:  Date: 2018-02-18 04:59
Hello,

I was wondering, does the Vector Class Library optimizes code path at run time?
Namely, if I compile it on Computer 001 of mine with SSE4 only (Use vec8f) and then run it on Computer 002 of mine which has AVX, will it use AVX automatically?

Namely does it create optimized code path according to CPU features on run time?

Thank You.

   
Optimization of Code Path at Run Time
Author: Agner Date: 2018-02-18 11:17
Royi wrote:
does it create optimized code path according to CPU features on run time?
This is indeed possible. You need to compile the same code multiple times with different instruction sets enabled on the compiler command line, and then link the multiple object files together so that you can select the optimal one at runtime. See the chapter "Instruction sets and CPU dispatching" in the manual. The file dispatch_example.cpp shows an example of how to do this.
   
Optimization of Code Path at Run Time
Author:  Date: 2018-02-18 18:30
Hi Agner,
With your permission, maybe going a different which might be easier for me.

I have already in my code 2 versions of each function.
One targets CPU's with SSE4 and one targets AVX.
What I would like to be able to do is the following:

1. When I call a function from VCL on __m128, for instance exp(), I would like the generated code to use SSE4 only.
2. When I call a function from VCL on __m256, for instance exp(), I would like the generated code to use AVX only.

Is there a way to do so with VCL?

Thank You.

   
Optimization of Code Path at Run Time
Author: Agner Date: 2018-02-19 00:13
The exp() function is inlined by default, so it will be compiled with the same options as your code. Inlining means that the entire code of the exp function is inserted at the place of the call to exp().

If you call a function that is not inlined then make sure it is compiled together with your code.