1 | // Definitions of utility functions and enums |
2 | #pragma once |
3 | |
4 | #include "taichi/util/io.h" |
5 | #include "taichi/common/core.h" |
6 | #include "taichi/system/profiler.h" |
7 | #include "taichi/common/exceptions.h" |
8 | #include "taichi/ir/stmt_op_types.h" |
9 | #include "taichi/ir/type.h" |
10 | #include "taichi/ir/type_utils.h" |
11 | #include "taichi/ir/type_factory.h" |
12 | |
13 | namespace taichi::lang { |
14 | |
15 | real get_cpu_frequency(); |
16 | |
17 | extern real default_measurement_time; |
18 | |
19 | real measure_cpe(std::function<void()> target, |
20 | int64 elements_per_call, |
21 | real time_second = default_measurement_time); |
22 | |
23 | struct RuntimeContext; |
24 | |
25 | using FunctionType = std::function<void(RuntimeContext &)>; |
26 | |
27 | inline std::string make_list(const std::vector<std::string> &data, |
28 | std::string bracket = "" ) { |
29 | std::string ret = bracket; |
30 | for (int i = 0; i < (int)data.size(); i++) { |
31 | ret += data[i]; |
32 | if (i + 1 < (int)data.size()) { |
33 | ret += ", " ; |
34 | } |
35 | } |
36 | if (bracket == "<" ) { |
37 | ret += ">" ; |
38 | } else if (bracket == "{" ) { |
39 | ret += "}" ; |
40 | } else if (bracket == "[" ) { |
41 | ret += "]" ; |
42 | } else if (bracket == "(" ) { |
43 | ret += ")" ; |
44 | } else if (bracket != "" ) { |
45 | TI_P(bracket); |
46 | TI_NOT_IMPLEMENTED |
47 | } |
48 | return ret; |
49 | } |
50 | |
51 | template <typename T> |
52 | std::string make_list(const std::vector<T> &data, |
53 | std::function<std::string(const T &t)> func, |
54 | std::string bracket = "" ) { |
55 | std::vector<std::string> ret(data.size()); |
56 | for (int i = 0; i < (int)data.size(); i++) { |
57 | ret[i] = func(data[i]); |
58 | } |
59 | return make_list(ret, bracket); |
60 | } |
61 | |
62 | extern std::string compiled_lib_dir; |
63 | extern std::string runtime_tmp_dir; |
64 | std::string runtime_lib_dir(); |
65 | |
66 | bool command_exist(const std::string &command); |
67 | |
68 | } // namespace taichi::lang |
69 | |
70 | namespace taichi { |
71 | void initialize_benchmark(); |
72 | |
73 | template <typename T, typename... Args, typename FP = T (*)(Args...)> |
74 | FP function_pointer_helper(std::function<T(Args...)>) { |
75 | return nullptr; |
76 | } |
77 | |
78 | template <typename T, typename... Args, typename FP = T (*)(Args...)> |
79 | FP function_pointer_helper(T (*)(Args...)) { |
80 | return nullptr; |
81 | } |
82 | |
83 | template <typename T> |
84 | using function_pointer_type = |
85 | decltype(function_pointer_helper(std::declval<T>())); |
86 | |
87 | } // namespace taichi |
88 | |