Skip to content

Commit 6311ed8

Browse files
committed
SWDEV-371628 Use integrated Comgr action to link ROCm device libs
Previously, we used the following approach and Comgr actions for device lib linking: AMD_COMGR_COMPILE_SOURCE_TO_BC (compile with clang driver) AMD_COMGR_ADD_DEVICE_LIBRARIES (link in device libs with llvm-link API) However, the clang driver can link in device libraries as part of compilation, assuming a --rocm-path is set. In this context, this is accomplished by using the following Comgr action instead: AMD_COMGR_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC (compile and link in device libs with clang driver) Change-Id: Ie0bbee7d9a12672536b6d751056a941128ed58be
1 parent 14bcbcc commit 6311ed8

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

rocclr/device/devprogram.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ amd_comgr_status_t Program::createAction(const amd_comgr_language_t oclver,
342342
bool Program::linkLLVMBitcode(const amd_comgr_data_set_t inputs,
343343
const std::vector<std::string>& options,
344344
amd::option::Options* amdOptions, amd_comgr_data_set_t* output,
345-
char* binaryData[], size_t* binarySize, const bool link_dev_libs) {
345+
char* binaryData[], size_t* binarySize) {
346346

347347
amd_comgr_language_t langver = getCOMGRLanguage(isHIP(), *amdOptions);
348348
if (langver == AMD_COMGR_LANGUAGE_NONE) {
@@ -351,28 +351,13 @@ bool Program::linkLLVMBitcode(const amd_comgr_data_set_t inputs,
351351

352352
// Create the action for linking
353353
amd_comgr_action_info_t action;
354-
amd_comgr_data_set_t dataSetDevLibs;
355354
bool hasAction = false;
356-
bool hasDataSetDevLibs = false;
357355

358356
amd_comgr_status_t status = createAction(langver, options, &action, &hasAction);
359357

360-
if (link_dev_libs) {
361-
if (status == AMD_COMGR_STATUS_SUCCESS) {
362-
status = amd::Comgr::create_data_set(&dataSetDevLibs);
363-
}
364-
365-
if (status == AMD_COMGR_STATUS_SUCCESS) {
366-
hasDataSetDevLibs = true;
367-
status = amd::Comgr::do_action(AMD_COMGR_ACTION_ADD_DEVICE_LIBRARIES, action, inputs,
368-
dataSetDevLibs);
369-
extractBuildLog(dataSetDevLibs);
370-
}
371-
}
372-
373358
if (status == AMD_COMGR_STATUS_SUCCESS) {
374359
status = amd::Comgr::do_action(AMD_COMGR_ACTION_LINK_BC_TO_BC, action,
375-
(link_dev_libs) ? dataSetDevLibs : inputs, *output);
360+
inputs, *output);
376361
extractBuildLog(*output);
377362
}
378363

@@ -389,17 +374,14 @@ bool Program::linkLLVMBitcode(const amd_comgr_data_set_t inputs,
389374
amd::Comgr::destroy_action_info(action);
390375
}
391376

392-
if (hasDataSetDevLibs) {
393-
amd::Comgr::destroy_data_set(dataSetDevLibs);
394-
}
395-
396377
return (status == AMD_COMGR_STATUS_SUCCESS);
397378
}
398379

399380
bool Program::compileToLLVMBitcode(const amd_comgr_data_set_t compileInputs,
400381
const std::vector<std::string>& options,
401382
amd::option::Options* amdOptions,
402-
char* binaryData[], size_t* binarySize) {
383+
char* binaryData[], size_t* binarySize,
384+
const bool link_dev_libs) {
403385

404386
amd_comgr_language_t langver = getCOMGRLanguage(isHIP(), *amdOptions);
405387
if (langver == AMD_COMGR_LANGUAGE_NONE) {
@@ -473,8 +455,14 @@ bool Program::compileToLLVMBitcode(const amd_comgr_data_set_t compileInputs,
473455

474456
// Compiling the source codes with precompiled headers or directly compileInputs
475457
if (status == AMD_COMGR_STATUS_SUCCESS) {
476-
status = amd::Comgr::do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC,
477-
action, input, output);
458+
if (link_dev_libs) {
459+
status = amd::Comgr::do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC,
460+
action, input, output);
461+
}
462+
else {
463+
status = amd::Comgr::do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC,
464+
action, input, output);
465+
}
478466
extractBuildLog(output);
479467
}
480468

@@ -960,9 +948,8 @@ bool Program::linkImplLC(const std::vector<Program*>& inputPrograms,
960948
char* binaryData = nullptr;
961949
size_t binarySize = 0;
962950
std::vector<std::string> linkOptions;
963-
constexpr bool kLinkDevLibs = false;
964951
bool ret = linkLLVMBitcode(inputs, linkOptions, options, &output, &binaryData,
965-
&binarySize, kLinkDevLibs);
952+
&binarySize);
966953

967954
amd::Comgr::destroy_data_set(output);
968955
amd::Comgr::destroy_data_set(inputs);

rocclr/device/devprogram.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,13 @@ class Program : public amd::HeapObject {
460460
bool linkLLVMBitcode(const amd_comgr_data_set_t inputs,
461461
const std::vector<std::string>& options,
462462
amd::option::Options* amdOptions, amd_comgr_data_set_t* output,
463-
char* binaryData[] = nullptr, size_t* binarySize = nullptr,
464-
const bool link_dev_libs = true);
463+
char* binaryData[] = nullptr, size_t* binarySize = nullptr);
465464

466465
//! Create the bitcode of the compiled input dataset
467466
bool compileToLLVMBitcode(const amd_comgr_data_set_t compileInputs,
468467
const std::vector<std::string>& options, amd::option::Options* amdOptions,
469-
char* binaryData[], size_t* binarySize);
468+
char* binaryData[], size_t* binarySize,
469+
const bool link_dev_libs = true);
470470

471471
//! Compile and create the excutable of the input dataset
472472
bool compileAndLinkExecutable(const amd_comgr_data_set_t inputs,

0 commit comments

Comments
 (0)