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: Ic8c95228eb139058da8b5d66ba8439486154ca6f
[ROCm/hip commit: da27fd2b09]
This commit is contained in:
@@ -211,10 +211,7 @@ if ($HIP_PLATFORM eq "clang") {
|
||||
$HIPCXXFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
||||
$HIPCFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
|
||||
$HIPLDFLAGS .= " -L$HIP_LIB_PATH";
|
||||
if (not $isWindows) {
|
||||
$HIPLDFLAGS .= " -Wl,--rpath-link=$HIP_LIB_PATH";
|
||||
$HIPLDFLAGS .= " -lhip_hcc";
|
||||
} else {
|
||||
if ($isWindows) {
|
||||
$HIPLDFLAGS .= " -lamdhip64";
|
||||
}
|
||||
if ($HIP_CLANG_HCC_COMPAT_MODE) {
|
||||
@@ -480,6 +477,7 @@ foreach $arg (@ARGV)
|
||||
{
|
||||
$linkType = 0;
|
||||
$setLinkType = 1;
|
||||
$swallowArg = 1;
|
||||
}
|
||||
if(($trimarg eq '-use-sharedlib') and ($setLinkType eq 0))
|
||||
{
|
||||
@@ -770,6 +768,14 @@ if ($HIP_PLATFORM eq "clang") {
|
||||
if (not $isWindows) {
|
||||
$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
|
||||
|
||||
EXE=bit_extract
|
||||
EXE_STATIC=bit_extract_static
|
||||
|
||||
$(EXE): bit_extract.cpp
|
||||
$(HIPCC) $(HIPCC_FLAGS) $< -o $@
|
||||
|
||||
$(EXE_STATIC): bit_extract.cpp
|
||||
$(HIPCC) -use-staticlib $(HIPCC_FLAGS) $< -o $@
|
||||
|
||||
all: $(EXE) $(EXE_STATIC)
|
||||
|
||||
clean:
|
||||
rm -f *.o $(EXE)
|
||||
rm -f *.o $(EXE) $(EXE_STATIC)
|
||||
|
||||
@@ -11,7 +11,7 @@ else
|
||||
SOURCES=square.cpp
|
||||
endif
|
||||
|
||||
all: square.out
|
||||
all: square.out square.out.static
|
||||
|
||||
# Step
|
||||
square.cpp: square.cu
|
||||
@@ -20,5 +20,8 @@ square.cpp: square.cu
|
||||
square.out: $(SOURCES)
|
||||
$(HIPCC) $(CXXFLAGS) $(SOURCES) -o $@
|
||||
|
||||
square.out.static: $(SOURCES)
|
||||
$(HIPCC) -use-staticlib $(CXXFLAGS) $(SOURCES) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out square.cpp
|
||||
rm -f *.o *.out *.out.static square.cpp
|
||||
|
||||
@@ -156,13 +156,35 @@ add_library(amdhip64_static STATIC
|
||||
$<TARGET_OBJECTS:hip64>
|
||||
)
|
||||
|
||||
# We expect amdhip64_static to contain objects of vdi and hip. But linker
|
||||
# let amdhip64_static contain objects of hip only. So we will use a
|
||||
# a custom amdhip64_static_combiner to combine objects of vid and hip into
|
||||
# amdhip64_static. To avoid amdhip64_static contains itself,
|
||||
# amdhip64_static_temp is created internally.
|
||||
add_library(amdhip64_static_temp STATIC
|
||||
$<TARGET_OBJECTS:hip64>
|
||||
)
|
||||
|
||||
add_library(host INTERFACE)
|
||||
target_link_libraries(host INTERFACE amdhip64)
|
||||
add_library(device INTERFACE)
|
||||
target_link_libraries(device INTERFACE host)
|
||||
# TODO: we may create host_static and device_static to let app
|
||||
# link amdhip64_static
|
||||
|
||||
target_link_libraries(amdhip64_static PRIVATE amdvdi_static pthread dl)
|
||||
target_link_libraries(amdhip64 PRIVATE amdvdi_static pthread dl)
|
||||
target_link_libraries(amdhip64_static PRIVATE pthread dl)
|
||||
target_link_libraries(amdhip64_static_temp PRIVATE pthread dl)
|
||||
|
||||
# combine objects of vid and hip into amdhip64_static
|
||||
add_custom_target(
|
||||
amdhip64_static_combiner
|
||||
ALL
|
||||
COMMAND rm -f $<TARGET_FILE:amdhip64_static> # Must remove old one, otherwise the new one will contain obsolete stuff
|
||||
COMMAND ${CMAKE_AR} -rcsT $<TARGET_FILE:amdhip64_static> $<TARGET_FILE:amdhip64_static_temp> $<TARGET_FILE:amdvdi_static>
|
||||
DEPENDS amdhip64_static amdhip64_static_temp amdvdi_static # To make sure this is the last step
|
||||
COMMENT "Combining static libs into amdhip64_static"
|
||||
)
|
||||
|
||||
|
||||
INSTALL(PROGRAMS $<TARGET_FILE:amdhip64_static> DESTINATION lib COMPONENT MAIN)
|
||||
@@ -174,6 +196,6 @@ 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(TARGETS amdhip64_static amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
|
||||
INSTALL(TARGETS amdhip64 amdhip64_static host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
|
||||
INSTALL(EXPORT hip-targets DESTINATION ${CONFIG_PACKAGE_INSTALL_DIR} NAMESPACE hip::)
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ namespace hip {
|
||||
extern void init();
|
||||
|
||||
extern Device* getCurrentDevice();
|
||||
|
||||
extern void setCurrentDevice(unsigned int index);
|
||||
|
||||
/// Get VDI queue associated with hipStream
|
||||
@@ -255,6 +256,11 @@ private:
|
||||
~PlatformState() {}
|
||||
public:
|
||||
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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF"
|
||||
|
||||
thread_local std::stack<ihipExec_t> execStack_;
|
||||
PlatformState* PlatformState::platform_ = new PlatformState();
|
||||
PlatformState* PlatformState::platform_; // Initiaized as nullptr by default
|
||||
|
||||
struct __CudaFatBinaryWrapper {
|
||||
unsigned int magic;
|
||||
|
||||
Reference in New Issue
Block a user