Solve issues with hip-vdi runtime static lib
1.Combine libamdhip64_static_base.a and libamdvdi_static.a into libamdhip64_static.a.
2.Let hipcc use -use-staticlib to link libamdhip64_static.a.
3.Add some samples for static lib.
4.Fix compiling failure of code object.
Change-Id: Ia2333622a8d05639b90974c4c5d3d85654ba0138
[ROCm/hip commit: 4c2ab3f41e]
This commit is contained in:
+10
-4
@@ -211,10 +211,7 @@ if ($HIP_PLATFORM eq "clang") {
|
|||||||
$HIPCXXFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
$HIPCXXFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
||||||
$HIPCFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
$HIPCFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
||||||
$HIPLDFLAGS .= " -L$HIP_LIB_PATH";
|
$HIPLDFLAGS .= " -L$HIP_LIB_PATH";
|
||||||
if (not $isWindows) {
|
if ($isWindows) {
|
||||||
$HIPLDFLAGS .= " -Wl,--rpath-link=$HIP_LIB_PATH";
|
|
||||||
$HIPLDFLAGS .= " -lhip_hcc";
|
|
||||||
} else {
|
|
||||||
$HIPLDFLAGS .= " -lamdhip64";
|
$HIPLDFLAGS .= " -lamdhip64";
|
||||||
}
|
}
|
||||||
if ($HIP_CLANG_HCC_COMPAT_MODE) {
|
if ($HIP_CLANG_HCC_COMPAT_MODE) {
|
||||||
@@ -480,6 +477,7 @@ foreach $arg (@ARGV)
|
|||||||
{
|
{
|
||||||
$linkType = 0;
|
$linkType = 0;
|
||||||
$setLinkType = 1;
|
$setLinkType = 1;
|
||||||
|
$swallowArg = 1;
|
||||||
}
|
}
|
||||||
if(($trimarg eq '-use-sharedlib') and ($setLinkType eq 0))
|
if(($trimarg eq '-use-sharedlib') and ($setLinkType eq 0))
|
||||||
{
|
{
|
||||||
@@ -770,6 +768,14 @@ if ($HIP_PLATFORM eq "clang") {
|
|||||||
if (not $isWindows) {
|
if (not $isWindows) {
|
||||||
$HIPLDFLAGS .= " -lgcc_s -lgcc -lpthread -lm";
|
$HIPLDFLAGS .= " -lgcc_s -lgcc -lpthread -lm";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (not $isWindows and not $compileOnly) {
|
||||||
|
if ($linkType eq 0) {
|
||||||
|
$toolArgs .= " -L$HIP_LIB_PATH -lamdhip64_static -L$ROCM_PATH/lib -lhsa-runtime64 -ldl ";
|
||||||
|
} else {
|
||||||
|
$toolArgs .= " -Wl,--enable-new-dtags -Wl,--rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lhip_hcc ";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,15 @@ ifeq (${HIP_PLATFORM}, nvcc)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
EXE=bit_extract
|
EXE=bit_extract
|
||||||
|
EXE_STATIC=bit_extract_static
|
||||||
|
|
||||||
$(EXE): bit_extract.cpp
|
$(EXE): bit_extract.cpp
|
||||||
$(HIPCC) $(HIPCC_FLAGS) $< -o $@
|
$(HIPCC) $(HIPCC_FLAGS) $< -o $@
|
||||||
|
|
||||||
|
$(EXE_STATIC): bit_extract.cpp
|
||||||
|
$(HIPCC) -use-staticlib $(HIPCC_FLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(EXE) $(EXE_STATIC)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o $(EXE)
|
rm -f *.o $(EXE) $(EXE_STATIC)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ else
|
|||||||
SOURCES=square.cpp
|
SOURCES=square.cpp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: square.out
|
all: square.out square.out.static
|
||||||
|
|
||||||
# Step
|
# Step
|
||||||
square.cpp: square.cu
|
square.cpp: square.cu
|
||||||
@@ -20,5 +20,8 @@ square.cpp: square.cu
|
|||||||
square.out: $(SOURCES)
|
square.out: $(SOURCES)
|
||||||
$(HIPCC) $(CXXFLAGS) $(SOURCES) -o $@
|
$(HIPCC) $(CXXFLAGS) $(SOURCES) -o $@
|
||||||
|
|
||||||
|
square.out.static: $(SOURCES)
|
||||||
|
$(HIPCC) -use-staticlib $(CXXFLAGS) $(SOURCES) -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.out square.cpp
|
rm -f *.o *.out *.out.static square.cpp
|
||||||
|
|||||||
@@ -152,21 +152,33 @@ add_library(amdhip64 SHARED
|
|||||||
$<TARGET_OBJECTS:hip64>
|
$<TARGET_OBJECTS:hip64>
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(amdhip64_static STATIC
|
add_library(amdhip64_static_base STATIC
|
||||||
$<TARGET_OBJECTS:hip64>
|
$<TARGET_OBJECTS:hip64>
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(host INTERFACE)
|
add_library(host INTERFACE)
|
||||||
target_link_libraries(host INTERFACE amdhip64)
|
target_link_libraries(host INTERFACE amdhip64)
|
||||||
|
target_link_libraries(host INTERFACE amdhip64_static_base)
|
||||||
add_library(device INTERFACE)
|
add_library(device INTERFACE)
|
||||||
target_link_libraries(device INTERFACE host)
|
target_link_libraries(device INTERFACE host)
|
||||||
|
|
||||||
target_link_libraries(amdhip64_static PRIVATE amdvdi_static pthread dl)
|
target_link_libraries(amdhip64_static_base PRIVATE amdvdi_static pthread dl)
|
||||||
target_link_libraries(amdhip64 PRIVATE amdvdi_static pthread dl)
|
target_link_libraries(amdhip64 PRIVATE amdvdi_static pthread dl)
|
||||||
|
|
||||||
|
set(STATICLIBNAME "${hip_BINARY_DIR}/lib/libamdhip64_static.a")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${STATICLIBNAME}
|
||||||
|
COMMAND rm -f ${STATICLIBNAME}
|
||||||
|
COMMAND ${CMAKE_AR} -rcsT ${STATICLIBNAME} $<TARGET_FILE:amdhip64_static_base> $<TARGET_FILE:amdvdi_static>
|
||||||
|
DEPENDS amdhip64_static_base amdvdi_static
|
||||||
|
COMMENT "Combining static libs into ${STATICLIBNAME} "
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(amdhip64_static ALL
|
||||||
|
DEPENDS ${STATICLIBNAME}
|
||||||
|
)
|
||||||
|
|
||||||
INSTALL(PROGRAMS $<TARGET_FILE:amdhip64_static> DESTINATION lib COMPONENT MAIN)
|
|
||||||
INSTALL(PROGRAMS $<TARGET_FILE:amdhip64> DESTINATION lib COMPONENT MAIN)
|
|
||||||
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhip_hcc.so )" DESTINATION lib COMPONENT MAIN)
|
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhip_hcc.so )" DESTINATION lib COMPONENT MAIN)
|
||||||
|
|
||||||
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhiprtc.so )" DESTINATION lib COMPONENT MAIN)
|
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhiprtc.so )" DESTINATION lib COMPONENT MAIN)
|
||||||
@@ -174,6 +186,7 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/libhip_hcc.so DESTINATION lib COMPONENT MA
|
|||||||
|
|
||||||
INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/libhiprtc.so DESTINATION lib COMPONENT MAIN)
|
INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/libhiprtc.so DESTINATION lib COMPONENT MAIN)
|
||||||
|
|
||||||
INSTALL(TARGETS amdhip64_static amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
|
INSTALL(PROGRAMS ${STATICLIBNAME} DESTINATION ${LIB_INSTALL_DIR})
|
||||||
|
INSTALL(TARGETS amdhip64_static_base amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
|
||||||
INSTALL(EXPORT hip-targets DESTINATION ${CONFIG_PACKAGE_INSTALL_DIR} NAMESPACE hip::)
|
INSTALL(EXPORT hip-targets DESTINATION ${CONFIG_PACKAGE_INSTALL_DIR} NAMESPACE hip::)
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ namespace hip {
|
|||||||
extern void init();
|
extern void init();
|
||||||
|
|
||||||
extern Device* getCurrentDevice();
|
extern Device* getCurrentDevice();
|
||||||
|
|
||||||
extern void setCurrentDevice(unsigned int index);
|
extern void setCurrentDevice(unsigned int index);
|
||||||
|
|
||||||
/// Get VDI queue associated with hipStream
|
/// Get VDI queue associated with hipStream
|
||||||
@@ -255,6 +256,11 @@ private:
|
|||||||
~PlatformState() {}
|
~PlatformState() {}
|
||||||
public:
|
public:
|
||||||
static PlatformState& instance() {
|
static PlatformState& instance() {
|
||||||
|
if (platform_ == nullptr) {
|
||||||
|
// __hipRegisterFatBinary() will call this when app starts, thus
|
||||||
|
// there is no multiple entry issue here.
|
||||||
|
platform_ = new PlatformState();
|
||||||
|
}
|
||||||
return *platform_;
|
return *platform_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF"
|
constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF"
|
||||||
|
|
||||||
thread_local std::stack<ihipExec_t> execStack_;
|
thread_local std::stack<ihipExec_t> execStack_;
|
||||||
PlatformState* PlatformState::platform_ = new PlatformState();
|
PlatformState* PlatformState::platform_ = nullptr;
|
||||||
|
|
||||||
struct __CudaFatBinaryWrapper {
|
struct __CudaFatBinaryWrapper {
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
|
|||||||
Reference in New Issue
Block a user