|
|
|
@ -46,63 +46,100 @@ static inline std::string join(const std::string& part1, const std::string& part
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void GetDsoHandleWithSearchPath(
|
|
|
|
|
static inline void GetDsoHandleFromDefaultPath(
|
|
|
|
|
std::string& dso_path, void** dso_handle, int dynload_flags) {
|
|
|
|
|
LOG(INFO) << "Try to find cuda library: " << dso_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__) or defined(__OSX__)
|
|
|
|
|
if (nullptr == *dso_handle) {
|
|
|
|
|
dso_path = join("/usr/local/cuda/lib/", dso_path);
|
|
|
|
|
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);
|
|
|
|
|
if (nullptr == *dso_handle) {
|
|
|
|
|
if (dso_path == "libcudnn.dylib") {
|
|
|
|
|
LOG(FATAL) << "Note: [Recommend] copy cudnn into /usr/local/cuda/ \n"
|
|
|
|
|
<< "For instance, sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C "
|
|
|
|
|
<< "/usr/local \n sudo chmod a+r /usr/local/cuda/include/cudnn.h "
|
|
|
|
|
<< "/usr/local/cuda/lib/libcudnn*";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void GetDsoHandleFromSearchPath(
|
|
|
|
|
const std::string& search_root,
|
|
|
|
|
const std::string& dso_path,
|
|
|
|
|
const std::string& dso_name,
|
|
|
|
|
void** dso_handle) {
|
|
|
|
|
int dynload_flags = RTLD_LAZY | RTLD_LOCAL;
|
|
|
|
|
*dso_handle = nullptr;
|
|
|
|
|
|
|
|
|
|
std::string dlPath = dso_path;
|
|
|
|
|
std::string dlPath = dso_name;
|
|
|
|
|
if (search_root.empty()) {
|
|
|
|
|
// default search xxx.so from LD_LIBRARY_PATH
|
|
|
|
|
*dso_handle = dlopen(dlPath.c_str(), dynload_flags);
|
|
|
|
|
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
|
|
|
|
|
} else {
|
|
|
|
|
// search xxx.so from custom path
|
|
|
|
|
dlPath = join(search_root, dso_path);
|
|
|
|
|
dlPath = join(search_root, dso_name);
|
|
|
|
|
*dso_handle = dlopen(dlPath.c_str(), dynload_flags);
|
|
|
|
|
// then, search xxx.so from LD_LIBRARY_PATH
|
|
|
|
|
if (nullptr == *dso_handle) {
|
|
|
|
|
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);
|
|
|
|
|
// if not found, search from default path
|
|
|
|
|
if (nullptr == dso_handle) {
|
|
|
|
|
LOG(WARNING) << "Failed to find cuda library: " << dlPath;
|
|
|
|
|
dlPath = dso_name;
|
|
|
|
|
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CHECK(nullptr != *dso_handle)
|
|
|
|
|
<< "For Gpu version of PaddlePaddle, it couldn't find CUDA library: "
|
|
|
|
|
<< dlPath.c_str() << ". Please make sure you already specify its path. "
|
|
|
|
|
<< "Note: for training data on Cpu using Gpu version of PaddlePaddle, "
|
|
|
|
|
<< "you must specify libcudart via export LD_LIBRARY_PATH for Linux or "
|
|
|
|
|
<< "export DYLD_LIBRARY_PATH for MAC OS.";
|
|
|
|
|
<< "Failed to find cuda library: " << dlPath << std::endl
|
|
|
|
|
<< "Please specify its path correctly using one of the following ideas: \n"
|
|
|
|
|
|
|
|
|
|
<< "Idea 1. set cuda and cudnn lib path at runtime. "
|
|
|
|
|
<< "http://www.paddlepaddle.org/doc/ui/cmd_argument/argument_outline.html \n"
|
|
|
|
|
<< "For instance, issue command: paddle train --use_gpu=1 "
|
|
|
|
|
<< "--cuda_dir=/usr/local/cudnn/lib --cudnn_dir=/usr/local/cudnn/lib ...\n"
|
|
|
|
|
|
|
|
|
|
<< "Idea 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, @Idea 1"
|
|
|
|
|
<< "always work well.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetCublasDsoHandle(void** dso_handle) {
|
|
|
|
|
#if defined(__APPLE__) || defined(__OSX__)
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cuda_dir, "libcublas.dylib", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.dylib", dso_handle);
|
|
|
|
|
#else
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cuda_dir, "libcublas.so", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.so", dso_handle);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetCudnnDsoHandle(void** dso_handle) {
|
|
|
|
|
#if defined(__APPLE__) || defined(__OSX__)
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", dso_handle);
|
|
|
|
|
#else
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cudnn_dir, "libcudnn.so", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.so", dso_handle);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetCudartDsoHandle(void** dso_handle) {
|
|
|
|
|
#if defined(__APPLE__) || defined(__OSX__)
|
|
|
|
|
GetDsoHandleWithSearchPath("", "libcudart.dylib", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath("", "libcudart.dylib", dso_handle);
|
|
|
|
|
#else
|
|
|
|
|
GetDsoHandleWithSearchPath("", "libcudart.so", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath("", "libcudart.so", dso_handle);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetCurandDsoHandle(void** dso_handle) {
|
|
|
|
|
#if defined(__APPLE__) || defined(__OSX__)
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cuda_dir, "libcurand.dylib", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.dylib", dso_handle);
|
|
|
|
|
#else
|
|
|
|
|
GetDsoHandleWithSearchPath(FLAGS_cuda_dir, "libcurand.so", dso_handle);
|
|
|
|
|
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so", dso_handle);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|