Skip to content
Snippets Groups Projects
Commit 35e94f4a authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Removed an unused link dir in hpvm-clang that may cause conflict

When the GCC used to compile tensor runtime is not the system's default,
path to that GCC's GLIBC leaks into hpvm-clang
that can override system's default and cause GLIBC failure.
parent ccf9b09e
No related branches found
No related tags found
No related merge requests found
...@@ -52,9 +52,8 @@ if(USE_GFLAGS) ...@@ -52,9 +52,8 @@ if(USE_GFLAGS)
list(APPEND LINK_LIBS gflags) list(APPEND LINK_LIBS gflags)
endif() endif()
# -- Manually list the directories (TRT_LINK_DIRS) and libraries (TRT_LINK_LIBS) # -- Manually list the directories (TRT_LINK_DIRS) tensor_runtime links to.
# tensor_runtime links to, because CMake doesn't help us do this. # This is needed by the RPATH setting step below, manually, because CMake doesn't help us do this.
# This is needed by both hpvm-clang and the RPATH setting step (below).
# First, take a guess at the paths to the libraries that are used here. # First, take a guess at the paths to the libraries that are used here.
# (CMake, why do you make this so difficult?) # (CMake, why do you make this so difficult?)
foreach(interface_lib ${LINK_LIBS}) foreach(interface_lib ${LINK_LIBS})
...@@ -62,18 +61,13 @@ foreach(interface_lib ${LINK_LIBS}) ...@@ -62,18 +61,13 @@ foreach(interface_lib ${LINK_LIBS})
foreach(actual_lib ${actual_libs}) foreach(actual_lib ${actual_libs})
# ${actual_lib} may not be a path, then taking the directory of it should return "". # ${actual_lib} may not be a path, then taking the directory of it should return "".
get_filename_component(libdir ${actual_lib} DIRECTORY) get_filename_component(libdir ${actual_lib} DIRECTORY)
get_filename_component(libname ${actual_lib} NAME)
if(NOT ${libdir} STREQUAL "") if(NOT ${libdir} STREQUAL "")
list(APPEND TRT_LINK_DIRS ${libdir}) list(APPEND TRT_LINK_DIRS ${libdir})
endif() endif()
if(NOT ${libname} STREQUAL "" AND NOT ${libname} STREQUAL "actual_libs-NOTFOUND")
list(APPEND TRT_LINK_LIBS ${libname})
endif()
endforeach() endforeach()
endforeach() endforeach()
# Dedup, just for shorter compiler arguments. # Dedup, just for shorter compiler arguments.
list(REMOVE_DUPLICATES TRT_LINK_DIRS) list(REMOVE_DUPLICATES TRT_LINK_DIRS)
list(REMOVE_DUPLICATES TRT_LINK_LIBS)
# -- Definitions # -- Definitions
set(DEFS -DPROMISE_TUNER_ENABLED -DSIMULATION_MODE=true) set(DEFS -DPROMISE_TUNER_ENABLED -DSIMULATION_MODE=true)
...@@ -120,13 +114,6 @@ function(add_tensor_runtime target_name) ...@@ -120,13 +114,6 @@ function(add_tensor_runtime target_name)
foreach(libdir ${TRT_LINK_DIRS}) foreach(libdir ${TRT_LINK_DIRS})
target_link_options(${target_name} PRIVATE "-Wl,-rpath,${libdir}") target_link_options(${target_name} PRIVATE "-Wl,-rpath,${libdir}")
endforeach() endforeach()
# Also slap TRT_LINK_DIRS and TRT_LINK_LIBS on this target
# so that hpvm-clang can read them. (we'll create our own properties.)
set_target_properties(
${target_name} PROPERTIES
TRT_LINK_DIRS "${TRT_LINK_DIRS}"
TRT_LINK_LIBS "${TRT_LINK_LIBS}"
)
endfunction(add_tensor_runtime) endfunction(add_tensor_runtime)
# Adding new rule for building a cuDNN runtime library # Adding new rule for building a cuDNN runtime library
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
# ---[ Define variables for main.py.in # ---[ Define variables for main.py.in
# main.py.in requires the following variables: # main.py.in requires the following variables:
# LLVM_PROJECT_DIR, LLVM_BUILD_DIR # LLVM_PROJECT_DIR, LLVM_BUILD_DIR
# INCLUDE_DIRS, LINK_DIRS, LINK_LIBS # INCLUDE_DIRS, DIRECT_LINK_LIBS
# DIRECT_LINK_LIBS, HPVM_USE_OPENCL (defined globally), HPVM_HAS_TRT # HPVM_USE_OPENCL (defined globally), HPVM_HAS_TRT
# AVAILABLE_PASSES, HPVM_RT_PATH # AVAILABLE_PASSES, HPVM_RT_PATH
set(LLVM_PROJECT_DIR ${CMAKE_SOURCE_DIR}) set(LLVM_PROJECT_DIR ${CMAKE_SOURCE_DIR})
...@@ -22,12 +22,8 @@ if(TARGET tensor_runtime) ...@@ -22,12 +22,8 @@ if(TARGET tensor_runtime)
set(HPVM_HAS_TRT 1) # Has tensor runtime set(HPVM_HAS_TRT 1) # Has tensor runtime
get_target_property(TRT_INCLUDE_DIRS tensor_runtime INCLUDE_DIRECTORIES) get_target_property(TRT_INCLUDE_DIRS tensor_runtime INCLUDE_DIRECTORIES)
get_target_property(TRT_LINK_DIRS tensor_runtime TRT_LINK_DIRS)
get_target_property(TRT_LINK_LIBS tensor_runtime TRT_LINK_LIBS)
list(APPEND INCLUDE_DIRS ${TRT_INCLUDE_DIRS}) list(APPEND INCLUDE_DIRS ${TRT_INCLUDE_DIRS})
list(APPEND LINK_DIRS ${TRT_LINK_DIRS})
list(APPEND LINK_LIBS ${TRT_LINK_LIBS})
list(APPEND DIRECT_LINK_LIBS "$<TARGET_FILE:tensor_runtime>") list(APPEND DIRECT_LINK_LIBS "$<TARGET_FILE:tensor_runtime>")
list(APPEND DEPS tensor_runtime) list(APPEND DEPS tensor_runtime)
else() else()
......
...@@ -11,8 +11,8 @@ LLVM_BUILD_BIN = Path("@LLVM_BUILD_DIR@") / "bin" ...@@ -11,8 +11,8 @@ LLVM_BUILD_BIN = Path("@LLVM_BUILD_DIR@") / "bin"
# Directories to include # Directories to include
INCLUDE_DIRS = "@INCLUDE_DIRS@".split(";") INCLUDE_DIRS = "@INCLUDE_DIRS@".split(";")
LINK_DIRS = [Path(s) for s in "@LINK_DIRS@".split(";")] # TODO: This dependency comes from hpvm-rt. Should have CMake inject this instead.
LINK_LIBS = "@LINK_LIBS@".split(";") LINK_LIBS = ["pthread"]
DIRECT_LINK_LIBS = "@DIRECT_LINK_LIBS@".split(";") DIRECT_LINK_LIBS = "@DIRECT_LINK_LIBS@".split(";")
HPVM_USE_OPENCL = int("@HPVM_USE_OPENCL@") HPVM_USE_OPENCL = int("@HPVM_USE_OPENCL@")
HPVM_HAS_TRT = int("@HPVM_HAS_TRT@") HPVM_HAS_TRT = int("@HPVM_HAS_TRT@")
...@@ -131,32 +131,29 @@ def link_binary( ...@@ -131,32 +131,29 @@ def link_binary(
extra_link_dirs: List[PathLike] = None, extra_link_dirs: List[PathLike] = None,
extra_link_libs: List[str] = None extra_link_libs: List[str] = None
) -> List[str]: ) -> List[str]:
link_dirs, link_libs = _link_args(extra_link_dirs or [], extra_link_libs or []) link_dirs, link_libnames = _parse_direct_link_libs()
link_dirs += (extra_link_dirs or [])
link_libstems = (extra_link_libs or []) + LINK_LIBS
linker_dir_flags = [] linker_dir_flags = []
for path in link_dirs: for path in link_dirs:
linker_dir_flags.extend([f"-L{path}", f"-Wl,-rpath={path}"]) linker_dir_flags.extend([f"-L{path}", f"-Wl,-rpath={path}"])
linker_lib_flags = [f"-l{lib}" for lib in link_libs] linker_lib_flags = (
[f"-l{lib}" for lib in link_libstems] +
[f"-l:{libname}" for libname in link_libnames]
)
return [ return [
str(LLVM_BUILD_BIN / "clang++"), str(src_file), str(LLVM_BUILD_BIN / "clang++"), str(src_file),
"-o", str(target_file), *linker_dir_flags, *linker_lib_flags "-o", str(target_file), *linker_dir_flags, *linker_lib_flags
] ]
def _link_args(extra_link_dirs: List[PathLike], extra_link_libs: List[str]): def _parse_direct_link_libs():
def drop_suffix(libname: str): link_dirs, link_libnames = [], []
import re
match = re.match(r"lib(.*)\.so", libname)
return libname if match is None else match.group(1)
link_dirs, link_libs = extra_link_dirs.copy(), extra_link_libs.copy()
for lib in DIRECT_LINK_LIBS: for lib in DIRECT_LINK_LIBS:
lib = Path(lib) lib = Path(lib)
link_dirs.append(lib.parent) link_dirs.append(lib.parent)
link_libs.append(lib.name) link_libnames.append(lib.name)
link_dirs += LINK_DIRS
link_libs += LINK_LIBS
link_libnames = [drop_suffix(s) for s in link_libs]
return link_dirs, link_libnames return link_dirs, link_libnames
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment