Skip to content

Commit

Permalink
Addressing review comments - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
djramic committed Dec 10, 2024
1 parent 588592a commit a478ee0
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions mlir/utils/performance/analysis/quickTuningGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def replace_section(
with open(file_path, 'w') as file:
file.write(content)

def isAccel(self, arch, datatype):
def is_accel(self, arch, datatype):
instruction_type = self.get_instruction_type(arch, datatype)
if instruction_type == "XDL" or instruction_type == "Wmma":
return True
Expand Down Expand Up @@ -97,33 +97,33 @@ def init_inc_file(self, file_path):
file.write("// THIS IS AN AUTOGENERATED FILE.\n")
file.write("// DO NOT EDIT THIS FILE DIRECTLY!\n\n")
file.write("// clang-format off\n")
for instrction_type, datatypes in instruction_types_to_datatypes.items():
file.write(f"#ifdef {instrction_type}_DEFINITIONS_GEN\n\n")
for instruction_type, datatypes in instruction_types_to_datatypes.items():
file.write(f"#ifdef {instruction_type}_DEFINITIONS_GEN\n\n")
for datatype in datatypes:
for marker in markers:
file.write(
f"{marker}_{instrction_type}_{datatype}_DEFS\n\n")
f"{marker}_{instruction_type}_{datatype}_DEFS\n\n")
file.write(f"#endif\n\n")

file.write(f"#ifdef {instrction_type}_DECLARATIONS_GEN\n\n")
file.write(f"#ifdef {instruction_type}_DECLARATIONS_GEN\n\n")
for datatype in datatypes:
for marker in markers:
file.write(
f"{marker}_{instrction_type}_{datatype}_DECS\n\n")
f"{marker}_{instruction_type}_{datatype}_DECS\n\n")
file.write(f"#endif\n\n")

def get_init_params_definitions(self, arch, dtype, op):
"""
Generates initialization parameter definitions for a given data type and operation.
"""
accel_type = 'Accel' if self.isAccel(arch, dtype) else 'NonAccel'
accel_type = 'Accel' if self.is_accel(arch, dtype) else 'NonAccel'
instruction_type = self.get_instruction_type(arch, dtype)
op_cap = op.capitalize()

if dtype == 'f32':
init_params = f"initParameters{op_cap}"
n_init_params = f"nInitParameters{op_cap}"
if not self.isAccel(arch, dtype):
n_init_params = f"nInitParameters{op_cap}"
if not self.is_accel(arch, dtype):
instruction_type = ''
elif dtype == 'f16':
init_params = f"initParametersFp16{op_cap}"
Expand All @@ -141,7 +141,7 @@ def get_init_params_declaration(self, arch, dtype, op):
Generates initialization parameter declarations for a given data type and operation.
"""
op_cap = op.capitalize()
accel_type = 'Accel' if self.isAccel(arch, dtype) else 'NonAccel'
accel_type = 'Accel' if self.is_accel(arch, dtype) else 'NonAccel'

if dtype == 'f32':
init_params = f"initParameters{op_cap}"
Expand Down Expand Up @@ -238,7 +238,7 @@ def get_unique_perfconfigs_list(self, problems_to_perfconfigs):

def get_top_n_perfconfigs_per_problems(self, df, targetColumns):
"""
Identifies the top perfcofnigs for each problem based on a threshold
Identifies the top perfconfigs for each problem based on a threshold
"""
grouped = df.groupby(targetColumns)
problem_df = {}
Expand All @@ -253,7 +253,7 @@ def find(self):
"""
Finds the minimal set of perfconfigs that cover all
problems using set cover optimizaiton.
Returns : A dictionary containing data types as keys and thier
Returns : A dictionary containing data types as keys and their
corresponding selected perfconfigs.
"""
result = {}
Expand Down Expand Up @@ -291,26 +291,20 @@ def find(self):

n = len(problems)
m = len(perfconfigs)
problem_to_index = {
problem: idx for idx,
problem in enumerate(problems)}
perfconfig_to_index = {
perfconfig: idx for idx,
perfconfig in enumerate(perfconfigs)}

# Create coverage matrix
A = np.zeros((n, m), dtype=int)
for problem, perfconfig_list in problems_to_perfconfigs.items():
i = problem_to_index[problem]
for perfconfig in perfconfig_list:
j = perfconfig_to_index[perfconfig]
for i, (problem, perfconfig_list) in enumerate(problems_to_perfconfigs.items()):
for j, perfconfig in enumerate(perfconfig_list):
A[i][j] = 1

# Linear programming model to minimize the number of perfconfigs
prob = pulp.LpProblem("SetCoverProblems", pulp.LpMinimize)
x = pulp.LpVariable.dicts("x", range(m), cat='Binary')
# Set up objective function to minimize the sum of selected perfconfigs
prob += pulp.lpSum([x[j]] for j in range(m))
for i in range(n):
# Add a constraint for each problem ensuring at least one perfconfig is selected
prob += pulp.lpSum([A[i][j] * x[j]
for j in range(m)]) >= 1, f"Cover_problem_{i}"

Expand Down

0 comments on commit a478ee0

Please sign in to comment.