greenwaves-technologies / bfloat16 Goto Github PK
View Code? Open in Web Editor NEWbfloat16 dtype for numpy
License: Apache License 2.0
bfloat16 dtype for numpy
License: Apache License 2.0
Hi, I am trying to use this package, but it has no requirements.txt(this package has a dependency on numpy), so automatical build in CI is failing due to that issue. Could you please add that?
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 ?
Collecting bfloat16
Using cached bfloat16-1.1.tar.gz (550 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: bfloat16
Building wheel for bfloat16 (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [152 lines of output]
/opt/homebrew/lib/python3.11/site-packages/setuptools/dist.py:788: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
warnings.warn(
bfloat16.cc:43:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using bfloat16 = Eigen::bfloat16;
^
bfloat16.cc:44:17: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint8 = std::uint8_t;
^
bfloat16.cc:45:16: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int8 = std::int8_t;
^
bfloat16.cc:46:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint16 = std::uint16_t;
^
bfloat16.cc:47:17: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int16 = std::int16_t;
^
bfloat16.cc:48:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint64 = std::uint64_t;
^
bfloat16.cc:57:28: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Safe_PyObjectPtr = std::unique_ptr<PyObject, PyDecrefDeleter>;
^
bfloat16.cc:462:26: error: unexpected type name 'bfloat16': expected expression
/*alignment=*/alignof(bfloat16),
^
bfloat16.cc:757:43: error: a space is required between consecutive right angle brackets (use '> >')
struct TypeDescriptor<std::complex<float>>
^~
> >
bfloat16.cc:764:44: error: a space is required between consecutive right angle brackets (use '> >')
struct TypeDescriptor<std::complex<double>>
^~
> >
bfloat16.cc:782:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
const auto *from =
^
bfloat16.cc:784:4: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto *to = reinterpret_cast<typename TypeDescriptor<To>::T *>(to_void);
^
bfloat16.cc:818:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {TypeDescriptor<InType>::Dtype(), TypeDescriptor<OutType>::Dtype()};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:827:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto x = *reinterpret_cast<const typename TypeDescriptor<InType>::T *>(i0);
^
bfloat16.cc:841:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {TypeDescriptor<InType>::Dtype(), TypeDescriptor<OutType>::Dtype(),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:852:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto x = *reinterpret_cast<const typename TypeDescriptor<InType>::T *>(i0);
^
bfloat16.cc:853:11: error: no member named 'tie' in namespace 'std'; did you mean 'time'?
std::tie(*reinterpret_cast<typename TypeDescriptor<OutType>::T *>(o0),
~~~~~^~~
time
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/c++/v1/ctime:70:9: note: 'time' declared here
using ::time _LIBCPP_USING_IF_EXISTS;
^
bfloat16.cc:868:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {TypeDescriptor<InType>::Dtype(), TypeDescriptor<InType>::Dtype(),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:884:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto x = *reinterpret_cast<const typename TypeDescriptor<InType>::T *>(i0);
^
bfloat16.cc:885:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto y = *reinterpret_cast<const typename TypeDescriptor<InType>::T *>(i1);
^
bfloat16.cc:912:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {TypeDescriptor<InType>::Dtype(), TypeDescriptor<InType2>::Dtype(),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:928:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto x = *reinterpret_cast<const typename TypeDescriptor<InType>::T *>(i0);
^
bfloat16.cc:929:6: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto y =
^
bfloat16.cc:1040:13: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {nan, nan};
^~~~~~~~~~
bfloat16.cc:1040:13: error: non-aggregate type 'std::pair<float, float>' cannot be initialized with an initializer list
return {nan, nan};
^~~~~~~~~~
bfloat16.cc:1070:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {floordiv, mod};
^~~~~~~~~~~~~~~
bfloat16.cc:1070:12: error: non-aggregate type 'std::pair<float, float>' cannot be initialized with an initializer list
return {floordiv, mod};
^~~~~~~~~~~~~~~
bfloat16.cc:1092:13: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {npy_bfloat16, npy_bfloat16, npy_bfloat16, npy_bfloat16};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:1092:13: error: non-aggregate type 'std::vector<int>' cannot be initialized with an initializer list
return {npy_bfloat16, npy_bfloat16, npy_bfloat16, npy_bfloat16};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:1106:12: error: no member named 'tie' in namespace 'std'
std::tie(floordiv, mod) =
~~~~~^
bfloat16.cc:1202:13: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {bfloat16(f), exp};
^~~~~~~~~~~~~~~~~~
bfloat16.cc:1202:13: error: non-aggregate type 'std::pair<bfloat16, int>' (aka 'pair<Eigen::bfloat16, int>') cannot be initialized with an initializer list
return {bfloat16(f), exp};
^~~~~~~~~~~~~~~~~~
bfloat16.cc:1331:13: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions]
return {bfloat16(f), bfloat16(integral)};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:1331:13: error: non-aggregate type 'std::pair<bfloat16, bfloat16>' (aka 'pair<Eigen::bfloat16, Eigen::bfloat16>') cannot be initialized with an initializer list
return {bfloat16(f), bfloat16(integral)};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bfloat16.cc:1495:13: error: unknown type name 'constexpr'
static constexpr float radians_per_degree = M_PI / 180.0f;
^
bfloat16.cc:1503:13: error: unknown type name 'constexpr'
static constexpr float degrees_per_radian = 180.0f / M_PI;
^
bfloat16.cc:1688:3: warning: implicit conversion of NULL constant to 'bool' [-Wnull-conversion]
import_array();
^~~~~~~~~~~~~~
/opt/homebrew/lib/python3.11/site-packages/numpy/core/include/numpy/__multiarray_api.h:1559:151: note: expanded from macro 'import_array'
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NULL; } }
~~~~~~ ^
bfloat16.cc:1747:31: error: expression is not assignable
Py_TYPE(&NPyBfloat16_Descr) = &PyArrayDescr_Type;
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
bfloat16.cc:1830:47: error: a space is required between consecutive right angle brackets (use '> >')
if (!RegisterBfloat16Cast<std::complex<float>>(NPY_COMPLEX64,
^~
> >
bfloat16.cc:1835:48: error: a space is required between consecutive right angle brackets (use '> >')
if (!RegisterBfloat16Cast<std::complex<double>>(NPY_COMPLEX128, /*cast_is_safe=*/true))
^~
> >
bfloat16.cc:1841:61: error: a space is required between consecutive right angle brackets (use '> >')
RegisterUFunc<BinaryUFunc<bfloat16, bfloat16, ufuncs::Add>>(numpy.get(), "add") &&
^~
> >
bfloat16.cc:1842:80: error: a space is required between consecutive right angle brackets (use '> >')
RegisterUFunc<BinaryUFunc2<float, bfloat16, bfloat16, ufuncs::ScalarFloatAdd>>(numpy.get(), "add") &&
^~
> >
bfloat16.cc:1843:80: error: a space is required between consecutive right angle brackets (use '> >')
RegisterUFunc<BinaryUFunc2<bfloat16, float, bfloat16, ufuncs::AddScalarFloat>>(numpy.get(), "add") &&
^~
> >
bfloat16.cc:1844:66: error: a space is required between consecutive right angle brackets (use '> >')
RegisterUFunc<BinaryUFunc<bfloat16, bfloat16, ufuncs::Subtract>>(numpy.get(), "subtract") &&
^~
> >
fatal error: too many errors emitted, stopping now [-ferror-limit=]
25 warnings and 20 errors generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for bfloat16
Running setup.py clean for bfloat16
Failed to build bfloat16
ERROR: Could not build wheels for bfloat16, which is required to install pyproject.toml-based projects
Bfloat16 module crashes when tried to import along with tensorflow.
Tensorflow supports bfloat16, i am aware of it, but in larger project this is affecting the bfloat16 usage
Simple steps to reproduce the issue
$ python
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.import tensorflow
import bfloat16
Segmentation fault (core dumped)
tensorflow version 2.6.2
bfloat16 version 1.1
ValueError: descr is not a valid dtype descriptor: '<g2'
This happens after saving a numpy array to a file using np.save and loading it again using np.load. It seems like the descriptor type is not registered
Kindly have a look at the following:
>>> a = np.array([[1.0345,2.0000], [2.0101,3.0003]], dtype=bfloat16)
>>> a
array([[1.031250, 2.000000],
[2.015625, 3.000000]], dtype=bfloat16)
The array was created with relatively small values, shouldn't they have remained the same?
When I want to get memoryview of numpy array of bfloat16, I got this:
>>> from bfloat16 import bfloat16
>>> import numpy as np
>>> a = np.full((2,2), 1, bfloat16)
>>> a
array([[1.000000, 1.000000],
[1.000000, 1.000000]], dtype=bfloat16)
>>> m = memoryview(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot include dtype 'E' in a buffer
The bfloat16
package fails at import with numpy
2.x+ because of the breaking changes introduced to the ABI and C-APIs (changelog). It still works with numpy
1.x versions for now.
Please upload the source for 1.2 to PyPI so that the package can be used on non-x86 platforms and on future versions of Python like 3.13. Currently pip is forced to go back to bfloat16 1.1 on these systems which doesn't contain the recent fixes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.