From 514c7c8ef80cf91c1cd963c463949eb7fdbcb578 Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 28 Feb 2020 10:34:56 -0800 Subject: [PATCH] Fix HIPRTC headers to export C style symbols Change-Id: I3e0d2b19ace4a9096e3e46bd22f420483da51a8a --- hipamd/vdi/hip_hcc.map.in | 14 ++------- hipamd/vdi/hip_rtc.cpp | 55 +++++++++++++++++++++------------- hipamd/vdi/hiprtc_internal.hpp | 14 ++++++++- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/hipamd/vdi/hip_hcc.map.in b/hipamd/vdi/hip_hcc.map.in index 043ea856ff..03d48fe9e7 100644 --- a/hipamd/vdi/hip_hcc.map.in +++ b/hipamd/vdi/hip_hcc.map.in @@ -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: *; diff --git a/hipamd/vdi/hip_rtc.cpp b/hipamd/vdi/hip_rtc.cpp index 1f9a6e1636..4ec48f3af3 100644 --- a/hipamd/vdi/hip_rtc.cpp +++ b/hipamd/vdi/hip_rtc.cpp @@ -23,10 +23,6 @@ #include #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 oarr(&options[0], &options[numOptions]); std::copy(oarr.begin(), oarr.end(), std::ostream_iterator(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 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); } diff --git a/hipamd/vdi/hiprtc_internal.hpp b/hipamd/vdi/hiprtc_internal.hpp index 2b9bdf026a..e95a28c08f 100644 --- a/hipamd/vdi/hiprtc_internal.hpp +++ b/hipamd/vdi/hiprtc_internal.hpp @@ -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 +#include + +#elif defined(_WIN32) +#include +#include + +#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()); \