@@ -19,22 +19,14 @@ limitations under the License.
1919#include " tensorflow/stream_executor/dso_loader.h"
2020
2121#include < limits.h>
22- #if defined(__APPLE__)
23- #include < mach-o/dyld.h>
24- #endif
2522#include < stdlib.h>
26- #if defined(PLATFORM_WINDOWS)
27- #include < windows.h>
28- #define PATH_MAX MAX_PATH
29- #else
30- #include < unistd.h>
31- #endif
3223#include < initializer_list>
3324#include < vector>
3425
3526#include " tensorflow/core/platform/load_library.h"
3627#include " tensorflow/stream_executor/lib/env.h"
3728#include " tensorflow/stream_executor/lib/error.h"
29+ #include " tensorflow/stream_executor/lib/path.h"
3830#include " tensorflow/stream_executor/lib/str_util.h"
3931#include " tensorflow/stream_executor/lib/strcat.h"
4032#include " tensorflow/stream_executor/lib/stringprintf.h"
@@ -130,29 +122,8 @@ string GetCudnnVersion() { return TF_CUDNN_VERSION; }
130122}
131123
132124/* static */ string DsoLoader::GetBinaryDirectory (bool strip_executable_name) {
133- char exe_path[PATH_MAX ] = {0 };
134- #ifdef __APPLE__
135- uint32_t buffer_size (0U );
136- _NSGetExecutablePath (nullptr , &buffer_size);
137- char unresolved_path[buffer_size];
138- _NSGetExecutablePath (unresolved_path, &buffer_size);
139- CHECK_ERR (realpath (unresolved_path, exe_path) ? 1 : -1 );
140- #elif defined(PLATFORM_WINDOWS)
141- HMODULE hModule = GetModuleHandle (NULL );
142- GetModuleFileName (hModule, exe_path, MAX_PATH );
143- #else
144- CHECK_ERR (readlink (" /proc/self/exe" , exe_path, sizeof (exe_path) - 1 ));
145- #endif
146- // Make sure it's null-terminated:
147- exe_path[sizeof (exe_path) - 1 ] = 0 ;
148-
149- if (strip_executable_name) {
150- // The exe is the last component of the path, so remove one component.
151- std::vector<string> components = port::Split (exe_path, ' /' );
152- components.pop_back ();
153- return port::Join (components, " /" );
154- }
155- return exe_path;
125+ string exe_path = port::Env::Default ()->GetExecutablePath ();
126+ return strip_executable_name ? port::Dirname (exe_path).ToString () : exe_path;
156127}
157128
158129// Creates a heap-allocated vector for initial rpaths.
0 commit comments