SWDEV-2 - Fix hiprtcCompileProgram
- hiprtcCompileProgram should create isa with temp name when
program name is not provided along with --save-temps option
Change-Id: I47974e2ac56336c851531622ff7d2a3ffb53455e
[ROCm/clr commit: 958b97b433]
This commit is contained in:
@@ -86,7 +86,12 @@ hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog, const char* src, const cha
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_PROGRAM_CREATION_FAILURE);
|
||||
}
|
||||
|
||||
if (!rtcProgram->addSource(std::string(src), std::string("CompileSource"))) {
|
||||
if (name == nullptr || strlen(name) == 0) {
|
||||
progName = "CompileSourceXXXXXX";
|
||||
hiprtc::helpers::GenerateUniqueFileName(progName);
|
||||
}
|
||||
|
||||
if (!rtcProgram->addSource(std::string(src), progName)) {
|
||||
delete rtcProgram;
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hiprtcComgrHelper.hpp"
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
namespace hiprtc {
|
||||
|
||||
@@ -345,9 +348,26 @@ bool createExecutable(const amd_comgr_data_set_t linkInputs, const std::string&
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenerateUniqueFileName(std::string &name) {
|
||||
#if !defined(_WIN32)
|
||||
char *name_template = const_cast<char*>(name.c_str());
|
||||
int temp_fd = mkstemp(name_template);
|
||||
#else
|
||||
char *name_template = new char[name.length()+1];
|
||||
strcpy_s(name_template, name.length()+1, name.data());
|
||||
int sizeinchars = strnlen(name_template, 20) + 1;
|
||||
_mktemp_s(name_template, sizeinchars);
|
||||
#endif
|
||||
name = name_template;
|
||||
#if !defined(_WIN32)
|
||||
unlink(name_template);
|
||||
close(temp_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool dumpIsaFromBC(const amd_comgr_data_set_t isaInputs, const std::string& isa,
|
||||
std::vector<std::string>& exeOptions, std::string name, std::string& buildLog) {
|
||||
if (name.size() == 0) return false;
|
||||
|
||||
amd_comgr_action_info_t action;
|
||||
|
||||
if (auto res = createAction(action, exeOptions, isa); res != AMD_COMGR_STATUS_SUCCESS) {
|
||||
@@ -376,7 +396,18 @@ bool dumpIsaFromBC(const amd_comgr_data_set_t isaInputs, const std::string& isa,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto isaFileName = name + ".s";
|
||||
if (name.size() == 0) {
|
||||
// Generate a unique name if the program name is not specified by the user
|
||||
name = std::string("hiprtcXXXXXX");
|
||||
GenerateUniqueFileName(name);
|
||||
}
|
||||
std::string isaName = isa;
|
||||
#if defined(_WIN32)
|
||||
// Replace special charaters that are not supported by Windows FS.
|
||||
std::replace(isaName.begin(), isaName.end(), ':', '@');
|
||||
#endif
|
||||
|
||||
auto isaFileName = name + std::string("-hip-") + isaName + ".s";
|
||||
std::ofstream f(isaFileName.c_str(), std::ios::trunc | std::ios::binary);
|
||||
if (f.is_open()) {
|
||||
f.write(isaOutput.data(), isaOutput.size());
|
||||
|
||||
@@ -55,5 +55,6 @@ std::string handleMangledName(std::string loweredName);
|
||||
bool fillMangledNames(std::vector<char>& executable, std::vector<std::string>& mangledNames);
|
||||
bool getDemangledNames(const std::vector<std::string>& mangledNames,
|
||||
std::map<std::string, std::string>& demangledNames);
|
||||
void GenerateUniqueFileName(std::string &name);
|
||||
} // namespace helpers
|
||||
} // namespace hiprtc
|
||||
|
||||
Reference in New Issue
Block a user