Skip to content

Commit 25acf65

Browse files
committed
Remove the nothrow version and simplify the query
1 parent 526d24c commit 25acf65

3 files changed

Lines changed: 27 additions & 57 deletions

File tree

PanGPA.log

Whitespace-only changes.

libcudacxx/include/cuda/__memory/is_pointer_accessible.h

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <cuda/__runtime/ensure_current_context.h>
2727
#include <cuda/std/__exception/cuda_error.h>
2828
#include <cuda/std/__exception/exception_macros.h>
29+
#include <cuda/std/__type_traits/always_false.h>
2930
#include <cuda/std/__type_traits/integral_constant.h>
3031

3132
#include <cuda/std/__cccl/prologue.h>
@@ -205,59 +206,25 @@ _CCCL_HOST_API inline bool __is_device_accessible(
205206
{
206207
return false;
207208
}
208-
_CCCL_TRY
209+
if constexpr (_IsNothrow)
210+
{
211+
static_assert(!_IsNothrow, "TODO: implement a no-throw context setter for __is_device_accessible_nothrow");
212+
return false;
213+
}
214+
else
209215
{
210216
::cuda::__ensure_current_context __ctx_setter{__device};
211217

212-
::CUpointer_attribute __attrs[4] = {
213-
::CU_POINTER_ATTRIBUTE_MEMORY_TYPE,
214-
::CU_POINTER_ATTRIBUTE_IS_MANAGED,
215-
::CU_POINTER_ATTRIBUTE_DEVICE_POINTER,
216-
::CU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE};
217-
auto __memory_type = static_cast<::CUmemorytype>(0);
218-
int __is_managed = 0;
219-
void* __device_ptr = nullptr;
220-
::CUmemoryPool __mempool = nullptr;
221-
void* __results[4] = {&__memory_type, &__is_managed, &__device_ptr, &__mempool};
222-
const auto __status = ::cuda::__driver::__pointerGetAttributesNoThrow(__attrs, __results, __p);
218+
void* __device_ptr = nullptr;
219+
const auto __status = ::cuda::__driver::__pointerGetAttributeNoThrow<::CU_POINTER_ATTRIBUTE_DEVICE_POINTER>(
220+
__device_ptr, __p);
223221
if (__status == ::cudaErrorInvalidValue)
224222
{
225223
return false;
226224
}
227225
_CCCL_THROW_OR_RETURN(__status, "Failed to get attributes of a pointer");
228-
// (1) check if the pointer is unregistered
229-
if (__memory_type == static_cast<::CUmemorytype>(0))
230-
{
231-
return false;
232-
}
233-
// (2) check if the pointer is a device accessible pointer or managed memory
234-
if (!__is_managed && __memory_type != ::CU_MEMORYTYPE_DEVICE)
235-
{
236-
return false;
237-
}
238-
// (3) check if a memory pool is associated with the pointer
239-
if (__mempool != nullptr)
240-
{
241-
::CUmemLocation __prop{::CU_MEM_LOCATION_TYPE_DEVICE, __device.get()};
242-
::CUmemAccess_flags __pool_flags;
243-
const auto __status2 = ::cuda::__driver::__mempoolGetAccessNoThrow(__pool_flags, __mempool, &__prop);
244-
_CCCL_THROW_OR_RETURN(__status2, "Failed to get access of a memory pool");
245-
return __pool_flags & unsigned{::CU_MEM_ACCESS_FLAGS_PROT_READ};
246-
}
247-
// (4) check if the pointer is actually accessible from the specified device
248226
return __device_ptr != nullptr;
249227
}
250-
_CCCL_CATCH_ALL
251-
{
252-
if constexpr (_IsNothrow)
253-
{
254-
return false;
255-
}
256-
else
257-
{
258-
_CCCL_RETHROW;
259-
}
260-
}
261228
}
262229

263230
/**
@@ -273,10 +240,13 @@ _CCCL_HOST_API inline bool is_device_accessible(const void* __p, device_ref __de
273240
return ::cuda::__is_device_accessible(__p, __device, ::cuda::std::false_type{});
274241
}
275242

243+
template <class _Dependent = void>
276244
[[nodiscard]]
277-
_CCCL_HOST_API inline bool __is_device_accessible_nothrow(const void* __p, device_ref __device) noexcept
245+
_CCCL_HOST_API inline bool __is_device_accessible_nothrow(const void*, device_ref) noexcept
278246
{
279-
return ::cuda::__is_device_accessible(__p, __device, ::cuda::std::true_type{});
247+
static_assert(::cuda::std::__always_false_v<_Dependent>,
248+
"TODO: implement a no-throw context setter for __is_device_accessible_nothrow");
249+
return false;
280250
}
281251

282252
# undef _CCCL_THROW_OR_RETURN

libcudacxx/test/libcudacxx/cuda/memory/is_pointer_accessible.pass.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void test_accessible_pointer(
3434
assert(cuda::is_host_accessible(ptr) == is_host_accessible);
3535
assert(cuda::__is_host_accessible_nothrow(ptr) == is_host_accessible);
3636
assert(cuda::is_device_accessible(ptr, device) == is_device_accessible);
37-
assert(cuda::__is_device_accessible_nothrow(ptr, device) == is_device_accessible);
37+
// assert(cuda::__is_device_accessible_nothrow(ptr, device) == is_device_accessible);
3838
assert(cuda::__is_device_or_managed_memory(ptr) == is_device_accessible);
3939
assert(cuda::is_managed(ptr) == is_managed_accessible);
4040
assert(cuda::__is_managed_nothrow(ptr) == is_managed_accessible);
@@ -43,7 +43,7 @@ void test_accessible_pointer(
4343
assert(cuda::is_host_accessible(ptr + 1) == is_host_accessible);
4444
assert(cuda::__is_host_accessible_nothrow(ptr + 1) == is_host_accessible);
4545
assert(cuda::is_device_accessible(ptr + 1, device) == is_device_accessible);
46-
assert(cuda::__is_device_accessible_nothrow(ptr + 1, device) == is_device_accessible);
46+
// assert(cuda::__is_device_accessible_nothrow(ptr + 1, device) == is_device_accessible);
4747
assert(cuda::__is_device_or_managed_memory(ptr + 1) == is_device_accessible);
4848
assert(cuda::is_managed(ptr + 1) == is_managed_accessible);
4949
assert(cuda::__is_managed_nothrow(ptr + 1) == is_managed_accessible);
@@ -77,8 +77,8 @@ bool test_basic()
7777
test_accessible_pointer(host_ptr1, true, false, false, dev); // global host array
7878
test_accessible_pointer(host_ptr2, true, false, false, dev); // local host array
7979
test_accessible_pointer(host_ptr3, true, false, false, dev); // non-cuda malloc host memory
80-
test_accessible_pointer(host_ptr4, true, false, false, dev); // stack-allocated host memory
81-
test_accessible_pointer(host_ptr5, true, false, false, dev); // pinned host memory
80+
test_accessible_pointer(host_ptr4, true, true, false, dev); // pinned host memory
81+
test_accessible_pointer(host_ptr5, true, true, false, dev); // mapped pinned host memory
8282

8383
test_accessible_pointer(device_ptr2, false, true, false, dev); // cudaMalloc device pointer
8484
test_accessible_pointer(device_ptr3, false, true, false, dev); // cudaMallocAsync device pointer
@@ -179,9 +179,9 @@ bool test_multiple_devices()
179179
cuda::__ensure_current_context ctx1(dev1);
180180
assert(cuda::__is_device_or_managed_memory(device_ptr0) == true);
181181
assert(cuda::is_device_accessible(device_ptr0, dev0) == true);
182-
assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev0) == true);
182+
// assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev0) == true);
183183
assert(cuda::is_device_accessible(device_ptr0, dev1) == false);
184-
assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == false);
184+
// assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == false);
185185

186186
int can_access_peer = 0;
187187
assert(cudaDeviceCanAccessPeer(&can_access_peer, dev1.get(), dev0.get()) == cudaSuccess);
@@ -191,13 +191,13 @@ bool test_multiple_devices()
191191
}
192192
assert(cuda::__is_device_or_managed_memory(device_ptr0) == true);
193193
assert(cuda::is_device_accessible(device_ptr0, dev1) == false);
194-
assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == false);
194+
// assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == false);
195195

196196
assert(cudaDeviceEnablePeerAccess(dev0.get(), 0) == cudaSuccess);
197197
assert(cuda::is_device_accessible(device_ptr0, dev0) == true);
198-
assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev0) == true);
198+
// assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev0) == true);
199199
assert(cuda::is_device_accessible(device_ptr0, dev1) == true);
200-
assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == true);
200+
// assert(cuda::__is_device_accessible_nothrow(device_ptr0, dev1) == true);
201201
assert(cudaDeviceDisablePeerAccess(dev0.get()) == cudaSuccess);
202202
return true;
203203
}
@@ -223,7 +223,7 @@ bool test_multiple_devices_from_pool()
223223
return true;
224224
}
225225
assert(cuda::is_device_accessible(ptr, dev1) == false);
226-
assert(cuda::__is_device_accessible_nothrow(ptr, dev1) == false);
226+
// assert(cuda::__is_device_accessible_nothrow(ptr, dev1) == false);
227227
assert(cuda::__is_device_or_managed_memory(ptr) == true);
228228

229229
cudaMemAccessDesc access_desc = {};
@@ -232,9 +232,9 @@ bool test_multiple_devices_from_pool()
232232
access_desc.location.id = dev1.get();
233233
assert(cudaMemPoolSetAccess(mem_pool, &access_desc, 1) == cudaSuccess);
234234
assert(cuda::is_device_accessible(ptr, dev0) == true);
235-
assert(cuda::__is_device_accessible_nothrow(ptr, dev0) == true);
235+
// assert(cuda::__is_device_accessible_nothrow(ptr, dev0) == true);
236236
assert(cuda::is_device_accessible(ptr, dev1) == true);
237-
assert(cuda::__is_device_accessible_nothrow(ptr, dev1) == true);
237+
// assert(cuda::__is_device_accessible_nothrow(ptr, dev1) == true);
238238
return true;
239239
}
240240

0 commit comments

Comments
 (0)