1

I have a static library that is linked to IPP 7.1 for 4 calls to ippi_Mul. The project is built in Visual Studio. This was previously a dynamic link, but it turns out that in IPP 7.1 dynamic libraries are internally multi-threaded, which is disallowed for me, so I changed it to a static link to single-threaded IPP. The size of the lib then increased from several MB to about 150MB.

Is this normal for such a link? I am only calling one function from IPP, as I said.

In the latest IPP 8.2 multi-threading is deprecated, so updating would solve the problem for me. However I am still intrigued by this. If I am only using a single function from the library, wouldn't static linking be a more correct option? And is such an inflation of the lib size to be expected?

buzjwa
  • 2,632
  • 2
  • 24
  • 37

1 Answers1

2

First, need to clarify the your project model. "Static library" usually is not linked to any of external libraries. Static library is just an archive of object modules, if we talk about Windows' .lib files of course.

You use linker only when producing application executible (.exe file), or dynamic library (.dll).

I can assume, that your solution has two projects - one for static library, and the default project for application. In this case, linking to dynamic IPP library definitely minimizes application footprint, because application does not contain IPP function code (only calls to external function from dynamic library). The functions are stored in dynamic library files, there are hundreds of MBs.

If you want to build your application with static IPP libraries and, at the same time, decrease application executable size, you need to limit the CPU optimization included into your application simultaneously.

When you do nothing special, just use static IPP libraries in the command line to the linker, the application object file is linked with all function variants, optimized for different CPU architectures (from SSE to AVX2).

For example, if you included function "ippSomeFunction" into your source code, the linker will add "ippSomeFunction_SSE" + "ippSomeFunction_SSE2" + ... + "ippSomeFunction_AVX2" to application executable. This will increase application size, but will allow execute your application on any of Intel CPUs with most optimization for current CPU. The dispatcher will turn on the most appropriate function variants for CPU.

If you know the target CPU architecture, you can make linker to add only required optimization of the functions. Read "readme.htm" doc in your IPP installation directory "/ipp/tools/ia32 (or, intel64) /staticlib".

In this case, the only change you need to do for the source code is to add "#include ipp_cpuletter.h" file before including of other IPP-related .h files, e.g.

#include "ipp_p8.h"
// From now on only IPP functions for SSE4.2 CPU will be used
#include "ippi.h"
// The rest of code
Sergey Khlystov
  • 276
  • 2
  • 5