From e34249f786dd9199de7107af4d4b9de84943a280 Mon Sep 17 00:00:00 2001 From: Aakanksha Patil Date: Mon, 4 Nov 2024 11:27:49 -0500 Subject: [PATCH 1/4] Introduce files for cutensor support + Add support for tensorStatus --- CMakeLists.txt | 7 +++ src/CUDA2HIP_TENSOR_API_functions.cpp | 23 ++++++++ src/CUDA2HIP_TENSOR_API_types.cpp | 53 +++++++++++++++++++ .../synthetic/libraries/cutensor2hiptensor.cu | 39 ++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/CUDA2HIP_TENSOR_API_functions.cpp create mode 100644 src/CUDA2HIP_TENSOR_API_types.cpp create mode 100644 tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu diff --git a/CMakeLists.txt b/CMakeLists.txt index 689d7328..be1c01c6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,6 +278,7 @@ if(HIPIFY_CLANG_TESTS OR HIPIFY_CLANG_TESTS_ONLY) set(CUDA_TOOLKIT_ROOT_DIR "" CACHE PATH "Path to CUDA Toolkit to use in hipify-clang unit testing") set(CUDA_SDK_ROOT_DIR "" CACHE PATH "Path to CUDA Toolkit Samples") set(CUDA_DNN_ROOT_DIR "" CACHE PATH "Path to cuDNN") + set(CUDA_TENSOR_ROOT_DIR "" CACHE PATH "Path to cuTENSOR") set(CUDA_CUB_ROOT_DIR "" CACHE PATH "Path to CUB") if(NOT CUDA_TOOLKIT_ROOT_DIR STREQUAL "" AND NOT CUDA_TOOLKIT_ROOT_DIR MATCHES "OFF") @@ -294,6 +295,7 @@ if(HIPIFY_CLANG_TESTS OR HIPIFY_CLANG_TESTS_ONLY) message(STATUS " - CUDA Toolkit path : ${CUDA_TOOLKIT_ROOT_DIR}") message(STATUS " - CUDA Samples path : ${CUDA_SDK_ROOT_DIR}") message(STATUS " - cuDNN path : ${CUDA_DNN_ROOT_DIR}") + message(STATUS " - cuTENSOR path : ${CUDA_TENSOR_ROOT_DIR}") message(STATUS " - CUB path : ${CUDA_CUB_ROOT_DIR}") if(${CMAKE_VERSION} VERSION_LESS "3.27.0") @@ -332,6 +334,10 @@ if(HIPIFY_CLANG_TESTS OR HIPIFY_CLANG_TESTS_ONLY) set(CUDA_DNN_ROOT_DIR OFF) endif() + if(CUDA_TENSOR_ROOT_DIR STREQUAL "") + set(CUDA_TENSOR_ROOT_DIR OFF) + endif() + if(CUDA_CUB_ROOT_DIR STREQUAL "") if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0") if(WIN32 OR (UNIX AND CUDA_VERSION VERSION_LESS "11.4" OR CUDA_VERSION VERSION_GREATER_EQUAL "11.6")) @@ -348,6 +354,7 @@ if(HIPIFY_CLANG_TESTS OR HIPIFY_CLANG_TESTS_ONLY) message(STATUS " - CUDA Toolkit path : ${CUDA_TOOLKIT_ROOT_DIR}") message(STATUS " - CUDA Samples path : ${CUDA_SDK_ROOT_DIR}") message(STATUS " - cuDNN path : ${CUDA_DNN_ROOT_DIR}") + message(STATUS " - cuTENSOR path : ${CUDA_TENSOR_ROOT_DIR}") message(STATUS " - CUB path : ${CUDA_CUB_ROOT_DIR}") if((CUDA_VERSION VERSION_LESS "7.0") OR (LLVM_PACKAGE_VERSION VERSION_LESS "3.8") OR diff --git a/src/CUDA2HIP_TENSOR_API_functions.cpp b/src/CUDA2HIP_TENSOR_API_functions.cpp new file mode 100644 index 00000000..286321a5 --- /dev/null +++ b/src/CUDA2HIP_TENSOR_API_functions.cpp @@ -0,0 +1,23 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, 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. +*/ + + diff --git a/src/CUDA2HIP_TENSOR_API_types.cpp b/src/CUDA2HIP_TENSOR_API_types.cpp new file mode 100644 index 00000000..784f6424 --- /dev/null +++ b/src/CUDA2HIP_TENSOR_API_types.cpp @@ -0,0 +1,53 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, 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. +*/ + +#include "CUDA2HIP.h" + +// Map of all functions +const std::map CUDA_TENSOR_TYPE_NAME_MAP { + // cuTENSOR defines + + + // cuTENSOR enums + {"cutensorDataType_t", {"", "", CONV_TYPE, API_TENSOR, 1, HIP_UNSUPPORTED}}, + {"cutensorOperator_t", {"", "", CONV_TYPE, API_TENSOR, 1, HIP_UNSUPPORTED}}, + + {"cutensorStatus_t", {"hiptensorStatus_t", "", CONV_TYPE, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_SUCCESS", {"HIPTENSOR_STATUS_SUCCESS", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_NOT_INITIALIZED", {"HIPTENSOR_STATUS_NOT_INITIALIZED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_ALLOC_FAILED", {"HIPTENSOR_STATUS_ALLOC_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_INVALID_VALUE", {"HIPTENSOR_STATUS_INVALID_VALUE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_ARCH_MISMATCH", {"HIPTENSOR_STATUS_ARCH_MISMATCH", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_MAPPING_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_EXECUTION_FAILED", {"HIPTENSOR_STATUS_EXECUTION_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_INTERNAL_ERROR", {"HIPTENSOR_STATUS_INTERNAL_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_NOT_SUPPORTED", {"HIPTENSOR_STATUS_NOT_SUPPORTED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_LICENSE_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_CUBLAS_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_CUDA_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE", {"HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_INSUFFICIENT_DRIVER", {"HIPTENSOR_STATUS_INSUFFICIENT_DRIVER", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; + {"CUTENSOR_STATUS_IO_ERROR", {"HIPTENSOR_STATUS_IO_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; +} + +const std::map CUDA_TENSOR_TYPE_NAME_VER_MAP { + diff --git a/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu new file mode 100644 index 00000000..bf05608c --- /dev/null +++ b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu @@ -0,0 +1,39 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 3 --amap --skip-excluded-preprocessor-conditional-blocks --experimental %clang_args -D__CUDA_API_VERSION_INTERNAL -ferror-limit=500 + +// CHECK: #include +#include +#include +// CHECK: #include "hiptensor.h" +#include "cutensor.h" +// CHECK-NOT: #include "hiptensor.h" + +int main() { + + // CHECK: hiptensorStatus_t tensorStatus; + // CHECK: hiptensorStatus_t tensorStatus_t; + // CHECK-NEXT hiptensorStatus_t tensorStatus; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_SUCCESS HIPTENSOR_STATUS_SUCCESS; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_INITIALIZED HIPTENSOR_STATUS_NOT_INITIALIZED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ALLOC_FAILED HIPTENSOR_STATUS_ALLOC_FAILED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INVALID_VALUE HIPTENSOR_STATUS_INVALID_VALUE; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ARCH_MISMATCH HIPTENSOR_STATUS_ARCH_MISMATCH; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_EXECUTION_FAILED HIPTENSOR_STATUS_EXECUTION_FAILED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INTERNAL_ERROR HIPTENSOR_STATUS_INTERNAL_ERROR; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_SUPPORTED HIPTENSOR_STATUS_NOT_SUPPORTED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER HIPTENSOR_STATUS_INSUFFICIENT_DRIVER; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_IO_ERROR HIPTENSOR_STATUS_IO_ERROR; + cutensorStatus tensorStatus; + cutensorStatus_t tensorStatus_t; + cutensorStatus_t TENSOR_STATUS_SUCCESS = CUTENSOR_STATUS_SUCCESS; + cutensorStatus_t TENSOR_STATUS_NOT_INITIALIZED CUTENSOR_STATUS_NOT_INITIALIZED; + cutensorStatus_t TENSOR_STATUS_ALLOC_FAILED CUTENSOR_STATUS_ALLOC_FAILED; + cutensorStatus_t TENSOR_STATUS_INVALID_VALUE CUTENSOR_STATUS_INVALID_VALUE; + cutensorStatus_t TENSOR_STATUS_ARCH_MISMATCH CUTENSOR_STATUS_ARCH_MISMATCH; + cutensorStatus_t TENSOR_STATUS_EXECUTION_FAILED CUTENSOR_STATUS_EXECUTION_FAILED; + cutensorStatus_t TENSOR_STATUS_INTERNAL_ERROR CUTENSOR_STATUS_INTERNAL_ERROR; + cutensorStatus_t TENSOR_STATUS_NOT_SUPPORTED CUTENSOR_STATUS_NOT_SUPPORTED; + cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE; + cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER CUTENSOR_STATUS_INSUFFICIENT_DRIVER; + cutensorStatus_t TENSOR_STATUS_IO_ERROR CUTENSOR_STATUS_IO_ERROR; +} From 9d24bf6d287511485728c0163eac6a75ab6b03af Mon Sep 17 00:00:00 2001 From: Aakanksha Patil Date: Thu, 7 Nov 2024 11:37:33 -0500 Subject: [PATCH 2/4] Add missing support --- src/CUDA2HIP.cpp | 4 ++ src/CUDA2HIP.h | 4 ++ src/CUDA2HIP_TENSOR_API_functions.cpp | 3 ++ src/CUDA2HIP_TENSOR_API_types.cpp | 32 +++++++------- src/Statistics.cpp | 6 ++- src/Statistics.h | 1 + tests/lit.cfg | 26 ++++++++++- tests/lit.site.cfg.in | 1 + .../synthetic/libraries/cutensor2hiptensor.cu | 44 +++++++++---------- 9 files changed, 78 insertions(+), 43 deletions(-) diff --git a/src/CUDA2HIP.cpp b/src/CUDA2HIP.cpp index d6d8feb0..074ff2e0 100644 --- a/src/CUDA2HIP.cpp +++ b/src/CUDA2HIP.cpp @@ -67,6 +67,8 @@ const std::map CUDA_INCLUDE_MAP { {"curand_uniform.h", {"hiprand/hiprand_kernel.h", "rocrand/rocrand_uniform.h", CONV_INCLUDE, API_RAND, 0}}, // cuDNN includes {"cudnn.h", {"hipDNN.h", "miopen/miopen.h", CONV_INCLUDE_CUDA_MAIN_H, API_DNN, 0}}, + // cuTensor includes + {"cutensor.h", {"hiptensor.h", "", CONV_INCLUDE_CUDA_MAIN_H, API_TENSOR, 0}}, // cuFFT includes {"cufft.h", {"hipfft/hipfft.h", "", CONV_INCLUDE_CUDA_MAIN_H, API_FFT, 0}}, {"cufftXt.h", {"hipfft/hipfftXt.h", "", CONV_INCLUDE, API_FFT, 0}}, @@ -127,6 +129,8 @@ const std::map &CUDA_RENAMES_MAP() { ret.insert(CUDA_DEVICE_TYPE_NAME_MAP.begin(), CUDA_DEVICE_TYPE_NAME_MAP.end()); ret.insert(CUDA_SOLVER_TYPE_NAME_MAP.begin(), CUDA_SOLVER_TYPE_NAME_MAP.end()); ret.insert(CUDA_SOLVER_FUNCTION_MAP.begin(), CUDA_SOLVER_FUNCTION_MAP.end()); + ret.insert(CUDA_TENSOR_TYPE_NAME_MAP.begin(), CUDA_TENSOR_TYPE_NAME_MAP.end()); + ret.insert(CUDA_TENSOR_FUNCTION_MAP.begin(), CUDA_TENSOR_FUNCTION_MAP.end()); return ret; }; diff --git a/src/CUDA2HIP.h b/src/CUDA2HIP.h index b262f44b..382c6c05 100644 --- a/src/CUDA2HIP.h +++ b/src/CUDA2HIP.h @@ -85,6 +85,10 @@ extern const std::map CUDA_RTC_FUNCTION_MAP; extern const std::map CUDA_SOLVER_TYPE_NAME_MAP; // Maps the names of CUDA SOLVER API functions to the corresponding HIP functions extern const std::map CUDA_SOLVER_FUNCTION_MAP; +// Maps the names of CUDA TENSOR API types to the corresponding HIP types +extern const std::map CUDA_TENSOR_TYPE_NAME_MAP; +// Maps the names of CUDA TENSOR API functions to the corresponding HIP functions +extern const std::map CUDA_TENSOR_FUNCTION_MAP; /** * The union of all the above maps, except includes. diff --git a/src/CUDA2HIP_TENSOR_API_functions.cpp b/src/CUDA2HIP_TENSOR_API_functions.cpp index 286321a5..4b0b1d10 100644 --- a/src/CUDA2HIP_TENSOR_API_functions.cpp +++ b/src/CUDA2HIP_TENSOR_API_functions.cpp @@ -20,4 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "CUDA2HIP.h" +const std::map CUDA_TENSOR_FUNCTION_MAP { +}; diff --git a/src/CUDA2HIP_TENSOR_API_types.cpp b/src/CUDA2HIP_TENSOR_API_types.cpp index 784f6424..4f9cd4a9 100644 --- a/src/CUDA2HIP_TENSOR_API_types.cpp +++ b/src/CUDA2HIP_TENSOR_API_types.cpp @@ -33,21 +33,21 @@ const std::map CUDA_TENSOR_TYPE_NAME_MAP { {"cutensorStatus_t", {"hiptensorStatus_t", "", CONV_TYPE, API_TENSOR, 1}}, {"CUTENSOR_STATUS_SUCCESS", {"HIPTENSOR_STATUS_SUCCESS", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, - {"CUTENSOR_STATUS_NOT_INITIALIZED", {"HIPTENSOR_STATUS_NOT_INITIALIZED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_ALLOC_FAILED", {"HIPTENSOR_STATUS_ALLOC_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_INVALID_VALUE", {"HIPTENSOR_STATUS_INVALID_VALUE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_ARCH_MISMATCH", {"HIPTENSOR_STATUS_ARCH_MISMATCH", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_MAPPING_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_EXECUTION_FAILED", {"HIPTENSOR_STATUS_EXECUTION_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_INTERNAL_ERROR", {"HIPTENSOR_STATUS_INTERNAL_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_NOT_SUPPORTED", {"HIPTENSOR_STATUS_NOT_SUPPORTED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_LICENSE_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_CUBLAS_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_CUDA_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE", {"HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_INSUFFICIENT_DRIVER", {"HIPTENSOR_STATUS_INSUFFICIENT_DRIVER", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; - {"CUTENSOR_STATUS_IO_ERROR", {"HIPTENSOR_STATUS_IO_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}; -} + {"CUTENSOR_STATUS_NOT_INITIALIZED", {"HIPTENSOR_STATUS_NOT_INITIALIZED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_ALLOC_FAILED", {"HIPTENSOR_STATUS_ALLOC_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_INVALID_VALUE", {"HIPTENSOR_STATUS_INVALID_VALUE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_ARCH_MISMATCH", {"HIPTENSOR_STATUS_ARCH_MISMATCH", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_MAPPING_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_EXECUTION_FAILED", {"HIPTENSOR_STATUS_EXECUTION_FAILED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_INTERNAL_ERROR", {"HIPTENSOR_STATUS_INTERNAL_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_NOT_SUPPORTED", {"HIPTENSOR_STATUS_NOT_SUPPORTED", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_LICENSE_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_CUBLAS_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_CUDA_ERROR", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE", {"HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_INSUFFICIENT_DRIVER", {"HIPTENSOR_STATUS_INSUFFICIENT_DRIVER", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_STATUS_IO_ERROR", {"HIPTENSOR_STATUS_IO_ERROR", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, +}; const std::map CUDA_TENSOR_TYPE_NAME_VER_MAP { - +}; diff --git a/src/Statistics.cpp b/src/Statistics.cpp index ba625fab..84596f00 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -145,7 +145,8 @@ const char *apiNames[NUM_API_TYPES] = { "cuSOLVER API", "CUB API", "CAFFE2 API", - "RTC API" + "RTC API", + "TENSOR API" }; const char *apiTypes[NUM_API_TYPES] = { @@ -160,7 +161,8 @@ const char *apiTypes[NUM_API_TYPES] = { "API_SPARSE", "API_SOLVER", "API_CAFFE2", - "API_RTC" + "API_RTC", + "API_TENSOR" }; namespace { diff --git a/src/Statistics.h b/src/Statistics.h index 0206c450..7a1baa34 100644 --- a/src/Statistics.h +++ b/src/Statistics.h @@ -178,6 +178,7 @@ enum ApiTypes { API_CUB, API_CAFFE2, API_RTC, + API_TENSOR, API_LAST }; constexpr int NUM_API_TYPES = (int) ApiTypes::API_LAST; diff --git a/tests/lit.cfg b/tests/lit.cfg index 074bf3ee..678cc760 100644 --- a/tests/lit.cfg +++ b/tests/lit.cfg @@ -248,6 +248,10 @@ if config.cuda_dnn_root and config.cuda_dnn_root != "OFF": if config.cuda_cub_root and config.cuda_cub_root != "OFF": clang_arguments += " -I'%s'" +# cuTensor ROOT +if config.cuda_tensor_root and config.cuda_tensor_root != "OFF": + clang_arguments += " -I'%s'/include" + i_subst = 0 if config.cuda_sdk_root != "OFF": i_subst = 1 @@ -255,8 +259,26 @@ if config.cuda_dnn_root != "OFF": i_subst += 2 if config.cuda_cub_root != "OFF": i_subst += 4 - -if i_subst == 7: +if config.cuda_tensor_root != "OFF": + i_subst += 8 + +if i_subst == 15: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_sdk_root, config.cuda_dnn_root, config.cuda_cub_root, config.cuda_tensor_root))) +elif i_subst == 14: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_dnn_root, config.cuda_cub_root, config.cuda_tensor_root))) +elif i_subst == 13: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_sdk_root, config.cuda_cub_root, config.cuda_tensor_root))) +elif i_subst == 12: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_cub_root, config.cuda_tensor_root))) +elif i_subst == 11: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_sdk_root, config.cuda_dnn_root, config.cuda_tensor_root))) +elif i_subst == 10: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_dnn_root, config.cuda_tensor_root))) +elif i_subst == 9: + config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_sdk_root, config.cuda_tensor_root))) +elif i_subst == 8: + config.substitutions.append(("%clang_args", clang_arguments % config.cuda_tensor_root)) +elif i_subst == 7: config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_sdk_root, config.cuda_dnn_root, config.cuda_cub_root))) elif i_subst == 6: config.substitutions.append(("%clang_args", clang_arguments % (config.cuda_dnn_root, config.cuda_cub_root))) diff --git a/tests/lit.site.cfg.in b/tests/lit.site.cfg.in index 9ca7bbc8..6bc74b6a 100644 --- a/tests/lit.site.cfg.in +++ b/tests/lit.site.cfg.in @@ -12,6 +12,7 @@ config.cuda_root = "@CUDA_TOOLKIT_ROOT_DIR@" config.cuda_sdk_root = "@CUDA_SDK_ROOT_DIR@" config.cuda_dnn_root = "@CUDA_DNN_ROOT_DIR@" config.cuda_cub_root = "@CUDA_CUB_ROOT_DIR@" +config.cuda_tensor_root = "@CUDA_TENSOR_ROOT_DIR@" config.cuda_version_major = int("@CUDA_VERSION_MAJOR@") config.cuda_version_minor = int("@CUDA_VERSION_MINOR@") config.cuda_version_full = "@CUDA_VERSION_FULL@" diff --git a/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu index bf05608c..d031d2d8 100644 --- a/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu +++ b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu @@ -9,31 +9,29 @@ int main() { - // CHECK: hiptensorStatus_t tensorStatus; // CHECK: hiptensorStatus_t tensorStatus_t; // CHECK-NEXT hiptensorStatus_t tensorStatus; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_SUCCESS HIPTENSOR_STATUS_SUCCESS; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_INITIALIZED HIPTENSOR_STATUS_NOT_INITIALIZED; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ALLOC_FAILED HIPTENSOR_STATUS_ALLOC_FAILED; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INVALID_VALUE HIPTENSOR_STATUS_INVALID_VALUE; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ARCH_MISMATCH HIPTENSOR_STATUS_ARCH_MISMATCH; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_EXECUTION_FAILED HIPTENSOR_STATUS_EXECUTION_FAILED; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INTERNAL_ERROR HIPTENSOR_STATUS_INTERNAL_ERROR; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_SUPPORTED HIPTENSOR_STATUS_NOT_SUPPORTED; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER HIPTENSOR_STATUS_INSUFFICIENT_DRIVER; - // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_IO_ERROR HIPTENSOR_STATUS_IO_ERROR; - cutensorStatus tensorStatus; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_SUCCESS = HIPTENSOR_STATUS_SUCCESS; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_INITIALIZED = HIPTENSOR_STATUS_NOT_INITIALIZED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ALLOC_FAILED = HIPTENSOR_STATUS_ALLOC_FAILED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INVALID_VALUE = HIPTENSOR_STATUS_INVALID_VALUE; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_ARCH_MISMATCH = HIPTENSOR_STATUS_ARCH_MISMATCH; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_EXECUTION_FAILED = HIPTENSOR_STATUS_EXECUTION_FAILED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INTERNAL_ERROR = HIPTENSOR_STATUS_INTERNAL_ERROR; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_NOT_SUPPORTED = HIPTENSOR_STATUS_NOT_SUPPORTED; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE = HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER = HIPTENSOR_STATUS_INSUFFICIENT_DRIVER; + // CHECK-NEXT hiptensorStatus_t TENSOR_STATUS_IO_ERROR = HIPTENSOR_STATUS_IO_ERROR; cutensorStatus_t tensorStatus_t; cutensorStatus_t TENSOR_STATUS_SUCCESS = CUTENSOR_STATUS_SUCCESS; - cutensorStatus_t TENSOR_STATUS_NOT_INITIALIZED CUTENSOR_STATUS_NOT_INITIALIZED; - cutensorStatus_t TENSOR_STATUS_ALLOC_FAILED CUTENSOR_STATUS_ALLOC_FAILED; - cutensorStatus_t TENSOR_STATUS_INVALID_VALUE CUTENSOR_STATUS_INVALID_VALUE; - cutensorStatus_t TENSOR_STATUS_ARCH_MISMATCH CUTENSOR_STATUS_ARCH_MISMATCH; - cutensorStatus_t TENSOR_STATUS_EXECUTION_FAILED CUTENSOR_STATUS_EXECUTION_FAILED; - cutensorStatus_t TENSOR_STATUS_INTERNAL_ERROR CUTENSOR_STATUS_INTERNAL_ERROR; - cutensorStatus_t TENSOR_STATUS_NOT_SUPPORTED CUTENSOR_STATUS_NOT_SUPPORTED; - cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE; - cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER CUTENSOR_STATUS_INSUFFICIENT_DRIVER; - cutensorStatus_t TENSOR_STATUS_IO_ERROR CUTENSOR_STATUS_IO_ERROR; + cutensorStatus_t TENSOR_STATUS_NOT_INITIALIZED = CUTENSOR_STATUS_NOT_INITIALIZED; + cutensorStatus_t TENSOR_STATUS_ALLOC_FAILED = CUTENSOR_STATUS_ALLOC_FAILED; + cutensorStatus_t TENSOR_STATUS_INVALID_VALUE = CUTENSOR_STATUS_INVALID_VALUE; + cutensorStatus_t TENSOR_STATUS_ARCH_MISMATCH = CUTENSOR_STATUS_ARCH_MISMATCH; + cutensorStatus_t TENSOR_STATUS_EXECUTION_FAILED = CUTENSOR_STATUS_EXECUTION_FAILED; + cutensorStatus_t TENSOR_STATUS_INTERNAL_ERROR = CUTENSOR_STATUS_INTERNAL_ERROR; + cutensorStatus_t TENSOR_STATUS_NOT_SUPPORTED = CUTENSOR_STATUS_NOT_SUPPORTED; + cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_WORKSPACE = CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE; + cutensorStatus_t TENSOR_STATUS_INSUFFICIENT_DRIVER = CUTENSOR_STATUS_INSUFFICIENT_DRIVER; + cutensorStatus_t TENSOR_STATUS_IO_ERROR = CUTENSOR_STATUS_IO_ERROR; } From 32668274c61dab2d33701a6b8915ed1c65aa8075 Mon Sep 17 00:00:00 2001 From: Aakanksha Patil Date: Thu, 14 Nov 2024 11:56:53 -0500 Subject: [PATCH 3/4] Add cuTensor support in hipify-perl --- bin/hipify-perl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/hipify-perl b/bin/hipify-perl index d6ae392a..e3ebea98 100755 --- a/bin/hipify-perl +++ b/bin/hipify-perl @@ -6159,6 +6159,7 @@ sub simpleSubstitutions { subst("cuda.h", "hip\/hip_runtime.h", "include_cuda_main_header"); subst("cuda_runtime.h", "hip\/hip_runtime.h", "include_cuda_main_header"); subst("cudnn.h", "hipDNN.h", "include_cuda_main_header"); + subst("cutensor.h", "hiptensor.h", "include"); subst("cufft.h", "hipfft\/hipfft.h", "include_cuda_main_header"); subst("curand.h", "hiprand\/hiprand.h", "include_cuda_main_header"); subst("cusolverDn.h", "hipsolver.h", "include_cuda_main_header"); @@ -6655,6 +6656,7 @@ sub simpleSubstitutions { subst("cudnnStatus_t", "hipdnnStatus_t", "type"); subst("cudnnTensorDescriptor_t", "hipdnnTensorDescriptor_t", "type"); subst("cudnnTensorFormat_t", "hipdnnTensorFormat_t", "type"); + subst("cutensorStatus_t", "hiptensorStatus_t", "type"); subst("cufftComplex", "hipfftComplex", "type"); subst("cufftDoubleComplex", "hipfftDoubleComplex", "type"); subst("cufftDoubleReal", "hipfftDoubleReal", "type"); From bf8edebf5754a82a728208df614500eca7d3392f Mon Sep 17 00:00:00 2001 From: Aakanksha Patil Date: Mon, 18 Nov 2024 00:34:47 -0500 Subject: [PATCH 4/4] Revert "Add cuTensor support in hipify-perl" This reverts commit 32668274c61dab2d33701a6b8915ed1c65aa8075. hipify-perl is auto generated --- bin/hipify-perl | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/hipify-perl b/bin/hipify-perl index e3ebea98..d6ae392a 100755 --- a/bin/hipify-perl +++ b/bin/hipify-perl @@ -6159,7 +6159,6 @@ sub simpleSubstitutions { subst("cuda.h", "hip\/hip_runtime.h", "include_cuda_main_header"); subst("cuda_runtime.h", "hip\/hip_runtime.h", "include_cuda_main_header"); subst("cudnn.h", "hipDNN.h", "include_cuda_main_header"); - subst("cutensor.h", "hiptensor.h", "include"); subst("cufft.h", "hipfft\/hipfft.h", "include_cuda_main_header"); subst("curand.h", "hiprand\/hiprand.h", "include_cuda_main_header"); subst("cusolverDn.h", "hipsolver.h", "include_cuda_main_header"); @@ -6656,7 +6655,6 @@ sub simpleSubstitutions { subst("cudnnStatus_t", "hipdnnStatus_t", "type"); subst("cudnnTensorDescriptor_t", "hipdnnTensorDescriptor_t", "type"); subst("cudnnTensorFormat_t", "hipdnnTensorFormat_t", "type"); - subst("cutensorStatus_t", "hiptensorStatus_t", "type"); subst("cufftComplex", "hipfftComplex", "type"); subst("cufftDoubleComplex", "hipfftDoubleComplex", "type"); subst("cufftDoubleReal", "hipfftDoubleReal", "type");