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
13namespace taichi::lang {
14
15real get_cpu_frequency();
16
17extern real default_measurement_time;
18
19real measure_cpe(std::function<void()> target,
20 int64 elements_per_call,
21 real time_second = default_measurement_time);
22
23struct RuntimeContext;
24
25using FunctionType = std::function<void(RuntimeContext &)>;
26
27inline 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
51template <typename T>
52std::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
62extern std::string compiled_lib_dir;
63extern std::string runtime_tmp_dir;
64std::string runtime_lib_dir();
65
66bool command_exist(const std::string &command);
67
68} // namespace taichi::lang
69
70namespace taichi {
71void initialize_benchmark();
72
73template <typename T, typename... Args, typename FP = T (*)(Args...)>
74FP function_pointer_helper(std::function<T(Args...)>) {
75 return nullptr;
76}
77
78template <typename T, typename... Args, typename FP = T (*)(Args...)>
79FP function_pointer_helper(T (*)(Args...)) {
80 return nullptr;
81}
82
83template <typename T>
84using function_pointer_type =
85 decltype(function_pointer_helper(std::declval<T>()));
86
87} // namespace taichi
88