pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.09k stars 2.05k forks source link

failed to compile with intel c++ compiler 18.0 #1411

Open timbad opened 6 years ago

timbad commented 6 years ago

It looks like Intel c++ 18 fails to compile pybind11. I tried to reproduce small example which compiles with Microsoft compiler and GCC but fails to compile with Intel 18 compiler:

#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include <pybind11/common.h>
#include <pybind11/buffer_info.h>

#include <iostream>
#include <vector>

namespace py = pybind11;
using namespace py::literals;

class Matrix {
public:
  Matrix(size_t rows, size_t cols) : m_rows(rows), m_cols(cols) {
    m_data = new float[rows*cols];
  }

  ~Matrix() {
    delete[] m_data;
  }

  float *data() { return m_data; }
  size_t rows() const { return m_rows; }
  size_t cols() const { return m_cols; }
private:
  size_t m_rows, m_cols;
  float *m_data;
};

typedef std::vector<_inittab> inittab_vec_t;

void init_Matrix(py::module &m)
{
  py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
    .def_buffer([](Matrix &m) -> py::buffer_info {
    return py::buffer_info(
      m.data(),                               /* Pointer to buffer */
      sizeof(float),                          /* Size of one scalar */
      py::format_descriptor<float>::format(), /* Python struct-style format descriptor */
      2,                                      /* Number of dimensions */
      { m.rows(), m.cols() },                 /* Buffer dimensions */
      { sizeof(float) * m.cols(),             /* Strides (in bytes) for each index */
      sizeof(float) }
    );
  });
}

int main()
{
  return 0;
}

Compiler options:

/Yu"stdafx.h" /GS /W3 /Gy /Zc:wchar_t /I"D:\ProgramData\Python34_64\include" /I"D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\\include" /Zi /O2 /Fd"x64\Release\vc140.pdb" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Qipo /Zc:forScope /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Qstd=c++17 /Fp"x64\Release\Test1.pch" 

Linker options:

/OUT:"D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\x64\Release\Test1.exe" /MANIFEST /NXCOMPAT /PDB:"D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\x64\Release\Test1.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\Test1.exe.intermediate.manifest" /OPT:ICF /NOLOGO /LIBPATH:"D:\ProgramData\Python34_64\libs" /TLBID:1 

Compiler gives strange errors. For example it seems like compiler expects PYBIND11_DEPRECATED to be function in definition of method object_api:call

D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\\include\pybind11/pytypes.h(110): error : expected a type specifier
      PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\\include\pybind11/pytypes.h(110): error #303: explicit type is missing ("int" assumed)
      PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\\include\pybind11/pytypes.h(111): error : expected a ";"
          object call(Args&&... args) const;

Or says that m_ptr is undefined in handle class

D:\ProgramData\code_dump\VisualStudioProjects\TestPybind11\\include\pybind11/pytypes.h(150): error : identifier "m_ptr" is undefined
      PyObject *ptr() const { return m_ptr; }
loriab commented 6 years ago

At least on Linux & MacOS, I've used pb11 2.2.3 and Intel 2018.0.2 with no problem.

timbad commented 6 years ago

@loriab were you able to compile given code?

loriab commented 6 years ago

yes

>>> icpc -Wall -shared -std=c++11 -fPIC `python -m pybind11 --includes` test.cc -o test.so
In file included from test.cc(3):
/home/psilocaluser/toolchainconda/envs/p4dev36/include/python3.6m/pybind11/common.h(2): warning #1224: #warning directive: "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'."
  #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'."
   ^

>>> ldd test.so 
    linux-vdso.so.1 =>  (0x00007ffd67de3000)
    libimf.so => /theoryfs2/common/software/intel2018/compilers_and_libraries_2018.2.199/linux/compiler/lib/intel64/libimf.so (0x00007f64d2202000)
    libsvml.so => /theoryfs2/common/software/intel2018/compilers_and_libraries_2018.2.199/linux/compiler/lib/intel64/libsvml.so (0x00007f64d0b4c000)
    libirng.so => /theoryfs2/common/software/intel2018/compilers_and_libraries_2018.2.199/linux/compiler/lib/intel64/libirng.so (0x00007f64d07d8000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f64d04a9000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f64d01a7000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f64cff91000)
    libintlc.so.5 => /theoryfs2/common/software/intel2018/compilers_and_libraries_2018.2.199/linux/compiler/lib/intel64/libintlc.so.5 (0x00007f64cfd22000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f64cf961000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f64cf75d000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f64d29bf000)
loriab commented 6 years ago

whoops, executable, not module. it does not segfault upon execution.

>>> icpc -Wall -std=c++11 -fPIC `python -m pybind11 --includes` /home/psilocaluser/toolchainconda/envs/p4dev36/lib/libpython3.6m.so test.cc
In file included from test.cc(3):
/home/psilocaluser/toolchainconda/envs/p4dev36/include/python3.6m/pybind11/common.h(2): warning #1224: #warning directive: "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'."
  #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'."
   ^

>>> ldd a.out 
    linux-vdso.so.1 =>  (0x00007ffec9ff9000)
    libpython3.6m.so.1.0 => not found
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f76515dc000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f76512da000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f76510c3000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f7650d02000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f7650afe000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f765190c000)
>>> LD_LIBRARY_PATH=/home/psilocaluser/toolchainconda/envs/p4dev36/lib:$LD_LIBRARY_PATH ./a.out
MisesEnForce commented 6 years ago

What's the status on this, and on pybind11 wrt ICC 2018 ? I have on my side a bunch of errors :

image

loriab commented 6 years ago

Problems are confined to Windows, I believe. I can vouch for pb11 with 2018.0.2 & 2018.0.3 on Linux and 2018.0.2 on Mac.

MisesEnForce commented 6 years ago

I know, my question was : what is planned for windows ? Is it an icc bug or is the issue on pybind11 side ?

loriab commented 6 years ago

Ah, that I couldn't venture (I don't even have a Windows box around). If can't build https://github.com/pybind/cmake_example, then it's a real problem. If you or a friend likes template metaprogramming, handing over your terminal and jiggling the pb11 syntax has fixed a few Intel-specific pb11 problems for me.

davidson16807 commented 5 years ago

I'm having similar trouble with icpc 18. I'm running on Linux CentOS6:

In file included from /home/davidsca/.pyenv/versions/lxc6-cronuspy2.7/include/site/python2.7/pybind11/pytypes.h(12),
                 from /home/davidsca/.pyenv/versions/lxc6-cronuspy2.7/include/site/python2.7/pybind11/cast.h(13),
                 from /home/davidsca/.pyenv/versions/lxc6-cronuspy2.7/include/site/python2.7/pybind11/attr.h(13),
                 from /home/davidsca/.pyenv/versions/lxc6-cronuspy2.7/include/site/python2.7/pybind11/pybind11.h(43),
                 from src/CronusPy.cpp(1):
/home/davidsca/.pyenv/versions/lxc6-cronuspy2.7/include/site/python2.7/pybind11/detail/common.h(147): catastrophic error: cannot open source file "typeindex"
  #include <typeindex>
                      ^

compilation aborted for src/CronusPy.cpp (code 4)
error: command 'icpc' failed with exit status 4

I've been porting a wrapper library from boost::python to pybind11. My boost::python environment works in this environment using icpc 15, so the problem probably isn't icpc. My pybind wrapper also works for a similar environment when built using g++, so it's not my implementation. The problem appears to be with combining pybind11 + icpc.

henryiii commented 3 years ago

Latest master seems to work on Intel 18+, reopen if it doesn't! Hope to add CI based on OneAPI in the future.

henryiii commented 3 years ago

Sorry, Intel + Windows has not been tested.