diff --git a/.github/intel-llvm-mirror-base-commit b/.github/intel-llvm-mirror-base-commit index 92370b5a92..9ff7b6669c 100644 --- a/.github/intel-llvm-mirror-base-commit +++ b/.github/intel-llvm-mirror-base-commit @@ -1 +1 @@ -1dee8fc72d540109e13ea80193caa4432545790a +76c80a0fcc0a55a2820d068173f5bfa3756d375c diff --git a/include/ur_api.h b/include/ur_api.h index e6f814e178..f70e9dbbc7 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -1908,6 +1908,8 @@ typedef enum ur_device_type_t { UR_DEVICE_TYPE_MCA = 6, /// Vision Processing Unit UR_DEVICE_TYPE_VPU = 7, + /// Generic custom device type + UR_DEVICE_TYPE_CUSTOM = 8, /// @cond UR_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -1940,7 +1942,7 @@ typedef enum ur_device_type_t { /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_SIZE /// + `NumEntries == 0 && phDevices != NULL` /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER @@ -1987,7 +1989,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_VALUE UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetSelected( /// [in] handle of the platform instance diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 17a8a5267e..9faf3e37f1 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -2609,6 +2609,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_type_t value) { case UR_DEVICE_TYPE_VPU: os << "UR_DEVICE_TYPE_VPU"; break; + case UR_DEVICE_TYPE_CUSTOM: + os << "UR_DEVICE_TYPE_CUSTOM"; + break; default: os << "unknown enumerator"; break; diff --git a/scripts/core/device.yml b/scripts/core/device.yml index 7bef8a45a5..2ad5a2171f 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -108,6 +108,8 @@ etors: desc: "Memory Copy Accelerator" - name: VPU desc: "Vision Processing Unit" + - name: CUSTOM + desc: "Generic custom device type" --- #-------------------------------------------------------------------------- type: function desc: "Retrieves devices within a platform" diff --git a/scripts/core/manifests.yml b/scripts/core/manifests.yml index 875d47ded9..b380469a9e 100644 --- a/scripts/core/manifests.yml +++ b/scripts/core/manifests.yml @@ -23,6 +23,7 @@ device_types: - $X_DEVICE_TYPE_FPGA - $X_DEVICE_TYPE_MCA - $X_DEVICE_TYPE_VPU + - $X_DEVICE_TYPE_CUSTOM --- #-------------------------------------------------------------------------- type: manifest name: cuda diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index 5410125ede..0b0db4d634 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -155,8 +155,13 @@ ur_result_t urDeviceGet( bool isComposite = isCombinedMode && (D->ZeDeviceProperties->flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) == 0; - if (!isComposite) + if (!isComposite) { MatchedDevices.push_back(D.get()); + // For UR_DEVICE_TYPE_DEFAULT only a single device should be returned, + // so exit the loop after first proper match. + if (DeviceType == UR_DEVICE_TYPE_DEFAULT) + break; + } } } diff --git a/source/adapters/level_zero/enqueued_pool.hpp b/source/adapters/level_zero/enqueued_pool.hpp index 8d582d2414..2d947d2d00 100644 --- a/source/adapters/level_zero/enqueued_pool.hpp +++ b/source/adapters/level_zero/enqueued_pool.hpp @@ -35,7 +35,8 @@ class EnqueuedPool { EnqueuedPool(event_release_callback_t EventReleaseFn, memory_free_callback_t MemFreeFn) - : EventReleaseFn(EventReleaseFn), MemFreeFn(MemFreeFn) {} + : EventReleaseFn(std::move(EventReleaseFn)), + MemFreeFn(std::move(MemFreeFn)) {} ~EnqueuedPool(); std::optional getBestFit(size_t Size, size_t Alignment, diff --git a/source/adapters/opencl/adapter.cpp b/source/adapters/opencl/adapter.cpp index 7f79b95b89..a2a97b56c7 100644 --- a/source/adapters/opencl/adapter.cpp +++ b/source/adapters/opencl/adapter.cpp @@ -26,17 +26,15 @@ static ur_adapter_handle_t liveAdapter = nullptr; ur_adapter_handle_t_::ur_adapter_handle_t_() : handle_base() { #ifdef _MSC_VER - // Loading OpenCL.dll increments the libraries internal reference count. - auto handle = LoadLibraryA("OpenCL.dll"); + // Retrieving handle of an already linked OpenCL.dll library doesn't increase + // the reference count. + auto handle = GetModuleHandleA("OpenCL.dll"); + assert(handle); #define CL_CORE_FUNCTION(FUNC) \ FUNC = reinterpret_cast(GetProcAddress(handle, #FUNC)); #include "core_functions.def" #undef CL_CORE_FUNCTION - - // So we can safely decrement it here wihtout actually unloading OpenCL.dll. - FreeLibrary(handle); - #else // _MSC_VER // Use the default shared object search order (RTLD_DEFAULT) since the diff --git a/source/adapters/opencl/device.cpp b/source/adapters/opencl/device.cpp index 9c9c82ea47..4f697b05b5 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -36,6 +36,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform, case UR_DEVICE_TYPE_VPU: Type = CL_DEVICE_TYPE_ACCELERATOR; break; + case UR_DEVICE_TYPE_CUSTOM: + Type = CL_DEVICE_TYPE_CUSTOM; + break; case UR_DEVICE_TYPE_DEFAULT: Type = CL_DEVICE_TYPE_DEFAULT; break; @@ -47,11 +50,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform, uint32_t DeviceNumIter = 0; for (uint32_t i = 0; i < AllDevicesNum; i++) { cl_device_type DevTy = hPlatform->Devices[i]->Type; - if (DevTy == Type || Type == CL_DEVICE_TYPE_ALL) { + if (DevTy == Type || Type == CL_DEVICE_TYPE_ALL || + Type == CL_DEVICE_TYPE_DEFAULT) { if (phDevices) { phDevices[DeviceNumIter] = hPlatform->Devices[i].get(); } DeviceNumIter++; + // For default, the first device is the only returned device. + if (Type == CL_DEVICE_TYPE_DEFAULT) + break; } } if (pNumDevices) { @@ -141,6 +148,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, URDeviceType = UR_DEVICE_TYPE_GPU; } else if (CLType & CL_DEVICE_TYPE_ACCELERATOR) { URDeviceType = UR_DEVICE_TYPE_FPGA; + } else if (CLType & CL_DEVICE_TYPE_CUSTOM) { + URDeviceType = UR_DEVICE_TYPE_CUSTOM; } return ReturnValue(URDeviceType); diff --git a/source/loader/layers/sanitizer/msan/msan_shadow.cpp b/source/loader/layers/sanitizer/msan/msan_shadow.cpp index 123dab662f..12ee3154cc 100644 --- a/source/loader/layers/sanitizer/msan/msan_shadow.cpp +++ b/source/loader/layers/sanitizer/msan/msan_shadow.cpp @@ -88,12 +88,9 @@ ur_result_t MsanShadowMemoryCPU::Setup() { uptr End = kMemoryLayout[i].end; uptr Size = End - Start; MappingDesc::Type Type = kMemoryLayout[i].type; - bool InitOrigins = true; - bool IsMap = Type == MappingDesc::SHADOW || - (InitOrigins && Type == MappingDesc::ORIGIN); - bool IsProtect = Type == MappingDesc::INVALID || - (!InitOrigins && Type == MappingDesc::ORIGIN); + bool IsMap = Type == MappingDesc::SHADOW || Type == MappingDesc::ORIGIN; + bool IsProtect = Type == MappingDesc::INVALID; if (IsMap) { if (MmapFixedNoReserve(Start, Size) == 0) { @@ -124,9 +121,7 @@ ur_result_t MsanShadowMemoryCPU::Destory() { uptr End = kMemoryLayout[i].end; uptr Size = End - Start; MappingDesc::Type Type = kMemoryLayout[i].type; - bool InitOrigins = true; - bool IsMap = Type == MappingDesc::SHADOW || - (InitOrigins && Type == MappingDesc::ORIGIN); + bool IsMap = Type == MappingDesc::SHADOW || Type == MappingDesc::ORIGIN; if (IsMap) { if (Munmap(Start, Size)) { return UR_RESULT_ERROR_UNKNOWN; diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 82e898fab8..32dec6f1b2 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -513,7 +513,7 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet( if (NULL == hPlatform) return UR_RESULT_ERROR_INVALID_NULL_HANDLE; - if (UR_DEVICE_TYPE_VPU < DeviceType) + if (UR_DEVICE_TYPE_CUSTOM < DeviceType) return UR_RESULT_ERROR_INVALID_ENUMERATION; if (NumEntries == 0 && phDevices != NULL) diff --git a/source/loader/ur_lib.cpp b/source/loader/ur_lib.cpp index e186f188f2..9a074b5a9b 100644 --- a/source/loader/ur_lib.cpp +++ b/source/loader/ur_lib.cpp @@ -275,6 +275,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform, case UR_DEVICE_TYPE_CPU: case UR_DEVICE_TYPE_FPGA: case UR_DEVICE_TYPE_MCA: + case UR_DEVICE_TYPE_CUSTOM: break; default: return UR_RESULT_ERROR_INVALID_ENUMERATION; @@ -647,10 +648,15 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform, [&](ur_device_handle_t urDeviceHandle) { // obtain and record device type from platform (squash // errors) - ur_device_type_t hardwareType = ::UR_DEVICE_TYPE_DEFAULT; - urDeviceGetInfo(urDeviceHandle, UR_DEVICE_INFO_TYPE, - sizeof(ur_device_type_t), &hardwareType, - 0); + ur_device_type_t hardwareType; + ur_result_t res = urDeviceGetInfo( + urDeviceHandle, UR_DEVICE_INFO_TYPE, + sizeof(ur_device_type_t), &hardwareType, 0); + // ignore failures and just assume the default hw type + if (res != UR_RESULT_SUCCESS) { + hardwareType = ::UR_DEVICE_TYPE_DEFAULT; + } + return DeviceSpec{DevicePartLevel::ROOT, hardwareType, deviceCount++, DeviceIdTypeALL, DeviceIdTypeALL, urDeviceHandle}; diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index a7559029e2..4ec2282647 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -826,7 +826,7 @@ ur_result_t UR_APICALL urPlatformGetBackendOption( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_SIZE /// + `NumEntries == 0 && phDevices != NULL` /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER @@ -881,7 +881,7 @@ ur_result_t UR_APICALL urDeviceGet( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_VALUE ur_result_t UR_APICALL urDeviceGetSelected( /// [in] handle of the platform instance diff --git a/source/loader/ur_manifests.hpp b/source/loader/ur_manifests.hpp index 3e672c0744..c376ab26a4 100644 --- a/source/loader/ur_manifests.hpp +++ b/source/loader/ur_manifests.hpp @@ -40,6 +40,7 @@ const std::vector ur_adapter_manifests = { UR_DEVICE_TYPE_FPGA, UR_DEVICE_TYPE_MCA, UR_DEVICE_TYPE_VPU, + UR_DEVICE_TYPE_CUSTOM, }}, {"cuda", MAKE_LIBRARY_NAME("ur_adapter_cuda", "0"), diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 4709496405..8e3424b693 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -740,7 +740,7 @@ ur_result_t UR_APICALL urPlatformGetBackendOption( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_SIZE /// + `NumEntries == 0 && phDevices != NULL` /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER @@ -790,7 +790,7 @@ ur_result_t UR_APICALL urDeviceGet( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hPlatform` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_TYPE_VPU < DeviceType` +/// + `::UR_DEVICE_TYPE_CUSTOM < DeviceType` /// - ::UR_RESULT_ERROR_INVALID_VALUE ur_result_t UR_APICALL urDeviceGetSelected( /// [in] handle of the platform instance diff --git a/test/conformance/device/urDeviceGet.cpp b/test/conformance/device/urDeviceGet.cpp index ad3c0d3c3d..35ef449df7 100644 --- a/test/conformance/device/urDeviceGet.cpp +++ b/test/conformance/device/urDeviceGet.cpp @@ -87,7 +87,8 @@ UUR_PLATFORM_TEST_SUITE_WITH_PARAM( urDeviceGetTestWithDeviceTypeParam, ::testing::Values(UR_DEVICE_TYPE_DEFAULT, UR_DEVICE_TYPE_GPU, UR_DEVICE_TYPE_CPU, UR_DEVICE_TYPE_FPGA, - UR_DEVICE_TYPE_MCA, UR_DEVICE_TYPE_VPU), + UR_DEVICE_TYPE_MCA, UR_DEVICE_TYPE_VPU, + UR_DEVICE_TYPE_CUSTOM), uur::platformTestWithParamPrinter); TEST_P(urDeviceGetTestWithDeviceTypeParam, Success) {