- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have some c++ code built on MKL. Recently, we would like to expose the functionality as a dll to Python using ctypes.
The code on Python side is the following
####################################################
conv = ctypes.cdll.LoadLibrary('myconvolutiondll.dll')
fun = conv.convolution
fun.argtypes = [ctypes.size_t, ndpointer(ctypes.c_float, flags="C_CONTINGUOUS"), ndpointer(ctypes.c_float, flags="C_CONTINGUOUS"), ]
input = numpy.arrange(6, dtype = "float32")
kernel = numpy.arrange(6, dtype = "float32")
fun(6, input, kernel)
#########################################################
When I ran this, I got "access violation reading 0x00000000000000003". The error occurs when I call DftiCreateDescriptor in the c++ code.
Any thoughts on what might go wrong? Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the correct spelling of the flag, C_CONTIGUOUS.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks mecej4. That was a typo. I have to type in the code... I posted the code at the bottom of the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you share your minimal reproducer code so that I can give it a try at my end?
Also, kindly specify your OS env, Visual Studio/Parallel Studio version(if applicable).
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you may also show us how did you build this dll.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Rahul and Gennady.
The dlls works by calling from a c++ code. I am using visual studio 2019.
In the python code, I did use "C_CONTIGUOUS" in the code. Had a typo while retype the code.
Below are four files. myconvolutiondll.h and 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...
File 1: myconvolutiondll.h
/////////////////////////////////////////////////////////////////////
#ifdef MYCONVOLUTIONDLL_EXPORTS
#define MYCONVOLUTIONDLL_API __declspec(dllexport)
#else
#define MYCONVOLUTIONDLL_API __declspec(dllimport)
#endif
extern "C" MYCONVOLUTIONDLL_API size_t convolution(size_t n, float* input, const float* kernel);
//////////////////////////////////////////////////////////////////////////////////
File 2: myconvolutiondll.cpp
//////////////////////////////////////////////////////////////////////////////////
#include "Convolve.h"
#include "myconvolutiondll.h"
MYCONVOLUTIONDLL_API size_t convolution(size_t n, float* input, const float* kernel)
{
return Convolve::convole(n, input, kernel);
}
///////////////////////////////////////////////////////////////////
File 3: Convolve.h
//////////////////////////////////////////////////////////////////
class Convolve
{
public:
static size_t convolve(size_t n, float* input, const float* kernel);
};
////////////////////////////////////////////////////////////////////
File 4: Convolve.cpp
//////////////////////////////////////////////////////////////////
#include "Convolve.h"
#Include "mkl_dfti.h"
#include "mkl.h"
#if defined(_WIN32)
#ifdef _WIN64
#pragma comment(lib, "mkl_intel_lp64_dll.lib")
#else
#pragma comment(lib, "mkl_intel_c_dll.lib")
#endif
#pragma comment(lib, "mkl_intel_thread_dll.lib")
#pragma comment(lib, "mkl_core_dll.lib")
#endif
size_t Convolve::convolve(size_t n, float* input, const float* kernel)
{
MKL_LONG status;
DFTI_DESCRIPTOR_HANDLE my_desc1_handle;
status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, n); /// This is where access violation is occurred!
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
https://community.intel.com/t5/Intel-Distribution-for-Python/bd-p/distribution-python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The issue is closing and we will no longer respond to this thread
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page