From d3f6d7b09c1c1d90b056b1dae6ceebd0e48525cc Mon Sep 17 00:00:00 2001 From: Akila Premachandra Date: Thu, 30 May 2019 17:21:19 -0600 Subject: [PATCH] ran formatter through entire repo (clang-9) --- .clang-format | 120 + .githooks/install | 8 + .githooks/pre-commit | 43 + Jenkinsfile | 2 +- examples/cpp_integration/device.h | 1 - examples/cpp_integration/host.cpp | 11 +- examples/include/timer.h | 131 +- performance/build/perftest.h | 157 +- performance/build/timer.h | 186 +- testing/backend/omp/nvcc_independence.cpp | 79 +- testing/testframework.cpp | 954 ++-- testing/unittest/assertions.h | 657 +-- testing/unittest/exceptions.h | 84 +- testing/unittest/meta.h | 619 ++- testing/unittest/random.h | 172 +- testing/unittest/special_types.h | 183 +- testing/unittest/system.h | 29 +- testing/unittest/testframework.h | 312 +- testing/unittest/unittest.h | 3 +- testing/unittest/util.h | 23 +- testing/vector_cpp_subset.cpp | 2 - thrust/adjacent_difference.h | 199 +- thrust/advance.h | 25 +- thrust/binary_search.h | 1508 ++++--- thrust/complex.h | 502 ++- thrust/copy.h | 433 +- thrust/count.h | 127 +- thrust/detail/allocator/allocator_traits.h | 495 +-- .../detail/allocator/copy_construct_range.h | 47 +- .../allocator/default_construct_range.h | 17 +- thrust/detail/allocator/destroy_range.h | 14 +- .../detail/allocator/fill_construct_range.h | 17 +- thrust/detail/allocator/malloc_allocator.h | 38 +- thrust/detail/allocator/no_throw_allocator.h | 69 +- thrust/detail/allocator/tagged_allocator.h | 149 +- thrust/detail/allocator/temporary_allocator.h | 91 +- thrust/detail/complex/arithmetic.h | 399 +- thrust/detail/complex/c99math.h | 325 +- thrust/detail/complex/catrig.h | 1066 ++--- thrust/detail/complex/catrigf.h | 807 ++-- thrust/detail/complex/ccosh.h | 230 +- thrust/detail/complex/ccoshf.h | 185 +- thrust/detail/complex/cexp.h | 216 +- thrust/detail/complex/cexpf.h | 194 +- thrust/detail/complex/clog.h | 286 +- thrust/detail/complex/clogf.h | 262 +- thrust/detail/complex/cpow.h | 88 +- thrust/detail/complex/cpowf.h | 25 +- thrust/detail/complex/cproj.h | 94 +- thrust/detail/complex/csinh.h | 227 +- thrust/detail/complex/csinhf.h | 182 +- thrust/detail/complex/csqrt.h | 185 +- thrust/detail/complex/csqrtf.h | 168 +- thrust/detail/complex/ctanh.h | 162 +- thrust/detail/complex/ctanhf.h | 134 +- thrust/detail/complex/math_private.h | 189 +- thrust/detail/complex/stream.h | 85 +- thrust/detail/config.h | 1 - thrust/detail/config/compiler.h | 55 +- thrust/detail/config/compiler_fence.h | 16 +- thrust/detail/config/config.h | 13 +- thrust/detail/config/debug.h | 17 +- thrust/detail/config/device_system.h | 40 +- thrust/detail/config/exec_check_disable.h | 6 +- thrust/detail/config/forceinline.h | 3 +- thrust/detail/config/global_workarounds.h | 10 +- thrust/detail/config/host_device.h | 1 - thrust/detail/config/host_system.h | 31 +- thrust/detail/config/simple_defines.h | 5 +- thrust/detail/contiguous_storage.h | 185 +- thrust/detail/copy.h | 113 +- thrust/detail/copy_if.h | 80 +- thrust/detail/cstdint.h | 101 +- thrust/detail/dispatch/is_trivial_copy.h | 47 +- thrust/detail/execute_with_allocator.h | 134 +- thrust/detail/execution_policy.h | 109 +- thrust/detail/function.h | 155 +- thrust/detail/functional/actor.h | 345 +- thrust/detail/functional/argument.h | 69 +- thrust/detail/functional/composite.h | 246 +- thrust/detail/functional/operators.h | 5 +- .../operators/arithmetic_operators.h | 593 +-- .../operators/assignment_operator.h | 74 +- .../functional/operators/bitwise_operators.h | 450 +- .../operators/compound_assignment_operators.h | 658 ++- .../functional/operators/logical_operators.h | 175 +- .../functional/operators/operator_adaptors.h | 155 +- .../operators/relational_operators.h | 466 +- thrust/detail/functional/placeholder.h | 25 +- thrust/detail/functional/value.h | 88 +- thrust/detail/get_iterator_value.h | 56 +- thrust/detail/integer_math.h | 129 +- thrust/detail/integer_traits.h | 211 +- thrust/detail/internal_functional.h | 1076 +++-- thrust/detail/malloc_and_free.h | 76 +- thrust/detail/minmax.h | 61 +- thrust/detail/mpl/math.h | 275 +- thrust/detail/numeric_traits.h | 187 +- thrust/detail/overlapped_copy.h | 202 +- thrust/detail/pointer.h | 308 +- thrust/detail/range/head_flags.h | 409 +- thrust/detail/range/tail_flags.h | 212 +- thrust/detail/raw_pointer_cast.h | 15 +- thrust/detail/raw_reference_cast.h | 725 ++- thrust/detail/reference.h | 215 +- thrust/detail/reference_forward_declaration.h | 6 +- thrust/detail/seq.h | 60 +- thrust/detail/static_assert.h | 84 +- thrust/detail/static_map.h | 289 +- thrust/detail/swap.h | 18 +- thrust/detail/temporary_array.h | 254 +- thrust/detail/temporary_buffer.h | 101 +- thrust/detail/trivial_sequence.h | 148 +- thrust/detail/tuple_meta_transform.h | 297 +- thrust/detail/tuple_transform.h | 762 ++-- thrust/detail/type_traits.h | 1435 +++--- ...mediate_type_from_function_and_iterators.h | 66 +- thrust/detail/type_traits/function_traits.h | 171 +- .../detail/type_traits/has_member_function.h | 265 +- thrust/detail/type_traits/has_nested_type.h | 25 +- .../detail/type_traits/has_trivial_assign.h | 31 +- thrust/detail/type_traits/is_call_possible.h | 262 +- .../type_traits/is_metafunction_defined.h | 26 +- .../iterator/is_discard_iterator.h | 24 +- .../type_traits/iterator/is_output_iterator.h | 74 +- thrust/detail/type_traits/minimum_type.h | 257 +- thrust/detail/type_traits/pointer_traits.h | 518 +-- .../result_of_adaptable_function.h | 63 +- thrust/detail/use_default.h | 7 +- thrust/detail/util/align.h | 59 +- thrust/detail/util/blocking.h | 60 +- thrust/detail/vector_base.h | 1005 ++--- thrust/device_allocator.h | 145 +- thrust/device_delete.h | 15 +- thrust/device_free.h | 13 +- thrust/device_malloc.h | 20 +- thrust/device_malloc_allocator.h | 271 +- thrust/device_new.h | 32 +- thrust/device_new_allocator.h | 261 +- thrust/device_ptr.h | 206 +- thrust/device_reference.h | 301 +- thrust/device_vector.h | 292 +- thrust/distance.h | 26 +- thrust/equal.h | 124 +- thrust/execution_policy.h | 162 +- thrust/extrema.h | 627 +-- thrust/fill.h | 111 +- thrust/find.h | 179 +- thrust/for_each.h | 142 +- thrust/functional.h | 1246 +++--- thrust/gather.h | 355 +- thrust/generate.h | 144 +- thrust/host_vector.h | 287 +- thrust/inner_product.h | 220 +- thrust/iterator/constant_iterator.h | 285 +- thrust/iterator/counting_iterator.h | 255 +- thrust/iterator/detail/any_assign.h | 59 +- thrust/iterator/detail/any_system_tag.h | 24 +- .../iterator/detail/constant_iterator_base.h | 72 +- thrust/iterator/detail/device_system_tag.h | 9 +- .../iterator/detail/discard_iterator_base.h | 75 +- thrust/iterator/detail/distance_from_result.h | 34 +- thrust/iterator/detail/host_system_tag.h | 9 +- thrust/iterator/detail/is_iterator_category.h | 65 +- thrust/iterator/detail/is_trivial_iterator.h | 84 +- .../iterator/detail/iterator_adaptor_base.h | 144 +- .../detail/iterator_category_to_system.h | 87 +- .../detail/iterator_category_to_traversal.h | 194 +- ...rator_category_with_system_and_traversal.h | 69 +- .../detail/iterator_facade_category.h | 439 +- .../iterator/detail/iterator_traversal_tags.h | 34 +- thrust/iterator/detail/join_iterator.h | 204 +- thrust/iterator/detail/minimum_category.h | 56 +- thrust/iterator/detail/minimum_system.h | 146 +- thrust/iterator/detail/normal_iterator.h | 90 +- .../detail/permutation_iterator_base.h | 46 +- thrust/iterator/detail/retag.h | 216 +- .../iterator/detail/reverse_iterator_base.h | 27 +- thrust/iterator/detail/tagged_iterator.h | 82 +- .../detail/tuple_of_iterator_references.h | 489 ++- thrust/iterator/detail/universal_categories.h | 149 +- thrust/iterator/detail/zip_iterator_base.h | 695 ++- thrust/iterator/discard_iterator.h | 152 +- thrust/iterator/iterator_adaptor.h | 310 +- thrust/iterator/iterator_categories.h | 183 +- thrust/iterator/iterator_facade.h | 1093 +++-- thrust/iterator/iterator_traits.h | 123 +- thrust/iterator/permutation_iterator.h | 189 +- thrust/iterator/retag.h | 9 +- thrust/iterator/reverse_iterator.h | 152 +- thrust/iterator/transform_iterator.h | 347 +- thrust/iterator/transform_output_iterator.h | 103 +- thrust/iterator/zip_iterator.h | 225 +- thrust/logical.h | 156 +- thrust/memory.h | 288 +- thrust/merge.h | 789 ++-- thrust/mismatch.h | 178 +- thrust/pair.h | 222 +- thrust/partition.h | 1355 +++--- thrust/random.h | 103 +- .../linear_congruential_engine_discard.h | 165 +- .../linear_feedback_shift_engine_wordmask.h | 38 +- thrust/random/detail/mod.h | 127 +- .../random/detail/normal_distribution_base.h | 245 +- thrust/random/detail/random_core_access.h | 53 +- thrust/random/detail/xor_combine_engine_max.h | 517 +-- thrust/random/discard_block_engine.h | 327 +- thrust/random/linear_congruential_engine.h | 354 +- thrust/random/linear_feedback_shift_engine.h | 332 +- thrust/random/normal_distribution.h | 356 +- thrust/random/subtract_with_carry_engine.h | 359 +- thrust/random/uniform_int_distribution.h | 350 +- thrust/random/uniform_real_distribution.h | 355 +- thrust/random/xor_combine_engine.h | 379 +- thrust/reduce.h | 679 +-- thrust/remove.h | 681 +-- thrust/replace.h | 658 +-- thrust/reverse.h | 118 +- thrust/scan.h | 1497 ++++--- thrust/scatter.h | 432 +- thrust/sequence.h | 227 +- thrust/set_operations.h | 3892 ++++++++++------- thrust/sort.h | 1049 ++--- thrust/swap.h | 127 +- .../system/cpp/detail/adjacent_difference.h | 1 - thrust/system/cpp/detail/assign_value.h | 1 - thrust/system/cpp/detail/binary_search.h | 1 - thrust/system/cpp/detail/copy.h | 1 - thrust/system/cpp/detail/copy_if.h | 1 - thrust/system/cpp/detail/count.h | 3 +- thrust/system/cpp/detail/equal.h | 3 +- thrust/system/cpp/detail/execution_policy.h | 123 +- thrust/system/cpp/detail/extrema.h | 1 - thrust/system/cpp/detail/fill.h | 3 +- thrust/system/cpp/detail/find.h | 1 - thrust/system/cpp/detail/for_each.h | 1 - thrust/system/cpp/detail/gather.h | 3 +- thrust/system/cpp/detail/generate.h | 3 +- thrust/system/cpp/detail/get_value.h | 1 - thrust/system/cpp/detail/inner_product.h | 3 +- thrust/system/cpp/detail/iter_swap.h | 1 - thrust/system/cpp/detail/logical.h | 3 +- thrust/system/cpp/detail/malloc_and_free.h | 1 - thrust/system/cpp/detail/merge.h | 1 - thrust/system/cpp/detail/mismatch.h | 3 +- thrust/system/cpp/detail/par.h | 83 +- thrust/system/cpp/detail/partition.h | 1 - thrust/system/cpp/detail/reduce.h | 1 - thrust/system/cpp/detail/reduce_by_key.h | 1 - thrust/system/cpp/detail/remove.h | 1 - thrust/system/cpp/detail/replace.h | 3 +- thrust/system/cpp/detail/reverse.h | 3 +- thrust/system/cpp/detail/scan.h | 1 - thrust/system/cpp/detail/scan_by_key.h | 1 - thrust/system/cpp/detail/scatter.h | 3 +- thrust/system/cpp/detail/sequence.h | 3 +- thrust/system/cpp/detail/set_operations.h | 1 - thrust/system/cpp/detail/sort.h | 1 - thrust/system/cpp/detail/swap_ranges.h | 1 - thrust/system/cpp/detail/tabulate.h | 3 +- thrust/system/cpp/detail/temporary_buffer.h | 1 - thrust/system/cpp/detail/transform.h | 1 - thrust/system/cpp/detail/transform_reduce.h | 3 +- thrust/system/cpp/detail/transform_scan.h | 3 +- thrust/system/cpp/detail/uninitialized_copy.h | 3 +- thrust/system/cpp/detail/uninitialized_fill.h | 3 +- thrust/system/cpp/detail/unique.h | 1 - thrust/system/cpp/detail/unique_by_key.h | 1 - thrust/system/cpp/execution_policy.h | 3 - thrust/system/cpp/memory.h | 523 ++- thrust/system/cpp/vector.h | 243 +- .../system/cuda/detail/adjacent_difference.h | 45 +- thrust/system/cuda/detail/assign_value.h | 287 +- thrust/system/cuda/detail/binary_search.h | 3 +- thrust/system/cuda/detail/block/copy.h | 556 +-- .../system/cuda/detail/block/exclusive_scan.h | 104 +- .../system/cuda/detail/block/inclusive_scan.h | 569 ++- thrust/system/cuda/detail/block/merge.h | 91 +- .../system/cuda/detail/block/merging_sort.h | 342 +- .../system/cuda/detail/block/odd_even_sort.h | 237 +- thrust/system/cuda/detail/block/reduce.h | 72 +- thrust/system/cuda/detail/bulk.h | 53 +- thrust/system/cuda/detail/bulk/algorithm.hpp | 15 +- .../cuda/detail/bulk/algorithm/accumulate.hpp | 358 +- .../bulk/algorithm/adjacent_difference.hpp | 220 +- .../cuda/detail/bulk/algorithm/copy.hpp | 450 +- .../algorithm/detail/stable_merge_sort.hpp | 399 +- .../cuda/detail/bulk/algorithm/for_each.hpp | 76 +- .../cuda/detail/bulk/algorithm/gather.hpp | 102 +- .../cuda/detail/bulk/algorithm/merge.hpp | 1098 ++--- .../cuda/detail/bulk/algorithm/reduce.hpp | 415 +- .../detail/bulk/algorithm/reduce_by_key.hpp | 353 +- .../cuda/detail/bulk/algorithm/scan.hpp | 1147 ++--- .../cuda/detail/bulk/algorithm/scatter.hpp | 307 +- .../cuda/detail/bulk/algorithm/sort.hpp | 290 +- thrust/system/cuda/detail/bulk/async.hpp | 201 +- thrust/system/cuda/detail/bulk/bulk.hpp | 9 +- .../system/cuda/detail/bulk/choose_sizes.hpp | 117 +- .../cuda/detail/bulk/detail/alignment.hpp | 391 +- .../detail/bulk/detail/apply_from_tuple.hpp | 308 +- .../cuda/detail/bulk/detail/closure.hpp | 405 +- .../system/cuda/detail/bulk/detail/config.hpp | 34 +- .../cuda_launcher/cuda_launch_config.hpp | 688 +-- .../detail/cuda_launcher/cuda_launcher.hpp | 728 +-- .../detail/cuda_launcher/parameter_ptr.hpp | 139 +- .../cuda_launcher/runtime_introspection.hpp | 42 +- .../cuda_launcher/triple_chevron_launcher.hpp | 332 +- .../cuda/detail/bulk/detail/cuda_task.hpp | 608 ++- .../bulk/detail/guarded_cuda_runtime_api.hpp | 66 +- .../cuda/detail/bulk/detail/head_flags.hpp | 438 +- .../bulk/detail/is_contiguous_iterator.hpp | 19 +- .../detail/bulk/detail/pointer_traits.hpp | 71 +- .../cuda/detail/bulk/detail/synchronize.hpp | 40 +- .../cuda/detail/bulk/detail/tail_flags.hpp | 226 +- .../cuda/detail/bulk/detail/terminate.hpp | 56 +- .../detail/bulk/detail/throw_on_error.hpp | 68 +- .../bulk/detail/tuple_meta_transform.hpp | 295 +- .../detail/bulk/detail/tuple_transform.hpp | 756 ++-- .../cuda/detail/bulk/execution_policy.hpp | 1053 ++--- thrust/system/cuda/detail/bulk/future.hpp | 235 +- thrust/system/cuda/detail/bulk/iterator.hpp | 3 +- .../detail/bulk/iterator/strided_iterator.hpp | 150 +- thrust/system/cuda/detail/bulk/malloc.hpp | 1029 +++-- .../system/cuda/detail/bulk/uninitialized.hpp | 572 +-- thrust/system/cuda/detail/copy.h | 99 +- thrust/system/cuda/detail/copy_cross_system.h | 66 +- .../cuda/detail/copy_device_to_device.h | 39 +- thrust/system/cuda/detail/copy_if.h | 48 +- thrust/system/cuda/detail/count.h | 3 +- thrust/system/cuda/detail/cub.h | 93 +- .../system/cuda/detail/cuda_launch_config.h | 701 +-- thrust/system/cuda/detail/decomposition.h | 434 +- .../cuda/detail/default_decomposition.h | 33 +- thrust/system/cuda/detail/detail/alignment.h | 419 +- .../system/cuda/detail/detail/balanced_path.h | 294 +- .../detail/cached_temporary_allocator.h | 272 +- .../cuda/detail/detail/launch_calculator.h | 80 +- .../cuda/detail/detail/launch_closure.h | 252 +- thrust/system/cuda/detail/detail/merge.h | 173 +- .../system/cuda/detail/detail/set_operation.h | 60 +- .../cuda/detail/detail/stable_merge_sort.h | 68 +- .../detail/detail/stable_primitive_sort.h | 96 +- .../cuda/detail/detail/stable_radix_sort.h | 107 +- .../cuda/detail/detail/stable_sort_each.h | 62 +- .../system/cuda/detail/detail/uninitialized.h | 587 +-- .../detail/detail/virtualized_smem_closure.h | 86 +- thrust/system/cuda/detail/equal.h | 3 +- thrust/system/cuda/detail/execute_on_stream.h | 192 +- thrust/system/cuda/detail/execution_policy.h | 215 +- thrust/system/cuda/detail/extern_shared_ptr.h | 56 +- thrust/system/cuda/detail/extrema.h | 3 +- thrust/system/cuda/detail/fill.h | 1 - thrust/system/cuda/detail/find.h | 3 +- thrust/system/cuda/detail/for_each.h | 63 +- thrust/system/cuda/detail/gather.h | 3 +- thrust/system/cuda/detail/generate.h | 3 +- thrust/system/cuda/detail/get_value.h | 115 +- .../cuda/detail/guarded_cuda_runtime_api.h | 4 +- .../system/cuda/detail/guarded_driver_types.h | 57 +- thrust/system/cuda/detail/inner_product.h | 3 +- thrust/system/cuda/detail/iter_swap.h | 63 +- thrust/system/cuda/detail/logical.h | 3 +- thrust/system/cuda/detail/malloc_and_free.h | 85 +- thrust/system/cuda/detail/merge.h | 51 +- thrust/system/cuda/detail/mismatch.h | 3 +- thrust/system/cuda/detail/par.h | 93 +- thrust/system/cuda/detail/partition.h | 3 +- thrust/system/cuda/detail/reduce.h | 45 +- thrust/system/cuda/detail/reduce_by_key.h | 58 +- thrust/system/cuda/detail/reduce_intervals.h | 47 +- .../system/cuda/detail/reduce_intervals.hpp | 160 +- thrust/system/cuda/detail/remove.h | 3 +- thrust/system/cuda/detail/replace.h | 3 +- thrust/system/cuda/detail/reverse.h | 3 +- .../cuda/detail/runtime_introspection.h | 63 +- thrust/system/cuda/detail/scan.h | 67 +- thrust/system/cuda/detail/scan_by_key.h | 3 +- thrust/system/cuda/detail/scatter.h | 3 +- thrust/system/cuda/detail/sequence.h | 3 +- thrust/system/cuda/detail/set_operations.h | 128 +- thrust/system/cuda/detail/sort.h | 62 +- thrust/system/cuda/detail/swap_ranges.h | 1 - thrust/system/cuda/detail/synchronize.h | 34 +- thrust/system/cuda/detail/tabulate.h | 3 +- thrust/system/cuda/detail/temporary_buffer.h | 1 - .../detail/temporary_indirect_permutation.h | 445 +- thrust/system/cuda/detail/terminate.h | 46 +- thrust/system/cuda/detail/throw_on_error.h | 47 +- thrust/system/cuda/detail/transform.h | 1 - thrust/system/cuda/detail/transform_reduce.h | 3 +- thrust/system/cuda/detail/transform_scan.h | 3 +- thrust/system/cuda/detail/trivial_copy.h | 63 +- .../system/cuda/detail/uninitialized_copy.h | 3 +- .../system/cuda/detail/uninitialized_fill.h | 3 +- thrust/system/cuda/detail/unique.h | 3 +- thrust/system/cuda/detail/unique_by_key.h | 3 +- thrust/system/cuda/error.h | 224 +- thrust/system/cuda/execution_policy.h | 7 +- .../cuda/experimental/pinned_allocator.h | 261 +- thrust/system/cuda/memory.h | 395 +- thrust/system/cuda/vector.h | 132 +- .../system/detail/adl/adjacent_difference.h | 7 +- thrust/system/detail/adl/assign_value.h | 4 +- thrust/system/detail/adl/binary_search.h | 7 +- thrust/system/detail/adl/copy.h | 1 - thrust/system/detail/adl/copy_if.h | 1 - thrust/system/detail/adl/count.h | 1 - thrust/system/detail/adl/equal.h | 1 - thrust/system/detail/adl/extrema.h | 1 - thrust/system/detail/adl/fill.h | 1 - thrust/system/detail/adl/find.h | 1 - thrust/system/detail/adl/for_each.h | 1 - thrust/system/detail/adl/gather.h | 1 - thrust/system/detail/adl/generate.h | 1 - thrust/system/detail/adl/get_value.h | 1 - thrust/system/detail/adl/inner_product.h | 7 +- thrust/system/detail/adl/iter_swap.h | 1 - thrust/system/detail/adl/logical.h | 1 - thrust/system/detail/adl/malloc_and_free.h | 7 +- thrust/system/detail/adl/merge.h | 1 - thrust/system/detail/adl/mismatch.h | 1 - thrust/system/detail/adl/partition.h | 1 - thrust/system/detail/adl/reduce.h | 1 - thrust/system/detail/adl/reduce_by_key.h | 7 +- thrust/system/detail/adl/remove.h | 1 - thrust/system/detail/adl/replace.h | 1 - thrust/system/detail/adl/reverse.h | 1 - thrust/system/detail/adl/scan.h | 1 - thrust/system/detail/adl/scan_by_key.h | 4 +- thrust/system/detail/adl/scatter.h | 1 - thrust/system/detail/adl/sequence.h | 1 - thrust/system/detail/adl/set_operations.h | 7 +- thrust/system/detail/adl/sort.h | 1 - thrust/system/detail/adl/swap_ranges.h | 4 +- thrust/system/detail/adl/tabulate.h | 1 - thrust/system/detail/adl/temporary_buffer.h | 7 +- thrust/system/detail/adl/transform.h | 1 - thrust/system/detail/adl/transform_reduce.h | 7 +- thrust/system/detail/adl/transform_scan.h | 7 +- thrust/system/detail/adl/uninitialized_copy.h | 7 +- thrust/system/detail/adl/uninitialized_fill.h | 7 +- thrust/system/detail/adl/unique.h | 1 - thrust/system/detail/adl/unique_by_key.h | 7 +- thrust/system/detail/bad_alloc.h | 64 +- thrust/system/detail/errno.h | 172 +- .../detail/generic/adjacent_difference.h | 56 +- thrust/system/detail/generic/advance.h | 29 +- thrust/system/detail/generic/binary_search.h | 306 +- thrust/system/detail/generic/copy.h | 60 +- thrust/system/detail/generic/copy_if.h | 72 +- thrust/system/detail/generic/count.h | 51 +- thrust/system/detail/generic/distance.h | 32 +- thrust/system/detail/generic/equal.h | 48 +- thrust/system/detail/generic/extrema.h | 113 +- thrust/system/detail/generic/fill.h | 70 +- thrust/system/detail/generic/find.h | 68 +- thrust/system/detail/generic/for_each.h | 78 +- thrust/system/detail/generic/gather.h | 96 +- thrust/system/detail/generic/generate.h | 57 +- thrust/system/detail/generic/inner_product.h | 69 +- thrust/system/detail/generic/logical.h | 67 +- thrust/system/detail/generic/memory.h | 56 +- thrust/system/detail/generic/merge.h | 140 +- thrust/system/detail/generic/mismatch.h | 60 +- thrust/system/detail/generic/partition.h | 256 +- thrust/system/detail/generic/reduce.h | 66 +- thrust/system/detail/generic/reduce_by_key.h | 111 +- thrust/system/detail/generic/remove.h | 153 +- thrust/system/detail/generic/replace.h | 151 +- thrust/system/detail/generic/reverse.h | 54 +- .../detail/generic/scalar/binary_search.h | 89 +- thrust/system/detail/generic/scan.h | 134 +- thrust/system/detail/generic/scan_by_key.h | 219 +- thrust/system/detail/generic/scatter.h | 93 +- thrust/system/detail/generic/select_system.h | 293 +- thrust/system/detail/generic/sequence.h | 66 +- thrust/system/detail/generic/set_operations.h | 558 ++- thrust/system/detail/generic/sort.h | 228 +- thrust/system/detail/generic/swap_ranges.h | 40 +- thrust/system/detail/generic/tabulate.h | 39 +- thrust/system/detail/generic/tag.h | 41 +- .../system/detail/generic/temporary_buffer.h | 50 +- thrust/system/detail/generic/transform.h | 147 +- .../system/detail/generic/transform_reduce.h | 50 +- thrust/system/detail/generic/transform_scan.h | 74 +- thrust/system/detail/generic/type_traits.h | 324 +- .../detail/generic/uninitialized_copy.h | 60 +- .../detail/generic/uninitialized_fill.h | 58 +- thrust/system/detail/generic/unique.h | 85 +- thrust/system/detail/generic/unique_by_key.h | 118 +- thrust/system/detail/internal/decompose.h | 182 +- .../detail/sequential/adjacent_difference.h | 71 +- .../system/detail/sequential/assign_value.h | 34 +- .../system/detail/sequential/binary_search.h | 238 +- thrust/system/detail/sequential/copy.h | 60 +- .../system/detail/sequential/copy_backward.h | 58 +- thrust/system/detail/sequential/copy_if.h | 74 +- thrust/system/detail/sequential/count.h | 1 - thrust/system/detail/sequential/equal.h | 1 - .../detail/sequential/execution_policy.h | 86 +- thrust/system/detail/sequential/extrema.h | 200 +- thrust/system/detail/sequential/fill.h | 1 - thrust/system/detail/sequential/find.h | 75 +- thrust/system/detail/sequential/for_each.h | 120 +- thrust/system/detail/sequential/gather.h | 1 - .../system/detail/sequential/general_copy.h | 203 +- thrust/system/detail/sequential/generate.h | 1 - thrust/system/detail/sequential/get_value.h | 40 +- .../system/detail/sequential/inner_product.h | 1 - .../system/detail/sequential/insertion_sort.h | 242 +- thrust/system/detail/sequential/iter_swap.h | 40 +- thrust/system/detail/sequential/logical.h | 1 - .../detail/sequential/malloc_and_free.h | 56 +- thrust/system/detail/sequential/merge.h | 88 +- thrust/system/detail/sequential/mismatch.h | 1 - thrust/system/detail/sequential/partition.h | 573 ++- thrust/system/detail/sequential/reduce.h | 70 +- .../system/detail/sequential/reduce_by_key.h | 157 +- thrust/system/detail/sequential/remove.h | 321 +- thrust/system/detail/sequential/replace.h | 1 - thrust/system/detail/sequential/reverse.h | 1 - thrust/system/detail/sequential/scan.h | 243 +- thrust/system/detail/sequential/scan_by_key.h | 229 +- thrust/system/detail/sequential/scatter.h | 1 - thrust/system/detail/sequential/sequence.h | 1 - .../system/detail/sequential/set_operations.h | 367 +- thrust/system/detail/sequential/sort.h | 64 +- .../detail/sequential/stable_merge_sort.h | 64 +- .../detail/sequential/stable_primitive_sort.h | 55 +- .../detail/sequential/stable_radix_sort.h | 55 +- thrust/system/detail/sequential/swap_ranges.h | 1 - thrust/system/detail/sequential/tabulate.h | 1 - .../detail/sequential/temporary_buffer.h | 1 - thrust/system/detail/sequential/transform.h | 1 - .../detail/sequential/transform_reduce.h | 1 - .../system/detail/sequential/transform_scan.h | 3 +- .../system/detail/sequential/trivial_copy.h | 44 +- .../detail/sequential/uninitialized_copy.h | 3 +- .../detail/sequential/uninitialized_fill.h | 1 - thrust/system/detail/sequential/unique.h | 128 +- .../system/detail/sequential/unique_by_key.h | 171 +- thrust/system/error_code.h | 786 ++-- .../system/omp/detail/adjacent_difference.h | 48 +- thrust/system/omp/detail/assign_value.h | 1 - thrust/system/omp/detail/binary_search.h | 98 +- thrust/system/omp/detail/copy.h | 56 +- thrust/system/omp/detail/copy_if.h | 47 +- thrust/system/omp/detail/count.h | 1 - .../system/omp/detail/default_decomposition.h | 29 +- thrust/system/omp/detail/equal.h | 1 - thrust/system/omp/detail/execution_policy.h | 170 +- thrust/system/omp/detail/extrema.h | 83 +- thrust/system/omp/detail/fill.h | 1 - thrust/system/omp/detail/find.h | 42 +- thrust/system/omp/detail/for_each.h | 56 +- thrust/system/omp/detail/gather.h | 1 - thrust/system/omp/detail/generate.h | 1 - thrust/system/omp/detail/get_value.h | 1 - thrust/system/omp/detail/inner_product.h | 1 - thrust/system/omp/detail/iter_swap.h | 1 - thrust/system/omp/detail/logical.h | 1 - thrust/system/omp/detail/malloc_and_free.h | 1 - thrust/system/omp/detail/merge.h | 1 - thrust/system/omp/detail/mismatch.h | 1 - thrust/system/omp/detail/par.h | 83 +- thrust/system/omp/detail/partition.h | 106 +- thrust/system/omp/detail/reduce.h | 44 +- thrust/system/omp/detail/reduce_by_key.h | 58 +- thrust/system/omp/detail/reduce_intervals.h | 44 +- thrust/system/omp/detail/remove.h | 93 +- thrust/system/omp/detail/replace.h | 1 - thrust/system/omp/detail/reverse.h | 1 - thrust/system/omp/detail/scan.h | 1 - thrust/system/omp/detail/scan_by_key.h | 1 - thrust/system/omp/detail/scatter.h | 1 - thrust/system/omp/detail/sequence.h | 1 - thrust/system/omp/detail/set_operations.h | 1 - thrust/system/omp/detail/sort.h | 53 +- thrust/system/omp/detail/swap_ranges.h | 1 - thrust/system/omp/detail/tabulate.h | 1 - thrust/system/omp/detail/temporary_buffer.h | 1 - thrust/system/omp/detail/transform.h | 1 - thrust/system/omp/detail/transform_reduce.h | 1 - thrust/system/omp/detail/transform_scan.h | 1 - thrust/system/omp/detail/uninitialized_copy.h | 1 - thrust/system/omp/detail/uninitialized_fill.h | 1 - thrust/system/omp/detail/unique.h | 62 +- thrust/system/omp/detail/unique_by_key.h | 78 +- thrust/system/omp/execution_policy.h | 3 - thrust/system/omp/memory.h | 380 +- thrust/system/omp/vector.h | 134 +- thrust/system/system_error.h | 203 +- .../system/tbb/detail/adjacent_difference.h | 48 +- thrust/system/tbb/detail/assign_value.h | 1 - thrust/system/tbb/detail/binary_search.h | 1 - thrust/system/tbb/detail/copy.h | 56 +- thrust/system/tbb/detail/copy_if.h | 45 +- thrust/system/tbb/detail/count.h | 1 - thrust/system/tbb/detail/equal.h | 1 - thrust/system/tbb/detail/execution_policy.h | 125 +- thrust/system/tbb/detail/extrema.h | 83 +- thrust/system/tbb/detail/fill.h | 1 - thrust/system/tbb/detail/find.h | 37 +- thrust/system/tbb/detail/for_each.h | 55 +- thrust/system/tbb/detail/gather.h | 1 - thrust/system/tbb/detail/generate.h | 1 - thrust/system/tbb/detail/get_value.h | 1 - thrust/system/tbb/detail/inner_product.h | 1 - thrust/system/tbb/detail/iter_swap.h | 1 - thrust/system/tbb/detail/logical.h | 1 - thrust/system/tbb/detail/malloc_and_free.h | 1 - thrust/system/tbb/detail/merge.h | 81 +- thrust/system/tbb/detail/mismatch.h | 1 - thrust/system/tbb/detail/par.h | 83 +- thrust/system/tbb/detail/partition.h | 106 +- thrust/system/tbb/detail/reduce.h | 44 +- thrust/system/tbb/detail/reduce_by_key.h | 59 +- thrust/system/tbb/detail/reduce_intervals.h | 224 +- thrust/system/tbb/detail/remove.h | 93 +- thrust/system/tbb/detail/replace.h | 1 - thrust/system/tbb/detail/reverse.h | 1 - thrust/system/tbb/detail/scan.h | 62 +- thrust/system/tbb/detail/scan_by_key.h | 1 - thrust/system/tbb/detail/scatter.h | 1 - thrust/system/tbb/detail/sequence.h | 1 - thrust/system/tbb/detail/set_operations.h | 1 - thrust/system/tbb/detail/sort.h | 57 +- thrust/system/tbb/detail/swap_ranges.h | 1 - thrust/system/tbb/detail/tabulate.h | 1 - thrust/system/tbb/detail/temporary_buffer.h | 1 - thrust/system/tbb/detail/transform.h | 1 - thrust/system/tbb/detail/transform_reduce.h | 1 - thrust/system/tbb/detail/transform_scan.h | 1 - thrust/system/tbb/detail/uninitialized_copy.h | 1 - thrust/system/tbb/detail/uninitialized_fill.h | 1 - thrust/system/tbb/detail/unique.h | 62 +- thrust/system/tbb/detail/unique_by_key.h | 78 +- thrust/system/tbb/execution_policy.h | 3 - thrust/system/tbb/memory.h | 380 +- thrust/system/tbb/vector.h | 129 +- thrust/system_error.h | 28 +- thrust/tabulate.h | 83 +- thrust/transform.h | 839 ++-- thrust/transform_reduce.h | 119 +- thrust/transform_scan.h | 274 +- thrust/tuple.h | 871 ++-- thrust/uninitialized_copy.h | 233 +- thrust/uninitialized_fill.h | 158 +- thrust/unique.h | 812 ++-- thrust/version.h | 15 +- 650 files changed, 50920 insertions(+), 48870 deletions(-) create mode 100644 .clang-format create mode 100755 .githooks/install create mode 100755 .githooks/pre-commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a04f49b --- /dev/null +++ b/.clang-format @@ -0,0 +1,120 @@ +# Style file for MLSE Libraries based on the modified rocBLAS style + +# Common settings +BasedOnStyle: WebKit +TabWidth: 4 +IndentWidth: 4 +UseTab: Never +ColumnLimit: 100 + +# Other languages JavaScript, Proto + +--- +Language: Cpp + +# http://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code +# int formatted_code; +# // clang-format off +# void unformatted_code ; +# // clang-format on +# void formatted_code_again; + +DisableFormat: false +Standard: Cpp11 + +AccessModifierOffset: -4 +AlignAfterOpenBracket: true +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false + +# Configure each individual brace in BraceWrapping +BreakBeforeBraces: Custom +# Control of individual brace wrapping cases +BraceWrapping: { + AfterClass: 'true' + AfterControlStatement: 'true' + AfterEnum : 'true' + AfterFunction : 'true' + AfterNamespace : 'true' + AfterStruct : 'true' + AfterUnion : 'true' + BeforeCatch : 'true' + BeforeElse : 'true' + IndentBraces : 'false' +# AfterExternBlock : 'true' +} + +#BreakAfterJavaFieldAnnotations: true +#BreakBeforeInheritanceComma: false +#BreakBeforeBinaryOperators: None +#BreakBeforeTernaryOperators: true +#BreakConstructorInitializersBeforeComma: true +#BreakStringLiterals: true + +CommentPragmas: '^ IWYU pragma:' +#CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +#SpaceBeforeCpp11BracedList: false +DerivePointerAlignment: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IndentCaseLabels: false +#FixNamespaceComments: true +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +#JavaScriptQuotes: Double +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBlockIndentWidth: 4 +#ObjCSpaceAfterProperty: true +#ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 + +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: Never +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +#SpaceAfterTemplateKeyword: true +#SpaceBeforeInheritanceColon: true + +#SortUsingDeclarations: true +SortIncludes: true + +# Comments are for developers, they should arrange them +ReflowComments: false + +#IncludeBlocks: Preserve +#IndentPPDirectives: AfterHash +--- diff --git a/.githooks/install b/.githooks/install new file mode 100755 index 0000000..cbb0569 --- /dev/null +++ b/.githooks/install @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd $(git rev-parse --git-dir) +cd hooks + +echo "Installing hooks..." +ln -s ../../.githooks/pre-commit pre-commit +echo "Done!" diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..aea1a69 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,43 @@ +#!/bin/sh +# +# This pre-commit hook checks if any versions of clang-format +# are installed, and if so, uses the installed version to format +# the staged changes. + +base=/opt/rocm/hcc/bin/clang-format +format="" + +# Redirect output to stderr. +exec 1>&2 + + # check if clang-format is installed +type "$base" >/dev/null 2>&1 && format="$base" + +# no versions of clang-format are installed +if [ -z "$format" ] +then + echo "$base is not installed. Pre-commit hook will not be executed." + exit 0 +fi + +# Do everything from top - level +cd $(git rev-parse --show-toplevel) + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# do the formatting +for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$') +do + if [ -e "$file" ] + then + echo "$format $file" + "$format" -i -style=file "$file" + fi +done + diff --git a/Jenkinsfile b/Jenkinsfile index 0d3d81d..fbadf4e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,6 @@ #!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ -@Library('rocJenkins') _ +@Library('rocJenkins@clang9') _ // This is file for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. diff --git a/examples/cpp_integration/device.h b/examples/cpp_integration/device.h index e398edf..0ecf9d0 100644 --- a/examples/cpp_integration/device.h +++ b/examples/cpp_integration/device.h @@ -4,4 +4,3 @@ // function prototype void sort_on_device(thrust::host_vector& V); - diff --git a/examples/cpp_integration/host.cpp b/examples/cpp_integration/host.cpp index 009f3fa..2a17568 100644 --- a/examples/cpp_integration/host.cpp +++ b/examples/cpp_integration/host.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include // defines the function prototype #include "device.h" @@ -12,7 +12,7 @@ int main(void) { // generate 20 random numbers on the host - thrust::host_vector h_vec(20); + thrust::host_vector h_vec(20); thrust::default_random_engine rng; thrust::generate(h_vec.begin(), h_vec.end(), rng); @@ -24,4 +24,3 @@ int main(void) return 0; } - diff --git a/examples/include/timer.h b/examples/include/timer.h index 66c1d2d..bfd91cf 100644 --- a/examples/include/timer.h +++ b/examples/include/timer.h @@ -22,53 +22,53 @@ // use CUDA's high-resolution timers when possible #include +#include #include #include -#include void cuda_safe_call(hipError_t error, const std::string& message = "") { - if(error) - throw thrust::system_error(error, thrust::cuda_category(), message); + if(error) + throw thrust::system_error(error, thrust::cuda_category(), message); } struct timer { - hipEvent_t start; - hipEvent_t end; - - timer(void) - { - cuda_safe_call(hipEventCreate(&start)); - cuda_safe_call(hipEventCreate(&end)); - restart(); - } - - ~timer(void) - { - cuda_safe_call(hipEventDestroy(start)); - cuda_safe_call(hipEventDestroy(end)); - } - - void restart(void) - { - cuda_safe_call(hipEventRecord(start, 0)); - } - - double elapsed(void) - { - cuda_safe_call(hipEventRecord(end, 0)); - cuda_safe_call(hipEventSynchronize(end)); - - float ms_elapsed; - cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end)); - return ms_elapsed / 1e3; - } - - double epsilon(void) - { - return 0.5e-6; - } + hipEvent_t start; + hipEvent_t end; + + timer(void) + { + cuda_safe_call(hipEventCreate(&start)); + cuda_safe_call(hipEventCreate(&end)); + restart(); + } + + ~timer(void) + { + cuda_safe_call(hipEventDestroy(start)); + cuda_safe_call(hipEventDestroy(end)); + } + + void restart(void) + { + cuda_safe_call(hipEventRecord(start, 0)); + } + + double elapsed(void) + { + cuda_safe_call(hipEventRecord(end, 0)); + cuda_safe_call(hipEventSynchronize(end)); + + float ms_elapsed; + cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end)); + return ms_elapsed / 1e3; + } + + double epsilon(void) + { + return 0.5e-6; + } }; #else @@ -78,35 +78,32 @@ struct timer struct timer { - clock_t start; - clock_t end; - - timer(void) - { - restart(); - } - - ~timer(void) - { - } - - void restart(void) - { - start = clock(); - } - - double elapsed(void) - { - end = clock(); - - return static_cast(end - start) / static_cast(CLOCKS_PER_SEC); - } - - double epsilon(void) - { - return 1.0 / static_cast(CLOCKS_PER_SEC); - } + clock_t start; + clock_t end; + + timer(void) + { + restart(); + } + + ~timer(void) {} + + void restart(void) + { + start = clock(); + } + + double elapsed(void) + { + end = clock(); + + return static_cast(end - start) / static_cast(CLOCKS_PER_SEC); + } + + double epsilon(void) + { + return 1.0 / static_cast(CLOCKS_PER_SEC); + } }; #endif - diff --git a/performance/build/perftest.h b/performance/build/perftest.h index 4dc195c..b61c52e 100644 --- a/performance/build/perftest.h +++ b/performance/build/perftest.h @@ -1,53 +1,76 @@ -#include +#include #include #include -#include - +#include #include //#include -#define RECORD_RESULT(name, value, units) { std::cout << " " << std::endl; } -#define RECORD_TIME() RECORD_RESULT("Time", best_time, "seconds") -#define RECORD_RATE(name, value, units) RECORD_RESULT(name, (double(value)/best_time), units) -#define RECORD_BANDWIDTH(bytes) RECORD_RATE("Bandwidth", double(bytes) / 1e9, "GBytes/s") -#define RECORD_THROUGHPUT(value) RECORD_RATE("Throughput", double(value) / 1e9, "GOp/s") -#define RECORD_SORTING_RATE(size) RECORD_RATE("Sorting", double(size) / 1e6, "MKeys/s") -#define RECORD_VARIABLE(name, value) { std::cout << " " << std::endl; } -#define RECORD_TEST_STATUS(result, message) { std::cout << " " << std::endl; } -#define RECORD_TEST_SUCCESS() RECORD_TEST_STATUS("Success", "") -#define RECORD_TEST_FAILURE(message) RECORD_TEST_STATUS("Failure", message) -#define BEGIN_TEST(name) { std::cout << "" << std::endl; } -#define END_TEST() { std::cout << "" << std::endl; } -#define BEGIN_TESTSUITE(name) { std::cout << "" << std::endl << "" << std::endl; } -#define END_TESTSUITE() { std::cout << "" << std::endl; } - +#define RECORD_RESULT(name, value, units) \ + { \ + std::cout << " " << std::endl; \ + } +#define RECORD_TIME() RECORD_RESULT("Time", best_time, "seconds") +#define RECORD_RATE(name, value, units) RECORD_RESULT(name, (double(value) / best_time), units) +#define RECORD_BANDWIDTH(bytes) RECORD_RATE("Bandwidth", double(bytes) / 1e9, "GBytes/s") +#define RECORD_THROUGHPUT(value) RECORD_RATE("Throughput", double(value) / 1e9, "GOp/s") +#define RECORD_SORTING_RATE(size) RECORD_RATE("Sorting", double(size) / 1e6, "MKeys/s") +#define RECORD_VARIABLE(name, value) \ + { \ + std::cout << " " \ + << std::endl; \ + } +#define RECORD_TEST_STATUS(result, message) \ + { \ + std::cout << " " \ + << std::endl; \ + } +#define RECORD_TEST_SUCCESS() RECORD_TEST_STATUS("Success", "") +#define RECORD_TEST_FAILURE(message) RECORD_TEST_STATUS("Failure", message) +#define BEGIN_TEST(name) \ + { \ + std::cout << "" << std::endl; \ + } +#define END_TEST() \ + { \ + std::cout << "" << std::endl; \ + } +#define BEGIN_TESTSUITE(name) \ + { \ + std::cout << "" << std::endl \ + << "" << std::endl; \ + } +#define END_TESTSUITE() \ + { \ + std::cout << "" << std::endl; \ + } -#if defined(__GNUC__) // GCC +#if defined(__GNUC__) // GCC #define __HOST_COMPILER_NAME__ "GCC" -# if defined(__GNUC_PATCHLEVEL__) +#if defined(__GNUC_PATCHLEVEL__) #define __HOST_COMPILER_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -# else +#else #define __HOST_COMPILER_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) -# endif +#endif #elif defined(_MSC_VER) // Microsoft Visual C++ #define __HOST_COMPILER_NAME__ "MSVC" -#define __HOST_COMPILER_VERSION__ _MSC_VER +#define __HOST_COMPILER_VERSION__ _MSC_VER #elif defined(__INTEL_COMPILER) // Intel Compiler #define __HOST_COMPILER_NAME__ "ICC" -#define __HOST_COMPILER_VERSION__ __INTEL_COMPILER +#define __HOST_COMPILER_VERSION__ __INTEL_COMPILER #else // Unknown #define __HOST_COMPILER_NAME__ "UNKNOWN" #define __HOST_COMPILER_VERSION__ 0 #endif - inline void RECORD_PLATFORM_INFO(void) { -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA int deviceCount; hipGetDeviceCount(&deviceCount); - if (deviceCount == 0){ + if(deviceCount == 0) + { std::cerr << "There is no device supporting CUDA" << std::endl; exit(1); } @@ -57,28 +80,49 @@ inline void RECORD_PLATFORM_INFO(void) hipDeviceProp_t deviceProp; hipGetDeviceProperties(&deviceProp, dev); - if (dev == 0 && deviceProp.major == 9999 && deviceProp.minor == 9999){ + if(dev == 0 && deviceProp.major == 9999 && deviceProp.minor == 9999) + { std::cerr << "There is no device supporting CUDA" << std::endl; exit(1); } std::cout << "" << std::endl; std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; - std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; - #ifdef __HIP_PLATFORM_NVCC__ - std::cout << " " << std::endl; - #endif - std::cout << " " << std::endl; +#ifdef __HIP_PLATFORM_NVCC__ + std::cout << " " + << std::endl; +#endif + std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; std::cout << " " << std::endl; @@ -86,26 +130,23 @@ inline void RECORD_PLATFORM_INFO(void) #endif } - -inline void PROCESS_ARGUMENTS(int argc, char **argv) +inline void PROCESS_ARGUMENTS(int argc, char** argv) { - for(int i = 1; i < argc; ++i) - { - if(std::string(argv[i]) == "--device") + for(int i = 1; i < argc; ++i) { - ++i; - if(i == argc) - { - std::cerr << "usage: --device n" << std::endl; - exit(-1); - } + if(std::string(argv[i]) == "--device") + { + ++i; + if(i == argc) + { + std::cerr << "usage: --device n" << std::endl; + exit(-1); + } -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA - int device_index = atoi(argv[i]); - hipSetDevice(device_index); +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + int device_index = atoi(argv[i]); + hipSetDevice(device_index); #endif + } } - } } - - diff --git a/performance/build/timer.h b/performance/build/timer.h index f3f6066..9400abd 100644 --- a/performance/build/timer.h +++ b/performance/build/timer.h @@ -22,53 +22,53 @@ // use CUDA's high-resolution timers when possible #include +#include #include #include -#include void cuda_safe_call(hipError_t error, const std::string& message = "") { - if(error) - throw thrust::system_error(error, thrust::cuda_category(), message); + if(error) + throw thrust::system_error(error, thrust::cuda_category(), message); } struct timer { - hipEvent_t start; - hipEvent_t end; - - timer(void) - { - cuda_safe_call(hipEventCreate(&start)); - cuda_safe_call(hipEventCreate(&end)); - restart(); - } - - ~timer(void) - { - cuda_safe_call(hipEventDestroy(start)); - cuda_safe_call(hipEventDestroy(end)); - } - - void restart(void) - { - cuda_safe_call(hipEventRecord(start, 0)); - } - - double elapsed(void) - { - cuda_safe_call(hipEventRecord(end, 0)); - cuda_safe_call(hipEventSynchronize(end)); - - float ms_elapsed; - cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end)); - return ms_elapsed / 1e3; - } - - double epsilon(void) - { - return 0.5e-6; - } + hipEvent_t start; + hipEvent_t end; + + timer(void) + { + cuda_safe_call(hipEventCreate(&start)); + cuda_safe_call(hipEventCreate(&end)); + restart(); + } + + ~timer(void) + { + cuda_safe_call(hipEventDestroy(start)); + cuda_safe_call(hipEventDestroy(end)); + } + + void restart(void) + { + cuda_safe_call(hipEventRecord(start, 0)); + } + + double elapsed(void) + { + cuda_safe_call(hipEventRecord(end, 0)); + cuda_safe_call(hipEventSynchronize(end)); + + float ms_elapsed; + cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end)); + return ms_elapsed / 1e3; + } + + double epsilon(void) + { + return 0.5e-6; + } }; #elif defined(__linux__) @@ -77,34 +77,33 @@ struct timer struct timer { - timeval start; - timeval end; - - timer(void) - { - restart(); - } - - ~timer(void) - { - } - - void restart(void) - { - gettimeofday(&start, NULL); - } - - double elapsed(void) - { - gettimeofday(&end, NULL); - - return static_cast(end.tv_sec - start.tv_sec) + 1e-6 * static_cast((int)end.tv_usec - (int)start.tv_usec); - } - - double epsilon(void) - { - return 0.5e-6; - } + timeval start; + timeval end; + + timer(void) + { + restart(); + } + + ~timer(void) {} + + void restart(void) + { + gettimeofday(&start, NULL); + } + + double elapsed(void) + { + gettimeofday(&end, NULL); + + return static_cast(end.tv_sec - start.tv_sec) + + 1e-6 * static_cast((int)end.tv_usec - (int)start.tv_usec); + } + + double epsilon(void) + { + return 0.5e-6; + } }; #else @@ -114,35 +113,32 @@ struct timer struct timer { - clock_t start; - clock_t end; - - timer(void) - { - restart(); - } - - ~timer(void) - { - } - - void restart(void) - { - start = clock(); - } - - double elapsed(void) - { - end = clock(); - - return static_cast(end - start) / static_cast(CLOCKS_PER_SEC); - } - - double epsilon(void) - { - return 1.0 / static_cast(CLOCKS_PER_SEC); - } + clock_t start; + clock_t end; + + timer(void) + { + restart(); + } + + ~timer(void) {} + + void restart(void) + { + start = clock(); + } + + double elapsed(void) + { + end = clock(); + + return static_cast(end - start) / static_cast(CLOCKS_PER_SEC); + } + + double epsilon(void) + { + return 1.0 / static_cast(CLOCKS_PER_SEC); + } }; #endif - diff --git a/testing/backend/omp/nvcc_independence.cpp b/testing/backend/omp/nvcc_independence.cpp index c870928..2613de4 100644 --- a/testing/backend/omp/nvcc_independence.cpp +++ b/testing/backend/omp/nvcc_independence.cpp @@ -1,75 +1,74 @@ -#include #include -#include #include #include #include #include +#include +#include void TestNvccIndependenceTransform(void) { - typedef int T; - const int n = 10; + typedef int T; + const int n = 10; + + thrust::host_vector h_input = unittest::random_integers(n); + thrust::device_vector d_input = h_input; - thrust::host_vector h_input = unittest::random_integers(n); - thrust::device_vector d_input = h_input; + thrust::host_vector h_output(n); + thrust::device_vector d_output(n); - thrust::host_vector h_output(n); - thrust::device_vector d_output(n); + thrust::transform(h_input.begin(), h_input.end(), h_output.begin(), thrust::negate()); + thrust::transform(d_input.begin(), d_input.end(), d_output.begin(), thrust::negate()); - thrust::transform(h_input.begin(), h_input.end(), h_output.begin(), thrust::negate()); - thrust::transform(d_input.begin(), d_input.end(), d_output.begin(), thrust::negate()); - - ASSERT_EQUAL(h_output, d_output); + ASSERT_EQUAL(h_output, d_output); } DECLARE_UNITTEST(TestNvccIndependenceTransform); void TestNvccIndependenceReduce(void) { - typedef int T; - const int n = 10; + typedef int T; + const int n = 10; - thrust::host_vector h_data = unittest::random_integers(n); - thrust::device_vector d_data = h_data; + thrust::host_vector h_data = unittest::random_integers(n); + thrust::device_vector d_data = h_data; - T init = 13; + T init = 13; - T h_result = thrust::reduce(h_data.begin(), h_data.end(), init); - T d_result = thrust::reduce(d_data.begin(), d_data.end(), init); + T h_result = thrust::reduce(h_data.begin(), h_data.end(), init); + T d_result = thrust::reduce(d_data.begin(), d_data.end(), init); - ASSERT_ALMOST_EQUAL(h_result, d_result); + ASSERT_ALMOST_EQUAL(h_result, d_result); } DECLARE_UNITTEST(TestNvccIndependenceReduce); void TestNvccIndependenceExclusiveScan(void) { - typedef int T; - const int n = 10; - - thrust::host_vector h_input = unittest::random_integers(n); - thrust::device_vector d_input = h_input; - - thrust::host_vector h_output(n); - thrust::device_vector d_output(n); - - thrust::inclusive_scan(h_input.begin(), h_input.end(), h_output.begin()); - thrust::inclusive_scan(d_input.begin(), d_input.end(), d_output.begin()); - ASSERT_EQUAL(d_output, h_output); + typedef int T; + const int n = 10; + + thrust::host_vector h_input = unittest::random_integers(n); + thrust::device_vector d_input = h_input; + + thrust::host_vector h_output(n); + thrust::device_vector d_output(n); + + thrust::inclusive_scan(h_input.begin(), h_input.end(), h_output.begin()); + thrust::inclusive_scan(d_input.begin(), d_input.end(), d_output.begin()); + ASSERT_EQUAL(d_output, h_output); } DECLARE_UNITTEST(TestNvccIndependenceExclusiveScan); void TestNvccIndependenceSort(void) { - typedef int T; - const int n = 10; + typedef int T; + const int n = 10; - thrust::host_vector h_data = unittest::random_integers(n); - thrust::device_vector d_data = h_data; + thrust::host_vector h_data = unittest::random_integers(n); + thrust::device_vector d_data = h_data; - thrust::sort(h_data.begin(), h_data.end(), thrust::less()); - thrust::sort(d_data.begin(), d_data.end(), thrust::less()); + thrust::sort(h_data.begin(), h_data.end(), thrust::less()); + thrust::sort(d_data.begin(), d_data.end(), thrust::less()); - ASSERT_EQUAL(h_data, d_data); + ASSERT_EQUAL(h_data, d_data); } DECLARE_UNITTEST(TestNvccIndependenceSort); - diff --git a/testing/testframework.cpp b/testing/testframework.cpp index 57006b0..a5b6a35 100644 --- a/testing/testframework.cpp +++ b/testing/testframework.cpp @@ -2,520 +2,614 @@ #include "unittest/exceptions.h" #include -// #include backends' testframework.h, if they exist and are required for the build +// #include backends' testframework.h, if they exist and are required for the +// build #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA #include "backend/cuda/testframework.h" #endif -#include -#include -#include #include -#include -#include -#include +#include #include +#include +#include #include +#include +#include - -const size_t standard_test_sizes[] = -{ - 0, 1, 2, 3, 4, 5, 8, 10, 13, 16, 17, 19, 27, 30, 31, 32, - 33, 35, 42, 53, 58, 63, 64, 65, 72, 97, 100, 127, 128, 129, 142, 183, 192, 201, 240, 255, 256, - 257, 302, 511, 512, 513, 687, 900, 1023, 1024, 1025, 1565, 1786, 1973, 2047, 2048, 2049, 3050, 4095, 4096, - 4097, 5030, 7791, 10000, 10027, 12345, 16384, 17354, 26255, 32768, 43718, 65533, 65536, - 65539, 123456, 131072, 731588, 1048575, 1048576, - 3398570, 9760840, (1 << 24) - 1, (1 << 24), - (1 << 24) + 1, (1 << 25) - 1, (1 << 25), (1 << 25) + 1, (1 << 26) - 1, 1 << 26, - (1 << 26) + 1, (1 << 27) - 1, (1 << 27) -}; - - -const size_t tiny_threshold = 1 << 5; // 32 -const size_t small_threshold = 1 << 8; // 256 -const size_t medium_threshold = 1 << 12; // 4K -const size_t default_threshold = 1 << 16; // 64K -const size_t large_threshold = 1 << 20; // 1M -const size_t huge_threshold = 1 << 24; // 16M -const size_t epic_threshold = 1 << 26; // 64M +const size_t standard_test_sizes[] = {0, + 1, + 2, + 3, + 4, + 5, + 8, + 10, + 13, + 16, + 17, + 19, + 27, + 30, + 31, + 32, + 33, + 35, + 42, + 53, + 58, + 63, + 64, + 65, + 72, + 97, + 100, + 127, + 128, + 129, + 142, + 183, + 192, + 201, + 240, + 255, + 256, + 257, + 302, + 511, + 512, + 513, + 687, + 900, + 1023, + 1024, + 1025, + 1565, + 1786, + 1973, + 2047, + 2048, + 2049, + 3050, + 4095, + 4096, + 4097, + 5030, + 7791, + 10000, + 10027, + 12345, + 16384, + 17354, + 26255, + 32768, + 43718, + 65533, + 65536, + 65539, + 123456, + 131072, + 731588, + 1048575, + 1048576, + 3398570, + 9760840, + (1 << 24) - 1, + (1 << 24), + (1 << 24) + 1, + (1 << 25) - 1, + (1 << 25), + (1 << 25) + 1, + (1 << 26) - 1, + 1 << 26, + (1 << 26) + 1, + (1 << 27) - 1, + (1 << 27)}; + +const size_t tiny_threshold = 1 << 5; // 32 +const size_t small_threshold = 1 << 8; // 256 +const size_t medium_threshold = 1 << 12; // 4K +const size_t default_threshold = 1 << 16; // 64K +const size_t large_threshold = 1 << 20; // 1M +const size_t huge_threshold = 1 << 24; // 16M +const size_t epic_threshold = 1 << 26; // 64M const size_t max_threshold = std::numeric_limits::max(); - std::vector test_sizes; - std::vector get_test_sizes(void) { - return test_sizes; + return test_sizes; } - void set_test_sizes(const std::string& val) { - size_t threshold = 0; - - if(val == "tiny") - threshold = tiny_threshold; - else if(val == "small") - threshold = small_threshold; - else if(val == "medium") - threshold = medium_threshold; - else if(val == "default") - threshold = default_threshold; - else if(val == "large") - threshold = large_threshold; - else if(val == "huge") - threshold = huge_threshold; - else if(val == "epic") - threshold = epic_threshold; - else if(val == "max") - threshold = max_threshold; - else - { - std::cerr << "invalid test size \"" << val << "\"" << std::endl; - exit(1); - } - - for(size_t i = 0; i < sizeof(standard_test_sizes) / sizeof(*standard_test_sizes); i++) - { - if(standard_test_sizes[i] <= threshold) - test_sizes.push_back(standard_test_sizes[i]); - } -} + size_t threshold = 0; + + if(val == "tiny") + threshold = tiny_threshold; + else if(val == "small") + threshold = small_threshold; + else if(val == "medium") + threshold = medium_threshold; + else if(val == "default") + threshold = default_threshold; + else if(val == "large") + threshold = large_threshold; + else if(val == "huge") + threshold = huge_threshold; + else if(val == "epic") + threshold = epic_threshold; + else if(val == "max") + threshold = max_threshold; + else + { + std::cerr << "invalid test size \"" << val << "\"" << std::endl; + exit(1); + } + for(size_t i = 0; i < sizeof(standard_test_sizes) / sizeof(*standard_test_sizes); i++) + { + if(standard_test_sizes[i] <= threshold) + test_sizes.push_back(standard_test_sizes[i]); + } +} -void UnitTestDriver::register_test(UnitTest * test) +void UnitTestDriver::register_test(UnitTest* test) { - if(UnitTestDriver::s_driver().test_map.count(test->name) ) - { - std::cout << "[WARNING] Test name \"" << test->name << " already encountered " << std::endl; - } + if(UnitTestDriver::s_driver().test_map.count(test->name)) + { + std::cout << "[WARNING] Test name \"" << test->name << " already encountered " << std::endl; + } - UnitTestDriver::s_driver().test_map[test->name] = test; + UnitTestDriver::s_driver().test_map[test->name] = test; } - -UnitTest::UnitTest(const char * _name) : name(_name) +UnitTest::UnitTest(const char* _name) + : name(_name) { - UnitTestDriver::s_driver().register_test(this); + UnitTestDriver::s_driver().register_test(this); } - -void process_args(int argc, char ** argv, - ArgumentSet& args, - ArgumentMap& kwargs) +void process_args(int argc, char** argv, ArgumentSet& args, ArgumentMap& kwargs) { - for(int i = 1; i < argc; i++) - { - std::string arg(argv[i]); - - // look for --key or --key=value arguments - if(arg.substr(0,2) == "--") - { - std::string::size_type n = arg.find('=',2); - - if(n == std::string::npos) - { - kwargs[arg.substr(2)] = std::string(); // (key,"") - } - else - { - kwargs[arg.substr(2, n - 2)] = arg.substr(n + 1); // (key,value) - } - } - else + for(int i = 1; i < argc; i++) { - args.insert(arg); + std::string arg(argv[i]); + + // look for --key or --key=value arguments + if(arg.substr(0, 2) == "--") + { + std::string::size_type n = arg.find('=', 2); + + if(n == std::string::npos) + { + kwargs[arg.substr(2)] = std::string(); // (key,"") + } + else + { + kwargs[arg.substr(2, n - 2)] = arg.substr(n + 1); // (key,value) + } + } + else + { + args.insert(arg); + } } - } } - void usage(int argc, char** argv) { - std::string indent = " "; - - std::cout << "Example Usage:\n"; - std::cout << indent << argv[0] << "\n"; - std::cout << indent << argv[0] << " TestName1 [TestName2 ...] \n"; - std::cout << indent << argv[0] << " PartialTestName1* [PartialTestName2* ...] \n"; - std::cout << indent << argv[0] << " --device=1\n"; - std::cout << indent << argv[0] << " --sizes={tiny,small,medium,default,large,huge,epic,max}\n"; - std::cout << indent << argv[0] << " --verbose or --concise\n"; - std::cout << indent << argv[0] << " --list\n"; - std::cout << indent << argv[0] << " --help\n"; - std::cout << "\n"; - std::cout << "Options:\n"; - std::cout << indent << "The sizes option determines which input sizes are tested.\n"; - std::cout << indent << indent << "--sizes=tiny tests sizes up to " << tiny_threshold << "\n"; - std::cout << indent << indent << "--sizes=small tests sizes up to " << small_threshold << "\n"; - std::cout << indent << indent << "--sizes=medium tests sizes up to " << medium_threshold << "\n"; - std::cout << indent << indent << "--sizes=default tests sizes up to " << default_threshold << "\n"; - std::cout << indent << indent << "--sizes=large tests sizes up to " << large_threshold << " (0.25 GB memory)\n"; - std::cout << indent << indent << "--sizes=huge tests sizes up to " << huge_threshold << " (1.50 GB memory)\n"; - std::cout << indent << indent << "--sizes=epic tests sizes up to " << epic_threshold << " (3.00 GB memory)\n"; - std::cout << indent << indent << "--sizes=max tests all available sizes\n"; + std::string indent = " "; + + std::cout << "Example Usage:\n"; + std::cout << indent << argv[0] << "\n"; + std::cout << indent << argv[0] << " TestName1 [TestName2 ...] \n"; + std::cout << indent << argv[0] << " PartialTestName1* [PartialTestName2* ...] \n"; + std::cout << indent << argv[0] << " --device=1\n"; + std::cout << indent << argv[0] << " --sizes={tiny,small,medium,default,large,huge,epic,max}\n"; + std::cout << indent << argv[0] << " --verbose or --concise\n"; + std::cout << indent << argv[0] << " --list\n"; + std::cout << indent << argv[0] << " --help\n"; + std::cout << "\n"; + std::cout << "Options:\n"; + std::cout << indent << "The sizes option determines which input sizes are tested.\n"; + std::cout << indent << indent << "--sizes=tiny tests sizes up to " << tiny_threshold << "\n"; + std::cout << indent << indent << "--sizes=small tests sizes up to " << small_threshold + << "\n"; + std::cout << indent << indent << "--sizes=medium tests sizes up to " << medium_threshold + << "\n"; + std::cout << indent << indent << "--sizes=default tests sizes up to " << default_threshold + << "\n"; + std::cout << indent << indent << "--sizes=large tests sizes up to " << large_threshold + << " (0.25 GB memory)\n"; + std::cout << indent << indent << "--sizes=huge tests sizes up to " << huge_threshold + << " (1.50 GB memory)\n"; + std::cout << indent << indent << "--sizes=epic tests sizes up to " << epic_threshold + << " (3.00 GB memory)\n"; + std::cout << indent << indent << "--sizes=max tests all available sizes\n"; } - struct TestResult { - TestStatus status; - std::string name; - std::string message; - - // XXX use a c++11 timer result when available - /*std::*/clock_t elapsed; - - TestResult(const TestStatus status, /*std::*/clock_t elapsed, const UnitTest& u, const std::string& message = "") - : status(status), name(u.name), message(message), elapsed(elapsed) - {} - - bool operator<(const TestResult& tr) const - { - if(status < tr.status) + TestStatus status; + std::string name; + std::string message; + + // XXX use a c++11 timer result when available + /*std::*/ clock_t elapsed; + + TestResult(const TestStatus status, + /*std::*/ clock_t elapsed, + const UnitTest& u, + const std::string& message = "") + : status(status) + , name(u.name) + , message(message) + , elapsed(elapsed) { - return true; } - else if(tr.status < status) + + bool operator<(const TestResult& tr) const { - return false; + if(status < tr.status) + { + return true; + } + else if(tr.status < status) + { + return false; + } + else + { + return name < tr.name; + } } - else +}; + +void record_result(const TestResult& test_result, std::vector& test_results) +{ + test_results.push_back(test_result); +} + +void report_results(std::vector& test_results, double elapsed_minutes) +{ + std::cout << std::endl; + + std::string hline = "================================================================"; + + std::sort(test_results.begin(), test_results.end()); + + size_t num_passes = 0; + size_t num_failures = 0; + size_t num_known_failures = 0; + size_t num_errors = 0; + + for(size_t i = 0; i < test_results.size(); i++) { - return name < tr.name; + const TestResult& tr = test_results[i]; + + if(tr.status == Pass) + { + num_passes++; + } + else + { + std::cout << hline << std::endl; + + switch(tr.status) + { + case Failure: + std::cout << "FAILURE"; + num_failures++; + break; + case KnownFailure: + std::cout << "KNOWN FAILURE"; + num_known_failures++; + break; + case Error: + std::cout << "ERROR"; + num_errors++; + break; + default: + break; + } + + std::cout << ": " << tr.name << std::endl << tr.message << std::endl; + } } - } -}; + std::cout << hline << std::endl; + + std::cout << "Totals: "; + std::cout << num_failures << " failures, "; + std::cout << num_known_failures << " known failures, "; + std::cout << num_errors << " errors, and "; + std::cout << num_passes << " passes." << std::endl; + std::cout << "Time: " << elapsed_minutes << " minutes" << std::endl; +} -void record_result(const TestResult& test_result, std::vector< TestResult >& test_results) +void UnitTestDriver::list_tests(void) { - test_results.push_back(test_result); + for(TestMap::iterator iter = test_map.begin(); iter != test_map.end(); iter++) + { + std::cout << iter->second->name << std::endl; + } } +bool UnitTestDriver::post_test_sanity_check(const UnitTest& test, bool concise) +{ + return true; +} -void report_results(std::vector< TestResult >& test_results, double elapsed_minutes) +bool UnitTestDriver::run_tests(std::vector& tests_to_run, const ArgumentMap& kwargs) { - std::cout << std::endl; - - std::string hline = "================================================================"; - - std::sort(test_results.begin(), test_results.end()); - - size_t num_passes = 0; - size_t num_failures = 0; - size_t num_known_failures = 0; - size_t num_errors = 0; - - for(size_t i = 0; i < test_results.size(); i++) - { - const TestResult& tr = test_results[i]; - - if(tr.status == Pass) + std::time_t start_time = std::time(0); + + bool verbose = kwargs.count("verbose"); + bool concise = kwargs.count("concise"); + + std::vector test_results; + + if(verbose && concise) { - num_passes++; + std::cout << "--verbose and --concise cannot be used together" << std::endl; + exit(EXIT_FAILURE); } - else + + if(!concise) { - std::cout << hline << std::endl; - - switch(tr.status) - { - case Failure: - std::cout << "FAILURE"; num_failures++; break; - case KnownFailure: - std::cout << "KNOWN FAILURE"; num_known_failures++; break; - case Error: - std::cout << "ERROR"; num_errors++; break; - default: - break; - } - - std::cout << ": " << tr.name << std::endl << tr.message << std::endl; + std::cout << "Running " << tests_to_run.size() << " unit tests." << std::endl; } - } - - std::cout << hline << std::endl; - - std::cout << "Totals: "; - std::cout << num_failures << " failures, "; - std::cout << num_known_failures << " known failures, "; - std::cout << num_errors << " errors, and "; - std::cout << num_passes << " passes." << std::endl; - std::cout << "Time: " << elapsed_minutes << " minutes" << std::endl; -} + for(size_t i = 0; i < tests_to_run.size(); i++) + { + UnitTest& test = *tests_to_run[i]; -void UnitTestDriver::list_tests(void) -{ - for(TestMap::iterator iter = test_map.begin(); iter != test_map.end(); iter++) - { - std::cout << iter->second->name << std::endl; - } -} + if(verbose) + { + std::cout << "Running " << test.name << "..." << std::flush; + } + try + { + // time the test + /*std::*/ clock_t start = std::clock(); -bool UnitTestDriver::post_test_sanity_check(const UnitTest &test, bool concise) -{ - return true; -} + // run the test + test.run(); + + // test passed + record_result(TestResult(Pass, std::clock() - start, test), test_results); + } + catch(unittest::UnitTestFailure& f) + { + record_result( + TestResult(Failure, std::numeric_limits::max(), test, f.message), + test_results); + } + catch(unittest::UnitTestKnownFailure& f) + { + record_result( + TestResult( + KnownFailure, std::numeric_limits::max(), test, f.message), + test_results); + } + catch(std::bad_alloc& e) + { + record_result( + TestResult(Error, std::numeric_limits::max(), test, e.what()), + test_results); + } + catch(unittest::UnitTestError& e) + { + record_result( + TestResult(Error, std::numeric_limits::max(), test, e.message), + test_results); + } + // immediate report + if(!concise) + { + if(verbose) + { + switch(test_results.back().status) + { + case Pass: + std::cout << "\r[PASS] "; + std::cout << std::setw(10) + << 1000.f * float(test_results.back().elapsed) / CLOCKS_PER_SEC + << " ms"; + break; + case Failure: + std::cout << "\r[FAILURE] "; + break; + case KnownFailure: + std::cout << "\r[KNOWN FAILURE] "; + break; + case Error: + std::cout << "\r[ERROR] "; + break; + default: + break; + } + + std::cout << " " << test.name << std::endl; + } + else + { + switch(test_results.back().status) + { + case Pass: + std::cout << "."; + break; + case Failure: + std::cout << "F"; + break; + case KnownFailure: + std::cout << "K"; + break; + case Error: + std::cout << "E"; + break; + default: + break; + } + } + } -bool UnitTestDriver::run_tests(std::vector& tests_to_run, const ArgumentMap& kwargs) -{ - std::time_t start_time = std::time(0); - - bool verbose = kwargs.count("verbose"); - bool concise = kwargs.count("concise"); - - std::vector< TestResult > test_results; - - if(verbose && concise) - { - std::cout << "--verbose and --concise cannot be used together" << std::endl; - exit(EXIT_FAILURE); - } - - if(!concise) - { - std::cout << "Running " << tests_to_run.size() << " unit tests." << std::endl; - } - - for(size_t i = 0; i < tests_to_run.size(); i++) - { - UnitTest& test = *tests_to_run[i]; - - if(verbose) - { - std::cout << "Running " << test.name << "..." << std::flush; - } - - try - { - // time the test - /*std::*/clock_t start = std::clock(); - - // run the test - test.run(); - - // test passed - record_result(TestResult(Pass, std::clock() - start, test), test_results); - } - catch(unittest::UnitTestFailure& f) - { - record_result(TestResult(Failure, std::numeric_limits::max(), test, f.message), test_results); - } - catch(unittest::UnitTestKnownFailure& f) - { - record_result(TestResult(KnownFailure, std::numeric_limits::max(), test, f.message), test_results); - } - catch(std::bad_alloc& e) - { - record_result(TestResult(Error, std::numeric_limits::max(), test, e.what()), test_results); - } - catch(unittest::UnitTestError& e) - { - record_result(TestResult(Error, std::numeric_limits::max(), test, e.message), test_results); - } - - // immediate report - if(!concise) - { - if(verbose) - { - switch(test_results.back().status) - { - case Pass: - std::cout << "\r[PASS] "; - std::cout << std::setw(10) << 1000.f * float(test_results.back().elapsed) / CLOCKS_PER_SEC << " ms"; - break; - case Failure: - std::cout << "\r[FAILURE] "; break; - case KnownFailure: - std::cout << "\r[KNOWN FAILURE] "; break; - case Error: - std::cout << "\r[ERROR] "; break; - default: - break; - } - - std::cout << " " << test.name << std::endl; - } - else - { - switch(test_results.back().status) - { - case Pass: - std::cout << "."; break; - case Failure: - std::cout << "F"; break; - case KnownFailure: - std::cout << "K"; break; - case Error: - std::cout << "E"; break; - default: - break; - } - } - } - - if(!post_test_sanity_check(test, concise)) - { - return false; - } - - std::cout.flush(); - } - - double elapsed_minutes = double(std::time(0) - start_time) / 60; - - // summary report - if(!concise) - { - report_results(test_results, elapsed_minutes); - } - - - // if any failures or errors return false - for(size_t i = 0; i < test_results.size(); i++) - { - if(test_results[i].status != Pass && test_results[i].status != KnownFailure) + if(!post_test_sanity_check(test, concise)) + { + return false; + } + + std::cout.flush(); + } + + double elapsed_minutes = double(std::time(0) - start_time) / 60; + + // summary report + if(!concise) { - return false; + report_results(test_results, elapsed_minutes); + } + + // if any failures or errors return false + for(size_t i = 0; i < test_results.size(); i++) + { + if(test_results[i].status != Pass && test_results[i].status != KnownFailure) + { + return false; + } } - } - - // all tests pass or are known failures - return true; -} + // all tests pass or are known failures + return true; +} bool UnitTestDriver::run_tests(const ArgumentSet& args, const ArgumentMap& kwargs) { - if(args.empty()) - { - // run all tests - std::vector tests_to_run; - - for(TestMap::iterator iter = test_map.begin(); iter != test_map.end(); iter++) - { - tests_to_run.push_back(iter->second); - } - - return run_tests(tests_to_run, kwargs); - } - else - { - // all non-keyword arguments are assumed to be test names or partial test names - - typedef TestMap::iterator TestMapIterator; - - // vector to accumulate tests - std::vector tests_to_run; - - for(ArgumentSet::const_iterator iter = args.begin(); iter != args.end(); iter++) + if(args.empty()) { - const std::string& arg = *iter; - - size_t len = arg.size(); - size_t matches = 0; - - if(arg[len-1] == '*') - { - // wildcard search - std::string search = arg.substr(0,len-1); - - TestMapIterator lb = test_map.lower_bound(search); - while(lb != test_map.end()) + // run all tests + std::vector tests_to_run; + + for(TestMap::iterator iter = test_map.begin(); iter != test_map.end(); iter++) { - if(search != lb->first.substr(0,len-1)) - { - break; - } - - tests_to_run.push_back(lb->second); - lb++; - matches++; + tests_to_run.push_back(iter->second); } - } - else - { - // non-wildcard search - TestMapIterator lb = test_map.find(arg); - - if(lb != test_map.end()) + + return run_tests(tests_to_run, kwargs); + } + else + { + // all non-keyword arguments are assumed to be test names or partial test + // names + + typedef TestMap::iterator TestMapIterator; + + // vector to accumulate tests + std::vector tests_to_run; + + for(ArgumentSet::const_iterator iter = args.begin(); iter != args.end(); iter++) { - tests_to_run.push_back(lb->second); - matches++; + const std::string& arg = *iter; + + size_t len = arg.size(); + size_t matches = 0; + + if(arg[len - 1] == '*') + { + // wildcard search + std::string search = arg.substr(0, len - 1); + + TestMapIterator lb = test_map.lower_bound(search); + while(lb != test_map.end()) + { + if(search != lb->first.substr(0, len - 1)) + { + break; + } + + tests_to_run.push_back(lb->second); + lb++; + matches++; + } + } + else + { + // non-wildcard search + TestMapIterator lb = test_map.find(arg); + + if(lb != test_map.end()) + { + tests_to_run.push_back(lb->second); + matches++; + } + } + + if(matches == 0) + { + std::cout << "[ERROR] found no test names matching the pattern: " << arg + << std::endl; + return false; + } } - } - - if(matches == 0) - { - std::cout << "[ERROR] found no test names matching the pattern: " << arg << std::endl; - return false; - } + + return run_tests(tests_to_run, kwargs); } - - return run_tests(tests_to_run, kwargs); - } } - // driver_instance maps a DeviceSystem to a singleton UnitTestDriver -//template -UnitTestDriver &driver_instance(/*DeviceSystem tag*/) +// template +UnitTestDriver& driver_instance(/*DeviceSystem tag*/) { - static UnitTestDriver s_instance; - return s_instance; + static UnitTestDriver s_instance; + return s_instance; } - // if we need a special kind of UnitTestDriver, overload // driver_instance in that function -UnitTestDriver &UnitTestDriver::s_driver() +UnitTestDriver& UnitTestDriver::s_driver() { - return driver_instance(/*thrust::device_system_tag()*/); + return driver_instance(/*thrust::device_system_tag()*/); } - -int main(int argc, char **argv) +int main(int argc, char** argv) { - ArgumentSet args; - ArgumentMap kwargs; - - process_args(argc, argv, args, kwargs); - - if(kwargs.count("help")) - { - usage(argc, argv); - return 0; - } - - if(kwargs.count("list")) - { - UnitTestDriver::s_driver().list_tests(); - return 0; - } - - if(kwargs.count("sizes")) - { - set_test_sizes(kwargs["sizes"]); - } - else - { - set_test_sizes("default"); - } - - bool passed = UnitTestDriver::s_driver().run_tests(args, kwargs); - - if(kwargs.count("concise")) - { - std::cout << ((passed) ? "PASSED" : "FAILED") << std::endl; - } - - return (passed) ? EXIT_SUCCESS : EXIT_FAILURE; -} + ArgumentSet args; + ArgumentMap kwargs; + process_args(argc, argv, args, kwargs); + + if(kwargs.count("help")) + { + usage(argc, argv); + return 0; + } + + if(kwargs.count("list")) + { + UnitTestDriver::s_driver().list_tests(); + return 0; + } + + if(kwargs.count("sizes")) + { + set_test_sizes(kwargs["sizes"]); + } + else + { + set_test_sizes("default"); + } + + bool passed = UnitTestDriver::s_driver().run_tests(args, kwargs); + + if(kwargs.count("concise")) + { + std::cout << ((passed) ? "PASSED" : "FAILED") << std::endl; + } + + return (passed) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/testing/unittest/assertions.h b/testing/unittest/assertions.h index 0e9f308..92d112c 100644 --- a/testing/unittest/assertions.h +++ b/testing/unittest/assertions.h @@ -1,357 +1,444 @@ #pragma once #include -#include +#include #include +#include #include -#include #include #include -#define ASSERT_EQUAL_QUIET(X,Y) unittest::assert_equal_quiet((X),(Y), __FILE__, __LINE__) -#define ASSERT_EQUAL(X,Y) unittest::assert_equal((X),(Y), __FILE__, __LINE__) -#define ASSERT_LEQUAL(X,Y) unittest::assert_lequal((X),(Y), __FILE__, __LINE__) -#define ASSERT_GEQUAL(X,Y) unittest::assert_gequal((X),(Y), __FILE__, __LINE__) -#define ASSERT_ALMOST_EQUAL(X,Y) unittest::assert_almost_equal((X),(Y), __FILE__, __LINE__) -#define KNOWN_FAILURE { unittest::UnitTestKnownFailure f; f << "[" << __FILE__ ":" << __LINE__ << "]"; throw f;} - -#define ASSERT_EQUAL_RANGES(X,Y,Z) unittest::assert_equal((X),(Y),(Z), __FILE__, __LINE__) - -#define ASSERT_THROWS(X,Y) \ - { bool thrown = false; try { X; } catch (Y) { thrown = true; } \ - if (!thrown) { unittest::UnitTestFailure f; f << "[" << __FILE__ << ":" << __LINE__ << "] did not throw " << #Y; throw f; } \ +#define ASSERT_EQUAL_QUIET(X, Y) unittest::assert_equal_quiet((X), (Y), __FILE__, __LINE__) +#define ASSERT_EQUAL(X, Y) unittest::assert_equal((X), (Y), __FILE__, __LINE__) +#define ASSERT_LEQUAL(X, Y) unittest::assert_lequal((X), (Y), __FILE__, __LINE__) +#define ASSERT_GEQUAL(X, Y) unittest::assert_gequal((X), (Y), __FILE__, __LINE__) +#define ASSERT_ALMOST_EQUAL(X, Y) unittest::assert_almost_equal((X), (Y), __FILE__, __LINE__) +#define KNOWN_FAILURE \ + { \ + unittest::UnitTestKnownFailure f; \ + f << "[" << __FILE__ ":" << __LINE__ << "]"; \ + throw f; \ } +#define ASSERT_EQUAL_RANGES(X, Y, Z) unittest::assert_equal((X), (Y), (Z), __FILE__, __LINE__) + +#define ASSERT_THROWS(X, Y) \ + { \ + bool thrown = false; \ + try \ + { \ + X; \ + } \ + catch(Y) \ + { \ + thrown = true; \ + } \ + if(!thrown) \ + { \ + unittest::UnitTestFailure f; \ + f << "[" << __FILE__ << ":" << __LINE__ << "] did not throw " << #Y; \ + throw f; \ + } \ + } namespace unittest { -static size_t MAX_OUTPUT_LINES = 10; + static size_t MAX_OUTPUT_LINES = 10; -static double DEFAULT_RELATIVE_TOL = 1e-4; -static double DEFAULT_ABSOLUTE_TOL = 1e-4; + static double DEFAULT_RELATIVE_TOL = 1e-4; + static double DEFAULT_ABSOLUTE_TOL = 1e-4; -template - struct value_type -{ - typedef typename thrust::detail::remove_const< - typename thrust::detail::remove_reference< - T - >::type - >::type type; -}; - -template - struct value_type< thrust::device_reference > -{ - typedef typename value_type::type type; -}; - -//// -// check scalar values -template -void assert_equal(const T1& a, const T2& b, - const std::string& filename = "unknown", int lineno = -1) -{ - // convert a & b to a's value_type to avoid warning upon comparison - typedef typename value_type::type T; + template + struct value_type + { + typedef typename thrust::detail::remove_const< + typename thrust::detail::remove_reference::type>::type type; + }; - if(!(T(a) == T(b))){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << "values are not equal: " << a << " " << b; - f << " [type='" << type_name() << "']"; - throw f; - } -} + template + struct value_type> + { + typedef typename value_type::type type; + }; + + //// + // check scalar values + template + void assert_equal(const T1& a, + const T2& b, + const std::string& filename = "unknown", + int lineno = -1) + { + // convert a & b to a's value_type to avoid warning upon comparison + typedef typename value_type::type T; -// sometimes it's not possible to << a type -template -void assert_equal_quiet(const T1& a, const T2& b, - const std::string& filename = "unknown", int lineno = -1) -{ - if(!(a == b)){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << "values are not equal."; - f << " [type='" << type_name() << "']"; - throw f; + if(!(T(a) == T(b))) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << "values are not equal: " << a << " " << b; + f << " [type='" << type_name() << "']"; + throw f; + } } -} -template -void assert_lequal(const T1& a, const T2& b, - const std::string& filename = "unknown", int lineno = -1) -{ - if(!(a <= b)){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << a << " is greater than " << b; - f << " [type='" << type_name() << "']"; - throw f; + // sometimes it's not possible to << a type + template + void assert_equal_quiet(const T1& a, + const T2& b, + const std::string& filename = "unknown", + int lineno = -1) + { + if(!(a == b)) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << "values are not equal."; + f << " [type='" << type_name() << "']"; + throw f; + } } -} -template -void assert_gequal(const T1& a, const T2& b, - const std::string& filename = "unknown", int lineno = -1) -{ - if(!(a >= T1(b))){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << a << " is less than " << b; - f << " [type='" << type_name() << "']"; - throw f; + template + void assert_lequal(const T1& a, + const T2& b, + const std::string& filename = "unknown", + int lineno = -1) + { + if(!(a <= b)) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << a << " is greater than " << b; + f << " [type='" << type_name() << "']"; + throw f; + } } -} -// define our own abs() because std::abs() isn't portable for all types for some reason -template - T abs(const T &x) -{ - return x > 0 ? x : -x; -} + template + void assert_gequal(const T1& a, + const T2& b, + const std::string& filename = "unknown", + int lineno = -1) + { + if(!(a >= T1(b))) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << a << " is less than " << b; + f << " [type='" << type_name() << "']"; + throw f; + } + } + // define our own abs() because std::abs() isn't portable for all types for some + // reason + template + T abs(const T& x) + { + return x > 0 ? x : -x; + } -inline -bool almost_equal(const double& a, const double& b, const double& a_tol, const double& r_tol) -{ - if(abs(a - b) > r_tol * (abs(a) + abs(b)) + a_tol) - return false; - else - return true; -} + inline bool + almost_equal(const double& a, const double& b, const double& a_tol, const double& r_tol) + { + if(abs(a - b) > r_tol * (abs(a) + abs(b)) + a_tol) + return false; + else + return true; + } -template -void assert_almost_equal(const T1& a, const T2& b, - const std::string& filename = "unknown", int lineno = -1, - double a_tol = DEFAULT_ABSOLUTE_TOL, double r_tol = DEFAULT_RELATIVE_TOL) + template + void assert_almost_equal(const T1& a, + const T2& b, + const std::string& filename = "unknown", + int lineno = -1, + double a_tol = DEFAULT_ABSOLUTE_TOL, + double r_tol = DEFAULT_RELATIVE_TOL) -{ - if(!almost_equal(a, b, a_tol, r_tol)){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << "values are not approximately equal: " << (double) a << " " << (double) b; - f << " [type='" << type_name() << "']"; - throw f; + { + if(!almost_equal(a, b, a_tol, r_tol)) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << "values are not approximately equal: " << (double)a << " " << (double)b; + f << " [type='" << type_name() << "']"; + throw f; + } } -} + template + void assert_almost_equal(const thrust::complex& a, + const thrust::complex& b, + const std::string& filename = "unknown", + int lineno = -1, + double a_tol = DEFAULT_ABSOLUTE_TOL, + double r_tol = DEFAULT_RELATIVE_TOL) -template - void assert_almost_equal(const thrust::complex& a, const thrust::complex& b, - const std::string& filename = "unknown", int lineno = -1, - double a_tol = DEFAULT_ABSOLUTE_TOL, double r_tol = DEFAULT_RELATIVE_TOL) - -{ - if(!almost_equal(a.real(), b.real(), a_tol, r_tol)){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << "values are not approximately equal: " << a << " " << b; - f << " [type='" << type_name() << "']"; - throw f; + { + if(!almost_equal(a.real(), b.real(), a_tol, r_tol)) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << "values are not approximately equal: " << a << " " << b; + f << " [type='" << type_name() << "']"; + throw f; + } } -} + template + void assert_almost_equal(const thrust::complex& a, + const std::complex& b, + const std::string& filename = "unknown", + int lineno = -1, + double a_tol = DEFAULT_ABSOLUTE_TOL, + double r_tol = DEFAULT_RELATIVE_TOL) -template - void assert_almost_equal(const thrust::complex& a, const std::complex& b, - const std::string& filename = "unknown", int lineno = -1, - double a_tol = DEFAULT_ABSOLUTE_TOL, double r_tol = DEFAULT_RELATIVE_TOL) - -{ - if(!almost_equal(a.real(), b.real(), a_tol, r_tol)){ - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; - f << "values are not approximately equal: " << a << " " << b; - f << " [type='" << type_name() << "']"; - throw f; + { + if(!almost_equal(a.real(), b.real(), a_tol, r_tol)) + { + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; + f << "values are not approximately equal: " << a << " " << b; + f << " [type='" << type_name() << "']"; + throw f; + } } -} -template -class almost_equal_to -{ + template + class almost_equal_to + { public: double a_tol, r_tol; - almost_equal_to(double _a_tol = DEFAULT_ABSOLUTE_TOL, double _r_tol = DEFAULT_RELATIVE_TOL) : a_tol(_a_tol), r_tol(_r_tol) {} - bool operator()(const T& a, const T& b) const { - return almost_equal((double) a, (double) b, a_tol, r_tol); + almost_equal_to(double _a_tol = DEFAULT_ABSOLUTE_TOL, double _r_tol = DEFAULT_RELATIVE_TOL) + : a_tol(_a_tol) + , r_tol(_r_tol) + { } -}; - + bool operator()(const T& a, const T& b) const + { + return almost_equal((double)a, (double)b, a_tol, r_tol); + } + }; -template -class almost_equal_to > -{ + template + class almost_equal_to> + { public: double a_tol, r_tol; - almost_equal_to(double _a_tol = DEFAULT_ABSOLUTE_TOL, double _r_tol = DEFAULT_RELATIVE_TOL) : a_tol(_a_tol), r_tol(_r_tol) {} - bool operator()(const thrust::complex& a, const thrust::complex& b) const { - return almost_equal((double) a.real(), (double) b.real(), a_tol, r_tol) && - almost_equal((double) a.imag(), (double) b.imag(), a_tol, r_tol); + almost_equal_to(double _a_tol = DEFAULT_ABSOLUTE_TOL, double _r_tol = DEFAULT_RELATIVE_TOL) + : a_tol(_a_tol) + , r_tol(_r_tol) + { + } + bool operator()(const thrust::complex& a, const thrust::complex& b) const + { + return almost_equal((double)a.real(), (double)b.real(), a_tol, r_tol) + && almost_equal((double)a.imag(), (double)b.imag(), a_tol, r_tol); } -}; + }; + + //// + // check sequences + + template + void assert_equal(ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2, + ForwardIterator2 last2, + BinaryPredicate op, + const std::string& filename = "unknown", + int lineno = -1) + { + typedef typename thrust::iterator_difference::type difference_type; + typedef typename thrust::iterator_value::type InputType; -//// -// check sequences + bool failure = false; -template -void assert_equal(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate op, - const std::string& filename = "unknown", int lineno = -1) -{ - typedef typename thrust::iterator_difference::type difference_type; - typedef typename thrust::iterator_value::type InputType; - - bool failure = false; + difference_type length1 = thrust::distance(first1, last1); + difference_type length2 = thrust::distance(first2, last2); - difference_type length1 = thrust::distance(first1, last1); - difference_type length2 = thrust::distance(first2, last2); - - difference_type min_length = thrust::min(length1, length2); + difference_type min_length = thrust::min(length1, length2); - unittest::UnitTestFailure f; - f << "[" << filename << ":" << lineno << "] "; + unittest::UnitTestFailure f; + f << "[" << filename << ":" << lineno << "] "; - // check lengths - if (length1 != length2) - { - failure = true; - f << "Sequences have different sizes (" << length1 << " != " << length2 << ")\n"; - } + // check lengths + if(length1 != length2) + { + failure = true; + f << "Sequences have different sizes (" << length1 << " != " << length2 << ")\n"; + } - // check values - - size_t mismatches = 0; + // check values - for (difference_type i = 0; i < min_length; i++) - { - if(!op(*first1, *first2)) - { - if (mismatches == 0) + size_t mismatches = 0; + + for(difference_type i = 0; i < min_length; i++) { - failure = true; - f << "Sequences are not equal [type='" << type_name() << "']\n"; - f << "--------------------------------\n"; + if(!op(*first1, *first2)) + { + if(mismatches == 0) + { + failure = true; + f << "Sequences are not equal [type='" << type_name() << "']\n"; + f << "--------------------------------\n"; + } + + mismatches++; + + if(mismatches <= MAX_OUTPUT_LINES) + { + if(sizeof(InputType) == 1) + f << " [" << i << "] " << *first1 + InputType() << " " + << *first2 + InputType() << "\n"; // unprintable chars are a problem + else + f << " [" << i << "] " << *first1 << " " << *first2 << "\n"; + } + } + + first1++; + first2++; } - mismatches++; - - if(mismatches <= MAX_OUTPUT_LINES) + if(mismatches > 0) { - if (sizeof(InputType) == 1) - f << " [" << i << "] " << *first1 + InputType() << " " << *first2 + InputType() << "\n"; // unprintable chars are a problem - else - f << " [" << i << "] " << *first1 << " " << *first2 << "\n"; + if(mismatches > MAX_OUTPUT_LINES) + f << " (output limit reached)\n"; + f << "--------------------------------\n"; + f << "Sequences differ at " << mismatches << " of " << min_length << " positions" + << "\n"; + } + else if(length1 != length2) + { + f << "Sequences agree through " << min_length << " positions [type='" + << type_name() << "']\n"; } - } - first1++; - first2++; + if(failure) + throw f; } - if (mismatches > 0) + template + void assert_equal(ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2, + ForwardIterator2 last2, + const std::string& filename = "unknown", + int lineno = -1) { - if(mismatches > MAX_OUTPUT_LINES) - f << " (output limit reached)\n"; - f << "--------------------------------\n"; - f << "Sequences differ at " << mismatches << " of " << min_length << " positions" << "\n"; + typedef typename thrust::iterator_traits::value_type InputType; + assert_equal(first1, last1, first2, last2, thrust::equal_to(), filename, lineno); } - else if (length1 != length2) + + template + void assert_almost_equal(ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2, + ForwardIterator2 last2, + const std::string& filename = "unknown", + int lineno = -1, + const double a_tol = DEFAULT_ABSOLUTE_TOL, + const double r_tol = DEFAULT_RELATIVE_TOL) { - f << "Sequences agree through " << min_length << " positions [type='" << type_name() << "']\n"; + typedef typename thrust::iterator_traits::value_type InputType; + assert_equal(first1, + last1, + first2, + last2, + almost_equal_to(a_tol, r_tol), + filename, + lineno); } - if (failure) - throw f; -} - -template -void assert_equal(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, - const std::string& filename = "unknown", int lineno = -1) -{ - typedef typename thrust::iterator_traits::value_type InputType; - assert_equal(first1, last1, first2, last2, thrust::equal_to(), filename, lineno); -} - + template + void assert_equal(const thrust::host_vector& A, + const thrust::host_vector& B, + const std::string& filename = "unknown", + int lineno = -1) + { + assert_equal(A.begin(), A.end(), B.begin(), B.end(), filename, lineno); + } -template -void assert_almost_equal(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, - const std::string& filename = "unknown", int lineno = -1, - const double a_tol = DEFAULT_ABSOLUTE_TOL, const double r_tol = DEFAULT_RELATIVE_TOL) -{ - typedef typename thrust::iterator_traits::value_type InputType; - assert_equal(first1, last1, first2, last2, almost_equal_to(a_tol, r_tol), filename, lineno); -} + template + void assert_almost_equal(const thrust::host_vector& A, + const thrust::host_vector& B, + const std::string& filename = "unknown", + int lineno = -1, + const double a_tol = DEFAULT_ABSOLUTE_TOL, + const double r_tol = DEFAULT_RELATIVE_TOL) + { + assert_almost_equal(A.begin(), A.end(), B.begin(), B.end(), filename, lineno, a_tol, r_tol); + } + template + void assert_equal(const thrust::host_vector& A, + const thrust::device_vector& B, + const std::string& filename = "unknown", + int lineno = -1) + { + thrust::host_vector B_host = B; + assert_equal(A, B_host, filename, lineno); + } -template -void assert_equal(const thrust::host_vector& A, const thrust::host_vector& B, - const std::string& filename = "unknown", int lineno = -1) -{ - assert_equal(A.begin(), A.end(), B.begin(), B.end(), filename, lineno); -} + template + void assert_equal(const thrust::device_vector& A, + const thrust::host_vector& B, + const std::string& filename = "unknown", + int lineno = -1) + { + thrust::host_vector A_host = A; + assert_equal(A_host, B, filename, lineno); + } -template -void assert_almost_equal(const thrust::host_vector& A, const thrust::host_vector& B, - const std::string& filename = "unknown", int lineno = -1, - const double a_tol = DEFAULT_ABSOLUTE_TOL, const double r_tol = DEFAULT_RELATIVE_TOL) -{ - assert_almost_equal(A.begin(), A.end(), B.begin(), B.end(), filename, lineno, a_tol, r_tol); -} + template + void assert_equal(const thrust::device_vector& A, + const thrust::device_vector& B, + const std::string& filename = "unknown", + int lineno = -1) + { + thrust::host_vector A_host = A; + thrust::host_vector B_host = B; + assert_equal(A_host, B_host, filename, lineno); + } -template -void assert_equal(const thrust::host_vector& A, const thrust::device_vector& B, - const std::string& filename = "unknown", int lineno = -1) -{ - thrust::host_vector B_host = B; - assert_equal(A, B_host, filename, lineno); -} + template + void assert_almost_equal(const thrust::host_vector& A, + const thrust::device_vector& B, + const std::string& filename = "unknown", + int lineno = -1, + const double a_tol = DEFAULT_ABSOLUTE_TOL, + const double r_tol = DEFAULT_RELATIVE_TOL) + { + thrust::host_vector B_host = B; + assert_almost_equal(A, B_host, filename, lineno, a_tol, r_tol); + } -template -void assert_equal(const thrust::device_vector& A, const thrust::host_vector& B, - const std::string& filename = "unknown", int lineno = -1) -{ - thrust::host_vector A_host = A; - assert_equal(A_host, B, filename, lineno); -} + template + void assert_almost_equal(const thrust::device_vector& A, + const thrust::host_vector& B, + const std::string& filename = "unknown", + int lineno = -1, + const double a_tol = DEFAULT_ABSOLUTE_TOL, + const double r_tol = DEFAULT_RELATIVE_TOL) + { + thrust::host_vector A_host = A; + assert_almost_equal(A_host, B, filename, lineno, a_tol, r_tol); + } -template -void assert_equal(const thrust::device_vector& A, const thrust::device_vector& B, - const std::string& filename = "unknown", int lineno = -1) -{ - thrust::host_vector A_host = A; - thrust::host_vector B_host = B; - assert_equal(A_host, B_host, filename, lineno); -} - -template -void assert_almost_equal(const thrust::host_vector& A, const thrust::device_vector& B, - const std::string& filename = "unknown", int lineno = -1, - const double a_tol = DEFAULT_ABSOLUTE_TOL, const double r_tol = DEFAULT_RELATIVE_TOL) -{ - thrust::host_vector B_host = B; - assert_almost_equal(A, B_host, filename, lineno, a_tol, r_tol); -} - -template -void assert_almost_equal(const thrust::device_vector& A, const thrust::host_vector& B, - const std::string& filename = "unknown", int lineno = -1, - const double a_tol = DEFAULT_ABSOLUTE_TOL, const double r_tol = DEFAULT_RELATIVE_TOL) -{ - thrust::host_vector A_host = A; - assert_almost_equal(A_host, B, filename, lineno, a_tol, r_tol); -} - -template -void assert_almost_equal(const thrust::device_vector& A, const thrust::device_vector& B, - const std::string& filename = "unknown", int lineno = -1, - const double a_tol = DEFAULT_ABSOLUTE_TOL, const double r_tol = DEFAULT_RELATIVE_TOL) -{ - thrust::host_vector A_host = A; - thrust::host_vector B_host = B; - assert_almost_equal(A_host, B_host, filename, lineno, a_tol, r_tol); -} + template + void assert_almost_equal(const thrust::device_vector& A, + const thrust::device_vector& B, + const std::string& filename = "unknown", + int lineno = -1, + const double a_tol = DEFAULT_ABSOLUTE_TOL, + const double r_tol = DEFAULT_RELATIVE_TOL) + { + thrust::host_vector A_host = A; + thrust::host_vector B_host = B; + assert_almost_equal(A_host, B_host, filename, lineno, a_tol, r_tol); + } -}; //end namespace unittest +}; // end namespace unittest diff --git a/testing/unittest/exceptions.h b/testing/unittest/exceptions.h index 3f3633f..5674af3 100644 --- a/testing/unittest/exceptions.h +++ b/testing/unittest/exceptions.h @@ -1,56 +1,66 @@ #pragma once -#include #include #include +#include namespace unittest { -class UnitTestException -{ + class UnitTestException + { public: - std::string message; + std::string message; - UnitTestException() {} - UnitTestException(const std::string& msg) : message(msg) {} + UnitTestException() {} + UnitTestException(const std::string& msg) + : message(msg) + { + } - friend std::ostream& operator<<(std::ostream& os, const UnitTestException& e) - { - return os << e.message; - } - - template - UnitTestException& operator<<(const T& t) - { - std::ostringstream oss; - oss << t; - message += oss.str(); - return *this; - } -}; + friend std::ostream& operator<<(std::ostream& os, const UnitTestException& e) + { + return os << e.message; + } + template + UnitTestException& operator<<(const T& t) + { + std::ostringstream oss; + oss << t; + message += oss.str(); + return *this; + } + }; -class UnitTestError : public UnitTestException -{ + class UnitTestError : public UnitTestException + { public: - UnitTestError() {} - UnitTestError(const std::string& msg) : UnitTestException(msg) {} -}; + UnitTestError() {} + UnitTestError(const std::string& msg) + : UnitTestException(msg) + { + } + }; -class UnitTestFailure : public UnitTestException -{ + class UnitTestFailure : public UnitTestException + { public: - UnitTestFailure() {} - UnitTestFailure(const std::string& msg) : UnitTestException(msg) {} -}; + UnitTestFailure() {} + UnitTestFailure(const std::string& msg) + : UnitTestException(msg) + { + } + }; -class UnitTestKnownFailure : public UnitTestException -{ + class UnitTestKnownFailure : public UnitTestException + { public: - UnitTestKnownFailure() {} - UnitTestKnownFailure(const std::string& msg) : UnitTestException(msg) {} -}; - + UnitTestKnownFailure() {} + UnitTestKnownFailure(const std::string& msg) + : UnitTestException(msg) + { + } + }; -}; //end namespace unittest +}; // end namespace unittest diff --git a/testing/unittest/meta.h b/testing/unittest/meta.h index 9a2b6d8..76ba1bf 100644 --- a/testing/unittest/meta.h +++ b/testing/unittest/meta.h @@ -9,252 +9,417 @@ namespace unittest { -// mark the absence of a type -struct null_type {}; + // mark the absence of a type + struct null_type + { + }; -// this type encapsulates a list of -// up to 10 types -template - struct type_list -{ - typedef T0 type_0; - typedef T1 type_1; - typedef T2 type_2; - typedef T3 type_3; - typedef T4 type_4; - typedef T5 type_5; - typedef T6 type_6; - typedef T7 type_7; - typedef T8 type_8; - typedef T9 type_9; - typedef T10 type_10; - typedef T11 type_11; - typedef T12 type_12; - typedef T13 type_13; - typedef T14 type_14; - typedef T15 type_15; - typedef T16 type_16; - typedef T17 type_17; - typedef T18 type_18; - typedef T19 type_19; -}; + // this type encapsulates a list of + // up to 10 types + template + struct type_list + { + typedef T0 type_0; + typedef T1 type_1; + typedef T2 type_2; + typedef T3 type_3; + typedef T4 type_4; + typedef T5 type_5; + typedef T6 type_6; + typedef T7 type_7; + typedef T8 type_8; + typedef T9 type_9; + typedef T10 type_10; + typedef T11 type_11; + typedef T12 type_12; + typedef T13 type_13; + typedef T14 type_14; + typedef T15 type_15; + typedef T16 type_16; + typedef T17 type_17; + typedef T18 type_18; + typedef T19 type_19; + }; -// this type provides a way of indexing -// into a type_list -template - struct get_type -{ - typedef null_type type; -}; + // this type provides a way of indexing + // into a type_list + template + struct get_type + { + typedef null_type type; + }; -template struct get_type { typedef typename List::type_0 type; }; -template struct get_type { typedef typename List::type_1 type; }; -template struct get_type { typedef typename List::type_2 type; }; -template struct get_type { typedef typename List::type_3 type; }; -template struct get_type { typedef typename List::type_4 type; }; -template struct get_type { typedef typename List::type_5 type; }; -template struct get_type { typedef typename List::type_6 type; }; -template struct get_type { typedef typename List::type_7 type; }; -template struct get_type { typedef typename List::type_8 type; }; -template struct get_type { typedef typename List::type_9 type; }; -template struct get_type { typedef typename List::type_10 type; }; -template struct get_type { typedef typename List::type_11 type; }; -template struct get_type { typedef typename List::type_12 type; }; -template struct get_type { typedef typename List::type_13 type; }; -template struct get_type { typedef typename List::type_14 type; }; -template struct get_type { typedef typename List::type_15 type; }; -template struct get_type { typedef typename List::type_16 type; }; -template struct get_type { typedef typename List::type_17 type; }; -template struct get_type { typedef typename List::type_18 type; }; -template struct get_type { typedef typename List::type_19 type; }; + template + struct get_type + { + typedef typename List::type_0 type; + }; + template + struct get_type + { + typedef typename List::type_1 type; + }; + template + struct get_type + { + typedef typename List::type_2 type; + }; + template + struct get_type + { + typedef typename List::type_3 type; + }; + template + struct get_type + { + typedef typename List::type_4 type; + }; + template + struct get_type + { + typedef typename List::type_5 type; + }; + template + struct get_type + { + typedef typename List::type_6 type; + }; + template + struct get_type + { + typedef typename List::type_7 type; + }; + template + struct get_type + { + typedef typename List::type_8 type; + }; + template + struct get_type + { + typedef typename List::type_9 type; + }; + template + struct get_type + { + typedef typename List::type_10 type; + }; + template + struct get_type + { + typedef typename List::type_11 type; + }; + template + struct get_type + { + typedef typename List::type_12 type; + }; + template + struct get_type + { + typedef typename List::type_13 type; + }; + template + struct get_type + { + typedef typename List::type_14 type; + }; + template + struct get_type + { + typedef typename List::type_15 type; + }; + template + struct get_type + { + typedef typename List::type_16 type; + }; + template + struct get_type + { + typedef typename List::type_17 type; + }; + template + struct get_type + { + typedef typename List::type_18 type; + }; + template + struct get_type + { + typedef typename List::type_19 type; + }; -// this type and its specialization provides a way to -// iterate over a type_list, and -// applying a unary function to each type -template class Function, - typename T, - unsigned int i = 0> - struct for_each_type -{ - template - void operator()(U n) - { - // run the function on type T - Function f; - f(n); + // this type and its specialization provides a way to + // iterate over a type_list, and + // applying a unary function to each type + template class Function, typename T, unsigned int i = 0> + struct for_each_type + { + template + void operator()(U n) + { + // run the function on type T + Function f; + f(n); - // get the next type - typedef typename get_type::type next_type; + // get the next type + typedef typename get_type::type next_type; - // recurse to i + 1 - for_each_type loop; - loop(n); - } + // recurse to i + 1 + for_each_type loop; + loop(n); + } - void operator()(void) - { - // run the function on type T - Function f; - f(); + void operator()(void) + { + // run the function on type T + Function f; + f(); - // get the next type - typedef typename get_type::type next_type; + // get the next type + typedef typename get_type::type next_type; - // recurse to i + 1 - for_each_type loop; - loop(); - } -}; + // recurse to i + 1 + for_each_type loop; + loop(); + } + }; -// terminal case: do nothing when encountering null_type -template class Function, - unsigned int i> - struct for_each_type -{ - template - void operator()(U n) - { - // no-op - } + // terminal case: do nothing when encountering null_type + template class Function, unsigned int i> + struct for_each_type + { + template + void operator()(U n) + { + // no-op + } - void operator()(void) - { - // no-op - } -}; + void operator()(void) + { + // no-op + } + }; -// this type and its specialization instantiates -// a template by applying T to Template. -// if T == null_type, then its result is also null_type -template