-
Notifications
You must be signed in to change notification settings - Fork 58
[AIROCMLIR-426] rocMLIR - MIOpen layout translation #2298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
518d88f
fc3e55c
ea1b9d1
d27c5d1
ea4fb03
e8a6b67
78b4bde
58d5fba
ceb8c23
013436d
82fc60e
a0631d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,37 @@ def inverse_filter_layouts(filter_layout): | |
| return "".join(map[char] for char in filter_layout) | ||
|
|
||
|
|
||
| # Map rocMLIR-specific layout names to MIOpenDriver layout names (NCHW, NHWC). | ||
| # MIOpenDriver does not accept rocMLIR layout names (e.g. GNC01, NGC01). | ||
| ROCMLIR_TO_MIOPEN_LAYOUT = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could simplify this by first converting 0 -> H and 1 -> W.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, I see we just drop "G", we can do that if it's not a group conv (G=1), if it is, we can't. Are we checking that somewhere?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also input and output have "K" as well, we aren't converting that here? it's probably easier to keep separate dicts for input, filter and output.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we emit an error (or at least a warning) if we are dropping G?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you run nightly reports to see if it runs into any errors or not ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just kicked one https://ml-ci-internal.amd.com/job/MLIR/job/mlir/job/PR-2298/ |
||
| 'GNC01': 'NCHW', | ||
| 'NGC01': 'NCHW', | ||
| 'NC0G1': 'NCHW', | ||
| 'G0NC1': 'NCHW', | ||
| '01NGC': 'NHWC', | ||
| 'N01GC': 'NHWC', | ||
| 'N01GK': 'NHWC', | ||
|
dorde-antic marked this conversation as resolved.
Outdated
|
||
| 'NCHW': 'NCHW', | ||
| 'NHWC': 'NHWC', | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be worth adding a comment (or an assert / A lightweight safeguard: def conv_commandline_to_miopen_layouts(commandline):
...
if result[i] in layout_flags:
layout = result[i + 1]
translated = ROCMLIR_TO_MIOPEN_LAYOUT.get(layout)
if translated is None:
print(f"Warning: unknown rocMLIR layout '{layout}' passed through untranslated")
translated = layout
result[i + 1] = translatedAlternatively, document that |
||
|
|
||
|
|
||
| def conv_commandline_to_miopen_layouts(commandline): | ||
| """Return a copy of commandline with -f, -I, -O layout values translated to MIOpen names.""" | ||
| result = list(commandline) | ||
| for i in range(len(result)): | ||
| if result[i] == '-f' and i + 1 < len(result): | ||
| layout = result[i + 1] | ||
| result[i + 1] = ROCMLIR_TO_MIOPEN_LAYOUT.get(layout, layout) | ||
| elif result[i] == '-I' and i + 1 < len(result): | ||
| layout = result[i + 1] | ||
| result[i + 1] = ROCMLIR_TO_MIOPEN_LAYOUT.get(layout, layout) | ||
| elif result[i] == '-O' and i + 1 < len(result): | ||
| layout = result[i + 1] | ||
| result[i + 1] = ROCMLIR_TO_MIOPEN_LAYOUT.get(layout, layout) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The three def conv_commandline_to_miopen_layouts(commandline):
"""Return a copy of commandline with -f, -I, -O layout values translated to MIOpen names."""
result = list(commandline)
layout_flags = {'-f', '-I', '-O'}
for i in range(len(result) - 1):
if result[i] in layout_flags:
result[i + 1] = ROCMLIR_TO_MIOPEN_LAYOUT.get(result[i + 1], result[i + 1])
return resultAlso note that iterating
dorde-antic marked this conversation as resolved.
Outdated
|
||
| return result | ||
|
Comment on lines
+98
to
+148
|
||
|
|
||
|
|
||
| @dataclass | ||
| class MLIRPaths: | ||
| rocmlir_gen_path: str | ||
|
|
@@ -694,20 +725,24 @@ def benchmark_external(cls, commandline, paths: Paths, arch, num_cu, num_chiplet | |
| if os.path.exists(get_profiler_output_path(arch, BENCHMARKING_METRICS_FILE_NAME)): | ||
| os.remove(get_profiler_output_path(arch, BENCHMARKING_METRICS_FILE_NAME)) | ||
| config = cls.from_command_line(commandline, arch, num_cu, num_chiplets) | ||
| miopen_driver_cmd = [MIOPENDRIVER, *commandline, '-V', '0', '-t', '1'] | ||
| # Configs use rocMLIR layout names; MIOpenDriver expects NCHW/NHWC. | ||
| miopen_commandline = conv_commandline_to_miopen_layouts(commandline) | ||
| miopen_driver_cmd = [MIOPENDRIVER, *miopen_commandline, '-V', '0', '-t', '1'] | ||
| print("Running MIOpen Benchmark: ", ' '.join(commandline)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The print still shows print("Running MIOpen Benchmark: ", ' '.join(miopen_driver_cmd))
dorde-antic marked this conversation as resolved.
Outdated
|
||
| # invoke MIOpenDriver. | ||
| outs, noerr = run_pipeline([miopen_driver_cmd]) | ||
| nanoseconds = np.nan | ||
| if noerr: | ||
| # convert bytes to str | ||
| outs = outs.decode('utf-8') | ||
| # Extract Elapsed time in ms from the output of MIOpenDriver | ||
| # Use regular expression to match the contents between | ||
| # "Elasped: " (note the space at the end) and "ms" | ||
| elapsed_time_in_ms = ELAPSED_TIME_RE.search(outs).group(1) | ||
| nanoseconds = float(elapsed_time_in_ms) * 1.0e6 | ||
|
|
||
| if not noerr: | ||
| err_msg = outs.decode('utf-8') if isinstance(outs, bytes) else str(outs) | ||
| raise RuntimeError("MIOpen benchmark failed. CI must fail on MIOpen errors.\n" | ||
| "Failing command: " + ' '.join(miopen_driver_cmd) + "\n" | ||
| "Error: " + err_msg) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Fixed format: raise RuntimeError("MIOpen benchmark failed. CI must fail on MIOpen errors.
"
"Failing command: " + ' '.join(miopen_driver_cmd) + "
"
"Error: " + err_msg)
Comment on lines
+756
to
+760
|
||
| # convert bytes to str | ||
| outs = outs.decode('utf-8') | ||
| # Extract Elapsed time in ms from the output of MIOpenDriver | ||
| # Use regular expression to match the contents between | ||
| # "Elasped: " (note the space at the end) and "ms" | ||
|
dorde-antic marked this conversation as resolved.
Outdated
|
||
| elapsed_time_in_ms = ELAPSED_TIME_RE.search(outs).group(1) | ||
|
dorde-antic marked this conversation as resolved.
Outdated
|
||
| nanoseconds = float(elapsed_time_in_ms) * 1.0e6 | ||
| return config.table_entry(nanoseconds) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that this is "best effort mapping" and may not result in fair comparison.
Add comment that it is doing "channel first" mapping to NCHW and "channel last" to "NHWC"