Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions clang/lib/DPCT/APINamesLIBCU.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===--------------------APINamesLIBCU.inc----------------------------===//
//
// Copyright (C) Intel Corporation. All rights reserved.
//
// The information and source code contained herein is the exclusive
// property of Intel Corporation and may not be disclosed, examined
// or reproduced in whole or in part without explicit written authorization
// from the company.
//
//===-----------------------------------------------------------------===//

// Base API

CALL_FACTORY_ENTRY("cuda::std::atomic_thread_fence", CALL(MapNames::getClNamespace() + "atomic_fence",
ARG(0)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_store,
MEMBER_CALL_FACTORY_ENTRY(
"store", DEREF(0), false, "store",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_load,
MEMBER_CALL_FACTORY_ENTRY(
"load", DEREF(0), false, "load",
ARG(0)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_exchange,
MEMBER_CALL_FACTORY_ENTRY(
"exchange", DEREF(0), false, "exchange",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_compare_exchange_weak,
MEMBER_CALL_FACTORY_ENTRY(
"compare_exchange_weak", DEREF(0), false, "compare_exchange_weak",
ARG(0),ARG(1), ARG(2), ARG(3)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_compare_exchange_strong,
MEMBER_CALL_FACTORY_ENTRY(
"compare_exchange_strong", DEREF(0), false, "compare_exchange_strong",
ARG(0),ARG(1), ARG(2), ARG(3)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_fetch_add,
MEMBER_CALL_FACTORY_ENTRY(
"fetch_add", DEREF(0), false, "fetch_add",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_fetch_sub,
MEMBER_CALL_FACTORY_ENTRY(
"fetch_sub", DEREF(0), false, "fetch_sub",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_fetch_sub,
MEMBER_CALL_FACTORY_ENTRY(
"fetch_and", DEREF(0), false, "fetch_and",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_fetch_or,
MEMBER_CALL_FACTORY_ENTRY(
"fetch_or", DEREF(0), false, "fetch_or",
ARG(0),ARG(1)))

FEATURE_REQUEST_FACTORY(HelperFeatureEnum::AtomicUtils_atomic_utils_fetch_xor,
MEMBER_CALL_FACTORY_ENTRY(
"fetch_xor", DEREF(0), false, "fetch_xor",
ARG(0),ARG(1)))
11 changes: 11 additions & 0 deletions clang/lib/DPCT/APINamesTemplateType.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

TYPE_REWRITE_ENTRY(
"cuda::atomic",
TYPE_CONDITIONAL_FACTORY(
CheckTemplateArgCount(2),
TYPE_FACTORY(STR(MapNames::getDpctNamespace() + "atomic"),
TEMPLATE_ARG(0),
STR(MapNames::getClNamespace() + "memory_order::relaxed"),
TEMPLATE_ARG(1)),
TYPE_FACTORY(STR(MapNames::getDpctNamespace() + "atomic"),
TEMPLATE_ARG(0))))

TYPE_REWRITE_ENTRY(
"cuda::std::atomic",
TYPE_CONDITIONAL_FACTORY(
CheckTemplateArgCount(2),
TYPE_FACTORY(STR(MapNames::getDpctNamespace() + "atomic"),
Expand Down
42 changes: 20 additions & 22 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "MisleadingBidirectional.h"
#include "DNNAPIMigration.h"
#include "NCCLAPIMigration.h"
#include "LIBCUAPIMigration.h"
#include "SaveNewFiles.h"
#include "TextModification.h"
#include "Utility.h"
Expand Down Expand Up @@ -982,6 +983,19 @@ void IncludesCallbacks::InclusionDirective(
Updater.update(false);
}

if (FileName.compare(StringRef("cuda/atomic")) == 0||
FileName.compare(StringRef("cuda/std/atomic")) == 0) {

DpctGlobalInfo::setMKLHeaderUsed(true);

DpctGlobalInfo::getInstance().insertHeader(HashLoc, HT_AtomicUtils);
TransformSet.emplace_back(new ReplaceInclude(
CharSourceRange(SourceRange(HashLoc, FilenameRange.getEnd()),
/*IsTokenRange=*/false),
""));
Updater.update(false);
}

if (!isChildPath(CudaPath, IncludePath) &&
IncludePath.compare(0, 15, "/usr/local/cuda", 15)) {

Expand Down Expand Up @@ -17122,6 +17136,12 @@ REGISTER_RULE(CuDNNAPIRule)

REGISTER_RULE(NCCLRule)

REGISTER_RULE(LIBCUAPIRule)

REGISTER_RULE(LIBCUMemberFuncRule)

REGISTER_RULE(LIBCUTypeRule)

void ComplexAPIRule::registerMatcher(ast_matchers::MatchFinder &MF) {
auto ComplexAPI = [&]() {
return hasAnyName("make_cuDoubleComplex", "cuCreal", "cuCrealf", "cuCimag",
Expand All @@ -17146,28 +17166,6 @@ void ComplexAPIRule::runRule(

REGISTER_RULE(ComplexAPIRule)

void TemplateSpecializationTypeLocRule::registerMatcher(
ast_matchers::MatchFinder &MF) {
auto TargetTypeName = [&]() { return hasAnyName("cuda::atomic"); };

MF.addMatcher(typeLoc(
loc(qualType(hasDeclaration(namedDecl(TargetTypeName())))))
.bind("loc"),
this);
}

void TemplateSpecializationTypeLocRule::runRule(
const ast_matchers::MatchFinder::MatchResult &Result) {
if (auto TL = getNodeAsType<TypeLoc>(Result, "loc")) {
ExprAnalysis EA;
EA.analyze(*TL);
emplaceTransformation(EA.getReplacement());
EA.applyAllSubExprRepl();
}
}

REGISTER_RULE(TemplateSpecializationTypeLocRule)

void ASTTraversalManager::matchAST(ASTContext &Context, TransformSetTy &TS,
StmtStringMap &SSM) {
this->Context = &Context;
Expand Down
8 changes: 0 additions & 8 deletions clang/lib/DPCT/ASTTraversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,6 @@ class TypeInDeclRule : public NamedMigrationRule<TypeInDeclRule> {
bool isCapturedByLambda(const TypeLoc *TL);
};

class TemplateSpecializationTypeLocRule
: public clang::dpct::NamedMigrationRule<
TemplateSpecializationTypeLocRule> {

public:
void registerMatcher(clang::ast_matchers::MatchFinder &MF) override;
void runRule(const clang::ast_matchers::MatchFinder::MatchResult &Result);
};

class UserDefinedAPIRule
: public clang::dpct::NamedMigrationRule<UserDefinedAPIRule> {
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/DPCT/AnalysisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ enum HeaderType {
HT_Lib_Common_Utils,
HT_Dnnl,
HT_CCL,
HT_AtomicUtils,
};

enum UsingType {
Expand Down Expand Up @@ -571,6 +572,10 @@ class DpctFileInfo {
return insertHeader(HeaderType::HT_CCL, LastIncludeOffset,
"<" + getCustomMainHelperFileName() +
"/ccl_utils.hpp>");
case HT_AtomicUtils:
return insertHeader(HeaderType::HT_AtomicUtils, LastIncludeOffset,
"<" + getCustomMainHelperFileName() +
"/atomic_utils.hpp>");
}
}

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/DPCT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(CONT_FILES
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/kernel.hpp.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/rng_utils.hpp.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/lib_common_utils.hpp.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/atomic_utils.hpp.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpl_extras/algorithm.h.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpl_extras/functional.h.inc
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpl_extras/iterators.h.inc
Expand Down Expand Up @@ -52,6 +53,7 @@ set(PROCESS_FILES_OUTPUT
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/util.all.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/rng_utils.all.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/lib_common_utils.all.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/atomic_utils.all.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/atomic.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/blas_utils.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/dnnl_utils.inc
Expand All @@ -64,6 +66,7 @@ set(PROCESS_FILES_OUTPUT
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/util.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/rng_utils.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/lib_common_utils.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/atomic_utils.inc
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/HelperFeatureEnum.inc
)

Expand Down
1 change: 1 addition & 0 deletions clang/lib/DPCT/CallExprRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,7 @@ void CallExprRewriterFactoryBase::initRewriterMap() {
#include "APINamesWarp.inc"
#include "APINamesCUDNN.inc"
#include "APINamesErrorHandling.inc"
#include "APINamesLIBCU.inc"
#define FUNCTION_CALL
#define CLASS_METHOD_CALL
#include "APINamesCooperativeGroups.inc"
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/DPCT/CustomHelperFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "ASTTraversal.h"
#include "DNNAPIMigration.h"
#include "LIBCUAPIMigration.h"
#include "AnalysisInfo.h"
#include "Config.h"

Expand Down Expand Up @@ -366,6 +367,7 @@ void generateAllHelperFiles() {
GENERATE_ALL_FILE_CONTENT(RngUtils)
GENERATE_ALL_FILE_CONTENT(LibCommonUtils)
GENERATE_ALL_FILE_CONTENT(CclUtils)
GENERATE_ALL_FILE_CONTENT(AtomicUtils)
GENERATE_DPL_EXTRAS_ALL_FILE_CONTENT(DplExtrasAlgorithm)
GENERATE_DPL_EXTRAS_ALL_FILE_CONTENT(DplExtrasFunctional)
GENERATE_DPL_EXTRAS_ALL_FILE_CONTENT(DplExtrasIterators)
Expand Down Expand Up @@ -461,6 +463,7 @@ void generateHelperFunctions() {
std::vector<clang::dpct::HelperFunc> RngUtilsFileContent;
std::vector<clang::dpct::HelperFunc> LibCommonUtilsFileContent;
std::vector<clang::dpct::HelperFunc> CclUtilsFileContent;
std::vector<clang::dpct::HelperFunc> AtomicUtilsFileContent;
std::vector<clang::dpct::HelperFunc> DplExtrasAlgorithmFileContent;
std::vector<clang::dpct::HelperFunc> DplExtrasFunctionalFileContent;
std::vector<clang::dpct::HelperFunc> DplExtrasIteratorsFileContent;
Expand Down Expand Up @@ -575,6 +578,7 @@ void generateHelperFunctions() {
UPDATE_FILE(RngUtils)
UPDATE_FILE(LibCommonUtils)
UPDATE_FILE(CclUtils)
UPDATE_FILE(AtomicUtils)
UPDATE_FILE(DplExtrasAlgorithm)
UPDATE_FILE(DplExtrasFunctional)
UPDATE_FILE(DplExtrasIterators)
Expand Down Expand Up @@ -671,6 +675,7 @@ void generateHelperFunctions() {
ADD_INCLUDE_DIRECTIVE(RngUtils)
ADD_INCLUDE_DIRECTIVE(LibCommonUtils)
ADD_INCLUDE_DIRECTIVE(CclUtils)
ADD_INCLUDE_DIRECTIVE(AtomicUtils)
#undef ADD_INCLUDE_DIRECTIVE

auto Item = HelperNameContentMap.at(std::make_pair(
Expand Down Expand Up @@ -927,6 +932,7 @@ std::map<HelperFeatureIDTy, clang::dpct::HelperFunc> HelperNameContentMap {
#include "clang/DPCT/memory.inc"
#include "clang/DPCT/rng_utils.inc"
#include "clang/DPCT/util.inc"
#include "clang/DPCT/atomic_utils.inc"
#undef DPCT_CONTENT_BEGIN
#undef DPCT_DEPENDENCY
#undef DPCT_CONTENT_END
Expand All @@ -946,6 +952,7 @@ std::unordered_map<clang::dpct::HelperFileEnum, std::string> HelperFileNameMap{
{clang::dpct::HelperFileEnum::RngUtils, "rng_utils.hpp"},
{clang::dpct::HelperFileEnum::LibCommonUtils, "lib_common_utils.hpp"},
{clang::dpct::HelperFileEnum::CclUtils, "ccl_utils.hpp"},
{clang::dpct::HelperFileEnum::AtomicUtils, "atomic_utils.hpp"},
{clang::dpct::HelperFileEnum::DplExtrasAlgorithm, "algorithm.h"},
{clang::dpct::HelperFileEnum::DplExtrasFunctional, "functional.h"},
{clang::dpct::HelperFileEnum::DplExtrasIterators, "iterators.h"},
Expand All @@ -969,6 +976,7 @@ std::unordered_map<std::string, clang::dpct::HelperFileEnum> HelperFileIDMap{
{"rng_utils.hpp", clang::dpct::HelperFileEnum::RngUtils},
{"lib_common_utils.hpp", clang::dpct::HelperFileEnum::LibCommonUtils},
{"ccl_utils.hpp", clang::dpct::HelperFileEnum::CclUtils},
{"atomic_utils.hpp", clang::dpct::HelperFileEnum::AtomicUtils},
{"algorithm.h", clang::dpct::HelperFileEnum::DplExtrasAlgorithm},
{"functional.h", clang::dpct::HelperFileEnum::DplExtrasFunctional},
{"iterators.h", clang::dpct::HelperFileEnum::DplExtrasIterators},
Expand All @@ -994,6 +1002,7 @@ const std::unordered_map<clang::dpct::HelperFileEnum, std::string>
{clang::dpct::HelperFileEnum::LibCommonUtils,
"__DPCT_LIB_COMMON_UTILS_HPP__"},
{clang::dpct::HelperFileEnum::CclUtils, "__DPCT_CCL_HPP__"},
{clang::dpct::HelperFileEnum::AtomicUtils, "__DPCT_ATOMIC_UTILS_HPP__"},
{clang::dpct::HelperFileEnum::DplExtrasAlgorithm,
"__DPCT_ALGORITHM_H__"},
{clang::dpct::HelperFileEnum::DplExtrasFunctional,
Expand Down Expand Up @@ -1054,6 +1063,9 @@ const std::string LibCommonUtilsAllContentStr =
const std::string CclUtilsAllContentStr =
#include "clang/DPCT/ccl_utils.all.inc"
;
const std::string AtomicUtilsAllContentStr =
#include "clang/DPCT/atomic_utils.all.inc"
;
const std::string DplExtrasAlgorithmAllContentStr =
#include "clang/DPCT/dpl_extras/algorithm.all.inc"
;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/DPCT/CustomHelperFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ extern const std::string UtilAllContentStr;
extern const std::string RngUtilsAllContentStr;
extern const std::string LibCommonUtilsAllContentStr;
extern const std::string CclUtilsAllContentStr;
extern const std::string AtomicUtilsAllContentStr;
extern const std::string DplExtrasAlgorithmAllContentStr;
extern const std::string DplExtrasFunctionalAllContentStr;
extern const std::string DplExtrasIteratorsAllContentStr;
Expand Down
Loading