Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c2ab3f

Browse files
committed
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
1 parent 85fdbb8 commit 4c2ab3f

6 files changed

Lines changed: 46 additions & 13 deletions

File tree

bin/hipcc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ if ($HIP_PLATFORM eq "clang") {
211211
$HIPCXXFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
212212
$HIPCFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/..";
213213
$HIPLDFLAGS .= " -L$HIP_LIB_PATH";
214-
if (not $isWindows) {
215-
$HIPLDFLAGS .= " -Wl,--rpath-link=$HIP_LIB_PATH";
216-
$HIPLDFLAGS .= " -lhip_hcc";
217-
} else {
214+
if ($isWindows) {
218215
$HIPLDFLAGS .= " -lamdhip64";
219216
}
220217
if ($HIP_CLANG_HCC_COMPAT_MODE) {
@@ -480,6 +477,7 @@ foreach $arg (@ARGV)
480477
{
481478
$linkType = 0;
482479
$setLinkType = 1;
480+
$swallowArg = 1;
483481
}
484482
if(($trimarg eq '-use-sharedlib') and ($setLinkType eq 0))
485483
{
@@ -770,6 +768,14 @@ if ($HIP_PLATFORM eq "clang") {
770768
if (not $isWindows) {
771769
$HIPLDFLAGS .= " -lgcc_s -lgcc -lpthread -lm";
772770
}
771+
772+
if (not $isWindows and not $compileOnly) {
773+
if ($linkType eq 0) {
774+
$toolArgs .= " -L$HIP_LIB_PATH -lamdhip64_static -L$ROCM_PATH/lib -lhsa-runtime64 -ldl ";
775+
} else {
776+
$toolArgs .= " -Wl,--enable-new-dtags -Wl,--rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lhip_hcc ";
777+
}
778+
}
773779
}
774780

775781

samples/0_Intro/bit_extract/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ ifeq (${HIP_PLATFORM}, nvcc)
1313
endif
1414

1515
EXE=bit_extract
16+
EXE_STATIC=bit_extract_static
1617

1718
$(EXE): bit_extract.cpp
1819
$(HIPCC) $(HIPCC_FLAGS) $< -o $@
1920

21+
$(EXE_STATIC): bit_extract.cpp
22+
$(HIPCC) -use-staticlib $(HIPCC_FLAGS) $< -o $@
23+
24+
all: $(EXE) $(EXE_STATIC)
2025

2126
clean:
22-
rm -f *.o $(EXE)
27+
rm -f *.o $(EXE) $(EXE_STATIC)

samples/0_Intro/square/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ else
1111
SOURCES=square.cpp
1212
endif
1313

14-
all: square.out
14+
all: square.out square.out.static
1515

1616
# Step
1717
square.cpp: square.cu
@@ -20,5 +20,8 @@ square.cpp: square.cu
2020
square.out: $(SOURCES)
2121
$(HIPCC) $(CXXFLAGS) $(SOURCES) -o $@
2222

23+
square.out.static: $(SOURCES)
24+
$(HIPCC) -use-staticlib $(CXXFLAGS) $(SOURCES) -o $@
25+
2326
clean:
24-
rm -f *.o *.out square.cpp
27+
rm -f *.o *.out *.out.static square.cpp

vdi/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,41 @@ add_library(amdhip64 SHARED
152152
$<TARGET_OBJECTS:hip64>
153153
)
154154

155-
add_library(amdhip64_static STATIC
155+
add_library(amdhip64_static_base STATIC
156156
$<TARGET_OBJECTS:hip64>
157157
)
158158

159159
add_library(host INTERFACE)
160160
target_link_libraries(host INTERFACE amdhip64)
161+
target_link_libraries(host INTERFACE amdhip64_static_base)
161162
add_library(device INTERFACE)
162163
target_link_libraries(device INTERFACE host)
163164

164-
target_link_libraries(amdhip64_static PRIVATE amdvdi_static pthread dl)
165+
target_link_libraries(amdhip64_static_base PRIVATE amdvdi_static pthread dl)
165166
target_link_libraries(amdhip64 PRIVATE amdvdi_static pthread dl)
166167

168+
set(STATICLIBNAME "${hip_BINARY_DIR}/lib/libamdhip64_static.a")
169+
170+
add_custom_command(
171+
OUTPUT ${STATICLIBNAME}
172+
COMMAND rm -f ${STATICLIBNAME}
173+
COMMAND ${CMAKE_AR} -rcsT ${STATICLIBNAME} $<TARGET_FILE:amdhip64_static_base> $<TARGET_FILE:amdvdi_static>
174+
DEPENDS amdhip64_static_base amdvdi_static
175+
COMMENT "Combining static libs into ${STATICLIBNAME} "
176+
)
177+
178+
add_custom_target(amdhip64_static ALL
179+
DEPENDS ${STATICLIBNAME}
180+
)
167181

168-
INSTALL(PROGRAMS $<TARGET_FILE:amdhip64_static> DESTINATION lib COMPONENT MAIN)
169-
INSTALL(PROGRAMS $<TARGET_FILE:amdhip64> DESTINATION lib COMPONENT MAIN)
170182
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhip_hcc.so )" DESTINATION lib COMPONENT MAIN)
171183

172184
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink libamdhip64.so lib/libhiprtc.so )" DESTINATION lib COMPONENT MAIN)
173185
INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/libhip_hcc.so DESTINATION lib COMPONENT MAIN)
174186

175187
INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/libhiprtc.so DESTINATION lib COMPONENT MAIN)
176188

177-
INSTALL(TARGETS amdhip64_static amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
189+
INSTALL(PROGRAMS ${STATICLIBNAME} DESTINATION ${LIB_INSTALL_DIR})
190+
INSTALL(TARGETS amdhip64_static_base amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR})
178191
INSTALL(EXPORT hip-targets DESTINATION ${CONFIG_PACKAGE_INSTALL_DIR} NAMESPACE hip::)
179192

vdi/hip_internal.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace hip {
132132
extern void init();
133133

134134
extern Device* getCurrentDevice();
135+
135136
extern void setCurrentDevice(unsigned int index);
136137

137138
/// Get VDI queue associated with hipStream
@@ -255,6 +256,11 @@ class PlatformState {
255256
~PlatformState() {}
256257
public:
257258
static PlatformState& instance() {
259+
if (platform_ == nullptr) {
260+
// __hipRegisterFatBinary() will call this when app starts, thus
261+
// there is no multiple entry issue here.
262+
platform_ = new PlatformState();
263+
}
258264
return *platform_;
259265
}
260266

vdi/hip_platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF"
3131

3232
thread_local std::stack<ihipExec_t> execStack_;
33-
PlatformState* PlatformState::platform_ = new PlatformState();
33+
PlatformState* PlatformState::platform_ = nullptr;
3434

3535
struct __CudaFatBinaryWrapper {
3636
unsigned int magic;

0 commit comments

Comments
 (0)