mirror of
https://github.com/fumiama/base16384-sycl.git
synced 2026-06-09 20:50:29 +08:00
optimize: add xeinfo class & more compl. kernel
This commit is contained in:
@@ -5,36 +5,56 @@
|
||||
#include <iostream>
|
||||
#include <sycl/sycl.hpp>
|
||||
|
||||
typedef enum {
|
||||
base16384_errors_code_ok,
|
||||
base16384_errors_code_sync_sycl_exception,
|
||||
base16384_errors_code_std_exception,
|
||||
base16384_errors_code_unknown_exception,
|
||||
} base16384_errors_code_enum_t;
|
||||
|
||||
template <typename T>
|
||||
concept base16384_has_what_concept_t = requires(T t) { t.what(); };
|
||||
|
||||
template <base16384_has_what_concept_t T>
|
||||
static void base16384_print_what(T e, std::string msg) {
|
||||
std::cerr << msg << e.what() << std::endl;
|
||||
}
|
||||
template <typename F>
|
||||
concept base16384_callable_concept_t = requires(F f) { f(); };
|
||||
|
||||
// failed try to exec fn, catch and print .what() when exception is thrown.
|
||||
static base16384_errors_code_enum_t base16384_try_failed(std::function<void(void)> fn) {
|
||||
try {
|
||||
fn();
|
||||
} catch (sycl::exception &e) {
|
||||
base16384_print_what(e, "Caught sync SYCL exception: ");
|
||||
return base16384_errors_code_sync_sycl_exception;
|
||||
} catch (std::exception &e) {
|
||||
base16384_print_what(e, "Caught std exception: ");
|
||||
return base16384_errors_code_std_exception;
|
||||
} catch (...) {
|
||||
std::cerr << "Caught unknown exception." << std::endl;
|
||||
return base16384_errors_code_unknown_exception;
|
||||
}
|
||||
return base16384_errors_code_ok;
|
||||
}
|
||||
namespace base16384 {
|
||||
class errors {
|
||||
private:
|
||||
errors() = default;
|
||||
|
||||
template <base16384_has_what_concept_t T>
|
||||
static void print_what(T e, std::string msg) {
|
||||
std::cerr << msg << e.what() << std::endl;
|
||||
};
|
||||
|
||||
public:
|
||||
errors(const errors &) = delete;
|
||||
errors(errors &&) = delete;
|
||||
errors &operator=(const errors &) = delete;
|
||||
errors &operator=(errors &&) = delete;
|
||||
auto operator<=>(const errors &) const = delete;
|
||||
~errors() noexcept = default;
|
||||
|
||||
typedef enum {
|
||||
code_ok,
|
||||
code_sync_sycl_exception,
|
||||
code_std_exception,
|
||||
code_unknown_exception,
|
||||
} code_enum_t;
|
||||
|
||||
// failed try to exec fn, catch and print .what() when exception is thrown.
|
||||
template <base16384_callable_concept_t F>
|
||||
static code_enum_t try_failed(F &&fn) {
|
||||
try {
|
||||
fn();
|
||||
} catch (sycl::exception &e) {
|
||||
print_what(e, "Caught sync SYCL exception: ");
|
||||
return code_sync_sycl_exception;
|
||||
} catch (std::exception &e) {
|
||||
print_what(e, "Caught std exception: ");
|
||||
return code_std_exception;
|
||||
} catch (...) {
|
||||
std::cerr << "Caught unknown exception." << std::endl;
|
||||
return code_unknown_exception;
|
||||
}
|
||||
return code_ok;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace base16384
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user