|
| 1 | +//===---------------------- CUTensorAPIMigration.cpp ----------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===-----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "CUTensorAPIMigration.h" |
| 10 | +#include "RuleInfra/ExprAnalysis.h" |
| 11 | + |
| 12 | +using namespace clang::dpct; |
| 13 | +using namespace clang::ast_matchers; |
| 14 | + |
| 15 | +void clang::dpct::CUTensorRule::registerMatcher(ast_matchers::MatchFinder &MF) { |
| 16 | + auto CutensorAPIs = [&]() { |
| 17 | + return hasAnyName( |
| 18 | + // Helper Functions |
| 19 | + "cutensorCreate", "cutensorDestroy", "cutensorCreateTensorDescriptor", |
| 20 | + "cutensorDestroyTensorDescriptor", "cutensorGetErrorString", |
| 21 | + "cutensorGetVersion", "cutensorGetCudartVersion", |
| 22 | + // Element-wise Operations |
| 23 | + "cutensorCreateElementwiseTrinary", "cutensorElementwiseTrinaryExecute", |
| 24 | + "cutensorCreateElementwiseBinary", "cutensorElementwiseBinaryExecute", |
| 25 | + "cutensorCreatePermutation", "cutensorPermute", |
| 26 | + // Contraction Operations |
| 27 | + "cutensorCreateContraction", "cutensorContract", |
| 28 | + "cutensorCreateContractionTrinary", "cutensorContractTrinary", |
| 29 | + // Reduction Operations |
| 30 | + "cutensorCreateReduction", "cutensorReduce", |
| 31 | + // Generic Operation Functions |
| 32 | + "cutensorDestroyOperationDescriptor", |
| 33 | + "cutensorOperationDescriptorGetAttribute", |
| 34 | + "cutensorOperationDescriptorSetAttribute", |
| 35 | + "cutensorCreatePlanPreference", "cutensorDestroyPlanPreference", |
| 36 | + "cutensorPlanPreferenceSetAttribute", "cutensorEstimateWorkspaceSize", |
| 37 | + "cutensorCreatePlan", "cutensorDestroyPlan", "cutensorPlanGetAttribute", |
| 38 | + // Cache-related Operations |
| 39 | + "cutensorHandleResizePlanCache", "cutensorHandleReadPlanCacheFromFile", |
| 40 | + "cutensorHandleWritePlanCacheToFile", "cutensorReadKernelCacheFromFile", |
| 41 | + "cutensorWriteKernelCacheToFile", |
| 42 | + // Logger Functions |
| 43 | + "cutensorLoggerSetCallback", "cutensorLoggerSetFile", |
| 44 | + "cutensorLoggerOpenFile", "cutensorLoggerSetLevel", |
| 45 | + "cutensorLoggerSetMask", "cutensorLoggerForceDisable", |
| 46 | + // cuTENSORMg - General Operations |
| 47 | + "cutensorMgCreate", "cutensorMgDestroy", |
| 48 | + "cutensorMgCreateTensorDescriptor", "cutensorMgDestroyTensorDescriptor", |
| 49 | + "cutensorMgCreateCopyDescriptor", "cutensorMgDestroyCopyDescriptor", |
| 50 | + "cutensorMgCopyGetWorkspace", "cutensorMgCreateCopyPlan", |
| 51 | + "cutensorMgDestroyCopyPlan", "cutensorMgCopy", |
| 52 | + // cuTENSORMg - Contraction Operations |
| 53 | + "cutensorMgCreateContractionDescriptor", |
| 54 | + "cutensorMgDestroyContractionDescriptor", |
| 55 | + "cutensorMgCreateContractionFind", "cutensorMgDestroyContractionFind", |
| 56 | + "cutensorMgContractionGetWorkspace", "cutensorMgCreateContractionPlan", |
| 57 | + "cutensorMgDestroyContractionPlan", "cutensorMgContraction"); |
| 58 | + }; |
| 59 | + |
| 60 | + MF.addMatcher(callExpr(callee(functionDecl(CutensorAPIs()))).bind("call"), |
| 61 | + this); |
| 62 | +} |
| 63 | + |
| 64 | +void clang::dpct::CUTensorRule::runRule( |
| 65 | + const ast_matchers::MatchFinder::MatchResult &Result) { |
| 66 | + if (const CallExpr *CE = getNodeAsType<CallExpr>(Result, "call")) { |
| 67 | + std::string FuncName = ""; |
| 68 | + const FunctionDecl *FD = CE->getDirectCallee(); |
| 69 | + if (FD) { |
| 70 | + FuncName = FD->getNameInfo().getName().getAsString(); |
| 71 | + } |
| 72 | + |
| 73 | + report(CE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false, FuncName); |
| 74 | + } |
| 75 | + |
| 76 | + return; |
| 77 | +} |
0 commit comments