From 6931f87fcd4c5920de40c1ccc21c45f517451f95 Mon Sep 17 00:00:00 2001 From: Evghenii Date: Wed, 22 Jan 2014 10:16:37 +0100 Subject: [PATCH] added support to run test via NVVM --- examples_ptx/ptxcc/PTXParser.h | 21 ++++++++------- examples_ptx/ptxcc/ptx.ll | 2 ++ examples_ptx/ptxcc/ptxcc | 2 +- examples_ptx/ptxcc/ptxgrammar.yy | 13 ++++++--- module.cpp | 45 +++++++++++++++++++++++++------- run_tests.py | 14 ++++++++-- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/examples_ptx/ptxcc/PTXParser.h b/examples_ptx/ptxcc/PTXParser.h index 5ae0d903..e3f5b80f 100644 --- a/examples_ptx/ptxcc/PTXParser.h +++ b/examples_ptx/ptxcc/PTXParser.h @@ -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); } diff --git a/examples_ptx/ptxcc/ptx.ll b/examples_ptx/ptxcc/ptx.ll index 04d546fa..b717e0cd 100644 --- a/examples_ptx/ptxcc/ptx.ll +++ b/examples_ptx/ptxcc/ptx.ll @@ -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;} diff --git a/examples_ptx/ptxcc/ptxcc b/examples_ptx/ptxcc/ptxcc index 7953f902..ae0fca91 100755 --- a/examples_ptx/ptxcc/ptxcc +++ b/examples_ptx/ptxcc/ptxcc @@ -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 diff --git a/examples_ptx/ptxcc/ptxgrammar.yy b/examples_ptx/ptxcc/ptxgrammar.yy index 009ba140..843d88c0 100644 --- a/examples_ptx/ptxcc/ptxgrammar.yy +++ b/examples_ptx/ptxcc/ptxgrammar.yy @@ -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($4,@1); -} + { state.visibleInitializableDeclaration($4,@1); } +| TOKEN_VISIBLE TOKEN_GLOBAL addressableVariablePrefix identifier ';' + {state.arrayDimensions(0); state.visibleInitializableDeclaration($4,@1); } +| TOKEN_VISIBLE TOKEN_GLOBAL addressableVariablePrefix identifier '=' + {state.arrayDimensions(0); state.visibleInitializableDeclaration($4,@1); } %% diff --git a/module.cpp b/module.cpp index 93b0dcd6..3536c10f 100644 --- a/module.cpp +++ b/module.cpp @@ -2588,6 +2588,29 @@ lCreateDispatchModule(std::map &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) { diff --git a/run_tests.py b/run_tests.py index 0da70e72..0d4ed194 100755 --- a/run_tests.py +++ b/run_tests.py @@ -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],