Skip to content

MKLShim Support for OneAPI 2025 #981

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
MKLShim Support for OneAPI 2025
  • Loading branch information
pvelesko committed Mar 20, 2025
commit 93f0e7427a88afdb77006b7819b7be31ea336621
2 changes: 1 addition & 1 deletion H4I-MKLShim
Submodule H4I-MKLShim updated 1 files
+49 −10 src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
*/

#include <oneapi/mkl.hpp>
#if INTEL_MKL_VERSION >= 20230000
#if INTEL_MKL_VERSION >= 20250000
#include <sycl/backend.hpp>
#elif INTEL_MKL_VERSION >= 20230000
#include <sycl/ext/oneapi/backend/level_zero.hpp>
#else
#include <CL/sycl/backend/level_zero.hpp>
Expand Down Expand Up @@ -88,19 +90,33 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
std::string hipBackendName((char *)nativeHandlers[0]);
sycl::queue sycl_queue;
if (!hipBackendName.compare("opencl")) {
// handle openCl case here
cl_platform_id hPlatformId = (cl_platform_id)nativeHandlers[1];
cl_device_id hDeviceId = (cl_device_id)nativeHandlers[2];
cl_context hContext = (cl_context)nativeHandlers[3];
cl_command_queue hQueue = (cl_command_queue)nativeHandlers[4];
sycl::platform sycl_platform =
sycl::opencl::make_platform((pi_native_handle)hPlatformId);
sycl::device sycl_device =
sycl::opencl::make_device((pi_native_handle)hDeviceId);
sycl::context sycl_context =
sycl::opencl::make_context((pi_native_handle)hContext);
sycl_queue =
sycl::opencl::make_queue(sycl_context, (pi_native_handle)hQueue);
// handle openCl case here
cl_platform_id hPlatformId = (cl_platform_id)nativeHandlers[1];
cl_device_id hDeviceId = (cl_device_id)nativeHandlers[2];
cl_context hContext = (cl_context)nativeHandlers[3];
cl_command_queue hQueue = (cl_command_queue)nativeHandlers[4];

#if INTEL_MKL_VERSION >= 20250000
// MKL 2025 uses UR API
sycl::platform sycl_platform =
sycl::detail::make_platform((ur_native_handle_t)hPlatformId, sycl::backend::opencl);
sycl::device sycl_device =
sycl::detail::make_device((ur_native_handle_t)hDeviceId, sycl::backend::opencl);
sycl::context sycl_context =
sycl::detail::make_context((ur_native_handle_t)hContext, {}, sycl::backend::opencl, false);
sycl_queue =
sycl::detail::make_queue((ur_native_handle_t)hQueue, false, sycl_context, &sycl_device, false, {}, {}, sycl::backend::opencl);
#else
// MKL 2024 and earlier use PI API
sycl::platform sycl_platform =
sycl::opencl::make_platform((pi_native_handle)hPlatformId);
sycl::device sycl_device =
sycl::opencl::make_device((pi_native_handle)hDeviceId);
sycl::context sycl_context =
sycl::opencl::make_context((pi_native_handle)hContext);
sycl_queue =
sycl::opencl::make_queue(sycl_context, (pi_native_handle)hQueue);
#endif
} else if (!hipBackendName.compare("level0")) {
// handle L0 here
// Extract the native information
Expand All @@ -114,6 +130,26 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,

bool isImmCmdList = hCommandList ? true : false;

#if INTEL_MKL_VERSION >= 20250000
// MKL 2025 uses UR API
sycl::platform sycl_platform =
sycl::detail::make_platform((ur_native_handle_t)hDriver, sycl::backend::ext_oneapi_level_zero);
sycl::device sycl_device =
sycl::detail::make_device((ur_native_handle_t)hDevice, sycl::backend::ext_oneapi_level_zero);

std::vector<sycl::device> sycl_devices(1);
sycl_devices[0] = sycl_device;
sycl::context sycl_context =
sycl::detail::make_context((ur_native_handle_t)hContext, {}, sycl::backend::ext_oneapi_level_zero, false, sycl_devices);

if (isImmCmdList) {
sycl_queue = sycl::detail::make_queue((ur_native_handle_t)hCommandList, true, sycl_context, &sycl_device, false,
{sycl::property::queue::in_order()}, {}, sycl::backend::ext_oneapi_level_zero);
} else {
sycl_queue = sycl::detail::make_queue((ur_native_handle_t)hQueue, false, sycl_context, &sycl_device, false,
{sycl::property::queue::in_order()}, {}, sycl::backend::ext_oneapi_level_zero);
}
#elif __INTEL_LLVM_COMPILER >= 20240000
auto keep_ownership =
static_cast<sycl::ext::oneapi::level_zero::ownership>(1);
sycl::platform sycl_platform =
Expand All @@ -126,7 +162,6 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
sycl::context sycl_context = sycl::ext::oneapi::level_zero::make_context(
sycl_devices, (pi_native_handle)hContext, 1);

#if __INTEL_LLVM_COMPILER >= 20240000
if (isImmCmdList) {
sycl_queue = sycl::ext::oneapi::level_zero::make_queue(
sycl_context, sycl_device, (pi_native_handle)hCommandList, true, 1,
Expand All @@ -137,6 +172,18 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
sycl::property::queue::in_order());
}
#else
auto keep_ownership =
static_cast<sycl::ext::oneapi::level_zero::ownership>(1);
sycl::platform sycl_platform =
sycl::ext::oneapi::level_zero::make_platform((pi_native_handle)hDriver);
sycl::device sycl_device = sycl::ext::oneapi::level_zero::make_device(
sycl_platform, (pi_native_handle)hDevice);

std::vector<sycl::device> sycl_devices(1);
sycl_devices[0] = sycl_device;
sycl::context sycl_context = sycl::ext::oneapi::level_zero::make_context(
sycl_devices, (pi_native_handle)hContext, 1);

sycl_queue = sycl::ext::oneapi::level_zero::make_queue(
sycl_context, sycl_device, (pi_native_handle)hQueue, 1);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
*/

#include <oneapi/mkl.hpp>
#if INTEL_MKL_VERSION >= 20230000
#if INTEL_MKL_VERSION >= 20250000
#include <sycl/backend.hpp>
#elif INTEL_MKL_VERSION >= 20230000
#include <sycl/ext/oneapi/backend/level_zero.hpp>
#else
#include <CL/sycl/backend/level_zero.hpp>
Expand Down Expand Up @@ -85,19 +87,33 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
std::string hipBackendName((char *)nativeHandlers[0]);
sycl::queue sycl_queue;
if (!hipBackendName.compare("opencl")) {
// handle openCl case here
cl_platform_id hPlatformId = (cl_platform_id)nativeHandlers[1];
cl_device_id hDeviceId = (cl_device_id)nativeHandlers[2];
cl_context hContext = (cl_context)nativeHandlers[3];
cl_command_queue hQueue = (cl_command_queue)nativeHandlers[4];
sycl::platform sycl_platform =
sycl::opencl::make_platform((pi_native_handle)hPlatformId);
sycl::device sycl_device =
sycl::opencl::make_device((pi_native_handle)hDeviceId);
sycl::context sycl_context =
sycl::opencl::make_context((pi_native_handle)hContext);
sycl_queue =
sycl::opencl::make_queue(sycl_context, (pi_native_handle)hQueue);
// handle openCl case here
cl_platform_id hPlatformId = (cl_platform_id)nativeHandlers[1];
cl_device_id hDeviceId = (cl_device_id)nativeHandlers[2];
cl_context hContext = (cl_context)nativeHandlers[3];
cl_command_queue hQueue = (cl_command_queue)nativeHandlers[4];

#if INTEL_MKL_VERSION >= 20250000
// MKL 2025 uses UR API
sycl::platform sycl_platform =
sycl::detail::make_platform((ur_native_handle_t)hPlatformId, sycl::backend::opencl);
sycl::device sycl_device =
sycl::detail::make_device((ur_native_handle_t)hDeviceId, sycl::backend::opencl);
sycl::context sycl_context =
sycl::detail::make_context((ur_native_handle_t)hContext, {}, sycl::backend::opencl, false);
sycl_queue =
sycl::detail::make_queue((ur_native_handle_t)hQueue, false, sycl_context, &sycl_device, false, {}, {}, sycl::backend::opencl);
#else
// MKL 2024 and earlier use PI API
sycl::platform sycl_platform =
sycl::opencl::make_platform((pi_native_handle)hPlatformId);
sycl::device sycl_device =
sycl::opencl::make_device((pi_native_handle)hDeviceId);
sycl::context sycl_context =
sycl::opencl::make_context((pi_native_handle)hContext);
sycl_queue =
sycl::opencl::make_queue(sycl_context, (pi_native_handle)hQueue);
#endif
} else if (!hipBackendName.compare("level0")) {
// Extract the native information
ze_driver_handle_t hDriver = (ze_driver_handle_t)nativeHandlers[1];
Expand All @@ -110,6 +126,28 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,

bool isImmCmdList = hCommandList ? true : false;

#if INTEL_MKL_VERSION >= 20250000
// MKL 2025 uses UR API
sycl::platform sycl_platform =
sycl::detail::make_platform((ur_native_handle_t)hDriver, sycl::backend::ext_oneapi_level_zero);

// make devices from converted platform and L0 device
sycl::device sycl_device =
sycl::detail::make_device((ur_native_handle_t)hDevice, sycl::backend::ext_oneapi_level_zero);

std::vector<sycl::device> sycl_devices(1);
sycl_devices[0] = sycl_device;
sycl::context sycl_context =
sycl::detail::make_context((ur_native_handle_t)hContext, {}, sycl::backend::ext_oneapi_level_zero, false, sycl_devices);

if (isImmCmdList) {
sycl_queue = sycl::detail::make_queue((ur_native_handle_t)hCommandList, true, sycl_context, &sycl_device, false,
{sycl::property::queue::in_order()}, {}, sycl::backend::ext_oneapi_level_zero);
} else {
sycl_queue = sycl::detail::make_queue((ur_native_handle_t)hQueue, false, sycl_context, &sycl_device, false,
{sycl::property::queue::in_order()}, {}, sycl::backend::ext_oneapi_level_zero);
}
#elif __INTEL_LLVM_COMPILER >= 20240000
auto keep_ownership =
static_cast<sycl::ext::oneapi::level_zero::ownership>(1);
sycl::platform sycl_platform =
Expand All @@ -125,7 +163,6 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
sycl::context sycl_context = sycl::ext::oneapi::level_zero::make_context(
sycl_devices, (pi_native_handle)hContext, 1);

#if __INTEL_LLVM_COMPILER >= 20240000
if (isImmCmdList) {
sycl_queue = sycl::ext::oneapi::level_zero::make_queue(
sycl_context, sycl_device, (pi_native_handle)hCommandList, true, 1,
Expand All @@ -136,6 +173,21 @@ int oneMKLGemmTest(uintptr_t *nativeHandlers, float *A,
sycl::property::queue::in_order());
}
#else
auto keep_ownership =
static_cast<sycl::ext::oneapi::level_zero::ownership>(1);
sycl::platform sycl_platform =
sycl::ext::oneapi::level_zero::make_platform(
(pi_native_handle)hDriver);

// make devices from converted platform and L0 device
sycl::device sycl_device = sycl::ext::oneapi::level_zero::make_device(
sycl_platform, (pi_native_handle)hDevice);

std::vector<sycl::device> sycl_devices(1);
sycl_devices[0] = sycl_device;
sycl::context sycl_context = sycl::ext::oneapi::level_zero::make_context(
sycl_devices, (pi_native_handle)hContext, 1);

sycl_queue = sycl::ext::oneapi::level_zero::make_queue(
sycl_context, sycl_device, (pi_native_handle)hQueue, 1);
#endif
Expand Down