Skip to content
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

Changed pi_context to ur_context_handle_t and include pi.hpp to ur.hpp #546

Merged
merged 6 commits into from
Aug 21, 2024
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
9 changes: 9 additions & 0 deletions src/blas/backends/cublas/cublas_scope_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ namespace cublas {
* takes place if no other element in the container has a key equivalent to
* the one being emplaced (keys in a map container are unique).
*/
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
thread_local cublas_handle<ur_context_handle_t> CublasScopedContextHandler::handle_helper =
cublas_handle<ur_context_handle_t>{};
#else
thread_local cublas_handle<pi_context> CublasScopedContextHandler::handle_helper =
cublas_handle<pi_context>{};
#endif

CublasScopedContextHandler::CublasScopedContextHandler(sycl::queue queue, sycl::interop_handle &ih)
: ih(ih),
Expand Down Expand Up @@ -92,7 +97,11 @@ cublasHandle_t CublasScopedContextHandler::get_handle(const sycl::queue &queue)
CUresult cuErr;
CUcontext desired;
CUDA_ERROR_FUNC(cuDevicePrimaryCtxRetain, cuErr, &desired, cudaDevice);
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
auto piPlacedContext_ = reinterpret_cast<ur_context_handle_t>(desired);
#else
auto piPlacedContext_ = reinterpret_cast<pi_context>(desired);
#endif
CUstream streamId = get_stream(queue);
cublasStatus_t err;
auto it = handle_helper.cublas_handle_mapper_.find(piPlacedContext_);
Expand Down
17 changes: 16 additions & 1 deletion src/blas/backends/cublas/cublas_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@
#include <sycl/backend/cuda.hpp>
#endif
#include <sycl/context.hpp>
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/backend/cuda.hpp>
#include <CL/sycl/context.hpp>
#endif

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that instead of removing a footgun you have just reloaded it so it will fire at you once again in upcoming months (or years) when we drop UR in favor of something else.

You should not use implementation details like this in your project. Why aren't use using the official SYCL interop interface, i.e. backend_return_t<your_backend, context>?

I'm also surprised that you are changing the type of that variable without changing any of its uses, meaning that the type doesn't matter for you because it will be erased at some point. Wouldn't it be better to use some opaque type right away to avoid dependency on particular SYCL implementation?

#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif

#include <atomic>
#include <memory>
#include <thread>
Expand Down Expand Up @@ -77,7 +88,11 @@ class CublasScopedContextHandler {
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handle &ih;
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
static thread_local cublas_handle<ur_context_handle_t> handle_helper;
#else
static thread_local cublas_handle<pi_context> handle_helper;
#endif
CUstream get_stream(const sycl::queue &queue);
sycl::context get_context(const sycl::queue &queue);

Expand Down
14 changes: 11 additions & 3 deletions src/blas/backends/cublas/cublas_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@
#include "oneapi/mkl/types.hpp"
#ifndef __HIPSYCL__
#include "cublas_scope_handle.hpp"
#if __has_include(<sycl/detail/pi.hpp>)
#else
#include "cublas_scope_handle_hipsycl.hpp"

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif
#else
#include "cublas_scope_handle_hipsycl.hpp"

namespace sycl {
using interop_handler = sycl::interop_handle;
}
Expand Down
9 changes: 9 additions & 0 deletions src/blas/backends/rocblas/rocblas_scope_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ rocblas_handle_container<T>::~rocblas_handle_container() noexcept(false) {
* takes place if no other element in the container has a key equivalent to
* the one being emplaced (keys in a map container are unique).
*/
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
thread_local rocblas_handle_container<ur_context_handle_t>
RocblasScopedContextHandler::handle_helper = rocblas_handle_container<ur_context_handle_t>{};
#else
thread_local rocblas_handle_container<pi_context> RocblasScopedContextHandler::handle_helper =
rocblas_handle_container<pi_context>{};
#endif

RocblasScopedContextHandler::RocblasScopedContextHandler(sycl::queue queue,
sycl::interop_handle &ih)
Expand Down Expand Up @@ -108,7 +113,11 @@ rocblas_handle RocblasScopedContextHandler::get_handle(const sycl::queue &queue)
hipError_t hipErr;
hipCtx_t desired;
HIP_ERROR_FUNC(hipDevicePrimaryCtxRetain, hipErr, &desired, hipDevice);
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
auto piPlacedContext_ = reinterpret_cast<ur_context_handle_t>(desired);
#else
auto piPlacedContext_ = reinterpret_cast<pi_context>(desired);
#endif
hipStream_t streamId = get_stream(queue);
rocblas_status err;
auto it = handle_helper.rocblas_handle_container_mapper_.find(piPlacedContext_);
Expand Down
16 changes: 16 additions & 0 deletions src/blas/backends/rocblas/rocblas_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
#include <unordered_map>
#include "rocblas_helper.hpp"

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif

namespace oneapi {
namespace mkl {
namespace blas {
Expand All @@ -43,7 +55,11 @@ class RocblasScopedContextHandler {
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handle &interop_h;
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
static thread_local rocblas_handle_container<ur_context_handle_t> handle_helper;
#else
static thread_local rocblas_handle_container<pi_context> handle_helper;
#endif
sycl::context get_context(const sycl::queue &queue);
hipStream_t get_stream(const sycl::queue &queue);

Expand Down
15 changes: 11 additions & 4 deletions src/blas/backends/rocblas/rocblas_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@
#include "oneapi/mkl/types.hpp"
#ifndef __HIPSYCL__
#include "rocblas_scope_handle.hpp"
#if __has_include(<sycl/detail/pi.hpp>)
#else
#include "rocblas_scope_handle_hipsycl.hpp"
#endif

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif
#else
#include "rocblas_scope_handle_hipsycl.hpp"

#endif
namespace oneapi {
namespace mkl {
namespace blas {
Expand Down
9 changes: 9 additions & 0 deletions src/lapack/backends/cusolver/cusolver_scope_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ namespace cusolver {
* takes place if no other element in the container has a key equivalent to
* the one being emplaced (keys in a map container are unique).
*/
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
thread_local cusolver_handle<ur_context_handle_t> CusolverScopedContextHandler::handle_helper =
cusolver_handle<ur_context_handle_t>{};
#else
thread_local cusolver_handle<pi_context> CusolverScopedContextHandler::handle_helper =
cusolver_handle<pi_context>{};
#endif

CusolverScopedContextHandler::CusolverScopedContextHandler(sycl::queue queue,
sycl::interop_handle &ih)
Expand Down Expand Up @@ -93,7 +98,11 @@ cusolverDnHandle_t CusolverScopedContextHandler::get_handle(const sycl::queue &q
CUresult cuErr;
CUcontext desired;
CUDA_ERROR_FUNC(cuDevicePrimaryCtxRetain, cuErr, &desired, cudaDevice);
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
auto piPlacedContext_ = reinterpret_cast<ur_context_handle_t>(desired);
#else
auto piPlacedContext_ = reinterpret_cast<pi_context>(desired);
#endif
CUstream streamId = get_stream(queue);
cusolverStatus_t err;
auto it = handle_helper.cusolver_handle_mapper_.find(piPlacedContext_);
Expand Down
18 changes: 16 additions & 2 deletions src/lapack/backends/cusolver/cusolver_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
#include <sycl/backend/cuda.hpp>
#endif
#include <sycl/context.hpp>
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/backend/cuda.hpp>
#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/pi.hpp>
#endif
#include <atomic>
#include <memory>
Expand All @@ -41,6 +39,18 @@
#include "cusolver_helper.hpp"
#include "cusolver_handle.hpp"

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif

namespace oneapi {
namespace mkl {
namespace lapack {
Expand Down Expand Up @@ -82,7 +92,11 @@ class CusolverScopedContextHandler {
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handle &ih;
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
static thread_local cusolver_handle<ur_context_handle_t> handle_helper;
#else
static thread_local cusolver_handle<pi_context> handle_helper;
#endif
CUstream get_stream(const sycl::queue &queue);
sycl::context get_context(const sycl::queue &queue);

Expand Down
10 changes: 9 additions & 1 deletion src/lapack/backends/cusolver/cusolver_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
#endif
#include "oneapi/mkl/types.hpp"
#include "cusolver_scope_handle.hpp"
#if __has_include(<sycl/detail/pi.hpp>)

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif

namespace oneapi {
namespace mkl {
namespace lapack {
Expand Down
9 changes: 9 additions & 0 deletions src/lapack/backends/rocsolver/rocsolver_scope_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ namespace rocsolver {
* takes place if no other element in the container has a key equivalent to
* the one being emplaced (keys in a map container are unique).
*/
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
thread_local rocsolver_handle<ur_context_handle_t> RocsolverScopedContextHandler::handle_helper =
rocsolver_handle<ur_context_handle_t>{};
#else
thread_local rocsolver_handle<pi_context> RocsolverScopedContextHandler::handle_helper =
rocsolver_handle<pi_context>{};
#endif

RocsolverScopedContextHandler::RocsolverScopedContextHandler(sycl::queue queue,
sycl::interop_handle &ih)
Expand Down Expand Up @@ -95,7 +100,11 @@ rocblas_handle RocsolverScopedContextHandler::get_handle(const sycl::queue &queu
hipError_t hipErr;
hipCtx_t desired;
HIP_ERROR_FUNC(hipDevicePrimaryCtxRetain, hipErr, &desired, hipDevice);
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
auto piPlacedContext_ = reinterpret_cast<ur_context_handle_t>(desired);
#else
auto piPlacedContext_ = reinterpret_cast<pi_context>(desired);
#endif
hipStream_t streamId = get_stream(queue);
rocblas_status err;
auto it = handle_helper.rocsolver_handle_mapper_.find(piPlacedContext_);
Expand Down
16 changes: 16 additions & 0 deletions src/lapack/backends/rocsolver/rocsolver_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
#include "rocsolver_helper.hpp"
#include "rocsolver_handle.hpp"

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif

namespace oneapi {
namespace mkl {
namespace lapack {
Expand All @@ -43,7 +55,11 @@ class RocsolverScopedContextHandler {
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handle &ih;
#ifdef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
static thread_local rocsolver_handle<ur_context_handle_t> handle_helper;
#else
static thread_local rocsolver_handle<pi_context> handle_helper;
#endif
hipStream_t get_stream(const sycl::queue &queue);
sycl::context get_context(const sycl::queue &queue);

Expand Down
9 changes: 8 additions & 1 deletion src/lapack/backends/rocsolver/rocsolver_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
#endif
#include "oneapi/mkl/types.hpp"
#include "rocsolver_scope_handle.hpp"
#if __has_include(<sycl/detail/pi.hpp>)

// After Plugin Interface removal in DPC++ ur.hpp is the new include
#if __has_include(<sycl/detail/ur.hpp>)
#include <sycl/detail/ur.hpp>
#ifndef ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#define ONEAPI_ONEMKL_PI_INTERFACE_REMOVED
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
Expand Down
Loading