Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and GDB*

Code with SYCL and Pybind not compiling.

Nikhil_T
Novice
1,629 Views

Hi there!

 

I am trying to compile a DCP++ code with pybind. The code seems to get stuck while compiling  and generates the following warnings in the output window.:

 

CODE-----------------------------------------------------------------------------------------------------

#include <CL/sycl.hpp>
#include <vector>
#include <oneapi/mkl.hpp>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/numpy.h>

PYBIND11_MAKE_OPAQUE(std::vector<double>);
PYBIND11_MAKE_OPAQUE(std::vector<int>);

using namespace sycl;
using namespace oneapi::mkl::sparse;
namespace py = pybind11;

struct csr_matrix_elements
{
    std::vector<int> row;
    std::vector<int>col;
    std::vector<double> values;  
    matrix_handle_t matrix_handle;
    int size;
};

csr_matrix_elements create_sparse_matrix_handle(py::array_t<int>& row, py::array_t<int>& col, py::array_t<double>& vals, int& size) {

//copy the py vectors to std::vectors
std::vector<int> row_vec(row.size());
std::vector<int> col_vec(col.size());
std::vector<double> vals_vec(vals.size());
std::memcpy(row_vec.data(), row.data(), row.size() * sizeof(int));
std::memcpy(col_vec.data(), col.data(), col.size() * sizeof(int));
std::memcpy(vals_vec.data(), vals.data(), vals.size() * sizeof(double));

// Create a matrix entity
csr_matrix_elements matrix;
matrix.row = row_vec;
matrix.col = col_vec;
matrix.values = vals_vec;
matrix.size = size;
init_matrix_handle(&matrix.matrix_handle);
set_csr_data(matrix.matrix_handle, matrix.size, matrix.size, oneapi::mkl::index_base::zero, matrix.row.data(),
matrix.col.data(), matrix.values.data());
return matrix;
}

py::array_t<double> jacobirelaxation(csr_matrix_elements &D_inv , csr_matrix_elements &R_omega , py::array_t<double>& b) {

std::vector<double> b_vec(b.size());
std::memcpy(b_vec.data(), b.data(), b.size() * sizeof(double));
cl::sycl::queue q;
const float omega = 4.0 / 5.0;
std::vector<double> ans(D_inv.size, 0.0);
std::vector<double> prod_1(D_inv.size, 0.0);
std::vector<double> prod_2(D_inv.size, 0.0);

cl::sycl::event R_V_mul_done = cl::sycl::event();
cl::sycl::event D_inv_F_done = cl::sycl::event(); // Replace it by a vector to vector multiplication
cl::sycl::event add_done = cl::sycl::event();

for (int i = 0; i < 10; i++) {
R_V_mul_done = gemv(q, oneapi::mkl::transpose::nontrans, 1.0, R_omega.matrix_handle,
ans.data(), 0.0, prod_1.data());
D_inv_F_done = gemv(q, oneapi::mkl::transpose::nontrans, omega, D_inv.matrix_handle,
b_vec.data(), 0.0, prod_2.data());
add_done = oneapi::mkl::vm::add(q, D_inv.size, prod_1.data(), prod_2.data(), ans.data(),
{ R_V_mul_done , D_inv_F_done });
}
// cast the result back to numpy array
auto result = py::array_t<double>(ans.size());
auto result_buffer = result.request();
double* result_ptr = (double*)result_buffer.ptr;
std::memcpy(result_ptr, ans.data(), ans.size() * sizeof(double));
return result;
}

PYBIND11_MODULE(smoother_sycl, m) {
py::class_<csr_matrix_elements>(m, "csr_martix_elements")
.def(py::init<>());
m.def("smoother_jacobi", &jacobirelaxation);
m.def("create_csr_matrix", &create_sparse_matrix_handle);
//py::bind_vector<std::vector>
}

 

CODE ENDS-----------------------------------------------------------------------------------------------

 

Build started...
1>------ Build started: Project: Smoother_test_pybind, Configuration: Debug x64 ------
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(245,22): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> auto t = strdup(s);
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(488,61): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> func->m_ml->ml_doc = signatures.empty() ? nullptr : strdup(signatures.c_str());
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^
1>2 warnings generated.
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(245,22): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> auto t = strdup(s);
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(488,61): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> func->m_ml->ml_doc = signatures.empty() ? nullptr : strdup(signatures.c_str());
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^
1>2 warnings generated.
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(245,22): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> auto t = strdup(s);
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^
1>In file included from Source.cpp:4:
1>C:\\Users\\nikhi\\AppData\\Local\\Programs\\Python\\Python37\\include\pybind11/pybind11.h(488,61): : warning : 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
1> func->m_ml->ml_doc = signatures.empty() ? nullptr : strdup(signatures.c_str());
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\string.h(535,20): note: 'strdup' has been explicitly marked deprecated here
1> _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
1> ^
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h(335,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
1> #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
1> ^
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
1>#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
1> ^

 

 

 

Can anyone help me with some sort of solution as to why is this happening. I have linked the necessary folders of pybind and python and have followed the procedure as mentioned on Visual Studio Website.

0 Kudos
18 Replies
VidyalathaB_Intel
Moderator
1,593 Views

Hi Nikhil,

Thanks for reaching out to us.

>> The code seems to get stuck while compiling and generates the following warnings

We tried to reproduce the issue from our end with the code which you have provided but we didn't get any such deprecated warnings 

we tried it with latest intel oneAPI Base Toolkit version 2021.2.0 and Microsoft Visual Studio 2019

Version 16.9.0

To configure the project, please follow below mentioned configurations

> Enable the oneMKL library under ----> configuration properties >> Intel Libraries for oneAPI 

> Provide the path of pybind11 & python header files under ----> configuration properties >> VC++ Directories >> Include Directories

And the path for python library files under ----> configuration properties >> Linker >> General >> Additional library Directories

Kindly refer the attached project file for further clarifications.

Regards,

Vidya.

Nikhil_T
Novice
1,585 Views

Thank you for your reply. I will check and get back to you. 

Nikhil_T
Novice
1,575 Views

@VidyalathaB_Intel 

 

I am using oneapi 2021.1.0. Is there a way to update oneapi directly rather than reinstalling it again?

 

I am supposing using the old version might be the issue.

VidyalathaB_Intel
Moderator
1,552 Views

Hi Nikhil,

>> Is there a way to update oneAPI directly rather than reinstalling it again?

Yes, you can update oneAPI directly.

Go to the directory where oneAPI is installed and check for installer from there you can update to the latest version of oneAPI

Eg: Path: C:\Program Files (x86)\Intel\oneAPI\Installer

After opening installer, by clicking on installer.exe you will find an option to update so that you can directly update to the latest version.

Please try this and let us know if the issue still persists.

Thanks & Regards,

Vidya.


Nikhil_T
Novice
1,538 Views

@VidyalathaB_Intel 

I am having issues with using oneMKL I guess and not pybind11. I tried running a simple oneMKL code and included oneMKL by setting the use mkl to parallel in properties.  The following thing happens everytime:


Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in TestingOneMkl-272333.obj TestingOneMkl D:\Camb research\Multigrid Code\TEMP\TestingOneMkl\mkl_tbb_thread.lib(vml_tbb_threading_templates.obj) : 1

 

and the one as :

Severity Code Description Project File Line Suppression State
Error linker command failed with exit code 1319 (use -v to see invocation) TestingOneMkl D:\Camb research\Multigrid Code\TEMP\TestingOneMkl\dpcpp: 1

 

I have set use MKL to Parallel mode. and rest settings as default. I am now using oneapi 2021.2.0 and VS 2019. Still getting the errors 

Nikhil_T
Novice
1,524 Views

@VidyalathaB_Intel 

 

I tried using the settings as there in the file. I am getting the following errors and warnings:

1) Severity Code Description Project File Line Suppression State
Error LNK1561 entry point must be defined Smoother_test_pybind D:\Camb research\Multigrid Code\SYCL_PYBIND\Smoother_test_pybind\LINK : 1

2) Severity Code Description Project File Line Suppression State
Error linker command failed with exit code 1561 (use -v to see invocation) Smoother_test_pybind D:\Camb research\Multigrid Code\SYCL_PYBIND\Smoother_test_pybind\dpcpp: 1. 

These are in the release mode.

 

In Debug mode:

 

Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Source-a42757.obj Smoother_test_pybind D:\Camb research\Multigrid Code\SYCL_PYBIND\Smoother_test_pybind\mkl_sycl.lib(init_matrix_handle_r_s_i8_sycl_usm.obj) : 1

 

and multiple warnings like those. Also please note that I am trying to build a .pyd file so that I can import it in python.

VidyalathaB_Intel
Moderator
1,504 Views

Hi Nikhil,


>> 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug'


Could you please try the following configurations


Configuration properties ---->> DPC++ ---->> Code Generation ---->> Runtime Library ---->> select "Multi-threaded DLL (/MD)"


>> entry point must be defined Smoother_test_pybind 


You will get this error if main function is missing in your code. so try adding main() function to the source code.


Please try this and let us know if the issue still persists.


Regards,

Vidya.  



Nikhil_T
Novice
1,495 Views

@VidyalathaB_Intel 

 

I tried compiling this simple code with one function and no main function. It was compiling without any errors and I was able to import the package (.pyd file) in python and perform the necessary things. am I missing any thing in the code mentioned in the original doubt? 

 

#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <vector>
#include <iostream>
#include <unordered_map>

namespace py = pybind11;

std::vector<int> check_numpy(py::array_t<int>& py_array) {
std::vector<int> temp_vec(py_array.data(), py_array.data() + py_array.size());
return temp_vec;
}
PYBIND11_MODULE(SYCL, m) {
m.def("push", &check_numpy);
py::bind_vector<std::vector<int>>(m, "IntVec");
//py::implicitly_convertible<py::list, std::vector<int>>();
}

 

I forgot to mention that in the original code, I am building a  DPC++ dll project with the settings mentioned on the microsoft webpage about linking the VS2019 with pybind11. Could you send me the settings that you mentioned worked for you while compiling the code @VidyalathaB_Intel ? thank you.

Nikhil_T
Novice
1,442 Views

@VidyalathaB_Intel 

 

Apparently, it seems like when I am building a normal C++ project, with the same settings, i am able to build it and use the .pyd file. But when I am building a DPC++ application (in order to use SYCL and oneMKL), it is giving the error as 

Severity Code Description Project File Line Suppression State
Error LNK1561 entry point must be defined.

 

Could you provide me with the settings that can allow me to build the code mentioned in the original message? 

VidyalathaB_Intel
Moderator
1,429 Views

Hi Nikhil,

>> Error LNK1561 entry point must be defined.

You need to change the configuration type to .dll in visual studio configuration properties.

Configuration properties >> General >> configuration type >> select Dynamic Library (.dll)

This helps to build your project successfully without any such errors.

Because when building DLLs in Visual Studio, it automatically links the default entry point (_DllMainCRTStartup) which is supplied by VCRuntime. 

Please note that dynamic-link library (DLL) acts as a shared library of functions and resources.

If you want to create an executable file for your code you need to change the configuration type to .exe then you will get the above mentioned error 

for which we have suggested you to add main function to your source code.

Thanks & regards,

Vidya.



Nikhil_T
Novice
1,404 Views

@VidyalathaB_Intel 

 

I am using the settings to build a dll only. Still I am getting the same errors. Below are the screenshots of the settings for the same. I have attached it in a form of zip file.

VidyalathaB_Intel
Moderator
1,356 Views

Hi Nikhil,

Thanks for sharing the screenshots.

We are looking into this issue internally. we will get back to you soon.

Thanks & Regards,

Vidya.


Subarnarek_G_Intel
1,339 Views

Hi Nikhil,

I am not sure whether this feature is enabled for DPC++. I will check with the Engineering and if it is not enabled I would talk with the teams of the chances of implementing this feature.


Regards,

Subarna


Nikhil_T
Novice
1,316 Views

Which feature are you asking about here? Is it linking pybind with DPC++?

Also, its a research project where I am trying to build a solver that also has a python interface. And hence, I am generating a python module for it. 

 

Subarnarek_G_Intel
1,336 Views

It would be great if you can mention the motivation behind trying this experiment? Also let me know if https://intelpython.github.io/dpctl/latest/index.html helps.


Subarnarek_G_Intel
1,257 Views

Thanks Nikhil. Did the document I provided help you in any way?


Subarnarek_G_Intel
1,240 Views

Also I think from the documentation of pybind11 https://pypi.org/project/pybind11/ Supported compilers doesn't include DPC++. Which version of pybind are you using currently?


Subarnarek_G_Intel
1,190 Views

Closing the case as there was no response from the customer.

We will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only


Reply