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

Return device_count=0 in error case #285

Merged
merged 3 commits into from
Dec 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion include/gtensor/backend_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,19 @@ class backend_ops<gt::space::cuda>
static int device_get_count()
{
int device_count;
gtGpuCheck(cudaGetDeviceCount(&device_count));
cudaError_t code = cudaGetDeviceCount(&device_count);
if (code == cudaErrorNoDevice) {
fprintf(stderr, "Error in cudaGetDeviceCount: %d (%s)\n", code,
cudaGetErrorString(code));
device_count = 0;
} else if (code == cudaErrorInsufficientDriver) {
fprintf(stderr, "Error in cudaGetDeviceCount: %d (%s)\n", code,
cudaGetErrorString(code));
fprintf(stderr, "Did you start the job on a CPU partition?\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of an app specific message, but given we have no way of the application defining it's own message, I guess I am ok with it. Really begs the question as to whether we should propagate certain errors up to the caller.

device_count = 0;
} else if (code != cudaSuccess) {
gtGpuCheck(code);
}
return device_count;
}

Expand Down
9 changes: 8 additions & 1 deletion include/gtensor/backend_hip.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ class backend_ops<gt::space::hip>
static int device_get_count()
{
int device_count;
gtGpuCheck(hipGetDeviceCount(&device_count));
hipError_t code = hipGetDeviceCount(&device_count);
if (code == hipErrorNoDevice) {
fprintf(stderr, "Error in hipGetDeviceCount: %d (%s)\n", code,
hipGetErrorString(code));
device_count = 0;
} else if (code != hipSuccess) {
gtGpuCheck(code);
}
return device_count;
}

Expand Down