3 from __future__
import absolute_import, division, print_function
8 from functools
import reduce
9 from itertools
import chain
11 from pyHIPIFY
import hipify_python
13 parser = argparse.ArgumentParser(description=
'Top-level script for HIPifying, filling in most common parameters')
15 '--out-of-place-only',
17 help=
"Whether to only run hipify out-of-place on source files")
20 '--project-directory',
23 help=
"The root of the project.",
30 help=
"The Directory to Store the Hipified Project",
37 help=argparse.SUPPRESS)
39 args = parser.parse_args()
41 amd_build_dir = os.path.dirname(os.path.realpath(__file__))
42 proj_dir = os.path.join(os.path.dirname(os.path.dirname(amd_build_dir)))
44 if args.project_directory:
45 proj_dir = args.project_directory
48 if args.output_directory:
49 out_dir = args.output_directory
55 "caffe2/transforms/*",
57 "caffe2/distributed/*",
65 "c10/cuda/test/CMakeLists.txt",
69 "aten/src/ATen/cuda/*",
70 "aten/src/ATen/native/cuda/*",
71 "aten/src/ATen/native/cudnn/*",
72 "aten/src/ATen/native/sparse/cuda/*",
75 "aten/src/ATen/test/*",
78 "aten/src/THC/CMakeLists.txt",
79 "aten/src/THCUNN/CMakeLists.txt",
81 "tools/autograd/templates/python_variable_methods.cpp",
85 "caffe2/operators/depthwise_3x3_conv_op_cudnn.cu",
86 "caffe2/operators/pool_op_cudnn.cu",
89 "aten/src/ATen/core/*",
90 "torch/csrc/autograd/engine.cpp",
92 "torch/lib/tmp_install/*",
96 json_settings = os.path.join(amd_build_dir,
"disabled_features.json")
98 if not args.out_of_place_only:
100 patch_folder = os.path.join(amd_build_dir,
"patches")
101 for filename
in os.listdir(os.path.join(amd_build_dir,
"patches")):
102 subprocess.Popen([
"git",
"apply", os.path.join(patch_folder, filename)], cwd=proj_dir)
107 "csrc/autograd/profiler.h",
108 "csrc/autograd/profiler.cpp",
110 "csrc/autograd/engine.cpp" 112 paths = (
"torch",
"tools")
113 for root, _directories, files
in chain.from_iterable(os.walk(path)
for path
in paths):
114 for filename
in files:
115 if filename.endswith(
".cpp")
or filename.endswith(
".h"):
116 source = os.path.join(root, filename)
118 if reduce(
lambda result, exclude: source.endswith(exclude)
or result, ignore_files,
False):
121 with open(source,
"r+")
as f:
123 contents = contents.replace(
"USE_CUDA",
"USE_ROCM")
124 contents = contents.replace(
"CUDA_VERSION",
"0")
131 hipify_python.hipify(
132 project_directory=proj_dir,
133 output_directory=out_dir,
136 out_of_place_only=args.out_of_place_only,
137 json_settings=json_settings,
138 hip_clang_launch=args.hip_clang_launch)