Skip to content

Commit a84ffd6

Browse files
committed
[Comgr] Add new DataAction flag for device library linking
Previously, some Comgr actions implicitly linked the device libraries, while others did not. With this new DataAction option, users can explicitly enforce or disable device library linking via: amd_comgr_action_info_set_device_lib_linking( DataAction ActionInfo, bool ShouldLinkDeviceLibs) This change impacts the following actions: AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC AMD_COMGR_ACTION_COMPILE_SOURCE_TO_EXECUTABLE AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE AMD_COMGR_ACTION_CODEGEN_BC_TO_ASSEMBLY AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE If device library linking is required for one of the above actions, it should be explicitly enforced via the new API. Currently the default behavior of each action is preserved, but in the future the default will be changed to NOT link, and linking will only occur if amd_comgr_action_info_set_device_lib_linking() is used. Note: In Comgr 4.0, we plan to remove AMD_COMGR_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC In favor of amd_comgr_action_info_set_device_lib_linking(ActionInfo, true); AMD_COMGR_COMPILE_SOURCE_TO_BC Change-Id: I46411d1bf01354ac5ad434813df84569956a34d5
1 parent 860819e commit a84ffd6

File tree

9 files changed

+112
-9
lines changed

9 files changed

+112
-9
lines changed

amd/comgr/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#COMGR_VERSION_MAJOR
22
2
33
#COMGR_VERSION_MINOR
4-
8
4+
9

amd/comgr/docs/ReleaseNotes.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ device library from v4 to v5
2525
(libamd\_comgr.dll -> libamd\_comgr\_X.dll, where X is the major version)
2626
- oclc\_daz\_opt\_on.bc and oclc\_daz\_opt\_off.bc, and the corresponding
2727
variable \_\_oclc\_daz\_opt are no longer necessary.
28+
- Updated default device library linking behavior for several actions.
29+
Previously, linking was done for some actions and not others, and not
30+
controllable by the user. Now, linking is not done by default, but can
31+
optionally be enabled via the
32+
amd\_comgr\_action\_info\_set\_device\_lib\_linking() API. Users relying
33+
on enabled-by-default behavior should update to use the new API to avoid
34+
changes in behavior.
35+
36+
Note: This does not apply to the \*COMPILE\_SOURCE\_WITH\_DEVICE\_LIBS\_TO\_BC
37+
action. This action is not affected by the
38+
amd\_comgr\_action\_info\_set\_device\_lib\_linking() API. The new API will
39+
allow us to deprecate and remove this action in favor of the
40+
\*COMPILE\_SOURCE\_TO\_BC action.
2841

2942
New Features
3043
------------
@@ -95,10 +108,14 @@ New APIs
95108
- For a given executable and ELF virtual address, return a code object
96109
offset. This API will benifet the ROCm debugger and profilier
97110
- amd\_comgr\_action\_info\_set\_bundle\_entry\_ids() (v2.8)
98-
- amd\_comgr\_action\_info\_get\_bundle\_entry\_id_count() (v2.8)
111+
- amd\_comgr\_action\_info\_get\_bundle\_entry\_id\_count() (v2.8)
99112
- amd\_comgr\_action\_info\_get\_bundle\_entry\_id() (v2.8)
100113
- A user can provide a set of bundle entry IDs, which are processed when
101114
calling the AMD\_COMGR\_UNBUNDLE action
115+
- amd\_comgr\_action\_info\_set\_device\_lib\_linking() (v2.9)
116+
- By setting this ActionInfo property, a user can explicitly dictate if
117+
device libraries should be linked for a given action. (Previouly, the
118+
action type implicitly determined device library linking).
102119

103120

104121
Deprecated APIs

amd/comgr/include/amd_comgr.h.in

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,17 @@ extern "C" {
223223
#define AMD_COMGR_VERSION_2_7
224224

225225
/**
226-
* The function was introduced or changed in version 2.7 of the interface
227-
* and has the symbol version string of ``"@amd_comgr_NAME@_2.7"``.
226+
* The function was introduced or changed in version 2.8 of the interface
227+
* and has the symbol version string of ``"@amd_comgr_NAME@_2.8"``.
228228
*/
229229
#define AMD_COMGR_VERSION_2_8
230230

231+
/**
232+
* The function was introduced or changed in version 2.9 of the interface
233+
* and has the symbol version string of ``"@amd_comgr_NAME@_2.9"``.
234+
*/
235+
#define AMD_COMGR_VERSION_2_9
236+
231237
/** @} */
232238

233239
/**
@@ -1496,6 +1502,29 @@ amd_comgr_action_info_get_bundle_entry_id(
14961502
size_t *size,
14971503
char *bundle_entry_id) AMD_COMGR_VERSION_2_8;
14981504

1505+
/**
1506+
* @brief Set the device library linking behavior of an action info object.
1507+
*
1508+
* Device library linking can be either enforced or omitted for compilation
1509+
* actions.
1510+
*
1511+
* @param[in] action_info A handle to the action info object to be
1512+
* updated.
1513+
*
1514+
* @param[in] should_link_device_libs A boolean that directs the choice to
1515+
* link the device libraries.
1516+
*
1517+
* @retval ::AMD_COMGR_STATUS_SUCCESS The function has
1518+
* been executed successfully.
1519+
*
1520+
* @retval ::AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT @p
1521+
* action_info is an invalid action info object.
1522+
*/
1523+
amd_comgr_status_t AMD_COMGR_API
1524+
amd_comgr_action_info_set_device_lib_linking(
1525+
amd_comgr_action_info_t action_info,
1526+
bool should_link_device_libs) AMD_COMGR_VERSION_2_9;
1527+
14991528
/**
15001529
* @brief Set the working directory of an action info object.
15011530
*

amd/comgr/src/amdcomgr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ amd_comgr_symbol_get_info
4949
amd_comgr_action_info_set_bundle_entry_ids
5050
amd_comgr_action_info_get_bundle_entry_id_count
5151
amd_comgr_action_info_get_bundle_entry_id
52+
amd_comgr_action_info_set_device_lib_linking

amd/comgr/src/comgr-compiler.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ amd_comgr_status_t AMDGPUCompiler::compileToBitcode(bool WithDeviceLibs) {
11491149
Args.push_back("-fshort-wchar");
11501150
#endif
11511151

1152-
if (WithDeviceLibs) {
1152+
// TODO: Deprecate WithDeviceLibs in favor of ActionInfo->ShouldLinkDeviceLibs
1153+
if (WithDeviceLibs || ActionInfo->ShouldLinkDeviceLibs) {
11531154
if (auto Status = addDeviceLibraries()) {
11541155
return Status;
11551156
}
@@ -1188,8 +1189,12 @@ amd_comgr_status_t AMDGPUCompiler::compileToExecutable() {
11881189
Args.push_back("-fshort-wchar");
11891190
#endif
11901191

1191-
if (auto Status = addDeviceLibraries()) {
1192-
return Status;
1192+
// TODO: Remove "true" conditional once dependent APIs have included new
1193+
// new *_set_device_lib_linking API
1194+
if (ActionInfo->ShouldLinkDeviceLibs || true) {
1195+
if (auto Status = addDeviceLibraries()) {
1196+
return Status;
1197+
}
11931198
}
11941199

11951200
return processFiles(AMD_COMGR_DATA_KIND_EXECUTABLE, ".so");
@@ -1227,8 +1232,12 @@ amd_comgr_status_t AMDGPUCompiler::compileToRelocatable() {
12271232
Args.push_back("-fshort-wchar");
12281233
#endif
12291234

1230-
if (auto Status = addDeviceLibraries()) {
1231-
return Status;
1235+
// TODO: Remove "true" conditional once dependent APIs have included new
1236+
// new *_set_device_lib_linking API
1237+
if (ActionInfo->ShouldLinkDeviceLibs || true) {
1238+
if (auto Status = addDeviceLibraries()) {
1239+
return Status;
1240+
}
12321241
}
12331242

12341243
return processFiles(AMD_COMGR_DATA_KIND_RELOCATABLE, ".o");
@@ -1729,6 +1738,12 @@ amd_comgr_status_t AMDGPUCompiler::codeGenBitcodeToRelocatable() {
17291738
}
17301739
}
17311740

1741+
if (ActionInfo->ShouldLinkDeviceLibs) {
1742+
if (auto Status = addDeviceLibraries()) {
1743+
return Status;
1744+
}
1745+
}
1746+
17321747
Args.push_back("-c");
17331748

17341749
Args.push_back("-mllvm");
@@ -1748,6 +1763,12 @@ amd_comgr_status_t AMDGPUCompiler::codeGenBitcodeToAssembly() {
17481763
}
17491764
}
17501765

1766+
if (ActionInfo->ShouldLinkDeviceLibs) {
1767+
if (auto Status = addDeviceLibraries()) {
1768+
return Status;
1769+
}
1770+
}
1771+
17511772
Args.push_back("-S");
17521773

17531774
return processFiles(AMD_COMGR_DATA_KIND_SOURCE, ".s");
@@ -1768,6 +1789,12 @@ amd_comgr_status_t AMDGPUCompiler::assembleToRelocatable() {
17681789
return Status;
17691790
}
17701791

1792+
if (ActionInfo->ShouldLinkDeviceLibs) {
1793+
if (auto Status = addDeviceLibraries()) {
1794+
return Status;
1795+
}
1796+
}
1797+
17711798
Args.push_back("-c");
17721799
Args.push_back("-x");
17731800
Args.push_back("assembler");
@@ -1856,6 +1883,12 @@ amd_comgr_status_t AMDGPUCompiler::linkToExecutable() {
18561883
Args.push_back(Inputs.back().c_str());
18571884
}
18581885

1886+
if (ActionInfo->ShouldLinkDeviceLibs) {
1887+
if (auto Status = addDeviceLibraries()) {
1888+
return Status;
1889+
}
1890+
}
1891+
18591892
amd_comgr_data_t OutputT;
18601893
if (auto Status =
18611894
amd_comgr_create_data(AMD_COMGR_DATA_KIND_EXECUTABLE, &OutputT)) {

amd/comgr/src/comgr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,22 @@ amd_comgr_status_t AMD_COMGR_API
12711271
return ActionP->setBundleEntryIDs(ArrayRef<const char *>(EntryIDs, Count));
12721272
}
12731273

1274+
amd_comgr_status_t AMD_COMGR_API
1275+
// NOLINTNEXTLINE(readability-identifier-naming)
1276+
amd_comgr_action_info_set_device_lib_linking
1277+
//
1278+
(amd_comgr_action_info_t ActionInfo, bool ShouldLinkDeviceLibs) {
1279+
DataAction *ActionP = DataAction::convert(ActionInfo);
1280+
1281+
if (!ActionP) {
1282+
return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
1283+
}
1284+
1285+
ActionP->ShouldLinkDeviceLibs = ShouldLinkDeviceLibs;
1286+
1287+
return AMD_COMGR_STATUS_SUCCESS;
1288+
}
1289+
12741290
amd_comgr_status_t AMD_COMGR_API
12751291
// NOLINTNEXTLINE(readability-identifier-naming)
12761292
amd_comgr_action_info_set_working_directory_path

amd/comgr/src/comgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct DataAction {
237237
char *Path;
238238
amd_comgr_language_t Language;
239239
bool Logging;
240+
bool ShouldLinkDeviceLibs = false;
240241

241242
std::vector<std::string> BundleEntryIDs;
242243

amd/comgr/src/exportmap.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ global: amd_comgr_action_info_set_bundle_entry_ids;
8989
amd_comgr_action_info_get_bundle_entry_id_count;
9090
amd_comgr_action_info_get_bundle_entry_id;
9191
} @amd_comgr_NAME@_2.7;
92+
@amd_comgr_NAME@_2.9 {
93+
global: amd_comgr_action_info_set_device_lib_linking;
94+
} @amd_comgr_NAME@_2.8;

amd/comgr/test/compile_minimal_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ int main(int argc, char *argv[]) {
137137
Status = amd_comgr_create_data_set(&DataSetReloc);
138138
checkError(Status, "amd_comgr_create_data_set");
139139

140+
Status = amd_comgr_action_info_set_device_lib_linking(DataAction, true);
141+
checkError(Status, "amd_comgr_action_info_set_device_lib_linking");
142+
140143
Status = amd_comgr_do_action(AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE,
141144
DataAction, DataSetLinked, DataSetReloc);
142145
checkError(Status, "amd_comgr_do_action");

0 commit comments

Comments
 (0)