<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:Access violation error when calling dlls built on MKL from Python using ctypes in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1252269#M30798</link>
    <description>&lt;P&gt;I guess nobody at the mkl forum has no experience to help with this case. You may try to ask this question to the python forum.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.intel.com/t5/Intel-Distribution-for-Python/bd-p/distribution-python" target="_blank"&gt;https://community.intel.com/t5/Intel-Distribution-for-Python/bd-p/distribution-python&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 02 Feb 2021 07:24:21 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2021-02-02T07:24:21Z</dc:date>
    <item>
      <title>Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235257#M30466</link>
      <description>&lt;P&gt;We have some c++ code built on MKL.&amp;nbsp; Recently, we would like to expose the functionality as a dll to Python using ctypes.&lt;/P&gt;
&lt;P&gt;The code on Python side is the following&lt;/P&gt;
&lt;P&gt;####################################################&lt;/P&gt;
&lt;P&gt;conv = ctypes.cdll.LoadLibrary('myconvolutiondll.dll')&lt;/P&gt;
&lt;P&gt;fun = conv.convolution&lt;/P&gt;
&lt;P&gt;fun.argtypes = [ctypes.size_t, ndpointer(ctypes.c_float, flags="C_CONTINGUOUS"), ndpointer(ctypes.c_float, flags="C_CONTINGUOUS"), ]&lt;/P&gt;
&lt;P&gt;input = numpy.arrange(6, dtype = "float32")&lt;/P&gt;
&lt;P&gt;kernel = numpy.arrange(6, dtype = "float32")&lt;/P&gt;
&lt;P&gt;fun(6, input, kernel)&lt;/P&gt;
&lt;P&gt;#########################################################&lt;/P&gt;
&lt;P&gt;When I ran this, I got "access violation reading 0x00000000000000003".&amp;nbsp; The error occurs when I call DftiCreateDescriptor in the c++ code.&lt;/P&gt;
&lt;P&gt;Any thoughts on what might go wrong? Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 17:17:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235257#M30466</guid>
      <dc:creator>hello-world</dc:creator>
      <dc:date>2020-12-08T17:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235531#M30468</link>
      <description>&lt;P&gt;Try the correct spelling of the flag,&amp;nbsp;&lt;SPAN&gt;C_CONTIGUOUS.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If that does not work, I'm afraid that you will have to wait for someone who knows Python to help you. In general, before using a user-built DLL with an interpreted language, it is useful to test the DLL by calling it from a C or Fortran main program.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 08:26:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235531#M30468</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2020-12-09T08:26:05Z</dc:date>
    </item>
    <item>
      <title>Re:Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235574#M30471</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Could you share your minimal reproducer code so that I can give it a try at my end?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Also, kindly specify your OS env, Visual Studio/Parallel Studio version(if applicable).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Dec 2020 10:51:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235574#M30471</guid>
      <dc:creator>RahulV_intel</dc:creator>
      <dc:date>2020-12-09T10:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235608#M30472</link>
      <description>&lt;P&gt;you may also show us how did you build this dll.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 12:41:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235608#M30472</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2020-12-09T12:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235824#M30479</link>
      <description>&lt;P&gt;Thanks Rahul and Gennady.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dlls works by calling from a c++ code. I am using visual studio 2019.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the python code, I did use "C_CONTIGUOUS" in the code. Had a typo while retype the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are four files.&amp;nbsp;&lt;SPAN&gt;myconvolutiondll.h and&amp;nbsp;myconvolutiondll.cpp are the files to create dll. Convolution.h and Convolution.cpp are supporting class for computation. The access violation occurs in the function call DftiCreateDescriptor inside Convolution.cpp. The four files are listed below...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;File 1:&amp;nbsp;&lt;SPAN&gt;myconvolutiondll.h&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;/////////////////////////////////////////////////////////////////////&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#ifdef MYCONVOLUTIONDLL_EXPORTS&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#define MYCONVOLUTIONDLL_API __declspec(dllexport)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#define MYCONVOLUTIONDLL_API __declspec(dllimport)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;extern "C" MYCONVOLUTIONDLL_API size_t&amp;nbsp;convolution(size_t n, float* input, const float* kernel);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;//////////////////////////////////////////////////////////////////////////////////&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;File 2: myconvolutiondll.cpp&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;//////////////////////////////////////////////////////////////////////////////////&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#include "Convolve.h"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;#include "myconvolutiondll.h"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;MYCONVOLUTIONDLL_API size_t&amp;nbsp;convolution(size_t n, float* input, const float* kernel)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;return Convolve::convole(n, input, kernel);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;///////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;File 3: Convolve.h&lt;/P&gt;
&lt;P&gt;//////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;class Convolve&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;public:&lt;/P&gt;
&lt;P&gt;static size_t convolve(size_t n, float* input, const float* kernel);&lt;/P&gt;
&lt;P&gt;};&lt;/P&gt;
&lt;P&gt;////////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;File 4: Convolve.cpp&lt;/P&gt;
&lt;P&gt;//////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;#include "Convolve.h"&lt;/P&gt;
&lt;P&gt;#Include "mkl_dfti.h"&lt;/P&gt;
&lt;P&gt;#include "mkl.h"&lt;/P&gt;
&lt;P&gt;#if defined(_WIN32)&lt;/P&gt;
&lt;P&gt;#ifdef _WIN64&lt;/P&gt;
&lt;P&gt;#pragma comment(lib, "mkl_intel_lp64_dll.lib")&lt;/P&gt;
&lt;P&gt;#else&lt;/P&gt;
&lt;P&gt;#pragma comment(lib, "mkl_intel_c_dll.lib")&lt;/P&gt;
&lt;P&gt;#endif&lt;/P&gt;
&lt;P&gt;#pragma comment(lib, "mkl_intel_thread_dll.lib")&lt;/P&gt;
&lt;P&gt;#pragma comment(lib, "mkl_core_dll.lib")&lt;/P&gt;
&lt;P&gt;#endif&lt;/P&gt;
&lt;P&gt;size_t Convolve::convolve(size_t n, float* input, const float* kernel)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;MKL_LONG status;&lt;/P&gt;
&lt;P&gt;DFTI_DESCRIPTOR_HANDLE my_desc1_handle;&lt;/P&gt;
&lt;P&gt;status = DftiCreateDescriptor(&amp;amp;my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, n); /// This is where access violation is occurred!&lt;/P&gt;
&lt;P&gt;return 0;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 02:28:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235824#M30479</guid>
      <dc:creator>hello-world</dc:creator>
      <dc:date>2020-12-10T02:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235826#M30480</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;SPAN&gt;mecej4. That was a typo. I have to type in the code... I posted the code at the bottom of the thread.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 02:30:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1235826#M30480</guid>
      <dc:creator>hello-world</dc:creator>
      <dc:date>2020-12-10T02:30:40Z</dc:date>
    </item>
    <item>
      <title>Re:Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1252269#M30798</link>
      <description>&lt;P&gt;I guess nobody at the mkl forum has no experience to help with this case. You may try to ask this question to the python forum.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.intel.com/t5/Intel-Distribution-for-Python/bd-p/distribution-python" target="_blank"&gt;https://community.intel.com/t5/Intel-Distribution-for-Python/bd-p/distribution-python&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Feb 2021 07:24:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1252269#M30798</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2021-02-02T07:24:21Z</dc:date>
    </item>
    <item>
      <title>Re:Access violation error when calling dlls built on MKL from Python using ctypes</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1252270#M30799</link>
      <description>&lt;P&gt;The issue is closing and we will no longer respond to this thread&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Feb 2021 07:24:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Access-violation-error-when-calling-dlls-built-on-MKL-from/m-p/1252270#M30799</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2021-02-02T07:24:51Z</dc:date>
    </item>
  </channel>
</rss>

