Skip to content

Commit

Permalink
Corrected test_vulkan to use specific platform/device from harness (#…
Browse files Browse the repository at this point in the history
…2154)

Fixes #1926 according to task description
  • Loading branch information
shajder authored Jan 7, 2025
1 parent 4c70fec commit d058dfd
Show file tree
Hide file tree
Showing 14 changed files with 2,026 additions and 2,021 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ getCLImageInfoFromVkImageInfo(const VkImageCreateInfo *VulkanImageCreateInfo,
memcpy(img_fmt, &clImgFormat, sizeof(cl_image_format));

img_desc->image_type = getImageTypeFromVk(VulkanImageCreateInfo->imageType);
if (CL_INVALID_VALUE == img_desc->image_type)
if (CL_INVALID_VALUE == static_cast<cl_int>(img_desc->image_type))
{
return CL_INVALID_VALUE;
}
Expand Down Expand Up @@ -503,6 +503,8 @@ cl_int check_external_memory_handle_type(
errNum = clGetDeviceInfo(deviceID,
CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR,
0, NULL, &handle_type_size);
test_error(errNum, "clGetDeviceInfo failed");

handle_type =
(cl_external_memory_handle_type_khr *)malloc(handle_type_size);

Expand Down Expand Up @@ -539,6 +541,7 @@ cl_int check_external_semaphore_handle_type(

errNum =
clGetDeviceInfo(deviceID, queryParamName, 0, NULL, &handle_type_size);
test_error(errNum, "clGetDeviceInfo failed");

if (handle_type_size == 0)
{
Expand Down
86 changes: 48 additions & 38 deletions test_conformance/common/vulkan_wrapper/vulkan_utility.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 The Khronos Group Inc.
// Copyright (c) 2024 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,13 +40,10 @@ const VulkanInstance &getVulkanInstance()

const VulkanPhysicalDevice &getVulkanPhysicalDevice()
{
size_t pdIdx;
size_t pdIdx = 0;
cl_int errNum = 0;
cl_platform_id platform = NULL;
cl_platform_id platform = nullptr;
cl_uchar uuid[CL_UUID_SIZE_KHR];
cl_device_id *devices;
char *extensions = NULL;
size_t extensionSize = 0;
cl_uint num_devices = 0;
cl_uint device_no = 0;
const size_t bufsize = BUFFERSIZE;
Expand All @@ -69,49 +66,24 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
throw std::runtime_error(
"Error: clGetDeviceIDs failed in returning of devices\n");
}
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
if (NULL == devices)
{
throw std::runtime_error(
"Error: Unable to allocate memory for devices\n");
}
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, devices,
NULL);
std::vector<cl_device_id> devices(num_devices);
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices,
devices.data(), NULL);
if (CL_SUCCESS != errNum)
{
throw std::runtime_error("Error: Failed to get deviceID.\n");
}
bool is_selected = false;
for (device_no = 0; device_no < num_devices; device_no++)
{
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS, 0,
NULL, &extensionSize);
if (CL_SUCCESS != errNum)
{
throw std::runtime_error("Error in clGetDeviceInfo for getting "
"device_extension size....\n");
}
extensions = (char *)malloc(extensionSize);
if (NULL == extensions)
{
throw std::runtime_error(
"Unable to allocate memory for extensions\n");
}
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS,
extensionSize, extensions, NULL);
if (CL_SUCCESS != errNum)
{
throw std::runtime_error("Error: Error in clGetDeviceInfo for "
"getting device_extension\n");
}
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_UUID_KHR,
CL_UUID_SIZE_KHR, uuid, &extensionSize);
CL_UUID_SIZE_KHR, uuid, nullptr);
if (CL_SUCCESS != errNum)
{
throw std::runtime_error(
"Error: clGetDeviceInfo failed with error\n");
}
free(extensions);

for (pdIdx = 0; pdIdx < physicalDeviceList.size(); pdIdx++)
{
if (!memcmp(&uuid, physicalDeviceList[pdIdx].getUUID(),
Expand Down Expand Up @@ -139,10 +111,48 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
return physicalDeviceList[pdIdx];
}

const VulkanQueueFamily &getVulkanQueueFamily(uint32_t queueFlags)
const VulkanPhysicalDevice &
getAssociatedVulkanPhysicalDevice(cl_device_id deviceId)
{
size_t pdIdx;
cl_int errNum = 0;
cl_uchar uuid[CL_UUID_SIZE_KHR];
const VulkanInstance &instance = getVulkanInstance();
const VulkanPhysicalDeviceList &physicalDeviceList =
instance.getPhysicalDeviceList();

errNum = clGetDeviceInfo(deviceId, CL_DEVICE_UUID_KHR, CL_UUID_SIZE_KHR,
uuid, nullptr);
if (CL_SUCCESS != errNum)
{
throw std::runtime_error("Error: clGetDeviceInfo failed with error\n");
}
for (pdIdx = 0; pdIdx < physicalDeviceList.size(); pdIdx++)
{
if (!memcmp(&uuid, physicalDeviceList[pdIdx].getUUID(), VK_UUID_SIZE))
{
std::cout << "Selected physical device = "
<< physicalDeviceList[pdIdx] << std::endl;
break;
}
}

if ((pdIdx >= physicalDeviceList.size())
|| (physicalDeviceList[pdIdx] == (VkPhysicalDevice)VK_NULL_HANDLE))
{
throw std::runtime_error("failed to find a suitable GPU!");
}
std::cout << "Selected physical device is: " << physicalDeviceList[pdIdx]
<< std::endl;
return physicalDeviceList[pdIdx];
}


const VulkanQueueFamily &
getVulkanQueueFamily(const VulkanPhysicalDevice &physicalDevice,
uint32_t queueFlags)
{
size_t qfIdx;
const VulkanPhysicalDevice &physicalDevice = getVulkanPhysicalDevice();
const VulkanQueueFamilyList &queueFamilyList =
physicalDevice.getQueueFamilyList();

Expand Down
11 changes: 7 additions & 4 deletions test_conformance/common/vulkan_wrapper/vulkan_utility.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 The Khronos Group Inc.
// Copyright (c) 2024 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,9 +32,12 @@

const VulkanInstance& getVulkanInstance();
const VulkanPhysicalDevice& getVulkanPhysicalDevice();
const VulkanQueueFamily&
getVulkanQueueFamily(uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
| VULKAN_QUEUE_FLAG_COMPUTE);
const VulkanPhysicalDevice&
getAssociatedVulkanPhysicalDevice(cl_device_id deviceId);
const VulkanQueueFamily& getVulkanQueueFamily(
const VulkanPhysicalDevice& physicalDevice = getVulkanPhysicalDevice(),
uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
| VULKAN_QUEUE_FLAG_COMPUTE);
const VulkanMemoryType&
getVulkanMemoryType(const VulkanDevice& device,
VulkanMemoryTypeProperty memoryTypeProperty);
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class VulkanDevice {
virtual ~VulkanDevice();
const VulkanPhysicalDevice &getPhysicalDevice() const;
VulkanQueue &
getQueue(const VulkanQueueFamily &queueFamily = getVulkanQueueFamily(),
getQueue(const VulkanQueueFamily &queueFamily /* = getVulkanQueueFamily()*/,
uint32_t queueIndex = 0);
operator VkDevice() const;
};
Expand Down
1 change: 1 addition & 0 deletions test_conformance/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set (${MODULE_NAME}_SOURCES
test_vulkan_api_consistency_for_1dimages.cpp
test_vulkan_platform_device_info.cpp
vulkan_interop_common.cpp
vulkan_test_base.h
)

include_directories("../common/vulkan_wrapper")
Expand Down
Loading

0 comments on commit d058dfd

Please sign in to comment.