okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-139b-arc' into f-139-relad33b8074

main
3.2 KiB121 linesraw
1//==---- lib_common_utils.hpp ---------------------*- C++ -*----------------==//
2//
3// Copyright (C) Intel Corporation
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5// See https://llvm.org/LICENSE.txt for license information.
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef __DPCT_LIB_COMMON_UTILS_HPP__
10#define __DPCT_LIB_COMMON_UTILS_HPP__
11
12#include "compat_service.hpp"
13
14#if defined(__has_include) && __has_include(<oneapi/math.hpp>)
15#include <oneapi/math.hpp>
16#include <oneapi/mkl/namespace_alias.hpp>
17#elif defined(__has_include) && __has_include(<oneapi/mkl.hpp>)
18#include <oneapi/mkl.hpp>
19#elif defined(__has_include)
20#error "SYCLomatic runtime requires oneMath/oneMKL support"
21#else
22#error "SYCLomatic runtime requires __has_include support"
23#endif
24
25namespace dpct {
26
27enum class version_field : int { major, minor, update, patch };
28
29/// Returns the requested field of Intel(R) oneAPI Math Kernel Library version.
30/// \param field The version information field (major, minor, update or patch).
31/// \param result The result value.
32inline void mkl_get_version(version_field field, int *result) {
33#ifndef __INTEL_MKL__
34  throw std::runtime_error("The oneAPI Math Kernel Library (oneMKL) Interfaces "
35                           "Project does not support this API.");
36#else
37  MKLVersion version;
38  mkl_get_version(&version);
39  if (version_field::major == field) {
40    *result = version.MajorVersion;
41  } else if (version_field::minor == field) {
42    *result = version.MinorVersion;
43  } else if (version_field::update == field) {
44    *result = version.UpdateVersion;
45  } else if (version_field::patch == field) {
46    *result = 0;
47  } else {
48    throw std::runtime_error("unknown field");
49  }
50#endif
51}
52
53enum class library_data_t : unsigned char {
54  real_float = 0,
55  complex_float,
56  real_double,
57  complex_double,
58  real_half,
59  complex_half,
60  real_bfloat16,
61  complex_bfloat16,
62  real_int4,
63  complex_int4,
64  real_uint4,
65  complex_uint4,
66  real_int8,
67  complex_int8,
68  real_uint8,
69  complex_uint8,
70  real_int16,
71  complex_int16,
72  real_uint16,
73  complex_uint16,
74  real_int32,
75  complex_int32,
76  real_uint32,
77  complex_uint32,
78  real_int64,
79  complex_int64,
80  real_uint64,
81  complex_uint64,
82  real_int8_4,
83  real_int8_32,
84  real_uint8_4,
85  real_f8_e4m3,
86  real_f8_e5m2,
87  library_data_t_size
88};
89
90enum class compute_type : int {
91  f16,
92  f16_standard,
93  f32,
94  f32_standard,
95  f32_fast_bf16,
96  f32_fast_tf32,
97  f64,
98  f64_standard,
99  i32,
100  i32_standard,
101};
102
103#ifdef DPCT_USM_LEVEL_NONE
104/// Cast a "rvalue reference to a temporary object" to an "lvalue reference to
105/// that temporary object".
106/// CAUTION:
107/// The returned lvalue reference is available only before the last step in
108/// evaluating the full-expression that contains this function call.
109/// \param [in] temporary_object The rvalue reference to a temporary object.
110/// \returns The lvalue reference to that temporary object.
111template <typename T>
112inline typename std::enable_if_t<std::is_rvalue_reference_v<T &&>, T &>
113rvalue_ref_to_lvalue_ref(T &&temporary_object) {
114  return temporary_object;
115}
116#endif
117} // namespace dpct
118
119#include "detail/lib_common_utils_detail.hpp"
120
121#endif // __DPCT_LIB_COMMON_UTILS_HPP__