-
Notifications
You must be signed in to change notification settings - Fork 9
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
WIP: add bool type #54
base: main
Are you sure you want to change the base?
Conversation
* I need a bool type for Python array API standard conformance, and as far as I know Kokkos doesn't work with such a view type under the hood? * if I alias `bool_` and `bool` to the `uint8` type, the conformance test suite can see through it, and resolves the alias and fails my suite * I'm trying another approach now, but this fails i.e., the local `pykokkos-base` testsuite with ``` AttributeError: module 'kokkos.libpykokkos' has no attribute 'KokkosView_bool_HostSpace_LayoutRight_1' ``` * I'm not so sure either of these approaches really have many prospects for success--I'm open to better ideas... [skip ci]
@@ -134,6 +134,7 @@ enum KokkosViewDataType { | |||
Uint64, | |||
Float32, | |||
Float64, | |||
Bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this Bool
entity need to actually exist under the hood??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for the enum, this basically is just a definition
include/traits.hpp
Outdated
typedef uint8_t bool_t; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please if you do use using bool_t = uint8_t
@@ -134,6 +134,7 @@ enum KokkosViewDataType { | |||
Uint64, | |||
Float32, | |||
Float64, | |||
Bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for the enum, this basically is just a definition
Based on feedback from Jakob, I pushed in a small change to switch back to compiling with genuine
Each of those failures look pretty similar--one example:
|
* compile using genuine `bool` type instead of an alias * this seems to succeed at build stage, but a few tests do fail at the moment [skip ci]
f5d66e6
to
d5c85c6
Compare
* to accommodate `bool` view type, we use `True` instead of actual integer values in a number of tests
Ok, tests are passing locally now with the "native" I think they make sense--basically any positive non-zero integer value should be considered |
Looks like a subset of CI CMake builds fail with: |
Easy fix, in include/variants/atomics.hpp: Exclude all meaningless/invalid arithmetic operations on booleans via an _atomic.def(
"__mul__", [](atomic_type _obj, value_type _v) { return (_obj * _v); },
py::is_operator()); should be: constexpr bool is_boolean = std::is_same<Tp, bool>::value;
if constexpr(!is_boolean) {
_atomic.def(
"__mul__", [](atomic_type _obj, value_type _v) { return (_obj * _v); },
py::is_operator());
// ... etc
} |
if _kwargs["dtype"] == kokkos.bool: | ||
self.assertEqual(_data[1].create_mirror_view()[_idx], True) | ||
else: | ||
self.assertEqual(_data[1].create_mirror_view()[_idx], 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if _kwargs["dtype"] == kokkos.bool: | |
self.assertEqual(_data[1].create_mirror_view()[_idx], True) | |
else: | |
self.assertEqual(_data[1].create_mirror_view()[_idx], 2) | |
value = lambda v : v if _kwargs["dtype"] != kokkos.bool else v > 0 | |
self.assertEqual(_data[1].create_mirror_view()[_idx], value(2)) |
Just thought this scheme would be easier to maintain + more compact
I think >>> import numpy as np
>>> np.array([True, True]) * np.array([False, False])
array([False, False]) If C++ doesn't allow it, I suppose we could disable it here and use casting in the ufunc inner loops in |
@tylerjereddy sorry, disregard that statement. I saw something suggesting the compiler was trying to use |
I don't think this is necessarily an error. It is failing to build bc of #if defined(__GNUC__) // GCC and clang
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wint-in-bool-context"
#endif
// affected regions within generate_atomic_variant
#if defined(__GNUC__) // GCC and clang
#pragma GCC diagnostic pop
#endif |
Maybe I don't understand, but what would a multiplication of bools look like? I guess if you want to do this in cpp it will implicitly cast it to int, multiply and then cast it back ... which is the same as doing |
And if this is not possible, why not |
This would be ideal, I was under the impression from looking at the lambdas that |
Agree in principal but you would need a partial specialization and this is a freestanding function |
Oh wait nevermind, I remember seeing C++17 or higher is a requirement for Kokkos now so an if constexpr would work. |
I need a bool type for Python array API standard
conformance, and as far as I know Kokkos doesn't work
with such a view type under the hood?
if I alias
bool_
andbool
to theuint8
type,the conformance test suite can see through it, and
resolves the alias and fails my suite
I'm trying another approach now, but this fails
i.e., the local
pykokkos-base
testsuite withprospects for success--I'm open to better ideas...
[skip ci]