Skip to content

Commit b6a6233

Browse files
author
Jaime Arteaga
committed
Port Add support to propagate compile flags to device backend compiler
intel#8763 Signed-off-by: Jaime Arteaga <[email protected]>
1 parent e38b0cc commit b6a6233

File tree

6 files changed

+60
-23
lines changed

6 files changed

+60
-23
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,11 @@ pi_result piPluginGetLastError(char **message) {
6161
// Return '-ze-opt-disable' for frontend_option = -O0.
6262
// Return '-ze-opt-level=1' for frontend_option = -O1 or -O2.
6363
// Return '-ze-opt-level=2' for frontend_option = -O3.
64-
pi_result piPluginGetBackendOption(pi_platform, const char *frontend_option,
64+
pi_result piPluginGetBackendOption(pi_platform platform,
65+
const char *frontend_option,
6566
const char **backend_option) {
66-
using namespace std::literals;
67-
if (frontend_option == nullptr) {
68-
return PI_ERROR_INVALID_VALUE;
69-
}
70-
if (frontend_option == ""sv) {
71-
*backend_option = "";
72-
return PI_SUCCESS;
73-
}
74-
if (frontend_option == "-O0"sv) {
75-
*backend_option = "-ze-opt-disable";
76-
return PI_SUCCESS;
77-
}
78-
if (frontend_option == "-O1"sv || frontend_option == "-O2"sv) {
79-
*backend_option = "-ze-opt-level=1";
80-
return PI_SUCCESS;
81-
}
82-
if (frontend_option == "-O3"sv) {
83-
*backend_option = "-ze-opt-level=2";
84-
return PI_SUCCESS;
85-
}
86-
return PI_ERROR_INVALID_VALUE;
67+
return pi2ur::piPluginGetBackendOption(platform, frontend_option,
68+
backend_option);
8769
}
8870

8971
pi_result piDevicesGet(pi_platform Platform, pi_device_type DeviceType,

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (NOT DEFINED UNIFIED_RUNTIME_LIBRARY OR NOT DEFINED UNIFIED_RUNTIME_INCLUDE_D
44
include(FetchContent)
55

66
set(UNIFIED_RUNTIME_REPO "https://github.com/jandres742/unified-runtime.git")
7-
set(UNIFIED_RUNTIME_TAG 6bcd2a224d717cf904568d7311e84e2d057fcbef)
7+
set(UNIFIED_RUNTIME_TAG b674dc2b59997d5b6cff462f8c33ee05a2ce0450)
88

99
message(STATUS "Will fetch Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
1010
FetchContent_Declare(unified-runtime

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,22 @@ inline pi_result piextPluginGetOpaqueData(void *opaque_data_param,
506506
return PI_ERROR_UNKNOWN;
507507
}
508508

509+
// Returns plugin specific backend option.
510+
// Current support is only for optimization options.
511+
// Return '-ze-opt-disable' for frontend_option = -O0.
512+
// Return '-ze-opt-level=1' for frontend_option = -O1 or -O2.
513+
// Return '-ze-opt-level=2' for frontend_option = -O3.
514+
inline pi_result piPluginGetBackendOption(pi_platform Platform,
515+
const char *FrontendOption,
516+
const char **PlatformOption) {
517+
518+
auto UrPlatform = reinterpret_cast<ur_platform_handle_t>(Platform);
519+
HANDLE_ERRORS(
520+
urPlatformGetBackendOption(UrPlatform, FrontendOption, PlatformOption));
521+
522+
return PI_SUCCESS;
523+
}
524+
509525
// Platform
510526
///////////////////////////////////////////////////////////////////////////////
511527

sycl/plugins/unified_runtime/pi_unified_runtime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,13 @@ __SYCL_EXPORT pi_result piGetDeviceAndHostTimer(pi_device Device,
981981
return pi2ur::piGetDeviceAndHostTimer(Device, DeviceTime, HostTime);
982982
}
983983

984+
__SYCL_EXPORT pi_result piPluginGetBackendOption(pi_platform platform,
985+
const char *frontend_option,
986+
const char **backend_option) {
987+
return pi2ur::piPluginGetBackendOption(platform, frontend_option,
988+
backend_option);
989+
}
990+
984991
// This interface is not in Unified Runtime currently
985992
__SYCL_EXPORT pi_result piTearDown(void *PluginParameter) {
986993
return pi2ur::piTearDown(PluginParameter);
@@ -1025,6 +1032,7 @@ __SYCL_EXPORT pi_result piPluginInit(pi_plugin *PluginInit) {
10251032
_PI_API(piextPlatformCreateWithNativeHandle)
10261033
_PI_API(piextDeviceGetNativeHandle)
10271034
_PI_API(piextDeviceCreateWithNativeHandle)
1035+
_PI_API(piPluginGetBackendOption)
10281036

10291037
_PI_API(piContextCreate)
10301038
_PI_API(piContextRelease)

sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero_platform.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,33 @@ ur_result_t ur_platform_handle_t_::populateDeviceCacheIfNeeded() {
536536
DeviceCachePopulated = true;
537537
return UR_RESULT_SUCCESS;
538538
}
539+
540+
UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
541+
ur_platform_handle_t Platform, ///< [in] handle of the platform instance.
542+
const char *FrontendOption, ///< [in] string containing the frontend option.
543+
const char *
544+
*PlatformOption ///< [out] returns the correct platform specific
545+
///< compiler option based on the frontend option.
546+
) {
547+
using namespace std::literals;
548+
if (FrontendOption == nullptr) {
549+
return UR_RESULT_SUCCESS;
550+
}
551+
if (FrontendOption == ""sv) {
552+
*PlatformOption = "";
553+
return UR_RESULT_SUCCESS;
554+
}
555+
if (FrontendOption == "-O0"sv) {
556+
*PlatformOption = "-ze-opt-disable";
557+
return UR_RESULT_SUCCESS;
558+
}
559+
if (FrontendOption == "-O1"sv || FrontendOption == "-O2"sv) {
560+
*PlatformOption = "-ze-opt-level=1";
561+
return UR_RESULT_SUCCESS;
562+
}
563+
if (FrontendOption == "-O3"sv) {
564+
*PlatformOption = "-ze-opt-level=2";
565+
return UR_RESULT_SUCCESS;
566+
}
567+
return UR_RESULT_ERROR_INVALID_VALUE;
568+
}

sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_loader_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable(
180180
pDdiTable->pfnGetNativeHandle = urPlatformGetNativeHandle;
181181
pDdiTable->pfnCreateWithNativeHandle = urPlatformCreateWithNativeHandle;
182182
pDdiTable->pfnGetApiVersion = urPlatformGetApiVersion;
183+
pDdiTable->pfnGetBackendOption = urPlatformGetBackendOption;
183184

184185
return retVal;
185186
}

0 commit comments

Comments
 (0)