Skip to content

Commit 185e2a5

Browse files
author
David Salinas
committed
merge amd-stg-open into amd-mainline-open
Bulk Promotion from July 20th, 2023 Merge commit '821c4a5d622158015e6ff4847ab917f348228beb' into HEAD Change-Id: If49761004bf0a9856eb9eada0a7d3f2025c5dd62
2 parents 86a2444 + 821c4a5 commit 185e2a5

31 files changed

+1708
-187
lines changed

amd/comgr/CMakeLists.txt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
cmake_minimum_required(VERSION 3.13.4)
22

3-
project(amd_comgr VERSION "2.5.0" LANGUAGES C CXX)
3+
project(amd_comgr VERSION "2.6.0" LANGUAGES C CXX)
44
set(amd_comgr_NAME "${PROJECT_NAME}")
55

6+
# Get git branch and commit hash to add to log for easier debugging.
7+
# Modeled after https://github.com/pmirshad/cmake-with-git-metadata.
8+
# Current working branch
9+
if(EXISTS "${CMAKE_SOURCE_DIR}/../../.git")
10+
execute_process(
11+
COMMAND git rev-parse --abbrev-ref HEAD
12+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
OUTPUT_VARIABLE AMD_COMGR_GIT_BRANCH
14+
OUTPUT_STRIP_TRAILING_WHITESPACE
15+
)
16+
# Shortened commit hash
17+
execute_process(
18+
COMMAND git log -1 --format=%h
19+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
20+
OUTPUT_VARIABLE AMD_COMGR_GIT_COMMIT
21+
OUTPUT_STRIP_TRAILING_WHITESPACE
22+
)
23+
else(EXISTS "${CMAKE_SOURCE_DIR}/../../.git")
24+
set(AMD_COMGR_GIT_BRANCH "not-available")
25+
set(AMD_COMGR_GIT_COMMIT "not-available")
26+
endif(EXISTS "${CMAKE_SOURCE_DIR}/../../.git")
27+
628
include(GNUInstallDirs)
729
include(CMakePackageConfigHelpers)
830
# Disable file reorg backward compatibility for ASAN build
@@ -111,7 +133,6 @@ message("--CLANG_INCLUDE_DIRS: ${CLANG_INCLUDE_DIRS}")
111133
message("----LLD_INCLUDE_DIRS: ${LLD_INCLUDE_DIRS}")
112134
message("---AMDDeviceLibs_DIR: ${AMDDeviceLibs_DIR}")
113135
message("------------ROCM_DIR: ${ROCM_DIR}")
114-
message("")
115136

116137
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
117138

@@ -139,13 +160,19 @@ set(AMD_COMGR_PRIVATE_COMPILE_DEFINITIONS ${LLVM_DEFINITIONS})
139160
set(AMD_COMGR_PUBLIC_LINKER_OPTIONS)
140161
set(AMD_COMGR_PRIVATE_LINKER_OPTIONS)
141162

163+
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS "-DAMD_COMGR_GIT_COMMIT=${AMD_COMGR_GIT_COMMIT}")
164+
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS "-DAMD_COMGR_GIT_BRANCH=${AMD_COMGR_GIT_BRANCH}")
165+
message("----COMGR_GIT_COMMIT: ${AMD_COMGR_GIT_COMMIT}")
166+
message("----COMGR_GIT_BRANCH: ${AMD_COMGR_GIT_BRANCH}")
167+
message("")
168+
142169
if (UNIX)
143170
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS
144171
-fno-rtti -Wall -Wno-attributes -fms-extensions -fvisibility=hidden)
145172
# TODO: Confirm this is actually needed due to LLVM/Clang code
146173
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS -fno-strict-aliasing)
147174
list(APPEND AMD_COMGR_PRIVATE_COMPILE_DEFINITIONS
148-
_GNU_SOURCE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS)
175+
_GNU_SOURCE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS AMD_COMGR_BUILD)
149176
list(APPEND AMD_COMGR_PUBLIC_LINKER_OPTIONS -pthread)
150177
if (NOT APPLE AND COMGR_BUILD_SHARED_LIBS)
151178
configure_file(

amd/comgr/cmake/opencl_pch.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function(generate_pch version)
3838

3939
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opencl${version}-c.pch
4040
COMMAND $<TARGET_FILE:clang> -cc1 -x cl-header -triple amdgcn-amd-amdhsa
41-
-Werror -O3 -Dcl_khr_fp64 -Dcl_khr_fp16 -DNDEBUG -cl-std=CL${version}
41+
-Werror -Wno-builtin-macro-redefined -O3 -Dcl_khr_fp64 -Dcl_khr_fp16 -DNDEBUG -cl-std=CL${version}
4242
-emit-pch -o ${CMAKE_CURRENT_BINARY_DIR}/opencl${version}-c.pch
4343
< ${OPENCL_C_H}
4444
DEPENDS clang ${OPENCL_C_H} ${clang_resource_headers_gen}

amd/comgr/docs/ReleaseNotes.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ code bases.
1919
legal comgr-objdump option. However registering this as an LLVM option by Comgr
2020
prevents other LLVM tools or instances from registering a -h option in the same
2121
process, which is an issue because -h is a common short form for -help.
22+
- Updated default code object version used when linking code object specific
23+
device library from v4 to v5
2224

2325
New Features
2426
------------
@@ -49,6 +51,14 @@ prevented correct execution of
4951
COMPILE\_SOURCE\_WITH\_DEVICE\_LIBS\_TO\_BC action.
5052
- Fixed a multi-threading bug where programs would hang when calling Comgr APIs
5153
like amd\_comgr\_iterate\_symbols() from multiple threads
54+
- Fixed an issue where providing DataObjects with an empty name to the bitcode
55+
linking action caused errors when AMD\_COMGR\_SAVE\_TEMPS was enabled, or when
56+
linking bitcode bundles.
57+
- Updated to use lld::lldMain() introduced in D110949 instead of the older
58+
lld::elf::link in Comgr's linkWithLLD()
59+
- Added -x assembler option to assembly compilation. Before, if an assembly file
60+
did not end with a .s file extension, it was not handled properly by the Comgr
61+
ASSEMBLE\_SOURCE\_TO\_RELOCATABLE action.
5262

5363

5464
New APIs
@@ -58,6 +68,15 @@ New APIs
5868
- Support bitcode and executable name lowering. The first call populates a
5969
list of mangled names for a given data object, while the second fetches a
6070
name from a given object and index.
71+
- amd\_comgr\_populate\_name\_expression\_map() (v2.6)
72+
- amd\_comgr\_map\_name\_expression\_to\_symbol\_name() (v2.6)
73+
- Support bitcode and code object name expression mapping. The first call
74+
populates a map of name expressions for a given comgr data object, using
75+
LLVM APIs to traverse the bitcode or code object. The second call returns
76+
a value (mangled symbol name) from the map for a given key (unmangled
77+
name expression). These calls assume that names of interest have been
78+
enclosed the HIP runtime using a stub attribute containg the following
79+
string in the name: "__amdgcn_name_expr".
6180

6281
Deprecated APIs
6382
---------------
@@ -67,6 +86,10 @@ Removed APIs
6786

6887
New Comgr Actions and Data Types
6988
--------------------------------
89+
- (Action) AMD\_COMGR\_ACTION\_COMPILE\_SOURCE\_TO\_RELOCATABLE
90+
- This action performs compile-to-bitcode, linking device libraries, and
91+
codegen-to-relocatable in a single step. By doing so, clients are able to defer more
92+
of the flag handling to toolchain. Currently only supports HIP.
7093
- (Data Type) AMD\_COMGR\_DATA\_KIND\_BC\_BUNDLE
7194
- (Data Type) AMD\_COMGR\_DATA\_KIND\_AR\_BUNDLE
7295
- These data kinds can now be passed to an AMD\_COMGR\_ACTION\_LINK\_BC\_TO\_BC
@@ -95,6 +118,12 @@ metadata querys for code object v2 objects.
95118
deprecation of code object v3 in LLVM. However, we still test loading and
96119
metadata querys for code object v3 objects.
97120
- Revamp symbolizer test to fail on errors, among other improvments
121+
- Improve linking and unbundling log to correctly store temporary files in /tmp,
122+
and to output clang-offload-bundler command to allow users to re-create Comgr
123+
unbundling.
124+
- Add git branch and commit hash for Comgr, and commit hash for LLVM to log
125+
output for Comgr actions. This can help us debug issues more quickly in cases
126+
where reporters provide Comgr logs.
98127

99128
New Targets
100129
-----------

amd/comgr/include/amd_comgr.h.in

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
// Add deprecation support for Comgr on Linux
5252
// This can be removed in favor of generic [[deprecated]] in C23, which should
5353
// also allow us to more easily include support on Windows
54+
55+
#ifndef AMD_COMGR_DEPRECATED
56+
#ifdef AMD_COMGR_BUILD
57+
#define AMD_COMGR_DEPRECATED(msg) // empty
58+
#endif
59+
#endif
60+
5461
#ifndef AMD_COMGR_DEPRECATED
5562
#if defined __GNUC__ && (__GNUC__ > 5 || defined __clang__)
5663
#define AMD_COMGR_DEPRECATED(msg) __attribute__((deprecated(msg)))
@@ -203,6 +210,12 @@ extern "C" {
203210
*/
204211
#define AMD_COMGR_VERSION_2_5
205212

213+
/**
214+
* The function was introduced or changed in version 2.6 of the interface
215+
* and has the symbol version string of ``"@amd_comgr_NAME@_2.6"``.
216+
*/
217+
#define AMD_COMGR_VERSION_2_6
218+
206219
/** @} */
207220

208221
/**
@@ -1572,8 +1585,9 @@ typedef enum amd_comgr_action_kind_s {
15721585
* Return @p AMD_COMGR_STATUS_ERROR if the link or unbundling fails.
15731586
*
15741587
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
1575-
* if isa name is not set in @p info and does not match the isa name
1576-
* of all bc data objects in @p input.
1588+
* if IsaName is not set in @p info and does not match the isa name
1589+
* of all bc data objects in @p input, or if the Name field is not set for
1590+
* any DataObject in the input set.
15771591
*/
15781592
AMD_COMGR_ACTION_LINK_BC_TO_BC = 0x4,
15791593
/**
@@ -1731,10 +1745,27 @@ typedef enum amd_comgr_action_kind_s {
17311745
* if isa name or language is not set in @p info.
17321746
*/
17331747
AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC = 0xF,
1748+
/**
1749+
* Compile a single source data object in @p input in order. For each
1750+
* successful compilation add a relocatable data object to @p result.
1751+
* Resolve any include source names using the names of include data objects
1752+
* in @p input. Resolve any include relative path names using the
1753+
* working directory path in @p info. Produce relocatable for hip name in @p
1754+
* info. Compile the source for the language in @p info. Link against
1755+
* the device-specific and language-specific bitcode device libraries
1756+
* required for compilation. Currently only supports HIP language.
1757+
*
1758+
* Return @p AMD_COMGR_STATUS_ERROR if any compilation
1759+
* fails.
1760+
*
1761+
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
1762+
* if isa name or language is not set in @p info.
1763+
*/
1764+
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE = 0x10,
17341765
/**
17351766
* Marker for last valid action kind.
17361767
*/
1737-
AMD_COMGR_ACTION_LAST = AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC
1768+
AMD_COMGR_ACTION_LAST = AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE
17381769
} amd_comgr_action_kind_t;
17391770

17401771
/**
@@ -2386,6 +2417,76 @@ amd_comgr_get_mangled_name(
23862417
size_t *size,
23872418
char *mangled_name) AMD_COMGR_VERSION_2_5;
23882419

2420+
/**
2421+
* @brief Populate a name expression map from a given code object.
2422+
*
2423+
* Used to map stub names *__amdgcn_name_expr_* in bitcodes and code
2424+
* objects generated by hip runtime to an associated (unmangled) name
2425+
* expression and (mangled) symbol name.
2426+
*
2427+
* @param[in] data A data object of kind @p
2428+
* AMD_COMGR_DATA_KIND_EXECUTABLE or @p AMD_COMGR_DATA_KIND_BC
2429+
*
2430+
* @param[out] count The number of name expressions mapped. This value
2431+
* can be used as an upper bound to the Index provided to the corresponding
2432+
* amd_comgr_map_name_expression_to_symbol_name() call.
2433+
*
2434+
* @retval ::AMD_COMGR_STATUS_SUCCESS The function executed successfully.
2435+
*
2436+
* @retval ::AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT @p data is
2437+
* an invalid data object or not of kind @p AMD_COMGR_DATA_KIND_EXECUTABLE or
2438+
* @p AMD_COMGR_DATA_KIND_BC.
2439+
*
2440+
* @retval ::AMD_COMGR_STATUS_ERROR LLVM API failure, which should be
2441+
* accompanied by an LLVM error message to stderr
2442+
*
2443+
*/
2444+
amd_comgr_status_t AMD_COMGR_API
2445+
amd_comgr_populate_name_expression_map(
2446+
amd_comgr_data_t data,
2447+
size_t *count) AMD_COMGR_VERSION_2_6;
2448+
2449+
/**
2450+
* @brief Fetch a related symbol name for a given name expression;
2451+
* or that name's length.
2452+
*
2453+
* The @p data must have had its name expression map populated with @p
2454+
* amd_comgr_populate_name_expression_map.
2455+
*
2456+
* @param[in] data A data object of kind @p
2457+
* AMD_COMGR_DATA_KIND_EXECUTABLE or @p AMD_COMGR_DATA_KIND_BC used to
2458+
* identify which map of name expressions to retrieve from.
2459+
*
2460+
* @param[in, out] size For out, the size of @p symbol_name. For in,
2461+
* if @symbol_name is NULL, set to the size of the Nth option string including
2462+
* the terminating null character.
2463+
*
2464+
* @param[in] name_expression A character array of a name expression. This name
2465+
* is used as the key to the name expression map in order to locate the desired
2466+
* @symbol_name.
2467+
*
2468+
* @param[out] symbol_name If not NULL, then the first @p size characters of
2469+
* the symbol name string mapped from @name_expression are copied into @p
2470+
* symbol_name. If NULL, no symbol name string is copied, and only @p size is
2471+
* updated (useful in order to find the size of the buffer required to copy the
2472+
* symbol_name string).
2473+
*
2474+
* @retval ::AMD_COMGR_STATUS_SUCCESS The function executed successfully.
2475+
*
2476+
* @retval ::AMD_COMGR_STATUS_ERROR @p data object is not valid (NULL or not of
2477+
* type bitcode or code object)
2478+
*
2479+
* @retval ::AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT @p name_expression is not
2480+
* present in the name expression map.
2481+
*
2482+
*/
2483+
amd_comgr_status_t AMD_COMGR_API
2484+
amd_comgr_map_name_expression_to_symbol_name(
2485+
amd_comgr_data_t data,
2486+
size_t *size,
2487+
char *name_expression,
2488+
char *symbol_name) AMD_COMGR_VERSION_2_6;
2489+
23892490
/**
23902491
* @brief A data structure for Code object information.
23912492
*/

0 commit comments

Comments
 (0)