提交 5a86891f 编写于 作者: S silingtong123 提交者: liuwei1031

cherry pick #18761 (#19199)

* fix warpctc dynamic library not found issue on mac and windows platform
上级 de5dec84
...@@ -16,7 +16,6 @@ if (CUPTI_FOUND) ...@@ -16,7 +16,6 @@ if (CUPTI_FOUND)
list(APPEND CUDA_SRCS cupti.cc) list(APPEND CUDA_SRCS cupti.cc)
endif(CUPTI_FOUND) endif(CUPTI_FOUND)
nv_library(dynload_cuda SRCS ${CUDA_SRCS} DEPS dynamic_loader) nv_library(dynload_cuda SRCS ${CUDA_SRCS} DEPS dynamic_loader)
configure_file(warpctc_lib_path.h.in ${CMAKE_CURRENT_BINARY_DIR}/warpctc_lib_path.h)
cc_library(dynload_warpctc SRCS warpctc.cc DEPS dynamic_loader warpctc) cc_library(dynload_warpctc SRCS warpctc.cc DEPS dynamic_loader warpctc)
if (WITH_MKLML) if (WITH_MKLML)
cc_library(dynload_mklml SRCS mklml.cc DEPS dynamic_loader mklml) cc_library(dynload_mklml SRCS mklml.cc DEPS dynamic_loader mklml)
......
...@@ -20,7 +20,6 @@ limitations under the License. */ ...@@ -20,7 +20,6 @@ limitations under the License. */
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "glog/logging.h" #include "glog/logging.h"
#include "paddle/fluid/platform/dynload/cupti_lib_path.h" #include "paddle/fluid/platform/dynload/cupti_lib_path.h"
#include "paddle/fluid/platform/dynload/warpctc_lib_path.h"
#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/port.h" #include "paddle/fluid/platform/port.h"
...@@ -34,8 +33,6 @@ DEFINE_string(cuda_dir, "", ...@@ -34,8 +33,6 @@ DEFINE_string(cuda_dir, "",
"libcurand. For instance, /usr/local/cuda/lib64. If default, " "libcurand. For instance, /usr/local/cuda/lib64. If default, "
"dlopen will search cuda from LD_LIBRARY_PATH"); "dlopen will search cuda from LD_LIBRARY_PATH");
DEFINE_string(warpctc_dir, "", "Specify path for loading libwarpctc.so.");
DEFINE_string(nccl_dir, "", DEFINE_string(nccl_dir, "",
"Specify path for loading nccl library, such as libcublas, " "Specify path for loading nccl library, such as libcublas, "
"libcurand. For instance, /usr/local/cuda/lib64. If default, " "libcurand. For instance, /usr/local/cuda/lib64. If default, "
...@@ -52,8 +49,15 @@ DEFINE_string(mklml_dir, "", "Specify path for loading libmklml_intel.so."); ...@@ -52,8 +49,15 @@ DEFINE_string(mklml_dir, "", "Specify path for loading libmklml_intel.so.");
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dynload { namespace dynload {
struct PathNode {
PathNode() {}
std::string path = "";
};
static constexpr char cupti_lib_path[] = CUPTI_LIB_PATH; static constexpr char cupti_lib_path[] = CUPTI_LIB_PATH;
static constexpr char warpctc_lib_path[] = WARPCTC_LIB_PATH;
static PathNode s_py_site_pkg_path;
#if defined(_WIN32) && defined(PADDLE_WITH_CUDA) #if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
static constexpr char* win_cublas_lib = "cublas64_" PADDLE_CUDA_BINVER ".dll"; static constexpr char* win_cublas_lib = "cublas64_" PADDLE_CUDA_BINVER ".dll";
...@@ -78,6 +82,11 @@ static inline std::string join(const std::string& part1, ...@@ -78,6 +82,11 @@ static inline std::string join(const std::string& part1,
return ret; return ret;
} }
void SetPaddleLibPath(const std::string& py_site_pkg_path) {
s_py_site_pkg_path.path = py_site_pkg_path;
VLOG(3) << "Set paddle lib path : " << py_site_pkg_path;
}
static inline void* GetDsoHandleFromDefaultPath(const std::string& dso_path, static inline void* GetDsoHandleFromDefaultPath(const std::string& dso_path,
int dynload_flags) { int dynload_flags) {
VLOG(3) << "Try to find library: " << dso_path VLOG(3) << "Try to find library: " << dso_path
...@@ -214,9 +223,9 @@ void* GetCurandDsoHandle() { ...@@ -214,9 +223,9 @@ void* GetCurandDsoHandle() {
} }
void* GetWarpCTCDsoHandle() { void* GetWarpCTCDsoHandle() {
std::string warpctc_dir = warpctc_lib_path; std::string warpctc_dir = "";
if (!FLAGS_warpctc_dir.empty()) { if (!s_py_site_pkg_path.path.empty()) {
warpctc_dir = FLAGS_warpctc_dir; warpctc_dir = s_py_site_pkg_path.path;
} }
#if defined(__APPLE__) || defined(__OSX__) #if defined(__APPLE__) || defined(__OSX__)
return GetDsoHandleFromSearchPath(warpctc_dir, "libwarpctc.dylib"); return GetDsoHandleFromSearchPath(warpctc_dir, "libwarpctc.dylib");
......
...@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and ...@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#pragma once #pragma once
#include <string>
namespace paddle { namespace paddle {
namespace platform { namespace platform {
...@@ -33,6 +34,7 @@ void* GetNCCLDsoHandle(); ...@@ -33,6 +34,7 @@ void* GetNCCLDsoHandle();
void* GetTensorRtDsoHandle(); void* GetTensorRtDsoHandle();
void* GetMKLMLDsoHandle(); void* GetMKLMLDsoHandle();
void SetPaddleLibPath(const std::string&);
} // namespace dynload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle
/* Copyright (c) 2019 PaddlePaddle Authors. 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#define WARPCTC_LIB_PATH "@WARPCTC_INSTALL_DIR@/lib/"
...@@ -47,6 +47,7 @@ limitations under the License. */ ...@@ -47,6 +47,7 @@ limitations under the License. */
#include "paddle/fluid/operators/reader/lod_tensor_blocking_queue.h" #include "paddle/fluid/operators/reader/lod_tensor_blocking_queue.h"
#include "paddle/fluid/platform/cpu_helper.h" #include "paddle/fluid/platform/cpu_helper.h"
#include "paddle/fluid/platform/cpu_info.h" #include "paddle/fluid/platform/cpu_info.h"
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/init.h" #include "paddle/fluid/platform/init.h"
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
...@@ -197,6 +198,8 @@ PYBIND11_MODULE(core_noavx, m) { ...@@ -197,6 +198,8 @@ PYBIND11_MODULE(core_noavx, m) {
m.def("print_mem_usage", m.def("print_mem_usage",
[]() { return memory::allocation::GPUMemMonitor.PrintMemUsage(); }); []() { return memory::allocation::GPUMemMonitor.PrintMemUsage(); });
m.def("_set_paddle_lib_path", &paddle::platform::dynload::SetPaddleLibPath);
BindImperative(&m); BindImperative(&m);
py::class_<Tensor>(m, "Tensor", py::buffer_protocol()) py::class_<Tensor>(m, "Tensor", py::buffer_protocol())
......
...@@ -418,8 +418,6 @@ EOF ...@@ -418,8 +418,6 @@ EOF
#remove proxy here to fix dist error on mac #remove proxy here to fix dist error on mac
export http_proxy= export http_proxy=
export https_proxy= export https_proxy=
# TODO: jiabin need to refine this part when these tests fixed on mac
ctest --output-on-failure -j $2
# make install should also be test when unittest # make install should also be test when unittest
make install -j 8 make install -j 8
...@@ -447,6 +445,9 @@ EOF ...@@ -447,6 +445,9 @@ EOF
pip3.7 install --user ${INSTALL_PREFIX:-/paddle/build}/opt/paddle/share/wheels/*.whl pip3.7 install --user ${INSTALL_PREFIX:-/paddle/build}/opt/paddle/share/wheels/*.whl
fi fi
# TODO: jiabin need to refine this part when these tests fixed on mac
ctest --output-on-failure -j $2
paddle version paddle version
fi fi
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
from __future__ import print_function from __future__ import print_function
import site
import sys import sys
import os import os
...@@ -34,8 +35,8 @@ if os.path.exists(current_path + os.sep + 'core_noavx.' + core_suffix): ...@@ -34,8 +35,8 @@ if os.path.exists(current_path + os.sep + 'core_noavx.' + core_suffix):
try: try:
if os.name == 'nt': if os.name == 'nt':
third_lib_path = current_path + os.sep + '..' + os.sep + 'libs' third_lib_path = current_path + os.sep + '..' + os.sep + 'libs'
os.environ['path'] += ';' + third_lib_path os.environ['path'] = third_lib_path + ';' + os.environ['path']
sys.path.append(third_lib_path) sys.path.insert(0, third_lib_path)
except ImportError as e: except ImportError as e:
from .. import compat as cpt from .. import compat as cpt
...@@ -175,6 +176,7 @@ if avx_supported(): ...@@ -175,6 +176,7 @@ if avx_supported():
from .core_avx import _set_fuse_parameter_memory_size from .core_avx import _set_fuse_parameter_memory_size
from .core_avx import _is_dygraph_debug_enabled from .core_avx import _is_dygraph_debug_enabled
from .core_avx import _dygraph_debug_level from .core_avx import _dygraph_debug_level
from .core_avx import _set_paddle_lib_path
except Exception as e: except Exception as e:
if has_avx_core: if has_avx_core:
raise e raise e
...@@ -203,9 +205,29 @@ if load_noavx: ...@@ -203,9 +205,29 @@ if load_noavx:
from .core_noavx import _set_fuse_parameter_memory_size from .core_noavx import _set_fuse_parameter_memory_size
from .core_noavx import _is_dygraph_debug_enabled from .core_noavx import _is_dygraph_debug_enabled
from .core_noavx import _dygraph_debug_level from .core_noavx import _dygraph_debug_level
from .core_noavx import _set_paddle_lib_path
except Exception as e: except Exception as e:
if has_noavx_core: if has_noavx_core:
sys.stderr.write( sys.stderr.write(
'Error: Can not import noavx core while this file exists ' + 'Error: Can not import noavx core while this file exists ' +
current_path + os.sep + 'core_noavx.' + core_suffix + '\n') current_path + os.sep + 'core_noavx.' + core_suffix + '\n')
raise e raise e
# set paddle lib path
def set_paddle_lib_path():
site_dirs = site.getsitepackages() if hasattr(
site,
'getsitepackages') else [x for x in sys.path if 'site-packages' in x]
for site_dir in site_dirs:
lib_dir = os.path.sep.join([site_dir, 'paddle', 'libs'])
if os.path.exists(lib_dir):
_set_paddle_lib_path(lib_dir)
return
if hasattr(site, 'USER_SITE'):
lib_dir = os.path.sep.join([site.USER_SITE, 'paddle', 'libs'])
if os.path.exists(lib_dir):
_set_paddle_lib_path(lib_dir)
set_paddle_lib_path()
...@@ -3,13 +3,14 @@ import subprocess ...@@ -3,13 +3,14 @@ import subprocess
import os import os
import re import re
import shutil import shutil
import sys
class BinaryDistribution(Distribution): class BinaryDistribution(Distribution):
def has_ext_modules(foo): def has_ext_modules(foo):
return True return True
RC = 0 RC = 0
ext_name = '.dll' if os.name == 'nt' else '.so' ext_name = '.dll' if os.name == 'nt' else ('.dylib' if sys.platform == 'darwin' else '.so')
def git_commit(): def git_commit():
try: try:
...@@ -145,9 +146,9 @@ if '${CMAKE_SYSTEM_PROCESSOR}' not in ['arm', 'armv7-a', 'aarch64']: ...@@ -145,9 +146,9 @@ if '${CMAKE_SYSTEM_PROCESSOR}' not in ['arm', 'armv7-a', 'aarch64']:
paddle_bins = '' paddle_bins = ''
if not '${WIN32}': if not '${WIN32}':
paddle_bins = ['${PADDLE_BINARY_DIR}/paddle/scripts/paddle'] paddle_bins = ['${PADDLE_BINARY_DIR}/paddle/scripts/paddle']
package_data={'paddle.fluid': ['${FLUID_CORE_NAME}' + (ext_name if os.name != 'nt' else '.pyd')]} package_data={'paddle.fluid': ['${FLUID_CORE_NAME}' + ('.so' if os.name != 'nt' else '.pyd')]}
if '${HAS_NOAVX_CORE}' == 'ON': if '${HAS_NOAVX_CORE}' == 'ON':
package_data['paddle.fluid'] += ['core_noavx' + (ext_name if os.name != 'nt' else '.pyd')] package_data['paddle.fluid'] += ['core_noavx' + ('.so' if os.name != 'nt' else '.pyd')]
package_dir={ package_dir={
'': '${PADDLE_BINARY_DIR}/python', '': '${PADDLE_BINARY_DIR}/python',
...@@ -223,9 +224,9 @@ if '${CMAKE_BUILD_TYPE}' == 'Release': ...@@ -223,9 +224,9 @@ if '${CMAKE_BUILD_TYPE}' == 'Release':
if os.name != 'nt': if os.name != 'nt':
# only change rpath in Release mode, since in Debug mode, ${FLUID_CORE_NAME}.xx is too large to be changed. # only change rpath in Release mode, since in Debug mode, ${FLUID_CORE_NAME}.xx is too large to be changed.
if "@APPLE@" == "1": if "@APPLE@" == "1":
command = "install_name_tool -id \"@loader_path/../libs/\" ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + ext_name command = "install_name_tool -id \"@loader_path/../libs/\" ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so'
else: else:
command = "patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + ext_name command = "patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so'
if os.system(command) != 0: if os.system(command) != 0:
raise Exception("patch ${FLUID_CORE_NAME}.%s failed, command: %s" % (ext_name, command)) raise Exception("patch ${FLUID_CORE_NAME}.%s failed, command: %s" % (ext_name, command))
...@@ -237,6 +238,8 @@ if os.name == 'nt': ...@@ -237,6 +238,8 @@ if os.name == 'nt':
fix_package_dir[k] = v.replace('/', '\\') fix_package_dir[k] = v.replace('/', '\\')
package_dir = fix_package_dir package_dir = fix_package_dir
ext_modules = [] ext_modules = []
elif sys.platform == 'darwin':
ext_modules = []
setup(name='${PACKAGE_NAME}', setup(name='${PACKAGE_NAME}',
version='${PADDLE_VERSION}', version='${PADDLE_VERSION}',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册