Skip to content

Commit d058dfd

Browse files
authored
Corrected test_vulkan to use specific platform/device from harness (#2154)
Fixes #1926 according to task description
1 parent 4c70fec commit d058dfd

14 files changed

+2026
-2021
lines changed

test_conformance/common/vulkan_wrapper/opencl_vulkan_wrapper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ getCLImageInfoFromVkImageInfo(const VkImageCreateInfo *VulkanImageCreateInfo,
464464
memcpy(img_fmt, &clImgFormat, sizeof(cl_image_format));
465465

466466
img_desc->image_type = getImageTypeFromVk(VulkanImageCreateInfo->imageType);
467-
if (CL_INVALID_VALUE == img_desc->image_type)
467+
if (CL_INVALID_VALUE == static_cast<cl_int>(img_desc->image_type))
468468
{
469469
return CL_INVALID_VALUE;
470470
}
@@ -503,6 +503,8 @@ cl_int check_external_memory_handle_type(
503503
errNum = clGetDeviceInfo(deviceID,
504504
CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR,
505505
0, NULL, &handle_type_size);
506+
test_error(errNum, "clGetDeviceInfo failed");
507+
506508
handle_type =
507509
(cl_external_memory_handle_type_khr *)malloc(handle_type_size);
508510

@@ -539,6 +541,7 @@ cl_int check_external_semaphore_handle_type(
539541

540542
errNum =
541543
clGetDeviceInfo(deviceID, queryParamName, 0, NULL, &handle_type_size);
544+
test_error(errNum, "clGetDeviceInfo failed");
542545

543546
if (handle_type_size == 0)
544547
{

test_conformance/common/vulkan_wrapper/vulkan_utility.cpp

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 The Khronos Group Inc.
2+
// Copyright (c) 2024 The Khronos Group Inc.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -40,13 +40,10 @@ const VulkanInstance &getVulkanInstance()
4040

4141
const VulkanPhysicalDevice &getVulkanPhysicalDevice()
4242
{
43-
size_t pdIdx;
43+
size_t pdIdx = 0;
4444
cl_int errNum = 0;
45-
cl_platform_id platform = NULL;
45+
cl_platform_id platform = nullptr;
4646
cl_uchar uuid[CL_UUID_SIZE_KHR];
47-
cl_device_id *devices;
48-
char *extensions = NULL;
49-
size_t extensionSize = 0;
5047
cl_uint num_devices = 0;
5148
cl_uint device_no = 0;
5249
const size_t bufsize = BUFFERSIZE;
@@ -69,49 +66,24 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
6966
throw std::runtime_error(
7067
"Error: clGetDeviceIDs failed in returning of devices\n");
7168
}
72-
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
73-
if (NULL == devices)
74-
{
75-
throw std::runtime_error(
76-
"Error: Unable to allocate memory for devices\n");
77-
}
78-
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, devices,
79-
NULL);
69+
std::vector<cl_device_id> devices(num_devices);
70+
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices,
71+
devices.data(), NULL);
8072
if (CL_SUCCESS != errNum)
8173
{
8274
throw std::runtime_error("Error: Failed to get deviceID.\n");
8375
}
8476
bool is_selected = false;
8577
for (device_no = 0; device_no < num_devices; device_no++)
8678
{
87-
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS, 0,
88-
NULL, &extensionSize);
89-
if (CL_SUCCESS != errNum)
90-
{
91-
throw std::runtime_error("Error in clGetDeviceInfo for getting "
92-
"device_extension size....\n");
93-
}
94-
extensions = (char *)malloc(extensionSize);
95-
if (NULL == extensions)
96-
{
97-
throw std::runtime_error(
98-
"Unable to allocate memory for extensions\n");
99-
}
100-
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS,
101-
extensionSize, extensions, NULL);
102-
if (CL_SUCCESS != errNum)
103-
{
104-
throw std::runtime_error("Error: Error in clGetDeviceInfo for "
105-
"getting device_extension\n");
106-
}
10779
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_UUID_KHR,
108-
CL_UUID_SIZE_KHR, uuid, &extensionSize);
80+
CL_UUID_SIZE_KHR, uuid, nullptr);
10981
if (CL_SUCCESS != errNum)
11082
{
11183
throw std::runtime_error(
11284
"Error: clGetDeviceInfo failed with error\n");
11385
}
114-
free(extensions);
86+
11587
for (pdIdx = 0; pdIdx < physicalDeviceList.size(); pdIdx++)
11688
{
11789
if (!memcmp(&uuid, physicalDeviceList[pdIdx].getUUID(),
@@ -139,10 +111,48 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
139111
return physicalDeviceList[pdIdx];
140112
}
141113

142-
const VulkanQueueFamily &getVulkanQueueFamily(uint32_t queueFlags)
114+
const VulkanPhysicalDevice &
115+
getAssociatedVulkanPhysicalDevice(cl_device_id deviceId)
116+
{
117+
size_t pdIdx;
118+
cl_int errNum = 0;
119+
cl_uchar uuid[CL_UUID_SIZE_KHR];
120+
const VulkanInstance &instance = getVulkanInstance();
121+
const VulkanPhysicalDeviceList &physicalDeviceList =
122+
instance.getPhysicalDeviceList();
123+
124+
errNum = clGetDeviceInfo(deviceId, CL_DEVICE_UUID_KHR, CL_UUID_SIZE_KHR,
125+
uuid, nullptr);
126+
if (CL_SUCCESS != errNum)
127+
{
128+
throw std::runtime_error("Error: clGetDeviceInfo failed with error\n");
129+
}
130+
for (pdIdx = 0; pdIdx < physicalDeviceList.size(); pdIdx++)
131+
{
132+
if (!memcmp(&uuid, physicalDeviceList[pdIdx].getUUID(), VK_UUID_SIZE))
133+
{
134+
std::cout << "Selected physical device = "
135+
<< physicalDeviceList[pdIdx] << std::endl;
136+
break;
137+
}
138+
}
139+
140+
if ((pdIdx >= physicalDeviceList.size())
141+
|| (physicalDeviceList[pdIdx] == (VkPhysicalDevice)VK_NULL_HANDLE))
142+
{
143+
throw std::runtime_error("failed to find a suitable GPU!");
144+
}
145+
std::cout << "Selected physical device is: " << physicalDeviceList[pdIdx]
146+
<< std::endl;
147+
return physicalDeviceList[pdIdx];
148+
}
149+
150+
151+
const VulkanQueueFamily &
152+
getVulkanQueueFamily(const VulkanPhysicalDevice &physicalDevice,
153+
uint32_t queueFlags)
143154
{
144155
size_t qfIdx;
145-
const VulkanPhysicalDevice &physicalDevice = getVulkanPhysicalDevice();
146156
const VulkanQueueFamilyList &queueFamilyList =
147157
physicalDevice.getQueueFamilyList();
148158

test_conformance/common/vulkan_wrapper/vulkan_utility.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 The Khronos Group Inc.
2+
// Copyright (c) 2024 The Khronos Group Inc.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -32,9 +32,12 @@
3232

3333
const VulkanInstance& getVulkanInstance();
3434
const VulkanPhysicalDevice& getVulkanPhysicalDevice();
35-
const VulkanQueueFamily&
36-
getVulkanQueueFamily(uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
37-
| VULKAN_QUEUE_FLAG_COMPUTE);
35+
const VulkanPhysicalDevice&
36+
getAssociatedVulkanPhysicalDevice(cl_device_id deviceId);
37+
const VulkanQueueFamily& getVulkanQueueFamily(
38+
const VulkanPhysicalDevice& physicalDevice = getVulkanPhysicalDevice(),
39+
uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
40+
| VULKAN_QUEUE_FLAG_COMPUTE);
3841
const VulkanMemoryType&
3942
getVulkanMemoryType(const VulkanDevice& device,
4043
VulkanMemoryTypeProperty memoryTypeProperty);

test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class VulkanDevice {
145145
virtual ~VulkanDevice();
146146
const VulkanPhysicalDevice &getPhysicalDevice() const;
147147
VulkanQueue &
148-
getQueue(const VulkanQueueFamily &queueFamily = getVulkanQueueFamily(),
148+
getQueue(const VulkanQueueFamily &queueFamily /* = getVulkanQueueFamily()*/,
149149
uint32_t queueIndex = 0);
150150
operator VkDevice() const;
151151
};

test_conformance/vulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set (${MODULE_NAME}_SOURCES
2525
test_vulkan_api_consistency_for_1dimages.cpp
2626
test_vulkan_platform_device_info.cpp
2727
vulkan_interop_common.cpp
28+
vulkan_test_base.h
2829
)
2930

3031
include_directories("../common/vulkan_wrapper")

0 commit comments

Comments
 (0)