Skip to content

Commit

Permalink
Fix find_suitable_device logic to conditionally increment cl_device_c…
Browse files Browse the repository at this point in the history
…ount
  • Loading branch information
Beanavil committed May 29, 2024
1 parent 9edbe59 commit 25d5ed5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion samples/extensions/khr/externalmemory/vulkan_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,20 @@ find_suitable_device(VkInstance instance,
}
}

if (!cl_device_count)
{
printf("No suitable OpenCL Vulkan-compatible devices available\n");
goto platforms;
}

// For each OpenCL device, query its Vulkan-compatible device UUID and
// add it to the list of candidates. The device must support the
// cl_khr_device_uuid extension for us to be able to query the device's
// UUID.
struct cl_device_candidate* cl_candidates =
(struct cl_device_candidate*)malloc(
cl_device_count * sizeof(struct cl_device_candidate));
const size_t cl_devices_with_ext = cl_device_count;
cl_device_count = 0;
for (cl_uint platform_id = 0; platform_id < platform_count;
++platform_id)
Expand All @@ -275,7 +282,7 @@ find_suitable_device(VkInstance instance,

for (cl_uint cl_candidate_id = 0;
cl_candidate_id < cl_platform_devices_count;
++cl_candidate_id, ++cl_device_count)
++cl_candidate_id)
{
cl_device_id device = cl_util_get_device(
platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error);
Expand All @@ -292,6 +299,7 @@ find_suitable_device(VkInstance instance,
memcpy(candidate.uuid, &vk_candidate_uuid,
sizeof(cl_uchar) * CL_UUID_SIZE_KHR);
cl_candidates[cl_device_count] = candidate;
cl_device_count++;
}
}
}
Expand Down

0 comments on commit 25d5ed5

Please sign in to comment.