SWDEV-470698 - fix formatting, add format check workflow (#657)

This commit is contained in:
Danylo Lytovchenko
2025-08-20 16:28:06 +02:00
committed by GitHub
parent 5840940caa
commit f7338717ae
1574 changed files with 162972 additions and 199346 deletions
+61 -64
View File
@@ -103,7 +103,8 @@ static bool getTargetIDValue(std::string& input, std::string& processor, char& s
}
bool isCodeObjectCompatibleWithDevice(std::string co_triple_target_id,
std::string agent_triple_target_id, unsigned& genericVersion) {
std::string agent_triple_target_id,
unsigned& genericVersion) {
// Primitive Check
if (co_triple_target_id == agent_triple_target_id) return true;
@@ -137,8 +138,7 @@ bool isCodeObjectCompatibleWithDevice(std::string co_triple_target_id,
// Check for compatibility
if (genericVersion >= EF_AMDGPU_GENERIC_VERSION_MIN) {
// co_processor is generic target
if (!IsCompatibleWithGenericTarget(co_processor, agent_isa_processor))
return false;
if (!IsCompatibleWithGenericTarget(co_processor, agent_isa_processor)) return false;
} else if (agent_isa_processor != co_processor) {
return false;
}
@@ -455,29 +455,27 @@ bool compileToBitCode(const amd_comgr_data_set_t compileInputs, const std::strin
}
bool CheckIfBundled(std::vector<char>& llvm_bitcode) {
std::string magic(llvm_bitcode.begin(),
llvm_bitcode.begin() + bundle_magic_string_size);
std::string magic(llvm_bitcode.begin(), llvm_bitcode.begin() + bundle_magic_string_size);
if (magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) == 0) {
return true;
}
// File is not bundled
return false;
}
// Unbundle Bitcode using COMGR action
// Supports only 1 Bundle Entry ID for now
bool UnbundleUsingComgr(std::vector<char>& source, const std::string& isa,
std::vector<std::string>& linkOptions, std::string& buildLog,
std::vector<char>& unbundled_bitcode, const char *bundleEntryIDs[],
std::vector<char>& unbundled_bitcode, const char* bundleEntryIDs[],
size_t bundleEntryIDsCount) {
amd_comgr_data_set_t linkinput;
if (amd::Comgr::create_data_set(&linkinput) != AMD_COMGR_STATUS_SUCCESS) {
return false;
return false;
}
std::string name = "UnbundleCode.bc";
if (!helpers::addCodeObjData(linkinput, source, name, AMD_COMGR_DATA_KIND_BC_BUNDLE)) {
return false;
return false;
}
amd_comgr_action_info_t action;
@@ -490,7 +488,8 @@ bool UnbundleUsingComgr(std::vector<char>& source, const std::string& isa,
return false;
}
if(amd::Comgr::action_info_set_bundle_entry_ids(action, bundleEntryIDs, bundleEntryIDsCount) != AMD_COMGR_STATUS_SUCCESS) {
if (amd::Comgr::action_info_set_bundle_entry_ids(action, bundleEntryIDs, bundleEntryIDsCount) !=
AMD_COMGR_STATUS_SUCCESS) {
amd::Comgr::destroy_action_info(action);
return false;
}
@@ -501,15 +500,14 @@ bool UnbundleUsingComgr(std::vector<char>& source, const std::string& isa,
return false;
}
if (auto res =
amd::Comgr::do_action(AMD_COMGR_ACTION_UNBUNDLE, action, linkinput, output);
if (auto res = amd::Comgr::do_action(AMD_COMGR_ACTION_UNBUNDLE, action, linkinput, output);
res != AMD_COMGR_STATUS_SUCCESS) {
amd::Comgr::destroy_action_info(action);
amd::Comgr::destroy_data_set(output);
return false;
}
if (!extractBuildLog(output, buildLog)) {
if (!extractBuildLog(output, buildLog)) {
amd::Comgr::destroy_action_info(action);
amd::Comgr::destroy_data_set(output);
return false;
@@ -533,8 +531,7 @@ bool linkLLVMBitcode(const amd_comgr_data_set_t linkInputs, const std::string& i
const amd_comgr_language_t lang = AMD_COMGR_LANGUAGE_HIP;
amd_comgr_action_info_t action;
if (auto res = createAction(action, linkOptions, isa, lang);
res != AMD_COMGR_STATUS_SUCCESS) {
if (auto res = createAction(action, linkOptions, isa, lang); res != AMD_COMGR_STATUS_SUCCESS) {
return false;
}
@@ -569,8 +566,8 @@ bool linkLLVMBitcode(const amd_comgr_data_set_t linkInputs, const std::string& i
}
bool convertSPIRVToLLVMBC(const amd_comgr_data_set_t linkInputs, const std::string& isa,
std::vector<std::string>& linkOptions, std::string& buildLog,
std::vector<char>& LinkedLLVMBitcode) {
std::vector<std::string>& linkOptions, std::string& buildLog,
std::vector<char>& LinkedLLVMBitcode) {
amd_comgr_action_info_t action;
if (auto res = createAction(action, linkOptions, isa, AMD_COMGR_LANGUAGE_NONE);
@@ -832,39 +829,39 @@ bool fillMangledNames(std::vector<char>& dataVec, std::map<std::string, std::str
const std::map<std::string, std::string>& GenericTargetMapping() {
// The map is subject to change per removing policy
static const std::map<std::string, std::string> genericTargetMap{
// "gfx9-generic"
{"gfx900", "gfx9-generic"},
{"gfx902", "gfx9-generic"},
{"gfx904", "gfx9-generic"},
{"gfx906", "gfx9-generic"},
{"gfx909", "gfx9-generic"},
{"gfx90c", "gfx9-generic"},
// "gfx9-4-generic"
{"gfx942", "gfx9-4-generic"},
{"gfx950", "gfx9-4-generic"},
// "gfx10-1-generic"
{"gfx1010", "gfx10-1-generic"},
{"gfx1011", "gfx10-1-generic"},
{"gfx1012", "gfx10-1-generic"},
{"gfx1013", "gfx10-1-generic"},
// "gfx10-3-generic"
{"gfx1030", "gfx10-3-generic"},
{"gfx1031", "gfx10-3-generic"},
{"gfx1032", "gfx10-3-generic"},
{"gfx1033", "gfx10-3-generic"},
{"gfx1034", "gfx10-3-generic"},
{"gfx1035", "gfx10-3-generic"},
{"gfx1036", "gfx10-3-generic"},
// "gfx11-generic"
{"gfx1100", "gfx11-generic"},
{"gfx1101", "gfx11-generic"},
{"gfx1102", "gfx11-generic"},
{"gfx1103", "gfx11-generic"},
{"gfx1150", "gfx11-generic"},
{"gfx1151", "gfx11-generic"},
// "gfx12-generic"
{"gfx1200", "gfx12-generic"},
{"gfx1201", "gfx12-generic"},
// "gfx9-generic"
{"gfx900", "gfx9-generic"},
{"gfx902", "gfx9-generic"},
{"gfx904", "gfx9-generic"},
{"gfx906", "gfx9-generic"},
{"gfx909", "gfx9-generic"},
{"gfx90c", "gfx9-generic"},
// "gfx9-4-generic"
{"gfx942", "gfx9-4-generic"},
{"gfx950", "gfx9-4-generic"},
// "gfx10-1-generic"
{"gfx1010", "gfx10-1-generic"},
{"gfx1011", "gfx10-1-generic"},
{"gfx1012", "gfx10-1-generic"},
{"gfx1013", "gfx10-1-generic"},
// "gfx10-3-generic"
{"gfx1030", "gfx10-3-generic"},
{"gfx1031", "gfx10-3-generic"},
{"gfx1032", "gfx10-3-generic"},
{"gfx1033", "gfx10-3-generic"},
{"gfx1034", "gfx10-3-generic"},
{"gfx1035", "gfx10-3-generic"},
{"gfx1036", "gfx10-3-generic"},
// "gfx11-generic"
{"gfx1100", "gfx11-generic"},
{"gfx1101", "gfx11-generic"},
{"gfx1102", "gfx11-generic"},
{"gfx1103", "gfx11-generic"},
{"gfx1150", "gfx11-generic"},
{"gfx1151", "gfx11-generic"},
// "gfx12-generic"
{"gfx1200", "gfx12-generic"},
{"gfx1201", "gfx12-generic"},
};
return genericTargetMap;
}
@@ -900,7 +897,6 @@ RTCProgram::RTCProgram(std::string name) : name_(name) {
}
bool RTCProgram::findIsa() {
#ifdef BUILD_SHARED_LIBS
const char* libName;
#ifdef _WIN32
@@ -1009,7 +1005,7 @@ bool LinkProgram::isLinkerValid(LinkProgram* link_program) {
}
bool LinkProgram::AddLinkerOptions(unsigned int num_options, hipJitOption* options_ptr,
void** options_vals_ptr) {
void** options_vals_ptr) {
for (size_t opt_idx = 0; opt_idx < num_options; ++opt_idx) {
if (options_vals_ptr[opt_idx] == nullptr) {
LogError("Options value can not be nullptr");
@@ -1032,7 +1028,6 @@ bool LinkProgram::AddLinkerOptions(unsigned int num_options, hipJitOption* optio
}
amd_comgr_data_kind_t LinkProgram::GetCOMGRDataKind(hipJitInputType input_type) {
amd_comgr_data_kind_t data_kind = AMD_COMGR_DATA_KIND_UNDEF;
@@ -1061,7 +1056,7 @@ amd_comgr_data_kind_t LinkProgram::GetCOMGRDataKind(hipJitInputType input_type)
bool LinkProgram::AddLinkerDataImpl(std::vector<char>& link_data, hipJitInputType input_type,
std::string& link_file_name) {
std::string& link_file_name) {
std::vector<char> llvm_code_object;
is_bundled_ = helpers::CheckIfBundled(link_data);
@@ -1079,20 +1074,20 @@ bool LinkProgram::AddLinkerDataImpl(std::vector<char>& link_data, hipJitInputTyp
llvm_code_object.assign(link_data.begin() + co_offset, link_data.begin() + co_offset + co_size);
} else if (is_bundled_ && input_type == hipJitInputSpirv) {
const char* bundleEntryIDs[] = { helpers::SPIRV_BUNDLE_ENTRY_ID };
const char* bundleEntryIDs[] = {helpers::SPIRV_BUNDLE_ENTRY_ID};
size_t bundleEntryIDsCount = sizeof(bundleEntryIDs) / sizeof(bundleEntryIDs[0]);
if(!helpers::UnbundleUsingComgr(link_data, isa_, link_options_, build_log_, llvm_code_object,
bundleEntryIDs, bundleEntryIDsCount)) {
if (!helpers::UnbundleUsingComgr(link_data, isa_, link_options_, build_log_, llvm_code_object,
bundleEntryIDs, bundleEntryIDsCount)) {
LogError("Error in hip Linker: Unable to unbundle SPIRV Bitcode");
return false;
}
} else {
llvm_code_object.assign(link_data.begin(), link_data.end());
llvm_code_object.assign(link_data.begin(), link_data.end());
}
if ((data_kind_ = GetCOMGRDataKind(input_type)) == AMD_COMGR_DATA_KIND_UNDEF) {
LogError("Cannot find the correct COMGR data kind");
return false;
LogError("Cannot find the correct COMGR data kind");
return false;
}
if (!helpers::addCodeObjData(link_input_, llvm_code_object, link_file_name, data_kind_)) {
@@ -1126,7 +1121,7 @@ bool LinkProgram::AddLinkerFile(std::string file_path, hipJitInputType input_typ
}
bool LinkProgram::AddLinkerData(void* image_ptr, size_t image_size, std::string link_file_name,
hipJitInputType input_type) {
hipJitInputType input_type) {
char* image_char_buf = reinterpret_cast<char*>(image_ptr);
std::vector<char> llvm_code_object(image_char_buf, image_char_buf + image_size);
@@ -1146,13 +1141,15 @@ bool LinkProgram::LinkComplete(void** bin_out, size_t* size_out) {
if (data_kind_ == AMD_COMGR_DATA_KIND_SPIRV) {
// Convert SPIRV Unbundled code object to LLVM Bitcode
std::vector<char> llvmbc_from_spirv;
if (!helpers::convertSPIRVToLLVMBC(link_input_, isa_, link_options_, build_log_, llvmbc_from_spirv)) {
if (!helpers::convertSPIRVToLLVMBC(link_input_, isa_, link_options_, build_log_,
llvmbc_from_spirv)) {
LogError("Error in hip Linker: unable to convert SPIRV to BC");
return false;
}
std::string linkedFileName = "LLVMBitcodeFromSPIRV.bc";
if (!helpers::addCodeObjData(link_input, llvmbc_from_spirv, linkedFileName, AMD_COMGR_DATA_KIND_BC)) {
if (!helpers::addCodeObjData(link_input, llvmbc_from_spirv, linkedFileName,
AMD_COMGR_DATA_KIND_BC)) {
LogError("Error in hip Linker: unable to add linked LLVM bitcode");
return false;
}
@@ -1182,7 +1179,7 @@ bool LinkProgram::LinkComplete(void** bin_out, size_t* size_out) {
}()
.c_str());
if (!helpers::createExecutable(exec_input_, isa_, exe_options, build_log_, executable_,
data_kind_ == AMD_COMGR_DATA_KIND_SPIRV)) {
data_kind_ == AMD_COMGR_DATA_KIND_SPIRV)) {
LogPrintfInfo("Error in hip linker: unable to create exectuable: %s", build_log_.c_str());
return false;
}