From b8f8d23ab4fd180b608c0453e5f5fb4b574acaec Mon Sep 17 00:00:00 2001 From: bmedishe Date: Mon, 28 Mar 2022 18:37:37 +0000 Subject: [PATCH 1/3] add hipify_torch as submodule --- .gitmodules | 3 +++ third_party/hipify_torch | 1 + 2 files changed, 4 insertions(+) create mode 160000 third_party/hipify_torch diff --git a/.gitmodules b/.gitmodules index 3f127b847..0e83b8b83 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "third-party/googletest"] path = third-party/googletest url = https://github.com/google/googletest.git +[submodule "third_party/hipify_torch"] + path = third_party/hipify_torch + url = https://github.com/ROCmSoftwarePlatform/hipify_torch.git diff --git a/third_party/hipify_torch b/third_party/hipify_torch new file mode 160000 index 000000000..f98892d96 --- /dev/null +++ b/third_party/hipify_torch @@ -0,0 +1 @@ +Subproject commit f98892d96d87835a82d19aae4b254ab395ec47bf From 22da3d76a34b3835098fabdd69886f82a28f98e9 Mon Sep 17 00:00:00 2001 From: bmedishe Date: Mon, 28 Mar 2022 19:09:57 +0000 Subject: [PATCH 2/3] update build_amd.py to use hipify_torch hipify --- tools/amd_build/build_amd.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/amd_build/build_amd.py b/tools/amd_build/build_amd.py index 351a15087..418573a4d 100755 --- a/tools/amd_build/build_amd.py +++ b/tools/amd_build/build_amd.py @@ -4,8 +4,17 @@ import argparse import os +import sys +sys.path.append(os.path.realpath(os.path.join( + __file__, + os.path.pardir, + os.path.pardir, + os.path.pardir, + 'third_party', + 'hipify_torch'))) + +from hipify import hipify_python # type: ignore[import] -from pyHIPIFY import hipify_python parser = argparse.ArgumentParser( description="Top-level script for HIPifying, filling in most common parameters" @@ -64,7 +73,7 @@ os.path.join(args.root_dir, "*cuda*"), os.path.join(args.root_dir, "*nccl*"), ] - +includes = [os.path.join(proj_dir, include) for include in includes] ignores = [] hipify_python.hipify( @@ -72,6 +81,5 @@ output_directory=out_dir, includes=includes, ignores=ignores, - list_files_only=args.list_files_only, - show_progress=False, + show_progress=True, ) From 46285c9397f8d08d1f087ddc7c99aa8f9bc6443d Mon Sep 17 00:00:00 2001 From: bmedishe Date: Mon, 28 Mar 2022 19:13:38 +0000 Subject: [PATCH 3/3] remove current hipify --- tools/amd_build/pyHIPIFY/__init__.py | 0 tools/amd_build/pyHIPIFY/constants.py | 56 - .../pyHIPIFY/cuda_to_hip_mappings.py | 7800 ----------------- tools/amd_build/pyHIPIFY/hipify_python.py | 488 -- 4 files changed, 8344 deletions(-) delete mode 100644 tools/amd_build/pyHIPIFY/__init__.py delete mode 100644 tools/amd_build/pyHIPIFY/constants.py delete mode 100644 tools/amd_build/pyHIPIFY/cuda_to_hip_mappings.py delete mode 100755 tools/amd_build/pyHIPIFY/hipify_python.py diff --git a/tools/amd_build/pyHIPIFY/__init__.py b/tools/amd_build/pyHIPIFY/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/amd_build/pyHIPIFY/constants.py b/tools/amd_build/pyHIPIFY/constants.py deleted file mode 100644 index 4cda2e323..000000000 --- a/tools/amd_build/pyHIPIFY/constants.py +++ /dev/null @@ -1,56 +0,0 @@ -""" Constants for annotations in the mapping. -The constants defined here are used to annotate the mapping tuples in cuda_to_hip_mappings.py. -They are based on -https://github.com/ROCm-Developer-Tools/HIP/blob/master/hipify-clang/src/Statistics.h -and fall in three categories: 1) type of mapping, 2) API of mapping, 3) unsupported -mapping. -""" - -CONV_VERSION = (0,) -CONV_INIT = 1 -CONV_DEVICE = 2 -CONV_MEM = 3 -CONV_KERN = 4 -CONV_COORD_FUNC = 5 -CONV_MATH_FUNC = 6 -CONV_DEVICE_FUNC = 7 -CONV_SPECIAL_FUNC = 8 -CONV_STREAM = 9 -CONV_EVENT = 10 -CONV_OCCUPANCY = 11 -CONV_CONTEXT = 12 -CONV_PEER = 13 -CONV_MODULE = 14 -CONV_CACHE = 15 -CONV_EXEC = 16 -CONV_ERROR = 17 -CONV_DEF = 18 -CONV_TEX = 19 -CONV_GL = 20 -CONV_GRAPHICS = 21 -CONV_SURFACE = 22 -CONV_JIT = 23 -CONV_D3D9 = 24 -CONV_D3D10 = 25 -CONV_D3D11 = 26 -CONV_VDPAU = 27 -CONV_EGL = 28 -CONV_THREAD = 29 -CONV_OTHER = 30 -CONV_INCLUDE = 31 -CONV_INCLUDE_CUDA_MAIN_H = 32 -CONV_TYPE = 33 -CONV_LITERAL = 34 -CONV_NUMERIC_LITERAL = 35 -CONV_LAST = 36 - -API_DRIVER = 37 -API_RUNTIME = 38 -API_BLAS = 39 -API_SPARSE = 40 -API_RAND = 41 -API_LAST = 42 -API_FFT = 43 - -HIP_UNSUPPORTED = 43 -API_GLOO = 1340 diff --git a/tools/amd_build/pyHIPIFY/cuda_to_hip_mappings.py b/tools/amd_build/pyHIPIFY/cuda_to_hip_mappings.py deleted file mode 100644 index e8122b05c..000000000 --- a/tools/amd_build/pyHIPIFY/cuda_to_hip_mappings.py +++ /dev/null @@ -1,7800 +0,0 @@ -import collections - -from pyHIPIFY.constants import * - -""" Mapping of CUDA functions, include files, constants, and types to ROCm/HIP equivalents -This closely follows the implementation in hipify-clang -https://github.com/ROCm-Developer-Tools/HIP/blob/master/hipify-clang/src/CUDA2HipMap.cpp -and its structure. -There are different maps for fundamental names, include files, identifies, sparse, and -PyTorch specific translations. -Each of the entries in these maps translates a CUDA string to a tuple containing the -ROCm/HIP string, a type and API annotation and - optionally - an annotation if it is not -supported in ROCm/HIP yet. -""" - -CUDA_TYPE_NAME_MAP = collections.OrderedDict( - [ - ("CUresult", ("hipError_t", CONV_TYPE, API_DRIVER)), - ("cudaError_t", ("hipError_t", CONV_TYPE, API_RUNTIME)), - ( - "CUDA_ARRAY3D_DESCRIPTOR", - ("HIP_ARRAY3D_DESCRIPTOR", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUDA_ARRAY_DESCRIPTOR", ("HIP_ARRAY_DESCRIPTOR", CONV_TYPE, API_DRIVER)), - ("CUDA_MEMCPY2D", ("hip_Memcpy2D", CONV_TYPE, API_DRIVER)), - ("CUDA_MEMCPY3D", ("HIP_MEMCPY3D", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUDA_MEMCPY3D_PEER", - ("HIP_MEMCPY3D_PEER", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUDA_POINTER_ATTRIBUTE_P2P_TOKENS", - ( - "HIP_POINTER_ATTRIBUTE_P2P_TOKENS", - CONV_TYPE, - API_DRIVER, - HIP_UNSUPPORTED, - ), - ), - ( - "CUDA_RESOURCE_DESC", - ("HIP_RESOURCE_DESC", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUDA_RESOURCE_VIEW_DESC", - ("HIP_RESOURCE_VIEW_DESC", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUipcEventHandle", - ("hipIpcEventHandle", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUipcMemHandle", ("hipIpcMemHandle", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ("CUaddress_mode", ("hipAddress_mode", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUarray_cubemap_face", - ("hipArray_cubemap_face", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUarray_format", ("hipArray_format", CONV_TYPE, API_DRIVER)), - ("CUcomputemode", ("hipComputemode", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ("CUmem_advise", ("hipMemAdvise", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUmem_range_attribute", - ("hipMemRangeAttribute", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUctx_flags", ("hipCctx_flags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ("CUdevice", ("hipDevice_t", CONV_TYPE, API_DRIVER)), - ("CUdevice_attribute_enum", ("hipDeviceAttribute_t", CONV_TYPE, API_DRIVER)), - ("CUdevice_attribute", ("hipDeviceAttribute_t", CONV_TYPE, API_DRIVER)), - ("CUdeviceptr", ("hipDeviceptr_t", CONV_TYPE, API_DRIVER)), - ("CUarray_st", ("hipArray", CONV_TYPE, API_DRIVER)), - ("CUarray", ("hipArray *", CONV_TYPE, API_DRIVER)), - ("CUdevprop_st", ("hipDeviceProp_t", CONV_TYPE, API_DRIVER)), - ("CUdevprop", ("hipDeviceProp_t", CONV_TYPE, API_DRIVER)), - ("CUfunction", ("hipFunction_t", CONV_TYPE, API_DRIVER)), - ( - "CUgraphicsResource", - ("hipGraphicsResource_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUmipmappedArray", - ("hipMipmappedArray_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUfunction_attribute", - ("hipFuncAttribute_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUfunction_attribute_enum", - ("hipFuncAttribute_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUgraphicsMapResourceFlags", - ("hipGraphicsMapFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUgraphicsMapResourceFlags_enum", - ("hipGraphicsMapFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUgraphicsRegisterFlags", - ("hipGraphicsRegisterFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUgraphicsRegisterFlags_enum", - ("hipGraphicsRegisterFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUoccupancy_flags", - ("hipOccupancyFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUoccupancy_flags_enum", - ("hipOccupancyFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUfunc_cache_enum", ("hipFuncCache", CONV_TYPE, API_DRIVER)), - ("CUfunc_cache", ("hipFuncCache", CONV_TYPE, API_DRIVER)), - ("CUipcMem_flags", ("hipIpcMemFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUipcMem_flags_enum", - ("hipIpcMemFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUjit_cacheMode", ("hipJitCacheMode", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUjit_cacheMode_enum", - ("hipJitCacheMode", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUjit_fallback", ("hipJitFallback", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUjit_fallback_enum", - ("hipJitFallback", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUjit_option", ("hipJitOption", CONV_JIT, API_DRIVER)), - ("CUjit_option_enum", ("hipJitOption", CONV_JIT, API_DRIVER)), - ("CUjit_target", ("hipJitTarget", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED)), - ("CUjit_target_enum", ("hipJitTarget", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED)), - ("CUjitInputType", ("hipJitInputType", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUjitInputType_enum", - ("hipJitInputType", CONV_JIT, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUlimit", ("hipLimit_t", CONV_TYPE, API_DRIVER)), - ("CUlimit_enum", ("hipLimit_t", CONV_TYPE, API_DRIVER)), - ( - "CUmemAttach_flags", - ("hipMemAttachFlags_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUmemAttach_flags_enum", - ("hipMemAttachFlags_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUmemorytype", ("hipMemType_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ("CUmemorytype_enum", ("hipMemType_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ("CUresourcetype", ("hipResourceType", CONV_TEX, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUresourcetype_enum", - ("hipResourceType", CONV_TEX, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUresourceViewFormat", ("hipResourceViewFormat", CONV_TEX, API_DRIVER)), - ("CUresourceViewFormat_enum", ("hipResourceViewFormat", CONV_TEX, API_DRIVER)), - ("CUsharedconfig", ("hipSharedMemConfig", CONV_TYPE, API_DRIVER)), - ("CUsharedconfig_enum", ("hipSharedMemConfig", CONV_TYPE, API_DRIVER)), - ("CUcontext", ("hipCtx_t", CONV_TYPE, API_DRIVER)), - ("CUmodule", ("hipModule_t", CONV_TYPE, API_DRIVER)), - ("CUstream", ("hipStream_t", CONV_TYPE, API_DRIVER)), - ("CUstream_st", ("ihipStream_t", CONV_TYPE, API_DRIVER)), - ("CUstreamCallback", ("hipStreamCallback_t", CONV_TYPE, API_DRIVER)), - ("CUsurfObject", ("hipSurfaceObject", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUsurfref", - ("hipSurfaceReference_t", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUtexObject", ("hipTextureObject_t", CONV_TYPE, API_DRIVER)), - ("CUtexref", ("textureReference", CONV_TYPE, API_DRIVER)), - ("CUstream_flags", ("hipStreamFlags", CONV_TYPE, API_DRIVER)), - ( - "CUstreamWaitValue_flags", - ("hipStreamWaitValueFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUstreamWriteValue_flags", - ("hipStreamWriteValueFlags", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUstreamBatchMemOpType", - ("hipStreamBatchMemOpType", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUdevice_P2PAttribute", - ("hipDeviceP2PAttribute", CONV_TYPE, API_DRIVER, HIP_UNSUPPORTED), - ), - ("CUevent", ("hipEvent_t", CONV_TYPE, API_DRIVER)), - ("CUevent_flags", ("hipEventFlags", CONV_EVENT, API_DRIVER, HIP_UNSUPPORTED)), - ("CUfilter_mode", ("hipTextureFilterMode", CONV_TEX, API_DRIVER)), - ("CUGLDeviceList", ("hipGLDeviceList", CONV_GL, API_DRIVER, HIP_UNSUPPORTED)), - ("CUGLmap_flags", ("hipGLMapFlags", CONV_GL, API_DRIVER, HIP_UNSUPPORTED)), - ( - "CUd3d9DeviceList", - ("hipD3D9DeviceList", CONV_D3D9, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d9map_flags", - ("hipD3D9MapFlags", CONV_D3D9, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d9register_flags", - ("hipD3D9RegisterFlags", CONV_D3D9, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d10DeviceList", - ("hipd3d10DeviceList", CONV_D3D10, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d10map_flags", - ("hipD3D10MapFlags", CONV_D3D10, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d10register_flags", - ("hipD3D10RegisterFlags", CONV_D3D10, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUd3d11DeviceList", - ("hipd3d11DeviceList", CONV_D3D11, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUeglStreamConnection_st", - ("hipEglStreamConnection", CONV_EGL, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "CUeglStreamConnection", - ("hipEglStreamConnection", CONV_EGL, API_DRIVER, HIP_UNSUPPORTED), - ), - ( - "libraryPropertyType_t", - ("hipLibraryPropertyType_t", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "libraryPropertyType", - ("hipLibraryPropertyType_t", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaStreamCallback_t", ("hipStreamCallback_t", CONV_TYPE, API_RUNTIME)), - ("cudaArray", ("hipArray", CONV_MEM, API_RUNTIME)), - ("cudaArray_t", ("hipArray_t", CONV_MEM, API_RUNTIME)), - ("cudaArray_const_t", ("hipArray_const_t", CONV_MEM, API_RUNTIME)), - ("cudaMipmappedArray_t", ("hipMipmappedArray_t", CONV_MEM, API_RUNTIME)), - ( - "cudaMipmappedArray_const_t", - ("hipMipmappedArray_const_t", CONV_MEM, API_RUNTIME), - ), - ("cudaArrayDefault", ("hipArrayDefault", CONV_MEM, API_RUNTIME)), - ("cudaArrayLayered", ("hipArrayLayered", CONV_MEM, API_RUNTIME)), - ( - "cudaArraySurfaceLoadStore", - ("hipArraySurfaceLoadStore", CONV_MEM, API_RUNTIME), - ), - ("cudaArrayCubemap", ("hipArrayCubemap", CONV_MEM, API_RUNTIME)), - ("cudaArrayTextureGather", ("hipArrayTextureGather", CONV_MEM, API_RUNTIME)), - ("cudaMemoryAdvise", ("hipMemAdvise", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED)), - ( - "cudaMemRangeAttribute", - ("hipMemRangeAttribute", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaMemcpyKind", ("hipMemcpyKind", CONV_MEM, API_RUNTIME)), - ("cudaMemoryType", ("hipMemoryType", CONV_MEM, API_RUNTIME)), - ("cudaExtent", ("hipExtent", CONV_MEM, API_RUNTIME)), - ("cudaPitchedPtr", ("hipPitchedPtr", CONV_MEM, API_RUNTIME)), - ("cudaPos", ("hipPos", CONV_MEM, API_RUNTIME)), - ("cudaEvent_t", ("hipEvent_t", CONV_TYPE, API_RUNTIME)), - ("cudaStream_t", ("hipStream_t", CONV_TYPE, API_RUNTIME)), - ("cudaPointerAttributes", ("hipPointerAttribute_t", CONV_TYPE, API_RUNTIME)), - ("cudaDeviceAttr", ("hipDeviceAttribute_t", CONV_TYPE, API_RUNTIME)), - ("cudaDeviceProp", ("hipDeviceProp_t", CONV_TYPE, API_RUNTIME)), - ( - "cudaDeviceP2PAttr", - ("hipDeviceP2PAttribute", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaComputeMode", - ("hipComputeMode", CONV_TYPE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaFuncCache", ("hipFuncCache_t", CONV_CACHE, API_RUNTIME)), - ( - "cudaFuncAttributes", - ("hipFuncAttributes", CONV_EXEC, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaSharedMemConfig", ("hipSharedMemConfig", CONV_TYPE, API_RUNTIME)), - ("cudaLimit", ("hipLimit_t", CONV_TYPE, API_RUNTIME)), - ("cudaOutputMode", ("hipOutputMode", CONV_OTHER, API_RUNTIME, HIP_UNSUPPORTED)), - ("cudaTextureReadMode", ("hipTextureReadMode", CONV_TEX, API_RUNTIME)), - ("cudaTextureFilterMode", ("hipTextureFilterMode", CONV_TEX, API_RUNTIME)), - ("cudaChannelFormatKind", ("hipChannelFormatKind", CONV_TEX, API_RUNTIME)), - ("cudaChannelFormatDesc", ("hipChannelFormatDesc", CONV_TEX, API_RUNTIME)), - ("cudaResourceDesc", ("hipResourceDesc", CONV_TEX, API_RUNTIME)), - ("cudaResourceViewDesc", ("hipResourceViewDesc", CONV_TEX, API_RUNTIME)), - ("cudaTextureDesc", ("hipTextureDesc", CONV_TEX, API_RUNTIME)), - ( - "surfaceReference", - ("hipSurfaceReference", CONV_SURFACE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaTextureObject_t", ("hipTextureObject_t", CONV_TEX, API_RUNTIME)), - ("cudaResourceType", ("hipResourceType", CONV_TEX, API_RUNTIME)), - ("cudaResourceViewFormat", ("hipResourceViewFormat", CONV_TEX, API_RUNTIME)), - ("cudaTextureAddressMode", ("hipTextureAddressMode", CONV_TEX, API_RUNTIME)), - ( - "cudaSurfaceBoundaryMode", - ("hipSurfaceBoundaryMode", CONV_SURFACE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaSurfaceFormatMode", - ("hipSurfaceFormatMode", CONV_SURFACE, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaTextureType1D", ("hipTextureType1D", CONV_TEX, API_RUNTIME)), - ("cudaTextureType2D", ("hipTextureType2D", CONV_TEX, API_RUNTIME)), - ("cudaTextureType3D", ("hipTextureType3D", CONV_TEX, API_RUNTIME)), - ("cudaTextureTypeCubemap", ("hipTextureTypeCubemap", CONV_TEX, API_RUNTIME)), - ( - "cudaTextureType1DLayered", - ("hipTextureType1DLayered", CONV_TEX, API_RUNTIME), - ), - ( - "cudaTextureType2DLayered", - ("hipTextureType2DLayered", CONV_TEX, API_RUNTIME), - ), - ( - "cudaTextureTypeCubemapLayered", - ("hipTextureTypeCubemapLayered", CONV_TEX, API_RUNTIME), - ), - ("cudaIpcEventHandle_t", ("hipIpcEventHandle_t", CONV_TYPE, API_RUNTIME)), - ("cudaIpcEventHandle_st", ("hipIpcEventHandle_t", CONV_TYPE, API_RUNTIME)), - ("cudaIpcMemHandle_t", ("hipIpcMemHandle_t", CONV_TYPE, API_RUNTIME)), - ("cudaIpcMemHandle_st", ("hipIpcMemHandle_t", CONV_TYPE, API_RUNTIME)), - ( - "cudaGraphicsCubeFace", - ("hipGraphicsCubeFace", CONV_GRAPHICS, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaGraphicsMapFlags", - ("hipGraphicsMapFlags", CONV_GRAPHICS, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaGraphicsRegisterFlags", - ("hipGraphicsRegisterFlags", CONV_GRAPHICS, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaGLDeviceList", - ("hipGLDeviceList", CONV_GL, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cudaGLMapFlags", ("hipGLMapFlags", CONV_GL, API_RUNTIME, HIP_UNSUPPORTED)), - ( - "cudaD3D9DeviceList", - ("hipD3D9DeviceList", CONV_D3D9, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D9MapFlags", - ("hipD3D9MapFlags", CONV_D3D9, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D9RegisterFlags", - ("hipD3D9RegisterFlags", CONV_D3D9, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D10DeviceList", - ("hipd3d10DeviceList", CONV_D3D10, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D10MapFlags", - ("hipD3D10MapFlags", CONV_D3D10, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D10RegisterFlags", - ("hipD3D10RegisterFlags", CONV_D3D10, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaD3D11DeviceList", - ("hipd3d11DeviceList", CONV_D3D11, API_RUNTIME, HIP_UNSUPPORTED), - ), - ( - "cudaEglStreamConnection", - ("hipEglStreamConnection", CONV_EGL, API_RUNTIME, HIP_UNSUPPORTED), - ), - ("cublasHandle_t", ("rocblas_handle", CONV_TYPE, API_BLAS)), - ("cublasOperation_t", ("rocblas_operation", CONV_TYPE, API_BLAS)), - ("cublasStatus_t", ("rocblas_status", CONV_TYPE, API_BLAS)), - ("cublasFillMode_t", ("rocblas_fill", CONV_TYPE, API_BLAS)), - ("cublasDiagType_t", ("rocblas_diagonal", CONV_TYPE, API_BLAS)), - ("cublasSideMode_t", ("rocblas_side", CONV_TYPE, API_BLAS)), - ("cublasPointerMode_t", ("rocblas_pointer_mode", CONV_TYPE, API_BLAS)), - ( - "cublasAtomicsMode_t", - ("rocblas_atomics_mode", CONV_TYPE, API_BLAS, HIP_UNSUPPORTED), - ), - ( - "cublasDataType_t", - ("rocblas_data_type", CONV_TYPE, API_BLAS, HIP_UNSUPPORTED), - ), - ("curandStatus", ("hiprandStatus_t", CONV_TYPE, API_RAND)), - ("curandStatus_t", ("hiprandStatus_t", CONV_TYPE, API_RAND)), - ("curandRngType", ("hiprandRngType_t", CONV_TYPE, API_RAND)), - ("curandRngType_t", ("hiprandRngType_t", CONV_TYPE, API_RAND)), - ("curandGenerator_st", ("hiprandGenerator_st", CONV_TYPE, API_RAND)), - ("curandGenerator_t", ("hiprandGenerator_t", CONV_TYPE, API_RAND)), - ( - "curandDirectionVectorSet", - ("hiprandDirectionVectorSet_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDirectionVectorSet_t", - ("hiprandDirectionVectorSet_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ("curandOrdering", ("hiprandOrdering_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED)), - ( - "curandOrdering_t", - ("hiprandOrdering_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistribution_st", - ("hiprandDistribution_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2V_st", - ("hiprandDistribution_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistribution_t", - ("hiprandDistribution_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2V_t", - ("hiprandDistribution_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistributionShift_st", - ("hiprandDistributionShift_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistributionShift_t", - ("hiprandDistributionShift_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistributionM2Shift_st", - ("hiprandDistributionM2Shift_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDistributionM2Shift_t", - ("hiprandDistributionM2Shift_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2_st", - ("hiprandHistogramM2_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2_t", - ("hiprandHistogramM2_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2K_st", - ("hiprandHistogramM2K_st", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandHistogramM2K_t", - ("hiprandHistogramM2K_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandDiscreteDistribution_st", - ("hiprandDiscreteDistribution_st", CONV_TYPE, API_RAND), - ), - ( - "curandDiscreteDistribution_t", - ("hiprandDiscreteDistribution_t", CONV_TYPE, API_RAND), - ), - ("curandMethod", ("hiprandMethod_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED)), - ("curandMethod_t", ("hiprandMethod_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED)), - ( - "curandDirectionVectors32_t", - ("hiprandDirectionVectors32_t", CONV_TYPE, API_RAND), - ), - ( - "curandDirectionVectors64_t", - ("hiprandDirectionVectors64_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ("curandStateMtgp32_t", ("hiprandStateMtgp32_t", CONV_TYPE, API_RAND)), - ("curandStateMtgp32", ("hiprandStateMtgp32_t", CONV_TYPE, API_RAND)), - ( - "curandStateScrambledSobol64_t", - ("hiprandStateScrambledSobol64_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandStateSobol64_t", - ("hiprandStateSobol64_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ( - "curandStateScrambledSobol32_t", - ("hiprandStateScrambledSobol32_t", CONV_TYPE, API_RAND, HIP_UNSUPPORTED), - ), - ("curandStateSobol32_t", ("hiprandStateSobol32_t", CONV_TYPE, API_RAND)), - ("curandStateMRG32k3a_t", ("hiprandStateMRG32k3a_t", CONV_TYPE, API_RAND)), - ( - "curandStatePhilox4_32_10_t", - ("hiprandStatePhilox4_32_10_t", CONV_TYPE, API_RAND), - ), - ("curandStateXORWOW_t", ("hiprandStateXORWOW_t", CONV_TYPE, API_RAND)), - ("curandState_t", ("hiprandState_t", CONV_TYPE, API_RAND)), - ("curandState", ("hiprandState_t", CONV_TYPE, API_RAND)), - ] -) - -CUDA_INCLUDE_MAP = collections.OrderedDict( - [ - # since pytorch uses "\b{pattern}\b" as the actual re pattern, - # patterns listed here have to begin and end with alnum chars - ( - "include ", ("", API_GLOO)), - ("GLOO_USE_NCCL", ("GLOO_USE_RCCL", API_GLOO)), - ] -) - -# NB: C10 mappings are more specific than Caffe2 mappings, so run them -# first -CUDA_TO_HIP_MAPPINGS = [ - CUDA_IDENTIFIER_MAP, - CUDA_TYPE_NAME_MAP, - CUDA_INCLUDE_MAP, - CUDA_SPARSE_MAP, - GLOO_SPECIFIC_MAPPINGS, -] diff --git a/tools/amd_build/pyHIPIFY/hipify_python.py b/tools/amd_build/pyHIPIFY/hipify_python.py deleted file mode 100755 index bf2ddefcf..000000000 --- a/tools/amd_build/pyHIPIFY/hipify_python.py +++ /dev/null @@ -1,488 +0,0 @@ -#!/usr/bin/env python3 -""" The Python Hipify script. -## -# Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. -# 2017-2018 Advanced Micro Devices, Inc. and -# Facebook Inc. All rights reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -""" - -from __future__ import absolute_import, division, print_function - -import fnmatch -import os -import re - -from pyHIPIFY.cuda_to_hip_mappings import CUDA_TO_HIP_MAPPINGS - - -class InputError(Exception): - # Exception raised for errors in the input. - - def __init__(self, message): - super(InputError, self).__init__(message) - self.message = message - - def __str__(self): - return "{}: {}".format("Input error", self.message) - - -def matched_files_iter(root_path, includes=("*",), ignores=(), extensions=()): - def _fnmatch(filepath, patterns): - return any(fnmatch.fnmatch(filepath, pattern) for pattern in patterns) - - def match_extensions(filename): - """Helper method to see if filename ends with certain extension""" - return any(filename.endswith(e) for e in extensions) - - exact_matches = set(includes) - - # This is a very rough heuristic; really, we want to avoid scanning - # any file which is not checked into source control, but this script - # needs to work even if you're in a Git or Hg checkout, so easier to - # just blacklist the biggest time sinks that won't matter in the - # end. - for (abs_dirpath, dirs, filenames) in os.walk(root_path, topdown=True): - rel_dirpath = os.path.relpath(abs_dirpath, root_path) - if rel_dirpath == ".": - # Blah blah blah O(n) blah blah - if ".git" in dirs: - dirs.remove(".git") - if "build" in dirs: - dirs.remove("build") - if "third_party" in dirs: - dirs.remove("third_party") - for filename in filenames: - filepath = os.path.join(rel_dirpath, filename) - # We respect extensions, UNLESS you wrote the entire - # filename verbatim, in which case we always accept it - if ( - _fnmatch(filepath, includes) - and (not _fnmatch(filepath, ignores)) - and (match_extensions(filepath) or filepath in exact_matches) - ): - yield filepath - - -def preprocess(project_directory, output_directory, all_files, show_progress=True): - """ - Call preprocessor on selected files. - """ - - for filepath in all_files: - preprocessor(project_directory, output_directory, filepath) - if show_progress: - print(filepath, "->", get_hip_file_path(filepath)) - - print("Successfully preprocessed all matching files.") - - -def add_dim3(kernel_string, cuda_kernel): - """adds dim3() to the second and third arguments in the kernel launch""" - count = 0 - closure = 0 - kernel_string = kernel_string.replace("<<<", "").replace(">>>", "") - arg_locs = [{} for _ in range(2)] - arg_locs[count]["start"] = 0 - for ind, c in enumerate(kernel_string): - if count > 1: - break - if c == "(": - closure += 1 - elif c == ")": - closure -= 1 - elif (c == "," or ind == len(kernel_string) - 1) and closure == 0: - arg_locs[count]["end"] = ind + (c != ",") - count += 1 - if count < 2: - arg_locs[count]["start"] = ind + 1 - - first_arg_raw = kernel_string[arg_locs[0]["start"] : arg_locs[0]["end"] + 1] - second_arg_raw = kernel_string[arg_locs[1]["start"] : arg_locs[1]["end"]] - - first_arg_clean = ( - kernel_string[arg_locs[0]["start"] : arg_locs[0]["end"]] - .replace("\n", "") - .strip(" ") - ) - second_arg_clean = ( - kernel_string[arg_locs[1]["start"] : arg_locs[1]["end"]] - .replace("\n", "") - .strip(" ") - ) - - first_arg_dim3 = "dim3({})".format(first_arg_clean) - second_arg_dim3 = "dim3({})".format(second_arg_clean) - - first_arg_raw_dim3 = first_arg_raw.replace(first_arg_clean, first_arg_dim3) - second_arg_raw_dim3 = second_arg_raw.replace(second_arg_clean, second_arg_dim3) - cuda_kernel = cuda_kernel.replace( - first_arg_raw + second_arg_raw, first_arg_raw_dim3 + second_arg_raw_dim3 - ) - return cuda_kernel - - -RE_KERNEL_LAUNCH = re.compile(r"([ ]+)(detail?)::[ ]+\\\n[ ]+") - - -def processKernelLaunches(string): - """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_KERNEL_LAUNCH.sub( - lambda inp: "{0}{1}::".format(inp.group(1), inp.group(2)), string - ) - - def grab_method_and_template(in_kernel): - # The positions for relevant kernel components. - pos = { - "kernel_launch": {"start": in_kernel["start"], "end": in_kernel["end"]}, - "kernel_name": {"start": -1, "end": -1}, - "template": {"start": -1, "end": -1}, - } - - # Count for balancing template - count = {"<>": 0} - - # Status for whether we are parsing a certain item. - START = 0 - AT_TEMPLATE = 1 - AFTER_TEMPLATE = 2 - AT_KERNEL_NAME = 3 - - status = START - - # Parse the string character by character - for i in range(pos["kernel_launch"]["start"] - 1, -1, -1): - char = string[i] - - # Handle Templating Arguments - if status == START or status == AT_TEMPLATE: - if char == ">": - if status == START: - status = AT_TEMPLATE - pos["template"]["end"] = i - count["<>"] += 1 - - if char == "<": - count["<>"] -= 1 - if count["<>"] == 0 and (status == AT_TEMPLATE): - pos["template"]["start"] = i - status = AFTER_TEMPLATE - - # Handle Kernel Name - if status != AT_TEMPLATE: - if string[i].isalnum() or string[i] in {"(", ")", "_", ":", "#"}: - if status != AT_KERNEL_NAME: - status = AT_KERNEL_NAME - pos["kernel_name"]["end"] = i - - # Case: Kernel name starts the string. - if i == 0: - pos["kernel_name"]["start"] = 0 - - # Finished - return [ - (pos["kernel_name"]), - (pos["template"]), - (pos["kernel_launch"]), - ] - - else: - # Potential ending point if we're already traversing a kernel's name. - if status == AT_KERNEL_NAME: - pos["kernel_name"]["start"] = i - - # Finished - return [ - (pos["kernel_name"]), - (pos["template"]), - (pos["kernel_launch"]), - ] - - def find_kernel_bounds(string): - """Finds the starting and ending points for all kernel launches in the string.""" - kernel_end = 0 - kernel_positions = [] - - # Continue until we cannot find any more kernels anymore. - while string.find("<<<", kernel_end) != -1: - # Get kernel starting position (starting from the previous ending point) - kernel_start = string.find("<<<", kernel_end) - - # Get kernel ending position (adjust end point past the >>>) - kernel_end = string.find(">>>", kernel_start) + 3 - if kernel_end <= 0: - raise InputError("no kernel end found") - - # Add to list of traversed kernels - kernel_positions.append( - { - "start": kernel_start, - "end": kernel_end, - "group": string[kernel_start:kernel_end], - } - ) - - return kernel_positions - - # Grab positional ranges of all kernel launchces - get_kernel_positions = [k for k in find_kernel_bounds(string)] - output_string = string - - # Replace each CUDA kernel with a HIP kernel. - for kernel in get_kernel_positions: - # Get kernel components - params = grab_method_and_template(kernel) - - # Find parenthesis after kernel launch - parenthesis = string.find("(", kernel["end"]) - - # Extract cuda kernel - cuda_kernel = string[params[0]["start"] : parenthesis + 1] - kernel_string = string[kernel["start"] : kernel["end"]] - cuda_kernel_dim3 = add_dim3(kernel_string, cuda_kernel) - # Keep number of kernel launch params consistent (grid dims, group dims, stream, dynamic shared size) - num_klp = len( - extract_arguments( - 0, kernel["group"].replace("<<<", "(").replace(">>>", ")") - ) - ) - - hip_kernel = "hipLaunchKernelGGL(" + cuda_kernel_dim3[0:-1].replace( - ">>>", ", 0" * (4 - num_klp) + ">>>" - ).replace("<<<", ", ").replace(">>>", ", ") - - # Replace cuda kernel with hip kernel - output_string = output_string.replace(cuda_kernel, hip_kernel) - - return output_string - - -def get_hip_file_path(filepath): - """ - Returns the new name of the hipified file - """ - dirpath, filename = os.path.split(filepath) - root, ext = os.path.splitext(filename) - - # Concretely, we do the following: - # - # - If there is a directory component named "cuda", replace - # it with "hip", AND - # - # - If the file name contains "CUDA", replace it with "HIP", AND - # Furthermore, ALWAYS replace '.cu' with '.hip', because those files - # contain CUDA kernels that needs to be hipified and processed with - # hcc compiler - # - # This isn't set in stone; we might adjust this to support other - # naming conventions. - - if ext == ".cu": - ext = ".hip" - - orig_dirpath = dirpath - dirpath = dirpath.replace("cuda", "hip") - root = root.replace("cuda", "hip") - root = root.replace("CUDA", "HIP") - - return os.path.join(dirpath, root + ext) - - -# Cribbed from https://stackoverflow.com/questions/42742810/speed-up-millions-of-regex-replacements-in-python-3/42789508#42789508 -class Trie: - """Regex::Trie in Python. Creates a Trie out of a list of words. The trie can be exported to a Regex pattern. - The corresponding Regex should match much faster than a simple Regex union.""" - - def __init__(self): - self.data = {} - - def add(self, word): - ref = self.data - for char in word: - ref[char] = char in ref and ref[char] or {} - ref = ref[char] - ref[""] = 1 - - def dump(self): - return self.data - - def quote(self, char): - return re.escape(char) - - def _pattern(self, pData): - data = pData - if "" in data and len(data.keys()) == 1: - return None - - alt = [] - cc = [] - q = 0 - for char in sorted(data.keys()): - if isinstance(data[char], dict): - try: - recurse = self._pattern(data[char]) - alt.append(self.quote(char) + recurse) - except Exception: - cc.append(self.quote(char)) - else: - q = 1 - cconly = not len(alt) > 0 - - if len(cc) > 0: - if len(cc) == 1: - alt.append(cc[0]) - else: - alt.append("[" + "".join(cc) + "]") - - if len(alt) == 1: - result = alt[0] - else: - result = "(?:" + "|".join(alt) + ")" - - if q: - if cconly: - result += "?" - else: - result = "(?:%s)?" % result - return result - - def pattern(self): - return self._pattern(self.dump()) - - -RE_TRIE = Trie() -RE_MAP = {} -for mapping in CUDA_TO_HIP_MAPPINGS: - for src, value in mapping.items(): - dst = value[0] - RE_TRIE.add(src) - RE_MAP[src] = dst -RE_PREPROCESSOR = re.compile(RE_TRIE.pattern()) - - -def re_replace(input_string): - def sub_repl(m): - return RE_MAP[m.group(0)] - - return RE_PREPROCESSOR.sub(sub_repl, input_string) - - -def preprocessor(project_directory, output_directory, filepath): - """Executes the CUDA -> HIP conversion on the specified file.""" - fin_path = os.path.join(project_directory, filepath) - with open(fin_path, "r") as fin: - output_source = fin.read() - - fout_path = os.path.join(output_directory, get_hip_file_path(filepath)) - assert os.path.join(output_directory, fout_path) != os.path.join( - project_directory, fin_path - ) - if not os.path.exists(os.path.dirname(fout_path)): - os.makedirs(os.path.dirname(fout_path)) - - with open(fout_path, "w") as fout: - output_source = re_replace(output_source) - - # Perform Kernel Launch Replacements - output_source = processKernelLaunches(output_source) - - fout.write(output_source) - - -def extract_arguments(start, string): - """Return the list of arguments in the upcoming function parameter closure. - Example: - string (input): '(blocks, threads, 0, THCState_getCurrentStream(state))' - arguments (output): - '[{'start': 1, 'end': 7}, - {'start': 8, 'end': 16}, - {'start': 17, 'end': 19}, - {'start': 20, 'end': 53}]' - """ - - arguments = [] - closures = {"<": 0, "(": 0} - current_position = start - argument_start_pos = current_position + 1 - - # Search for final parenthesis - while current_position < len(string): - if string[current_position] == "(": - closures["("] += 1 - elif string[current_position] == ")": - closures["("] -= 1 - elif string[current_position] == "<": - closures["<"] += 1 - elif ( - string[current_position] == ">" - and string[current_position - 1] != "-" - and closures["<"] > 0 - ): - closures["<"] -= 1 - - # Finished all arguments - if closures["("] == 0 and closures["<"] == 0: - # Add final argument - arguments.append({"start": argument_start_pos, "end": current_position}) - break - - # Finished current argument - if ( - closures["("] == 1 - and closures["<"] == 0 - and string[current_position] == "," - ): - arguments.append({"start": argument_start_pos, "end": current_position}) - argument_start_pos = current_position + 1 - - current_position += 1 - - return arguments - - -def hipify( - project_directory, - extensions=(".cu", ".cuh", ".c", ".cc", ".cpp", ".h", ".in", ".hpp"), - output_directory=None, - includes=(), - ignores=(), - list_files_only=False, - show_progress=True, -): - assert os.path.exists(project_directory) - - # If no output directory, provide a default one. - if not output_directory: - output_directory = os.path.join(project_directory, "hip") - - all_files = list( - matched_files_iter( - project_directory, includes=includes, ignores=ignores, extensions=extensions - ) - ) - if list_files_only: - print(os.linesep.join(all_files)) - return - - # Start Preprocessor - preprocess( - project_directory, output_directory, all_files, show_progress=show_progress - )