Commit Graph

246 Commits

Author SHA1 Message Date
Jieyang Chen
723e133055 Merge topic 'hip-support'
a157c0e84 Add changes for supporting Kokkos/HIP

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Vicente Bolea <vicente.bolea@kitware.com>
Merge-request: !2554
2021-10-05 10:42:55 -04:00
Jieyang Chen
a157c0e846 Add changes for supporting Kokkos/HIP
Some of the unit tests for serial and kokkos are disable for hipcc to
properly compile.
VTKM_MATH_ASSERT and VTKM_TEST_ASSERT fail to compile with HIP in
execution environment so they are disabled with building with HIP.
Kokkos::finalize is causing error so it is temporarily disabled.
2021-10-01 15:27:00 -04:00
Vicente Adolfo Bolea Sanchez
557124f6fc testing/Testing.h when VTKm_ENABLE_TESTING_LIBRARY 2021-10-01 13:17:16 -04:00
Kenneth Moreland
6447b17303 Disable floating point exception traps when testing NaNs
Some functions are supposed to behave correctly when given a NaN. This
might only be valid if floation point exceptions are not trapped, so
disable trapping for these tests.
2021-07-12 10:29:45 -06:00
Kenneth Moreland
b01ca530b8 Turn on floating point exception trapping for GCC in tests
Some simulations trap floating point exceptions to ensure that their
code is working correctly, and we want VTK-m to work correctly in their
code. To check this, we want to turn on floating point exception
trapping in our test code. This is very implementation-specific, so for
now we are just turning it on for GCC. This will at least alert a
problem on some of the dashboards.
2021-07-12 10:29:37 -06:00
Nick Thompson
82361fc45e Better message on failure for DifferenceOfProducts. 2021-04-13 19:09:55 -04:00
Nick Thompson
384fea5ced Make sure arguments are placed in correct order. 2021-04-13 16:00:23 -04:00
Nick Thompson
cddb6f7b6d Do not flush the stream when you're just going to convert it to string. 2021-04-13 14:37:20 -04:00
Nick Thompson
bdc73333c9 Speed up UnitTestMath. 2021-04-12 18:51:52 -04:00
Nick Thompson
94a32bf64c Improve code in response to review. 2021-04-12 13:42:19 -04:00
Nick Thompson
568c0b5d29 Small formatting changes. 2021-04-12 13:05:36 -04:00
Nick Thompson
a8e25da0ab Add __func__ to unit test metadata printed on failure. 2021-04-12 12:54:38 -04:00
Nick Thompson
d4ead2d767 Remove superfluous subbraces. 2021-04-08 16:23:42 -04:00
Nick Thompson
a7ecd30cdd Commute #ifdef with braces to make clang-format happy. 2021-04-08 16:23:42 -04:00
Nick Thompson
dd8863637a Return a vec<T,2> rather than a vtkm::Pair<T,T>. 2021-04-08 16:23:42 -04:00
Nick Thompson
91bec19e97 Additional comments and fix typo in unit test. 2021-04-08 16:23:42 -04:00
Nick Thompson
6f9515aa94 Quadratic roots to 3 ulps. 2021-04-08 16:23:42 -04:00
nadavi
1c9ae402b0 Deprecate vtkm/BinarySearch.h, it is unused and similar to LowerBound 2021-04-07 19:10:28 +00:00
nadavi
26d9ecb398 split vtkm/Algorithms.h into UpperBound.h, LowerBound.h, and BinarySearch.h 2021-04-07 18:53:09 +00:00
Nick Thompson
068399b817 Fix build errors on Windows and compiler warnings on Ubuntu. 2021-04-07 08:09:39 -04:00
Nick Thompson
8d54138d3e Kahan's difference of products algorithm 2021-04-05 15:20:56 -04:00
Kenneth Moreland
80c1f0a974 Be more conservative about is_trivial support
`std::is_trivial` is part of the C++14 specification. However, we have
encountered multiple compilers that purport to implement C++14 but do
not implement `std::is_trivial` and the like checks correctly.

To avoid such issues, only use `std::is_trivial` on compilers that we
have tested to support it.
2021-03-01 15:12:27 -07:00
Nick Thompson
e4241aa530 Make matrix unit tests less verbose. 2021-02-08 16:18:13 -05:00
Kenneth Moreland
97324e75cd Enable reinterpreting UnknownArrayHandle to compatible C types
The base C types have several "duplicate" types that the compiler
considers different even though the byte representation is the same. For
example, `char` and `signed char` have the same meaning but are treated
as different types. Likewise, 'long', 'int', and 'long long' are all
different types even though 'long' is the same as either 'int' or 'long
long'.

When pulling extracted components from `UnknownArrayHandle`, there is
little value for creating multiple code paths for types like `char` and
`signed char`. Instead, allow implicit conversion among these types.
2021-01-13 09:19:27 -07:00
Kenneth Moreland
755af739e3 Add ArrayHandleRecombineVec
The primary purpose of `ArrayHandleRecombineVec` is to take arrays
returned from `ArrayExtractComponent` and recombine them again into a
single `ArrayHandle` that has `Vec` values.
2021-01-04 11:55:02 -07:00
Kenneth Moreland
5610d674d8 Print TestEqualResult messages in VTK_TEST_ASSERT
Some of the `test_equal` functions return a `TestEqualResult`
instead of a `bool` to capture more information about what
the error was. Unfortunately, using this was awkward because
you couldn't just call the `test_equal_*` inside of a
`VTKM_TEST_ASSERT`. Rather, you would have to do the comparison
and then check it.

This change adds an overload to `VTKM_TEST_ASSERT` that specifically
takes a `TestEqualResult`, checks its condition, and prints out
the contained messages. Thus, your command can just look like
`VTKM_TEST_ASSERT(test_equal_ArrayHandles(...));` and it will
provide the additional information.
2020-12-22 17:17:10 -07:00
Kenneth Moreland
0ab3edd87d Add VecFlat class
`vtkm::VecFlat` is a wrapper around a `Vec`-like class that may be a
nested series of vectors. For example, if you run a gradient operation
on a vector field, you are probably going to get a `Vec` of `Vec`s that
looks something like `vtkm::Vec<vtkm::Vec<vtkm::Float32, 3>, 3>`. That
is fine, but what if you want to treat the result simply as a `Vec` of
size 9?

The `VecFlat` wrapper class allows you to do this. Simply place the
nested `Vec` as an argument to `VecFlat` and it will behave as a flat
`Vec` class. (In fact, `VecFlat` is a subclass of `Vec`.) The `VecFlat`
class can be copied to and from the nested `Vec` it is wrapping.

There is a `vtkm::make_VecFlat` convenience function that takes an
object and returns a `vtkm::VecFlat` wrapped around it.
2020-12-16 17:22:44 -07:00
Kenneth Moreland
88eed2bbeb Make sure all C scalar types are in TypeListScalarAll
C++ template considers some types different even though they have the
exact same format. For example `int`, `long`, and `long long` all match
different types even though they all represent either signed 32-bit ints
or signed 64-bit ints.

List all these possible types in
`TypeListScalarAll`.
2020-11-12 16:18:56 -07:00
Robert Maynard
77a979ff2b Merge topic 'corrections_for_swap_and_math_for_hip'
0b2ddb83b UnitTestBounds custom compile flags expressed via generator expression
1ed5dfca0 vtkm/Math frexp(float) version works now with HIP
ff381bf8b vtkm/Swap works with hip

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <kmorel@sandia.gov>
Merge-request: !2301
2020-10-29 10:55:55 -04:00
Robert Maynard
0b2ddb83b3 UnitTestBounds custom compile flags expressed via generator expression 2020-10-22 16:48:18 -04:00
Kenneth Moreland
28ecf3636d Change interface of atomic compare and swap
The old atomic compare and swap operations (`vtkm::AtomicCompareAndSwap`
and `vtkm::exec::AtomicArrayExecutionObject::CompareAndSwap`) had an
order of arguments that was confusing. The order of the arguments was
shared pointer (or index), desired value, expected value. Most people
probably assume expected value comes before desired value. And this
order conflicts with the order in the `std` methods, GCC atomics, and
Kokkos.

Change the interface of atomic operations to be patterned off the
`std::atomic_compare_exchange` and `std::atomic<T>::compare_exchange`
methods. First, these methods have a more intuitive order of parameters
(shared pointer, expected, desired). Second, rather than take a value
for the expected and return the actual old value, they take a pointer to
the expected value (or reference in `AtomicArrayExecutionObject`) and
modify this value in the case that it does not match the actual value.
This makes it harder to mix up the expected and desired parameters.
Also, because the methods return a bool indicating whether the value was
changed, there is an additional benefit that compare-exchange loops are
implemented easier.

For example, consider you want to apply the function `MyOp` on a
`sharedValue` atomically. With the old interface, you would have to do
something like this.

```cpp
T oldValue;
T newValue;
do
{
  oldValue = *sharedValue;
  newValue = MyOp(oldValue);
} while (vtkm::AtomicCompareAndSwap(sharedValue, newValue, oldValue) != oldValue);
```

With the new interface, this is simplfied to this.

```cpp
T oldValue = *sharedValue;
while (!vtkm::AtomicCompareExchange(sharedValue, &oldValue, MyOp(oldValue));
```
2020-10-20 08:39:22 -06:00
Kitware Robot
cf0cdcf7d1 clang-format: reformat the repository with clang-format-9 2020-08-24 14:01:08 -04:00
Kenneth Moreland
7573d4ed57 Fix compiler warnings 2020-08-20 17:08:36 -06:00
Kenneth Moreland
13056b3af5 Deprecate AtomicInterfaceControl and AtomicInterfaceExecution
Now that we have the functions in `vtkm/Atomic.h`, we can deprecate (and
eventually remove) the more cumbersome classes `AtomicInterfaceControl`
and `AtomicInterfaceExecution`.

Also reversed the order of the `expected` and `desired` parameters of
`vtkm::AtomicCompareAndSwap`. I think the former order makes more sense
and matches more other implementations (such as `std::atomic` and the
GCC `__atomic` built ins). However, there are still some non-deprecated
classes with similar methods that cannot easily be switched. Thus, it's
better to be inconsistent with most other libraries and consistent with
ourself than to be inconsitent with ourself.
2020-08-20 13:40:44 -06:00
Kenneth Moreland
ebbebd7369 Add atomic free functions
Previously, all atomic functions were stored in classes named
`AtomicInterfaceControl` and `AtomicInterfaceExecution`, which required
you to know at compile time which device was using the methods. That in
turn means that anything using an atomic needed to be templated on the
device it is running on.

That can be a big hassle (and is problematic for some code structure).
Instead, these methods are moved to free functions in the `vtkm`
namespace. These functions operate like those in `Math.h`. Using
compiler directives, an appropriate version of the function is compiled
for the current device the compiler is using.
2020-08-20 13:40:43 -06:00
Kenneth Moreland
ed41874cc8 Consolidate tests for base vtkm code that is device-specific
Some of the code in the base `vtkm` namespace is device specific. For
example, the functions in `Math.h` are customized for specific devices.
Thus, we want this code to be specially compiled and run on these
devices.

Previously, we made a header file and then added separate tests to each
device package. That was created before we had ways of running on any
device. Now, it is much easier to compile the test a single time for all
devices and use the `ALL_BACKENDS` feature of `vtkm_unit_tests` CMake
function to automatically create the test for all devices.
2020-08-18 14:30:25 -06:00
Sujin Philip
db57ed26a2 Fix warnings 2020-08-12 13:55:24 -04:00
Kenneth Moreland
d1a4aecc59 Improvements to moving data into ArrayHandle
We have made several improvements to adding data into an `ArrayHandle`.

## Moving data from an `std::vector`

For numerous reasons, it is convenient to define data in a `std::vector`
and then wrap that into an `ArrayHandle`. It is often the case that an
`std::vector` is filled and then becomes unused once it is converted to an
`ArrayHandle`. In this case, what we really want is to pass the data off to
the `ArrayHandle` so that the `ArrayHandle` is now managing the data and
not the `std::vector`.

C++11 has a mechanism to do this: move semantics. You can now pass
variables to functions as an "rvalue" (right-hand value). When something is
passed as an rvalue, it can pull state out of that variable and move it
somewhere else. `std::vector` implements this movement so that an rvalue
can be moved to another `std::vector` without actually copying the data.
`make_ArrayHandle` now also takes advantage of this feature to move rvalue
`std::vector`s.

There is a special form of `make_ArrayHandle` named `make_ArrayHandleMove`
that takes an rvalue. There is also a special overload of
`make_ArrayHandle` itself that handles an rvalue `vector`. (However, using
the explicit move version is better if you want to make sure the data is
actually moved.)

## Make `ArrayHandle` from initalizer list

A common use case for using `std::vector` (particularly in our unit tests)
is to quickly add an initalizer list into an `ArrayHandle`. Now you can
by simply passing an initializer list to `make_ArrayHandle`.

## Deprecated `make_ArrayHandle` with default shallow copy

For historical reasons, passing an `std::vector` or a pointer to
`make_ArrayHandle` does a shallow copy (i.e. `CopyFlag` defaults to `Off`).
Although more efficient, this mode is inherintly unsafe, and making it the
default is asking for trouble.

To combat this, calling `make_ArrayHandle` without a copy flag is
deprecated. In this way, if you wish to do the faster but more unsafe
creation of an `ArrayHandle` you should explicitly express that.

This requried quite a few changes through the VTK-m source (particularly in
the tests).

## Similar changes to `Field`

`vtkm::cont::Field` has a `make_Field` helper function that is similar to
`make_ArrayHandle`. It also features the ability to create fields from
`std::vector`s and C arrays. It also likewise had the same unsafe behavior
by default of not copying from the source of the arrays.

That behavior has similarly been depreciated. You now have to specify a
copy flag.

The ability to construct a `Field` from an initializer list of values has
also been added.
2020-07-23 10:53:38 -06:00
Sujin Philip
2f7ae83c9f Fix warnings 2020-07-09 08:10:54 -05:00
Nick
470058c328 Unfoobar the float_distance MR. 2020-06-24 10:52:59 -04:00
Kenneth Moreland
f6a8993469 Make tests that throw an STL exception fail
If a test throws any unexpected exception, the test is supposed to
detect that and fail. For the STL exceptions, the test failed to return
an error code. Fix that.
2020-06-23 16:25:09 -06:00
Kenneth Moreland
3c4e8a2ea5 Convert filters to use precompiled field map functions where applicable 2020-05-21 08:34:32 -06:00
Kenneth Moreland
dca8144345 Add vtkmstd::integer_sequence
`integer_sequence` is an essential tool when dealing with structures
like a `Tuple`. Make sure that we have one (even though it was not
introduced until C++14).
2020-03-16 17:12:16 -06:00
Kenneth Moreland
56636afc7a Make Tuple class
Made a new vtkm::Tuple class to replace tao tuple.

This version of Tuple should hopefully compile faster. Having our own
implementation should also make it easier to port to new devices.
2020-03-16 17:12:16 -06:00
Kenneth Moreland
ec34cb56c4 Use new ways to get array portal in control environment
Also fix deadlocks that occur when portals are not destroyed
in time.
2020-02-26 13:10:46 -07:00
Kenneth Moreland
ad0a53af71 Convert execution preparation to use tokens
Marked the old versions of PrepareFor* that do not use tokens as
deprecated and moved all of the code to use the new versions that
require a token. This makes the scope of the execution object more
explicit so that it will be kept while in use and can potentially be
reclaimed afterward.
2020-02-25 09:39:19 -07:00
Kenneth Moreland
aa59224f28 More testing of long lists
We encountered some issues with `ListIndexOf` for longer lists with
repeated elements. Add some tests for that.
2020-01-09 10:33:49 -07:00
Allison Vacanti
39d981bcf9 Shorten names returned by testing's TypeName utility.
Eg:

```
vtkm::Float32                                       -> F32
vtkm::Int64                                         -> I64
vtkm::Vec< vtkm::Float32, 3 >                       -> Vec3f_32
vtkm::Vec< vtkm::Pair< vtkm::Int32, vtkm::Float64 > -> Vec<Pair<I32, F64>>
```

This makes the benchmark names a lot shorter to keep rows tabular
results on
a single line.
2020-01-08 10:58:51 -05:00
Allison Vacanti
44c4f0838f Add vtkm/Algorithms.h header with device-friendly binary search algorithms. 2019-12-20 12:35:10 -05:00
Allison Vacanti
84eedc8855 Make BinaryOperators/Predicates more flexible.
Allow the argument types to differ. This allows ArrayPortalValueReferences to be used.
2019-12-18 15:51:59 -05:00