Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 47 additions & 64 deletions examples/examples_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T> constexpr bool always_false_v = false;

template <typename T> struct smax_int_type {
static_assert(always_false_v<T>, "Unsupported integer type");
};

template <> struct smax_int_type<int> {
static constexpr SMAX::IntType value = SMAX::IntType::INT32;
};

template <> struct smax_int_type<unsigned int> {
static constexpr SMAX::IntType value = SMAX::IntType::UINT32;
};

template <> struct smax_int_type<long> {
static constexpr SMAX::IntType value = SMAX::IntType::INT64;
};

template <> struct smax_int_type<long long> {
static constexpr SMAX::IntType value = SMAX::IntType::INT64;
};

template <> struct smax_int_type<unsigned long long> {
static constexpr SMAX::IntType value = SMAX::IntType::UINT64;
};

template <typename T> struct smax_float_type {
static_assert(always_false_v<T>, "Unsupported integer type");
};

template <> struct smax_float_type<float> {
static constexpr SMAX::FloatType value = SMAX::FloatType::FLOAT32;
};

template <> struct smax_float_type<double> {
static constexpr SMAX::FloatType value = SMAX::FloatType::FLOAT64;
};

template <typename IT, typename VT>
void register_kernel(SMAX::Interface *smax, std::string kernel_name,
SMAX::KernelType KernelType,
SMAX::PlatformType PlatformType) {
if constexpr (std::is_same_v<IT, int>) {
if constexpr (std::is_same_v<VT, float>) {
smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType,
SMAX::IntType::INT32,
SMAX::FloatType::FLOAT32);
} else if constexpr (std::is_same_v<VT, double>) {
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<IT, long>) {
if constexpr (std::is_same_v<VT, float>) {
smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType,
SMAX::IntType::INT64,
SMAX::FloatType::FLOAT32);
} else if constexpr (std::is_same_v<VT, double>) {
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<IT, unsigned int>) {
if constexpr (std::is_same_v<VT, float>) {
smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType,
SMAX::IntType::UINT32,
SMAX::FloatType::FLOAT32);
} else if constexpr (std::is_same_v<VT, double>) {
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<IT, long long>) {
if constexpr (std::is_same_v<VT, float>) {
smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType,
SMAX::IntType::INT64,
SMAX::FloatType::FLOAT32);
} else if constexpr (std::is_same_v<VT, double>) {
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<IT, unsigned long long>) {
if constexpr (std::is_same_v<VT, float>) {
smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType,
SMAX::IntType::UINT64,
SMAX::FloatType::FLOAT32);
} else if constexpr (std::is_same_v<VT, double>) {
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>, "IT must be an integral type");
static_assert(std::is_floating_point_v<VT>,
"VT must be a floating point type");

constexpr SMAX::IntType itype = smax_int_type<IT>::value;
constexpr SMAX::FloatType ftype = smax_float_type<VT>::value;

smax->register_kernel(kernel_name.c_str(), KernelType, PlatformType, itype,
ftype);
};

double compute_euclid_dist(const ULL n_rows, const double *y_SMAX,
Expand Down