Jump to content

Problem to interface DLL with the new DPC++ intel compiler


Recommended Posts

Hi Everybody,

 

Intel recently released a DPC++ (data parallel c++) compiler that optimizes speeds for Intel CPUs and GPUs.

My problem is that when I compile the functions with the normal Intel 2022 compiler (or the classic Visual Studio compiler) there is no problem and when I use the new intel DPC++ compiler LabVIEW returns an error.

Both Intel compilers work perfectly in C and C++ under visual studio. For the exemple, i made a simple function that just multiplies an int32 by 3 and returns the result as an example.

 

The DPC++ compiler is only under the X64 architecture and I use LabVIEW 2020.

 I made a video to show the problem

 

 

 

File here: https://we.tl/t-9Iwkf1IGvr you can compile by yourself and see the problem. I added all Visual studio 2022 + Intel Compiler + Intel DPC++ compiler installers in the "install" repository.

(on visual studio alt-F7 to go directly to the parameter and change the compiler - F5 to compile)

 

Is someone can tell me what's wrong ?

how I can make my DLL work with the DPC++ compiler?

 

Edited by Youssef Menjour
Link to comment

Did you try Release build also? I noticed, that you're exporting Mult function without explicit specification of the calling convention. By default Visual Studio exports in cdecl convention. But in LabVIEW you set stdcall convention. Likely it's not the reason for errors though.

  • Like 1
Link to comment
7 minutes ago, dadreamer said:

Did you try Release build also? I noticed, that you're exporting Mult function without explicit specification of the calling convention. By default Visual Studio exports in cdecl convention. But in LabVIEW you set stdcall convention. Likely it's not the reason for errors though.

 😱 😱 😱 😱 😱

Where can i specify the calling convention !!! (really sorry for the question)

 

Link to comment
12 minutes ago, Youssef Menjour said:

Where can i specify the calling convention !!! (really sorry for the question)

For MSVS - on the left of the function name, for LabVIEW - in the CLFN settings.

extern "C" __declspec(dllexport) int __stdcall Mult(int a)
{
  // will be exported with stdcall convention
}

 

Edited by dadreamer
  • Like 1
Link to comment
3 minutes ago, dadreamer said:

For MSVS - on the left of the function name, for LabVIEW - in the CLFN settings.

extern "C" __declspec(dllexport) int __stdcall Mult(int a)
{
  // will be exported with stdcall convention
}

Thank you for the information but unfortunatelly does not solve my problem

 

Regarding the release build, I haven't tried it because I didn't understand the difference and how to make it work. Could you be more explicit?
"this Shareable board exclusively owned." is very strange

Link to comment
10 minutes ago, Youssef Menjour said:

Regarding the release build, I haven't tried it because I didn't understand the difference and how to make it work. Could you be more explicit?

Just switch to Release option on the MSVS toolbar. As to the differences, you may read about them e.g. here . To add to there, debug builds depend on the debug version of Visual Studio Runtime libraries, whereas release builds depend on common MSVCRT DLLs, that are very likely already installed in the system. Hence if you compile debug app or library and deploy it to machines without Visual Studio installed, it will ask you for the debug DLLs or even the whole Visual Studio to be installed. Release app/DLL on the other hand usually requires Visual C++ Redistributable Runtime only.

  • Like 1
Link to comment

 

8 minutes ago, dadreamer said:

Just switch to Release option on the MSVS toolbar. As to the differences, you may read about them e.g. here . To add to there, debug builds depend on the debug version of Visual Studio Runtime libraries, whereas release builds depend on common MSVCRT DLLs, that are very likely already installed in the system. Hence if you compile debug app or library and deploy it to machines without Visual Studio installed, it will ask you for the debug DLLs or even the whole Visual Studio to be installed. Release app/DLL on the other hand usually requires Visual C++ Redistributable Runtime only.

Thanks a lot ! Unfortunattely it doesn't solve the problem.

This issu is very strange ! 

Link to comment
13 hours ago, dadreamer said:

Maybe the reason is that LabVIEW cannot find some DPC++ Runtime library during the DLL load process (sycl.dll for instance or another one). Could you check with Dependency Walker, which libraries are in dependencies of your DLL?

 

It seems that you are right (which reassures me because your reasoning is logical)

Here is the screenshot of the "dependency walker"

are there routines to integrate into my code in order to remove these objections?

Error: At least one required implicit or forwarded dependency was not found.
Warning: At least one delay-load dependency module was not found.

 

1880850499_dependancywlaker.PNG.8ee31c57ff4854c0e3ee770270c1d865.PNG

 

As a reminder

 

Header.h

///////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifdef DPCPP_DLL_EXPORTS
#define DPCPP_DLL_API __declspec(dllexport)
#else
#define DPCPP_DLL_API __declspec(dllimport)
#endif


extern "C"  __declspec(dllexport) DPCPP_DLL_API int __stdcall  Mult(int a);

///////////////////////////////////////////////////////////////////////////////////////////////////////////

dllmain.cpp

///////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "pch.h"
#include "Header.h"

__declspec(dllexport) int Mult(int a)
{
     return a * 3;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

dllmain.cpp Header.h

Link to comment

 I have the same problem (LabVIEW error 13) when I use a function from the MKL library (math kernel library)

There must be a file dependency issue that is not loaded in the DLL runtime.

The question now to solve the problem is: How to add its dependencies properly.

🤔  Another question comes to mind:

Logically as it stands, my DLLs should not work if I call them with C code (this is normally independent of LabVIEW) --> I will check (need to find how to call DLL in c code)

If this is the case then our solution is to include all runtime dependencies (which is of course possible - you just have to know how to do it)

One thing is sure, I will have learned a lot!

Link to comment
3 hours ago, Youssef Menjour said:

are there routines to integrate into my code in order to remove these objections?

In fact your app requires the libraries on the very first level shown in Dependency Walker. The others are needed too, but they are being loaded by their "parent" DLLs, so you don't need to worry about them. Could you collapse that DLL list on the left of the DW, so we could see the first level libraries except sycl.dll and kernel32.dll? Don't look at those red warnings as they are about not finding some libraries, which likely are loaded during the runtime or have delayed loading or could even be absent in the system (as some .NET assemblies) and the app is able to run fine without them. So if only sycl is necessary, then you could either provide the path to it in your PATH environment variable or try to put it near your own DLL and check, whether LabVIEW loads it all without errors.

  • Like 1
Link to comment

Maybe completely unrelated, but I had a similar issue some time ago. I had some software which just did not run on a certain PC, it gave some weird error message. The error was actually in the LabVIEW "Mean.vi" which is part of the advanced analysis libraries.

See this thread for my post.

To cut a long story short, I had to add a setting to my PC environment variables. Doing so allowed the Math Kernel libraries to work with my CPU. Something similar to this

MKL_DEBUG_CPU_TYPE=4

image.png.3ef39daa70921d9e2090dfdba30ecde8.png

Edited by Neil Pate
  • Like 1
Link to comment
21 hours ago, dadreamer said:

In fact your app requires the libraries on the very first level shown in Dependency Walker. The others are needed too, but they are being loaded by their "parent" DLLs, so you don't need to worry about them. Could you collapse that DLL list on the left of the DW, so we could see the first level libraries except sycl.dll and kernel32.dll? Don't look at those red warnings as they are about not finding some libraries, which likely are loaded during the runtime or have delayed loading or could even be absent in the system (as some .NET assemblies) and the app is able to run fine without them. So if only sycl is necessary, then you could either provide the path to it in your PATH environment variable or try to put it near your own DLL and check, whether LabVIEW loads it all without errors.

It works !!!  💪 SOLVED

image.png.2213b66851a12f68610a52e41152950c.png 

 

I put sycl.dll at the same place of my called DLL and no error LabVIEW well worked !!!

Dadreamer many thanks !!!!!!! 💪 SOLVED

18 hours ago, Neil Pate said:

Maybe completely unrelated, but I had a similar issue some time ago. I had some software which just did not run on a certain PC, it gave some weird error message. The error was actually in the LabVIEW "Mean.vi" which is part of the advanced analysis libraries.

See this thread for my post.

To cut a long story short, I had to add a setting to my PC environment variables. Doing so allowed the Math Kernel libraries to work with my CPU. Something similar to this

MKL_DEBUG_CPU_TYPE=4

image.png.3ef39daa70921d9e2090dfdba30ecde8.png

Ok let's now try to solve this one now !! 

 

Link to comment
On 6/3/2022 at 4:24 PM, Neil Pate said:

Maybe completely unrelated, but I had a similar issue some time ago. I had some software which just did not run on a certain PC, it gave some weird error message. The error was actually in the LabVIEW "Mean.vi" which is part of the advanced analysis libraries.

See this thread for my post.

To cut a long story short, I had to add a setting to my PC environment variables. Doing so allowed the Math Kernel libraries to work with my CPU. Something similar to this

MKL_DEBUG_CPU_TYPE=4

image.png.3ef39daa70921d9e2090dfdba30ecde8.png

Thank you for your help but I'm not sure thats the good way to solve this problem because if i well understood, you propose to make modification on my configuration machine to make the VI well working.

It's not user friendly if i want to use MKL inside an exported library.(Or have to script it to automatize the installation)

By the way i looked also about the dependancy 

image.png.6b84aa61e0302dcd601048b7861eac23.png

I found MKL_intel_THREAD.2.DLL (C:\Program Files (x86)\Intel\oneAPI\mkl\2022.1.0\redist\intel64)unfortunaelly moving this DLL doesn't worked. (Well tried !)

 

image.png.635650f5cea32d1f0b834ccc64f98e9a.png

 

--> i suppose MKL_intel_THREAD.2.DLL is calling other DLL so i have to scan this one to know dependany etc etc ... --> maybe a better way to solve this one (edit : done uper image 🤠 --> tried and failed)

image.png.dc0cea3cc2dd08e0c71f45052d597155.png

 

 

Is it possible to script  PATH environment variable modification to make it more acceptable ? (I already have the answers - It's yes, but my actual knowledge on this subject are low)

We can inspire from  DNNL library (another library inside the intel package) -  Intel propose a script to fix environnent variable but when i launch it on my cmd console seems does not work.

I suppose i make it bad.

 

vars.bat

Edited by Youssef Menjour
Link to comment

My assumption is that if you already have MKL Runtime installed (I see that it is so), then your PATH environment variable should contain full path to the \bin\ directory of the MKL parent directory (as stated in mklvars_intel64.bat or mklvars.bat). But I have never compiled DLLs with MKL linking, so you better to ask on some C/C++ forums or stackoverflow or experiment with it on your own.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.