Skip to content

Commit

Permalink
[sycl][hip] Exception for unsupported get_native<sycl::context> (#14476)
Browse files Browse the repository at this point in the history
Add exception for unsupported get_native<sycl::context> specialization
for HIP backend.
This was previously marked deprecated. We keep the specialization in
order to give an error message to users.

---------

Signed-off-by: JackAKirk <jack.kirk@codeplay.com>
Co-authored-by: ldrumm <luke.drummond@codeplay.com>
Co-authored-by: Kenneth Benzie (Benie) <k.benzie@codeplay.com>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent ee05fbf commit 51438d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
14 changes: 7 additions & 7 deletions sycl/cmake/modules/FetchUnifiedRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ if(SYCL_UR_USE_FETCH_CONTENT)
endfunction()

set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
# commit 9ca3ec7a9c1d2f4a362d7e5add103b30271a8a55
# Merge: 7384e2d7 59e5e405
# Author: Piotr Balcer <piotr.balcer@intel.com>
# Date: Mon Sep 23 10:58:51 2024 +0200
# Merge pull request #2113 from oneapi-src/revert-1698-counter-based-2
# Revert "[L0] Phase 2 of Counter-Based Event Implementation"
set(UNIFIED_RUNTIME_TAG 9ca3ec7a9c1d2f4a362d7e5add103b30271a8a55)
# commit f5c907a0f74fd6729be5c2e137144f1a43f87111
# Merge: 9ca3ec7 be38e567
# Author: aarongreig <aaron.greig@codeplay.com>
# Date: Mon Sep 23 08:27:12 2024 -0700
# Merge pull request #1830 from JackAKirk/hip-set-device
# [hip] Remove deprecated hip APIs, simplify urContext
set(UNIFIED_RUNTIME_TAG f5c907a0f74fd6729be5c2e137144f1a43f87111)

set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need
Expand Down
13 changes: 6 additions & 7 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,16 @@ inline backend_return_t<backend::ext_oneapi_cuda, context> get_native<
#if SYCL_EXT_ONEAPI_BACKEND_HIP

template <>
__SYCL_DEPRECATED(
"Context interop is deprecated for HIP. If a native context is required,"
" use hipDevicePrimaryCtxRetain with a native device")
inline backend_return_t<backend::ext_oneapi_hip, context> get_native<
backend::ext_oneapi_hip, context>(const context &Obj) {
inline backend_return_t<backend::ext_oneapi_hip, context>
get_native<backend::ext_oneapi_hip, context>(const context &Obj) {
if (Obj.get_backend() != backend::ext_oneapi_hip) {
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
return reinterpret_cast<backend_return_t<backend::ext_oneapi_hip, context>>(
Obj.getNative());
throw sycl::exception(
make_error_code(sycl::errc::feature_not_supported),
"Context interop is not supported for HIP. If a native context is "
"required, use hipDevicePrimaryCtxRetain with a native device");
}

#endif // SYCL_EXT_ONEAPI_BACKEND_HIP
Expand Down
9 changes: 9 additions & 0 deletions sycl/test-e2e/Basic/interop/interop_all_backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ int main() {
auto Event3 = InteropQueue.memcpy(&vec[0], A, N * sizeof(int), Event2);
Event3.wait();

if constexpr (BACKEND == backend::ext_oneapi_hip) {
try {
backend_traits<BACKEND>::return_type<context> NativeContext =
get_native<BACKEND>(Context);
} catch (sycl::exception &e) {
assert(e.code() == sycl::errc::feature_not_supported);
}
}

free(A, InteropQueue);

for (const auto &val : vec) {
Expand Down
6 changes: 3 additions & 3 deletions sycl/test/basic_tests/interop-hip.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: hip
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API %s
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify %s
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -D__SYCL_INTERNAL_API %s

// Test for HIP interop API

Expand Down Expand Up @@ -51,7 +51,7 @@ int main() {
// backend-defined and specified in the backend specification.

hip_device = get_native<backend::ext_oneapi_hip>(Device);
// expected-warning@+1{{'get_native<sycl::backend::ext_oneapi_hip, sycl::context>' is deprecated: Context interop is deprecated for HIP. If a native context is required, use hipDevicePrimaryCtxRetain with a native device}}
// expected-no-diagnostics
hip_context = get_native<backend::ext_oneapi_hip>(Context);
hip_event = get_native<backend::ext_oneapi_hip>(Event);
hip_queue = get_native<backend::ext_oneapi_hip>(Queue);
Expand Down

0 comments on commit 51438d5

Please sign in to comment.