Skip to content

Commit e9b108d

Browse files
authored
[SYCLomaitc] Add migration for 3 IPC memory API to level zero APIs with option: --use-experimental-features=level_zero (#2694)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent 7053fdf commit e9b108d

24 files changed

+508
-24
lines changed

clang/include/clang/DPCT/DPCTOptions.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@ DPCT_ENUM_OPTION(
834834
"prefetch", int(ExperimentalFeatures::Exp_Prefetch),
835835
"Experimental extension that allows use of SYCL prefetch APIs.\n",
836836
false),
837+
DPCT_OPTION_ENUM_VALUE(
838+
"level_zero", int(ExperimentalFeatures::Exp_LevelZero),
839+
"Experimental migration feature that enables the use of Level Zero "
840+
"APIs to migrate target code, like CUDA Inter-Process "
841+
"Communication (IPC) APIs.\n", false),
837842
DPCT_OPTION_ENUM_VALUE(
838843
"all", int(ExperimentalFeatures::Exp_All),
839844
"Enable all experimental extensions listed in this option.\n",

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,9 @@ void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset,
905905
// Add the label for profiling macro "DPCT_PROFILING_ENABLED", which will be
906906
// replaced by "#define DPCT_PROFILING_ENABLED" or not in the post
907907
// replacement.
908+
if (DpctGlobalInfo::useExtLevelZero())
909+
OS << "#define ONEAPI_BACKEND_LEVEL_ZERO_EXT" << getNL();
910+
908911
OS << "{{NEEDREPLACEP0}}";
909912

910913
if (DpctGlobalInfo::getUsmLevel() == UsmLevel::UL_None)

clang/lib/DPCT/AnalysisInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,9 @@ class DpctGlobalInfo {
13491349
return getUsingExperimental<
13501350
ExperimentalFeatures::Exp_NonStandardSYCLBuiltins>();
13511351
}
1352+
static bool useExtLevelZero() {
1353+
return getUsingExperimental<ExperimentalFeatures::Exp_LevelZero>();
1354+
}
13521355
static bool useExtPrefetch() {
13531356
return getUsingExperimental<ExperimentalFeatures::Exp_Prefetch>();
13541357
}

clang/lib/DPCT/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(RUNTIME_HEADERS
2121
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/lib_common_utils.hpp
2222
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/ccl_utils.hpp
2323
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/sparse_utils.hpp
24+
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/ze_utils.hpp
2425
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/fft_utils.hpp
2526
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/lapack_utils.hpp
2627
${CMAKE_SOURCE_DIR}/../clang/runtime/dpct-rt/include/dpct/group_utils.hpp
@@ -71,6 +72,7 @@ set(PROCESS_FILES_OUTPUT
7172
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/rng_utils.hpp.inc
7273
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/lib_common_utils.hpp.inc
7374
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/ccl_utils.hpp.inc
75+
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/ze_utils.hpp.inc
7476
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/sparse_utils.hpp.inc
7577
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/fft_utils.hpp.inc
7678
${CMAKE_BINARY_DIR}/tools/clang/include/clang/DPCT/lapack_utils.hpp.inc

clang/lib/DPCT/CommandOption/ValidateArguments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ enum class ExperimentalFeatures : unsigned int {
102102
Exp_ExperimentalFeaturesEnumSize,
103103
Exp_NonStandardSYCLBuiltins,
104104
Exp_Prefetch,
105+
Exp_LevelZero,
105106
Exp_All
106107
};
107108
enum class HelperFuncPreference : unsigned int { NoQueueDevice = 0 };

clang/lib/DPCT/DPCT.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,8 @@ int runDPCT(int argc, const char **argv) {
10611061
Experimentals.addValue(ExperimentalFeatures::Exp_Graph);
10621062
else if (Option.ends_with("prefetch"))
10631063
Experimentals.addValue(ExperimentalFeatures::Exp_Prefetch);
1064+
else if (Option.ends_with("level_zero"))
1065+
Experimentals.addValue(ExperimentalFeatures::Exp_LevelZero);
10641066
} else if (Option == "--no-dry-pattern") {
10651067
NoDRYPattern.setValue(true);
10661068
}

clang/lib/DPCT/FileGenerator/GenHelperFunction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ const std::string CodePinSerializationBasicAllContentStr =
150150
#include "clang/DPCT/codepin/serialization/basic.hpp.inc"
151151
;
152152

153+
const std::string ZEUtilsAllContentStr =
154+
#include "clang/DPCT/ze_utils.hpp.inc"
155+
;
156+
153157
const std::string CmakeAllContentStr =
154158
#include "clang/DPCT/dpct.cmake.inc"
155159
;
@@ -206,6 +210,7 @@ void genHelperFunction(const clang::tooling::UnifiedPath &OutRoot) {
206210
GENERATE_ALL_FILE_CONTENT(Util, ".", util.hpp)
207211
GENERATE_ALL_FILE_CONTENT(RngUtils, ".", rng_utils.hpp)
208212
GENERATE_ALL_FILE_CONTENT(LibCommonUtils, ".", lib_common_utils.hpp)
213+
GENERATE_ALL_FILE_CONTENT(ZEUtils, ".", ze_utils.hpp)
209214
GENERATE_ALL_FILE_CONTENT(CclUtils, ".", ccl_utils.hpp)
210215
GENERATE_ALL_FILE_CONTENT(SparseUtils, ".", sparse_utils.hpp)
211216
GENERATE_ALL_FILE_CONTENT(FftUtils, ".", fft_utils.hpp)

clang/lib/DPCT/FileGenerator/GenHelperFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern const std::string MathDetailAllContentStr;
4545
extern const std::string MemoryDetailAllContentStr;
4646
extern const std::string CodePinAllContentStr;
4747
extern const std::string CodePinSerializationBasicAllContentStr;
48+
extern const std::string ZEUtilsAllContentStr;
4849
extern const std::string DpctCmakeHelperFileStr;
4950
void genHelperFunction(const clang::tooling::UnifiedPath &OutRoot);
5051
void genCmakeHelperFunction(const clang::tooling::UnifiedPath &OutRoot);

clang/lib/DPCT/RuleInfra/CallExprRewriterCommon.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,10 @@ inline auto UseExtBindlessImages = [](const CallExpr *C) -> bool {
18251825
return DpctGlobalInfo::useExtBindlessImages();
18261826
};
18271827

1828+
inline auto UseExtLevelZero = [](const CallExpr *C) -> bool {
1829+
return DpctGlobalInfo::useExtLevelZero();
1830+
};
1831+
18281832
inline auto UseExtGraph = [](const CallExpr *C) -> bool {
18291833
return DpctGlobalInfo::useExtGraph();
18301834
};

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ void MapNames::setExplicitNamespaceMap(
363363
{"CUstreamCallback",
364364
std::make_shared<TypeNameRule>(getDpctNamespace() + "queue_callback",
365365
HelperFeatureEnum::device_ext)},
366+
{"cudaIpcMemHandle_t",
367+
std::make_shared<TypeNameRule>(getDpctNamespace() +
368+
"experimental::ipc_mem_handle_ext_t")},
366369
{"char1", std::make_shared<TypeNameRule>("int8_t")},
367370
{"char2", std::make_shared<TypeNameRule>(getClNamespace() + "char2")},
368371
{"char3", std::make_shared<TypeNameRule>(getClNamespace() + "char3")},

0 commit comments

Comments
 (0)