Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 85aa4d24 authored by ANDRADE-BARROSO Guillermo's avatar ANDRADE-BARROSO Guillermo
Browse files

add write Assembler code

parent 99ec3c48
No related branches found
No related tags found
No related merge requests found
......@@ -8,16 +8,34 @@ X = numpy.random.rand(sizeX).astype(numpy.float32)
Y = numpy.empty(sizeX).astype(numpy.float32)
def BenchmarkCode(name, code,X,Y):
def get_assembly(code):
return inline.cxx2asm(code, compiler_extra_args=['-msse2','-fopenmp', '-lstdc++'])
def BenchmarkCode(name, code, X, Y, SSE=True, OMP=True):
# init
Y[:]=0.5
X[:]=1.0
# compile the code
lib=inline.cxx(code, compiler_extra_args=['-msse2','-fopenmp'], link_extra_args= ['-msse2','-fopenmp'])
compiler_extra_args = ['-g0','-lstdc++']
link_extra_args = ['-lstdc++']
if SSE :
compiler_extra_args+=['-msse2']
link_extra_args += ['-msse2']
if OMP:
compiler_extra_args+=['-fopenmp']
link_extra_args += ['-fopenmp']
lib=inline.cxx(code, compiler_extra_args= compiler_extra_args, link_extra_args= link_extra_args)
p_float= numpy.ctypeslib.ndpointer(dtype=numpy.float32)
lib.compute.argtypes = [ctypes.c_int, ctypes.c_int, p_float, p_float]
# print assembler code
asm_code=inline.cxx2asm(code, compiler_extra_args= compiler_extra_args)
with open(name+'.s','w') as f:
f.write(asm_code)
# start chronometer
start_time = time()
# run the code
......@@ -53,7 +71,7 @@ void compute(int numberIterations, int sizeX, float *X, float *Y )
}
"""
referenceTime=BenchmarkCode('Reference', referenceCode,X,Y)
referenceTime=BenchmarkCode('Reference', referenceCode, X, Y)
SSECode="""
#line 59 "saxpy.py" // helpful for debug
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment