Fix HIPRTC headers to export C style symbols

Change-Id: I3e0d2b19ace4a9096e3e46bd22f420483da51a8a
This commit is contained in:
Saleel Kudchadker
2020-02-28 10:34:56 -08:00
orang tua a15e895cfd
melakukan 514c7c8ef8
3 mengubah file dengan 49 tambahan dan 34 penghapusan
+2 -12
Melihat File
@@ -181,6 +181,8 @@ global:
hiprtcGetCode;
hiprtcGetCodeSize;
hiprtcGetErrorString;
hiprtcAddNameExpression;
hiprtcVersion;
extern "C++" {
hip_impl::hipLaunchKernelGGLImpl*;
hip_impl::demangle*;
@@ -221,18 +223,6 @@ global:
hipInitActivityCallback*;
hipEnableActivityCallback*;
hipGetCmdName*;
hiprtcAddNameExpression*;
hiprtcCompileProgram*;
hiprtcCreateProgram*;
hiprtcDestroyProgram*;
hiprtcGetLoweredName*;
hiprtcGetProgramLog*;
hiprtcGetProgramLogSize*;
hiprtcGetCode*;
hiprtcGetCodeSize*;
hiprtcGetErrorString*;
hiprtcVersion*;
hiprtcGetTypeName*;
};
local:
*;
+34 -21
Melihat File
@@ -23,10 +23,6 @@
#include <hip/hiprtc.h>
#include "platform/program.hpp"
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;
}
@@ -105,30 +101,34 @@ uint32_t ProgramState::addNameExpression(const char* name_expression) {
return nameExpresssion_.size();
}
namespace hip_impl {
char* demangle(const char* loweredName) {
#ifdef ATI_OS_LINUX
if (!loweredName) {
return nullptr;
}
#if HIPRTC_USE_CXXABI || __linux__
int status = 0;
char* demangledName = __cxa_demangle(loweredName, nullptr, nullptr, &status);
char* demangledName = abi::__cxa_demangle(loweredName, nullptr, nullptr, &status);
if (status != 0) {
return nullptr;
}
#elif defined(_WIN32)
char* demangledName = (char*)malloc(UNDECORATED_SIZE);
return demangledName;
if (!UnDecorateSymbolName(loweredName, demangledName,
UNDECORATED_SIZE/ sizeof(*demangledName), UNDNAME_COMPLETE))
{
free(demangledName);
return nullptr;
}
#else
return nullptr;
#endif
#error "Only Linux and Windows are supported"
#endif // HIPRTC_USE_CXXABI || __linux__
return demangledName;
}
} // hip_impl
static std::string handleMangledName(std::string name) {
std::string loweredName;
char* demangled = hip_impl::demangle(name.c_str());
char* demangled = demangle(name.c_str());
loweredName.assign(demangled == nullptr ? std::string() : demangled);
free(demangled);
@@ -165,7 +165,6 @@ static std::string handleMangledName(std::string name) {
return loweredName;
}
const char* hiprtcGetErrorString(hiprtcResult x) {
switch (x) {
case HIPRTC_SUCCESS:
@@ -232,7 +231,6 @@ hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog, const char* src, const cha
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char** options) {
// FIXME[skudchad] Add headers to amd::Program::build and device::Program::build,
@@ -244,6 +242,8 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char
std::ostringstream ostrstr;
std::vector<const char*> oarr(&options[0], &options[numOptions]);
std::copy(oarr.begin(), oarr.end(), std::ostream_iterator<std::string>(ostrstr, " "));
ostrstr.str().append(" -DHIP_VERSION_MAJOR=").append(std::to_string(HIP_VERSION_MAJOR));
ostrstr.str().append(" -DHIP_VERSION_MINOR=").append(std::to_string(HIP_VERSION_MINOR));
std::vector<amd::Device*> devices{hip::getCurrentDevice()->devices()[0]};
if (CL_SUCCESS != program->build(devices, ostrstr.str().c_str(), nullptr, nullptr)) {
@@ -305,7 +305,7 @@ hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expressio
*loweredName = it->second.second.c_str();
HIPRTC_RETURN(HIPRTC_SUCCESS);
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcDestroyProgram(hiprtcProgram* prog) {
@@ -320,7 +320,7 @@ hiprtcResult hiprtcDestroyProgram(hiprtcProgram* prog) {
program->release();
HIPRTC_RETURN(HIPRTC_SUCCESS);
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcGetCode(hiprtcProgram prog, char* binaryMem) {
@@ -345,7 +345,7 @@ hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, size_t* binarySizeRet) {
*binarySizeRet =
program->getDeviceProgram(*hip::getCurrentDevice()->devices()[0])->binary().second;
HIPRTC_RETURN(HIPRTC_SUCCESS);
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcGetProgramLog(hiprtcProgram prog, char* dst) {
@@ -360,7 +360,7 @@ hiprtcResult hiprtcGetProgramLog(hiprtcProgram prog, char* dst) {
log.copy(dst, log.size());
dst[log.size()] = '\0';
HIPRTC_RETURN(HIPRTC_SUCCESS);
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram prog, size_t* logSizeRet) {
@@ -375,5 +375,18 @@ hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram prog, size_t* logSizeRet) {
*logSizeRet = log.size() + 1;
HIPRTC_RETURN(HIPRTC_SUCCESS);
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
hiprtcResult hiprtcVersion(int* major, int* minor) {
HIPRTC_INIT_API(major, minor);
if (major == nullptr || minor == nullptr) {
HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT);
}
*major = 9;
*minor = 0;
HIPRTC_RETURN(HIPRTC_SUCCESS);
}
+13 -1
Melihat File
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-present Advanced Micro Devices, Inc.
/* Copyright (c) 2015-present Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,6 +23,18 @@
#include "hip_internal.hpp"
#if HIPRTC_USE_CXXABI || __linux__
#include <cxxabi.h>
#include <cstdlib>
#elif defined(_WIN32)
#include <Windows.h>
#include <DbgHelp.h>
#define UNDECORATED_SIZE 4096
#endif // HIPRTC_USE_CXXABI || __linux__
// This macro should be called at the beginning of every HIP RTC API.
#define HIPRTC_INIT_API(...) \
ClPrint(amd::LOG_INFO, amd::LOG_API, "[%zx] %s ( %s )", std::this_thread::get_id(), __func__, ToString( __VA_ARGS__ ).c_str()); \