Skip to content

[SYCLomatic] Add migration support for cudaKernelNodeParams, cudaKernelAddKernelNode, cudaGraphKernelNodeSetParams, cudaKernelNodeGetParams #2803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: SYCLomatic
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ REGISTER_RULE(TypeRemoveRule, PassKind::PK_Analysis)
REGISTER_RULE(CompatWithClangRule, PassKind::PK_Migration)
REGISTER_RULE(AssertRule, PassKind::PK_Migration)
REGISTER_RULE(GraphRule, PassKind::PK_Migration)
REGISTER_RULE(GraphAnalysisRule, PassKind::PK_Analysis)
REGISTER_RULE(GraphicsInteropRule, PassKind::PK_Migration)
REGISTER_RULE(RulesLangAddrSpaceConvRule, PassKind::PK_Migration)

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ unsigned DpctGlobalInfo::ExperimentalFlag = 0;
unsigned DpctGlobalInfo::HelperFuncPreferenceFlag = 0;
bool DpctGlobalInfo::AnalysisModeFlag = false;
bool DpctGlobalInfo::UseSYCLCompatFlag = false;
bool DpctGlobalInfo::CVersionCUDALaunchUsedFlag = false;
bool DpctGlobalInfo::UseWrapperRegisterFnPtrFlag = false;
unsigned int DpctGlobalInfo::ColorOption = 1;
std::unordered_map<int, std::shared_ptr<DeviceFunctionInfo>>
DpctGlobalInfo::CubPlaceholderIndexMap;
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/DPCT/AnalysisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1355,8 +1355,10 @@ class DpctGlobalInfo {
static bool useNoQueueDevice() {
return getHelperFuncPreference(HelperFuncPreference::NoQueueDevice);
}
static void setCVersionCUDALaunchUsed() { CVersionCUDALaunchUsedFlag = true; }
static bool isCVersionCUDALaunchUsed() { return CVersionCUDALaunchUsedFlag; }
static void setUseWrapperRegisterFnPtr() {
UseWrapperRegisterFnPtrFlag = true;
}
static bool useWrapperRegisterFnPtr() { return UseWrapperRegisterFnPtrFlag; }
static void setUseSYCLCompat(bool Flag = true) { UseSYCLCompatFlag = Flag; }
static bool useSYCLCompat() { return UseSYCLCompatFlag; }
static bool useEnqueueBarrier() {
Expand Down Expand Up @@ -1686,7 +1688,7 @@ class DpctGlobalInfo {
static unsigned HelperFuncPreferenceFlag;
static bool AnalysisModeFlag;
static bool UseSYCLCompatFlag;
static bool CVersionCUDALaunchUsedFlag;
static bool UseWrapperRegisterFnPtrFlag;
static unsigned int ColorOption;
static std::unordered_map<int, std::shared_ptr<DeviceFunctionInfo>>
CubPlaceholderIndexMap;
Expand Down
16 changes: 16 additions & 0 deletions clang/lib/DPCT/RuleInfra/APINamesTemplateType.inc
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ TYPE_REWRITE_ENTRY(
WARNING_FACTORY(Diagnostics::TRY_EXPERIMENTAL_FEATURE, TYPESTR,
STR("--use-experimental-features=graph"))))

TYPE_REWRITE_ENTRY(
"cudaGraphExecUpdateResultInfo",
TYPE_CONDITIONAL_FACTORY(
checkEnableGraphForType(), TYPE_FACTORY(STR("int")),
WARNING_FACTORY(Diagnostics::TRY_EXPERIMENTAL_FEATURE, TYPESTR,
STR("--use-experimental-features=graph"))))

TYPE_REWRITE_ENTRY(
"cudaKernelNodeParams",
TYPE_CONDITIONAL_FACTORY(
checkEnableGraphForType(),
TYPE_FACTORY(STR(MapNames::getDpctNamespace() +
"experimental::kernel_node_params")),
WARNING_FACTORY(Diagnostics::TRY_EXPERIMENTAL_FEATURE, TYPESTR,
STR("--use-experimental-features=graph"))))

// Graphics Interop Handle
TYPE_REWRITE_ENTRY(
"cudaGraphicsResource",
Expand Down
45 changes: 45 additions & 0 deletions clang/lib/DPCT/RuleInfra/MapNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ void MapNames::setExplicitNamespaceMap(
DpctGlobalInfo::useExtGraph()
? getClNamespace() + "ext::oneapi::experimental::node_type"
: "cudaGraphNodeType")},
{"cudaGraphExecUpdateResult",
std::make_shared<TypeNameRule>(DpctGlobalInfo::useExtGraph()
? "int"
: "cudaGraphExecUpdateResult")},
{"CUmem_advise", std::make_shared<TypeNameRule>("int")},
{"CUmemorytype",
std::make_shared<TypeNameRule>(getClNamespace() + "usm::alloc")},
Expand Down Expand Up @@ -1151,6 +1155,47 @@ void MapNames::setExplicitNamespaceMap(
? getClNamespace() +
"ext::oneapi::experimental::node_type::empty"
: "cudaGraphNodeTypeEmpty")},
{"cudaGraphExecUpdateSuccess",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph() ? "1" : "cudaGraphExecUpdateSuccess")},
{"cudaGraphExecUpdateError",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph() ? "0" : "cudaGraphExecUpdateError")},
{"cudaGraphExecUpdateErrorTopologyChanged",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorTopologyChanged")},
{"cudaGraphExecUpdateErrorNodeTypeChanged",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorNodeTypeChanged")},
{"cudaGraphExecUpdateErrorFunctionChanged",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorFunctionChanged")},
{"cudaGraphExecUpdateErrorParametersChanged",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorParametersChanged")},
{"cudaGraphExecUpdateErrorNotSupported",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorNotSupported")},
{"cudaGraphExecUpdateErrorUnsupportedFunctionChange",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorUnsupportedFunctionChange")},
{"cudaGraphExecUpdateErrorAttributesChanged",
std::make_shared<EnumNameRule>(
DpctGlobalInfo::useExtGraph()
? "0"
: "cudaGraphExecUpdateErrorAttributesChanged")},
// enum CUmem_advise_enum
{"CU_MEM_ADVISE_SET_READ_MOSTLY", std::make_shared<EnumNameRule>("0")},
{"CU_MEM_ADVISE_UNSET_READ_MOSTLY", std::make_shared<EnumNameRule>("0")},
Expand Down
70 changes: 52 additions & 18 deletions clang/lib/DPCT/RulesLang/APINamesGraph.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
//
//===----------------------------------------------------------------------===//

CONDITIONAL_FACTORY_ENTRY(
ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY(
"cudaGraphInstantiate", DEREF(0),
NEW(MapNames::getClNamespace() +
"ext::oneapi::experimental::command_graph<" +
MapNames::getClNamespace() +
"ext::oneapi::experimental::graph_state::executable>",
MEMBER_CALL(ARG(1), true, "finalize")))),
CALL_FACTORY_ENTRY("cudaGraphInstantiate",
CALL(MapNames::getDpctNamespace() +
"experimental::instantiate",
ARG(0), ARG(1))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphInstantiate",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphInstantiate"),
ARG("--use-experimental-features=graph")))
ARG("--use-experimental-features=graph"))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph, DELETE_FACTORY_ENTRY("cudaGraphExecDestroy", ARG(0)),
Expand All @@ -29,8 +26,9 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
MEMBER_CALL_FACTORY_ENTRY("cudaGraphLaunch", ARG(1), true,
"ext_oneapi_graph", DEREF(0)),
CALL_FACTORY_ENTRY("cudaGraphLaunch", CALL(MapNames::getDpctNamespace() +
"experimental::launch",
ARG(0), ARG(1))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphLaunch",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphLaunch"),
Expand Down Expand Up @@ -60,22 +58,25 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
MEMBER_CALL_FACTORY_ENTRY("cudaGraphExecUpdate", ARG(0), true, "update",
DEREF(1)),
CALL_FACTORY_ENTRY("cudaGraphExecUpdate",
CALL(MapNames::getDpctNamespace() +
"experimental::update",
ARG(0), ARG(1), ARG(2))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphExecUpdate",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphExecUpdate"),
ARG("--use-experimental-features=graph"))))

CONDITIONAL_FACTORY_ENTRY(
ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cudaGraphNodeGetType", DEREF(1),
MEMBER_CALL(ARG(0), true,
"get_type"))),
CALL_FACTORY_ENTRY("cudaGraphNodeGetType",
CALL(MapNames::getDpctNamespace() +
"experimental::get_node_type",
ARG(0), ARG(1))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphNodeGetType",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphNodeGetType"),
ARG("--use-experimental-features=graph")))
ARG("--use-experimental-features=graph"))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
Expand Down Expand Up @@ -104,3 +105,36 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphDestroy"),
ARG("--use-experimental-features=graph"))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
CALL_FACTORY_ENTRY("cudaGraphAddKernelNode",
CALL(MapNames::getDpctNamespace() +
"experimental::add_kernel_node",
ARG(0), ARG(1), ARG(2), ARG(3), ARG(4))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphAddKernelNode",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphAddKernelNode"),
ARG("--use-experimental-features=graph"))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
CALL_FACTORY_ENTRY("cudaGraphKernelNodeGetParams",
CALL(MapNames::getDpctNamespace() +
"experimental::kernel_node_get_params",
ARG(0), ARG(1))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphKernelNodeGetParams",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphKernelNodeGetParams"),
ARG("--use-experimental-features=graph"))))

ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
UseExtGraph,
CALL_FACTORY_ENTRY("cudaGraphKernelNodeSetParams",
CALL(MapNames::getDpctNamespace() +
"experimental::kernel_node_set_params",
ARG(0), ARG(1))),
UNSUPPORT_FACTORY_ENTRY("cudaGraphKernelNodeSetParams",
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
ARG("cudaGraphKernelNodeSetParams"),
ARG("--use-experimental-features=graph"))))
10 changes: 9 additions & 1 deletion clang/lib/DPCT/RulesLang/MapNamesLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,13 @@ const std::unordered_map<std::string, HelperFeatureEnum>
{"sampler", HelperFeatureEnum::device_ext},
};

// Graph kernel node params mapping
MapNamesLang::MapTy GraphRule::KernelNodeParamNames{
{"gridDim", "grid_dim"},
{"blockDim", "block_dim"},
{"kernelParams", "kernel_params"},
{"sharedMemBytes", "shared_mem_bytes"},
{"func", "func"}};

} // namespace dpct
} // namespace clang
} // namespace clang
Loading