提交 e9f50bd5 编写于 作者: Y Yu Yang

Merge branch 'develop' into feature/add_clang_format_plugin

* Merge conflict using theirs
...@@ -12,17 +12,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,17 +12,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "hl_dso_loader.h" #include "hl_dso_loader.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/CommandLineParser.h" #include "paddle/utils/CommandLineParser.h"
#include "paddle/utils/Logging.h"
P_DEFINE_string(cudnn_dir, "", P_DEFINE_string(cudnn_dir,
"",
"Specify path for loading libcudnn.so. For instance, " "Specify path for loading libcudnn.so. For instance, "
"/usr/local/cudnn/lib64. If empty [default], dlopen " "/usr/local/cudnn/lib. If empty [default], dlopen "
"will search cudnn from LD_LIBRARY_PATH"); "will search cudnn from LD_LIBRARY_PATH");
P_DEFINE_string(cuda_dir, "", P_DEFINE_string(cuda_dir,
"",
"Specify path for loading cuda library, such as libcublas, " "Specify path for loading cuda library, such as libcublas, "
"libcurand. For instance, /usr/local/cuda/lib64. (Note: " "libcurand. For instance, /usr/local/cuda/lib64. (Note: "
"libcudart can not be specified by cuda_dir, since some " "libcudart can not be specified by cuda_dir, since some "
...@@ -33,7 +34,6 @@ static inline std::string join(const std::string& part1, ...@@ -33,7 +34,6 @@ static inline std::string join(const std::string& part1,
const std::string& part2) { const std::string& part2) {
// directory separator // directory separator
const char sep = '/'; const char sep = '/';
if (!part2.empty() && part2.front() == sep) { if (!part2.empty() && part2.front() == sep) {
return part2; return part2;
} }
...@@ -47,100 +47,115 @@ static inline std::string join(const std::string& part1, ...@@ -47,100 +47,115 @@ static inline std::string join(const std::string& part1,
return ret; return ret;
} }
static inline void GetDsoHandleFromDefaultPath( static inline void GetDsoHandleFromDefaultPath(std::string& dso_path,
std::string& dso_path, void** dso_handle, int dynload_flags) { void** dso_handle,
VLOG(3) << "Try to find cuda library: " << dso_path int dynload_flags) {
<< " from default system path."; VLOG(3) << "Try to find cuda library: " << dso_path
// default search from LD_LIBRARY_PATH/DYLD_LIBRARY_PATH << " from default system path.";
// default search from LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);
// DYLD_LIBRARY_PATH is disabled after Mac OS 10.11 to
// bring System Integrity Projection (SIP), if dso_handle
// is null, search from default package path in Mac OS.
#if defined(__APPLE__) || defined(__OSX__)
if (nullptr == *dso_handle) {
dso_path = join("/usr/local/cuda/lib/", dso_path);
*dso_handle = dlopen(dso_path.c_str(), dynload_flags); *dso_handle = dlopen(dso_path.c_str(), dynload_flags);
// DYLD_LIBRARY_PATH is disabled after Mac OS 10.11 to
// bring System Integrity Projection (SIP), if dso_handle
// is null, search from default package path in Mac OS.
#if defined(__APPLE__) || defined(__OSX__)
if (nullptr == *dso_handle) { if (nullptr == *dso_handle) {
dso_path = join("/usr/local/cuda/lib/", dso_path); if (dso_path == "libcudnn.dylib") {
*dso_handle = dlopen(dso_path.c_str(), dynload_flags); LOG(FATAL)
if (nullptr == *dso_handle) { << "Note: [Recommend] copy cudnn into /usr/local/cuda/ \n" // NOLINT
if (dso_path == "libcudnn.dylib") { << "For instance, sudo tar -xzf "
LOG(FATAL) << "Note: [Recommend] copy cudnn into /usr/local/cuda/ \n" // NOLINT "cudnn-7.5-osx-x64-v5.0-ga.tgz -C " // NOLINT
<< "For instance, sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C " // NOLINT << "/usr/local \n sudo chmod a+r "
<< "/usr/local \n sudo chmod a+r /usr/local/cuda/include/cudnn.h " // NOLINT "/usr/local/cuda/include/cudnn.h " // NOLINT
<< "/usr/local/cuda/lib/libcudnn*"; << "/usr/local/cuda/lib/libcudnn*";
} }
}
} }
#endif }
#endif
} }
static inline void GetDsoHandleFromSearchPath( static inline void GetDsoHandleFromSearchPath(const std::string& search_root,
const std::string& search_root, const std::string& dso_name,
const std::string& dso_name, void** dso_handle) {
void** dso_handle) { int dynload_flags = RTLD_LAZY | RTLD_LOCAL;
int dynload_flags = RTLD_LAZY | RTLD_LOCAL; *dso_handle = nullptr;
*dso_handle = nullptr;
std::string dlPath = dso_name;
std::string dlPath = dso_name; if (search_root.empty()) {
if (search_root.empty()) { GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags); } else {
} else { // search xxx.so from custom path
// search xxx.so from custom path dlPath = join(search_root, dso_name);
dlPath = join(search_root, dso_name); *dso_handle = dlopen(dlPath.c_str(), dynload_flags);
*dso_handle = dlopen(dlPath.c_str(), dynload_flags); // if not found, search from default path
// if not found, search from default path if (nullptr == *dso_handle) {
if (nullptr == dso_handle) { LOG(WARNING) << "Failed to find cuda library: " << dlPath;
LOG(WARNING) << "Failed to find cuda library: " << dlPath; dlPath = dso_name;
dlPath = dso_name; GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
}
} }
}
CHECK(nullptr != *dso_handle) CHECK(nullptr != *dso_handle) << "Failed to find cuda library: " << dlPath
<< "Failed to find cuda library: " << dlPath << std::endl << std::endl
<< "Please specify its path correctly using one of the following ways: \n" // NOLINT << "Please specify its path correctly using "
"one of the following ways: \n" // NOLINT
<< "Method 1. set cuda and cudnn lib path at runtime. "
<< "http://www.paddlepaddle.org/doc/ui/cmd_argument/argument_outline.html \n" // NOLINT << "Method 1. set cuda and cudnn lib path at "
<< "For instance, issue command: paddle train --use_gpu=1 " "runtime. "
<< "--cuda_dir=/usr/local/cuda/lib64 --cudnn_dir=/usr/local/cudnn/lib ...\n" // NOLINT << "http://www.paddlepaddle.org/doc/ui/"
"cmd_argument/"
<< "Method 2. set environment variable LD_LIBRARY_PATH on Linux or " "argument_outline.html \n" // NOLINT
<< "DYLD_LIBRARY_PATH on Mac OS. \n" << "For instance, issue command: paddle train "
<< "For instance, issue command: export LD_LIBRARY_PATH=... \n" "--use_gpu=1 "
<< "--cuda_dir=/usr/local/cuda/lib64 "
<< "Note: After Mac OS 10.11, using the DYLD_LIBRARY_PATH is impossible " "--cudnn_dir=/usr/local/cudnn/lib "
<< "unless System Integrity Protection (SIP) is disabled. However, method 1 " // NOLINT "...\n" // NOLINT
<< "always work well.";
<< "Method 2. set environment variable "
"LD_LIBRARY_PATH on Linux or "
<< "DYLD_LIBRARY_PATH on Mac OS. \n"
<< "For instance, issue command: export "
"LD_LIBRARY_PATH=... \n"
<< "Note: After Mac OS 10.11, using the "
"DYLD_LIBRARY_PATH is impossible "
<< "unless System Integrity Protection (SIP) "
"is disabled. However, "
"method 1 " // NOLINT
<< "always work well.";
} }
void GetCublasDsoHandle(void** dso_handle) { void GetCublasDsoHandle(void** dso_handle) {
#if defined(__APPLE__) || defined(__OSX__) #if defined(__APPLE__) || defined(__OSX__)
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.dylib", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.dylib", dso_handle);
#else #else
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.so", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.so", dso_handle);
#endif #endif
} }
void GetCudnnDsoHandle(void** dso_handle) { void GetCudnnDsoHandle(void** dso_handle) {
#if defined(__APPLE__) || defined(__OSX__) #if defined(__APPLE__) || defined(__OSX__)
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", dso_handle);
#else #else
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.so", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.so", dso_handle);
#endif #endif
} }
void GetCudartDsoHandle(void** dso_handle) { void GetCudartDsoHandle(void** dso_handle) {
#if defined(__APPLE__) || defined(__OSX__) #if defined(__APPLE__) || defined(__OSX__)
GetDsoHandleFromSearchPath("", "libcudart.dylib", dso_handle); GetDsoHandleFromSearchPath("", "libcudart.dylib", dso_handle);
#else #else
GetDsoHandleFromSearchPath("", "libcudart.so", dso_handle); GetDsoHandleFromSearchPath("", "libcudart.so", dso_handle);
#endif #endif
} }
void GetCurandDsoHandle(void** dso_handle) { void GetCurandDsoHandle(void** dso_handle) {
#if defined(__APPLE__) || defined(__OSX__) #if defined(__APPLE__) || defined(__OSX__)
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.dylib", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.dylib", dso_handle);
#else #else
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so", dso_handle); GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so", dso_handle);
#endif #endif
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册