|
| 1 | +load("@bazel_skylib//lib:paths.bzl", "paths") |
| 2 | +load("//caffe2:defs_hip.bzl", "get_hip_file_path") |
| 3 | + |
| 4 | +gpu_file_extensions = [".cu", ".c", ".cc", ".cpp"] |
| 5 | +gpu_header_extensions = [".cuh", ".h", ".hpp"] |
| 6 | + |
| 7 | +def is_test_files(filepath): |
| 8 | + if filepath.startswith("test"): |
| 9 | + return True |
| 10 | + else: |
| 11 | + return False |
| 12 | + |
| 13 | +def get_c10_hip_srcs(): |
| 14 | + gpu_file_pattern = [ |
| 15 | + base + suffix |
| 16 | + for base in c10_includes |
| 17 | + for suffix in gpu_file_extensions |
| 18 | + ] |
| 19 | + native_gpu_files = native.glob(gpu_file_pattern) |
| 20 | + |
| 21 | + gpu_files = [] |
| 22 | + hip_files = [] |
| 23 | + for name in native_gpu_files: |
| 24 | + # exclude the test folder |
| 25 | + if is_test_files(name): |
| 26 | + continue |
| 27 | + |
| 28 | + gpu_files.append(name) |
| 29 | + hip_file_name = get_hip_file_path(paths.join("cuda/", name)) |
| 30 | + hip_files.append(hip_file_name) |
| 31 | + |
| 32 | + # there will be some native hip files that needs suffix changed |
| 33 | + native_hip_pattern = [ |
| 34 | + "hip/**/*.hip", |
| 35 | + ] |
| 36 | + native_hip_files = native.glob(native_hip_pattern) |
| 37 | + |
| 38 | + gpu_files += native_hip_files |
| 39 | + hip_files += native_hip_files |
| 40 | + |
| 41 | + # we run hipify script under the caffe2 folder; therefore we need to |
| 42 | + # prepend c10 to the path so that buck can find the hipified file |
| 43 | + real_hip_files = [] |
| 44 | + for filename in hip_files: |
| 45 | + real_hip_files.append(paths.join("c10", filename)) |
| 46 | + |
| 47 | + # return the src and output_gen files |
| 48 | + return gpu_files, real_hip_files |
| 49 | + |
| 50 | +def get_c10_hip_headers(): |
| 51 | + gpu_file_pattern = [ |
| 52 | + base + suffix |
| 53 | + for base in c10_includes |
| 54 | + for suffix in gpu_header_extensions |
| 55 | + ] |
| 56 | + native_gpu_files = native.glob(gpu_file_pattern) |
| 57 | + |
| 58 | + # store the original |
| 59 | + gpu_files = [] |
| 60 | + hip_files = [] |
| 61 | + for name in native_gpu_files: |
| 62 | + if is_test_files(name): |
| 63 | + continue |
| 64 | + |
| 65 | + gpu_files.append(name) |
| 66 | + hip_file_name = get_hip_file_path(paths.join("cuda/", name)) |
| 67 | + hip_files.append(hip_file_name) |
| 68 | + |
| 69 | + # there will be some native hip files that needs suffix changed |
| 70 | + native_hip_pattern = [ |
| 71 | + "hip/**/*" + suffix |
| 72 | + for suffix in gpu_header_extensions |
| 73 | + ] |
| 74 | + native_hip_files = native.glob(native_hip_pattern) |
| 75 | + |
| 76 | + gpu_files += native_hip_files |
| 77 | + hip_files += native_hip_files |
| 78 | + |
| 79 | + # we run hipify script under the caffe2 folder; therefore we need to |
| 80 | + # prepend c10 to the path so that buck can find the hipified file |
| 81 | + real_hip_files = [] |
| 82 | + for filename in hip_files: |
| 83 | + real_hip_files.append(paths.join("c10", filename)) |
| 84 | + |
| 85 | + # return the src and output_gen files |
| 86 | + return gpu_files, real_hip_files |
| 87 | + |
| 88 | +def get_c10_hip_test_files(): |
| 89 | + gpu_file_pattern = [ |
| 90 | + base + suffix |
| 91 | + for base in c10_includes |
| 92 | + for suffix in gpu_file_extensions |
| 93 | + ] |
| 94 | + native_gpu_files = native.glob(gpu_file_pattern) |
| 95 | + |
| 96 | + # store the original |
| 97 | + gpu_files = [] |
| 98 | + hip_files = [] |
| 99 | + for name in native_gpu_files: |
| 100 | + if not is_test_files(name): |
| 101 | + continue |
| 102 | + |
| 103 | + gpu_files.append(name) |
| 104 | + hip_file_name = get_hip_file_path(paths.join("cuda/", name)) |
| 105 | + hip_files.append(hip_file_name) |
| 106 | + |
| 107 | + # there will be some native hip files that needs suffix changed |
| 108 | + native_hip_pattern = [ |
| 109 | + "hip/test/**/*" + suffix |
| 110 | + for suffix in gpu_header_extensions |
| 111 | + ] |
| 112 | + native_hip_files = native.glob(native_hip_pattern) |
| 113 | + |
| 114 | + gpu_files += native_hip_files |
| 115 | + hip_files += native_hip_files |
| 116 | + |
| 117 | + # we run hipify script under the caffe2 folder; therefore we need to |
| 118 | + # prepend c10 to the path so that buck can find the hipified file |
| 119 | + real_hip_files = [] |
| 120 | + for filename in hip_files: |
| 121 | + real_hip_files.append(paths.join("c10", filename)) |
| 122 | + |
| 123 | + # return the src and output_gen files |
| 124 | + return gpu_files, real_hip_files |
| 125 | + |
| 126 | +c10_includes = ["**/*"] |
0 commit comments