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

[cuSolver] Avoid repeated ctxCreate/Destroy for all Lapack API calls. #298

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/dft/backends/mklcpu/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void descriptor<prec, dom>::commit(backend_selector<backend::mklcpu> selector) {
if (pimpl_) {
pimpl_->get_queue().wait();
}
pimpl_.reset(mklgpu::create_commit(*this, selector.get_queue()));
pimpl_.reset(mklcpu::create_commit(*this, selector.get_queue()));
}
pimpl_->commit(values_);
}
Expand Down
9 changes: 5 additions & 4 deletions src/lapack/backends/cusolver/cusolver_scope_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ CusolverScopedContextHandler::CusolverScopedContextHandler(sycl::queue queue,
sycl::interop_handler &ih)
: ih(ih),
needToRecover_(false) {
placedContext_ = queue.get_context();
placedContext_ = new sycl::context(queue.get_context());
auto device = queue.get_device();
auto desired = sycl::get_native<sycl::backend::cuda>(placedContext_);
auto desired = sycl::get_native<sycl::backend::cuda>(*placedContext_);
CUresult err;
CUDA_ERROR_FUNC(cuCtxGetCurrent, err, &original_);
if (original_ != desired) {
Expand All @@ -65,6 +65,7 @@ CusolverScopedContextHandler::~CusolverScopedContextHandler() noexcept(false) {
CUresult err;
CUDA_ERROR_FUNC(cuCtxSetCurrent, err, original_);
}
delete placedContext_;
}

void ContextCallback(void *userData) {
Expand All @@ -88,7 +89,7 @@ void ContextCallback(void *userData) {

cusolverDnHandle_t CusolverScopedContextHandler::get_handle(const sycl::queue &queue) {
auto piPlacedContext_ =
reinterpret_cast<pi_context>(sycl::get_native<sycl::backend::cuda>(placedContext_));
reinterpret_cast<pi_context>(sycl::get_native<sycl::backend::cuda>(*placedContext_));
CUstream streamId = get_stream(queue);
cusolverStatus_t err;
auto it = handle_helper.cusolver_handle_mapper_.find(piPlacedContext_);
Expand Down Expand Up @@ -120,7 +121,7 @@ cusolverDnHandle_t CusolverScopedContextHandler::get_handle(const sycl::queue &q
auto insert_iter = handle_helper.cusolver_handle_mapper_.insert(
std::make_pair(piPlacedContext_, new std::atomic<cusolverDnHandle_t>(handle)));

sycl::detail::pi::contextSetExtendedDeleter(placedContext_, ContextCallback,
sycl::detail::pi::contextSetExtendedDeleter(*placedContext_, ContextCallback,
insert_iter.first->second);

return handle;
Expand Down
6 changes: 4 additions & 2 deletions src/lapack/backends/cusolver/cusolver_scope_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#else
#include <CL/sycl.hpp>
#endif
#if __has_include(<sycl/backend/cuda.hpp>)
#if __has_include(<sycl/context.hpp>)
#if __SYCL_COMPILER_VERSION <= 20220930
#include <sycl/backend/cuda.hpp>
#endif
#include <sycl/context.hpp>
#include <sycl/detail/pi.hpp>
#else
Expand Down Expand Up @@ -77,7 +79,7 @@ cuSolver handle to the SYCL context.

class CusolverScopedContextHandler {
CUcontext original_;
sycl::context placedContext_;
sycl::context *placedContext_;
bool needToRecover_;
sycl::interop_handler &ih;
static thread_local cusolver_handle<pi_context> handle_helper;
Expand Down