-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[OpenMP] Adds omp_target_is_accessible routine #138294
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
025d36e
b33b27e
bf01578
d20f4d5
cb87242
03d45cc
21b1d6a
95ab6fe
2436211
c92c94f
eeb7604
9d97424
34acf27
d4ecaf6
2792290
712bdd1
dd15747
108e4b9
e9dccd6
4345232
4b51745
0ef2e79
454df9e
79dd36f
0ccae1d
588c394
b751e75
584553e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,8 @@ EXTERN int omp_get_device_num(void) { | |
EXTERN int omp_get_initial_device(void) { | ||
TIMESCOPE(); | ||
OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0))); | ||
int HostDevice = omp_get_num_devices(); | ||
int NumDevices = omp_get_num_devices(); | ||
int HostDevice = NumDevices == 0 ? -1 : NumDevices; | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
DP("Call to omp_get_initial_device returning %d\n", HostDevice); | ||
return HostDevice; | ||
} | ||
|
@@ -195,6 +196,48 @@ EXTERN int omp_target_is_present(const void *Ptr, int DeviceNum) { | |
return Rc; | ||
} | ||
|
||
/// Check whether a pointer is accessible from a device. | ||
/// the functionality is available in OpenMP 5.1 and later | ||
/// OpenMP 5.1 | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/// omp_target_is_accessible checks whether a host pointer is accessible from a | ||
/// device OpenMP 6.0 removes restriction on pointer, allowing any pointer | ||
/// interpreted as a pointer in the address space of the given device. | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
EXTERN int omp_target_is_accessible(const void *Ptr, size_t Size, | ||
int DeviceNum) { | ||
TIMESCOPE(); | ||
OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0))); | ||
DP("Call to omp_target_is_accessible for device %d, address " DPxMOD | ||
", size %zu\n", | ||
DeviceNum, DPxPTR(Ptr), Size); | ||
|
||
if (!Ptr) { | ||
DP("Call to omp_target_is_accessible with NULL ptr returning false\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does spec say so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does. OMP Specs 6.0, page 607 "If ptr is NULL, the routine returns zero". Please check the specs before asking. |
||
return false; | ||
} | ||
|
||
if (DeviceNum == omp_get_initial_device()) { | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
DP("Call to omp_target_is_accessible on host, returning true\n"); | ||
return true; | ||
} | ||
|
||
// The device number must refer to a valid device | ||
auto DeviceOrErr = PM->getDevice(DeviceNum); | ||
if (!DeviceOrErr) | ||
FATAL_MESSAGE(DeviceNum, "%s", toString(DeviceOrErr.takeError()).c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether this is a fatal message or simple just return false? What does the spec say when the device number is invalid? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @shiltian : let's return false if the device doesn't exist. A warning is also in order. |
||
|
||
// For OpenMP 5.1 the routine checks whether a host pointer is accessible from | ||
// the device this requires for the device to support unified shared memory | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (DeviceOrErr->supportsUnifiedMemory()) { | ||
DP("Device %d supports unified memory, returning true\n", DeviceNum); | ||
return true; | ||
} | ||
|
||
// functionality to check whether a device pointer is accessible from a device | ||
nicebert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// (OpenMP 6.0) from the host might not be possible | ||
DP("Device %d does not support unified memory, returning false\n", DeviceNum); | ||
return false; | ||
} | ||
|
||
EXTERN int omp_target_memcpy(void *Dst, const void *Src, size_t Length, | ||
size_t DstOffset, size_t SrcOffset, int DstDevice, | ||
int SrcDevice) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %libomptarget-compilexx-generic | ||
// RUN: env HSA_XNACK=1 %libomptarget-run-generic 2>&1 \ | ||
// RUN: | %fcheck-generic | ||
|
||
// RUN: %libomptarget-compilexx-generic | ||
// RUN: env HSA_XNACK=0 %libomptarget-run-generic 2>&1 \ | ||
// RUN: | %fcheck-generic -check-prefix=NO_USM | ||
|
||
// REQUIRES: unified_shared_memory | ||
// REQUIRES: amdgpu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd make this a XFAIL for nvptx instead of a requirement, since it always returns false. |
||
|
||
// CHECK: SUCCESS | ||
// NO_USM: Not accessible | ||
|
||
#include <assert.h> | ||
#include <iostream> | ||
#include <omp.h> | ||
#include <stdio.h> | ||
|
||
int main() { | ||
int n = 10000; | ||
int *a = new int[n]; | ||
int err = 0; | ||
|
||
// program must be executed with HSA_XNACK=1 | ||
if (!omp_target_is_accessible(a, n * sizeof(int), /*device_num=*/0)) | ||
printf("Not accessible\n"); | ||
else { | ||
#pragma omp target teams distribute parallel for | ||
for (int i = 0; i < n; i++) | ||
a[i] = i; | ||
|
||
for (int i = 0; i < n; i++) | ||
if (a[i] != i) | ||
err++; | ||
} | ||
|
||
printf("%s\n", err == 0 ? "SUCCESS" : "FAIL"); | ||
return err; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.