SWDEV-339995 - Adding hiprtcGetBitcode and hiprtcBitcodeSize changes.
Change-Id: I378f1ac98de3b11fa3f74161abd036702c7b479b
[ROCm/clr commit: 2731d03f03]
Этот коммит содержится в:
коммит произвёл
Maneesh Gupta
родитель
abcbb979db
Коммит
8a049faccb
@@ -267,6 +267,8 @@ hiprtcGetProgramLogSize
|
||||
hiprtcGetCode
|
||||
hiprtcGetCodeSize
|
||||
hiprtcGetErrorString
|
||||
hiprtcGetBitcode
|
||||
hiprtcGetBitcodeSize
|
||||
hiprtcLinkCreate
|
||||
hiprtcLinkAddFile
|
||||
hiprtcLinkAddData
|
||||
|
||||
@@ -473,6 +473,8 @@ local:
|
||||
hip_5.3 {
|
||||
global:
|
||||
hipDeviceSetLimit;
|
||||
hiprtcGetBitcode;
|
||||
hiprtcGetBitcodeSize;
|
||||
local:
|
||||
*;
|
||||
} hip_5.2;
|
||||
} hip_5.2;
|
||||
|
||||
@@ -108,13 +108,18 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char
|
||||
|
||||
auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog);
|
||||
|
||||
bool fgpu_rdc = false;
|
||||
std::vector<std::string> opt;
|
||||
opt.reserve(numOptions);
|
||||
for (int i = 0; i < numOptions; i++) {
|
||||
opt.push_back(std::string(options[i]));
|
||||
if(std::string(options[i]) == std::string("-fgpu-rdc")) {
|
||||
fgpu_rdc = true;
|
||||
} else {
|
||||
opt.push_back(std::string(options[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (!rtcProgram->compile(opt)) {
|
||||
if (!rtcProgram->compile(opt, fgpu_rdc)) {
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_COMPILATION);
|
||||
}
|
||||
|
||||
@@ -227,6 +232,31 @@ hiprtcResult hiprtcVersion(int* major, int* minor) {
|
||||
HIPRTC_RETURN(HIPRTC_SUCCESS);
|
||||
}
|
||||
|
||||
hiprtcResult hiprtcGetBitcode (hiprtcProgram prog, char* bitcode) {
|
||||
if (bitcode == nullptr) {
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT);
|
||||
}
|
||||
|
||||
auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog);
|
||||
if (!rtcProgram->GetBitcode(bitcode)) {
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_PROGRAM);
|
||||
}
|
||||
HIPRTC_RETURN(HIPRTC_SUCCESS);
|
||||
}
|
||||
|
||||
hiprtcResult hiprtcGetBitcodeSize(hiprtcProgram prog, size_t* bitcode_size) {
|
||||
if (bitcode_size == nullptr) {
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT);
|
||||
}
|
||||
|
||||
auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog);
|
||||
if (!rtcProgram->GetBitcodeSize(bitcode_size)) {
|
||||
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_PROGRAM);
|
||||
}
|
||||
|
||||
HIPRTC_RETURN(HIPRTC_SUCCESS);
|
||||
}
|
||||
|
||||
hiprtcResult hiprtcLinkCreate(unsigned int num_options, hiprtcJIT_option* options_ptr,
|
||||
void** options_vals_pptr, hiprtcLinkState* hip_link_state_ptr) {
|
||||
HIPRTC_INIT_API(num_options, options_ptr, options_vals_pptr, hip_link_state_ptr);
|
||||
|
||||
@@ -14,3 +14,5 @@ hiprtcLinkAddFile
|
||||
hiprtcLinkAddData
|
||||
hiprtcLinkComplete
|
||||
hiprtcLinkDestroy
|
||||
hiprtcGetBitcode
|
||||
hiprtcGetBitcodeSize
|
||||
|
||||
@@ -16,6 +16,8 @@ global:
|
||||
hiprtcLinkAddData;
|
||||
hiprtcLinkComplete;
|
||||
hiprtcLinkDestroy;
|
||||
hiprtcGetBitcode;
|
||||
hiprtcGetBitcodeSize;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
@@ -94,7 +94,7 @@ bool RTCProgram::findIsa() {
|
||||
}
|
||||
|
||||
//RTC Compile Program Member Functions
|
||||
RTCCompileProgram::RTCCompileProgram(std::string name_) : RTCProgram(name_) {
|
||||
RTCCompileProgram::RTCCompileProgram(std::string name_) : RTCProgram(name_), fgpu_rdc_(false) {
|
||||
|
||||
if ((amd::Comgr::create_data_set(&compile_input_) != AMD_COMGR_STATUS_SUCCESS) ||
|
||||
(amd::Comgr::create_data_set(&link_input_) != AMD_COMGR_STATUS_SUCCESS)) {
|
||||
@@ -229,7 +229,7 @@ bool RTCCompileProgram::transformOptions() {
|
||||
|
||||
amd::Monitor RTCProgram::lock_("HIPRTC Program", true);
|
||||
|
||||
bool RTCCompileProgram::compile(const std::vector<std::string>& options) {
|
||||
bool RTCCompileProgram::compile(const std::vector<std::string>& options, bool fgpu_rdc) {
|
||||
amd::ScopedLock lock(lock_); // Lock, because LLVM is not multi threaded
|
||||
|
||||
if (!addSource_impl()) {
|
||||
@@ -237,6 +237,8 @@ bool RTCCompileProgram::compile(const std::vector<std::string>& options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fgpu_rdc_ = fgpu_rdc;
|
||||
|
||||
// Append compile options
|
||||
compile_options_.reserve(compile_options_.size() + options.size());
|
||||
compile_options_.insert(compile_options_.end(), options.begin(), options.end());
|
||||
@@ -246,14 +248,17 @@ bool RTCCompileProgram::compile(const std::vector<std::string>& options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<char> LLVMBitcode;
|
||||
if (!compileToBitCode(compile_input_, isa_, compile_options_, build_log_, LLVMBitcode)) {
|
||||
if (!compileToBitCode(compile_input_, isa_, compile_options_, build_log_, LLVMBitcode_)) {
|
||||
LogError("Error in hiprtc: unable to compile source to bitcode");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fgpu_rdc_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string linkFileName = "linked";
|
||||
if (!addCodeObjData(link_input_, LLVMBitcode, linkFileName, AMD_COMGR_DATA_KIND_BC)) {
|
||||
if (!addCodeObjData(link_input_, LLVMBitcode_, linkFileName, AMD_COMGR_DATA_KIND_BC)) {
|
||||
LogError("Error in hiprtc: unable to add linked code object");
|
||||
return false;
|
||||
}
|
||||
@@ -348,6 +353,25 @@ bool RTCCompileProgram::getDemangledName(const char* name_expression, const char
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTCCompileProgram::GetBitcode(char* bitcode) {
|
||||
|
||||
if (!fgpu_rdc_ || LLVMBitcode_.size() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::copy(LLVMBitcode_.begin(), LLVMBitcode_.end(), bitcode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTCCompileProgram::GetBitcodeSize(size_t* bitcode_size) {
|
||||
if (!fgpu_rdc_ || LLVMBitcode_.size() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*bitcode_size = LLVMBitcode_.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
//RTC Link Program Member Functions
|
||||
RTCLinkProgram::RTCLinkProgram(std::string name) : RTCProgram(name) {
|
||||
if (amd::Comgr::create_data_set(&link_input_) != AMD_COMGR_STATUS_SUCCESS) {
|
||||
|
||||
@@ -128,6 +128,9 @@ class RTCCompileProgram : public RTCProgram {
|
||||
amd_comgr_data_set_t compile_input_;
|
||||
amd_comgr_data_set_t link_input_;
|
||||
|
||||
bool fgpu_rdc_;
|
||||
std::vector<char> LLVMBitcode_;
|
||||
|
||||
// Private Member functions
|
||||
bool addSource_impl();
|
||||
bool addBuiltinHeader();
|
||||
@@ -155,10 +158,12 @@ class RTCCompileProgram : public RTCProgram {
|
||||
// Public Member Functions
|
||||
bool addSource(const std::string& source, const std::string& name);
|
||||
bool addHeader(const std::string& source, const std::string& name);
|
||||
bool compile(const std::vector<std::string>& options);
|
||||
bool compile(const std::vector<std::string>& options, bool fgpu_rdc);
|
||||
bool getDemangledName(const char* name_expression, const char** loweredName);
|
||||
bool trackMangledName(std::string& name);
|
||||
|
||||
bool GetBitcode(char* bitcode);
|
||||
bool GetBitcodeSize(size_t* bitcode_size);
|
||||
// Public Getter/Setters
|
||||
const std::vector<char>& getExec() const { return executable_; }
|
||||
size_t getExecSize() const { return executable_.size(); }
|
||||
|
||||
Ссылка в новой задаче
Block a user