Skip to content

Commit 4b7f02c

Browse files
authored
Correctness check for GPU Instruction Count sample (#16)
* Check correctness for gpu_inst_count tool
1 parent dfb005f commit 4b7f02c

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.49.17
1+
0.49.18

tests/samples/gpu_inst_count.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,43 @@ def build(path):
2121
return stderr
2222
return None
2323

24-
def parse(output):
24+
def parseTotal(output, countString=None):
2525
lines = output.split("\n")
2626
total_count = 0
2727
for line in lines:
2828
if line.find("[INFO]") != -1:
2929
continue
3030
if line.find("[") != 0:
3131
continue
32+
if countString != None and countString not in line:
33+
continue
3234
items = line.split("]")
3335
if len(items) == 2:
3436
if items[0].strip() and items[1].strip():
3537
count = int(items[0].lstrip("[").strip())
3638
if count < 0:
3739
return False
3840
total_count += count
39-
if total_count <= 0:
40-
return False
41-
return True
41+
return total_count
4242

43-
def run(path, option):
43+
def parse(output):
44+
return False if parseTotal(output) <= 0 else True
45+
46+
def getTestAppCommand(option, matrixSize, iterations):
4447
if option == "cl":
4548
app_folder = utils.get_sample_executable_path("cl_gemm")
4649
app_file = os.path.join(app_folder, "cl_gemm")
47-
command = ["./gpu_inst_count", app_file, "gpu", "1024", "1"]
50+
return ["./gpu_inst_count", app_file, "gpu", f"{matrixSize}", f"{iterations}"]
4851
elif option == "ze":
4952
app_folder = utils.get_sample_executable_path("ze_gemm")
5053
app_file = os.path.join(app_folder, "ze_gemm")
51-
command = ["./gpu_inst_count", app_file, "1024", "1"]
54+
return ["./gpu_inst_count", app_file, f"{matrixSize}", f"{iterations}"]
5255
else:
5356
app_folder = utils.get_sample_executable_path("dpc_gemm")
5457
app_file = os.path.join(app_folder, "dpc_gemm")
55-
command = ["./gpu_inst_count", app_file, "gpu", "1024", "1"]
56-
stdout, stderr = utils.run_process(command, path)
58+
return ["./gpu_inst_count", app_file, "gpu", f"{matrixSize}", f"{iterations}"]
59+
60+
def isValidOutput(stdout, stderr):
5761
if not stdout:
5862
return "stdout is empty"
5963
if not stderr:
@@ -66,6 +70,42 @@ def run(path, option):
6670
return stderr
6771
return None
6872

73+
def run(path, option):
74+
# Smoke test
75+
command = getTestAppCommand(option, 1024, 1)
76+
stdout, stderr = utils.run_process(command, path)
77+
res = isValidOutput(stdout, stderr)
78+
if res != None: return res
79+
80+
# Correctness test
81+
# Test is based on relative results of instruction count. Test appplicaiton
82+
# has N^3 complexity. Correctness based on number of executed multiply instructions
83+
# for matrix sizes {1, 2, 4} is checked as: (-12*r1-r2+r4)/44==(4*r1-r2)/-4:)
84+
85+
baseSize = 128
86+
command = getTestAppCommand(option, baseSize * 1, 1)
87+
stdout, stderr = utils.run_process(command, path)
88+
res = isValidOutput(stdout, stderr)
89+
if res != None: return res
90+
r1 = parseTotal(stderr, 'mad')
91+
92+
command = getTestAppCommand(option, baseSize * 2, 1)
93+
stdout, stderr = utils.run_process(command, path)
94+
res = isValidOutput(stdout, stderr)
95+
if res != None: return res
96+
r2 = parseTotal(stderr, 'mad')
97+
98+
command = getTestAppCommand(option, baseSize * 4, 1)
99+
stdout, stderr = utils.run_process(command, path)
100+
res = isValidOutput(stdout, stderr)
101+
if res != None: return res
102+
r4 = parseTotal(stderr, 'mad')
103+
104+
if (-12*r1 -r2 +r4)/44 != (4*r1 - r2)/-4:
105+
return f"Correctness check failed: {r1 * 8} != {r2}"
106+
107+
return None
108+
69109
def main(option):
70110
path = utils.get_sample_build_path("gpu_inst_count")
71111
if option == "cl":

0 commit comments

Comments
 (0)