Stop inserting static casts in Hipify (#14853)
authorJunjie Bai <bai@in.tum.de>
Thu, 6 Dec 2018 21:17:28 +0000 (13:17 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 6 Dec 2018 21:19:33 +0000 (13:19 -0800)
Summary:
Latest hcc can now properly cast to correct type internally, so there is no need to insert static_cast in hipify scripts anymore.
However the hcc included in the latest ROCm release (1.9.2) doesn't have this fix, so leaving a flag to continue doing static_cast for those using the official ROCm releases.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14853

Differential Revision: D13363171

Pulled By: bddppq

fbshipit-source-id: a36476a8511222ff3c933d31788e8a0ffb04f5ca

tools/amd_build/build_amd.py
tools/amd_build/pyHIPIFY/hipify_python.py

index 05cfa67..227ca25 100644 (file)
@@ -14,6 +14,10 @@ parser.add_argument(
     '--out-of-place-only',
     action='store_true',
     help="Whether to only run hipify out-of-place on source files")
+parser.add_argument(
+    '--add-static-casts',
+    action='store_true',
+    help="Whether to automatically add static_casts to kernel arguments.")
 args = parser.parse_args()
 
 amd_build_dir = os.path.dirname(os.path.realpath(__file__))
@@ -51,11 +55,9 @@ ignores = [
     "aten/src/ATen/core/*",
 ]
 
-json_file = ""  # Yeah, don't ask me why the default is ""...
-if not args.out_of_place_only:
-    # List of operators currently disabled (PyTorch only)
-    json_file = os.path.join(amd_build_dir, "disabled_features.json")
+json_settings = os.path.join(amd_build_dir, "disabled_features.json")
 
+if not args.out_of_place_only:
     # Apply patch files in place (PyTorch only)
     patch_folder = os.path.join(amd_build_dir, "patches")
     for filename in os.listdir(os.path.join(amd_build_dir, "patches")):
@@ -88,5 +90,5 @@ hipify_python.hipify(
     includes=includes,
     ignores=ignores,
     out_of_place_only=args.out_of_place_only,
-    json_settings=json_file,
-    add_static_casts_option=True)
+    json_settings=json_settings,
+    add_static_casts_option=args.add_static_casts)
index 9af02ce..dbffceb 100755 (executable)
@@ -250,10 +250,6 @@ def preprocess(
         show_detailed - Show a detailed summary of the transpilation process.
     """
 
-    # Compute the total number of files to be traversed.
-    total_count = len(all_files)
-    finished_count = 0
-
     # Preprocessing statistics.
     stats = {"unsupported_calls": [], "kernel_launches": []}
 
@@ -264,7 +260,6 @@ def preprocess(
             print(
                 filepath, "->",
                 get_hip_file_path(filepath))
-            finished_count += 1
 
     print(bcolors.OKGREEN + "Successfully preprocessed all matching files." + bcolors.ENDC, file=sys.stderr)
 
@@ -833,7 +828,7 @@ class Trie():
                 try:
                     recurse = self._pattern(data[char])
                     alt.append(self.quote(char) + recurse)
-                except:
+                except Exception:
                     cc.append(self.quote(char))
             else:
                 q = 1
@@ -1261,115 +1256,6 @@ def str2bool(v):
         raise argparse.ArgumentTypeError('Boolean value expected.')
 
 
-def main():
-    """Example invocation
-
-    python hipify.py --project-directory /home/myproject/ --extensions cu cuh h cpp --output-directory /home/gains/
-    """
-
-    parser = argparse.ArgumentParser(
-        description="The Python Hipify Script.")
-
-    # required argument: user has to specify it before proceed
-    # this is to avoid accidentally hipify files that are not intended
-    parser.add_argument(
-        '--project-directory',
-        type=str,
-        default=os.getcwd(),
-        help="The root of the project.",
-        required=True)
-
-    parser.add_argument(
-        '--show-detailed',
-        type=str2bool,
-        default=False,
-        help="Show detailed summary of the hipification process.",
-        required=False)
-
-    parser.add_argument(
-        '--extensions',
-        nargs='+',
-        default=[".cu", ".cuh", ".c", ".cpp", ".h", ".in", ".hpp"],
-        help="The extensions for files to run the Hipify script over.",
-        required=False)
-
-    parser.add_argument(
-        '--output-directory',
-        type=str,
-        default="",
-        help="The directory to store the hipified project.",
-        required=False)
-
-    parser.add_argument(
-        '--includes',
-        nargs='+',
-        default=[],
-        help="The patterns of files that should be included.",
-        required=False)
-
-    parser.add_argument(
-        '--json-settings',
-        type=str,
-        default="",
-        help="The json file storing information for disabled functions and modules.",
-        required=False)
-
-    parser.add_argument(
-        '--add-static-casts',
-        type=str2bool,
-        default=False,
-        help="Whether to automatically add static_casts to kernel arguments.",
-        required=False)
-
-    parser.add_argument(
-        '--out-of-place-only',
-        type=str2bool,
-        default=False,
-        help="Whether to only run hipify out-of-place on source files",
-        required=False),
-
-    parser.add_argument(
-        '--ignores',
-        nargs='+',
-        default=[],
-        help="list of patterns to ignore for hipifying")
-
-    parser.add_argument(
-        '--show-progress',
-        type=str2bool,
-        default=True,
-        help="Whether to show the progress bar during the transpilation proecss.",
-        required=False)
-
-    parser.add_argument(
-        '--hip-suffix',
-        type=str,
-        default='cc',
-        help="The suffix for the hipified files",
-        required=False)
-
-    parser.add_argument(
-        '--extensions-to-hip-suffix',
-        type=str,
-        default=('cc', 'cu'),
-        help="Specify the file extensions whose suffix will be changed "
-        + "to the new hip suffix",
-        required=False)
-
-    args = parser.parse_args()
-
-    hipify(
-        project_directory=args.project_directory,
-        show_detailed=args.show_detailed,
-        extensions=args.extensions,
-        output_directory=args.output_directory,
-        includes=args.includes,
-        json_settings=args.json_settings,
-        add_static_casts_option=args.add_static_casts,
-        out_of_place_only=args.out_of_place_only,
-        ignores=args.ignores,
-        show_progress=args.show_progress)
-
 
 def hipify(
     project_directory,
@@ -1517,7 +1403,3 @@ def hipify(
                     output_directory,
                     get_hip_file_path(filepath)),
                 KernelTemplateParams)
-
-
-if __name__ == '__main__':
-    main()