From 6a8141168cb1cf0149e38bf625b344a9cd394cd2 Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Tue, 15 Apr 2025 00:03:46 +0800 Subject: [PATCH 1/4] Added lit test case for all cuTensor APIs --- clang/test/dpct/cutensor.cu | 215 ++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 clang/test/dpct/cutensor.cu diff --git a/clang/test/dpct/cutensor.cu b/clang/test/dpct/cutensor.cu new file mode 100644 index 000000000000..520c0c0d1b0f --- /dev/null +++ b/clang/test/dpct/cutensor.cu @@ -0,0 +1,215 @@ +// 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; +} From 9da956031f4a1a69630a5d684ab8b7f636cb4dd8 Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Thu, 17 Apr 2025 23:14:30 +0800 Subject: [PATCH 2/4] Added init rules infra --- clang/lib/DPCT/ASTTraversal.cpp | 3 + clang/lib/DPCT/CMakeLists.txt | 2 + clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp | 11 +- clang/lib/DPCT/RuleInfra/CallExprRewriter.h | 1 + .../lib/DPCT/RulesInclude/InclusionHeaders.h | 1 + .../DPCT/RulesInclude/InclusionHeaders.inc | 3 + .../lib/DPCT/RulesTensor/APINamesCUTENSOR.inc | 10 ++ .../DPCT/RulesTensor/CUTENSORAPIMigration.cpp | 80 ++++++++++++ .../DPCT/RulesTensor/CUTENSORAPIMigration.h | 28 +++++ .../RulesTensor/CallExprRewriterCUTENSOR.cpp | 37 ++++++ clang/lib/DPCT/SrcAPI/APINames_cuTENSOR.inc | 116 +++++++++--------- clang/test/dpct/cutensor.cu | 2 + 12 files changed, 232 insertions(+), 62 deletions(-) create mode 100644 clang/lib/DPCT/RulesTensor/APINamesCUTENSOR.inc create mode 100644 clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp create mode 100644 clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h create mode 100644 clang/lib/DPCT/RulesTensor/CallExprRewriterCUTENSOR.cpp diff --git a/clang/lib/DPCT/ASTTraversal.cpp b/clang/lib/DPCT/ASTTraversal.cpp index 35a7eea5cb5f..3daf298bb7e3 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..e9f699bd5d89 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..2bda097969b1 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..b7ae3ecbf00b 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..80e14d2256a9 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..3735a2aba62f 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..1662f859aa39 --- /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..aed141179504 --- /dev/null +++ b/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp @@ -0,0 +1,80 @@ +//===---------------------- 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"); + }; + + llvm::outs() << "[DEBUG] Inside regMatcher\n"; + + MF.addMatcher(callExpr(callee(functionDecl(CutensorAPIs()))).bind("call"), + this); +} + +void clang::dpct::CUTENSORRule::runRule( + const ast_matchers::MatchFinder::MatchResult &Result) { + llvm::outs() << "[DEBUG] Inside runRule\n"; + 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..84641d9f8567 --- /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..c1908c8fd5be --- /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 index 520c0c0d1b0f..7a3b69bf2f07 100644 --- a/clang/test/dpct/cutensor.cu +++ b/clang/test/dpct/cutensor.cu @@ -1,3 +1,5 @@ +// 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 From 3090feba848a3ab6b92d86c638643c60c0de7f11 Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Fri, 25 Apr 2025 08:17:27 +0800 Subject: [PATCH 3/4] Cleaned up comments and changed the rule name --- clang/lib/DPCT/ASTTraversal.cpp | 2 +- clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp | 7 ++----- clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/clang/lib/DPCT/ASTTraversal.cpp b/clang/lib/DPCT/ASTTraversal.cpp index 3daf298bb7e3..3d462246aaf5 100644 --- a/clang/lib/DPCT/ASTTraversal.cpp +++ b/clang/lib/DPCT/ASTTraversal.cpp @@ -198,7 +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) +REGISTER_RULE(CUTensorRule, PassKind::PK_Migration, RuleGroupKind::RK_CUTENSOR) } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp b/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp index aed141179504..5a634902890f 100644 --- a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp +++ b/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp @@ -12,7 +12,7 @@ using namespace clang::dpct; using namespace clang::ast_matchers; -void clang::dpct::CUTENSORRule::registerMatcher(ast_matchers::MatchFinder &MF) { +void clang::dpct::CUTensorRule::registerMatcher(ast_matchers::MatchFinder &MF) { auto CutensorAPIs = [&]() { return hasAnyName( // Helper Functions @@ -57,15 +57,12 @@ void clang::dpct::CUTENSORRule::registerMatcher(ast_matchers::MatchFinder &MF) { "cutensorMgDestroyContractionPlan", "cutensorMgContraction"); }; - llvm::outs() << "[DEBUG] Inside regMatcher\n"; - MF.addMatcher(callExpr(callee(functionDecl(CutensorAPIs()))).bind("call"), this); } -void clang::dpct::CUTENSORRule::runRule( +void clang::dpct::CUTensorRule::runRule( const ast_matchers::MatchFinder::MatchResult &Result) { - llvm::outs() << "[DEBUG] Inside runRule\n"; if (const CallExpr *CE = getNodeAsType(Result, "call")) { std::string FuncName = ""; const FunctionDecl *FD = CE->getDirectCallee(); diff --git a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h b/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h index 84641d9f8567..2caaeae6c046 100644 --- a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h +++ b/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h @@ -16,7 +16,7 @@ using namespace clang::ast_matchers; namespace clang { namespace dpct { -class CUTENSORRule : public NamedMigrationRule { +class CUTensorRule : public NamedMigrationRule { public: void registerMatcher(ast_matchers::MatchFinder &MF) override; void runRule(const ast_matchers::MatchFinder::MatchResult &Result); From 18df0241b39820542dec87d36afe9942bee0e17f Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Fri, 25 Apr 2025 08:58:26 +0800 Subject: [PATCH 4/4] Changed CUTENSOR to CUTensor in all the places --- clang/lib/DPCT/ASTTraversal.cpp | 4 ++-- clang/lib/DPCT/CMakeLists.txt | 4 ++-- clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp | 2 +- clang/lib/DPCT/RuleInfra/CallExprRewriter.h | 2 +- clang/lib/DPCT/RulesInclude/InclusionHeaders.h | 2 +- clang/lib/DPCT/RulesInclude/InclusionHeaders.inc | 4 ++-- .../{APINamesCUTENSOR.inc => APINamesCUTensor.inc} | 2 +- .../{CUTENSORAPIMigration.cpp => CUTensorAPIMigration.cpp} | 4 ++-- .../{CUTENSORAPIMigration.h => CUTensorAPIMigration.h} | 2 +- ...xprRewriterCUTENSOR.cpp => CallExprRewriterCUTensor.cpp} | 6 +++--- 10 files changed, 16 insertions(+), 16 deletions(-) rename clang/lib/DPCT/RulesTensor/{APINamesCUTENSOR.inc => APINamesCUTensor.inc} (85%) rename clang/lib/DPCT/RulesTensor/{CUTENSORAPIMigration.cpp => CUTensorAPIMigration.cpp} (95%) rename clang/lib/DPCT/RulesTensor/{CUTENSORAPIMigration.h => CUTensorAPIMigration.h} (89%) rename clang/lib/DPCT/RulesTensor/{CallExprRewriterCUTENSOR.cpp => CallExprRewriterCUTensor.cpp} (88%) diff --git a/clang/lib/DPCT/ASTTraversal.cpp b/clang/lib/DPCT/ASTTraversal.cpp index 3d462246aaf5..427f0c4fcc8c 100644 --- a/clang/lib/DPCT/ASTTraversal.cpp +++ b/clang/lib/DPCT/ASTTraversal.cpp @@ -27,7 +27,7 @@ #include "RulesSHMEM/NVSHMEMAPIMigration.h" #include "RulesSecurity/Homoglyph.h" #include "RulesSecurity/MisleadingBidirectional.h" -#include "RulesTensor/CUTENSORAPIMigration.h" +#include "RulesTensor/CUTensorAPIMigration.h" #include "TextModification.h" #include "Utility.h" @@ -198,7 +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) +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 e9f699bd5d89..ad53ffc063b6 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -203,7 +203,7 @@ add_clang_library(DPCT RulesLang/CallExprRewriterCG.cpp RulesLang/CallExprRewriterWmma.cpp RulesSHMEM/CallExprRewriterNvshmem.cpp - RulesTensor/CallExprRewriterCUTENSOR.cpp + RulesTensor/CallExprRewriterCUTensor.cpp ErrorHandle/CrashRecovery.cpp Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp @@ -243,7 +243,7 @@ add_clang_library(DPCT RulesCCL/NCCLAPIMigration.cpp RuleInfra/TypeLocRewriters.cpp RulesSHMEM/NVSHMEMAPIMigration.cpp - RulesTensor/CUTENSORAPIMigration.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 2bda097969b1..55afcc9e9ce9 100644 --- a/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp +++ b/clang/lib/DPCT/RuleInfra/CallExprRewriter.cpp @@ -164,7 +164,7 @@ void CallExprRewriterFactoryBase::initRewriterMap() { initRewriterMapMisc(); initRewriterMapNccl(); initRewriterMapNvshmem(); - initRewriterMapCUTENSOR(); + initRewriterMapCUTensor(); initRewriterMapStream(); initRewriterMapTexture(); initRewriterMapThrust(); diff --git a/clang/lib/DPCT/RuleInfra/CallExprRewriter.h b/clang/lib/DPCT/RuleInfra/CallExprRewriter.h index b7ae3ecbf00b..8142ccd3def9 100644 --- a/clang/lib/DPCT/RuleInfra/CallExprRewriter.h +++ b/clang/lib/DPCT/RuleInfra/CallExprRewriter.h @@ -70,7 +70,7 @@ class CallExprRewriterFactoryBase { static void initRewriterMapMisc(); static void initRewriterMapNccl(); static void initRewriterMapNvshmem(); - static void initRewriterMapCUTENSOR(); + 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 80e14d2256a9..d6e89e8053c1 100644 --- a/clang/lib/DPCT/RulesInclude/InclusionHeaders.h +++ b/clang/lib/DPCT/RulesInclude/InclusionHeaders.h @@ -36,7 +36,7 @@ enum class RuleGroupKind : uint8_t { RK_CUB, RK_WMMA, RK_NVSHMEM, - RK_CUTENSOR, + RK_CUTensor, NUM }; diff --git a/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc b/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc index 3735a2aba62f..4e64bcf6fdf5 100644 --- a/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc +++ b/clang/lib/DPCT/RulesInclude/InclusionHeaders.inc @@ -113,5 +113,5 @@ REGIST_INCLUSION("nvshmem.h", FullMatch, NVSHMEM, Replace, false, 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) +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 similarity index 85% rename from clang/lib/DPCT/RulesTensor/APINamesCUTENSOR.inc rename to clang/lib/DPCT/RulesTensor/APINamesCUTensor.inc index 1662f859aa39..d5172d6f3e3c 100644 --- a/clang/lib/DPCT/RulesTensor/APINamesCUTENSOR.inc +++ b/clang/lib/DPCT/RulesTensor/APINamesCUTensor.inc @@ -1,4 +1,4 @@ -//===------------------------ APINamesCUTENSOR.inc ------------------------===// +//===------------------------ 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. diff --git a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp similarity index 95% rename from clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp rename to clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp index 5a634902890f..17f8c9c88daf 100644 --- a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.cpp +++ b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.cpp @@ -1,4 +1,4 @@ -//===---------------------- CUTENSORAPIMigration.cpp ----------------------===// +//===---------------------- 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. @@ -6,7 +6,7 @@ // //===-----------------------------------------------------------------------===// -#include "CUTENSORAPIMigration.h" +#include "CUTensorAPIMigration.h" #include "RuleInfra/ExprAnalysis.h" using namespace clang::dpct; diff --git a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h similarity index 89% rename from clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h rename to clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h index 2caaeae6c046..f5d8c21deea9 100644 --- a/clang/lib/DPCT/RulesTensor/CUTENSORAPIMigration.h +++ b/clang/lib/DPCT/RulesTensor/CUTensorAPIMigration.h @@ -1,4 +1,4 @@ -//===----------------------- CUTENSORAPIMigration.h -----------------------===// +//===----------------------- 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. diff --git a/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTENSOR.cpp b/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp similarity index 88% rename from clang/lib/DPCT/RulesTensor/CallExprRewriterCUTENSOR.cpp rename to clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp index c1908c8fd5be..d3cb6168e1dc 100644 --- a/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTENSOR.cpp +++ b/clang/lib/DPCT/RulesTensor/CallExprRewriterCUTensor.cpp @@ -1,4 +1,4 @@ -//===-------------------- CallExprRewriterCUTENSOR.cpp --------------------===// +//===-------------------- 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. @@ -21,11 +21,11 @@ namespace dpct { #define ENTRY_UNSUPPORTED(SOURCEAPINAME, MSGID) \ UNSUPPORTED_FACTORY_ENTRY(SOURCEAPINAME, MSGID) -void CallExprRewriterFactoryBase::initRewriterMapCUTENSOR() { +void CallExprRewriterFactoryBase::initRewriterMapCUTensor() { RewriterMap->merge( std::unordered_map>({ -#include "APINamesCUTENSOR.inc" +#include "APINamesCUTensor.inc" })); }