Skip to content
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ if(WITH_GPU AND WITH_ROCM)
endif()

if(WITH_GPU AND NOT APPLE)
#(Note risemeup1): The cudart dynamic library libcudart.so is used by set CUDA_USE_STATIC_CUDA_RUNTIME and CMAKE_CUDA_FLAGS
if(LINUX)
set(CUDA_USE_STATIC_CUDA_RUNTIME
OFF
CACHE BOOL "" FORCE)
set(CMAKE_CUDA_FLAGS "--cudart shared")
endif()
enable_language(CUDA)
message(STATUS "CUDA compiler: ${CMAKE_CUDA_COMPILER}, version: "
"${CMAKE_CUDA_COMPILER_ID} ${CMAKE_CUDA_COMPILER_VERSION}")
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ if(WITH_GPU)
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
DEPS ${PHI_DEPS})

elseif(WITH_ROCM)
hip_add_library(phi ${PHI_BUILD_TYPE} ${PHI_SRCS})
target_link_libraries(phi ${PHI_DEPS})
Expand Down
135 changes: 77 additions & 58 deletions paddle/phi/backends/dynload/dynamic_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License. */
#include <cstdlib>
#include <string>
#include <vector>

#include "paddle/phi/backends/dynload/cupti_lib_path.h"
#include "paddle/phi/backends/dynload/port.h"
#include "paddle/phi/core/enforce.h"
Expand All @@ -30,57 +29,20 @@ limitations under the License. */
#include "glog/logging.h"
#include "paddle/phi/core/flags.h"

PHI_DEFINE_string(cudnn_dir, // NOLINT
"",
"Specify path for loading libcudnn.so. For instance, "
"/usr/local/cudnn/lib. If empty [default], dlopen "
"will search cudnn from LD_LIBRARY_PATH");

PHI_DEFINE_string( // NOLINT
cuda_dir,
"",
"Specify path for loading cuda library, such as libcublas, libcublasLt "
"libcurand, libcusolver. For instance, /usr/local/cuda/lib64. "
"If default, dlopen will search cuda from LD_LIBRARY_PATH");

PHI_DEFINE_string(nccl_dir, // NOLINT
"",
"Specify path for loading nccl library, such as libnccl.so. "
"For instance, /usr/local/cuda/lib64. If default, "
"dlopen will search cuda from LD_LIBRARY_PATH");

PHI_DEFINE_string(cupti_dir,
"",
"Specify path for loading cupti.so."); // NOLINT

PHI_DEFINE_string( // NOLINT
tensorrt_dir,
"",
"Specify path for loading tensorrt library, such as libnvinfer.so.");

PHI_DEFINE_string(mklml_dir,
"",
"Specify path for loading libmklml_intel.so."); // NOLINT

PHI_DEFINE_string(lapack_dir,
"",
"Specify path for loading liblapack.so."); // NOLINT

PHI_DEFINE_string(mkl_dir, // NOLINT
"",
"Specify path for loading libmkl_rt.so. "
"For insrance, /opt/intel/oneapi/mkl/latest/lib/intel64/."
"If default, "
"dlopen will search mkl from LD_LIBRARY_PATH");

PHI_DEFINE_string(op_dir, // NOLINT
"",
"Specify path for loading user-defined op library.");

PHI_DEFINE_string(cusparselt_dir, // NOLINT
"",
"Specify path for loading libcusparseLt.so.");

PHI_DECLARE_string(cudnn_dir);
PHI_DECLARE_string(cuda_dir);
PHI_DECLARE_string(cublas_dir);
PHI_DECLARE_string(nccl_dir);
PHI_DECLARE_string(cupti_dir);
PHI_DECLARE_string(tensorrt_dir);
PHI_DECLARE_string(mklml_dir);
PHI_DECLARE_string(lapack_dir);
PHI_DECLARE_string(mkl_dir);
PHI_DECLARE_string(op_dir);
PHI_DECLARE_string(cusparselt_dir);
PHI_DECLARE_string(curand_dir);
PHI_DECLARE_string(cusolver_dir);
PHI_DECLARE_string(cusparse_dir);
#ifdef PADDLE_WITH_HIP

PHI_DEFINE_string(miopen_dir,
Expand Down Expand Up @@ -324,6 +286,17 @@ void* GetCublasDsoHandle() {
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return GetDsoHandleFromSearchPath(
FLAGS_cuda_dir, win_cublas_lib, true, {cuda_lib_path});
#elif defined(__linux__) && defined(PADDLE_WITH_CUDA)
if (CUDA_VERSION >= 11000 && CUDA_VERSION < 12000) {
return GetDsoHandleFromSearchPath(FLAGS_cublas_dir, "libcublas.so.11");
} else if (CUDA_VERSION >= 12000 && CUDA_VERSION <= 12030) {
return GetDsoHandleFromSearchPath(FLAGS_cublas_dir, "libcublas.so.12");
} else {
std::string warning_msg(
"Your CUDA_VERSION is less than 11 or greater than 12, paddle "
"temporarily no longer supports");
return nullptr;
}
#elif defined(PADDLE_WITH_HIP)
return GetDsoHandleFromSearchPath(FLAGS_rocm_dir, "librocblas.so");
#else
Expand All @@ -333,7 +306,18 @@ void* GetCublasDsoHandle() {

void* GetCublasLtDsoHandle() {
// APIs available after CUDA 10.1
#if defined(PADDLE_WITH_CUDA) && CUDA_VERSION >= 10010
#if defined(__linux__) && defined(PADDLE_WITH_CUDA)
if (CUDA_VERSION >= 11000 && CUDA_VERSION < 12000) {
return GetDsoHandleFromSearchPath(FLAGS_cublas_dir, "libcublasLt.so.11");
} else if (CUDA_VERSION >= 12000 && CUDA_VERSION <= 12030) {
return GetDsoHandleFromSearchPath(FLAGS_cublas_dir, "libcublasLt.so.12");
} else {
std::string warning_msg(
"Your CUDA_VERSION is less than 11 or greater than 12, paddle "
"temporarily no longer supports");
return nullptr;
}
#elif !defined(__linux__) && defined(PADDLE_WITH_CUDA) && CUDA_VERSION >= 10010
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublasLt.so");
#else
std::string warning_msg(
Expand Down Expand Up @@ -369,17 +353,30 @@ void* GetCUDNNDsoHandle() {
return GetDsoHandleFromSearchPath(FLAGS_miopen_dir, "libMIOpen.so", false);
#else
return GetDsoHandleFromSearchPath(
FLAGS_cudnn_dir, "libcudnn.so", false, {cuda_lib_path});
FLAGS_cudnn_dir, "libcudnn.so.8", false, {cuda_lib_path});
#endif
}

void* GetCUPTIDsoHandle() {
#if defined(__APPLE__) || defined(__OSX__)
return GetDsoHandleFromSearchPath(
FLAGS_cupti_dir, "libcupti.dylib", false, {cupti_lib_path});
#elif defined(__linux__) && defined(PADDLE_WITH_CUDA)
if (CUDA_VERSION >= 11000 && CUDA_VERSION < 12000) {
return GetDsoHandleFromSearchPath(
FLAGS_cupti_dir, "libcupti.so.11.7", false, {cupti_lib_path});
} else if (CUDA_VERSION >= 12000 && CUDA_VERSION < 12030) {
return GetDsoHandleFromSearchPath(
FLAGS_cupti_dir, "libcupti.so.12", false, {cupti_lib_path});
} else {
std::string warning_msg(
"Your CUDA_VERSION is less than 11 or greater than 12, paddle "
"temporarily no longer supports");
return nullptr;
}
#else
return GetDsoHandleFromSearchPath(
FLAGS_cupti_dir, "libcupti.so", false, {cupti_lib_path});
FLAGS_cupti_dir, "libcupti.so.11.7", false, {cupti_lib_path});
#endif
}

Expand All @@ -392,7 +389,7 @@ void* GetCurandDsoHandle() {
#elif defined(PADDLE_WITH_HIP)
return GetDsoHandleFromSearchPath(FLAGS_rocm_dir, "libhiprand.so");
#else
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so");
return GetDsoHandleFromSearchPath(FLAGS_curand_dir, "libcurand.so.10");
#endif
}

Expand Down Expand Up @@ -424,7 +421,7 @@ void* GetCusolverDsoHandle() {
return GetDsoHandleFromSearchPath(
FLAGS_cuda_dir, win_cusolver_lib, true, {cuda_lib_path});
#else
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcusolver.so");
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcusolver.so.11");
#endif
}

Expand All @@ -434,6 +431,17 @@ void* GetCusparseDsoHandle() {
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return GetDsoHandleFromSearchPath(
FLAGS_cuda_dir, win_cusparse_lib, true, {cuda_lib_path});
#elif defined(__linux__) && defined(PADDLE_WITH_CUDA)
if (CUDA_VERSION >= 11000 && CUDA_VERSION < 12000) {
return GetDsoHandleFromSearchPath(FLAGS_cusparse_dir, "libcusparse.so.11");
} else if (CUDA_VERSION >= 12000 && CUDA_VERSION <= 12030) {
return GetDsoHandleFromSearchPath(FLAGS_cusparse_dir, "libcusparse.so.12");
} else {
std::string warning_msg(
"Your CUDA_VERSION is less than 11 or greater than 12, paddle "
"temporarily no longer.");
return nullptr;
}
#elif defined(PADDLE_WITH_HIP)
return GetDsoHandleFromSearchPath(FLAGS_rocm_dir, "librocsparse.so");
#else
Expand Down Expand Up @@ -528,7 +536,7 @@ void* GetNCCLDsoHandle() {
FLAGS_rccl_dir, "librccl.so", true, {}, warning_msg);
#else
return GetDsoHandleFromSearchPath(
FLAGS_nccl_dir, "libnccl.so", true, {}, warning_msg);
FLAGS_nccl_dir, "libnccl.so.2", true, {}, warning_msg);
#endif
}

Expand Down Expand Up @@ -581,6 +589,17 @@ void* GetNvtxDsoHandle() {
void* GetCUFFTDsoHandle() {
#if defined(__APPLE__) || defined(__OSX__)
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcufft.dylib");
#elif defined(__linux__) && defined(PADDLE_WITH_CUDA)
if (CUDA_VERSION >= 11000 && CUDA_VERSION < 12000) {
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcufft.so.10");
} else if (CUDA_VERSION >= 12000 && CUDA_VERSION < 13000) {
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcufft.so.11");
} else {
std::string warning_msg(
"Your CUDA_VERSION is less than 11 or greater than 12, paddle "
"temporarily no longer.");
return nullptr;
}
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return GetDsoHandleFromSearchPath(
FLAGS_cuda_dir, win_cufft_lib, true, {cuda_lib_path});
Expand Down
67 changes: 67 additions & 0 deletions paddle/phi/core/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1528,3 +1528,70 @@ PHI_DEFINE_EXPORTED_int64(alloc_fill_value,
-1,
"Whether to fill fixed value after allocation. "
"This is usefull for debugging.");

PHI_DEFINE_EXPORTED_string(
cudnn_dir, // NOLINT
"",
"Specify path for loading libcudnn.so. For instance, "
"/usr/local/cudnn/lib. If empty [default], dlopen "
"will search cudnn from LD_LIBRARY_PATH");

PHI_DEFINE_EXPORTED_string( // NOLINT
cuda_dir,
"",
"Specify path for loading cuda library, such as libcublas, libcublasLt "
"libcurand, libcusolver. For instance, /usr/local/cuda/lib64. "
"If default, dlopen will search cuda from LD_LIBRARY_PATH");

PHI_DEFINE_EXPORTED_string(cublas_dir, // NOLINT
"",
"Specify path for loading libcublas.so.");
PHI_DEFINE_EXPORTED_string(
nccl_dir, // NOLINT
"",
"Specify path for loading nccl library, such as libnccl.so. "
"For instance, /usr/local/cuda/lib64. If default, "
"dlopen will search cuda from LD_LIBRARY_PATH");

PHI_DEFINE_EXPORTED_string(cupti_dir,
"",
"Specify path for loading cupti.so."); // NOLINT

PHI_DEFINE_EXPORTED_string( // NOLINT
tensorrt_dir,
"",
"Specify path for loading tensorrt library, such as libnvinfer.so.");

PHI_DEFINE_EXPORTED_string(
mklml_dir,
"",
"Specify path for loading libmklml_intel.so."); // NOLINT

PHI_DEFINE_EXPORTED_string(lapack_dir,
"",
"Specify path for loading liblapack.so."); // NOLINT

PHI_DEFINE_EXPORTED_string(
mkl_dir, // NOLINT
"",
"Specify path for loading libmkl_rt.so. "
"For insrance, /opt/intel/oneapi/mkl/latest/lib/intel64/."
"If default, "
"dlopen will search mkl from LD_LIBRARY_PATH");

PHI_DEFINE_EXPORTED_string(op_dir, // NOLINT
"",
"Specify path for loading user-defined op library.");

PHI_DEFINE_EXPORTED_string(cusparselt_dir, // NOLINT
"",
"Specify path for loading libcusparseLt.so.");
PHI_DEFINE_EXPORTED_string(curand_dir, // NOLINT
"",
"Specify path for loading libcurand.so.10.");
PHI_DEFINE_EXPORTED_string(cusolver_dir, // NOLINT
"",
"Specify path for loading libcusolver.so.*.");
PHI_DEFINE_EXPORTED_string(cusparse_dir, // NOLINT
"",
"Specify path for loading libcusparse.so.*.");
27 changes: 27 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,33 @@
if os.path.exists(cuh_file):
os.environ.setdefault('runtime_include_dir', runtime_include_dir)

if is_compiled_with_cuda():
import os

if os.name == 'posix':
package_dir = os.path.dirname(os.path.abspath(__file__))
cublas_lib_path = package_dir + "/.." + "/nvidia/cublas/lib"
set_flags({"FLAGS_cublas_dir": cublas_lib_path})

cudnn_lib_path = package_dir + "/.." + "/nvidia/cudnn/lib"
set_flags({"FLAGS_cudnn_dir": cudnn_lib_path})

curand_lib_path = package_dir + "/.." + "/nvidia/curand/lib"
set_flags({"FLAGS_curand_dir": curand_lib_path})

cusolver_lib_path = package_dir + "/.." + "/nvidia/cusolver/lib"
set_flags({"FLAGS_cusolver_dir": cusolver_lib_path})

cusparse_lib_path = package_dir + "/.." + "/nvidia/cusparse/lib"
set_flags({"FLAGS_cusparse_dir": cusparse_lib_path})

nccl_lib_path = package_dir + "/.." + "/nvidia/nccl/lib"
set_flags({"FLAGS_nccl_dir": nccl_lib_path})

cupti_dir_lib_path = package_dir + "/.." + "/nvidia/cuda_cupti/lib"
set_flags({"FLAGS_cupti_dir": cupti_dir_lib_path})


disable_static()

from .pir_utils import IrGuard
Expand Down
Loading