Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra rpath for prebuilt ffmpeg dependencies #5481

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions dali/plugin/plugin_manager.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018, 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,20 +15,29 @@
#include "dali/plugin/plugin_manager.h"
#include <dlfcn.h>
#include <filesystem>
#include <iostream>
#include <utility>
#include "dali/core/error_handling.h"

namespace fs = std::filesystem;

namespace dali {

void PluginManager::LoadLibrary(const std::string& lib_path, bool global_symbols) {
void PluginManager::LoadLibrary(const std::string& lib_path, bool global_symbols, bool allow_fail) {
// dlopen is thread safe
int flags = global_symbols ? RTLD_GLOBAL : RTLD_LOCAL;
flags |= RTLD_LAZY;
LOG_LINE << "Loading " << lib_path << "\n";
auto handle = dlopen(lib_path.c_str(), flags);
DALI_ENFORCE(handle != nullptr, "Failed to load library: " + std::string(dlerror()));
if (handle == nullptr) {
std::string err_msg =
std::string("Failed to load library ") + lib_path + ": " + std::string(dlerror());
if (allow_fail) {
std::cerr << err_msg << "\n";
} else {
DALI_FAIL(err_msg);
}
}
}

inline const std::string& DefaultPluginPath() {
Expand All @@ -49,7 +58,8 @@ inline const std::string& DefaultPluginPath() {
return path;
}

inline void PluginManager::LoadDirectory(const std::string& path, bool global_symbols) {
inline void PluginManager::LoadDirectory(const std::string& path, bool global_symbols,
bool allow_fail) {
std::vector<std::string> plugin_paths;
if (!fs::is_directory(path)) {
LOG_LINE << path << " is not a directory. Nothing to load\n";
Expand All @@ -61,7 +71,7 @@ inline void PluginManager::LoadDirectory(const std::string& path, bool global_sy
fpath.path().extension() == ".so") {
// filename starts with libdali_ and ends with .so
auto p = fpath.path().string();
PluginManager::LoadLibrary(std::move(p), global_symbols);
PluginManager::LoadLibrary(std::move(p), global_symbols, allow_fail);
}
}
}
Expand All @@ -77,9 +87,9 @@ inline void PreloadPluginList(const std::string& dali_preload_plugins) {
dali_preload_plugins.substr(previous, index - previous) :
dali_preload_plugins.substr(previous);
if (fs::is_directory(plugin_path)) {
PluginManager::LoadDirectory(plugin_path);
PluginManager::LoadDirectory(plugin_path, false, true);
} else {
PluginManager::LoadLibrary(plugin_path);
PluginManager::LoadLibrary(plugin_path, false, true);
}
previous = index + 1;
} while (index != std::string::npos);
Expand All @@ -92,7 +102,7 @@ void PluginManager::LoadDefaultPlugins() {
if (dali_preload_plugins)
preload_plugins_str = dali_preload_plugins;
if (preload_plugins_str == "default") {
PluginManager::LoadDirectory(DefaultPluginPath());
PluginManager::LoadDirectory(DefaultPluginPath(), false, true);
} else {
PreloadPluginList(preload_plugins_str);
}
Expand Down
10 changes: 7 additions & 3 deletions dali/plugin/plugin_manager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018, 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,19 +29,23 @@ class DLL_PUBLIC PluginManager {
* @param [in] lib_path path to the plugin library, e.g. "/usr/lib/libcustomplugin.so"
* @param [in] global_symbols if true, the library is loaded with RTLD_GLOBAL flag or equivalent
* otherwise, RTLD_LOCAL is used
* @param [in] allow_fail if true, not being able to load a library won't result in a hard error
* @throws std::runtime_error if the library could not be loaded
*/
static DLL_PUBLIC void LoadLibrary(const std::string& lib_path, bool global_symbols = false);
static DLL_PUBLIC void LoadLibrary(const std::string& lib_path, bool global_symbols = false,
bool allow_fail = false);

/**
* @brief Load plugin directory. The plugin paths will have the following pattern:
* {lib_path}/{subpath}/libdali_{plugin_name}.so
* @param [in] lib_path path to the root directory where the plugins are located
* @param [in] global_symbols if true, the library is loaded with RTLD_GLOBAL flag or equivalent
* otherwise, RTLD_LOCAL is used
* @param [in] allow_fail if true, not being able to load a library won't result in a hard error
* @throws std::runtime_error if the library could not be loaded
*/
static DLL_PUBLIC void LoadDirectory(const std::string& lib_path, bool global_symbols = false);
static DLL_PUBLIC void LoadDirectory(const std::string& lib_path, bool global_symbols = false,
bool allow_fail = false);

/**
* @brief Load default plugin library
Expand Down
6 changes: 4 additions & 2 deletions dali/python/backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1662,11 +1662,13 @@ PYBIND11_MODULE(backend_impl, m) {

m.def("LoadLibrary", &PluginManager::LoadLibrary,
py::arg("lib_path"),
py::arg("global_symbols") = false);
py::arg("global_symbols") = false,
py::arg("allow_fail") = false);

m.def("LoadDirectory", &PluginManager::LoadDirectory,
py::arg("dir_path"),
py::arg("global_symbols") = false);
py::arg("global_symbols") = false,
py::arg("allow_fail") = false);

m.def("LoadDefaultPlugins", &PluginManager::LoadDefaultPlugins);

Expand Down
1 change: 1 addition & 0 deletions dali/test/python/checkpointing/test_dali_checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ def pipeline():
unsupported_ops = [
"experimental.decoders.video",
"experimental.inputs.video",
"plugin.video.decoder",
]


Expand Down
1 change: 1 addition & 0 deletions dali/test/python/test_dali_cpu_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ def test_random_crop_generator_cpu():
"experimental.median_blur", # not supported for CPU
"experimental.dilate", # not supported for CPU
"experimental.erode", # not supported for CPU
"plugin.video.decoder", # not supported for CPU
]


Expand Down
1 change: 1 addition & 0 deletions dali/test/python/test_dali_variable_batch_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@ def pipe(max_batch_size, input_data, device):
"experimental.readers.video", # readers do not support variable batch size yet
"experimental.audio_resample", # Alias of audio_resample (already tested)
"experimental.readers.fits", # readers do not support variable batch size yet
"plugin.video.decoder", # plugin not yet tested
]


Expand Down
1 change: 1 addition & 0 deletions dali/test/python/test_eager_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ def test_video_decoder():
"experimental.median_blur", # not supported for CPU
"experimental.dilate", # not supported for CPU
"experimental.erode", # not supported for CPU
"plugin.video.decoder", # not supported for CPU
]


Expand Down
1 change: 1 addition & 0 deletions plugins/video/pkg_src/ffmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ endif()
list(APPEND CMAKE_BUILD_RPATH "$ORIGIN") # current directory
list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN") # current directory
list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN/../..") # DALI dir is ../../ from plugin/${PLUGIN_NAME}
list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN/deps/ffmpeg/lib/${CMAKE_HOST_SYSTEM_PROCESSOR}")

if (BUILD_FFMPEG)
message(STATUS "Building from ${FFMPEG_SOURCE_URL}")
Expand Down
Loading