Skip to content

Commit

Permalink
Add ifdefs to support past DPC++ releases
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkusiak97 committed Aug 7, 2024
1 parent 420111e commit fc3d4e2
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 10 deletions.
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 _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 _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/ur.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>
#ifndef _PI_INTERFACE_REMOVED_
#define _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 _PI_INTERFACE_REMOVED_
static thread_local cublas_handle<ur_context_handle_t> handle_helper;
#else
static thread_local cublas_handle<pi_xontext> handle_helper;
#endif
CUstream get_stream(const sycl::queue &queue);
sycl::context get_context(const sycl::queue &queue);

Expand Down
12 changes: 10 additions & 2 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"
#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 _PI_INTERFACE_REMOVED_
#define _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
13 changes: 11 additions & 2 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).
*/
thread_local rocblas_handle_container<ur_context_handle_t> RocblasScopedContextHandler::handle_helper =
rocblas_handle_container<ur_context_handle_t>{};
#ifdef _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 _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 _PI_INTERFACE_REMOVED_
#define _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 _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
13 changes: 10 additions & 3 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"
#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 _PI_INTERFACE_REMOVED_
#define _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 _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 _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/ur.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 _PI_INTERFACE_REMOVED_
#define _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 _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
8 changes: 8 additions & 0 deletions 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"

// 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 _PI_INTERFACE_REMOVED_
#define _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 _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 _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
4 changes: 4 additions & 0 deletions src/lapack/backends/rocsolver/rocsolver_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class RocsolverScopedContextHandler {
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handle &ih;
#ifdef _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
7 changes: 7 additions & 0 deletions src/lapack/backends/rocsolver/rocsolver_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@
#endif
#include "oneapi/mkl/types.hpp"
#include "rocsolver_scope_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 _PI_INTERFACE_REMOVED_
#define _PI_INTERFACE_REMOVED_
#endif
#elif __has_include(<sycl/detail/pi.hpp>)
#include <sycl/detail/pi.hpp>
#else
#include <CL/sycl/detail/pi.hpp>
#endif
Expand Down

0 comments on commit fc3d4e2

Please sign in to comment.