diff --git a/examples/examples_common.hpp b/examples/examples_common.hpp index ceef0ec..a23b5f7 100644 --- a/examples/examples_common.hpp +++ b/examples/examples_common.hpp @@ -168,74 +168,57 @@ Only type supported by this helper function at this time: - int, long int, long long int, unsigned long long int - float, double */ -// TODO: Clean the mess up! +template constexpr bool always_false_v = false; + +template struct smax_int_type { + static_assert(always_false_v, "Unsupported integer type"); +}; + +template <> struct smax_int_type { + static constexpr SMAX::IntType value = SMAX::IntType::INT32; +}; + +template <> struct smax_int_type { + static constexpr SMAX::IntType value = SMAX::IntType::UINT32; +}; + +template <> struct smax_int_type { + static constexpr SMAX::IntType value = SMAX::IntType::INT64; +}; + +template <> struct smax_int_type { + static constexpr SMAX::IntType value = SMAX::IntType::INT64; +}; + +template <> struct smax_int_type { + static constexpr SMAX::IntType value = SMAX::IntType::UINT64; +}; + +template struct smax_float_type { + static_assert(always_false_v, "Unsupported integer type"); +}; + +template <> struct smax_float_type { + static constexpr SMAX::FloatType value = SMAX::FloatType::FLOAT32; +}; + +template <> struct smax_float_type { + static constexpr SMAX::FloatType value = SMAX::FloatType::FLOAT64; +}; + template void register_kernel(SMAX::Interface *smax, std::string kernel_name, SMAX::KernelType KernelType, SMAX::PlatformType PlatformType) { - if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT32, - SMAX::FloatType::FLOAT32); - } else if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT32, - SMAX::FloatType::FLOAT64); - } else { - std::cout << "VT not recognized" << std::endl; - } - } else if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT64, - SMAX::FloatType::FLOAT32); - } else if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT64, - SMAX::FloatType::FLOAT64); - } else { - std::cout << "VT not recognized" << std::endl; - } - } else if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::UINT32, - SMAX::FloatType::FLOAT32); - } else if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::UINT32, - SMAX::FloatType::FLOAT64); - } else { - std::cout << "VT not recognized" << std::endl; - } - } else if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT64, - SMAX::FloatType::FLOAT32); - } else if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::INT64, - SMAX::FloatType::FLOAT64); - } else { - std::cout << "VT not recognized" << std::endl; - } - } else if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::UINT64, - SMAX::FloatType::FLOAT32); - } else if constexpr (std::is_same_v) { - smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, - SMAX::IntType::UINT64, - SMAX::FloatType::FLOAT64); - } else { - std::cout << "VT not recognized" << std::endl; - } - } else { - std::cout << "IT not recognized" << std::endl; - } + static_assert(std::is_integral_v, "IT must be an integral type"); + static_assert(std::is_floating_point_v, + "VT must be a floating point type"); + + constexpr SMAX::IntType itype = smax_int_type::value; + constexpr SMAX::FloatType ftype = smax_float_type::value; + + smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, itype, + ftype); }; double compute_euclid_dist(const ULL n_rows, const double *y_SMAX,