diff --git a/sycl/include/sycl/backend_types.hpp b/sycl/include/sycl/backend_types.hpp index 563ff1ed60416..c8d3d2aaae4bc 100644 --- a/sycl/include/sycl/backend_types.hpp +++ b/sycl/include/sycl/backend_types.hpp @@ -32,6 +32,7 @@ enum class backend : char { ext_intel_esimd_emulator, ext_oneapi_hip = 6, hip __SYCL2020_DEPRECATED("use 'ext_oneapi_hip' instead") = ext_oneapi_hip, + ext_oneapi_unified_runtime = 7, }; template class backend_traits; @@ -63,6 +64,9 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) { case backend::ext_oneapi_hip: Out << "ext_oneapi_hip"; break; + case backend::ext_oneapi_unified_runtime: + Out << "ext_oneapi_unified_runtime"; + break; case backend::all: Out << "all"; } diff --git a/sycl/include/sycl/detail/pi.hpp b/sycl/include/sycl/detail/pi.hpp index de1e61643596b..2284af4f6358e 100644 --- a/sycl/include/sycl/detail/pi.hpp +++ b/sycl/include/sycl/detail/pi.hpp @@ -67,11 +67,13 @@ bool trace(TraceLevel level); #define __SYCL_CUDA_PLUGIN_NAME "pi_cuda.dll" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "pi_esimd_emulator.dll" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll" +#define __SYCL_UNIFIED_RUNTIME_PLUGIN_NAME "pi_unified_runtime.dll" #elif defined(__SYCL_RT_OS_LINUX) #define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.so" #define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.so" #define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.so" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.so" +#define __SYCL_UNIFIED_RUNTIME_PLUGIN_NAME "libpi_unified_runtime.so" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.so" #elif defined(__SYCL_RT_OS_DARWIN) #define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dylib" @@ -79,6 +81,7 @@ bool trace(TraceLevel level); #define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dylib" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dylib" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dylib" +#define __SYCL_UNIFIED_RUNTIME_PLUGIN_NAME "libpi_unified_runtime.dylib" #else #error "Unsupported OS" #endif diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 94c14c270e016..ca6db69d26b76 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -198,87 +198,6 @@ template <> ze_result_t zeHostSynchronize(ze_command_queue_handle_t Handle) { return zeHostSynchronizeImpl(zeCommandQueueSynchronize, Handle); } -template -pi_result getInfoImpl(size_t param_value_size, void *param_value, - size_t *param_value_size_ret, T value, size_t value_size, - Assign &&assign_func) { - - if (param_value != nullptr) { - - if (param_value_size < value_size) { - return PI_ERROR_INVALID_VALUE; - } - - assign_func(param_value, value, value_size); - } - - if (param_value_size_ret != nullptr) { - *param_value_size_ret = value_size; - } - - return PI_SUCCESS; -} - -template -pi_result getInfo(size_t param_value_size, void *param_value, - size_t *param_value_size_ret, T value) { - - auto assignment = [](void *param_value, T value, size_t value_size) { - (void)value_size; - *static_cast(param_value) = value; - }; - - return getInfoImpl(param_value_size, param_value, param_value_size_ret, value, - sizeof(T), assignment); -} - -template -pi_result getInfoArray(size_t array_length, size_t param_value_size, - void *param_value, size_t *param_value_size_ret, - T *value) { - return getInfoImpl(param_value_size, param_value, param_value_size_ret, value, - array_length * sizeof(T), memcpy); -} - -template -pi_result getInfoArray(size_t array_length, size_t param_value_size, - void *param_value, size_t *param_value_size_ret, - T *value) { - if (param_value) { - memset(param_value, 0, param_value_size); - for (uint32_t I = 0; I < array_length; I++) - ((RetType *)param_value)[I] = (RetType)value[I]; - } - if (param_value_size_ret) - *param_value_size_ret = array_length * sizeof(RetType); - return PI_SUCCESS; -} - -template <> -pi_result getInfo(size_t param_value_size, void *param_value, - size_t *param_value_size_ret, - const char *value) { - return getInfoArray(strlen(value) + 1, param_value_size, param_value, - param_value_size_ret, value); -} - -class ReturnHelper { -public: - ReturnHelper(size_t param_value_size, void *param_value, - size_t *param_value_size_ret) - : param_value_size(param_value_size), param_value(param_value), - param_value_size_ret(param_value_size_ret) {} - - template pi_result operator()(const T &t) { - return getInfo(param_value_size, param_value, param_value_size_ret, t); - } - -private: - size_t param_value_size; - void *param_value; - size_t *param_value_size_ret; -}; - } // anonymous namespace // SYCL_PI_LEVEL_ZERO_USE_COMPUTE_ENGINE can be set to an integer (>=0) in @@ -439,11 +358,6 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) { return PI_SUCCESS; } -// Some opencl extensions we know are supported by all Level Zero devices. -constexpr char ZE_SUPPORTED_EXTENSIONS[] = - "cl_khr_il_program cl_khr_subgroups cl_intel_subgroups " - "cl_intel_subgroups_short cl_intel_required_subgroup_size "; - // Forward declarations static pi_result enqueueMemCopyHelper(pi_command_type CommandType, pi_queue Queue, void *Dst, @@ -2307,51 +2221,17 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms, pi_result piPlatformGetInfo(pi_platform Platform, pi_platform_info ParamName, size_t ParamValueSize, void *ParamValue, size_t *ParamValueSizeRet) { - - PI_ASSERT(Platform, PI_ERROR_INVALID_PLATFORM); - zePrint("==========================\n"); zePrint("SYCL over Level-Zero %s\n", Platform->ZeDriverVersion.c_str()); zePrint("==========================\n"); - ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet); - - switch (ParamName) { - case PI_PLATFORM_INFO_NAME: - // TODO: Query Level Zero driver when relevant info is added there. + // To distinguish this L0 platform from Unified Runtime one. + if (ParamName == PI_PLATFORM_INFO_NAME) { + ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet); return ReturnValue("Intel(R) Level-Zero"); - case PI_PLATFORM_INFO_VENDOR: - // TODO: Query Level Zero driver when relevant info is added there. - return ReturnValue("Intel(R) Corporation"); - case PI_PLATFORM_INFO_EXTENSIONS: - // Convention adopted from OpenCL: - // "Returns a space-separated list of extension names (the extension - // names themselves do not contain any spaces) supported by the platform. - // Extensions defined here must be supported by all devices associated - // with this platform." - // - // TODO: Check the common extensions supported by all connected devices and - // return them. For now, hardcoding some extensions we know are supported by - // all Level Zero devices. - return ReturnValue(ZE_SUPPORTED_EXTENSIONS); - case PI_PLATFORM_INFO_PROFILE: - // TODO: figure out what this means and how is this used - return ReturnValue("FULL_PROFILE"); - case PI_PLATFORM_INFO_VERSION: - // TODO: this should query to zeDriverGetDriverVersion - // but we don't yet have the driver handle here. - // - // From OpenCL 2.1: "This version string has the following format: - // OpenCL. Follow the same notation here. - // - return ReturnValue(Platform->ZeDriverApiVersion.c_str()); - default: - zePrint("piPlatformGetInfo: unrecognized ParamName\n"); - return PI_ERROR_INVALID_VALUE; } - - return PI_SUCCESS; + return pi2ur::piPlatformGetInfo(Platform, ParamName, ParamValueSize, + ParamValue, ParamValueSizeRet); } pi_result piextPlatformGetNativeHandle(pi_platform Platform, @@ -3068,10 +2948,9 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName, case PI_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: { // ze_device_compute_properties.subGroupSizes is in uint32_t whereas the // expected return is size_t datatype. size_t can be 8 bytes of data. - return getInfoArray( - Device->ZeDeviceComputeProperties->numSubGroupSizes, ParamValueSize, - ParamValue, ParamValueSizeRet, - Device->ZeDeviceComputeProperties->subGroupSizes); + return ReturnValue.template operator()( + Device->ZeDeviceComputeProperties->subGroupSizes, + Device->ZeDeviceComputeProperties->numSubGroupSizes); } case PI_DEVICE_INFO_IL_VERSION: { // Set to a space separated list of IL version strings of the form @@ -3463,8 +3342,7 @@ pi_result piContextGetInfo(pi_context Context, pi_context_info ParamName, ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet); switch (ParamName) { case PI_CONTEXT_INFO_DEVICES: - return getInfoArray(Context->Devices.size(), ParamValueSize, ParamValue, - ParamValueSizeRet, &Context->Devices[0]); + return ReturnValue(&Context->Devices[0], Context->Devices.size()); case PI_CONTEXT_INFO_NUM_DEVICES: return ReturnValue(pi_uint32(Context->Devices.size())); case PI_CONTEXT_INFO_REFERENCE_COUNT: @@ -5375,7 +5253,8 @@ pi_result piKernelGetGroupInfo(pi_kernel Kernel, pi_device Device, return ReturnValue(WorkSize); } case PI_KERNEL_GROUP_INFO_WORK_GROUP_SIZE: { - // As of right now, L0 is missing API to query kernel and device specific max work group size. + // As of right now, L0 is missing API to query kernel and device specific + // max work group size. return ReturnValue( pi_uint64{Device->ZeDeviceComputeProperties->maxTotalGroupSize}); } diff --git a/sycl/plugins/unified_runtime/pi2ur.hpp b/sycl/plugins/unified_runtime/pi2ur.hpp index c36d7d8e3240c..e1bf8f73ca1ad 100644 --- a/sycl/plugins/unified_runtime/pi2ur.hpp +++ b/sycl/plugins/unified_runtime/pi2ur.hpp @@ -15,13 +15,7 @@ // Map of UR error codes to PI error codes static pi_result ur2piResult(zer_result_t urResult) { - - // TODO: replace "global lifetime" objects with a non-trivial d'tor with - // either pointers to such objects (which would be allocated and dealocated - // during init and teardown) or objects with trivial d'tor. - // E.g. for this case we could have an std::array with sorted values. - // - static std::unordered_map ErrorMapping = { + std::unordered_map ErrorMapping = { {ZER_RESULT_SUCCESS, PI_SUCCESS}, {ZER_RESULT_ERROR_UNKNOWN, PI_ERROR_UNKNOWN}, {ZER_RESULT_ERROR_DEVICE_LOST, PI_ERROR_DEVICE_NOT_FOUND}, @@ -50,6 +44,24 @@ static pi_result ur2piResult(zer_result_t urResult) { if (auto Result = urCall) \ return ur2piResult(Result); +// A version of return helper that returns pi_result and not zer_result_t +class ReturnHelper : public UrReturnHelper { +public: + using UrReturnHelper::UrReturnHelper; + + template pi_result operator()(const T &t) { + return ur2piResult(UrReturnHelper::operator()(t)); + } + // Array return value + template pi_result operator()(const T *t, size_t s) { + return ur2piResult(UrReturnHelper::operator()(t, s)); + } + // Array return value where element type is differrent from T + template pi_result operator()(const T *t, size_t s) { + return ur2piResult(UrReturnHelper::operator()(t, s)); + } +}; + namespace pi2ur { inline pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms, pi_uint32 *num_platforms) { @@ -66,14 +78,31 @@ inline pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms, } inline pi_result piPlatformGetInfo(pi_platform platform, - pi_platform_info param_name, - size_t param_value_size, void *param_value, - size_t *param_value_size_ret) { - (void)platform; - (void)param_name; - (void)param_value_size; - (void)param_value; - (void)param_value_size_ret; - die("Unified Runtime: piPlatformGetInfo is not implemented"); + pi_platform_info ParamName, + size_t ParamValueSize, void *ParamValue, + size_t *ParamValueSizeRet) { + + static std::unordered_map InfoMapping = + { + {PI_PLATFORM_INFO_EXTENSIONS, ZER_PLATFORM_INFO_NAME}, + {PI_PLATFORM_INFO_NAME, ZER_PLATFORM_INFO_NAME}, + {PI_PLATFORM_INFO_PROFILE, ZER_PLATFORM_INFO_PROFILE}, + {PI_PLATFORM_INFO_VENDOR, ZER_PLATFORM_INFO_VENDOR_NAME}, + {PI_PLATFORM_INFO_VERSION, ZER_PLATFORM_INFO_VERSION}, + }; + + auto InfoType = InfoMapping.find(ParamName); + if (InfoType == InfoMapping.end()) { + return PI_ERROR_UNKNOWN; + } + + size_t SizeInOut = ParamValueSize; + auto hPlatform = reinterpret_cast(platform); + HANDLE_ERRORS( + zerPlatformGetInfo(hPlatform, InfoType->second, &SizeInOut, ParamValue)); + if (ParamValueSizeRet) { + *ParamValueSizeRet = SizeInOut; + } + return PI_SUCCESS; } } // namespace pi2ur diff --git a/sycl/plugins/unified_runtime/pi_unified_runtime.cpp b/sycl/plugins/unified_runtime/pi_unified_runtime.cpp index fe7cab726caa6..ee8e996789a0e 100644 --- a/sycl/plugins/unified_runtime/pi_unified_runtime.cpp +++ b/sycl/plugins/unified_runtime/pi_unified_runtime.cpp @@ -6,12 +6,79 @@ // //===------------------------------------------------------------------===// +#include + #include +#include + +// Stub function to where all not yet supported PI API are bound +static void DieUnsupported() { + die("Unified Runtime: functionality is not supported"); +} +// All PI API interfaces are C interfaces extern "C" { __SYCL_EXPORT pi_result piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms, pi_uint32 *num_platforms) { return pi2ur::piPlatformsGet(num_entries, platforms, num_platforms); } + +__SYCL_EXPORT pi_result piPlatformGetInfo(pi_platform Platform, + pi_platform_info ParamName, + size_t ParamValueSize, + void *ParamValue, + size_t *ParamValueSizeRet) { + return pi2ur::piPlatformGetInfo(Platform, ParamName, ParamValueSize, + ParamValue, ParamValueSizeRet); +} + +__SYCL_EXPORT pi_result piDevicesGet(pi_platform Platform, + pi_device_type DeviceType, + pi_uint32 NumEntries, pi_device *Devices, + pi_uint32 *NumDevices) { + // Report no devices, stab to have a minimal SYCL test running + if (NumDevices) { + *NumDevices = 0; + } + return PI_SUCCESS; +} + +// This interface is not in Unified Runtime currently +__SYCL_EXPORT pi_result piTearDown(void *) { return PI_SUCCESS; } + +// This interface is not in Unified Runtime currently +__SYCL_EXPORT pi_result piPluginInit(pi_plugin *PluginInit) { + PI_ASSERT(PluginInit, PI_ERROR_INVALID_VALUE); + + const char SupportedVersion[] = _PI_UNIFIED_RUNTIME_PLUGIN_VERSION_STRING; + + // Check that the major version matches in PiVersion and SupportedVersion + _PI_PLUGIN_VERSION_CHECK(PluginInit->PiVersion, SupportedVersion); + + // TODO: handle versioning/targets properly. + size_t PluginVersionSize = sizeof(PluginInit->PluginVersion); + + PI_ASSERT(strlen(_PI_UNIFIED_RUNTIME_PLUGIN_VERSION_STRING) < + PluginVersionSize, + PI_ERROR_INVALID_VALUE); + + strncpy(PluginInit->PluginVersion, SupportedVersion, PluginVersionSize); + + // Bind interfaces that are already supported and "die" for unsupported ones +#define _PI_API(api) \ + (PluginInit->PiFunctionTable).api = (decltype(&::api))(&DieUnsupported); +#include + +#define _PI_API(api) \ + (PluginInit->PiFunctionTable).api = (decltype(&::api))(&api); + + _PI_API(piPlatformsGet) + _PI_API(piPlatformGetInfo) + _PI_API(piDevicesGet) + _PI_API(piTearDown) + + return PI_SUCCESS; +} + } // extern "C diff --git a/sycl/plugins/unified_runtime/pi_unified_runtime.hpp b/sycl/plugins/unified_runtime/pi_unified_runtime.hpp index 1d40e4b9eb559..0439f704a8e93 100644 --- a/sycl/plugins/unified_runtime/pi_unified_runtime.hpp +++ b/sycl/plugins/unified_runtime/pi_unified_runtime.hpp @@ -6,3 +6,10 @@ // //===------------------------------------------------------------------===// #pragma once + +// This version should be incremented for any change made to this file or its +// corresponding .cpp file. +#define _PI_UNIFIED_RUNTIME_PLUGIN_VERSION 1 + +#define _PI_UNIFIED_RUNTIME_PLUGIN_VERSION_STRING \ + _PI_PLUGIN_VERSION_STRING(_PI_UNIFIED_RUNTIME_PLUGIN_VERSION) diff --git a/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp b/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp index cfbdda10db5ee..479d38c8f11a6 100644 --- a/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp +++ b/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp @@ -394,3 +394,57 @@ ZER_APIEXPORT zer_result_t ZER_APICALL zerPlatformGet( return ZER_RESULT_SUCCESS; } + +ZER_APIEXPORT zer_result_t ZER_APICALL zerPlatformGetInfo( + zer_platform_handle_t Platform, ///< [in] handle of the platform + zer_platform_info_t ParamName, ///< [in] type of the info to retrieve + size_t *pSize, ///< [in,out] pointer to the number of bytes needed to return + ///< info queried. the call shall update it with the real + ///< number of bytes needed to return the info + void *ParamValue ///< [out][optional] array of bytes holding the info. + ///< if *pSize is not equal to the real number of bytes + ///< needed to return the info then the + ///< ::ZER_RESULT_ERROR_INVALID_SIZE error is returned and + ///< pPlatformInfo is not used. +) { + + PI_ASSERT(Platform, ZER_RESULT_INVALID_PLATFORM); + UrReturnHelper ReturnValue(pSize, ParamValue); + + switch (ParamName) { + case ZER_PLATFORM_INFO_NAME: + // TODO: Query Level Zero driver when relevant info is added there. + return ReturnValue("Intel(R) oneAPI Unified Runtime over Level-Zero"); + case ZER_PLATFORM_INFO_VENDOR_NAME: + // TODO: Query Level Zero driver when relevant info is added there. + return ReturnValue("Intel(R) Corporation"); + case ZER_PLATFORM_INFO_EXTENSIONS: + // Convention adopted from OpenCL: + // "Returns a space-separated list of extension names (the extension + // names themselves do not contain any spaces) supported by the platform. + // Extensions defined here must be supported by all devices associated + // with this platform." + // + // TODO: Check the common extensions supported by all connected devices and + // return them. For now, hardcoding some extensions we know are supported by + // all Level Zero devices. + return ReturnValue(ZE_SUPPORTED_EXTENSIONS); + case ZER_PLATFORM_INFO_PROFILE: + // TODO: figure out what this means and how is this used + return ReturnValue("FULL_PROFILE"); + case ZER_PLATFORM_INFO_VERSION: + // TODO: this should query to zeDriverGetDriverVersion + // but we don't yet have the driver handle here. + // + // From OpenCL 2.1: "This version string has the following format: + // OpenCL. Follow the same notation here. + // + return ReturnValue(Platform->ZeDriverApiVersion.c_str()); + default: + zePrint("piPlatformGetInfo: unrecognized ParamName\n"); + return ZER_RESULT_INVALID_VALUE; + } + + return ZER_RESULT_SUCCESS; +} diff --git a/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp b/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp index 6c292139177d7..231979c0dfce2 100644 --- a/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp +++ b/sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp @@ -222,3 +222,8 @@ extern ZeUSMImportExtension ZeUSMImport; // This will count the calls to Level-Zero extern std::map *ZeCallCount; + +// Some opencl extensions we know are supported by all Level Zero devices. +constexpr char ZE_SUPPORTED_EXTENSIONS[] = + "cl_khr_il_program cl_khr_subgroups cl_intel_subgroups " + "cl_intel_subgroups_short cl_intel_required_subgroup_size "; diff --git a/sycl/plugins/unified_runtime/ur/ur.hpp b/sycl/plugins/unified_runtime/ur/ur.hpp index aca03ec12331c..0bbbcd3ea547a 100644 --- a/sycl/plugins/unified_runtime/ur/ur.hpp +++ b/sycl/plugins/unified_runtime/ur/ur.hpp @@ -9,8 +9,9 @@ #include #include -#include +#include #include +#include #include #include #include @@ -216,3 +217,106 @@ extern bool PrintTrace; extern std::vector *PiPlatformsCache; extern SpinLock *PiPlatformsCacheMutex; extern bool PiPlatformCachePopulated; + +// The getInfo*/ReturnHelper facilities provide shortcut way of +// writing return bytes for the various getInfo APIs. +template +zer_result_t getInfoImpl(size_t param_value_size, void *param_value, + size_t *param_value_size_ret, T value, + size_t value_size, Assign &&assign_func) { + + if (param_value != nullptr) { + + if (param_value_size < value_size) { + return ZER_RESULT_INVALID_VALUE; + } + + assign_func(param_value, value, value_size); + } + + if (param_value_size_ret != nullptr) { + *param_value_size_ret = value_size; + } + + return ZER_RESULT_SUCCESS; +} + +template +zer_result_t getInfo(size_t param_value_size, void *param_value, + size_t *param_value_size_ret, T value) { + + auto assignment = [](void *param_value, T value, size_t value_size) { + (void)value_size; + *static_cast(param_value) = value; + }; + + return getInfoImpl(param_value_size, param_value, param_value_size_ret, value, + sizeof(T), assignment); +} + +template +zer_result_t getInfoArray(size_t array_length, size_t param_value_size, + void *param_value, size_t *param_value_size_ret, + const T *value) { + return getInfoImpl(param_value_size, param_value, param_value_size_ret, value, + array_length * sizeof(T), memcpy); +} + +template +zer_result_t getInfoArray(size_t array_length, size_t param_value_size, + void *param_value, size_t *param_value_size_ret, + const T *value) { + if (param_value) { + memset(param_value, 0, param_value_size); + for (uint32_t I = 0; I < array_length; I++) + ((RetType *)param_value)[I] = (RetType)value[I]; + } + if (param_value_size_ret) + *param_value_size_ret = array_length * sizeof(RetType); + return ZER_RESULT_SUCCESS; +} + +template <> +inline zer_result_t +getInfo(size_t param_value_size, void *param_value, + size_t *param_value_size_ret, const char *value) { + return getInfoArray(strlen(value) + 1, param_value_size, param_value, + param_value_size_ret, value); +} + +class UrReturnHelper { +public: + UrReturnHelper(size_t param_value_size, void *param_value, + size_t *param_value_size_ret) + : param_value_size(param_value_size), param_value(param_value), + param_value_size_ret(param_value_size_ret) {} + + // A version where in/out info size is represented by a single pointer + // to a value which is updated on return + UrReturnHelper(size_t *param_value_size, void *param_value) + : param_value_size(*param_value_size), param_value(param_value), + param_value_size_ret(param_value_size) {} + + // Scalar return value + template zer_result_t operator()(const T &t) { + return getInfo(param_value_size, param_value, param_value_size_ret, t); + } + + // Array return value + template zer_result_t operator()(const T *t, size_t s) { + return getInfoArray(s, param_value_size, param_value, param_value_size_ret, + t); + } + + // Array return value where element type is differrent from T + template + zer_result_t operator()(const T *t, size_t s) { + return getInfoArray(s, param_value_size, param_value, + param_value_size_ret, t); + } + +protected: + size_t param_value_size; + void *param_value; + size_t *param_value_size_ret; +}; diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index bd32be2988280..42f7ce69b150b 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -172,14 +172,15 @@ getSyclDeviceTypeMap() { // Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST and // ONEAPI_DEVICE_SELECTOR -const std::array, 7> &getSyclBeMap() { - static const std::array, 7> SyclBeMap = { +const std::array, 8> &getSyclBeMap() { + static const std::array, 8> SyclBeMap = { {{"host", backend::host}, {"opencl", backend::opencl}, {"level_zero", backend::ext_oneapi_level_zero}, {"cuda", backend::ext_oneapi_cuda}, {"hip", backend::ext_oneapi_hip}, {"esimd_emulator", backend::ext_intel_esimd_emulator}, + {"ext_oneapi_unified_runtime", backend::ext_oneapi_unified_runtime}, {"*", backend::all}}}; return SyclBeMap; } diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index e825812996a87..7322b8cfab643 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -237,7 +237,7 @@ getSyclDeviceTypeMap(); // Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST and // ONEAPI_DEVICE_SELECTOR -const std::array, 7> &getSyclBeMap(); +const std::array, 8> &getSyclBeMap(); // --------------------------------------- // ONEAPI_DEVICE_SELECTOR support diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index fb228cd85979a..0a35919224f1c 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -293,6 +293,8 @@ std::vector> findPlugins() { backend::ext_oneapi_level_zero); PluginNames.emplace_back(__SYCL_CUDA_PLUGIN_NAME, backend::ext_oneapi_cuda); PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip); + PluginNames.emplace_back(__SYCL_UNIFIED_RUNTIME_PLUGIN_NAME, + backend::ext_oneapi_unified_runtime); } else if (FilterList) { std::vector Filters = FilterList->get(); bool OpenCLFound = false; @@ -351,6 +353,10 @@ std::vector> findPlugins() { if (list.backendCompatible(backend::ext_oneapi_hip)) { PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip); } + if (list.backendCompatible(backend::ext_oneapi_unified_runtime)) { + PluginNames.emplace_back(__SYCL_UNIFIED_RUNTIME_PLUGIN_NAME, + backend::ext_oneapi_unified_runtime); + } } return PluginNames; } diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index a7532dc9c494e..a1382cecacc70 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -126,8 +126,12 @@ std::vector platform_impl::get_platforms() { // insert PiPlatform into the Plugin Plugin.getPlatformId(PiPlatform); } - if (!Platform.get_devices(info::device_type::all).empty()) + // The users of (deprecated) SYCL_DEVICE_ALLOWLIST expect that + // platforms with no devices will not be reported. + if (!SYCLConfig::get() || + !Platform.get_devices(info::device_type::all).empty()) { Platforms.push_back(Platform); + } } } } @@ -153,11 +157,12 @@ std::vector platform_impl::get_platforms() { // to distinguish the case where we are working with ONEAPI_DEVICE_SELECTOR // in the places where the functionality diverges between these two // environment variables. -// The return value is a vector that represents the indices of the chosen +// The return value is a vector that represents the indices of the chosen // devices. template static std::vector filterDeviceFilter(std::vector &PiDevices, - RT::PiPlatform Platform, ListT *FilterList) { + RT::PiPlatform Platform, + ListT *FilterList) { constexpr bool is_ods_target = std::is_same_v; // There are some differences in implementation between SYCL_DEVICE_FILTER @@ -316,7 +321,7 @@ static bool supportsPartitionProperty(const device &dev, static std::vector amendDeviceAndSubDevices( backend PlatformBackend, std::vector &DeviceList, - ods_target_list *OdsTargetList, const std::vector& original_indices, + ods_target_list *OdsTargetList, const std::vector &original_indices, PlatformImplPtr PlatformImpl) { constexpr info::partition_property partitionProperty = info::partition_property::partition_by_affinity_domain; @@ -343,8 +348,7 @@ static std::vector amendDeviceAndSubDevices( target.DeviceType)); } else if (target.DeviceNum) { // opencl:0 - deviceMatch = - (target.DeviceNum.value() == original_indices[i]); + deviceMatch = (target.DeviceNum.value() == original_indices[i]); } if (deviceMatch) { @@ -518,8 +522,9 @@ platform_impl::get_devices(info::device_type DeviceType) const { PlatformDeviceIndices = filterDeviceFilter( PiDevices, MPlatform, OdsTargetList); } else if (FilterList) { - PlatformDeviceIndices = filterDeviceFilter( - PiDevices, MPlatform, FilterList); + PlatformDeviceIndices = + filterDeviceFilter( + PiDevices, MPlatform, FilterList); } // The next step is to inflate the filtered PIDevices into SYCL Device diff --git a/sycl/unittests/allowlist/ParseAllowList.cpp b/sycl/unittests/allowlist/ParseAllowList.cpp index 2612ad1005d18..0893004cc449d 100644 --- a/sycl/unittests/allowlist/ParseAllowList.cpp +++ b/sycl/unittests/allowlist/ParseAllowList.cpp @@ -167,9 +167,13 @@ TEST(ParseAllowListTests, CheckAllValidBackendNameValuesAreProcessed) { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(AllowList); sycl::detail::AllowListParsedT ExpectedValue{ - {{"BackendName", "host"}}, {{"BackendName", "opencl"}}, - {{"BackendName", "level_zero"}}, {{"BackendName", "cuda"}}, - {{"BackendName", "hip"}}, {{"BackendName", "esimd_emulator"}}, + {{"BackendName", "host"}}, + {{"BackendName", "opencl"}}, + {{"BackendName", "level_zero"}}, + {{"BackendName", "cuda"}}, + {{"BackendName", "hip"}}, + {{"BackendName", "esimd_emulator"}}, + {{"BackendName", "ext_oneapi_unified_runtime"}}, {{"BackendName", "*"}}}; EXPECT_EQ(ExpectedValue, ActualValue); }