@@ -21,39 +21,43 @@ def build(path):
21
21
return stderr
22
22
return None
23
23
24
- def parse (output ):
24
+ def parseTotal (output , countString = None ):
25
25
lines = output .split ("\n " )
26
26
total_count = 0
27
27
for line in lines :
28
28
if line .find ("[INFO]" ) != - 1 :
29
29
continue
30
30
if line .find ("[" ) != 0 :
31
31
continue
32
+ if countString != None and countString not in line :
33
+ continue
32
34
items = line .split ("]" )
33
35
if len (items ) == 2 :
34
36
if items [0 ].strip () and items [1 ].strip ():
35
37
count = int (items [0 ].lstrip ("[" ).strip ())
36
38
if count < 0 :
37
39
return False
38
40
total_count += count
39
- if total_count <= 0 :
40
- return False
41
- return True
41
+ return total_count
42
42
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 ):
44
47
if option == "cl" :
45
48
app_folder = utils .get_sample_executable_path ("cl_gemm" )
46
49
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 } " ]
48
51
elif option == "ze" :
49
52
app_folder = utils .get_sample_executable_path ("ze_gemm" )
50
53
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 } " ]
52
55
else :
53
56
app_folder = utils .get_sample_executable_path ("dpc_gemm" )
54
57
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 ):
57
61
if not stdout :
58
62
return "stdout is empty"
59
63
if not stderr :
@@ -66,6 +70,42 @@ def run(path, option):
66
70
return stderr
67
71
return None
68
72
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
+
69
109
def main (option ):
70
110
path = utils .get_sample_build_path ("gpu_inst_count" )
71
111
if option == "cl" :
0 commit comments