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

[SYCL][CUDA][HIP] Fix PI_MEM_ALLOC_DEVICE USM pointer query #5325

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4825,12 +4825,19 @@ pi_result cuda_piextUSMGetMemAllocInfo(pi_context context, const void *ptr,
#endif
}
case PI_MEM_ALLOC_DEVICE: {
unsigned int value;
// get device index associated with this pointer
unsigned int device_idx;
result = PI_CHECK_ERROR(cuPointerGetAttribute(
&value, CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL, (CUdeviceptr)ptr));
pi_platform platform;
result = cuda_piPlatformsGet(1, &platform, nullptr);
pi_device device = platform->devices_[value].get();
&device_idx, CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL, (CUdeviceptr)ptr));

// currently each device is in its own platform, so find the platform at
// the same index
std::vector<pi_platform> platforms;
platforms.resize(device_idx + 1);
result = cuda_piPlatformsGet(device_idx + 1, platforms.data(), nullptr);

// get the device from the platform
pi_device device = platforms[device_idx]->devices_[0].get();
return getInfo(param_value_size, param_value, param_value_size_ret,
device);
}
Expand Down
18 changes: 11 additions & 7 deletions sycl/plugins/hip/pi_hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4792,15 +4792,19 @@ pi_result hip_piextUSMGetMemAllocInfo(pi_context context, const void *ptr,
}

case PI_MEM_ALLOC_DEVICE: {
unsigned int value;
// get device index associated with this pointer
result = PI_CHECK_ERROR(
hipPointerGetAttributes(&hipPointerAttributeType, ptr));
auto devicePointer =
static_cast<int *>(hipPointerAttributeType.devicePointer);
value = *devicePointer;
pi_platform platform;
result = hip_piPlatformsGet(1, &platform, nullptr);
pi_device device = platform->devices_[value].get();
int device_idx = hipPointerAttributeType.device;

// currently each device is in its own platform, so find the platform at
// the same index
std::vector<pi_platform> platforms;
platforms.resize(device_idx + 1);
result = hip_piPlatformsGet(device_idx + 1, platforms.data(), nullptr);

// get the device from the platform
pi_device device = platforms[device_idx]->devices_[0].get();
return getInfo(param_value_size, param_value, param_value_size_ret,
device);
}
Expand Down