diff --git a/clang/lib/DPCT/ASTTraversal.cpp b/clang/lib/DPCT/ASTTraversal.cpp index 35a7eea5cb5f..427f0c4fcc8c 100644 --- a/clang/lib/DPCT/ASTTraversal.cpp +++ b/clang/lib/DPCT/ASTTraversal.cpp @@ -27,6 +27,7 @@ #include "RulesSHMEM/NVSHMEMAPIMigration.h" #include "RulesSecurity/Homoglyph.h" #include "RulesSecurity/MisleadingBidirectional.h" +#include "RulesTensor/CUTensorAPIMigration.h" #include "TextModification.h" #include "Utility.h" @@ -197,5 +198,7 @@ REGISTER_RULE(CuDNNAPIRule, PassKind::PK_Migration, RuleGroupKind::RK_DNN) REGISTER_RULE(NVSHMEMRule, PassKind::PK_Migration, RuleGroupKind::RK_NVSHMEM) +REGISTER_RULE(CUTensorRule, PassKind::PK_Migration, RuleGroupKind::RK_CUTensor) + } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index 161f72eb9bd9..ad53ffc063b6 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -203,6 +203,7 @@ add_clang_library(DPCT RulesLang/CallExprRewriterCG.cpp RulesLang/CallExprRewriterWmma.cpp RulesSHMEM/CallExprRewriterNvshmem.cpp + RulesTensor/CallExprRewriterCUTensor.cpp ErrorHandle/CrashRecovery.cpp Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp @@ -242,6 +243,7 @@ add_clang_library(DPCT RulesCCL/NCCLAPIMigration.cpp RuleInfra/TypeLocRewriters.cpp RulesSHMEM/NVSHMEMAPIMigration.cpp + RulesTensor/CUTensorAPIMigration.cpp Linux/AutoComplete.cpp RulesAsm/AsmMigration.cpp QueryAPIMapping/QueryAPIMapping.cpp diff --git a/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp b/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp index 72d009930e41..55afcc9e9ce9 100644 --- a/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp +++ b/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp @@ -134,13 +134,15 @@ std::optional FuncCallExprRewriter::buildRewriteString() { std::unique_ptr>> - CallExprRewriterFactoryBase::RewriterMap = std::make_unique>>(); + CallExprRewriterFactoryBase::RewriterMap = + std::make_unique>>(); std::unique_ptr>> - CallExprRewriterFactoryBase::MethodRewriterMap = std::make_unique>>(); + CallExprRewriterFactoryBase::MethodRewriterMap = + std::make_unique>>(); void CallExprRewriterFactoryBase::initRewriterMap() { if (DpctGlobalInfo::useSYCLCompat()) { @@ -162,6 +164,7 @@ void CallExprRewriterFactoryBase::initRewriterMap() { initRewriterMapMisc(); initRewriterMapNccl(); initRewriterMapNvshmem(); + initRewriterMapCUTensor(); initRewriterMapStream(); initRewriterMapTexture(); initRewriterMapThrust(); diff --git a/clang/lib/DPCT/RuleInfra/CallExprRewriter.h b/clang/lib/DPCT/RuleInfra/CallExprRewriter.h index 68656557abcb..8142ccd3def9 100644 --- a/clang/lib/DPCT/RuleInfra/CallExprRewriter.h +++ b/clang/lib/DPCT/RuleInfra/CallExprRewriter.h @@ -70,6 +70,7 @@ class CallExprRewriterFactoryBase { static void initRewriterMapMisc(); static void initRewriterMapNccl(); static void initRewriterMapNvshmem(); + static void initRewriterMapCUTensor(); static void initRewriterMapStream(); static void initRewriterMapTexture(); static void initRewriterMapThrust(); diff --git a/clang/lib/DPCT/RulesInclude/InclusionHeaders.h b/clang/lib/DPCT/RulesInclude/InclusionHeaders.h index 7e3c7c38db55..d6e89e8053c1 100644 --- a/clang/lib/DPCT/RulesInclude/InclusionHeaders.h +++ b/clang/lib/DPCT/RulesInclude/InclusionHeaders.h @@ -36,6 +36,7 @@ enum class RuleGroupKind : uint8_t { RK_CUB, RK_WMMA, RK_NVSHMEM, + RK_CUTensor, NUM }; diff --git a/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc b/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc index 49f19887ea34..4e64bcf6fdf5 100644 --- a/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc +++ b/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc @@ -112,3 +112,6 @@ REGIST_INCLUSION("nvshmem.h", FullMatch, NVSHMEM, Replace, false, HeaderType::HT_SHMEM) REGIST_INCLUSION("nvshmemx.h", FullMatch, NVSHMEM, Replace, false, HeaderType::HT_SHMEMX) + +REGIST_INCLUSION("cutensor.h", FullMatch, CUTensor, Remove, true) +REGIST_INCLUSION("cutensorMg.h", FullMatch, CUTensor, Remove, true) diff --git a/clang/lib/DPCT/RulesTensor/APINamesCUTensor.inc b/clang/lib/DPCT/RulesTensor/APINamesCUTensor.inc new file mode 100644 index 000000000000..d5172d6f3e3c --- /dev/null +++ b/clang/lib/DPCT/RulesTensor/APINamesCUTensor.inc @@ -0,0 +1,10 @@ +//===------------------------ APINamesCUTensor.inc ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Helper Functions +ENTRY_UNSUPPORTED("cutensorCreate", Diagnostics::API_NOT_MIGRATED) diff --git a/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp new file mode 100644 index 000000000000..17f8c9c88daf --- /dev/null +++ b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp @@ -0,0 +1,77 @@ +//===---------------------- CUTensorAPIMigration.cpp ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===-----------------------------------------------------------------------===// + +#include "CUTensorAPIMigration.h" +#include "RuleInfra/ExprAnalysis.h" + +using namespace clang::dpct; +using namespace clang::ast_matchers; + +void clang::dpct::CUTensorRule::registerMatcher(ast_matchers::MatchFinder &MF) { + auto CutensorAPIs = [&]() { + return hasAnyName( + // Helper Functions + "cutensorCreate", "cutensorDestroy", "cutensorCreateTensorDescriptor", + "cutensorDestroyTensorDescriptor", "cutensorGetErrorString", + "cutensorGetVersion", "cutensorGetCudartVersion", + // Element-wise Operations + "cutensorCreateElementwiseTrinary", "cutensorElementwiseTrinaryExecute", + "cutensorCreateElementwiseBinary", "cutensorElementwiseBinaryExecute", + "cutensorCreatePermutation", "cutensorPermute", + // Contraction Operations + "cutensorCreateContraction", "cutensorContract", + "cutensorCreateContractionTrinary", "cutensorContractTrinary", + // Reduction Operations + "cutensorCreateReduction", "cutensorReduce", + // Generic Operation Functions + "cutensorDestroyOperationDescriptor", + "cutensorOperationDescriptorGetAttribute", + "cutensorOperationDescriptorSetAttribute", + "cutensorCreatePlanPreference", "cutensorDestroyPlanPreference", + "cutensorPlanPreferenceSetAttribute", "cutensorEstimateWorkspaceSize", + "cutensorCreatePlan", "cutensorDestroyPlan", "cutensorPlanGetAttribute", + // Cache-related Operations + "cutensorHandleResizePlanCache", "cutensorHandleReadPlanCacheFromFile", + "cutensorHandleWritePlanCacheToFile", "cutensorReadKernelCacheFromFile", + "cutensorWriteKernelCacheToFile", + // Logger Functions + "cutensorLoggerSetCallback", "cutensorLoggerSetFile", + "cutensorLoggerOpenFile", "cutensorLoggerSetLevel", + "cutensorLoggerSetMask", "cutensorLoggerForceDisable", + // cuTENSORMg - General Operations + "cutensorMgCreate", "cutensorMgDestroy", + "cutensorMgCreateTensorDescriptor", "cutensorMgDestroyTensorDescriptor", + "cutensorMgCreateCopyDescriptor", "cutensorMgDestroyCopyDescriptor", + "cutensorMgCopyGetWorkspace", "cutensorMgCreateCopyPlan", + "cutensorMgDestroyCopyPlan", "cutensorMgCopy", + // cuTENSORMg - Contraction Operations + "cutensorMgCreateContractionDescriptor", + "cutensorMgDestroyContractionDescriptor", + "cutensorMgCreateContractionFind", "cutensorMgDestroyContractionFind", + "cutensorMgContractionGetWorkspace", "cutensorMgCreateContractionPlan", + "cutensorMgDestroyContractionPlan", "cutensorMgContraction"); + }; + + MF.addMatcher(callExpr(callee(functionDecl(CutensorAPIs()))).bind("call"), + this); +} + +void clang::dpct::CUTensorRule::runRule( + const ast_matchers::MatchFinder::MatchResult &Result) { + if (const CallExpr *CE = getNodeAsType(Result, "call")) { + std::string FuncName = ""; + const FunctionDecl *FD = CE->getDirectCallee(); + if (FD) { + FuncName = FD->getNameInfo().getName().getAsString(); + } + + report(CE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false, FuncName); + } + + return; +} diff --git a/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h new file mode 100644 index 000000000000..f5d8c21deea9 --- /dev/null +++ b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h @@ -0,0 +1,28 @@ +//===----------------------- CUTensorAPIMigration.h -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef CUTENSOR_API_MIGRATION_H +#define CUTENSOR_API_MIGRATION_H + +#include "ASTTraversal.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace dpct { + +class CUTensorRule : public NamedMigrationRule { +public: + void registerMatcher(ast_matchers::MatchFinder &MF) override; + void runRule(const ast_matchers::MatchFinder::MatchResult &Result); +}; + +} // namespace dpct +} // namespace clang + +#endif // CUTENSOR_API_MIGRATION_H diff --git a/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp b/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp new file mode 100644 index 000000000000..d3cb6168e1dc --- /dev/null +++ b/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp @@ -0,0 +1,37 @@ +//===-------------------- CallExprRewriterCUTensor.cpp --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RuleInfra/CallExprRewriter.h" +#include "RuleInfra/CallExprRewriterCommon.h" + +namespace clang { +namespace dpct { + +#define REWRITER_FACTORY_ENTRY(FuncName, RewriterFactory, ...) \ + {FuncName, std::make_shared(FuncName, __VA_ARGS__)}, +#define UNSUPPORTED_FACTORY_ENTRY(FuncName, MsgID) \ + REWRITER_FACTORY_ENTRY(FuncName, \ + UnsupportFunctionRewriterFactory, MsgID, \ + FuncName) +#define ENTRY_UNSUPPORTED(SOURCEAPINAME, MSGID) \ + UNSUPPORTED_FACTORY_ENTRY(SOURCEAPINAME, MSGID) + +void CallExprRewriterFactoryBase::initRewriterMapCUTensor() { + RewriterMap->merge( + std::unordered_map>({ +#include "APINamesCUTensor.inc" + })); +} + +#undef ENTRY_UNSUPPORTED +#undef UNSUPPORTED_FACTORY_ENTRY +#undef REWRITER_FACTORY_ENTRY + +} // namespace dpct +} // namespace clang diff --git a/clang/lib/DPCT/SrcAPI/APINames_cuTENSOR.inc b/clang/lib/DPCT/SrcAPI/APINames_cuTENSOR.inc index d14ee4367a8b..2bf96defc722 100644 --- a/clang/lib/DPCT/SrcAPI/APINames_cuTENSOR.inc +++ b/clang/lib/DPCT/SrcAPI/APINames_cuTENSOR.inc @@ -35,90 +35,90 @@ ****************************************************************************/ // Helper Functions -ENTRY(cutensorCreate, cutensorCreate, false, NO_FLAG, P4, "comment") -ENTRY(cutensorDestroy, cutensorDestroy, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreateTensorDescriptor, cutensorCreateTensorDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorDestroyTensorDescriptor, cutensorDestroyTensorDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorGetErrorString, cutensorGetErrorString, false, NO_FLAG, P4, "comment") -ENTRY(cutensorGetVersion, cutensorGetVersion, false, NO_FLAG, P4, "comment") -ENTRY(cutensorGetCudartVersion, cutensorGetCudartVersion, false, NO_FLAG, P4, "comment") +ENTRY(cutensorCreate, cutensorCreate, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorDestroy, cutensorDestroy, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreateTensorDescriptor, cutensorCreateTensorDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorDestroyTensorDescriptor, cutensorDestroyTensorDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorGetErrorString, cutensorGetErrorString, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorGetVersion, cutensorGetVersion, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorGetCudartVersion, cutensorGetCudartVersion, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Element-wise Operations -ENTRY(cutensorCreateElementwiseTrinary, cutensorCreateElementwiseTrinary, false, NO_FLAG, P4, "comment") -ENTRY(cutensorElementwiseTrinaryExecute, cutensorElementwiseTrinaryExecute, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreateElementwiseBinary, cutensorCreateElementwiseBinary, false, NO_FLAG, P4, "comment") -ENTRY(cutensorElementwiseBinaryExecute, cutensorElementwiseBinaryExecute, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreatePermutation, cutensorCreatePermutation, false, NO_FLAG, P4, "comment") -ENTRY(cutensorPermute, cutensorPermute, false, NO_FLAG, P4, "comment") +ENTRY(cutensorCreateElementwiseTrinary, cutensorCreateElementwiseTrinary, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorElementwiseTrinaryExecute, cutensorElementwiseTrinaryExecute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreateElementwiseBinary, cutensorCreateElementwiseBinary, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorElementwiseBinaryExecute, cutensorElementwiseBinaryExecute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreatePermutation, cutensorCreatePermutation, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorPermute, cutensorPermute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Contraction Operations -ENTRY(cutensorCreateContraction, cutensorCreateContraction, false, NO_FLAG, P4, "comment") -ENTRY(cutensorContract, cutensorContract, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreateContractionTrinary, cutensorCreateContractionTrinary, false, NO_FLAG, P4, "comment") -ENTRY(cutensorContractTrinary, cutensorContractTrinary, false, NO_FLAG, P4, "comment") +ENTRY(cutensorCreateContraction, cutensorCreateContraction, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorContract, cutensorContract, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreateContractionTrinary, cutensorCreateContractionTrinary, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorContractTrinary, cutensorContractTrinary, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Reduction Operations -ENTRY(cutensorCreateReduction, cutensorCreateReduction, false, NO_FLAG, P4, "comment") -ENTRY(cutensorReduce, cutensorReduce, false, NO_FLAG, P4, "comment") +ENTRY(cutensorCreateReduction, cutensorCreateReduction, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorReduce, cutensorReduce, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Generic Operation Functions -ENTRY(cutensorDestroyOperationDescriptor, cutensorDestroyOperationDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorOperationDescriptorGetAttribute, cutensorOperationDescriptorGetAttribute, false, NO_FLAG, P4, "comment") -ENTRY(cutensorOperationDescriptorSetAttribute, cutensorOperationDescriptorSetAttribute, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreatePlanPreference, cutensorCreatePlanPreference, false, NO_FLAG, P4, "comment") -ENTRY(cutensorDestroyPlanPreference, cutensorDestroyPlanPreference, false, NO_FLAG, P4, "comment") -ENTRY(cutensorPlanPreferenceSetAttribute, cutensorPlanPreferenceSetAttribute, false, NO_FLAG, P4, "comment") -ENTRY(cutensorEstimateWorkspaceSize, cutensorEstimateWorkspaceSize, false, NO_FLAG, P4, "comment") -ENTRY(cutensorCreatePlan, cutensorCreatePlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorDestroyPlan, cutensorDestroyPlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorPlanGetAttribute, cutensorPlanGetAttribute, false, NO_FLAG, P4, "comment") +ENTRY(cutensorDestroyOperationDescriptor, cutensorDestroyOperationDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorOperationDescriptorGetAttribute, cutensorOperationDescriptorGetAttribute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorOperationDescriptorSetAttribute, cutensorOperationDescriptorSetAttribute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreatePlanPreference, cutensorCreatePlanPreference, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorDestroyPlanPreference, cutensorDestroyPlanPreference, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorPlanPreferenceSetAttribute, cutensorPlanPreferenceSetAttribute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorEstimateWorkspaceSize, cutensorEstimateWorkspaceSize, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorCreatePlan, cutensorCreatePlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorDestroyPlan, cutensorDestroyPlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorPlanGetAttribute, cutensorPlanGetAttribute, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Cache-related Operations -ENTRY(cutensorHandleResizePlanCache, cutensorHandleResizePlanCache, false, NO_FLAG, P4, "comment") -ENTRY(cutensorHandleReadPlanCacheFromFile, cutensorHandleReadPlanCacheFromFile, false, NO_FLAG, P4, "comment") -ENTRY(cutensorHandleWritePlanCacheToFile, cutensorHandleWritePlanCacheToFile, false, NO_FLAG, P4, "comment") -ENTRY(cutensorReadKernelCacheFromFile, cutensorReadKernelCacheFromFile, false, NO_FLAG, P4, "comment") -ENTRY(cutensorWriteKernelCacheToFile, cutensorWriteKernelCacheToFile, false, NO_FLAG, P4, "comment") +ENTRY(cutensorHandleResizePlanCache, cutensorHandleResizePlanCache, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorHandleReadPlanCacheFromFile, cutensorHandleReadPlanCacheFromFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorHandleWritePlanCacheToFile, cutensorHandleWritePlanCacheToFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorReadKernelCacheFromFile, cutensorReadKernelCacheFromFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorWriteKernelCacheToFile, cutensorWriteKernelCacheToFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // Logger Functions -ENTRY(cutensorLoggerSetCallback, cutensorLoggerSetCallback, false, NO_FLAG, P4, "comment") -ENTRY(cutensorLoggerSetFile, cutensorLoggerSetFile, false, NO_FLAG, P4, "comment") -ENTRY(cutensorLoggerOpenFile, cutensorLoggerOpenFile, false, NO_FLAG, P4, "comment") -ENTRY(cutensorLoggerSetLevel, cutensorLoggerSetLevel, false, NO_FLAG, P4, "comment") -ENTRY(cutensorLoggerSetMask, cutensorLoggerSetMask, false, NO_FLAG, P4, "comment") -ENTRY(cutensorLoggerForceDisable, cutensorLoggerForceDisable, false, NO_FLAG, P4, "comment") +ENTRY(cutensorLoggerSetCallback, cutensorLoggerSetCallback, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorLoggerSetFile, cutensorLoggerSetFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorLoggerOpenFile, cutensorLoggerOpenFile, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorLoggerSetLevel, cutensorLoggerSetLevel, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorLoggerSetMask, cutensorLoggerSetMask, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorLoggerForceDisable, cutensorLoggerForceDisable, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // cuTENSORMg - General Operations -ENTRY(cutensorMgCreate, cutensorMgCreate, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroy, cutensorMgDestroy, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCreateTensorDescriptor, cutensorMgCreateTensorDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyTensorDescriptor, cutensorMgDestroyTensorDescriptor, false, NO_FLAG, P4, "comment") +ENTRY(cutensorMgCreate, cutensorMgCreate, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroy, cutensorMgDestroy, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCreateTensorDescriptor, cutensorMgCreateTensorDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyTensorDescriptor, cutensorMgDestroyTensorDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // cuTENSORMg - Copy Operations -ENTRY(cutensorMgCreateCopyDescriptor, cutensorMgCreateCopyDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyCopyDescriptor, cutensorMgDestroyCopyDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCopyGetWorkspace, cutensorMgCopyGetWorkspace, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCreateCopyPlan, cutensorMgCreateCopyPlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyCopyPlan, cutensorMgDestroyCopyPlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCopy, cutensorMgCopy, false, NO_FLAG, P4, "comment") +ENTRY(cutensorMgCreateCopyDescriptor, cutensorMgCreateCopyDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyCopyDescriptor, cutensorMgDestroyCopyDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCopyGetWorkspace, cutensorMgCopyGetWorkspace, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCreateCopyPlan, cutensorMgCreateCopyPlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyCopyPlan, cutensorMgDestroyCopyPlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCopy, cutensorMgCopy, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // cuTENSORMg - Contraction Operations -ENTRY(cutensorMgCreateContractionDescriptor, cutensorMgCreateContractionDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyContractionDescriptor, cutensorMgDestroyContractionDescriptor, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCreateContractionFind, cutensorMgCreateContractionFind, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyContractionFind, cutensorMgDestroyContractionFind, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgContractionGetWorkspace, cutensorMgContractionGetWorkspace, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgCreateContractionPlan, cutensorMgCreateContractionPlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgDestroyContractionPlan, cutensorMgDestroyContractionPlan, false, NO_FLAG, P4, "comment") -ENTRY(cutensorMgContraction, cutensorMgContraction, false, NO_FLAG, P4, "comment") +ENTRY(cutensorMgCreateContractionDescriptor, cutensorMgCreateContractionDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyContractionDescriptor, cutensorMgDestroyContractionDescriptor, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCreateContractionFind, cutensorMgCreateContractionFind, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyContractionFind, cutensorMgDestroyContractionFind, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgContractionGetWorkspace, cutensorMgContractionGetWorkspace, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgCreateContractionPlan, cutensorMgCreateContractionPlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgDestroyContractionPlan, cutensorMgDestroyContractionPlan, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") +ENTRY(cutensorMgContraction, cutensorMgContraction, false, API_CALL_UNSUPPORTED, P4, "DPCT1007") // clang-format on diff --git a/clang/test/dpct/cutensor.cu b/clang/test/dpct/cutensor.cu new file mode 100644 index 000000000000..7a3b69bf2f07 --- /dev/null +++ b/clang/test/dpct/cutensor.cu @@ -0,0 +1,217 @@ +// UNSUPPORTED: cuda-8.0, cuda-9.2, cuda-10.0, cuda-10.2, cuda-11.1, cuda-11.2, cuda-11.3, cuda-11.4, cuda-11.5, cuda-11.6, cuda-11.7, cuda-12.0, cuda-12.1, cuda-12.2, cuda-12.3, cuda-12.4, cuda-12.5, cuda-12.6 +// UNSUPPORTED: v8.0, v9.2, v10.0, v10.2, v11.1, v11.2, v11.3, v11.4, v11.5, v11.6, v11.7, v12.0, v12.1, v12.2, v12.3, v12.4, v12.5, v12.6 +// RUN: dpct --format-range=none --out-root=%T/cutensor %s --cuda-include-path="%cuda-path/include" +// RUN: FileCheck %s --match-full-lines --input-file %T/cutensor/cutensor.dp.cpp +#include +#include +#include + +int main() { + cudaStream_t stream; + + // Basic handle creation and destruction + cutensorHandle_t handle; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreate is not supported. + cutensorCreate(&handle); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroy is not supported. + cutensorDestroy(handle); + + // Tensor descriptor + cutensorTensorDescriptor_t tensorDesc; + uint32_t numModes = 0; + int64_t *extent; + int64_t *stride; + cutensorDataType_t tensorDataType; + uint32_t alignmentRequirement; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateTensorDescriptor is not supported. + cutensorCreateTensorDescriptor(handle, &tensorDesc, numModes, extent, stride, tensorDataType, alignmentRequirement); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyTensorDescriptor is not supported. + cutensorDestroyTensorDescriptor(tensorDesc); + + // Get cuTENSOR versions and error strings + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetErrorString is not supported. + const char *errStr = cutensorGetErrorString(CUTENSOR_STATUS_SUCCESS); + printf("Error String: %s\n", errStr); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetVersion is not supported. + int version = cutensorGetVersion(); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetCudartVersion is not supported. + int cudartVer = cutensorGetCudartVersion(); + printf("cuTENSOR Version: %d, CUDA Runtime Version: %d\n", version, cudartVer); + + // Elementwise trinary operations + cutensorOperationDescriptor_t opDesc; + int32_t *modes; + cutensorOperator_t op; + cutensorComputeDescriptor_t descCompute; + cutensorPlan_t plan; + const void *alpha, *A, *beta, *B, *gamma, *C; + void *D; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateElementwiseTrinary is not supported. + cutensorCreateElementwiseTrinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, op, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorElementwiseTrinaryExecute is not supported. + cutensorElementwiseTrinaryExecute(handle, plan, alpha, A, beta, B, gamma, C, D, stream); + + // Elementwise binary operations + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateElementwiseBinary is not supported. + cutensorCreateElementwiseBinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorElementwiseBinaryExecute is not supported. + cutensorElementwiseBinaryExecute(handle, plan, alpha, A, gamma, C, D, stream); + + // Permutation + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePermutation is not supported. + cutensorCreatePermutation(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPermute is not supported. + cutensorPermute(handle, plan, alpha, A, D, stream); + + // Contraction + void *workspace; + uint64_t workspaceSize; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateContraction is not supported. + cutensorCreateContraction(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorContract is not supported. + cutensorContract(handle, plan, alpha, A, B, beta, C, D, workspace, workspaceSize, stream); + + // Contraction Trinary + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateContractionTrinary is not supported. + cutensorCreateContractionTrinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorContractTrinary is not supported. + cutensorContractTrinary(handle, plan, alpha, A, B, C, beta, C, D, workspace, workspaceSize, stream); + + // Reduction + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateReduction is not supported. + cutensorCreateReduction(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, descCompute); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorReduce is not supported. + cutensorReduce(handle, plan, alpha, A, beta, C, D, workspace, workspaceSize, stream); + + // Operation descriptor functions + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyOperationDescriptor is not supported. + cutensorDestroyOperationDescriptor(opDesc); + cutensorOperationDescriptorAttribute_t opAttr; + void *buf; + size_t sizeInBytes; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorOperationDescriptorGetAttribute is not supported. + cutensorOperationDescriptorGetAttribute(handle, opDesc, opAttr, buf, sizeInBytes); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorOperationDescriptorSetAttribute is not supported. + cutensorOperationDescriptorSetAttribute(handle, opDesc, opAttr, buf, sizeInBytes); + + // Plan preference functions + cutensorPlanPreference_t planPref; + cutensorPlanPreferenceAttribute_t planPrefAttr; + cutensorAlgo_t algo; + cutensorJitMode_t jitMode; + cutensorWorksizePreference_t workspacePref; + uint64_t *workspaceSizeEstimate; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePlanPreference is not supported. + cutensorCreatePlanPreference(handle, &planPref, algo, jitMode); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyPlanPreference is not supported. + cutensorDestroyPlanPreference(planPref); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPlanPreferenceSetAttribute is not supported. + cutensorPlanPreferenceSetAttribute(handle, planPref, planPrefAttr, buf, sizeInBytes); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorEstimateWorkspaceSize is not supported. + cutensorEstimateWorkspaceSize(handle, opDesc, planPref, workspacePref, workspaceSizeEstimate); + cutensorPlanAttribute_t planAttr; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePlan is not supported. + cutensorCreatePlan(handle, &plan, opDesc, planPref, *workspaceSizeEstimate); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyPlan is not supported. + cutensorDestroyPlan(plan); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPlanGetAttribute is not supported. + cutensorPlanGetAttribute(handle, plan, planAttr, buf, sizeInBytes); + + // Plan cache management + uint32_t numCachelinesRead; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleResizePlanCache is not supported. + cutensorHandleResizePlanCache(handle, 0); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleReadPlanCacheFromFile is not supported. + cutensorHandleReadPlanCacheFromFile(handle, "plan_cache.dat", &numCachelinesRead); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleWritePlanCacheToFile is not supported. + cutensorHandleWritePlanCacheToFile(handle, "plan_cache.dat"); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorReadKernelCacheFromFile is not supported. + cutensorReadKernelCacheFromFile(handle, "kernel_cache.dat"); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorWriteKernelCacheToFile is not supported. + cutensorWriteKernelCacheToFile(handle, "kernel_cache.dat"); + + // Logger functions + cutensorLoggerCallback_t callback; + FILE *file; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetCallback is not supported. + cutensorLoggerSetCallback(callback); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetFile is not supported. + cutensorLoggerSetFile(file); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerOpenFile is not supported. + cutensorLoggerOpenFile("logfile.txt"); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetLevel is not supported. + cutensorLoggerSetLevel(0); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetMask is not supported. + cutensorLoggerSetMask(0); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerForceDisable is not supported. + cutensorLoggerForceDisable(); + + // Multi-grid (Mg) APIs + // Mg handle creation and destruction + cutensorMgHandle_t mgHandle; + uint32_t numDevices; + const int32_t *devices; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreate is not supported. + cutensorMgCreate(&mgHandle, numDevices, devices); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroy is not supported. + cutensorMgDestroy(mgHandle); + + // Mg tensor descriptor + cutensorMgTensorDescriptor_t *desc; + const int64_t *blockSize; + const int32_t *deviceCount; + cudaDataType_t dataType; + cutensorMgTensorDescriptor_t mgTensorDesc; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateTensorDescriptor is not supported. + cutensorMgCreateTensorDescriptor(mgHandle, &mgTensorDesc, numModes, extent, stride, blockSize, stride, deviceCount, numDevices, devices, dataType); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyTensorDescriptor is not supported. + cutensorMgDestroyTensorDescriptor(mgTensorDesc); + + // Mg copy descriptor & plan + cutensorMgCopyDescriptor_t mgCopyDesc; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateCopyDescriptor is not supported. + cutensorMgCreateCopyDescriptor(mgHandle, &mgCopyDesc, mgTensorDesc, modes, mgTensorDesc, modes); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyCopyDescriptor is not supported. + cutensorMgDestroyCopyDescriptor(mgCopyDesc); + int64_t hostWorkspaceSize = 0; + int64_t *deviceWorkspaceSize; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCopyGetWorkspace is not supported. + cutensorMgCopyGetWorkspace(mgHandle, mgCopyDesc, deviceWorkspaceSize, &hostWorkspaceSize); + cutensorMgCopyPlan_t mgCopyPlan; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateCopyPlan is not supported. + cutensorMgCreateCopyPlan(mgHandle, &mgCopyPlan, mgCopyDesc, deviceWorkspaceSize, hostWorkspaceSize); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyCopyPlan is not supported. + cutensorMgDestroyCopyPlan(mgCopyPlan); + void *ptrDst; + const void *ptrSrc; + void *deviceWorkspace; + void *hostWorkspace; + cudaStream_t *streams; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCopy is not supported. + cutensorMgCopy(mgHandle, mgCopyPlan, &ptrDst, &ptrSrc, &deviceWorkspace, hostWorkspace, streams); + + // Mg contraction descriptor, find, plan, and execution + cutensorMgContractionDescriptor_t mgContrDesc; + cutensorComputeType_t computeType; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionDescriptor is not supported. + cutensorMgCreateContractionDescriptor(mgHandle, &mgContrDesc, mgTensorDesc, modes, mgTensorDesc, modes, mgTensorDesc, modes, mgTensorDesc, modes, computeType); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionDescriptor is not supported. + cutensorMgDestroyContractionDescriptor(mgContrDesc); + cutensorMgContractionFind_t mgContrFind; + cutensorMgAlgo_t mgAlgo; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionFind is not supported. + cutensorMgCreateContractionFind(mgHandle, &mgContrFind, mgAlgo); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionFind is not supported. + cutensorMgDestroyContractionFind(mgContrFind); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgContractionGetWorkspace is not supported. + cutensorMgContractionGetWorkspace(mgHandle, mgContrDesc, mgContrFind, workspacePref, deviceWorkspaceSize, &hostWorkspaceSize); + cutensorMgContractionPlan_t mgContrPlan; + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionPlan is not supported. + cutensorMgCreateContractionPlan(mgHandle, &mgContrPlan, mgContrDesc, mgContrFind, deviceWorkspaceSize, hostWorkspaceSize); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionPlan is not supported. + cutensorMgDestroyContractionPlan(mgContrPlan); + // CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgContraction is not supported. + cutensorMgContraction(mgHandle, mgContrPlan, alpha, &A, &B, beta, &C, &D, &deviceWorkspace, hostWorkspace, streams); + + return 0; +}