Skip to content

Commit f170b3e

Browse files
authored
Refactor splitConfigFile to use sed-based slicing (#1870)
1 parent ec1cdfe commit f170b3e

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

mlir/utils/jenkins/Jenkinsfile

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ void preMergeCheckPackage(String codepath) {
227227

228228
void splitConfigFile(String inputFilePath, String outputFilePath, int run, int totalSplits = 5) {
229229
sh """
230-
totalLines=\$(grep -cv "^#" ${inputFilePath})
231-
linesPerSplit=\$(((totalLines + ${totalSplits} - 1) / ${totalSplits}))
232-
startLine=\$(((${run} - 1) * linesPerSplit + 1))
233-
endLine=\$((${run} * linesPerSplit))
234-
235-
awk 'BEGIN{count=0} !/^#/ {count++} {if (!/^#/ && count >= '\"\${startLine}\"' && count <= '\"\${endLine}\"') print' ${inputFilePath} > ${outputFilePath}}
230+
lines=\$(grep -Ev '(^\\s*\$|^\\s*#)' ${inputFilePath} | wc -l)
231+
lines_per_chunk=\$(((lines + ${totalSplits} - 1) / ${totalSplits}))
232+
start_line=\$((lines_per_chunk * (${run} - 1) + 1))
233+
end_line=\$((lines_per_chunk * ${run}))
234+
235+
grep -Ev '(^\\s*\$|^\\s*#)' ${inputFilePath} | sed -n "\${start_line},\${end_line}p" | tee ${outputFilePath}
236236
"""
237237
}
238238

@@ -1210,17 +1210,14 @@ pipeline {
12101210
"HOME=${env.WORKSPACE}"
12111211
]) {
12121212
dir('build') {
1213+
def convInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-conv-configs"
1214+
def convToUse = "${WORKSPACE}/build/tier1-conv-configs"
1215+
def gemmInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-gemm-configs"
1216+
def gemmToUse = "${WORKSPACE}/build/tier1-gemm-configs"
12131217
script {
1214-
def convInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-conv-configs"
1215-
def convToUse = convInput
12161218
if (params.nightly) {
12171219
def runIndex = ((env.BUILD_NUMBER as int) - 1) % 5 + 1
12181220
splitConfigFile(convInput, convToUse, runIndex)
1219-
}
1220-
def gemmInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-gemm-configs"
1221-
def gemmToUse = gemmInput
1222-
if (params.nightly) {
1223-
def runIndex = ((env.BUILD_NUMBER as int) - 1) % 5 + 1
12241221
splitConfigFile(gemmInput, gemmToUse, runIndex)
12251222
}
12261223
}
@@ -1290,9 +1287,9 @@ pipeline {
12901287
"HOME=${env.WORKSPACE}"
12911288
]) {
12921289
dir('build') {
1290+
def attnInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-attention-configs"
1291+
def attnToUse = "${WORKSPACE}/build/tier1-attention-configs"
12931292
script {
1294-
def attnInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-attention-configs"
1295-
def attnToUse = attnInput
12961293
if (params.nightly) {
12971294
def runIndex = ((env.BUILD_NUMBER as int) - 1) % 5 + 1
12981295
splitConfigFile(attnInput, attnToUse, runIndex)
@@ -1352,9 +1349,9 @@ pipeline {
13521349

13531350

13541351
dir('build') {
1352+
def gemmInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-gemm-configs"
1353+
def gemmToUse = "${WORKSPACE}/build/tier1-gemm-configs"
13551354
script {
1356-
def gemmInput = "${WORKSPACE}/mlir/utils/performance/configs/tier1-gemm-configs"
1357-
def gemmToUse = gemmInput
13581355
if (params.nightly) {
13591356
def runIndex = ((env.BUILD_NUMBER as int) - 1) % 5 + 1
13601357
splitConfigFile(gemmInput, gemmToUse, runIndex)

mlir/utils/performance/parameterSweeps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def main() -> bool:
449449
help="The build directory of MLIR based kernel generator",
450450
)
451451
args = parser.parse_args()
452-
arch = ','.join(getArch())
452+
arch = getArch()
453453
supported_codepath = ['mfma', 'vanilla', 'wmma']
454454
# If codepath not provided or not supported, infer it from the arch
455455
codepath = args.codepath

mlir/utils/performance/perfRunner.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,20 @@ def getNanoSeconds(fileName):
151151
return np.nan
152152
with open(fileName, 'r') as csv_file:
153153
reader = csv.DictReader(csv_file, delimiter = ',')
154-
155154
result = 0
156155
for row in reader:
157156
result += int(float(row['AverageNs']))
158157
csv_file.close()
159158
return result
160159

161-
def getProfilerOutputPath(arch, baseOutPath):
160+
def getProfilerOutputPath(arch: str, baseOutPath):
162161
chip = GFX_CHIP_RE.search(arch).group(0)
163162
# TODO (gfx950): check if gfx950 need this
164163
if(chip not in ["gfx942"]):
165164
return os.path.join('pmc_1', baseOutPath)
166165
return baseOutPath
167166

168-
def getMetricArgsForRocprof(arch):
167+
def getMetricArgsForRocprof(arch: str):
169168
chip = GFX_CHIP_RE.search(arch).group(0)
170169
current_dir = os.path.dirname(os.path.abspath(__file__))
171170
metrics_path = os.path.join(current_dir, ROCMLIR_INPUT_METRICS_FILE_NAME)
@@ -1750,16 +1749,19 @@ def hip_check(call_result):
17501749
raise RuntimeError(str(err))
17511750
return result
17521751

1753-
def getArch():
1752+
def getArch() -> str:
17541753
agents = set()
17551754
device_count = hip_check(hip.hipGetDeviceCount())
17561755
for device in range(device_count):
17571756
props = hip.hipDeviceProp_t()
17581757
hip_check(hip.hipGetDeviceProperties(props,device))
17591758
agent = props.gcnArchName.decode('utf-8')
17601759
agents.add(agent)
1761-
1762-
return agents
1760+
if(len(agents) > 1):
1761+
print(f"WARNING: Found {len(agents)} different kinds of agents on the same machine : {', '.join(agents)}")
1762+
print("WARNING: Using the first agent by default. If you want to use a different agent, please set the HIP_VISIBLE_DEVICES environment variable.")
1763+
# select first agent by default
1764+
return list(agents)[0]
17631765

17641766
def parseDataTypes(data_types):
17651767
if not data_types:
@@ -1779,8 +1781,7 @@ def parseDataTypes(data_types):
17791781
return datatypes, outMap
17801782

17811783
def getChip():
1782-
archNames = getArch()
1783-
arch = ','.join(archNames)
1784+
arch = getArch()
17841785
chip = GFX_CHIP_RE.search(arch).group(0)
17851786
return chip
17861787

@@ -1838,9 +1839,8 @@ def main(args=None):
18381839
if args is None:
18391840
args = sys.argv[1:]
18401841

1841-
archNames = getArch()
1842-
arch = ','.join(archNames)
1843-
chip = GFX_CHIP_RE.search(arch).group(0)
1842+
arch = getArch()
1843+
chip = getChip()
18441844
numCU = getNumCU(chip)
18451845

18461846
root_dir = str(subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode().strip())

mlir/utils/performance/tuningRunner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ def main(args=None):
240240
if args is None:
241241
args = sys.argv[1:]
242242

243-
archNames = perfRunner.getArch()
244-
arch = ','.join(archNames)
243+
arch = perfRunner.getArch()
245244
numCU = perfRunner.getNumCU(perfRunner.getChip())
246245
root_dir = str(subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode().strip())
247246
default_conv_configs = root_dir + '/mlir/utils/jenkins/performance/configs/tier1-conv-configs'

0 commit comments

Comments
 (0)