P4 to Git Change 2040890 by skudchad@skudchad_test2_win_opencl on 2019/12/04 14:16:51

SWDEV-203814 - HIPRTC Inprocess runtime changes(part2)

	ReviewBoardURL = http://ocltc.amd.com/reviews/r/18342/diff/

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.def.in#37 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.map.in#35 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#50 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_rtc.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#73 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#38 edit


[ROCm/clr commit: 6e9e96493f]
Этот коммит содержится в:
foreman
2019-12-04 14:22:03 -05:00
родитель 5cc928c1cc
Коммит c8a1e60eff
4 изменённых файлов: 126 добавлений и 9 удалений
+1
Просмотреть файл
@@ -129,6 +129,7 @@ hipLaunchCooperativeKernelMultiDevice
hipHccModuleLaunchKernel
hipModuleLoad
hipModuleLoadData
hipModuleLoadDataEx
hipModuleUnload
hipOccupancyMaxActiveBlocksPerMultiprocessor
hipOccupancyMaxActiveBlocksPerMultiprocessorWithFlags
+2
Просмотреть файл
@@ -129,6 +129,7 @@ global:
hipLaunchCooperativeKernelMultiDevice;
hipModuleLoad;
hipModuleLoadData;
hipModuleLoadDataEx;
hipModuleUnload;
hipOccupancyMaxActiveBlocksPerMultiprocessor;
hipOccupancyMaxActiveBlocksPerMultiprocessorWithFlags;
@@ -180,6 +181,7 @@ global:
hiprtcGetErrorString;
extern "C++" {
hip_impl::hipLaunchKernelGGLImpl*;
hip_impl::demangle*;
hipCreateTextureObject*;
hipDestroyTextureObject*;
hipGetTextureObjectResourceDesc*;
+10
Просмотреть файл
@@ -110,6 +110,16 @@ hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
HIP_RETURN(ihipModuleLoadData(module, image));
}
hipError_t hipModuleLoadDataEx(hipModule_t *module, const void *image,
unsigned int numOptions, hipJitOption* options,
void** optionsValues)
{
/* TODO: Pass options to Program */
HIP_INIT_API(hipModuleLoadData, module, image);
HIP_RETURN(ihipModuleLoadData(module, image));
}
extern bool __hipExtractCodeObjectFromFatBinary(const void* data,
const std::vector<const char*>& devices,
std::vector<std::pair<const void*, size_t>>& code_objs);
+113 -9
Просмотреть файл
@@ -24,7 +24,10 @@ THE SOFTWARE.
#include "hiprtc_internal.hpp"
#include <hip/hiprtc.h>
#include "platform/program.hpp"
#include <algorithm>
extern "C" char * __cxa_demangle(const char *mangled_name, char *output_buffer,
size_t *length, int *status);
namespace hiprtc {
thread_local hiprtcResult g_lastRtcError = HIPRTC_SUCCESS;
@@ -37,16 +40,18 @@ private:
ProgramState() : lock_("Guards program state") {}
~ProgramState() {}
public:
std::unordered_map<amd::Program*,
std::pair<std::vector<std::string>, std::vector<std::string>>> progHeaders_;
std::vector<std::string> nameExpresssion_;
public:
std::map<std::string, std::pair<std::string, std::string>> nameExpresssion_;
static ProgramState& instance();
void createProgramHeaders(amd::Program* program, int numHeaders,
const char** headers, const char** headerNames);
void getProgramHeaders(amd::Program* program, int* numHeaders, char** headers, char ** headerNames);
uint32_t addNameExpression(const char* name_expression);
char* getLoweredName(const char* name_expression);
};
ProgramState* ProgramState::programState_ = nullptr;
@@ -82,13 +87,86 @@ void ProgramState::getProgramHeaders(amd::Program* program, int* numHeaders,
}
}
uint32_t ProgramState::addNameExpression(const char* name_expression) {
amd::ScopedLock lock(lock_);
nameExpresssion_.emplace_back(name_expression);
// Strip clean of any '(' or ')' or '&'
std::string strippedName(name_expression);
if (strippedName.back() == ')') {
strippedName.pop_back();
strippedName.erase(0, strippedName.find('('));
}
if (strippedName.front() == '&') {
strippedName.erase(0, 1);
}
auto it = nameExpresssion_.find(name_expression);
if (it == nameExpresssion_.end()) {
nameExpresssion_.insert(std::pair<std::string, std::pair<std::string, std::string>>
(name_expression, std::make_pair(strippedName,"")));
}
return nameExpresssion_.size();
}
namespace hip_impl {
inline std::string demangle(const char* x) {
#ifdef ATI_OS_LINUX
if (!x) {
return {};
}
int s = 0;
std::unique_ptr<char, decltype(std::free)*> tmp{
__cxa_demangle(x, nullptr, nullptr, &s),
std::free};
if (s != 0) {
return {};
}
return tmp.get();
#else
return {};
#endif
}
} // hip_impl
std::string handleMangledName(std::string name) {
std::string demangled;
demangled = hip_impl::demangle(name.c_str());
if (demangled.empty()) {
return name;
}
if (demangled.find(".kd") != std::string::npos) {
return {};
}
if (demangled.find("void ") == 0) {
demangled.erase(0, strlen("void "));
}
auto dx{demangled.find_first_of("(<")};
if (dx == std::string::npos) {
return demangled;
}
if (demangled[dx] == '<') {
auto cnt{1u};
do {
++dx;
cnt += (demangled[dx] == '<') ? 1 : ((demangled[dx] == '>') ? -1 : 0);
} while (cnt);
demangled.erase(++dx);
} else {
demangled.erase(dx);
}
return demangled;
}
const char* hiprtcGetErrorString(hiprtcResult x) {
switch (x) {
@@ -192,13 +270,39 @@ hiprtcResult hiprtcAddNameExpression(hiprtcProgram prog, const char* name_expres
}
hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expression,
const char** loweredNames) {
HIPRTC_INIT_API(prog, name_expression, loweredNames);
const char** loweredName) {
HIPRTC_INIT_API(prog, name_expression, loweredName);
if (name_expression == nullptr || loweredNames == nullptr) {
if (name_expression == nullptr || loweredName == nullptr) {
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT);
}
amd::Program* program = as_amd(reinterpret_cast<cl_program>(prog));
device::Program* dev_program
= program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]);
auto it = ProgramState::instance().nameExpresssion_.find(name_expression);
if (it == ProgramState::instance().nameExpresssion_.end()) {
return HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID;
}
std::string strippedName = it->second.first;
std::vector<std::string> mangledNames;
if (!dev_program->getLoweredNames(&mangledNames)) {
HIPRTC_RETURN(HIPRTC_ERROR_COMPILATION);
}
for (auto &name : mangledNames) {
std::string demangledName = handleMangledName(name);
if (demangledName == strippedName) {
it->second.second.assign(name);
}
}
*loweredName = it->second.second.c_str();
HIPRTC_RETURN(HIPRTC_SUCCESS);
}