Skip to content

Commit 261f694

Browse files
authored
Enable static_host_libarary testing and remove --emit-static-lib for new llvm driver (#437)
* Enable static_host_library Signed-off-by: zichguan-amd <zichuan.guan@amd.com> * Remove --emit-static-lib for new llvm driver Signed-off-by: zichguan-amd <zichuan.guan@amd.com> * Fix static lib command Signed-off-by: zichguan-amd <zichuan.guan@amd.com> --------- Signed-off-by: zichguan-amd <zichuan.guan@amd.com>
1 parent 0613e68 commit 261f694

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

HIP-Basic/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,7 @@ add_subdirectory(occupancy)
133133
add_subdirectory(runtime_compilation)
134134
add_subdirectory(saxpy)
135135
add_subdirectory(shared_memory)
136-
# We cannot build the static library on Windows as the HIP SDK does not include CMAKE_AR.
137-
if(
138-
NOT CMAKE_SYSTEM_NAME MATCHES "Windows"
139-
AND NOT "${ROCM_EXAMPLES_GPU_LANGUAGE}" STREQUAL "HIP"
140-
)
141-
add_subdirectory(static_host_library)
142-
endif()
136+
add_subdirectory(static_host_library)
143137
add_subdirectory(streams)
144138
add_subdirectory(texture_management)
145139
add_subdirectory(warp_shuffle)

HIP-Basic/static_host_library/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ ROCM_INSTALL_DIR ?= /opt/rocm
2929
CUDA_INSTALL_DIR ?= /usr/local/cuda
3030
HIP_INCLUDE_DIR := $(ROCM_INSTALL_DIR)/include
3131

32-
HIPCXX ?= $(ROCM_INSTALL_DIR)/bin/hipcc
3332
CXX ?= g++
33+
HIPCXX ?= $(ROCM_INSTALL_DIR)/bin/hipcc
34+
AR ?= ar
3435

3536
# Common variables and flags
3637
CXX_STD := c++17
@@ -49,7 +50,7 @@ ifeq ($(GPU_RUNTIME), CUDA)
4950
HIPLIBS += -L$(CUDA_INSTALL_DIR)/lib64 -lcudart
5051
else ifeq ($(GPU_RUNTIME), HIP)
5152
CXXFLAGS ?= -Wall -Wextra
52-
LIBFLAGS += --emit-static-lib -fPIC
53+
LIBFLAGS += -c -fPIC
5354
HIPLIBS += -L$(ROCM_INSTALL_DIR)/lib -lamdhip64
5455
HOSTFLAGS += $(CXXFLAGS)
5556
else
@@ -63,6 +64,7 @@ ILDLIBS += $(LDLIBS)
6364

6465
EXAMPLE_CXX := $(EXAMPLE)_cxx
6566
EXAMPLE_LIB := hip_static_host
67+
LIBOBJ := lib$(EXAMPLE_LIB).o
6668
LIBEXAMPLE := lib$(EXAMPLE_LIB).a
6769

6870
all: $(EXAMPLE) $(EXAMPLE_CXX)
@@ -73,10 +75,13 @@ $(EXAMPLE): main.cpp $(LIBEXAMPLE)
7375
$(EXAMPLE_CXX): main.cpp $(LIBEXAMPLE)
7476
$(CXX) $(HOSTFLAGS) $(ICPPFLAGS) -L. $(ILDFLAGS) -o $@ $< -l$(EXAMPLE_LIB) $(HIPLIBS) $(ILDLIBS)
7577

76-
$(LIBEXAMPLE): library/library.hip $(COMMON_INCLUDE_DIR)/example_utils.hpp
78+
$(LIBOBJ): library/library.hip $(COMMON_INCLUDE_DIR)/example_utils.hpp
7779
$(HIPCXX) $(ICXXFLAGS) $(ICPPFLAGS) $(ILDFLAGS) $(LIBFLAGS) -o $@ $< $(ILDLIBS)
7880

81+
$(LIBEXAMPLE): $(LIBOBJ)
82+
$(AR) rcs $@ $(LIBOBJ)
83+
7984
clean:
80-
$(RM) $(EXAMPLE_CXX) $(EXAMPLE) $(LIBEXAMPLE)
85+
$(RM) $(EXAMPLE_CXX) $(EXAMPLE) $(LIBEXAMPLE) $(LIBOBJ)
8186

8287
.PHONY: all clean

HIP-Basic/static_host_library/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ This example shows how to create a static library that exports hosts functions.
1818

1919
## Build Process
2020

21-
A HIP static host library is built the same as a regular application, except that the additional flag `--emit-static-lib` must be passed to `hipcc`. Additionally, the library should be compiled with position independent code enabled:
21+
A HIP static host library is built the same as a regular application. Additionally, the library should be compiled with position independent code enabled:
2222

2323
```shell
24-
hipcc library/library.hip -o liblibrary.a --emit-static-lib -fPIC
24+
hipcc library/library.hip -o liblibrary.o -c -fPIC
25+
ar rcs liblibrary.a liblibrary.o
2526
```
2627

2728
Linking the static library with another library or object is done in the same way as a regular library:

0 commit comments

Comments
 (0)