added support to run test via NVVM

This commit is contained in:
Evghenii
2014-01-22 10:16:37 +01:00
parent 98fc43d859
commit 6931f87fcd
6 changed files with 72 additions and 25 deletions

View File

@@ -199,7 +199,10 @@ namespace parser
if (_alignment > 0)
s << "__attribute__((aligned(" << _alignment << "))) ";
s << tokenToDataType(_dataTypeId, 0);
s << name << "[" << arrayDimensionsList[0] << "] = {0};\n\n";
if (arrayDimensionsList[0] == 0)
s << name << ";\n\n";
else
s << name << "[" << arrayDimensionsList[0] << "] = {0};\n\n";
std::cout << s.str();
arrayDimensionsList.clear();
}
@@ -225,16 +228,16 @@ namespace parser
case TOKEN_U16: assert(0); s << "u16_t "; break;
case TOKEN_S16: assert(0); s << "s16_t "; break;
case TOKEN_B32: assert(dim == 1); s << "b32_t "; break;
case TOKEN_U32: assert(dim == 1); s << "u32_t "; break;
case TOKEN_S32: assert(dim == 1); s << "s32_t "; break;
case TOKEN_B32: assert(dim <= 1); s << "b32_t "; break;
case TOKEN_U32: assert(dim <= 1); s << "u32_t "; break;
case TOKEN_S32: assert(dim <= 1); s << "s32_t "; break;
case TOKEN_B64: assert(dim == 1); s << "b64_t "; break;
case TOKEN_U64: assert(dim == 1); s << "u64_t "; break;
case TOKEN_S64: assert(dim == 1); s << "s64_t "; break;
case TOKEN_B64: assert(dim <= 1); s << "b64_t "; break;
case TOKEN_U64: assert(dim <= 1); s << "u64_t "; break;
case TOKEN_S64: assert(dim <= 1); s << "s64_t "; break;
case TOKEN_F32: assert(dim == 1); s << "f32_t "; break;
case TOKEN_F64: assert(dim == 1); s << "f64_t "; break;
case TOKEN_F32: assert(dim <= 1); s << "f32_t "; break;
case TOKEN_F64: assert(dim <= 1); s << "f64_t "; break;
default: std::cerr << "token= " << token<< std::endl; assert(0);
}

View File

@@ -48,6 +48,8 @@ TAB [\t]*
"(" { return '(';}
")" { return ')';}
"," { return ',';}
";" { return ';';}
"=" { return '=';}
[0-9]+\.[0-9]+ { yylval->fvalue = atof(yytext); return TOKEN_FLOAT; }
[0-9]+ { yylval->ivalue = atoi(yytext); return TOKEN_INT; }
[a-zA-Z0-9_]+ { strcpy(yylval->svalue, yytext); return TOKEN_STRING;}

View File

@@ -10,7 +10,7 @@ DEPTX=dePTX
NVCC=nvcc
$DEPTX < $PTXSRC > $PTXCU &&
$NVCC -arch=sm_35 -dc $NVCCPARM -dryrun $PTXCU 2>&1 | \
$NVCC -arch=sm_35 -G -dc $NVCCPARM -dryrun $PTXCU 2>&1 | \
sed 's/\#\$//g'| \
awk '{ if ($1 == "LIBRARIES=") print $1$2; else if ($1 == "cicc") print "cp '$PTXSRC'", $NF; else print $0 }' > $PTXSH &&
sh $PTXSH

View File

@@ -105,7 +105,10 @@ anytoken:
| ']'
| '('
| ')'
| ',';
| ','
| ';'
| '='
;
ptxbody:
ptxbody visibleFunctionDeclaration | visibleFunctionDeclaration
@@ -157,9 +160,11 @@ visibleFunctionDeclaration: TOKEN_VISIBLE TOKEN_FUNC optionalReturnArgumentList
visibleInitializableDeclaration :
TOKEN_VISIBLE TOKEN_GLOBAL addressableVariablePrefix identifier arrayDimensionSet
{
state.visibleInitializableDeclaration($<svalue>4,@1);
}
{ state.visibleInitializableDeclaration($<svalue>4,@1); }
| TOKEN_VISIBLE TOKEN_GLOBAL addressableVariablePrefix identifier ';'
{state.arrayDimensions(0); state.visibleInitializableDeclaration($<svalue>4,@1); }
| TOKEN_VISIBLE TOKEN_GLOBAL addressableVariablePrefix identifier '='
{state.arrayDimensions(0); state.visibleInitializableDeclaration($<svalue>4,@1); }
%%

View File

@@ -2588,6 +2588,29 @@ lCreateDispatchModule(std::map<std::string, FunctionTargetVariants> &functions)
return module;
}
static std::string lCBEMangle(const std::string &S) {
std::string Result;
for (unsigned i = 0, e = S.size(); i != e; ++i) {
if (i+1 != e && ((S[i] == '>' && S[i+1] == '>') ||
(S[i] == '<' && S[i+1] == '<'))) {
Result += '_';
Result += 'A'+(S[i]&15);
Result += 'A'+((S[i]>>4)&15);
Result += '_';
i++;
} else if (isalnum(S[i]) || S[i] == '_' || S[i] == '<' || S[i] == '>') {
Result += S[i];
} else {
Result += '_';
Result += 'A'+(S[i]&15);
Result += 'A'+((S[i]>>4)&15);
Result += '_';
}
}
return Result;
}
int
Module::CompileAndOutput(const char *srcFile,
@@ -2618,17 +2641,21 @@ Module::CompileAndOutput(const char *srcFile,
*/
if (g->target->getISA() == Target::NVPTX)
{
llvm::Module::global_iterator
I = m->module->global_begin(),
E = m->module->global_end();
for (; I != E; I++)
/* mangle global variables names */
{
std::string name = I->getName();
for (int i = 0; i < name.length(); i++)
if (name[i] == '.')
name[i] = '_';
I->setName(name);
llvm::Module::global_iterator I = m->module->global_begin(), E = m->module->global_end();
for (; I != E; I++)
I->setName(lCBEMangle(I->getName()));
}
#if 0 /* mangles primitves as well grrr */
/* mangle functions names */
{
llvm::Module::iterator I = m->module->begin(), E = m->module->end();
for (; I != E; I++)
I->setName(lCBEMangle(I->getName()));
}
#endif
}
if (outputType == CXX) {

View File

@@ -205,6 +205,7 @@ def run_test(testname):
else:
global is_generic_target
global is_nvptx_target
global is_nvptx_nvvm
if is_windows:
if is_generic_target:
obj_name = "%s.cpp" % os.path.basename(filename)
@@ -220,7 +221,12 @@ def run_test(testname):
if is_generic_target:
obj_name = "%s.cpp" % testname
elif is_nvptx_target:
if os.environ.get("NVVM") == "1":
is_nvptx_nvvm = True
obj_name = "%s.bc" % testname
else:
obj_name = "%s.ptx" % testname
is_nvptx_nvvm = False
else:
obj_name = "%s.o" % testname
exe_name = "%s.run" % testname
@@ -271,8 +277,12 @@ def run_test(testname):
print "Grepping: %s" % grep_cmd
sp = subprocess.Popen(grep_cmd, shell=True)
sp.communicate()
ispc_cmd = ispc_exe_rel + " --woff %s -o %s -O3 --emit-asm --target=%s" % \
(filename4ptx, obj_name, options.target)
if is_nvptx_nvvm:
ispc_cmd = ispc_exe_rel + " --woff %s -o %s -O3 --emit-llvm --target=%s" % \
(filename4ptx, obj_name, options.target)
else:
ispc_cmd = ispc_exe_rel + " --woff %s -o %s -O3 --emit-asm --target=%s" % \
(filename4ptx, obj_name, options.target)
# compile the ispc code, make the executable, and run it...
(compile_error, run_error) = run_cmds([ispc_cmd, cc_cmd],