From 643eb7ace71f4980059231d4b2f0fd832a77f8fd Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 5 Oct 2017 16:38:36 +0300 Subject: [PATCH 1/3] [HIPIFY] CUDA RT Textures and Arrays support update [ROCm/hip commit: 53ce40ebab5a608dee7d8ba159664d00f76f186a] --- ..._Runtime_API_functions_supported_by_HIP.md | 23 ++++++++++++------- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 14 +++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/projects/hip/docs/markdown/CUDA_Runtime_API_functions_supported_by_HIP.md b/projects/hip/docs/markdown/CUDA_Runtime_API_functions_supported_by_HIP.md index 73994026e3..f27f1538b7 100644 --- a/projects/hip/docs/markdown/CUDA_Runtime_API_functions_supported_by_HIP.md +++ b/projects/hip/docs/markdown/CUDA_Runtime_API_functions_supported_by_HIP.md @@ -135,7 +135,7 @@ | `cudaMemcpy` | `hipMemcpy` | | `cudaMemcpy2D` | `hipMemcpy2D` | | `cudaMemcpy2DArrayToArray` | | -| `cudaMemcpy2DAsync` | | +| `cudaMemcpy2DAsync` | `hipMemcpy2DAsync` | | `cudaMemcpy2DFromArray` | | | `cudaMemcpy2DFromArrayAsync` | | | `cudaMemcpy2DToArray` | `hipMemcpy2DToArray` | @@ -743,17 +743,17 @@ | typedef | `cudaStream_t` | `hipStream_t` | | typedef | `cudaStreamCallback_t` | `hipStreamCallback_t` | | typedef | `cudaSurfaceObject_t` | | -| typedef | `cudaTextureObject_t` | | +| typedef | `cudaTextureObject_t` | `hipTextureObject_t` | | typedef | `CUuuid_stcudaUUID_t` | | | define | `CUDA_IPC_HANDLE_SIZE` | | -| define | `cudaArrayCubemap` | | -| define | `cudaArrayDefault` | | -| define | `cudaArrayLayered` | | -| define | `cudaArraySurfaceLoadStore` | | -| define | `cudaArrayTextureGather` | | +| define | `cudaArrayCubemap` | `hipArrayCubemap` | +| define | `cudaArrayDefault` | `hipArrayDefault` | +| define | `cudaArrayLayered` | `hipArrayLayered` | +| define | `cudaArraySurfaceLoadStore` | `hipArraySurfaceLoadStore` | +| define | `cudaArrayTextureGather` | `hipArrayTextureGather` | | define | `cudaDeviceBlockingSync` | `hipDeviceScheduleBlockingSync` | | define | `cudaDeviceLmemResizeToMax` | | -| define | `cudaDeviceMapHost` | | +| define | `cudaDeviceMapHost` | `hipDeviceMapHost` | | define | `cudaDeviceMask` | | | define | `cudaDevicePropDontCare` | | | define | `cudaDeviceScheduleAuto` | `hipDeviceScheduleAuto` | @@ -783,3 +783,10 @@ | define | `cudaStreamLegacy` | | | define | `cudaStreamNonBlocking` | `hipStreamNonBlocking` | | define | `cudaStreamPerThread` | | +| define | `cudaTextureType1D` | `hipTextureType1D` | +| define | `cudaTextureType2D` | `hipTextureType2D` | +| define | `cudaTextureType3D` | `hipTextureType3D` | +| define | `cudaTextureTypeCubemap` | `hipTextureTypeCubemap` | +| define | `cudaTextureType1DLayered` | `hipTextureType1DLayered` | +| define | `cudaTextureType2DLayered` | `hipTextureType2DLayered` | +| define | `cudaTextureTypeCubemapLayered` | `hipTextureTypeCubemapLayered` | diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 553ea5d8af..1f49313b56 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -1379,6 +1379,12 @@ struct cuda2hipMap { cuda2hipRename["cudaMipmappedArray_t"] = {"hipMipmappedArray_t", CONV_MEM, API_RUNTIME}; cuda2hipRename["cudaMipmappedArray_const_t"] = {"hipMipmappedArray_const_t", CONV_MEM, API_RUNTIME}; + cuda2hipRename["cudaArrayDefault"] = {"hipArrayDefault", CONV_MEM, API_RUNTIME}; // 0x00 + cuda2hipRename["cudaArrayLayered"] = {"hipArrayLayered", CONV_MEM, API_RUNTIME}; // 0x01 // Unsupported yet on NVCC path + cuda2hipRename["cudaArraySurfaceLoadStore"] = {"hipArraySurfaceLoadStore", CONV_MEM, API_RUNTIME}; // 0x02 // Unsupported yet on NVCC path + cuda2hipRename["cudaArrayCubemap"] = {"hipArrayCubemap", CONV_MEM, API_RUNTIME}; // 0x04 // Unsupported yet on NVCC path + cuda2hipRename["cudaArrayTextureGather"] = {"hipArrayTextureGather", CONV_MEM, API_RUNTIME}; // 0x08 // Unsupported yet on NVCC path + // memcpy // memcpy structs cuda2hipRename["cudaMemcpy3DParms"] = {"hipMemcpy3DParms", CONV_MEM, API_RUNTIME}; @@ -1903,6 +1909,14 @@ struct cuda2hipMap { cuda2hipRename["cudaAddressModeMirror"] = {"hipAddressModeMirror", CONV_TEX, API_RUNTIME}; cuda2hipRename["cudaAddressModeBorder"] = {"hipAddressModeBorder", CONV_TEX, API_RUNTIME}; + cuda2hipRename["cudaTextureType1D"] = {"hipTextureType1D", CONV_TEX, API_RUNTIME}; // 0x01 // Unsupported yet on NVCC path + cuda2hipRename["cudaTextureType2D"] = {"hipTextureType2D", CONV_TEX, API_RUNTIME}; // 0x02 + cuda2hipRename["cudaTextureType3D"] = {"hipTextureType3D", CONV_TEX, API_RUNTIME}; // 0x03 // Unsupported yet on NVCC path + cuda2hipRename["cudaTextureTypeCubemap"] = {"hipTextureTypeCubemap", CONV_TEX, API_RUNTIME}; // 0x0C // Unsupported yet on NVCC path + cuda2hipRename["cudaTextureType1DLayered"] = {"hipTextureType1DLayered", CONV_TEX, API_RUNTIME}; // 0xF1 // Unsupported yet on NVCC path + cuda2hipRename["cudaTextureType2DLayered"] = {"hipTextureType2DLayered", CONV_TEX, API_RUNTIME}; // 0xF2 // Unsupported yet on NVCC path + cuda2hipRename["cudaTextureTypeCubemapLayered"] = {"hipTextureTypeCubemapLayered", CONV_TEX, API_RUNTIME}; // 0xFC // Unsupported yet on NVCC path + // functions cuda2hipRename["cudaCreateTextureObject"] = {"hipCreateTextureObject", CONV_TEX, API_RUNTIME}; cuda2hipRename["cudaDestroyTextureObject"] = {"hipDestroyTextureObject", CONV_TEX, API_RUNTIME}; From 75508281a5dcc5bdd42795a28366fa3b3c9f7bfc Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Mon, 9 Oct 2017 20:28:20 +0300 Subject: [PATCH 2/3] [HIPIFY] cmake changes + standalone build support + WIN MSVC support + disable lit testing by default + to enable lit testing -DHIPIFY_CLANG_TESTS=1 should be specified Tested builds: + hipify-clang standalone {Ubuntu 16.04|Windows 10} {Debug|Release} {x86|x64a} {g++|clang++|MSVC 2017} {llvm 3.8.0|llvm 3.9.0} {-DHIPIFY_CLANG_TESTS=1| } + HIP {-DHIPIFY_CLANG_LLVM_DIR=..|} {Ubuntu 16.04} {Debug|Release} {x86|x64a} {hcc} {llvm 3.8.0|llvm 3.9.0} {-DHIPIFY_CLANG_TESTS=1| } [ROCm/hip commit: 87cf949d3906d2bad1efedb42ea2fd04eace21f1] --- projects/hip/hipify-clang/CMakeLists.txt | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/projects/hip/hipify-clang/CMakeLists.txt b/projects/hip/hipify-clang/CMakeLists.txt index 872db3defe..1aaa68097f 100644 --- a/projects/hip/hipify-clang/CMakeLists.txt +++ b/projects/hip/hipify-clang/CMakeLists.txt @@ -1,14 +1,16 @@ cmake_minimum_required(VERSION 2.8.8) project(hipify-clang) -set(BUILD_HIPIFY_CLANG 0 PARENT_SCOPE) +if (PARENT_SCOPE) + set(BUILD_HIPIFY_CLANG 0 PARENT_SCOPE) +endif() # Find LLVM package find_package(LLVM 3.8 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH) if (NOT ${LLVM_FOUND}) find_package(LLVM 3.9 QUIET PATHS ${HIPIFY_CLANG_LLVM_DIR} NO_DEFAULT_PATH) if (NOT ${LLVM_FOUND}) - message(STATUS "hipify-clang will not be built. To build it please specify absolute path to LLVM 3.8 or LLVM 3.9 package using -DHIPIFY_CLANG_LLVM_DIR") + message(STATUS "hipify-clang will not be built. To build it please specify absolute path to LLVM 3.8 or LLVM 3.9 package/dist using -DHIPIFY_CLANG_LLVM_DIR") endif() endif() if (${LLVM_FOUND}) @@ -21,12 +23,11 @@ if (${LLVM_FOUND}) link_directories(${LLVM_LIBRARY_DIRS}) add_definitions(${LLVM_DEFINITIONS}) add_llvm_executable(hipify-clang src/Cuda2Hip.cpp) - find_program(LIT_COMMAND lit) set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++) set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang) - # Link against LLVM and CLANG tools libraries + # Link against LLVM and CLANG libraries target_link_libraries(hipify-clang clangASTMatchers clangFrontend @@ -51,22 +52,35 @@ if (${LLVM_FOUND}) LLVMOption LLVMCore) +if(WIN32) + target_link_libraries(hipify-clang version) +endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR- /EHs- /EHc-") + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS") +else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -fno-rtti -fvisibility-inlines-hidden") +endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHIPIFY_CLANG_RES=\\\"${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}\\\"") install(TARGETS hipify-clang DESTINATION bin) +if (HIPIFY_CLANG_TESTS) # tests set(Python_ADDITIONAL_VERSIONS 2.7) include(FindPythonInterp) if(NOT PYTHONINTERP_FOUND) message(FATAL_ERROR - "Unable to find Python interpreter, required for builds and testing\n\n" + "Unable to find Python interpreter, required for builds and testing.\n\n" "Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") endif() + find_program(LIT_COMMAND lit) + set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) configure_file( @@ -83,8 +97,10 @@ if (${LLVM_FOUND}) add_custom_target(test-hipify-clang) add_dependencies(test-hipify-clang test-hipify) set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests") +endif() +if (PARENT_SCOPE) set(BUILD_HIPIFY_CLANG 1 PARENT_SCOPE) endif() -# vim: ts=4:sw=4:expandtab:smartindent +endif() From 0162211c2823195d7c07430dc6a656ee71638d07 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 12 Oct 2017 20:05:42 +0300 Subject: [PATCH 3/3] [HIPIFY][#199][Partial fix] Fix for cudaLaunchKernel transformation [Synopsis] If any of kernel arguments is a MACRO its location calculation is wrong (location of its definition is actually calculated). Thus garbage code is being produced on the place of such a MACRO starting from the end of its actual definition. [Solution] Add isMacroBodyExpansion and isMacroArgExpansion checks on kernel arguments. [ROCm/hip commit: 7ee8e2d51b2167de7d24f0e64f21a063d874570d] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 1f49313b56..a1af37bf7c 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -3314,7 +3314,17 @@ private: for (unsigned argno = 0; argno < launchKernel->getNumArgs(); argno++) { const Expr *arg = launchKernel->getArg(argno); SourceLocation sl(arg->getLocStart()); + if (SM->isMacroBodyExpansion(sl)) { + sl = SM->getExpansionLoc(sl); + } else if (SM->isMacroArgExpansion(sl)) { + sl = SM->getImmediateSpellingLoc(sl); + } SourceLocation el(arg->getLocEnd()); + if (SM->isMacroBodyExpansion(el)) { + el = SM->getExpansionLoc(el); + } else if (SM->isMacroArgExpansion(el)) { + el = SM->getImmediateSpellingLoc(el); + } SourceLocation stop = Lexer::getLocForEndOfToken(el, 0, *SM, DefaultLangOptions); std::string outs(SM->getCharacterData(sl), SM->getCharacterData(stop) - SM->getCharacterData(sl)); DEBUG(dbgs() << outs << "\n");