Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7014 Discussions

Reduce the size of program after linking with MKL libraries

dakotaa
Beginner
1,204 Views

I am just getting started with intel MKL libraries (mac/Xcode 10/clang) but I have noticed that the resulting binaries have been very big even if I am using just a couple of APIs. For eg-  the following sample code results in a 25MB executable

    int N = 1;
    fftw_complex *in, *out;
    fftw_plan my_plan;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N);
    my_plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_execute(my_plan);
    fftw_destroy_plan(my_plan);
    fftw_free(in);
    fftw_free(out);

 Following are my compilation settings (as generated by the link-line advisor)

Link Flags -

${MKLROOT}/lib/libmkl_intel_ilp64.a ${MKLROOT}/lib/libmkl_sequential.a ${MKLROOT}/lib/libmkl_core.a -lpthread -lm -ldl

Compiler Flags - 

-DMKL_ILP64 -m64 -I"${MKLROOT}/include"

I was statically linking to reduce the binary size as the same dylibs are 122 MB in size. Is it possible to reduce the size of the binary further? 

There is a similar question on the forum here, but the link to the answer is dead now.

0 Kudos
6 Replies
mecej4
Honored Contributor III
1,180 Views

Your statement/question, "I was statically linking to reduce the binary size as the same dylibs are 122 MB in size. Is it possible to reduce the size of the binary further? ", reveals several misconceptions.

Go back to the MKL Link Line Advisor, and ascertain the options to use dynamic libraries, instead. For a short program with source code a couple of kilobytes long, compiling and linking with shared libraries should produce an a.out that is some tens of kilobytes in size.

You can benefit from reading about how shared libraries work in Linux/OSX.

0 Kudos
dakotaa
Beginner
1,171 Views

Sorry, by "binary" I meant the total size of the application package (for eg .app bundle on mac). I thought by linking statically, only the code that I referenced would get embedded in the executable thereby reducing the overall size of the package. 

So I would like to rephrase my question as "Is it possible to reduce the size of the overall application package further?"

 

0 Kudos
dakotaa
Beginner
1,168 Views

Also, it seems the static libraries contain the code for all the supported ISAs. Would it be possible to skip an instruction set like AVX512 while linking statically?

0 Kudos
RahulV_intel
Moderator
1,140 Views

Hi,


We are forwarding your query to the MKL experts. They will get in touch with you.


Thanks,

Rahul


0 Kudos
Gennady_F_Intel
Moderator
1,134 Views

Yes, the statically linked executable contains optimizations for all supported ISA and in the case of Intel MKL, there is no opportunity to build the executable with only one supported code path

(instruction set). For another Intel performance library ( aka IPP), such an opportunity exists. We recommend submitting such a Feature Request to the official support channel - Intel Online Service Center.

Thanks, Gennady


0 Kudos
Gennady_F_Intel
Moderator
1,076 Views

The issue is closing and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.



0 Kudos
Reply