Merge pull request #1450 from emankov/hipify-clang
[HIPIFY][#1435][perl] Add HIP_SYMBOL wrapper to the templated Device Symbol argument of the following functions:
[ROCm/clr commit: 953f4608ab]
Cette révision appartient à :
@@ -160,6 +160,8 @@ while (@ARGV) {
|
||||
undef $/; # Read whole file at once, so we can match newlines.
|
||||
while (<INFILE>)
|
||||
{
|
||||
# chomp;
|
||||
# next if /^(\s*(#.*)?)?$/;
|
||||
$ft{'error'} += s/\bcudaGetErrorName\b/hipGetErrorName/g;
|
||||
$ft{'error'} += s/\bcudaGetErrorString\b/hipGetErrorString/g;
|
||||
$ft{'error'} += s/\bcudaGetLastError\b/hipGetLastError/g;
|
||||
@@ -1761,6 +1763,8 @@ while (@ARGV) {
|
||||
$ft{'kernel_func'} += countSupportedDeviceFunctions();
|
||||
}
|
||||
|
||||
$ft{'memory'} += transformSymbolFunctions();
|
||||
|
||||
# Print it!
|
||||
# TODO - would like to move this code outside loop but it uses $_ which contains the whole file.
|
||||
unless ($no_output) {
|
||||
@@ -1815,6 +1819,28 @@ if ($count_conversions) {
|
||||
}
|
||||
}
|
||||
|
||||
sub transformSymbolFunctions
|
||||
{
|
||||
my $m = 0;
|
||||
foreach $func (
|
||||
"hipMemcpyToSymbol",
|
||||
"hipMemcpyToSymbolAsync"
|
||||
)
|
||||
{
|
||||
$m += s/(?<!\/\/ CHECK: )($func)\s*\(\s*([^,]+)\s*,/$func\(HIP_SYMBOL\($2\),/g
|
||||
}
|
||||
foreach $func (
|
||||
"hipGetSymbolAddress",
|
||||
"hipGetSymbolSize",
|
||||
"hipMemcpyFromSymbol",
|
||||
"hipMemcpyFromSymbolAsync"
|
||||
)
|
||||
{
|
||||
$m += s/(?<!\/\/ CHECK: )($func)\s*\(\s*([^,]+)\s*,\s*([^,\)]+)\s*(,\s*|\))\s*/$func\($2, HIP_SYMBOL\($3\)$4/g;
|
||||
}
|
||||
return $m;
|
||||
}
|
||||
|
||||
sub countSupportedDeviceFunctions
|
||||
{
|
||||
my $m = 0;
|
||||
|
||||
@@ -41,6 +41,42 @@ namespace perl {
|
||||
const std::string triple_space = double_space + space;
|
||||
const std::string sSub = "sub";
|
||||
const std::string sReturn_0 = "return 0;\n";
|
||||
const std::string sReturn_m = "return $m;\n";
|
||||
const std::string sForeach = "foreach $func (\n";
|
||||
const std::string sMy = "my $m = 0;\n";
|
||||
|
||||
void generateSymbolFunctions(std::unique_ptr<std::ostream>& perlStreamPtr) {
|
||||
*perlStreamPtr.get() << "\n" << sSub << " transformSymbolFunctions\n" << "{\n" << space << sMy;
|
||||
std::string sCommon = space + sForeach;
|
||||
*perlStreamPtr.get() << sCommon;
|
||||
unsigned int count = 0;
|
||||
for (auto& dsf : DeviceSymbolFunctions0) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(dsf);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
*perlStreamPtr.get() << (count ? ",\n" : "") << double_space << "\"" << found->second.hipName.str() << "\"";
|
||||
count++;
|
||||
}
|
||||
}
|
||||
*perlStreamPtr.get() << "\n" << space << ")\n";
|
||||
*perlStreamPtr.get() << space << "{\n";
|
||||
*perlStreamPtr.get() << double_space << "$m += s/(?<!\\/\\/ CHECK: )($func)\\s*\\(\\s*([^,]+)\\s*,/$func\\(HIP_SYMBOL\\($2\\),/g\n";
|
||||
*perlStreamPtr.get() << space << "}\n";
|
||||
*perlStreamPtr.get() << sCommon;
|
||||
count = 0;
|
||||
for (auto& dsf : DeviceSymbolFunctions1) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(dsf);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
*perlStreamPtr.get() << (count ? ",\n" : "") << double_space << "\"" << found->second.hipName.str() << "\"";
|
||||
count++;
|
||||
}
|
||||
}
|
||||
*perlStreamPtr.get() << "\n" << space << ")\n";
|
||||
*perlStreamPtr.get() << space << "{\n";
|
||||
*perlStreamPtr.get() << double_space << "$m += s/(?<!\\/\\/ CHECK: )($func)\\s*\\(\\s*([^,]+)\\s*,\\s*([^,\\)]+)\\s*(,\\s*|\\))\\s*/$func\\($2, HIP_SYMBOL\\($3\\)$4/g;\n";
|
||||
*perlStreamPtr.get() << space << "}\n";
|
||||
*perlStreamPtr.get() << space << sReturn_m;
|
||||
*perlStreamPtr.get() << "}\n";
|
||||
}
|
||||
|
||||
void generateDeviceFunctions(std::unique_ptr<std::ostream>& perlStreamPtr) {
|
||||
unsigned int countUnsupported = 0;
|
||||
@@ -59,7 +95,7 @@ namespace perl {
|
||||
std::stringstream subCountSupported;
|
||||
std::stringstream subWarnUnsupported;
|
||||
std::stringstream subCommon;
|
||||
std::string sCommon = space + "my $m = 0;\n" + space + "foreach $func (\n";
|
||||
std::string sCommon = space + sMy + space + sForeach;
|
||||
subCountSupported << "\n" << sSub << " countSupportedDeviceFunctions\n" << "{\n" << (countSupported ? sCommon : space + sReturn_0);
|
||||
subWarnUnsupported << "\n" << sSub << " warnUnsupportedDeviceFunctions\n" << "{\n" << (countUnsupported ? space + "my $line_num = shift;\n" + sCommon : space + sReturn_0);
|
||||
if (countSupported) {
|
||||
@@ -85,7 +121,7 @@ namespace perl {
|
||||
subWarnUnsupported << triple_space << "print STDERR \" warning: $fileName:$line_num: unsupported device function \\\"$func\\\": $_\\n\";\n";
|
||||
}
|
||||
if (countSupported || countUnsupported) {
|
||||
sCommon = double_space + "}\n" + space + "}\n" + space + "return $m;\n";
|
||||
sCommon = double_space + "}\n" + space + "}\n" + space + sReturn_m;
|
||||
}
|
||||
if (countSupported) {
|
||||
subCountSupported << sCommon;
|
||||
@@ -157,6 +193,7 @@ namespace perl {
|
||||
}
|
||||
}
|
||||
}
|
||||
generateSymbolFunctions(perlStreamPtr);
|
||||
generateDeviceFunctions(perlStreamPtr);
|
||||
perlStreamPtr.get()->flush();
|
||||
bool ret = true;
|
||||
|
||||
@@ -22,6 +22,9 @@ THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
extern std::set<std::string> DeviceSymbolFunctions0;
|
||||
extern std::set<std::string> DeviceSymbolFunctions1;
|
||||
|
||||
namespace perl {
|
||||
|
||||
bool generate(bool Generate = true);
|
||||
|
||||
@@ -43,12 +43,12 @@ const std::string sCudaGetSymbolAddress = "cudaGetSymbolAddress";
|
||||
const std::string sCudaMemcpyFromSymbol = "cudaMemcpyFromSymbol";
|
||||
const std::string sCudaMemcpyFromSymbolAsync = "cudaMemcpyFromSymbolAsync";
|
||||
|
||||
const std::set<std::string> DeviceSymbolFunctions0 {
|
||||
std::set<std::string> DeviceSymbolFunctions0 {
|
||||
{sCudaMemcpyToSymbol},
|
||||
{sCudaMemcpyToSymbolAsync}
|
||||
};
|
||||
|
||||
const std::set<std::string> DeviceSymbolFunctions1 {
|
||||
std::set<std::string> DeviceSymbolFunctions1 {
|
||||
{sCudaGetSymbolSize},
|
||||
{sCudaGetSymbolAddress},
|
||||
{sCudaMemcpyFromSymbol},
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur