Skip to content

Commit 05defd6

Browse files
committed
[Comgr][v3.0] Remove deprecated HIP compilation workaround
- AMD_COMGR_COMPILE_SOURCE_TO_FATBIN Change-Id: I257207c1df624b2e068538a3f40a730c98138537
1 parent 11e989c commit 05defd6

File tree

9 files changed

+66
-435
lines changed

9 files changed

+66
-435
lines changed

amd/comgr/docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ Deprecated Comgr Actions and Data Types
160160

161161
Removed Comgr Actions and Data Types
162162
------------------------------------
163+
- (Action) AMD\_COMGR\_ACTION\_COMPILE\_SOURCE\_TO\_FATBIN
164+
- This workaround has been removed in favor of
165+
\*\_COMPILE\_SOURCE\_(WITH\_DEVICE\_LIBS\_)TO\_BC
163166

164167
Comgr Testing, Debugging, and Logging Updates
165168
---------------------------------------------

amd/comgr/include/amd_comgr.h.in

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,28 +1760,6 @@ typedef enum amd_comgr_action_kind_s {
17601760
* if isa name is not set in @p info
17611761
*/
17621762
AMD_COMGR_ACTION_DISASSEMBLE_BYTES_TO_SOURCE = 0xD,
1763-
/**
1764-
* Compile each source data object in @p input in order. For each
1765-
* successful compilation add a fat binary to @p result. Resolve
1766-
* any include source names using the names of include data objects
1767-
* in @p input. Resolve any include relative path names using the
1768-
* working directory path in @p info. Produce fat binary for isa name in @p
1769-
* info. Compile the source for the language in @p info.
1770-
*
1771-
* Return @p AMD_COMGR_STATUS_ERROR if any compilation
1772-
* fails.
1773-
*
1774-
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
1775-
* if isa name or language is not set in @p info.
1776-
*
1777-
* @deprecated since 2.5
1778-
* @see in-process compilation via AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC, etc.
1779-
* insteaad
1780-
*/
1781-
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN
1782-
AMD_COMGR_DEPRECATED("Will be removed in Comgr v3.0 (Rocm v6.0). Use "
1783-
"AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC, etc. "
1784-
"instead") = 0xE,
17851763
/**
17861764
* Compile each source data object in @p input in order. For each
17871765
* successful compilation add a bc data object to @p result. Resolve
@@ -1798,7 +1776,7 @@ typedef enum amd_comgr_action_kind_s {
17981776
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
17991777
* if isa name or language is not set in @p info.
18001778
*/
1801-
AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC = 0xF,
1779+
AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC = 0xE,
18021780
/**
18031781
* Compile a single source data object in @p input in order. For each
18041782
* successful compilation add a relocatable data object to @p result.
@@ -1815,7 +1793,7 @@ typedef enum amd_comgr_action_kind_s {
18151793
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
18161794
* if isa name or language is not set in @p info.
18171795
*/
1818-
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE = 0x10,
1796+
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE = 0xF,
18191797
/**
18201798
* Compile each source data object in @p input and create a single executabele
18211799
* in @p result. Resolve any include source names using the names of include
@@ -1831,7 +1809,7 @@ typedef enum amd_comgr_action_kind_s {
18311809
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
18321810
* if isa name or language is not set in @p info.
18331811
*/
1834-
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_EXECUTABLE = 0x11,
1812+
AMD_COMGR_ACTION_COMPILE_SOURCE_TO_EXECUTABLE = 0x10,
18351813

18361814
/**
18371815
* Unbundle each source data object in @p input. These objects can be
@@ -1845,7 +1823,7 @@ typedef enum amd_comgr_action_kind_s {
18451823
* Return @p AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT
18461824
* if isa name or language is not set in @p info.
18471825
*/
1848-
AMD_COMGR_ACTION_UNBUNDLE = 0x12,
1826+
AMD_COMGR_ACTION_UNBUNDLE = 0x11,
18491827

18501828
/**
18511829
* Marker for last valid action kind.

amd/comgr/src/comgr-compiler.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -837,44 +837,6 @@ amd_comgr_status_t AMDGPUCompiler::removeTmpDirs() {
837837
#endif
838838
}
839839

840-
amd_comgr_status_t AMDGPUCompiler::executeOutOfProcessHIPCompilation(
841-
llvm::ArrayRef<const char *> Args) {
842-
std::string Exec = (Twine(env::getHIPPath()) + "/bin/hipcc").str();
843-
std::vector<StringRef> ArgsV;
844-
ArgsV.push_back(Exec);
845-
for (unsigned I = 0, E = Args.size(); I != E; ++I) {
846-
if (strcmp(Args[I], "-hip-path") == 0) {
847-
++I;
848-
if (I == E) {
849-
LogS << "Error: -hip-path option misses argument.\n";
850-
return AMD_COMGR_STATUS_ERROR;
851-
}
852-
Exec = (Twine(Args[I]) + "/bin/hipcc").str();
853-
ArgsV[0] = Exec;
854-
855-
} else {
856-
ArgsV.push_back(Args[I]);
857-
}
858-
}
859-
860-
ArgsV.push_back("--genco");
861-
862-
if (env::shouldEmitVerboseLogs()) {
863-
LogS << "\t hipcc Command: ";
864-
for (auto A : ArgsV)
865-
LogS << A << " ";
866-
LogS << "\n";
867-
}
868-
869-
llvm::ArrayRef<std::optional<StringRef>> Redirects;
870-
std::string ErrMsg;
871-
int RC = sys::ExecuteAndWait(Exec, ArgsV,
872-
/*env=*/std::nullopt, Redirects, /*secondsToWait=*/0,
873-
/*memoryLimit=*/0, &ErrMsg);
874-
LogS << ErrMsg;
875-
return RC ? AMD_COMGR_STATUS_ERROR : AMD_COMGR_STATUS_SUCCESS;
876-
}
877-
878840
amd_comgr_status_t AMDGPUCompiler::processFile(const char *InputFilePath,
879841
const char *OutputFilePath) {
880842
SmallVector<const char *, 128> Argv = Args;
@@ -901,11 +863,6 @@ amd_comgr_status_t AMDGPUCompiler::processFile(const char *InputFilePath,
901863
Argv.push_back("-o");
902864
Argv.push_back(OutputFilePath);
903865

904-
// For HIP OOP compilation, we launch a process.
905-
if (CompileOOP && getLanguage() == AMD_COMGR_LANGUAGE_HIP) {
906-
return executeOutOfProcessHIPCompilation(Argv);
907-
}
908-
909866
return executeInProcessDriver(Argv);
910867
}
911868

@@ -1243,23 +1200,6 @@ amd_comgr_status_t AMDGPUCompiler::compileToRelocatable() {
12431200
return processFiles(AMD_COMGR_DATA_KIND_RELOCATABLE, ".o");
12441201
}
12451202

1246-
amd_comgr_status_t AMDGPUCompiler::compileToFatBin() {
1247-
if (auto Status = createTmpDirs()) {
1248-
return Status;
1249-
}
1250-
1251-
if (ActionInfo->Language != AMD_COMGR_LANGUAGE_HIP) {
1252-
return AMD_COMGR_STATUS_ERROR_INVALID_ARGUMENT;
1253-
}
1254-
1255-
// This is a workaround to support HIP OOP Fatbin Compilation
1256-
CompileOOP = true;
1257-
auto Status = processFiles(AMD_COMGR_DATA_KIND_FATBIN, ".fatbin");
1258-
CompileOOP = false;
1259-
1260-
return Status;
1261-
}
1262-
12631203
amd_comgr_status_t AMDGPUCompiler::unbundle() {
12641204
if (auto Status = createTmpDirs()) {
12651205
return Status;

amd/comgr/src/comgr-compiler.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class AMDGPUCompiler {
9494
std::string HIPIncludePath;
9595
std::string ClangIncludePath;
9696
std::string ClangIncludePath2;
97-
/// Perform out-of-process compilation.
98-
bool CompileOOP = false;
9997
/// Precompiled header file paths.
10098
llvm::SmallVector<llvm::SmallString<128>, 2> PrecompiledHeaders;
10199
/// Arguments common to all driver invocations in the current action.
@@ -123,8 +121,6 @@ class AMDGPUCompiler {
123121
bool CompilingSrc);
124122
amd_comgr_status_t addCompilationFlags();
125123
amd_comgr_status_t addDeviceLibraries();
126-
amd_comgr_status_t
127-
executeOutOfProcessHIPCompilation(llvm::ArrayRef<const char *> Args);
128124

129125
amd_comgr_status_t executeInProcessDriver(llvm::ArrayRef<const char *> Args);
130126

@@ -143,7 +139,6 @@ class AMDGPUCompiler {
143139
amd_comgr_status_t assembleToRelocatable();
144140
amd_comgr_status_t linkToRelocatable();
145141
amd_comgr_status_t linkToExecutable();
146-
amd_comgr_status_t compileToFatBin();
147142
amd_comgr_status_t compileToExecutable();
148143

149144
amd_comgr_language_t getLanguage() const { return ActionInfo->Language; }

amd/comgr/src/comgr.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ dispatchCompilerAction(amd_comgr_action_kind_t ActionKind,
179179
return Compiler.linkToRelocatable();
180180
case AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE:
181181
return Compiler.linkToExecutable();
182-
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN:
183-
return Compiler.compileToFatBin();
184182
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE:
185183
return Compiler.compileToRelocatable();
186184
case AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC:
@@ -243,8 +241,6 @@ StringRef getActionKindName(amd_comgr_action_kind_t ActionKind) {
243241
return "AMD_COMGR_ACTION_DISASSEMBLE_BYTES_TO_SOURCE";
244242
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE:
245243
return "AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE";
246-
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN:
247-
return "AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN";
248244
case AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC:
249245
return "AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC";
250246
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_EXECUTABLE:
@@ -1381,7 +1377,6 @@ amd_comgr_status_t AMD_COMGR_API
13811377
case AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_RELOCATABLE:
13821378
case AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE:
13831379
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_RELOCATABLE:
1384-
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN:
13851380
case AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC:
13861381
case AMD_COMGR_ACTION_COMPILE_SOURCE_TO_EXECUTABLE:
13871382
ActionStatus = dispatchCompilerAction(ActionKind, ActionInfoP, InputSetP,

amd/comgr/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ if (DEFINED HIP_COMPILER AND "${HIP_COMPILER}" STREQUAL "clang")
242242
add_test_archive(cube_archive cube source/cube.bc source/cube.a)
243243

244244
add_comgr_test(compile_hip_test c)
245-
add_comgr_test(compile_hip_test_in_process c)
246245
add_comgr_test(unbundle_hip_test c)
247246
add_comgr_test(compile_hip_to_relocatable c)
248247
add_comgr_test(mangled_names_hip_test c)

amd/comgr/test/compile_hip_test.c

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,65 +39,83 @@
3939
#include <stdlib.h>
4040
#include <string.h>
4141

42-
int main(int argc, char *argv[]) {
43-
char *BufSource1;
44-
size_t SizeSource1;
45-
amd_comgr_data_t DataSource1;
46-
amd_comgr_data_set_t DataSetIn, DataSetFatBin;
47-
amd_comgr_action_info_t DataAction;
42+
int main(int Argc, char *Argv[]) {
43+
char *BufSource;
44+
size_t SizeSource;
45+
amd_comgr_data_t DataSrc;
46+
amd_comgr_data_set_t DataSetSrc, DataSetBc, DataSetLinkedBc,
47+
DataSetAsm, DataSetReloc, DataSetExec;
48+
amd_comgr_action_info_t ActionInfo;
4849
amd_comgr_status_t Status;
49-
size_t Count;
50-
const char *Options[] = {"--amdgpu-target=gfx900"};
51-
size_t OptionsCount = sizeof(Options) / sizeof(Options[0]);
5250

53-
SizeSource1 = setBuf(TEST_OBJ_DIR "/source1.hip", &BufSource1);
51+
SizeSource = setBuf(TEST_OBJ_DIR "/source2.hip", &BufSource);
5452

55-
Status = amd_comgr_create_data_set(&DataSetIn);
56-
checkError(Status, "amd_comgr_create_data_set");
57-
58-
Status = amd_comgr_create_data(AMD_COMGR_DATA_KIND_SOURCE, &DataSource1);
53+
Status = amd_comgr_create_data(AMD_COMGR_DATA_KIND_SOURCE, &DataSrc);
5954
checkError(Status, "amd_comgr_create_data");
60-
Status = amd_comgr_set_data(DataSource1, SizeSource1, BufSource1);
55+
Status = amd_comgr_set_data(DataSrc, SizeSource, BufSource);
6156
checkError(Status, "amd_comgr_set_data");
62-
Status = amd_comgr_set_data_name(DataSource1, "source1.hip");
57+
Status = amd_comgr_set_data_name(DataSrc, "source2.hip");
6358
checkError(Status, "amd_comgr_set_data_name");
64-
Status = amd_comgr_data_set_add(DataSetIn, DataSource1);
59+
Status = amd_comgr_create_data_set(&DataSetSrc);
60+
checkError(Status, "amd_comgr_create_data_set");
61+
Status = amd_comgr_data_set_add(DataSetSrc, DataSrc);
6562
checkError(Status, "amd_comgr_data_set_add");
6663

67-
Status = amd_comgr_create_action_info(&DataAction);
64+
Status = amd_comgr_create_action_info(&ActionInfo);
6865
checkError(Status, "amd_comgr_create_action_info");
6966
Status =
70-
amd_comgr_action_info_set_language(DataAction, AMD_COMGR_LANGUAGE_HIP);
67+
amd_comgr_action_info_set_language(ActionInfo, AMD_COMGR_LANGUAGE_HIP);
7168
checkError(Status, "amd_comgr_action_info_set_language");
72-
Status =
73-
amd_comgr_action_info_set_option_list(DataAction, Options, OptionsCount);
74-
checkError(Status, "amd_comgr_action_info_set_option_list");
69+
Status = amd_comgr_action_info_set_isa_name(ActionInfo,
70+
"amdgcn-amd-amdhsa--gfx906");
71+
checkError(Status, "amd_comgr_action_info_set_isa_name");
7572

76-
Status = amd_comgr_create_data_set(&DataSetFatBin);
73+
Status = amd_comgr_create_data_set(&DataSetBc);
7774
checkError(Status, "amd_comgr_create_data_set");
75+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC,
76+
ActionInfo, DataSetSrc, DataSetBc);
77+
checkError(Status, "amd_comgr_do_action");
7878

79-
Status = amd_comgr_do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN,
80-
DataAction, DataSetIn, DataSetFatBin);
79+
Status = amd_comgr_create_data_set(&DataSetLinkedBc);
80+
checkError(Status, "amd_comgr_create_data_set");
81+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_LINK_BC_TO_BC, ActionInfo,
82+
DataSetBc, DataSetLinkedBc);
8183
checkError(Status, "amd_comgr_do_action");
8284

83-
Status = amd_comgr_action_data_count(DataSetFatBin,
84-
AMD_COMGR_DATA_KIND_FATBIN, &Count);
85-
checkError(Status, "amd_comgr_action_data_count");
85+
Status = amd_comgr_create_data_set(&DataSetAsm);
86+
checkError(Status, "amd_comgr_create_data_set");
87+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_CODEGEN_BC_TO_ASSEMBLY,
88+
ActionInfo, DataSetLinkedBc, DataSetAsm);
89+
checkError(Status, "amd_comgr_do_action");
8690

87-
if (Count != 1) {
88-
printf("AMD_COMGR_ACTION_COMPILE_SOURCE_TO_FATBIN Failed: "
89-
"produced %zu fab binaries (expected 1)\n",
90-
Count);
91-
exit(1);
92-
}
91+
Status = amd_comgr_create_data_set(&DataSetReloc);
92+
checkError(Status, "amd_comgr_create_data_set");
93+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE,
94+
ActionInfo, DataSetLinkedBc, DataSetReloc);
95+
checkError(Status, "amd_comgr_do_action");
9396

94-
Status = amd_comgr_release_data(DataSource1);
95-
checkError(Status, "amd_comgr_release_data");
96-
Status = amd_comgr_destroy_data_set(DataSetIn);
97+
Status = amd_comgr_create_data_set(&DataSetExec);
98+
checkError(Status, "amd_comgr_create_data_set");
99+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE,
100+
ActionInfo, DataSetReloc, DataSetExec);
101+
checkError(Status, "amd_comgr_do_action");
102+
103+
Status = amd_comgr_destroy_action_info(ActionInfo);
104+
checkError(Status, "amd_comgr_destroy_action_info");
105+
Status = amd_comgr_destroy_data_set(DataSetSrc);
97106
checkError(Status, "amd_comgr_destroy_data_set");
98-
Status = amd_comgr_destroy_data_set(DataSetFatBin);
107+
Status = amd_comgr_destroy_data_set(DataSetBc);
99108
checkError(Status, "amd_comgr_destroy_data_set");
100-
Status = amd_comgr_destroy_action_info(DataAction);
101-
checkError(Status, "amd_comgr_destroy_action_info");
102-
free(BufSource1);
109+
Status = amd_comgr_destroy_data_set(DataSetLinkedBc);
110+
checkError(Status, "amd_comgr_destroy_data_set");
111+
Status = amd_comgr_destroy_data_set(DataSetAsm);
112+
checkError(Status, "amd_comgr_destroy_data_set");
113+
Status = amd_comgr_destroy_data_set(DataSetReloc);
114+
checkError(Status, "amd_comgr_destroy_data_set");
115+
Status = amd_comgr_destroy_data_set(DataSetExec);
116+
checkError(Status, "amd_comgr_destroy_data_set");
117+
Status = amd_comgr_release_data(DataSrc);
118+
checkError(Status, "amd_comgr_release_data");
119+
120+
free(BufSource);
103121
}

0 commit comments

Comments
 (0)