Supporting perf.py on Windows and some small corrections in it

This commit is contained in:
Ilia Filippov
2013-07-02 19:23:18 +04:00
parent 8be4128c5a
commit fd7f87b55e
4 changed files with 69 additions and 22 deletions

View File

@@ -87,18 +87,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>ao</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<ExecutablePath>$(ExecutablePath);$(ProjectDir)..\..</ExecutablePath> <ExecutablePath>$(ExecutablePath);$(ProjectDir)..\..</ExecutablePath>
<TargetName>ao</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>ao</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>ao</TargetName>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -173,4 +177,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -65,18 +65,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>mandelbrot</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>mandelbrot</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>mandelbrot</TargetName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath> <ExecutablePath>$(ProjectDir)..\..;$(ExecutablePath)</ExecutablePath>
<TargetName>mandelbrot</TargetName>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>

View File

@@ -8,11 +8,17 @@ import operator
import time import time
import glob import glob
import string import string
import platform
def build_test(): def build_test():
global build_log global build_log
os.system("make clean >> "+build_log) global is_windows
return os.system("make >> "+build_log+" 2>> "+build_log) if is_windows == False:
os.system("make clean >> "+build_log)
return os.system("make >> "+build_log+" 2>> "+build_log)
else:
os.system("msbuild /t:clean >> " + build_log)
return os.system("msbuild /V:m /p:Platform=x64 /p:Configuration=Release /p:TargetDir=.\ /t:rebuild >> " + build_log)
def execute_test(command): def execute_test(command):
global perf_temp global perf_temp
@@ -38,7 +44,7 @@ def run_test(command, c1, c2, test):
for line in open(perf_temp): # we take test output for line in open(perf_temp): # we take test output
if "speedup" in line: # we are interested only in lines with speedup if "speedup" in line: # we are interested only in lines with speedup
if j == c1: # we are interested only in lines with c1 numbers if j == c1: # we are interested only in lines with c1 numbers
print line sys.stdout.write(line)
line = line.expandtabs(0) line = line.expandtabs(0)
line = line.replace("("," ") line = line.replace("("," ")
line = line.split(",") line = line.split(",")
@@ -66,10 +72,22 @@ def cpu_get():
#returns cpu_usage #returns cpu_usage
def cpu_check(): def cpu_check():
cpu1 = cpu_get() if is_windows == False:
time.sleep(1) cpu1 = cpu_get()
cpu2 = cpu_get() time.sleep(1)
cpu_percent = (float(cpu1[0] - cpu2[0])/float(cpu1[1] - cpu2[1]))*100 cpu2 = cpu_get()
cpu_percent = (float(cpu1[0] - cpu2[0])/float(cpu1[1] - cpu2[1]))*100
else:
os.system("wmic cpu get loadpercentage /value > cpu_temp")
c = open("cpu_temp", 'r')
c_lines = c.readlines()
c.close()
os.remove("cpu_temp")
t = "0"
for i in c_lines[2]:
if i.isdigit():
t = t + i
cpu_percent = int(t)
return cpu_percent return cpu_percent
#returns geomean of list #returns geomean of list
@@ -88,7 +106,7 @@ def geomean(par):
#test[2] - list of results with tasks #test[2] - list of results with tasks
#test[1] or test[2] may be empty #test[1] or test[2] may be empty
def print_answer(answer): def print_answer(answer):
print "Name of test:\t\tISPC:\tISPC + tasks:" sys.stdout.write("Name of test:\t\tISPC:\tISPC + tasks:\n")
max_t = [0,0] max_t = [0,0]
diff_t = [0,0] diff_t = [0,0]
geomean_t = [0,0] geomean_t = [0,0]
@@ -122,31 +140,45 @@ parser.add_option('-p', '--path', dest='path',
help='path to examples directory', default="./") help='path to examples directory', default="./")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
global is_windows
is_windows = (platform.system() == 'Windows' or
'CYGWIN_NT' in platform.system())
# save corrent path # save corrent path
pwd = os.getcwd() pwd = os.getcwd()
pwd = pwd + os.sep pwd = pwd + os.sep
if is_windows:
pwd = "..\\"
# check if cpu usage is low now # check if cpu usage is low now
cpu1 = cpu_get()
time.sleep(1)
cpu2 = cpu_get()
cpu_percent = (float(cpu1[0] - cpu2[0])/float(cpu1[1] - cpu2[1]))*100
cpu_percent = cpu_check() cpu_percent = cpu_check()
if cpu_percent > 20: if cpu_percent > 20:
sys.stdout.write("Warning: CPU Usage is very high.\n") sys.stdout.write("Warning: CPU Usage is very high.\n")
sys.stdout.write("Close other applications.\n") sys.stdout.write("Close other applications.\n")
# check that required compiler exists # check that required compilers exist
PATH_dir = string.split(os.getenv("PATH"), os.pathsep) PATH_dir = string.split(os.getenv("PATH"), os.pathsep)
compiler_exists = False compiler_exists = False
ref_compiler_exists = False
if is_windows == False:
compiler = "ispc"
ref_compiler = "g++"
else:
compiler = "ispc.exe"
ref_compiler = "cl.exe"
for counter in PATH_dir: for counter in PATH_dir:
if os.path.exists(counter + os.sep + "ispc"): if os.path.exists(counter + os.sep + compiler):
compiler_exists = True compiler_exists = True
break if os.path.exists(counter + os.sep + ref_compiler):
ref_compiler_exists = True
if not compiler_exists: if not compiler_exists:
sys.stderr.write("Fatal error: ISPC compiler not found.\n") sys.stderr.write("Fatal error: ISPC compiler not found.\n")
sys.stderr.write("Added path to ispc compiler to your PATH variable.\n") sys.stderr.write("Added path to ispc compiler to your PATH variable.\n")
sys.exit() sys.exit()
if not ref_compiler_exists:
sys.stderr.write("Fatal error: reference compiler %s not found.\n" % ref_compiler)
sys.stderr.write("Added path to %s compiler to your PATH variable.\n" % ref_compiler)
sys.exit()
# checks that config file exists # checks that config file exists
path_config = os.path.normpath(options.config) path_config = os.path.normpath(options.config)
@@ -168,8 +200,12 @@ length = len(lines)
# prepare build.log and perf_temp files # prepare build.log and perf_temp files
global build_log global build_log
build_log = pwd + "build.log" build_log = pwd + "build.log"
if os.path.exists(build_log): if is_windows == False:
os.remove(build_log) if os.path.exists(build_log):
os.remove(build_log)
else:
if os.path.exists("build.log"):
os.remove("build.log")
global perf_temp global perf_temp
perf_temp = pwd + "perf_temp" perf_temp = pwd + "perf_temp"
@@ -194,7 +230,10 @@ while i < length-2:
# read parameters of test # read parameters of test
command = lines[i+2] command = lines[i+2]
command = command[:-1] command = command[:-1]
command = "./"+command + " >> " + perf_temp if is_windows == False:
command = "./"+command + " >> " + perf_temp
else:
command = "x64\\Release\\"+command + " >> " + perf_temp
# parsing config parameters # parsing config parameters
next_line = lines[i+3] next_line = lines[i+3]
if next_line[0] == "!": # we should take only one part of test output if next_line[0] == "!": # we should take only one part of test output

View File

@@ -344,7 +344,7 @@ static inline void
lMemFence() { lMemFence() {
// Windows atomic functions already contain the fence // Windows atomic functions already contain the fence
// KNC doesn't need the memory barrier // KNC doesn't need the memory barrier
#if !defined ISPC_IS_KNC || !defined ISPC_IS_WINDOWS #if !defined ISPC_IS_KNC && !defined ISPC_IS_WINDOWS
__asm__ __volatile__("mfence":::"memory"); __asm__ __volatile__("mfence":::"memory");
#endif #endif
} }
@@ -374,7 +374,7 @@ lAtomicCompareAndSwapPointer(void **v, void *newValue, void *oldValue) {
static int32_t static int32_t
lAtomicCompareAndSwap32(volatile int32_t *v, int32_t newValue, int32_t oldValue) { lAtomicCompareAndSwap32(volatile int32_t *v, int32_t newValue, int32_t oldValue) {
#ifdef ISPC_IS_WINDOWS #ifdef ISPC_IS_WINDOWS
return InterlockedCompareExchange(v, newValue, oldValue); return InterlockedCompareExchange((volatile LONG *)v, newValue, oldValue);
#else #else
int32_t result; int32_t result;
__asm__ __volatile__("lock\ncmpxchgl %2,%1" __asm__ __volatile__("lock\ncmpxchgl %2,%1"
@@ -389,7 +389,7 @@ lAtomicCompareAndSwap32(volatile int32_t *v, int32_t newValue, int32_t oldValue)
static inline int32_t static inline int32_t
lAtomicAdd(volatile int32_t *v, int32_t delta) { lAtomicAdd(volatile int32_t *v, int32_t delta) {
#ifdef ISPC_IS_WINDOWS #ifdef ISPC_IS_WINDOWS
return InterlockedAdd(v, delta); return InterlockedAdd((volatile LONG *)v, delta);
#else #else
int32_t origValue; int32_t origValue;
__asm__ __volatile__("lock\n" __asm__ __volatile__("lock\n"