1 | /******************************************************************************* |
---|---|
2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. |
3 | The use of this software is governed by the LICENSE file. |
4 | *******************************************************************************/ |
5 | |
6 | #include "taichi/common/core.h" |
7 | #include "taichi/common/version.h" |
8 | #include "taichi/common/commit_hash.h" |
9 | |
10 | #include <spdlog/fmt/fmt.h> |
11 | #include <cstdlib> |
12 | #include "taichi/common/logging.h" |
13 | |
14 | #if defined(TI_PLATFORM_WINDOWS) |
15 | #include "taichi/platform/windows/windows.h" |
16 | #else |
17 | // Mac and Linux |
18 | #include <unistd.h> |
19 | #endif |
20 | |
21 | namespace taichi { |
22 | |
23 | std::string python_package_dir; |
24 | |
25 | std::string get_python_package_dir() { |
26 | return python_package_dir; |
27 | } |
28 | |
29 | void set_python_package_dir(const std::string &dir) { |
30 | python_package_dir = dir; |
31 | } |
32 | |
33 | std::string get_repo_dir() { |
34 | #if defined(TI_PLATFORM_WINDOWS) |
35 | return "C:/taichi_cache/"; |
36 | #elif defined(TI_PLATFORM_ANDROID) |
37 | // @FIXME: Not supported on Android. A possibility would be to return the |
38 | // application cache directory. This feature is not used yet on this OS so |
39 | // it should not break anything (yet!) |
40 | return ""; |
41 | #else |
42 | auto xdg_cache = std::getenv("XDG_CACHE_HOME"); |
43 | |
44 | std::string xdg_cache_str; |
45 | if (xdg_cache != nullptr) { |
46 | xdg_cache_str = xdg_cache; |
47 | } else { |
48 | // XDG_CACHE_HOME is not defined, defaulting to ~/.cache |
49 | auto home = std::getenv("HOME"); |
50 | TI_ASSERT(home != nullptr); |
51 | xdg_cache_str = home; |
52 | xdg_cache_str += "/.cache"; |
53 | } |
54 | |
55 | return xdg_cache_str + "/taichi/"; |
56 | #endif |
57 | } |
58 | |
59 | CoreState &CoreState::get_instance() { |
60 | static CoreState state; |
61 | return state; |
62 | } |
63 | |
64 | int __trash__; |
65 | |
66 | std::string get_version_string() { |
67 | return fmt::format("{}.{}.{}", get_version_major(), get_version_minor(), |
68 | get_version_patch()); |
69 | } |
70 | |
71 | int get_version_major() { |
72 | return TI_VERSION_MAJOR; |
73 | } |
74 | |
75 | int get_version_minor() { |
76 | return TI_VERSION_MINOR; |
77 | } |
78 | |
79 | int get_version_patch() { |
80 | return TI_VERSION_PATCH; |
81 | } |
82 | |
83 | std::string get_commit_hash() { |
84 | return TI_COMMIT_HASH; |
85 | } |
86 | |
87 | std::string get_cuda_version_string() { |
88 | return CUDA_VERSION; |
89 | } |
90 | |
91 | int PID::get_pid() { |
92 | #if defined(TI_PLATFORM_WINDOWS) |
93 | return (int)GetCurrentProcessId(); |
94 | #else |
95 | return (int)getpid(); |
96 | #endif |
97 | } |
98 | |
99 | int PID::get_parent_pid() { |
100 | #if defined(TI_PLATFORM_WINDOWS) |
101 | TI_NOT_IMPLEMENTED |
102 | return -1; |
103 | #else |
104 | return (int)getppid(); |
105 | #endif |
106 | } |
107 | |
108 | } // namespace taichi |
109 |