Ask Your Question
0

Dynamically choose best instruction set for hardware

asked 2019-08-19 03:51:46 -0600

Is it possible to let OpenCV dynamically choose which instruction set to use for the hardware it is running on?

We build OpenCV via Visual Studio in Win32, afterwards we changed the Solution and Project files to also support our own Platform.

We are running OpenCV on an embedded device which does not support SSE3 calls. When we run our program, OpenCV runs the hardware check and then decides to quit. Is there a solution that checks the hardware without quitting and then decides which instruction set it can use?

If this is not the case, is there a way to make these instruction set Platform dependent at compile time? So, both Win32 and our own Platform uses the same source files but via a define, or via an other way, decides which instruction set it can use.

edit retag flag offensive close merge delete

Comments

1

What do you mean by:

OpenCV runs the hardware check and then decides to quit

Look at CPU optimization dispatching. You choose a baseline instruction set, e.g. SSE2 and then you can dispatch some other instruction sets.

But normally if you want to target a specific CPU architecture, it should be enough to add the corresponding CPU flags in Visual Studio. If you want to produce a binary that "some kind of fit all", see CPU code dispatching.

Eduardo gravatar imageEduardo ( 2019-08-20 07:56:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-19 08:47:27 -0600

Automatically, not easy. On Ubuntu I did it by piping out the compiler flags of my CPU and than processing those to see what is supported. An installation, once build will also be dependent on the instruction set of the CPU. Some, like SSE and SSE2 are quite standard nowadays and can be integrated without problem, but quickly setting or unsetting instructions sets is not possible using OpenCV, or at least I haven't find an automatic system for that yet.

edit flag offensive delete link more

Comments

1

If you are doing something like cat /proc/cpuinfo to add flags like -mavx I suppose you want to build with full optimizations that match your CPU. So you can do instead -march=native.

The compiler will generate optimized instructions for your platform. But this means also that you cannot ship or redistribuate the binary to run on other platform (e.g. your CPU supports AVX2 but the shipped platform don't).

For this latter case, see CPU code dispatching.

Eduardo gravatar imageEduardo ( 2019-08-20 08:09:05 -0600 )edit

@Eduardo, that is what I mean, but the problem is that he is running on Windows, on which collecting that info is not as straightforward in my experience.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-20 08:21:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-19 03:51:46 -0600

Seen: 667 times

Last updated: Aug 19 '19