-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug in CUDA parser with macros
- Loading branch information
Showing
5 changed files
with
166 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/parser/static/test_instrument_macro_unused_parms/test_instrument_macro_unused_parms.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import os | ||
import pathlib | ||
import sys | ||
import subprocess | ||
import pytest | ||
|
||
sys.path.insert(1, str(pathlib.Path(__file__).parent.absolute())+"/../../../../parser") | ||
#sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser') | ||
from tokenizer import Tokenizer | ||
from instrument import Instrument | ||
|
||
RUNTIME='../../../../src/Runtime_parser.h' | ||
|
||
prog_1 = """ | ||
#define MULTI_LINE_MACRO(a, b, c, d, e) { a = b + c; } | ||
__device__ void comp(double *a, double b, double c) { | ||
double tmp1 = 0.0; | ||
double tmp2 = 0.1; | ||
MULTI_LINE_MACRO( a[0], | ||
b, c, | ||
tmp1, | ||
tmp2 ); tmp1 = tmp2; | ||
} | ||
__host__ void comp2(int N) { | ||
#pragma omp parallel | ||
#pragma omp for | ||
for (int i=0; i<N; i++) { | ||
// do something with i | ||
} | ||
} | ||
""" | ||
|
||
def setup_module(module): | ||
THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
os.chdir(THIS_DIR) | ||
|
||
def teardown_module(module): | ||
cmd = ["rm -f *.o *.ii *.cu"] | ||
cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) | ||
|
||
def preprocessFile(prog_name: str): | ||
cmd = ['nvcc -E '+prog_name+'.cu -o '+prog_name+'.ii'] | ||
cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) | ||
|
||
def createFile(prog: str, prog_name: str): | ||
with open(prog_name+'.cu', 'w') as fd: | ||
fd.write(prog) | ||
fd.write('\n') | ||
preprocessFile(prog_name) | ||
|
||
def instrument(prog_name: str): | ||
pass | ||
preFileName = prog_name+'.ii' | ||
sourceFileName = prog_name+'.cu' | ||
inst = Instrument(preFileName, sourceFileName) | ||
inst.deprocess() | ||
inst.findDeviceDeclarations() | ||
inst.findAssigments() | ||
inst.produceInstrumentedLines() | ||
inst.instrument() | ||
|
||
def compileProggram(prog_name: str): | ||
try: | ||
cmd = ['nvcc -std=c++11 -c -include '+RUNTIME+' '+prog_name+'_inst.cu'] | ||
cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) | ||
except Exception as e: | ||
print(e) | ||
exit() | ||
|
||
def countInstrumentationCalls(prog_name: str): | ||
ret = 0 | ||
with open(prog_name+'_inst.cu', 'r') as fd: | ||
for l in fd.readlines(): | ||
for w in l.split(): | ||
if '_FPC_CHECK_' in w: | ||
ret += 1 | ||
return ret | ||
|
||
def inst_program(prog: str, prog_name: str, num_inst: int): | ||
try: | ||
createFile(prog, prog_name) | ||
instrument(prog_name) | ||
compileProggram(prog_name) | ||
n = countInstrumentationCalls(prog_name) | ||
assert n == num_inst | ||
return True | ||
except Exception as e: | ||
print(e) | ||
return False | ||
|
||
#@pytest.mark.xfail(reason="Known parser issue with macros") | ||
def test_1(): | ||
os.environ['FPC_VERBOSE'] = '1' | ||
inst_program(prog_1, 'prog_1', 1) | ||
|
||
if __name__ == '__main__': | ||
test_1() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters