0

I read that certain c++ dll can auto - offload to Xeon Phi even if they weren't made specifically to use manycore..

My question - can I Interop a c++ dll built say using Intel parallel studio from c# ? Hoping it will auto-offload

Boppity Bop
  • 9,613
  • 13
  • 72
  • 151
  • What do you mean by "even if they weren't made specifically to use manycore"? There are DLLs, which can perform automatic offload to Xeon Phi, e.g. Intel MKL. And likely, these libraries can be linked with either C++ and C#. – Ilya Verbin Dec 05 '14 at 17:34
  • Intel studio and some open source compilers can compile C++ specifically to run on Phi (using pragmas for instance).. so i was asking if a ddl built without explicit Phi support can be used from C#. HTH – Boppity Bop Dec 11 '14 at 12:42
  • When a compiler compiles c++ files, it identifies pieces of code, which can be offloaded, then it wraps these code into some calls to runtime library. There is no difference whether they are marked by pragmas, or detected automatically by the compiler, the final binary (exec or dll) will be the same. However, at the moment there are no compilers, which can perform such auto-offload. – Ilya Verbin Dec 12 '14 at 19:02
  • https://software.intel.com/en-us/articles/intel-mkl-automatic-offload-enabled-functions-for-intel-xeon-phi-coprocessors – Boppity Bop Dec 15 '14 at 07:41
  • In this article "Automatic Offload enabled functions" means that one can call a function from a library, without using any offload pragmas. But the function from library itself contains some pragmas or some calls to runtime, to perform actual offloading. – Ilya Verbin Dec 15 '14 at 16:03
  • Ok.. reading further: `The offloading of computations is transparent to the user in the sense that the Intel MKL runtime decides how much work to offload. Depending on the problem size and the current status of coprocessor(s), the library may choose to run all the computational work, part of it, or none of it on coprocessor(s). Likewise, the library may decide to use all of the coprocessors available or to use only one coprocessor.` – Boppity Bop Dec 15 '14 at 22:32
  • The pragmas I know about dont do that - `the library may choose` - it marks a statement or a function to run on Phi.. so either you are wrong or there are some other 'magic' pragmas which can do dynamic auto offload.. However I propose a compromise - you put your very first comment as an answer and we call it a day! :) [cos i am not even sure what are we arguing about anymore :)] – Boppity Bop Dec 15 '14 at 22:35
  • 1
    "the library may choose" means that the developers who wrote the MKL library have written code containing heuristics to determine the best approach and then call either offloading or non-offloading versions of the routines based on that decision. It is referred to as automatic offloading because the "offloading of computations is transparent to the user". You are correct in saying that there are no 'magic' pragmas that can dynamically choose. The decision is made in code that was written specifically for that library and took a great deal of effort on the part of the developers. – froth Dec 16 '14 at 00:36

2 Answers2

2

I am also confused by your statement about dlls being able to auto-offload to the Intel Xeon Phi coprocessor "even if they weren't made specifically to use manycore". To auto-offload, the library must contain code which uses offload directives and is compiled with a compiler that recognizes the offload directives. By default, offload directives result in the compiler generating both processor and coprocessor executable code.

As to how to build a dynamic library containing offload code, let me quote from a reply Kevin Davis posted on the software.intel.com:

For the Dynamic library, all source files containing Language Extensions for Offload must be compiled with the -fPIC compiler option. You add this option under the IDE under the property setting: Configuration Properties > C/C++ > Code Generation [Intel C++] > Additional Options for MIC Offload Compiler .... When using the icl command-line, each source file from the Dynamic library that contains offload code must be compiled using the /Qoffload-option to pass the -fPIC option.

There is a limitation in that you cannot use _Cilk_offload directives in a dll but I think that is the only limitation.

As to calling a library containing offload directive from C#,there is a problem in the Intel® Parallel Studio XE 2015 which is fixed in Update 1. But other than that one version of the compiler, you should be able to call dynamic libraries containing offload directives.

froth
  • 319
  • 1
  • 6
1

There are DLLs, which can perform automatic offload to Intel Xeon Phi, e.g. Intel MKL. These libraries can be linked with either C++ and C# (see froth's answer).

Automatic offload in this context means that a library contains a code, which allows to offload its computations, transparent to the user.

Also, a library may contain some code, which would decide whether to run the computation on CPU or coprocessor(s).

Ilya Verbin
  • 647
  • 5
  • 20