Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Royi
Novice
274 Views

Create a LIB File from Intel IPP

Hello,

I'm using Visual Studio 2013 and the Intel IPP 8.2.

I have some Auxiliary Functions I build upon Intel IPP for image manipulation in C++ style by overloading some operators and defining function which are composition of many Intel IPP functions.

Now, I want to build a library of that functions I created and I want this library to be "Self Defined".
Namely, on my future projects I want to link to that library (And only that) and be able to use my functions (Which relies on Intel IPP).
Basically, it is something like the question here:

http://stackoverflow.com/questions/4736877/how-to-link-boost-in-a-dependant-static-library

Which refers me here:

http://stackoverflow.com/questions/5445023/c-can-you-build-one-static-library-into-another

Just to explain things, in Project 1 I build a library of function I created which relies on Intel IPP.
I use the static libraries and try to create a static lib out of it.
On Project 2 I use the functions I created.
I only link the LIB file I created from Project 1.
Yet when I try to compile Project 2 I get the following error:

LINK : fatal error LNK1104: cannot open file 'C:\Program Files (x86)\Intel\Composer XE 2015\ipp\include\ippi.h/../../lib/intel64/ippimt.lib'

I prefer the library to be static, but if there's no choice, a dynamic library would be OK as well.

0 Kudos
12 Replies
Ying_H_Intel
Employee
274 Views

Hi Royi, 

As i understand, you have the same questions as http://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries

and one of  solution is

If you are using Visual Studio then yes, you can do this.

The library builder tool that comes with Visual Studio allows you to join libraries together on the command line. I don't know of any way to do this in the visual editor though.

lib.exe /OUT:compositelib.lib  libyour.lib libippimt.lib 

Another way  may be , as you saw,  in http://stackoverflow.com/questions/5445023/c-can-you-build-one-static-library-into-another
in your project 1 , add the below code 

#pragma comment(lib, "ippimt.lib")
#pragma comment(lib, "ippsmt.lib")
#pragma comment(lib, "ippcoremt.lib")

... 

But the final static library may be too big.  

For the link model supported by IPP,  I may suggest to create  a  custom.dll  based on IPP static library. 

For example,  you can in Project 1 I build a custom.dll  dynamic library based on IPP static library, which of function you created which relies on Intel IPP.

Then link the custom.lib (custom.dll) in your project 2.   Thus you don't need to handle IPP related libraries. 

Best Regards,

Ying

Sergey_K_Intel
Employee
274 Views

Hi,

A static library cannot be "self-defined". It is only a sum of object modules with references to undefined external functions, hanging out of static libs. These can be references to IPP functions, to Microsoft run-time library, to any other external libraries.

Only linker tool can resolve external references by adding missing external object modules from libraries specified in linker command line options. This is done by DLL project or application (EXE) project of Visual Studio.

Royi
Novice
274 Views

Hi Ying,

I will try the comment thing and report.
We didn't try the manual thing with lib.exe as someone on StackOverflow commented how to do it using the internal settings yet as I showed above, it didn't work.
Regarding your second idea, the Dynamic DLL, the problem the blog post about how to create Customized DLL doesn't work.

Hi Sergey,

I didn't understand your answer.
Are you suggesting it can't be done?

Thank You Both.

 

Sergey_K_Intel
Employee
274 Views

Yes, Royi !

The only (exotic) way to have self-sufficient static library is to neatly extract missing object modules (missing external functions) from other libs and to put them into target static library (because, you can append any object modules to static lib). So, finally your static lib can contain ALL required functions. But, this is very hard work. You'd better pass this work to linker.

DLL is a kind of library what you need, when all external references resolved by linker, and only selected set of functions is seen from outside the DLL. You can specify the list of these functions using DEF file.

Royi
Novice
274 Views

Hi Sergey,

Again, I seem to miss something in your answer.
I'm trying let the linker do the work, I just want to link it to one file, Static Lib or DLL or anything created from Project 1.
Can that be done? How exactly?
I don't mind do hard work as long as it works.

As I wrote above,
I can't find a guide to describe how to create a custom DLL.
I need only the Image Processing part of IPP (Including the Core of course).
The current guide, the sample at its bottom doesn't work:

https://software.intel.com/en-us/articles/intel-ipp-version-81-custom-dll

Thank You for you assistance, I appreciate it.

Ying_H_Intel
Employee
274 Views

Hi Royi,

Regarding building a custom DLL,  you can create a dynamic library project in MSVS  as you create your Project 1 static library.  ( change the project type=>dynamic library).

Or you can use IPP custom DLL build tool,  It is in IPP legacy sample. (IPP 8.0 or IPP 7.1)

Intel® IPP provide a Building Custom DLLs tool to create a custom DLL in early version. It is  available in legacy sample
\ipp-samples\advanced-usage\linkage\customdll

Best Regards,

Ying

P.S there are similar descriptions in  the article https://software.intel.com/en-us/articles/intel-integrated-performance-primitives-intel-ipp-intel-ip...   

Royi
Novice
274 Views

Hi,

I'm coming to this problem as we never solved it.
I will try to add code to explain better.

On my computer I have Intel Compiler Suite.
I want to create a library (*.lib) so he could use functions I created which use Intel IPP.

Small example, let's say I have the following code:

#include "ippi.h"
#include "ippcore.h"
#include "ipps.h"
#include "ippcv.h"
#include "ippcc.h"
#include "ippvm.h"

#include <math.h>


void ApplyGaussianFilter(float* mO, float* mI, int numRows, int numCols, float kernelStd, float stdToRadiusFactor)
{
	int threads = 4; //omp_get_max_threads(); //TODO: not 1;

	int bytesStep = 4 * numCols;

	IppSizeL    specSize = 0;
	IppSizeL    initSize = 0;
	IppiSizeL   sizeL = { numCols, numRows };
	int         chunkSize = (numRows + threads * 2 - 1) / (threads * 2);

	int kernelRadius = (int)(ceilf(stdToRadiusFactor * kernelStd));
	int kernelSize = kernelRadius * 2 + 1;

	chunkSize = IPP_MAX(chunkSize, kernelRadius);

	ippiFilterGaussianGetSpecSize_L(kernelSize, ipp32f, 1, &specSize, &initSize);

	IppFilterGaussianSpec* pSpec = (IppFilterGaussianSpec*)ippMalloc(specSize);
	Ipp8u*                 pInitBuffer = (Ipp8u*)ippMalloc(initSize);

	ippiFilterGaussianInit_L(sizeL, kernelSize, kernelStd, ippBorderRepl, ipp32f, 1, pSpec, pInitBuffer);

#pragma omp parallel num_threads(threads)
	{
		IppSizeL        tmpSize = 0;
		Ipp32f         *pSrcT;
		Ipp32f         *pDstT;
		IppiSizeL       tRoi = { sizeL.width, chunkSize };
		IppSizeL        row;
		IppiBorderType  tBorder;

		ippiFilterGaussianGetBufferSize_L(tRoi, kernelSize, ipp32f, ippBorderRepl, 1, &tmpSize);
		Ipp8u* pBuffer = (Ipp8u*)ippMalloc(tmpSize);

#pragma omp for
		for (row = 0; row < sizeL.height; row += tRoi.height)
		{
			tBorder = ippBorderRepl;
			if (row)
				tBorder = (IppiBorderType)(tBorder | ippBorderInMemTop);
			if (sizeL.height - row - tRoi.height < kernelRadius)
				tRoi.height = sizeL.height - row;
			else
				tBorder = (IppiBorderType)(tBorder | ippBorderInMemBottom);
			//if (row + tRoi.height >= sizeL.height)


			pSrcT = (Ipp32f*)((Ipp8u*)(mI)+row * bytesStep);
			pDstT = (Ipp32f*)((Ipp8u*)(mO)+row * bytesStep);

			ippiFilterGaussian_32f_C1R_L(pSrcT, bytesStep, pDstT, bytesStep, tRoi, tBorder, NULL, pSpec, pBuffer);
		}
	}
}

This is a simple version which uses Intel's IPP Guassian Blur in Multi Threaded fashion.

I compile this on my computer (With the choice of static link in Visual Studio for IPP) as a `lib` file and with the corresponding `h` file I want to give it to my colleague who doesn't have access to IPP.

The problem is he can't use it as once he tries use tho (This is just example) the compiler asks for many other libs (svml_dispmt.lib, libmmt.lib, libirc.lib, libiomp5md.lib, libdecimal.lib).
Even when I give the as well there is a requirement for 'ippimt.lib'.
Even when this is supplied it seems the path is encoded into the files and even then the linker looks for Intel Compiler Installation folder.

My question is, how can I create a lib file (Really simple example above) which uses IPP functions and allows other to use it even if they don't have Intel IPP?

Thank You.

Pavel_B_Intel1
Employee
274 Views

Hello Royi,

a static library is an a simple archive of object files. If a function uses something that is not present in the library (e.g. call an IPP function) the reference on the IPP library is created in the object file and the static library starts to depend from the IPP library.

That is the reason why during linkage with your static library you receive many dependencies: (svml_dispmt.lib, libmmt.lib, libirc.lib, libiomp5md.lib, libdecimal.lib)

The most simple way I see here is to build a custom dynamic library from the IPP libraries. You can do it yourself using an export file and a simple link line or you can use IPP Custom Library Tool that is a part of IPP 2018 and 2019 releases.

Pavel

Royi
Novice
274 Views

Hi Pavel,

But I don't want a Dynamic Library (This I can create and this DLL doesn't require anything but OpenMP [libiomp5md.dll]).

I want to create a Lib file (For static linking but the OpenMP) that other on my team can use without the need for IPP (Or any other resource in Intel Composer but the OpenMP DLL).
How can I do that?

Sergey_K_Intel
Employee
274 Views

Hi Royi,

Let's look on what is in "ipp*.h" header files, let's take ippi:

#if !defined( IPP_NO_DEFAULT_LIB )
  #if defined( _IPP_SEQUENTIAL_DYNAMIC )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippi" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippcore" )
  #elif defined( _IPP_SEQUENTIAL_STATIC )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippimt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippsmt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippvmmt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippcoremt" )
  #elif defined( _IPP_PARALLEL_DYNAMIC )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippi" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippcore" )
  #elif defined( _IPP_PARALLEL_STATIC )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippimt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippsmt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippvmmt" )
    #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippcoremt" )
  #endif
#endif

If you do nothing, the above #pragma comment lines go to your object files like directives of where to look for the IPP libraries by default. So, if you don't specify the IPP libraries explicitly in linker command line, it (linker) will look for the libraries in the directory "<ippi.h file dir>/../../lib/lintel64/". Or, "ia32".

I strongly believe, that if you specify the new path to the IPP libraries in linker command, this will be enough for it and it won't be looking for default libraries. But you need to explicitly say "cl <options> <source or object files> <new IPP library dir>\ippimt.lib <the same>\ippsmt.lib ...ippcoremt.lib"

If it will not work, you can (option #2) recompile your source code files with definition "-DIPP_NO_DEFAULT_LIB" and compiler will not insert any library path hints into your object files. In this case linker will be simply complaining about non-resolved external references to IPP function names, until you specify IPP library path in the linker command line.

Hope it will help,

Sergey

Sergey_K_Intel
Employee
274 Views

Royi,

I described a way to build application from object files and IPP libraries on another computer.

I am sorry, but your desire

          I want to create a Lib file (For static linking but the OpenMP) that other on my team can use without the need for IPP (Or any other resource in Intel             Composer but the OpenMP DLL).
         How can I do that?

is practically impossible. Only using of DLL, when linker does all the job of collecting all required functions into a single file, could help.

Regards,
Sergey

Pavel_B_Intel1
Employee
274 Views

Royi wrote:

Hi Pavel,

But I don't want a Dynamic Library (This I can create and this DLL doesn't require anything but OpenMP [libiomp5md.dll]).

I want to create a Lib file (For static linking but the OpenMP) that other on my team can use without the need for IPP (Or any other resource in Intel Composer but the OpenMP DLL).
How can I do that?

Hi Royi,

Unfortunately there is no a way to build an own static library with required dependencies. It is possible to build the own static library include all other static libraries inside, but in this case the library will huge size. How to do it you can read here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/c5fa62ac-e84f-4d61-a9bf-eb8136305393/creating-a-static-libraries-that-depends-on-other-libraries?forum=vclanguage

The only one way to build a small own library with all required dependencies is dynamic library.

Pavel.

Reply