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

can't make a custom DLL of MKL routines

Brian_Murphy
New Contributor II
2,988 Views

To combat file bloat, I am trying to build a custom DLL with a subset of MKL routines by following the instructions given here.  But the instructions do not work.

I tried their following simple example:

#source Visual Studio environment variables
call vcvarsall.bat x86
#run custom dll builder script
nmake ia32

 and got this:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.7
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Xlrotor>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.7
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Xlrotor>nmake ia32

Microsoft (R) Program Maintenance Utility Version 14.27.29112.0
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make 'ia32'
Stop.

What am I missing?  Have I got the wrong nmake tool?  I tried specifying export=myfilelist.txt but get the same fatal error.

0 Kudos
1 Solution
RahulV_intel
Moderator
2,959 Views

Hi,

 

As per the error logs, it looks like your current directory does not contain any Makefile to build the target.

 

The Intel MKL custom DLL builder enables you to create a dynamic library containing the selected functions and located in the tools\builder directory.

 

MKL builder directory(Parallel studio installation):

C:\Program Files(x86)\IntelSWTools\compilers_and_libraries\ windows\mkl\tools\builder

 

MKL builder directory(oneAPI base toolkit installation):

C:\Program Files (x86)\Intel\oneAPI\mkl\latest\tools\builder

 

Steps:

  • Open command prompt (as an Administrator)
  • Source "vcvarsall.bat x86"
  • cd C:\Program Files(x86)\IntelSWTools\compilers_and_libraries\ windows\mkl\tools\builder
  • nmake ia32

 

This command creates the mkl_custom.dll and mkl_custom.lib libraries with the CDECL interface for processors using the IA-32 architecture in the current directory.

 

For other build options, please refer to the Developer Guide:

https://software.intel.com/content/www/us/en/develop/documentation/onemkl-windows-developer-guide/top/linking-your-application-with-the-intel-math-kernel-library/building-custom-dynamic-link-libraries/using-the-custom-dynamic-link-library-builder-in-the-command-line-mode.html

 

PFA screenshot below:

RahulV_intel_0-1608188246001.png

 

Regards,

Rahul

View solution in original post

10 Replies
RahulV_intel
Moderator
2,960 Views

Hi,

 

As per the error logs, it looks like your current directory does not contain any Makefile to build the target.

 

The Intel MKL custom DLL builder enables you to create a dynamic library containing the selected functions and located in the tools\builder directory.

 

MKL builder directory(Parallel studio installation):

C:\Program Files(x86)\IntelSWTools\compilers_and_libraries\ windows\mkl\tools\builder

 

MKL builder directory(oneAPI base toolkit installation):

C:\Program Files (x86)\Intel\oneAPI\mkl\latest\tools\builder

 

Steps:

  • Open command prompt (as an Administrator)
  • Source "vcvarsall.bat x86"
  • cd C:\Program Files(x86)\IntelSWTools\compilers_and_libraries\ windows\mkl\tools\builder
  • nmake ia32

 

This command creates the mkl_custom.dll and mkl_custom.lib libraries with the CDECL interface for processors using the IA-32 architecture in the current directory.

 

For other build options, please refer to the Developer Guide:

https://software.intel.com/content/www/us/en/develop/documentation/onemkl-windows-developer-guide/top/linking-your-application-with-the-intel-math-kernel-library/building-custom-dynamic-link-libraries/using-the-custom-dynamic-link-library-builder-in-the-command-line-mode.html

 

PFA screenshot below:

RahulV_intel_0-1608188246001.png

 

Regards,

Rahul

Brian_Murphy
New Contributor II
2,949 Views

Thank you very much, Rahul.  When I followed your steps it worked great.

Note: the command prompt window needs administrator privilege because folders in C:\Program Files (x86) have restricted access.

0 Kudos
RahulV_intel
Moderator
2,928 Views

Great! Thanks for the confirmation. Intel will no longer monitor this thread. Further responses on this thread will be considered community only.


--Rahul


0 Kudos
mecej4
Honored Contributor III
2,912 Views

The procedure given in the Intel documentation for building a custom library/DLL pair works fine when they are to be used with C/C++ code. For using with Fortran code, some adaptation is necessary. 

A second issue to overcome is that users are often not given write permission in the default directories where MKL is installed, and it is also risky to use those directories with elevated privileges.

Here is what I put together in my first attempt at building a custom MKL LIB/DLL when the list of exported names includes entry points from LAPACK95 and BLAS95.

-----------------------------------------------------------------------------------------------

Creating a custom library for LP64 from the MKL distribution
------------------------------------------------------------
1. From an Intel Fortran command window, create/choose a working directory and change to it
2. Create a LIB subdirectory
3. Copy the two small *.lib files from the MKL tools\builder\lib directory into the LIB subdirectory
4. Copy the makefile and mkl_custom_vers.res files to the working directory from the MKL tools\builder directory
5. Prepare a text file, subs.txt, containing the symbols to be exported by the custom DLL being built:

Example of contents of subs.txt (8 lines)
----------
DGEMM_F95
DGEMV_F95
DGESVX_F95
DGGEVX_F95
DGGEVX1_F95
DGELS_F95
DGETRF_F95
DGETRI_F95
----------

6. set LINK=mkl_lapack95_lp64.lib mkl_blas95_lp64.lib libifcoremd.lib
7. Issue the command

nmake libintel64 interface=lp64 threading=sequential cluster=no export=subs.txt

8. If all goes well, the new LIB/DLL pair, mkl_custom.lib and mkl_custom.dll, will have been created
9. Test the new library/DLL by building/running your Fortran code using the custom library instead of the Intel supplied MKL libraries and DLLs

0 Kudos
Brian_Murphy
New Contributor II
2,902 Views

Thank you for the recipe, mecej4.  When I did it, a file was created named user_def_file.def, and a folder was created named temp_cdll.  However, I got an error that a .lib file could not be found.  I tried running vcvarsall.bat x64, but still got the same error about the missing lib file.  Rahul's recipe also generates a similar error when done in this folder.

The missing file is on my system at C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.2.254\windows\mkl\lib\intel64\mkl_lapack95_lp64.lib

C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Xlrotor\MKL DLL>set LINK=mkl_lapack95_lp64.lib mkl_blas95_lp64.lib libifcoremd.lib

C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Xlrotor\MKL DLL>nmake libintel64 interface=lp64 threading=sequential cluster=no export=subs.txt

Microsoft (R) Program Maintenance Utility Version 14.27.29112.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        set Lib=..\..\lib\intel64;%Lib%;..\..\..\compiler\lib\intel64
        type "subs.txt" | findstr /V "^[;#]" >> user_def_file.def
        lib .\lib\mkl_cdll_intel64.lib /EXTRACT:"i_malloc_dll_static.obj" /OUT:".\temp_cdll\i_malloc_dll_static.obj"
Microsoft (R) Library Manager Version 14.27.29112.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        lib .\lib\mkl_cdll_intel64.lib /EXTRACT:_vml_dll_core.obj /OUT:.\temp_cdll\_vml_dll_core.obj
Microsoft (R) Library Manager Version 14.27.29112.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        link /DLL /MANIFEST /MACHINE:AMD64 /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libmmt.lib /NODEFAULTLIB:libirc.lib /NODEFAULTLIB:svml_dispmt.lib /NODEFAULTLIB:libdecimal.lib /def:user_def_file.def  .\temp_cdll\i_malloc_dll_static.obj .\temp_cdll\_vml_dll_core.obj      mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib    mkl_custom_vers.res  libcmt.lib  kernel32.lib user32.lib /out:mkl_custom.dll
Microsoft (R) Incremental Linker Version 14.27.29112.0
Copyright (C) Microsoft Corporation.  All rights reserved.

mkl_lapack95_lp64.lib mkl_blas95_lp64.lib libifcoremd.lib
LINK : fatal error LNK1181: cannot open input file 'mkl_lapack95_lp64.lib'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\link.EXE"' : return code '0x49d'
Stop.

 

0 Kudos
mecej4
Honored Contributor III
2,884 Views

In Step 1 of the recipe that I gave, you are asked to open an Intel Fortran command window for X64 development. You used vcvarsall.bat, which is not enough -- that is for C/C++ development only. 

There is a similar ifortvars.bat that is installed with Intel Parallel Studio, which is what you should have been using. A shortcut to that batch file is also installed as a Start Menu shortcut. You could use either of them.

0 Kudos
Brian_Murphy
New Contributor II
2,853 Views

Thank you, mecej4, for the extra instructions.  Following your lead, I have achieved a good measure of success both building and utilizing a 32 bit build of myMKL.DLL!  See below for my next hurdle.

I created the following two batch files to build a 32 bit version. 

The first opens a command prompt window and does a cd to stay in the folder from which it is run.  The cmd.exe command came from the Start menu shortcut.  I named this file cmd32.bat

C:\Windows\System32\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.2.254\windows\bin\ipsxe-comp-vars.bat" ia32 vs2019"
cd %CD%

 The second bat file does the 32 bit build.  I run this bat file in the command prompt window.  I named this build32.bat

nmake libia32 interface=cdecl threading=sequential cluster=no export=subs.txt name=myMKL

The 64 bit versions are, which build myMKL_x64.DLL

C:\Windows\System32\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.2.254\windows\bin\ipsxe-comp-vars.bat" intel64 vs2019"
cd %CD%
nmake libintel64 interface=lp64 threading=sequential cluster=no export=subs.txt name=myMKL_x64

 I just noticed that the above don't do the Set LINK= commands, but they still work.

My next hurdle;  I would like to statically link myMKL.lib into my program to eliminate the DLL dependency.  Do you know how do this?  I looked through the makefile for ideas, but couldn't find any.

0 Kudos
mecej4
Honored Contributor III
2,848 Views

If your custom DLL is not required to export Lapack95 or BLAS95 entry points, the SET LINK=... is not needed.

I am puzzled by your "next hurdle". I think that it is a bad idea to link with static libraries. That is what we used to do in 16 bit MSDOS. If you do so today, even a ten line MKL program may result in a 100 MB EXE file, whereas using a DLL library would have given a 10 kB EXE. If you are determined to do so, it is easy to do and make more trouble for yourself and everyone else. Just read the MS documentation on LIB, LINK, NMAKE, etc.

With most recent versions of MKL and Intel Fortran, it may even be impossible to remove all dependence on DLLs -- if you use OpenMP, there will be a dependence on libiomp5md.dll.

Perhaps you should spend a little time to think about issues and describe what your broad purpose is.

0 Kudos
Brian_Murphy
New Contributor II
2,834 Views

One issue is an end user won't have admin rights to install either my program or Intel libraries.  Also, I was expecting my custom DLL to be much smaller than the collection of dependent MKL library files, but as you pointed out it is not (as you know, 19.1 files are enormous compared to 13.0).  Bummer.  I also have an issue with MKL 19.1 versus 13.0.  As you suggested, I need to consider all factors and decide on a best approach.

0 Kudos
Brian_Murphy
New Contributor II
1,188 Views

Does anyone know how to modify the following two commands to work for Visual Studio 2022 and IVF 2023.2?  ipsxe-comp-vars.bat is not among the files installed with IVF 2023.2.

C:\Windows\System32\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.2.254\windows\bin\ipsxe-comp-vars.bat" intel64 vs2019"

nmake libintel64 interface=lp64 threading=sequential cluster=no export=subs.txt name=myMKL_x64

 

0 Kudos
Reply