Returns the path to the running executable. N.B. Derived from //knowledge/smalltalk/background_kb.cc Arg: strip_exe: if true, remove the name of the executable itself from the returned string. Example: calling this from /usr/bin/foo would return /usr/bin.
| 189 | // returned string. Example: calling this from /usr/bin/foo |
| 190 | // would return /usr/bin. |
| 191 | static string GetBinaryDir(bool strip_exe) { |
| 192 | char exe_path[PATH_MAX] = {0}; |
| 193 | #if defined(__APPLE__) |
| 194 | uint32_t buffer_size = 0U; |
| 195 | _NSGetExecutablePath(nullptr, &buffer_size); |
| 196 | char unresolved_path[buffer_size]; |
| 197 | _NSGetExecutablePath(unresolved_path, &buffer_size); |
| 198 | CHECK_ERR(realpath(unresolved_path, exe_path) ? 1 : -1); |
| 199 | #else |
| 200 | #if defined(PLATFORM_WINDOWS) |
| 201 | HMODULE hModule = GetModuleHandle(NULL); |
| 202 | GetModuleFileName(hModule, exe_path, MAX_PATH); |
| 203 | #else |
| 204 | PCHECK(readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1) != -1); |
| 205 | #endif |
| 206 | #endif |
| 207 | // Make sure it's null-terminated: |
| 208 | exe_path[sizeof(exe_path) - 1] = 0; |
| 209 | |
| 210 | if (strip_exe) { |
| 211 | // The exe is the last component of the path, so remove one component. |
| 212 | string ret = exe_path; |
| 213 | std::vector<string> components = absl::StrSplit(exe_path, '/'); |
| 214 | components.pop_back(); |
| 215 | return absl::StrJoin(components, "/"); |
| 216 | } |
| 217 | return exe_path; |
| 218 | } |
| 219 | |
| 220 | port::Status GpuExecutor::LoadModuleFromCuBin(const char* cubin, |
| 221 | CUmodule* module) { |