Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install fails with error: lvalue required as left operand of assignment #5

Open
amuthl opened this issue Jun 16, 2023 · 1 comment
Open

Comments

@amuthl
Copy link

amuthl commented Jun 16, 2023

running setup.py install fails with this error:

bfloat16# python setup.py install
/workspaces/.venv/lib/python3.11/site-packages/setuptools/dist.py:775: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
  warnings.warn(
/workspaces/.venv/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/workspaces/.venv/lib/python3.11/site-packages/setuptools/command/easy_install.py:146: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
warning: no files found matching 'bfloat16.h'
bfloat16.cc: In member function ‘greenwaves::{anonymous}::bfloat16 greenwaves::{anonymous}::ufuncs::NextAfter::operator()(greenwaves::{anonymous}::bfloat16, greenwaves::{anonymous}::bfloat16)’:
bfloat16.cc:1663:63: warning: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘using bfloat16 = struct Eigen::bfloat16’ {aka ‘struct Eigen::bfloat16’} from an array of ‘uint16_t’ {aka ‘short unsigned int’} [-Wclass-memaccess]
 1663 |                                                         memcpy(&out, &out_int, sizeof(bfloat16));
      |                                                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from eigen/Eigen/Core:170,
                 from bfloat16.cc:33:
eigen/Eigen/src/Core/arch/Default/BFloat16.h:58:8: note: ‘using bfloat16 = struct Eigen::bfloat16’ {aka ‘struct Eigen::bfloat16’} declared here
   58 | struct bfloat16 : public bfloat16_impl::bfloat16_base {
      |        ^~~~~~~~
bfloat16.cc:1675:47: warning: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘using bfloat16 = struct Eigen::bfloat16’ {aka ‘struct Eigen::bfloat16’} from an array of ‘uint16_t’ {aka ‘short unsigned int’} [-Wclass-memaccess]
 1675 |                                         memcpy(&out, &out_int, sizeof(bfloat16));
      |                                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
eigen/Eigen/src/Core/arch/Default/BFloat16.h:58:8: note: ‘using bfloat16 = struct Eigen::bfloat16’ {aka ‘struct Eigen::bfloat16’} declared here
   58 | struct bfloat16 : public bfloat16_impl::bfloat16_base {
      |        ^~~~~~~~
In file included from /usr/include/python3.11/Python.h:44,
                 from bfloat16.cc:27:
bfloat16.cc: In function ‘bool greenwaves::Initialize()’:
/usr/include/python3.11/object.h:136:30: error: lvalue required as left operand of assignment
  136 | #  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bfloat16.cc:1748:17: note: in expansion of macro ‘Py_TYPE’
 1748 |                 Py_TYPE(&NPyBfloat16_Descr) = &PyArrayDescr_Type;
      |                 ^~~~~~~
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

On Debian Bookworm, GCC 12, Python 3.11, Numpy 1.24.3.

The issue is that Py_TYPE is a function returning a PyTypeObject* so it can't be assigned a value.
Maybe there is a missing dereference ?

@amuthl
Copy link
Author

amuthl commented Jun 16, 2023

The fix is to use Py_SET_TYPE function which was added in python 3.9:
Py_SET_TYPE(&NPyBfloat16_Descr, &PyArrayDescr_Type);

See also: python/steering-council#79

swmoon00 added a commit to swmoon00/bfloat16 that referenced this issue Aug 21, 2023
xhmelon added a commit to xhmelon/bfloat16 that referenced this issue Sep 19, 2023
bfloat16 could not be built since Python 3.11, for Py_TYPE has been
deprecated since Python 3.9, see PEP 674 and Common Object
Structures docs for details. This issue was covered in GreenWaves-Technologies#5.
bfloat16 could not be built on macOS, because C++11 flag is not
enabled by default in clang. This issue was covered in GreenWaves-Technologies#7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant