// MIT License
//
// Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "test_device_segmented_radix_sort.hpp"

#define SUITE RocprimDeviceSegmentedRadixSort

#define INSTANTIATE(...) INSTANTIATE_TYPED_TEST(SUITE, __VA_ARGS__);

#cmakedefine ROCPRIM_TEST_SUITE_SLICE @ROCPRIM_TEST_SUITE_SLICE@
#cmakedefine ROCPRIM_TEST_TYPE_SLICE  @ROCPRIM_TEST_TYPE_SLICE@

#if   ROCPRIM_TEST_SUITE_SLICE == 0
    TYPED_TEST_P(SUITE, SortKeys                ) { sort_keys<TestFixture>(); } 
    REGISTER_TYPED_TEST_SUITE_P(SUITE, SortKeys);
#elif ROCPRIM_TEST_SUITE_SLICE == 1
    TYPED_TEST_P(SUITE, SortPairs               ) { sort_pairs<TestFixture>(); } 
    REGISTER_TYPED_TEST_SUITE_P(SUITE, SortPairs);
#elif ROCPRIM_TEST_SUITE_SLICE == 2
    TYPED_TEST_P(SUITE, SortKeysDoubleBuffer    ) { sort_keys_double_buffer<TestFixture>(); } 
    REGISTER_TYPED_TEST_SUITE_P(SUITE, SortKeysDoubleBuffer);
#elif ROCPRIM_TEST_SUITE_SLICE == 3
    TYPED_TEST_P(SUITE, SortPairsDoubleBuffer   ) { sort_pairs_double_buffer<TestFixture>(); } 
    REGISTER_TYPED_TEST_SUITE_P(SUITE, SortPairsDoubleBuffer);
#endif

#if   ROCPRIM_TEST_TYPE_SLICE == 0
    INSTANTIATE(params<signed char,         double,                             true,   0, 8,   0,      1000,  config_default>)
    INSTANTIATE(params<int,                 short,                              false,  0, 32,  0,      100,   config_semi_custom>)
    INSTANTIATE(params<short,               int,                                true,   0, 16,  0,      10000, config_semi_custom_warp_config>)
    INSTANTIATE(params<long long,           test_utils::custom_test_type<char>, false,  0, 64,  4000,   8000,  config_custom>)
    INSTANTIATE(params<double,              unsigned int,                       false,  0, 64,  2,      10>)
    INSTANTIATE(params<int8_t,              int8_t,                             true,   0, 8,   2000,   10000>)
    INSTANTIATE(params<int8_t,              int8_t,                             false,  0, 8,   0,      1000>)
    INSTANTIATE(params<uint8_t,             uint8_t,                            true,   0, 8,   2000,   10000>)
    INSTANTIATE(params<uint8_t,             uint8_t,                            false,  0, 8,   0,      1000>)
    INSTANTIATE(params<rocprim::half,       rocprim::half,                      true,   0, 16,  2000,   10000>)
    INSTANTIATE(params<rocprim::half,       rocprim::half,                      false,  0, 16,  0,      1000>)
    INSTANTIATE(params<rocprim::bfloat16,   rocprim::bfloat16,                  true,   0, 16,  2000,   10000>)
#elif ROCPRIM_TEST_TYPE_SLICE == 1
    INSTANTIATE(params<rocprim::bfloat16,   rocprim::bfloat16,                  false, 0, 16, 0, 1000>)
    INSTANTIATE(params<float,               int,                                false, 0, 32, 0, 1000>)
    INSTANTIATE(params<test_utils::custom_float_type, int,                      true,  0, 32, 0, 8192>)

    // start_bit and end_bit

    INSTANTIATE(params<uint8_t,             uint8_t,                                true,   2, 5,   0,      10000>)
    INSTANTIATE(params<uint8_t,             uint8_t,                                false,  2, 6,   1000,   10000>)
    INSTANTIATE(params<unsigned short,      rocprim::half,                          true,   4, 10,  0,      10000>)
    INSTANTIATE(params<unsigned short,      rocprim::bfloat16,                      true,   4, 10,  0,      10000>)
    INSTANTIATE(params<unsigned char,       int,                                    true,   2, 5,   0,      100>)
    INSTANTIATE(params<unsigned short,      int,                                    true,   4, 10,  0,      10000>)
    INSTANTIATE(params<unsigned int,        short,                                  false,  3, 22,  1000,   10000>)
    INSTANTIATE(params<unsigned int,        double,                                 true,   4, 21,  100,    100000>)
    INSTANTIATE(params<unsigned int,        short,                                  true,   0, 15,  100000, 200000>)
    INSTANTIATE(params<unsigned long long,  char,                                   false,  8, 20,  0,      1000>)
    INSTANTIATE(params<unsigned short,      test_utils::custom_test_type<double>,   false,  8, 11,  50,     200>)
#endif
