-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add pyHIPIFY scripts needed for ROCm transpilation to PyTorch #8812
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
Conversation
Bring our fork up to date.
Merge from upstream master into our fork.
sync w/ upstream
add pyHIPIFY to PyTorch repo
bddppq
left a comment
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.
Thanks for merging these python scripts into pytorch repo.
The CI failure is python code lint check, you can use autopep8 to automatically make them conforming the style requirements.
| #!/usr/bin/python | ||
| """ The Python Hipify script. | ||
| ## | ||
| # Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
the script is failing lint |
| "--output-directory", proj_dir, | ||
| "--include-dirs"] + include_dirs + ["--yaml-settings", yaml_file, "--add-static-casts", "True"] | ||
| os.execv("/opt/rocm/bin/hipify-python.py", ['python'] + args) | ||
| os.execv(os.path.join(amd_build_dir, "pyHIPIFY", "hipify-python.py"), ['python'] + args) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| @@ -0,0 +1,47 @@ | |||
| CONV_VERSION = 0, | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| @@ -0,0 +1,2097 @@ | |||
| from constants import * | |||
|
|
|||
| CUDA_TYPE_NAME_MAP = { | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| "CU_RES_VIEW_FORMAT_FLOAT_2X16": ("hipResViewFormatHalf2", CONV_TEX,API_DRIVER), | ||
| "CU_RES_VIEW_FORMAT_FLOAT_4X16": ("hipResViewFormatHalf4", CONV_TEX,API_DRIVER), | ||
| "CU_RES_VIEW_FORMAT_FLOAT_1X32": ("hipResViewFormatFloat1", CONV_TEX,API_DRIVER), | ||
| "CU_RES_VIEW_FORMAT_FLOAT_2X32": ("hipResVi |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| # Update the progress | ||
| print(os.path.join(dirpath, filename)) | ||
| update_progress_bar(total_files, current_file) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| def openf(filename, mode): | ||
| if sys.version_info[0] == 3: | ||
| return open(filename, mode, errors='ignore') |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| status) | ||
|
|
||
| # Send the progress to stdout. | ||
| sys.stdout.write(text) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| def filename_ends_with_extension(filename, extensions): | ||
| """Helper method to see if filename ends with certain extension""" | ||
| return reduce(lambda result, ext: filename.endswith("." + ext) or result, extensions, False) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| def processKernelLaunches(string, stats): | ||
| """ Replace the CUDA style Kernel launches with the HIP style kernel launches.""" | ||
| # Concat the namespace with the kernel names. (Find cleaner way of doing this later). | ||
| string = re.sub(r'([ ]+)(detail+)::[ ]+\\\n[ ]+', lambda inp: "%s%s::" % (inp.group(1), inp.group(2)), string) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| return output_string | ||
|
|
||
|
|
||
| def find_paranthesis_end(input_string, start): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Address even more comments
Fix static_cast logic in hipify script for better coverage
Add enum34 as a requirement for backwards compatibility.
Merge from upstream
Merge from upstream
Use generator directly in loop as by review
String inputs should have meta characters escaped prior to using them with regular expressions.
This reverts commit 4158af1.
The inputs into the regular expressions must have their meta characters escaped or unexpected replacements may occur.
This reverts commit cf2c228.
This reverts commit 08043e3.
facebook-github-bot
left a comment
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.
@bddppq has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This PR contains the ROCm contributions of last week: * documentation of pyHIPIFY data format originating from #8812 reviewing comments by ezyang * removal of most patch files from the `amd_build` directory and integration into the code base * enabling of previously disabled_features that do compile now * improvement to the static_cast feature in pyHIPIFY (it will only apply static_cast to kernel arguments, not launch arguments) * addition of two workarounds to pyHIPIFY for ROCm/HIP shortcomings: a) `__forceinline__` does not imply `static`, hence change to `__inline__`, b) `std::[exp,log,pow]` math functions cannot be selected in device code, use `::[exp,log,pow]` instead. Both of these workarounds will be removed once the issues are fixed upstream. Neither of these issues have surfaced on the CI but were reproduced internally. Pull Request resolved: #9432 Differential Revision: D8887441 Pulled By: ezyang fbshipit-source-id: 71cf5c6b13772a66d10be369a45ebf06e4e268e1
Summary: This PR contains the ROCm contributions of last week: * documentation of pyHIPIFY data format originating from pytorch#8812 reviewing comments by ezyang * removal of most patch files from the `amd_build` directory and integration into the code base * enabling of previously disabled_features that do compile now * improvement to the static_cast feature in pyHIPIFY (it will only apply static_cast to kernel arguments, not launch arguments) * addition of two workarounds to pyHIPIFY for ROCm/HIP shortcomings: a) `__forceinline__` does not imply `static`, hence change to `__inline__`, b) `std::[exp,log,pow]` math functions cannot be selected in device code, use `::[exp,log,pow]` instead. Both of these workarounds will be removed once the issues are fixed upstream. Neither of these issues have surfaced on the CI but were reproduced internally. Pull Request resolved: pytorch#9432 Differential Revision: D8887441 Pulled By: ezyang fbshipit-source-id: 71cf5c6b13772a66d10be369a45ebf06e4e268e1
…h#8812) Summary: As discussed in call, this will allow us to keep this integral part of the effort to run PyTorch on ROCm in sync with the main code. Pull Request resolved: pytorch#8812 Reviewed By: ezyang Differential Revision: D8796245 Pulled By: bddppq fbshipit-source-id: 8e12c2acf6a7e0740f31b21e50be74e10ed8b12c
Summary: This PR contains the ROCm contributions of last week: * documentation of pyHIPIFY data format originating from pytorch#8812 reviewing comments by ezyang * removal of most patch files from the `amd_build` directory and integration into the code base * enabling of previously disabled_features that do compile now * improvement to the static_cast feature in pyHIPIFY (it will only apply static_cast to kernel arguments, not launch arguments) * addition of two workarounds to pyHIPIFY for ROCm/HIP shortcomings: a) `__forceinline__` does not imply `static`, hence change to `__inline__`, b) `std::[exp,log,pow]` math functions cannot be selected in device code, use `::[exp,log,pow]` instead. Both of these workarounds will be removed once the issues are fixed upstream. Neither of these issues have surfaced on the CI but were reproduced internally. Pull Request resolved: pytorch#9432 Differential Revision: D8887441 Pulled By: ezyang fbshipit-source-id: 71cf5c6b13772a66d10be369a45ebf06e4e268e1
As discussed in call, this will allow us to keep this integral part of the effort to run PyTorch on ROCm in sync with the main code.