source = os.path.join(root, filename) # Disabled files if reduce( lambda result, exclude: source.endswith(exclude) or result, ignore_files, False): continue # Update contents. with open(source, "r+") as f: contents = f.read() contents = contents.replace("USE_CUDA", "USE_ROCM") contents = contents.replace("CUDA_VERSION", "0") f.seek(0) f.write(contents) f.truncate() f.flush() os.fsync(f) hipify_python.hipify(project_directory=proj_dir, output_directory=proj_dir, includes=includes, ignores=ignores, out_of_place_only=args.out_of_place_only, json_settings=json_settings, add_static_casts_option=args.add_static_casts) # Apply patch files in place post-transform patch_folder = os.path.join(amd_build_dir, "postpatch") for filename in os.listdir(os.path.join(amd_build_dir, "postpatch")): subprocess.Popen( ["git", "apply", os.path.join(patch_folder, filename)], cwd=proj_dir)
"caffe2/operators/*", "caffe2/sgd/*", "caffe2/image/*", "caffe2/transforms/*", "caffe2/video/*", "caffe2/distributed/*", "caffe2/queue/*", "binaries/*", "caffe2/**/*_test*", "caffe2/core/*", "caffe2/db/*", "caffe2/utils/*", "c10/cuda/*", ] ignores = [ "caffe2/operators/depthwise_3x3_conv_op_cudnn.cu", "caffe2/operators/pool_op_cudnn.cu", '**/hip/**', ] file_extensions = ['.cc', '.cu', '.h', '.cuh', '.in'] hipify_python.hipify(project_directory=proj_dir, output_directory=proj_dir, includes=includes, extensions=file_extensions, ignores=ignores, hipify_caffe2=True, add_static_casts_option=True)
args = parser.parse_args() amd_build_dir = os.path.dirname(os.path.realpath(__file__)) proj_dir = os.path.join(os.path.dirname(os.path.dirname(amd_build_dir))) if args.project_directory: proj_dir = args.project_directory out_dir = proj_dir if args.output_directory: out_dir = args.output_directory includes = [ "gloo/*cuda*", "gloo/allreduce_builder.h", "gloo/allreduce_builder.cc", "gloo/broadcast_builder.h", "gloo/broadcast_builder.cc" ] ignores = [ ] hipify_python.hipify( project_directory=proj_dir, output_directory=out_dir, includes=includes, ignores=ignores, list_files_only=args.list_files_only, show_progress=False)
"caffe2/operators/depthwise_3x3_conv_op.cu", "caffe2/operators/depthwise_3x3_conv_op_cudnn.cu", "caffe2/operators/top_k.cu", "caffe2/operators/top_k_radix_selection.cuh", "caffe2/operators/top_k_heap_selection.cuh", "caffe2/operators/pool_op_cudnn.cu", '**/hip/**', ] file_extensions = ['.cc', '.cu', '.h', '.cuh'] parser = argparse.ArgumentParser(description="The Script to Hipify Caffe2") parser.add_argument('--hip-suffix', type=str, default='cc', help="The suffix for the hipified files", required=False) args = parser.parse_args() hipify_python.hipify(project_directory=proj_dir, output_directory=proj_dir, includes=includes, extensions=file_extensions, ignores=ignores, hipify_caffe2=True, add_static_casts_option=True, hip_suffix=args.hip_suffix, extensions_to_hip_suffix=['.cc', '.cu'])
ignore_files = [ "csrc/autograd/profiler.h", "csrc/autograd/profiler.cpp", "csrc/cuda/cuda_check.h" ] for root, _directories, files in os.walk(os.path.join(proj_dir, "torch")): for filename in files: if filename.endswith(".cpp") or filename.endswith(".h"): source = os.path.join(root, filename) # Disabled files if reduce( lambda result, exclude: source.endswith(exclude) or result, ignore_files, False): continue # Update contents. with open(source, "r+") as f: contents = f.read() contents = contents.replace("USE_CUDA", "USE_ROCM") contents = contents.replace("CUDA_VERSION", "0") f.seek(0) f.write(contents) f.truncate() f.flush() os.fsync(f) hipify_python.hipify(project_directory=proj_dir, output_directory=proj_dir, includes=includes, yaml_settings=yaml_file, add_static_casts_option=True, show_progress=False)
] paths = ("torch", "tools") for root, _directories, files in chain.from_iterable( os.walk(path) for path in paths): for filename in files: if filename.endswith(".cpp") or filename.endswith(".h"): source = os.path.join(root, filename) # Disabled files if reduce( lambda result, exclude: source.endswith(exclude) or result, ignore_files, False): continue # Update contents. with open(source, "r+") as f: contents = f.read() contents = contents.replace("USE_CUDA", "USE_ROCM") contents = contents.replace("CUDA_VERSION", "0") f.seek(0) f.write(contents) f.truncate() f.flush() os.fsync(f) hipify_python.hipify(project_directory=proj_dir, output_directory=out_dir, includes=includes, ignores=ignores, out_of_place_only=args.out_of_place_only, json_settings=json_settings, hip_clang_launch=args.hip_clang_launch)
# generated files we shouldn't frob "torch/lib/tmp_install/*", "torch/include/*", ] 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")): subprocess.Popen( ["git", "apply", os.path.join(patch_folder, filename)], cwd=proj_dir) # Check if the compiler is hip-clang. def is_hip_clang(): try: hip_path = os.getenv('HIP_PATH', '/opt/rocm/hip') return 'HIP_COMPILER=clang' in open(hip_path + '/lib/.hipInfo').read() except IOError: return False hipify_python.hipify(project_directory=proj_dir, output_directory=out_dir, includes=includes, ignores=ignores, out_of_place_only=args.out_of_place_only, hip_clang_launch=is_hip_clang())