Merge pull request #41870 from vnvo2409:load-library-env

PiperOrigin-RevId: 323943232
Change-Id: I8353b74b35afb636fc70950beb8274578fd4d087
This commit is contained in:
TensorFlower Gardener 2020-07-29 23:06:44 -07:00
commit a41532d723
2 changed files with 39 additions and 0 deletions

View File

@ -186,3 +186,22 @@ void TF_JoinThread(TF_Thread* thread) {
// ::tensorflow::Thread joins on destruction
delete reinterpret_cast<::tensorflow::Thread*>(thread);
}
void* TF_LoadSharedLibrary(const char* library_filename, TF_Status* status) {
void* handle = nullptr;
TF_SetStatus(status, TF_OK, "");
::tensorflow::Set_TF_Status_from_Status(
status,
::tensorflow::Env::Default()->LoadLibrary(library_filename, &handle));
return handle;
}
void* TF_GetSymbolFromLibrary(void* handle, const char* symbol_name,
TF_Status* status) {
void* symbol = nullptr;
TF_SetStatus(status, TF_OK, "");
::tensorflow::Set_TF_Status_from_Status(
status, ::tensorflow::Env::Default()->GetSymbolFromLibrary(
handle, symbol_name, &symbol));
return symbol;
}

View File

@ -184,6 +184,26 @@ TF_CAPI_EXPORT extern TF_Thread* TF_StartThread(const TF_ThreadOptions* options,
// Waits for the given thread to finish execution, then deletes it.
TF_CAPI_EXPORT extern void TF_JoinThread(TF_Thread* thread);
// \brief Load a dynamic library.
//
// Pass "library_filename" to a platform-specific mechanism for dynamically
// loading a library. The rules for determining the exact location of the
// library are platform-specific and are not documented here.
//
// On success, place OK in status and return the newly created library handle.
// Otherwise returns nullptr and set error status.
TF_CAPI_EXPORT extern void* TF_LoadSharedLibrary(const char* library_filename,
TF_Status* status);
// \brief Get a pointer to a symbol from a dynamic library.
//
// "handle" should be a pointer returned from a previous call to
// TF_LoadLibraryFromEnv. On success, place OK in status and return a pointer to
// the located symbol. Otherwise returns nullptr and set error status.
TF_CAPI_EXPORT extern void* TF_GetSymbolFromLibrary(void* handle,
const char* symbol_name,
TF_Status* status);
#ifdef __cplusplus
}
#endif