Skip to content

Commit 4d4cd03

Browse files
committed
init source code
0 parents  commit 4d4cd03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+85298
-0
lines changed

ISA_parser/__init__.py

Whitespace-only changes.

ISA_parser/ptx_parser.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
##############################################################################
2+
# &copy 2017. Triad National Security, LLC. All rights reserved.
3+
4+
# This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration.
5+
6+
# All rights in the program are reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
7+
8+
# Recall that this copyright notice must be accompanied by the appropriate open source license terms and conditions. Additionally, it is prudent to include a statement of which license is being used with the copyright notice. For example, the text below could also be included in the copyright notice file: This is open source software; you can redistribute it and/or modify it under the terms of the Performance Prediction Toolkit (PPT) License. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL. Full text of the Performance Prediction Toolkit (PPT) License can be found in the License file in the main development branch of the repository.
9+
##############################################################################
10+
11+
# Author: Yehia Arafa
12+
# Last Update Date: April, 2021
13+
# Copyright: Open source, must acknowledge original author
14+
15+
##############################################################################
16+
17+
18+
def parse(units_latency, ptx_instructions, ptx_path, num_warps):
19+
20+
ptx_trace = open(ptx_path,'r').read().strip().split('\n')
21+
# task_list = [[]] * num_warps
22+
task_list = []
23+
count_gmem_reqs = 0
24+
25+
for inst in ptx_trace:
26+
inst_list = []
27+
28+
splitted_inst = inst.split(" ")
29+
current_inst = splitted_inst[0]
30+
opcodeAndOption = current_inst.split(".")
31+
opcode = opcodeAndOption[0]
32+
opcodeAndOption.pop(0)
33+
34+
#(1) add the inst HW unit and latency to the current instruction list
35+
if "ld" in opcode:
36+
if "global" in opcodeAndOption:
37+
inst_list.append("GLOB_MEM_ACCESS")
38+
inst_list.append("LD")
39+
count_gmem_reqs += 1
40+
elif "local" in opcodeAndOption:
41+
inst_list.append("LOCAL_MEM_ACCESS")
42+
inst_list.append("LD")
43+
elif "shared" in opcodeAndOption:
44+
inst_list.append("SHARED_MEM_ACCESS")
45+
inst_list.append("LD")
46+
elif "const" in opcodeAndOption:
47+
inst_list.append("CONST_MEM_ACCESS")
48+
inst_list.append("LD")
49+
elif "param" in opcodeAndOption:
50+
inst_list.append("CONST_MEM_ACCESS")
51+
inst_list.append("LD")
52+
else:
53+
print("\n[Warning]\n"+"\"memory unit in: "+current_inst+" is not defined, adding GLOB_MEM_ACCESS")
54+
inst_list.append("GLOB_MEM_ACCESS")
55+
inst_list.append("LD")
56+
elif "st" in opcode:
57+
if "global" in opcodeAndOption:
58+
inst_list.append("GLOB_MEM_ACCESS")
59+
inst_list.append("ST")
60+
count_gmem_reqs += 1
61+
elif "local" in opcodeAndOption:
62+
inst_list.append("LOCAL_MEM_ACCESS")
63+
inst_list.append("ST")
64+
elif "shared" in opcodeAndOption:
65+
inst_list.append("SHARED_MEM_ACCESS")
66+
inst_list.append("ST")
67+
elif "const" in opcodeAndOption:
68+
inst_list.append("CONST_MEM_ACCESS")
69+
inst_list.append("ST")
70+
elif "param" in opcodeAndOption:
71+
inst_list.append("CONST_MEM_ACCESS")
72+
inst_list.append("ST")
73+
else:
74+
print("\n[Warning]\n"+"\"memory unit in: "+current_inst+" is not defined, adding GLOB_MEM_ACCESS")
75+
inst_list.append("GLOB_MEM_ACCESS")
76+
inst_list.append("ST")
77+
elif "atom" in opcode or "red" in opcode:
78+
inst_list.append("ATOMIC_OP")
79+
inst_list.append("")
80+
elif "barrier" in opcode:
81+
inst_list.append("BarrierSYNC")
82+
else:
83+
try:
84+
if opcode == "mov" or opcode == "shfl" or opcode == "prmt" or opcode == "cvta" or opcode == "cvt"\
85+
or opcode == "set" or opcode == "setp" or opcode == "selp" or opcode == "bra" or opcode == "call"\
86+
or opcode == "ret" or opcode == "exit" or opcode == "bar":
87+
pass
88+
else:
89+
if "f" in opcodeAndOption[-1]:
90+
if "64" in opcodeAndOption[-1]:
91+
if opcode == "div" and opcodeAndOption[-2] == "approx":
92+
opcode = "Fastddiv"
93+
else:
94+
opcode = "d" + opcode
95+
elif "16" in opcodeAndOption[-1]:
96+
opcode = "h" + opcode
97+
else:
98+
opcode = "f" + opcode
99+
if opcode == "rcp" or opcode == "sqrt" or opcode == "rsqrt" and opcodeAndOption[-2] == "approx":
100+
opcode = "Fast" + opcode
101+
else:
102+
if "sub.cc" in current_inst:
103+
opcode = "sub.cc"
104+
elif "mad.cc" in current_inst:
105+
opcode = "mad.cc"
106+
107+
unit = ptx_instructions[opcode]
108+
if type(unit) != list:
109+
currentUnit = unit
110+
latency = units_latency[unit]
111+
else:
112+
currentUnit = unit[0]
113+
latency = unit[1]
114+
115+
except:
116+
print("\n[Error]\n"+"\""+current_inst+"\""+" is not available in PTX instructions table")
117+
exit(0)
118+
119+
# add the instruction HW unit to the tasklist
120+
inst_list.append(currentUnit)
121+
122+
# add the instruction latency to the tasklist
123+
inst_list.append(latency)
124+
125+
126+
#(2) add instruction dependencies to the current instruction list
127+
splitted_inst.pop(0)
128+
for dependency in splitted_inst:
129+
if dependency:
130+
inst_list.append(int(dependency))
131+
132+
133+
#(3) commit the current instruction list to the tasklist
134+
task_list.append(inst_list)
135+
136+
return task_list, count_gmem_reqs

ISA_parser/sass_parser.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
##############################################################################
2+
# &copy 2017. Triad National Security, LLC. All rights reserved.
3+
4+
# This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration.
5+
6+
# All rights in the program are reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
7+
8+
# Recall that this copyright notice must be accompanied by the appropriate open source license terms and conditions. Additionally, it is prudent to include a statement of which license is being used with the copyright notice. For example, the text below could also be included in the copyright notice file: This is open source software; you can redistribute it and/or modify it under the terms of the Performance Prediction Toolkit (PPT) License. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL. Full text of the Performance Prediction Toolkit (PPT) License can be found in the License file in the main development branch of the repository.
9+
##############################################################################
10+
11+
# Author: Yehia Arafa
12+
# Last Update Date: April, 2021
13+
# Copyright: Open source, must acknowledge original author
14+
15+
##############################################################################
16+
17+
18+
def parse(units_latency, sass_instructions, sass_path, num_warps):
19+
20+
sass_trace = open(sass_path,'r').read().strip().split('\n')
21+
task_list = {}
22+
depenedency_map = {}
23+
warp_inst_count = {}
24+
count_gmem_reqs = 0
25+
26+
for inst in sass_trace:
27+
inst_list = []
28+
29+
splitted_inst = inst.split(" ")
30+
warp_id = int(splitted_inst[0])
31+
current_inst = splitted_inst[1]
32+
opcodeAndOption = current_inst.split(".")
33+
opcode = opcodeAndOption[0]
34+
opcodeAndOption.pop(0)
35+
36+
isOpcodeST = False
37+
if warp_id in warp_inst_count:
38+
warp_inst_count[warp_id] += 1
39+
else:
40+
warp_inst_count[warp_id] = 0
41+
42+
#(1) type of inst
43+
if "LDG" in opcode:
44+
inst_list.append("GLOB_MEM_ACCESS")
45+
inst_list.append("LD")
46+
count_gmem_reqs += 1
47+
elif "STG" in opcode:
48+
isOpcodeST = True
49+
inst_list.append("GLOB_MEM_ACCESS")
50+
inst_list.append("ST")
51+
count_gmem_reqs += 1
52+
elif "LDL" in opcode:
53+
inst_list.append("LOCAL_MEM_ACCESS")
54+
inst_list.append("LD")
55+
elif "STL" in opcode:
56+
isOpcodeST = True
57+
inst_list.append("LOCAL_MEM_ACCESS")
58+
inst_list.append("ST")
59+
elif "LDS" in opcode:
60+
inst_list.append("SHARED_MEM_ACCESS")
61+
inst_list.append("LD")
62+
elif "STS" in opcode:
63+
isOpcodeST = True
64+
inst_list.append("SHARED_MEM_ACCESS")
65+
inst_list.append("ST")
66+
elif "LDC" in opcode:
67+
inst_list.append("CONST_MEM_ACCESS")
68+
inst_list.append("LD")
69+
elif "STC" in opcode:
70+
isOpcodeST = True
71+
inst_list.append("CONST_MEM_ACCESS")
72+
inst_list.append("ST")
73+
elif "ATOM" in opcode or "RED" in opcode:
74+
inst_list.append("ATOMIC_OP")
75+
inst_list.append("") #for now just put an empty holder; need to be changed to the type of atomic operation later
76+
elif "BAR" in opcode:
77+
inst_list.append("BarrierSYNC")
78+
elif "MEMBAR" in opcode:
79+
inst_list.append("MEMBAR")
80+
else:
81+
try:
82+
if "MUFU" in opcode:
83+
unit = "SFU"
84+
if "64" in opcodeAndOption:
85+
unit_64 = "dSFU"
86+
latency = units_latency[unit_64]
87+
else:
88+
latency = units_latency[unit]
89+
else:
90+
unit = sass_instructions[opcode]
91+
latency = units_latency[unit]
92+
except:
93+
print("\n[Error]\n"+"\""+current_inst+"\""+" is not available in SASS instructions table")
94+
exit(0)
95+
96+
# add the instruction HW unit to the warp tasklist
97+
inst_list.append(unit)
98+
# add the instruction latency to the warp tasklist
99+
inst_list.append(latency)
100+
101+
102+
#(2) add current instruction dependencies
103+
destination = None
104+
if warp_id not in depenedency_map:
105+
depenedency_map[warp_id] = {}
106+
107+
for i in range(2, len(splitted_inst)):
108+
if i == 2 and not isOpcodeST:
109+
destination = splitted_inst[i]
110+
else:
111+
source = splitted_inst[i]
112+
if source in depenedency_map[warp_id]:
113+
inst_list.append(depenedency_map[warp_id][source])
114+
115+
116+
if destination is not None:
117+
depenedency_map[warp_id][destination] = warp_inst_count[warp_id]
118+
119+
120+
121+
#(3) commit the instruction list to the tasklist
122+
if warp_id not in task_list:
123+
task_list[warp_id] = []
124+
task_list[warp_id].append(inst_list)
125+
126+
return task_list, count_gmem_reqs

0 commit comments

Comments
 (0)