Corrected test_vulkan to use specific platform/device from harness (#2154)

Fixes #1926 according to task description
This commit is contained in:
Marcin Hajder
2025-01-07 19:09:38 +01:00
committed by GitHub
parent 4c70fecad7
commit d058dfdeef
14 changed files with 2090 additions and 2085 deletions

View File

@@ -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;
}
@@ -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);
@@ -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)
{

View File

@@ -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.
@@ -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;
@@ -69,14 +66,9 @@ 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");
@@ -84,34 +76,14 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
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(),
@@ -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();

View File

@@ -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.
@@ -32,8 +32,11 @@
const VulkanInstance& getVulkanInstance();
const VulkanPhysicalDevice& getVulkanPhysicalDevice();
const VulkanQueueFamily&
getVulkanQueueFamily(uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
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,

View File

@@ -145,7 +145,7 @@ public:
virtual ~VulkanDevice();
const VulkanPhysicalDevice &getPhysicalDevice() const;
VulkanQueue &
getQueue(const VulkanQueueFamily &queueFamily = getVulkanQueueFamily(),
getQueue(const VulkanQueueFamily &queueFamily /* = getVulkanQueueFamily()*/,
uint32_t queueIndex = 0);
operator VkDevice() const;
};

View File

@@ -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")

View File

@@ -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.
@@ -30,121 +30,15 @@
#include <OpenCL/cl.h>
#endif
#include "procs.h"
#include "harness/testHarness.h"
#include "harness/parseParameters.h"
#include "harness/deviceInfo.h"
#if !defined(_WIN32)
#include <unistd.h>
#endif
#include <vulkan_interop_common.hpp>
#include <vulkan_wrapper.hpp>
#define BUFFERSIZE 3000
static void params_reset()
{
numCQ = 1;
multiImport = false;
multiCtx = false;
}
extern int test_buffer_common(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_,
bool use_fence);
extern int test_image_common(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_);
int test_buffer_single_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, false);
}
int test_buffer_multiple_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, false);
}
int test_buffer_multiImport_sameCtx(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
multiImport = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN SAME CONTEXT...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, false);
}
int test_buffer_multiImport_diffCtx(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
multiImport = true;
multiCtx = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN DIFFERENT CONTEXT...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, false);
}
int test_buffer_single_queue_fence(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, true);
}
int test_buffer_multiple_queue_fence(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, true);
}
int test_buffer_multiImport_sameCtx_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_)
{
params_reset();
multiImport = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN SAME CONTEXT...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, true);
}
int test_buffer_multiImport_diffCtx_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_)
{
params_reset();
multiImport = true;
multiCtx = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN DIFFERENT CONTEXT...... \n\n");
return test_buffer_common(device_, context_, queue_, numElements_, true);
}
int test_image_single_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return test_image_common(device_, context_, queue_, numElements_);
}
int test_image_multiple_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return test_image_common(device_, context_, queue_, numElements_);
}
test_definition test_list[] = { ADD_TEST(buffer_single_queue),
ADD_TEST(buffer_multiple_queue),
ADD_TEST(buffer_multiImport_sameCtx),
@@ -165,20 +59,6 @@ test_definition test_list[] = { ADD_TEST(buffer_single_queue),
const int test_num = ARRAY_SIZE(test_list);
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
char *choosen_platform_name = NULL;
cl_platform_id platform = NULL;
cl_int choosen_platform_index = -1;
char platform_name[1024] = "";
cl_platform_id select_platform = NULL;
char *extensions = NULL;
size_t extensionSize = 0;
cl_uint num_devices = 0;
cl_uint device_no = 0;
cl_device_id *devices;
const size_t bufsize = BUFFERSIZE;
char buf[BUFFERSIZE];
cl_uchar uuid[CL_UUID_SIZE_KHR];
unsigned int numCQ;
bool multiImport;
bool multiCtx;
@@ -269,19 +149,7 @@ size_t parseParams(int argc, const char *argv[], const char **argList)
int main(int argc, const char *argv[])
{
int errNum = 0;
test_start();
params_reset();
if (!checkVkSupport())
{
log_info("Vulkan supported GPU not found \n");
log_info("TEST SKIPPED \n");
return 0;
}
VulkanDevice vkDevice;
cl_device_type requestedDeviceType = CL_DEVICE_TYPE_GPU;
char *force_cpu = getenv("CL_DEVICE_TYPE");
@@ -305,104 +173,10 @@ int main(int argc, const char *argv[])
log_info("Vulkan tests can only run on a GPU device.\n");
return 0;
}
gDeviceType = CL_DEVICE_TYPE_GPU;
const char **argList = (const char **)calloc(argc, sizeof(char *));
size_t argCount = parseParams(argc, argv, argList);
if (argCount == 0) return 0;
// get the platform ID
errNum = clGetPlatformIDs(1, &platform, NULL);
if (errNum != CL_SUCCESS)
{
print_error(errNum, "Error: Failed to get platform\n");
return errNum;
}
errNum =
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
if (CL_SUCCESS != errNum)
{
print_error(errNum, "clGetDeviceIDs failed in returning of devices\n");
return errNum;
}
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
if (NULL == devices)
{
print_error(errNum, "Unable to allocate memory for devices\n");
return CL_OUT_OF_HOST_MEMORY;
}
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, devices,
NULL);
if (CL_SUCCESS != errNum)
{
print_error(errNum, "Failed to get deviceID.\n");
return errNum;
}
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)
{
log_error("Error in clGetDeviceInfo for getting "
"device_extension size....\n");
return errNum;
}
extensions = (char *)malloc(extensionSize);
if (NULL == extensions)
{
log_error("Unable to allocate memory for extensions\n");
return CL_OUT_OF_HOST_MEMORY;
}
errNum =
clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS,
extensionSize, extensions, NULL /*&extensionSize*/);
if (CL_SUCCESS != errNum)
{
print_error(errNum,
"Error in clGetDeviceInfo for getting "
"device_extension\n");
return errNum;
}
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_UUID_KHR,
CL_UUID_SIZE_KHR, uuid, &extensionSize);
if (CL_SUCCESS != errNum)
{
print_error(errNum, "clGetDeviceInfo failed with error\n ");
return errNum;
}
errNum =
memcmp(uuid, vkDevice.getPhysicalDevice().getUUID(), VK_UUID_SIZE);
if (errNum == 0)
{
break;
}
}
if (device_no >= num_devices)
{
fprintf(stderr,
"OpenCL error: "
"No Vulkan-OpenCL Interop capable GPU found.\n");
}
if (!(is_extension_available(devices[device_no], "cl_khr_external_memory")
&& is_extension_available(devices[device_no],
"cl_khr_external_semaphore")))
{
log_info("Device does not support cl_khr_external_memory "
"or cl_khr_external_semaphore\n");
log_info(" TEST SKIPPED\n");
return CL_SUCCESS;
}
init_cl_vk_ext(platform, num_devices, devices);
// Execute tests.
// Note: don't use the entire harness, because we have a different way of
// obtaining the device (via the context)
test_harness_config config{};
config.forceNoContextCreation = true;
config.numElementsToUse = 1024;
config.queueProps = 0;
errNum = parseAndCallCommandLineTests(argCount, argList, devices[device_no],
test_num, test_list, config);
return errNum;
return runTestHarness(argc, argv, test_num, test_list, false, 0);
}

View File

@@ -44,3 +44,36 @@ extern int test_platform_info(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_device_info(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_buffer_single_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_);
extern int test_buffer_multiple_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_multiImport_sameCtx(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_multiImport_diffCtx(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_single_queue_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_multiple_queue_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_multiImport_sameCtx_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_buffer_multiImport_diffCtx_fence(cl_device_id device_,
cl_context context_,
cl_command_queue queue_,
int numElements_);
extern int test_image_single_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_);
extern int test_image_multiple_queue(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_);

View File

@@ -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.
@@ -33,40 +33,33 @@
#include "harness/typeWrappers.h"
#include "harness/deviceInfo.h"
int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
cl_command_queue _queue, int num_elements)
#include "vulkan_test_base.h"
#include "opencl_vulkan_wrapper.hpp"
namespace {
struct ConsistencyExternalBufferTest : public VulkanTestBase
{
cl_int errNum;
VulkanDevice vkDevice;
// Context and command queue creation
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_command_queue cmd_queue = NULL;
ConsistencyExternalBufferTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error(errNum, "Failed to get platform Id");
contextProperties[1] = (cl_context_properties)platform;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error(errNum, "Unable to create context with properties");
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
test_error(errNum, "Unable to create command queue");
cl_int Run() override
{
cl_int errNum = CL_SUCCESS;
uint32_t bufferSize = 32;
cl_device_id devList[] = { deviceID, NULL };
#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
if (!is_extension_available(device, "cl_khr_external_memory_win32"))
{
throw std::runtime_error("Device does not support "
throw std::runtime_error(
"Device does not support "
"cl_khr_external_memory_win32 extension \n");
}
#else
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
if (!is_extension_available(device, "cl_khr_external_memory_opaque_fd"))
{
throw std::runtime_error(
"Device does not support "
@@ -77,14 +70,15 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
VulkanExternalMemoryHandleType vkExternalMemoryHandleType =
getSupportedVulkanExternalMemoryHandleTypeList()[0];
VulkanBuffer vkDummyBuffer(vkDevice, 4 * 1024, vkExternalMemoryHandleType);
VulkanBuffer vkDummyBuffer(*vkDevice, 4 * 1024,
vkExternalMemoryHandleType);
const VulkanMemoryTypeList& memoryTypeList =
vkDummyBuffer.getMemoryTypeList();
VulkanBufferList vkBufferList(1, vkDevice, bufferSize,
VulkanBufferList vkBufferList(1, *vkDevice, bufferSize,
vkExternalMemoryHandleType);
VulkanDeviceMemory* vkDeviceMem =
new VulkanDeviceMemory(vkDevice, vkBufferList[0], memoryTypeList[0],
VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory(
*vkDevice, vkBufferList[0], memoryTypeList[0],
vkExternalMemoryHandleType);
vkDeviceMem->bindBuffer(vkBufferList[0], 0);
@@ -94,7 +88,7 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
std::vector<cl_mem_properties> extMemProperties{
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR,
(cl_mem_properties)devList[0],
(cl_mem_properties)device,
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR,
};
cl_external_memory_handle_type_khr type;
@@ -104,14 +98,14 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR;
errNum = check_external_memory_handle_type(devList[0], type);
errNum = check_external_memory_handle_type(device, type);
extMemProperties.push_back((cl_mem_properties)type);
extMemProperties.push_back((cl_mem_properties)handle);
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR;
errNum = check_external_memory_handle_type(devList[0], type);
errNum = check_external_memory_handle_type(device, type);
extMemProperties.push_back((cl_mem_properties)type);
extMemProperties.push_back((cl_mem_properties)handle);
break;
@@ -119,7 +113,7 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR;
errNum = check_external_memory_handle_type(devList[0], type);
errNum = check_external_memory_handle_type(device, type);
extMemProperties.push_back((cl_mem_properties)type);
extMemProperties.push_back((cl_mem_properties)fd);
break;
@@ -140,15 +134,15 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
clMemWrapper buffer;
// Passing NULL properties and a valid extMem_desc size
buffer = clCreateBufferWithProperties(context, NULL, 1, bufferSize, NULL,
&errNum);
buffer = clCreateBufferWithProperties(context, NULL, 1, bufferSize,
NULL, &errNum);
test_error(errNum, "Unable to create buffer with NULL properties");
buffer.reset();
// Passing valid extMemProperties and buffersize
buffer = clCreateBufferWithProperties(context, extMemProperties.data(), 1,
bufferSize, NULL, &errNum);
buffer = clCreateBufferWithProperties(context, extMemProperties.data(),
1, bufferSize, NULL, &errNum);
test_error(errNum, "Unable to create buffer with Properties");
buffer.reset();
@@ -163,12 +157,12 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
(cl_mem_properties)-64, // Passing random invalid fd
#endif
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR,
(cl_mem_properties)devList[0],
(cl_mem_properties)device,
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR,
0
};
buffer = clCreateBufferWithProperties(context, extMemProperties2.data(), 1,
bufferSize, NULL, &errNum);
buffer = clCreateBufferWithProperties(context, extMemProperties2.data(),
1, bufferSize, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_VALUE,
"Should return CL_INVALID_VALUE ");
@@ -176,50 +170,38 @@ int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
// Passing extMem_desc size = 0 but valid memProperties, CL_INVALID_SIZE
// should be returned.
buffer = clCreateBufferWithProperties(context, extMemProperties.data(), 1,
0, NULL, &errNum);
buffer = clCreateBufferWithProperties(context, extMemProperties.data(),
1, 0, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_BUFFER_SIZE,
"Should return CL_INVALID_BUFFER_SIZE");
return TEST_PASS;
}
};
int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
cl_command_queue _queue, int num_elements)
struct ConsistencyExternalImageTest : public VulkanTestBase
{
cl_int errNum;
VulkanDevice vkDevice;
ConsistencyExternalImageTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
// Context and command queue creation
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_command_queue cmd_queue = NULL;
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error(errNum, "Failed to get platform id");
contextProperties[1] = (cl_context_properties)platform;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error(errNum, "Unable to create context with properties");
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
test_error(errNum, "Unable to create command queue");
cl_device_id devList[] = { deviceID, NULL };
cl_int Run() override
{
cl_int errNum = CL_SUCCESS;
#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
if (!is_extension_available(device, "cl_khr_external_memory_win32"))
{
throw std::runtime_error("Device does not support"
throw std::runtime_error(
"Device does not support"
"cl_khr_external_memory_win32 extension \n");
}
#else
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
if (!is_extension_available(device, "cl_khr_external_memory_opaque_fd"))
{
test_fail("Device does not support cl_khr_external_memory_opaque_fd "
test_fail(
"Device does not support cl_khr_external_memory_opaque_fd "
"extension \n");
}
#endif
@@ -234,30 +216,32 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
VulkanImageTiling vulkanImageTiling =
vkClExternalMemoryHandleTilingAssumption(
deviceID, vkExternalMemoryHandleType, &errNum);
device, vkExternalMemoryHandleType, &errNum);
ASSERT_SUCCESS(errNum, "Failed to query OpenCL tiling mode");
VulkanImage2D vkImage2D =
VulkanImage2D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height,
VulkanImage2D vkImage2D = VulkanImage2D(
*vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height,
vulkanImageTiling, 1, vkExternalMemoryHandleType);
const VulkanMemoryTypeList& memoryTypeList = vkImage2D.getMemoryTypeList();
const VulkanMemoryTypeList& memoryTypeList =
vkImage2D.getMemoryTypeList();
uint64_t totalImageMemSize = vkImage2D.getSize();
log_info("Memory type index: %lu\n", (uint32_t)memoryTypeList[0]);
log_info("Memory type index: %u\n", (uint32_t)memoryTypeList[0]);
log_info("Memory type property: %d\n",
memoryTypeList[0].getMemoryTypeProperty());
log_info("Image size : %d\n", totalImageMemSize);
log_info("Image size : %ld\n", totalImageMemSize);
VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory(
vkDevice, vkImage2D, memoryTypeList[0], vkExternalMemoryHandleType);
VulkanDeviceMemory* vkDeviceMem =
new VulkanDeviceMemory(*vkDevice, vkImage2D, memoryTypeList[0],
vkExternalMemoryHandleType);
vkDeviceMem->bindImage(vkImage2D, 0);
void* handle = NULL;
int fd;
std::vector<cl_mem_properties> extMemProperties{
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR,
(cl_mem_properties)devList[0],
(cl_mem_properties)device,
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR,
};
switch (vkExternalMemoryHandleType)
@@ -266,15 +250,16 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back((cl_mem_properties)handle);
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
extMemProperties.push_back(
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
@@ -284,7 +269,7 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back((cl_mem_properties)fd);
@@ -306,8 +291,9 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
const VkImageCreateInfo VulkanImageCreateInfo =
vkImage2D.getVkImageCreateInfo();
errNum = getCLImageInfoFromVkImageInfo(
&VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc);
errNum = getCLImageInfoFromVkImageInfo(&VulkanImageCreateInfo,
totalImageMemSize, &img_format,
&image_desc);
if (errNum != CL_SUCCESS)
{
log_error("getCLImageInfoFromVkImageInfo failed!!!");
@@ -325,8 +311,8 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
// Passing image_format as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, NULL, &image_desc,
NULL, &errNum);
CL_MEM_READ_WRITE, NULL,
&image_desc, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"
@@ -336,8 +322,8 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
// Passing image_desc as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, &img_format, NULL,
NULL, &errNum);
CL_MEM_READ_WRITE, &img_format,
NULL, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_DESCRIPTOR "
@@ -346,37 +332,39 @@ int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
return TEST_PASS;
}
};
int test_consistency_external_semaphore(cl_device_id deviceID,
cl_context _context,
cl_command_queue _queue,
int num_elements)
struct ConsistencyExternalSemaphoreTest : public VulkanTestBase
{
cl_int errNum;
VulkanDevice vkDevice;
// Context and command queue creation
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_command_queue cmd_queue = NULL;
ConsistencyExternalSemaphoreTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error(errNum, "Failed to get platform Id");
cl_int Run() override
{
cl_int errNum = CL_SUCCESS;
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
#ifdef _WIN32
if (!is_extension_available(device, "cl_khr_external_memory_win32"))
{
throw std::runtime_error(
"Device does not support"
"cl_khr_external_memory_win32 extension \n");
}
#else
if (!is_extension_available(device, "cl_khr_external_memory_opaque_fd"))
{
test_fail(
"Device does not support cl_khr_external_memory_opaque_fd "
"extension \n");
}
#endif
contextProperties[1] = (cl_context_properties)platform;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error(errNum, "Unable to create context with properties");
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
test_error(errNum, "Unable to create command queue");
cl_device_id devList[] = { deviceID, NULL };
std::vector<VulkanExternalSemaphoreHandleType> supportedExternalSemaphores =
getSupportedInteropExternalSemaphoreHandleTypes(devList[0], vkDevice);
std::vector<VulkanExternalSemaphoreHandleType>
supportedExternalSemaphores =
getSupportedInteropExternalSemaphoreHandleTypes(device,
*vkDevice);
if (supportedExternalSemaphores.empty())
{
@@ -386,8 +374,8 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
for (VulkanExternalSemaphoreHandleType semaphoreHandleType :
supportedExternalSemaphores)
{
VulkanSemaphore vkVk2Clsemaphore(vkDevice, semaphoreHandleType);
VulkanSemaphore vkCl2Vksemaphore(vkDevice, semaphoreHandleType);
VulkanSemaphore vkVk2Clsemaphore(*vkDevice, semaphoreHandleType);
VulkanSemaphore vkCl2Vksemaphore(*vkDevice, semaphoreHandleType);
cl_semaphore_khr clCl2Vksemaphore;
cl_semaphore_khr clVk2Clsemaphore;
void* handle1 = NULL;
@@ -405,25 +393,28 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
{
#ifdef _WIN32
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
log_info(" Opaque NT handles are only supported on Windows\n");
log_info(
" Opaque NT handles are only supported on Windows\n");
handle1 = vkVk2Clsemaphore.getHandle(semaphoreHandleType);
handle2 = vkCl2Vksemaphore.getHandle(semaphoreHandleType);
errNum = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)
device, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props1.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)handle1);
sema_props2.push_back((cl_semaphore_properties_khr)
sema_props2.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props2.push_back((cl_semaphore_properties_khr)handle2);
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
log_info(
" Opaque D3DKMT handles are only supported on Windows\n");
log_info(" Opaque D3DKMT handles are only supported on "
"Windows\n");
handle1 = vkVk2Clsemaphore.getHandle(semaphoreHandleType);
handle2 = vkCl2Vksemaphore.getHandle(semaphoreHandleType);
errNum = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
device, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
sema_props1.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
@@ -438,11 +429,13 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
fd1 = (int)vkVk2Clsemaphore.getHandle(semaphoreHandleType);
fd2 = (int)vkCl2Vksemaphore.getHandle(semaphoreHandleType);
errNum = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)
device, CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props1.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)fd1);
sema_props2.push_back((cl_semaphore_properties_khr)
sema_props2.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props2.push_back((cl_semaphore_properties_khr)fd2);
break;
@@ -450,7 +443,7 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
fd1 = -1;
fd2 = -1;
errNum = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_SYNC_FD_KHR);
device, CL_SEMAPHORE_HANDLE_SYNC_FD_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)fd1);
@@ -459,68 +452,70 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
sema_props2.push_back((cl_semaphore_properties_khr)fd2);
break;
#endif
default: log_error("Unsupported external memory handle type\n"); break;
default:
log_error("Unsupported external memory handle type\n");
break;
}
if (CL_SUCCESS != errNum)
{
throw std::runtime_error(
"Unsupported external sempahore handle type\n ");
}
sema_props1.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)devList[0]);
sema_props1.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR);
sema_props2.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR);
sema_props2.push_back((cl_semaphore_properties_khr)devList[0]);
sema_props2.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR);
sema_props1.push_back((cl_semaphore_properties_khr)device);
sema_props1.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR);
sema_props2.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR);
sema_props2.push_back((cl_semaphore_properties_khr)device);
sema_props2.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR);
sema_props1.push_back(0);
sema_props2.push_back(0);
// Pass NULL properties
cl_semaphore_khr cl_ext_semaphore =
clCreateSemaphoreWithPropertiesKHRptr(context, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_VALUE,
test_failure_error(
errNum, CL_INVALID_VALUE,
"Semaphore creation must fail with CL_INVALID_VALUE "
" when properties are passed as NULL");
// Pass invalid semaphore object to wait
errNum =
clEnqueueWaitSemaphoresKHRptr(cmd_queue, 1, NULL, NULL, 0, NULL, NULL);
test_failure_error(errNum, CL_INVALID_VALUE,
errNum = clEnqueueWaitSemaphoresKHRptr(queue, 1, NULL, NULL, 0,
NULL, NULL);
test_failure_error(
errNum, CL_INVALID_VALUE,
"clEnqueueWaitSemaphoresKHR fails with CL_INVALID_VALUE "
"when invalid semaphore object is passed");
// Pass invalid semaphore object to signal
errNum = clEnqueueSignalSemaphoresKHRptr(cmd_queue, 1, NULL, NULL, 0, NULL,
NULL);
errNum = clEnqueueSignalSemaphoresKHRptr(queue, 1, NULL, NULL, 0,
NULL, NULL);
test_failure_error(
errNum, CL_INVALID_VALUE,
"clEnqueueSignalSemaphoresKHR fails with CL_INVALID_VALUE"
"when invalid semaphore object is passed");
// Create two semaphore objects
clVk2Clsemaphore = clCreateSemaphoreWithPropertiesKHRptr(
context, sema_props1.data(), &errNum);
test_error(errNum,
test_error(
errNum,
"Unable to create semaphore with valid semaphore properties");
clCl2Vksemaphore = clCreateSemaphoreWithPropertiesKHRptr(
context, sema_props2.data(), &errNum);
test_error(errNum,
test_error(
errNum,
"Unable to create semaphore with valid semaphore properties");
// Pass invalid object to release call
errNum = clReleaseSemaphoreKHRptr(NULL);
test_failure_error(
errNum, CL_INVALID_SEMAPHORE_KHR,
test_failure_error(errNum, CL_INVALID_SEMAPHORE_KHR,
"clReleaseSemaphoreKHRptr fails with "
"CL_INVALID_SEMAPHORE_KHR when NULL semaphore object is passed");
"CL_INVALID_SEMAPHORE_KHR when NULL semaphore "
"object is passed");
// Release both semaphore objects
errNum = clReleaseSemaphoreKHRptr(clVk2Clsemaphore);
@@ -532,3 +527,31 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
return TEST_PASS;
}
};
} // anonymous namespace
int test_consistency_external_buffer(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
return MakeAndRunTest<ConsistencyExternalBufferTest>(
deviceID, context, defaultQueue, num_elements);
}
int test_consistency_external_image(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
return MakeAndRunTest<ConsistencyExternalImageTest>(
deviceID, context, defaultQueue, num_elements);
}
int test_consistency_external_semaphore(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
return MakeAndRunTest<ConsistencyExternalSemaphoreTest>(
deviceID, context, defaultQueue, num_elements);
}

View File

@@ -1,3 +1,19 @@
//
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <vulkan_interop_common.hpp>
#include <opencl_vulkan_wrapper.hpp>
#include <vulkan_wrapper.hpp>
@@ -17,42 +33,31 @@
#include "harness/typeWrappers.h"
#include "harness/deviceInfo.h"
int test_consistency_external_for_1dimage(cl_device_id deviceID,
cl_context _context,
cl_command_queue _queue,
int num_elements)
#include "vulkan_test_base.h"
#include "opencl_vulkan_wrapper.hpp"
namespace {
struct ConsistencyExternalImage1DTest : public VulkanTestBase
{
cl_int errNum;
VulkanDevice vkDevice;
ConsistencyExternalImage1DTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
// Context and command queue creation
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_command_queue cmd_queue = NULL;
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error(errNum, "Failed to get platform id");
contextProperties[1] = (cl_context_properties)platform;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error(errNum, "Unable to create context with properties");
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
test_error(errNum, "Unable to create command queue");
cl_device_id devList[] = { deviceID, NULL };
cl_int Run() override
{
cl_int errNum = CL_SUCCESS;
#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
if (!is_extension_available(device, "cl_khr_external_memory_win32"))
{
throw std::runtime_error("Device does not support"
throw std::runtime_error(
"Device does not support"
"cl_khr_external_memory_win32 extension \n");
}
#else
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
if (!is_extension_available(device, "cl_khr_external_memory_opaque_fd"))
{
throw std::runtime_error(
"Device does not support cl_khr_external_memory_opaque_fd "
@@ -69,14 +74,15 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
VulkanImageTiling vulkanImageTiling =
vkClExternalMemoryHandleTilingAssumption(
deviceID, vkExternalMemoryHandleType, &errNum);
device, vkExternalMemoryHandleType, &errNum);
ASSERT_SUCCESS(errNum, "Failed to query OpenCL tiling mode");
VulkanImage1D vkImage1D =
VulkanImage1D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width,
VulkanImage1D(*vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width,
vulkanImageTiling, 1, vkExternalMemoryHandleType);
const VulkanMemoryTypeList& memoryTypeList = vkImage1D.getMemoryTypeList();
const VulkanMemoryTypeList& memoryTypeList =
vkImage1D.getMemoryTypeList();
uint64_t totalImageMemSize = vkImage1D.getSize();
log_info("Memory type index: %u\n", (uint32_t)memoryTypeList[0]);
@@ -84,15 +90,16 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
memoryTypeList[0].getMemoryTypeProperty());
log_info("Image size : %lu\n", totalImageMemSize);
VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory(
vkDevice, vkImage1D, memoryTypeList[0], vkExternalMemoryHandleType);
VulkanDeviceMemory* vkDeviceMem =
new VulkanDeviceMemory(*vkDevice, vkImage1D, memoryTypeList[0],
vkExternalMemoryHandleType);
vkDeviceMem->bindImage(vkImage1D, 0);
void* handle = NULL;
int fd;
std::vector<cl_mem_properties> extMemProperties{
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR,
(cl_mem_properties)devList[0],
(cl_mem_properties)device,
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR,
};
switch (vkExternalMemoryHandleType)
@@ -101,15 +108,16 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back((cl_mem_properties)handle);
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
extMemProperties.push_back(
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
@@ -119,7 +127,7 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back((cl_mem_properties)fd);
@@ -141,8 +149,9 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
const VkImageCreateInfo VulkanImageCreateInfo =
vkImage1D.getVkImageCreateInfo();
errNum = getCLImageInfoFromVkImageInfo(
&VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc);
errNum = getCLImageInfoFromVkImageInfo(&VulkanImageCreateInfo,
totalImageMemSize, &img_format,
&image_desc);
if (errNum != CL_SUCCESS)
{
log_error("getCLImageInfoFromVkImageInfo failed!!!");
@@ -159,9 +168,9 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
image.reset();
// Passing NULL properties and a valid image_format and image_desc
image =
clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE,
&img_format, &image_desc, NULL, &errNum);
image = clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE,
&img_format, &image_desc, NULL,
&errNum);
test_error(errNum,
"Unable to create image with NULL properties "
"with valid image format and image desc");
@@ -170,8 +179,8 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
// Passing image_format as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, NULL, &image_desc,
NULL, &errNum);
CL_MEM_READ_WRITE, NULL,
&image_desc, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"
@@ -181,16 +190,24 @@ int test_consistency_external_for_1dimage(cl_device_id deviceID,
// Passing image_desc as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, &img_format, NULL,
NULL, &errNum);
CL_MEM_READ_WRITE, &img_format,
NULL, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_DESCRIPTOR "
"when image desc passed as NULL");
image.reset();
if (cmd_queue) clReleaseCommandQueue(cmd_queue);
if (context) clReleaseContext(context);
return TEST_PASS;
}
};
}
int test_consistency_external_for_1dimage(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
return MakeAndRunTest<ConsistencyExternalImage1DTest>(
deviceID, context, defaultQueue, num_elements);
}

View File

@@ -1,3 +1,19 @@
//
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <vulkan_interop_common.hpp>
#include <opencl_vulkan_wrapper.hpp>
#include <vulkan_wrapper.hpp>
@@ -18,43 +34,31 @@
#include "harness/deviceInfo.h"
#include <string>
#include "vulkan_test_base.h"
#include "opencl_vulkan_wrapper.hpp"
int test_consistency_external_for_3dimage(cl_device_id deviceID,
cl_context _context,
cl_command_queue _queue,
int num_elements)
namespace {
struct ConsistencyExternalImage3DTest : public VulkanTestBase
{
ConsistencyExternalImage3DTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
cl_int Run() override
{
cl_int errNum;
VulkanDevice vkDevice;
// Context and command queue creation
cl_platform_id platform = NULL;
cl_context context = NULL;
cl_command_queue cmd_queue = NULL;
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error(errNum, "Failed to get platform id");
contextProperties[1] = (cl_context_properties)platform;
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error(errNum, "Unable to create context with properties");
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
test_error(errNum, "Unable to create command queue");
cl_device_id devList[] = { deviceID, NULL };
#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
if (!is_extension_available(device, "cl_khr_external_memory_win32"))
{
throw std::runtime_error("Device does not support"
throw std::runtime_error(
"Device does not support"
"cl_khr_external_memory_win32 extension \n");
}
#else
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
if (!is_extension_available(device, "cl_khr_external_memory_opaque_fd"))
{
throw std::runtime_error(
"Device does not support cl_khr_external_memory_opaque_fd "
@@ -73,14 +77,15 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
VulkanImageTiling vulkanImageTiling =
vkClExternalMemoryHandleTilingAssumption(
deviceID, vkExternalMemoryHandleType, &errNum);
device, vkExternalMemoryHandleType, &errNum);
ASSERT_SUCCESS(errNum, "Failed to query OpenCL tiling mode");
VulkanImage3D vkImage3D =
VulkanImage3D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height,
depth, vulkanImageTiling, 1, vkExternalMemoryHandleType);
VulkanImage3D vkImage3D = VulkanImage3D(
*vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height, depth,
vulkanImageTiling, 1, vkExternalMemoryHandleType);
const VulkanMemoryTypeList& memoryTypeList = vkImage3D.getMemoryTypeList();
const VulkanMemoryTypeList& memoryTypeList =
vkImage3D.getMemoryTypeList();
uint64_t totalImageMemSize = vkImage3D.getSize();
log_info("Memory type index: %u\n", (uint32_t)memoryTypeList[0]);
@@ -88,15 +93,16 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
memoryTypeList[0].getMemoryTypeProperty());
log_info("Image size : %lu\n", totalImageMemSize);
VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory(
vkDevice, vkImage3D, memoryTypeList[0], vkExternalMemoryHandleType);
VulkanDeviceMemory* vkDeviceMem =
new VulkanDeviceMemory(*vkDevice, vkImage3D, memoryTypeList[0],
vkExternalMemoryHandleType);
vkDeviceMem->bindImage(vkImage3D, 0);
void* handle = NULL;
int fd;
std::vector<cl_mem_properties> extMemProperties{
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR,
(cl_mem_properties)devList[0],
(cl_mem_properties)device,
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR,
};
switch (vkExternalMemoryHandleType)
@@ -105,15 +111,16 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties.push_back((cl_mem_properties)handle);
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
extMemProperties.push_back(
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
@@ -123,7 +130,7 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
errNum = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
device, CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back((cl_mem_properties)fd);
@@ -145,8 +152,9 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
const VkImageCreateInfo VulkanImageCreateInfo =
vkImage3D.getVkImageCreateInfo();
errNum = getCLImageInfoFromVkImageInfo(
&VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc);
errNum = getCLImageInfoFromVkImageInfo(&VulkanImageCreateInfo,
totalImageMemSize, &img_format,
&image_desc);
if (errNum != CL_SUCCESS)
{
log_error("getCLImageInfoFromVkImageInfo failed!!!");
@@ -163,9 +171,9 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
image.reset();
// Passing NULL properties and a valid image_format and image_desc
image =
clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE,
&img_format, &image_desc, NULL, &errNum);
image = clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE,
&img_format, &image_desc, NULL,
&errNum);
test_error(errNum,
"Unable to create image with NULL properties "
"with valid image format and image desc");
@@ -174,8 +182,8 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
// Passing image_format as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, NULL, &image_desc,
NULL, &errNum);
CL_MEM_READ_WRITE, NULL,
&image_desc, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"
@@ -185,16 +193,25 @@ int test_consistency_external_for_3dimage(cl_device_id deviceID,
// Passing image_desc as NULL
image = clCreateImageWithProperties(context, extMemProperties.data(),
CL_MEM_READ_WRITE, &img_format, NULL,
NULL, &errNum);
CL_MEM_READ_WRITE, &img_format,
NULL, NULL, &errNum);
test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR,
"Image creation must fail with "
"CL_INVALID_IMAGE_DESCRIPTOR "
"when image desc passed as NULL");
image.reset();
if (cmd_queue) clReleaseCommandQueue(cmd_queue);
if (context) clReleaseContext(context);
return TEST_PASS;
}
};
} // anonymous namespace
int test_consistency_external_for_3dimage(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
return MakeAndRunTest<ConsistencyExternalImage3DTest>(
deviceID, context, defaultQueue, num_elements);
}

View File

@@ -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.
@@ -24,22 +24,25 @@
#include <string.h>
#include "harness/errorHelpers.h"
#include "harness/os_helpers.h"
#include "deviceInfo.h"
#include "vulkan_test_base.h"
#include "opencl_vulkan_wrapper.hpp"
#define MAX_BUFFERS 5
#define MAX_IMPORTS 5
#define BUFFERSIZE 3000
static cl_uchar uuid[CL_UUID_SIZE_KHR];
static cl_device_id deviceId = NULL;
namespace {
cl_uchar uuid[CL_UUID_SIZE_KHR];
cl_device_id deviceId = nullptr;
struct Params
{
uint32_t numBuffers;
uint32_t bufferSize;
uint32_t interBufferOffset;
};
}
const char *kernel_text_numbuffer_1 = " \
__kernel void clUpdateBuffer(int bufferSize, __global unsigned char *a) { \n\
@@ -81,6 +84,7 @@ __kernel void checkKernel(__global unsigned char *ptr, int size, int expVal, __g
} \n\
}";
int run_test_with_two_queue(
cl_context &context, cl_command_queue &cmd_queue1,
cl_command_queue &cmd_queue2, cl_kernel *kernel, cl_kernel &verify_kernel,
@@ -114,7 +118,8 @@ int run_test_with_two_queue(
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
std::shared_ptr<VulkanFence> fence = nullptr;
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue =
vkDevice.getQueue(getVulkanQueueFamily(vkDevice.getPhysicalDevice()));
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());
@@ -150,6 +155,7 @@ int run_test_with_two_queue(
}
const uint32_t maxIter = innerIterations;
VulkanCommandPool vkCommandPool(vkDevice);
VulkanCommandBuffer vkCommandBuffer(vkDevice, vkCommandPool);
@@ -446,7 +452,8 @@ int run_test_with_one_queue(
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
std::shared_ptr<VulkanFence> fence = nullptr;
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue =
vkDevice.getQueue(getVulkanQueueFamily(vkDevice.getPhysicalDevice()));
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());
@@ -482,6 +489,7 @@ int run_test_with_one_queue(
}
const uint32_t maxIter = innerIterations;
VulkanCommandPool vkCommandPool(vkDevice);
VulkanCommandBuffer vkCommandBuffer(vkDevice, vkCommandPool);
@@ -749,7 +757,7 @@ int run_test_with_multi_import_same_ctx(
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
std::shared_ptr<VulkanFence> fence = nullptr;
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue = vkDevice.getQueue(getVulkanQueueFamily());
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());
@@ -833,10 +841,10 @@ int run_test_with_multi_import_same_ctx(
std::vector<clExternalMemory *> pExternalMemory;
for (size_t cl_bIdx = 0; cl_bIdx < numImports; cl_bIdx++)
{
pExternalMemory.push_back(new clExternalMemory(
vkBufferListDeviceMemory[bIdx],
vkExternalMemoryHandleType, bufferSize, context,
deviceId));
pExternalMemory.push_back(
new clExternalMemory(vkBufferListDeviceMemory[bIdx],
vkExternalMemoryHandleType,
bufferSize, context, deviceId));
}
externalMemory.push_back(pExternalMemory);
}
@@ -851,12 +859,11 @@ int run_test_with_multi_import_same_ctx(
for (size_t bIdx = 0; bIdx < vkBufferList.size(); bIdx++)
{
size_t buffer_size = vkBufferList[bIdx].getSize();
vkBufferListDeviceMemory[bIdx]->bindBuffer(
vkBufferList[bIdx], 0);
vkBufferListDeviceMemory[bIdx]->bindBuffer(vkBufferList[bIdx],
0);
for (size_t cl_bIdx = 0; cl_bIdx < numImports; cl_bIdx++)
{
buffers[bIdx][cl_bIdx] =
externalMemory[bIdx][cl_bIdx]
buffers[bIdx][cl_bIdx] = externalMemory[bIdx][cl_bIdx]
->getExternalMemoryBuffer();
}
}
@@ -903,25 +910,24 @@ int run_test_with_multi_import_same_ctx(
else
{
err = clVk2CLExternalSemaphore->wait(cmd_queue1);
test_error_and_cleanup(
err, CLEANUP,
"Error: failed to wait on CL external semaphore\n");
test_error_and_cleanup(err, CLEANUP,
"Error: failed to wait on "
"CL external semaphore\n");
}
for (uint8_t launchIter = 0; launchIter < numImports;
launchIter++)
{
err = clSetKernelArg(update_buffer_kernel, 0,
sizeof(uint32_t),
(void *)&bufferSize);
sizeof(uint32_t), (void *)&bufferSize);
for (int i = 0; i < numBuffers; i++)
{
err |= clSetKernelArg(
update_buffer_kernel, i + 1, sizeof(cl_mem),
(void *)&(buffers[i][launchIter]));
err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers[i][launchIter], 0,
nullptr, nullptr);
cmd_queue1, 1, &buffers[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");
}
@@ -933,16 +939,15 @@ int run_test_with_multi_import_same_ctx(
err = clEnqueueNDRangeKernel(
cmd_queue1, update_buffer_kernel, 1, NULL,
global_work_size, NULL, 0, NULL, NULL);
test_error_and_cleanup(
err, CLEANUP,
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to launch "
"update_buffer_kernel, error\n ");
for (int i = 0; i < numBuffers; i++)
{
err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers[i][launchIter], 0,
nullptr, nullptr);
cmd_queue1, 1, &buffers[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");
}
@@ -954,8 +959,8 @@ int run_test_with_multi_import_same_ctx(
else if (!use_fence && iter != (maxIter - 1))
{
err = clCl2VkExternalSemaphore->signal(cmd_queue1);
test_error_and_cleanup(
err, CLEANUP, "Failed to signal CL semaphore\n");
test_error_and_cleanup(err, CLEANUP,
"Failed to signal CL semaphore\n");
}
}
@@ -968,12 +973,10 @@ int run_test_with_multi_import_same_ctx(
error_1 = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
sizeof(uint8_t), NULL, &err);
test_error_and_cleanup(err, CLEANUP,
"Error: clCreateBuffer \n");
test_error_and_cleanup(err, CLEANUP, "Error: clCreateBuffer \n");
uint8_t val = 0;
err =
clEnqueueWriteBuffer(cmd_queue1, error_1, CL_TRUE, 0,
err = clEnqueueWriteBuffer(cmd_queue1, error_1, CL_TRUE, 0,
sizeof(uint8_t), &val, 0, NULL, NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: clEnqueueWriteBuffer \n");
@@ -984,20 +987,19 @@ int run_test_with_multi_import_same_ctx(
{
err = clSetKernelArg(verify_kernel, 0, sizeof(cl_mem),
(void *)&(buffers[i][0]));
err |= clSetKernelArg(verify_kernel, 1, sizeof(int),
&bufferSize);
err |=
clSetKernelArg(verify_kernel, 1, sizeof(int), &bufferSize);
err |= clSetKernelArg(verify_kernel, 2, sizeof(int),
&calc_max_iter);
err |= clSetKernelArg(verify_kernel, 3, sizeof(cl_mem),
(void *)&error_1);
test_error_and_cleanup(
err, CLEANUP,
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to set arg values for "
"verify_kernel \n");
err = clEnqueueNDRangeKernel(cmd_queue1, verify_kernel, 1,
NULL, global_work_size, NULL,
0, NULL, NULL);
err = clEnqueueNDRangeKernel(cmd_queue1, verify_kernel, 1, NULL,
global_work_size, NULL, 0, NULL,
NULL);
test_error_and_cleanup(
err, CLEANUP,
"Error: Failed to launch verify_kernel, error\n");
@@ -1005,14 +1007,13 @@ int run_test_with_multi_import_same_ctx(
err = clEnqueueReadBuffer(cmd_queue1, error_1, CL_TRUE, 0,
sizeof(uint8_t), error_2, 0, NULL,
NULL);
test_error_and_cleanup(
err, CLEANUP, "Error: Failed read output, error \n");
test_error_and_cleanup(err, CLEANUP,
"Error: Failed read output, error \n");
if (*error_2 == 1)
{
test_fail_and_cleanup(
err, CLEANUP,
" vulkan_opencl_buffer test FAILED\n");
err, CLEANUP, " vulkan_opencl_buffer test FAILED\n");
}
}
for (size_t i = 0; i < vkBufferList.size(); i++)
@@ -1031,8 +1032,7 @@ int run_test_with_multi_import_same_ctx(
for (size_t i = 0; i < externalMemory.size(); i++)
{
externalMemory[i].erase(externalMemory[i].begin(),
externalMemory[i].begin()
+ numBuffers);
externalMemory[i].begin() + numBuffers);
}
externalMemory.clear();
}
@@ -1097,7 +1097,7 @@ int run_test_with_multi_import_diff_ctx(
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
std::shared_ptr<VulkanFence> fence = nullptr;
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue = vkDevice.getQueue(getVulkanQueueFamily());
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());
@@ -1273,9 +1273,9 @@ int run_test_with_multi_import_diff_ctx(
else
{
err = clVk2CLExternalSemaphore->wait(cmd_queue1);
test_error_and_cleanup(
err, CLEANUP,
"Error: failed to wait on CL external semaphore\n");
test_error_and_cleanup(err, CLEANUP,
"Error: failed to wait on "
"CL external semaphore\n");
}
for (uint8_t launchIter = 0; launchIter < numImports;
@@ -1361,17 +1361,16 @@ int run_test_with_multi_import_diff_ctx(
else
{
err = clVk2CLExternalSemaphore2->wait(cmd_queue2);
test_error_and_cleanup(
err, CLEANUP,
"Error: failed to wait on CL external semaphore\n");
test_error_and_cleanup(err, CLEANUP,
"Error: failed to wait on "
"CL external semaphore\n");
}
for (uint8_t launchIter = 0; launchIter < numImports;
launchIter++)
{
err = clSetKernelArg(update_buffer_kernel2[launchIter],
0, sizeof(uint32_t),
(void *)&bufferSize);
err = clSetKernelArg(update_buffer_kernel2[launchIter], 0,
sizeof(uint32_t), (void *)&bufferSize);
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");
@@ -1379,14 +1378,13 @@ int run_test_with_multi_import_diff_ctx(
{
err = clSetKernelArg(
update_buffer_kernel2[launchIter], i + 1,
sizeof(cl_mem),
(void *)&(buffers2[i][launchIter]));
sizeof(cl_mem), (void *)&(buffers2[i][launchIter]));
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");
err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue2, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr);
cmd_queue2, 1, &buffers2[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");
}
@@ -1396,17 +1394,16 @@ int run_test_with_multi_import_diff_ctx(
"kernel\n ");
err = clEnqueueNDRangeKernel(
cmd_queue2, update_buffer_kernel2[launchIter], 1,
NULL, global_work_size, NULL, 0, NULL, NULL);
test_error_and_cleanup(
err, CLEANUP,
cmd_queue2, update_buffer_kernel2[launchIter], 1, NULL,
global_work_size, NULL, 0, NULL, NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to launch "
"update_buffer_kernel, error\n ");
for (int i = 0; i < numBuffers; i++)
{
err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue2, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr);
cmd_queue2, 1, &buffers2[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");
}
@@ -1418,8 +1415,8 @@ int run_test_with_multi_import_diff_ctx(
else if (!use_fence && iter != (maxIter - 1))
{
err = clCl2VkExternalSemaphore2->signal(cmd_queue2);
test_error_and_cleanup(
err, CLEANUP, "Failed to signal CL semaphore\n");
test_error_and_cleanup(err, CLEANUP,
"Failed to signal CL semaphore\n");
}
}
clFinish(cmd_queue2);
@@ -1432,23 +1429,19 @@ int run_test_with_multi_import_diff_ctx(
error_1 = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
sizeof(uint8_t), NULL, &err);
test_error_and_cleanup(err, CLEANUP,
"Error: clCreateBuffer \n");
test_error_and_cleanup(err, CLEANUP, "Error: clCreateBuffer \n");
error_2 = clCreateBuffer(context2, CL_MEM_WRITE_ONLY,
sizeof(uint8_t), NULL, &err);
test_error_and_cleanup(err, CLEANUP,
"Error: clCreateBuffer \n");
test_error_and_cleanup(err, CLEANUP, "Error: clCreateBuffer \n");
uint8_t val = 0;
err =
clEnqueueWriteBuffer(cmd_queue1, error_1, CL_TRUE, 0,
err = clEnqueueWriteBuffer(cmd_queue1, error_1, CL_TRUE, 0,
sizeof(uint8_t), &val, 0, NULL, NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed read output, error \n");
err =
clEnqueueWriteBuffer(cmd_queue2, error_2, CL_TRUE, 0,
err = clEnqueueWriteBuffer(cmd_queue2, error_2, CL_TRUE, 0,
sizeof(uint8_t), &val, 0, NULL, NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed read output, error \n");
@@ -1458,30 +1451,28 @@ int run_test_with_multi_import_diff_ctx(
{
err = clSetKernelArg(verify_kernel, 0, sizeof(cl_mem),
(void *)&(buffers1[i][0]));
err |= clSetKernelArg(verify_kernel, 1, sizeof(int),
&pBufferSize);
err |=
clSetKernelArg(verify_kernel, 1, sizeof(int), &pBufferSize);
err |= clSetKernelArg(verify_kernel, 2, sizeof(int),
&calc_max_iter);
err |= clSetKernelArg(verify_kernel, 3, sizeof(cl_mem),
(void *)&error_1);
test_error_and_cleanup(
err, CLEANUP,
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to set arg values for "
"verify_kernel \n");
err = clEnqueueNDRangeKernel(cmd_queue1, verify_kernel, 1,
NULL, global_work_size, NULL,
0, NULL, NULL);
test_error_and_cleanup(
err, CLEANUP,
err = clEnqueueNDRangeKernel(cmd_queue1, verify_kernel, 1, NULL,
global_work_size, NULL, 0, NULL,
NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to launch verify_kernel,"
"error\n");
err = clEnqueueReadBuffer(cmd_queue1, error_1, CL_TRUE, 0,
sizeof(uint8_t), error_3, 0, NULL,
NULL);
test_error_and_cleanup(
err, CLEANUP, "Error: Failed read output, error\n");
test_error_and_cleanup(err, CLEANUP,
"Error: Failed read output, error\n");
if (*error_3 == 1)
{
@@ -1501,24 +1492,22 @@ int run_test_with_multi_import_diff_ctx(
&calc_max_iter);
err |= clSetKernelArg(verify_kernel2, 3, sizeof(cl_mem),
(void *)&error_2);
test_error_and_cleanup(
err, CLEANUP,
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to set arg values for "
"verify_kernel \n");
err = clEnqueueNDRangeKernel(cmd_queue2, verify_kernel2, 1,
NULL, global_work_size, NULL,
0, NULL, NULL);
test_error_and_cleanup(
err, CLEANUP,
NULL, global_work_size, NULL, 0,
NULL, NULL);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to launch verify_kernel,"
"error\n");
err = clEnqueueReadBuffer(cmd_queue2, error_2, CL_TRUE, 0,
sizeof(uint8_t), error_3, 0, NULL,
NULL);
test_error_and_cleanup(
err, CLEANUP, "Error: Failed read output, error\n");
test_error_and_cleanup(err, CLEANUP,
"Error: Failed read output, error\n");
if (*error_3 == 1)
{
@@ -1597,80 +1586,52 @@ CLEANUP:
return err;
}
int test_buffer_common(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_,
bool use_fence)
{
struct BufferTestBase : public VulkanTestBase
{
BufferTestBase(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
int test_buffer_common(bool use_fence)
{
int current_device = 0;
int device_count = 0;
int devices_prohibited = 0;
cl_int errNum = CL_SUCCESS;
cl_platform_id platform = NULL;
size_t extensionSize = 0;
cl_uint num_devices = 0;
cl_uint device_no = 0;
const size_t bufsize = BUFFERSIZE;
char buf[BUFFERSIZE];
cl_device_id *devices;
char *extensions = NULL;
cl_kernel verify_kernel;
cl_kernel verify_kernel2;
cl_kernel kernel[3] = { NULL, NULL, NULL };
cl_kernel kernel2[3] = { NULL, NULL, NULL };
clKernelWrapper verify_kernel;
clKernelWrapper verify_kernel2;
clKernelWrapper kernel[3] = { NULL, NULL, NULL };
clKernelWrapper kernel2[3] = { NULL, NULL, NULL };
const char *program_source_const[3] = { kernel_text_numbuffer_1,
kernel_text_numbuffer_2,
kernel_text_numbuffer_4 };
const char *program_source_const_verify;
size_t program_source_length;
cl_command_queue cmd_queue1 = NULL;
cl_command_queue cmd_queue2 = NULL;
cl_command_queue cmd_queue3 = NULL;
cl_context context = NULL;
cl_program program[3] = { NULL, NULL, NULL };
cl_program program_verify, program_verify2;
cl_context context2 = NULL;
clCommandQueueWrapper cmd_queue1;
clCommandQueueWrapper cmd_queue2;
clCommandQueueWrapper cmd_queue3;
clProgramWrapper program[3] = { NULL, NULL, NULL };
clProgramWrapper program_verify, program_verify2;
clContextWrapper context2;
VulkanDevice vkDevice;
uint32_t numBuffersList[] = { 1, 2, 4 };
uint32_t bufferSizeList[] = { 4 * 1024, 64 * 1024, 2 * 1024 * 1024 };
uint32_t bufferSizeListforOffset[] = { 256, 512, 1024 };
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
std::vector<VulkanExternalSemaphoreHandleType> supportedSemaphoreTypes;
errNum = clGetPlatformIDs(1, &platform, NULL);
test_error_and_cleanup(errNum, CLEANUP, "Error: Failed to get platform\n");
errNum =
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
test_error_and_cleanup(errNum, CLEANUP,
"clGetDeviceIDs failed in returning of devices\n");
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
if (NULL == devices)
{
test_fail_and_cleanup(errNum, CLEANUP,
"Unable to allocate memory for devices\n");
}
errNum = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, devices,
NULL);
test_error_and_cleanup(errNum, CLEANUP, "Failed to get deviceID.\n");
contextProperties[1] = (cl_context_properties)platform;
log_info("Assigned contextproperties for platform\n");
for (device_no = 0; device_no < num_devices; device_no++)
{
errNum = clGetDeviceInfo(devices[device_no], CL_DEVICE_UUID_KHR,
CL_UUID_SIZE_KHR, uuid, NULL);
test_error_and_cleanup(errNum, CLEANUP, "clGetDeviceInfo failed\n");
if (!use_fence)
{
supportedSemaphoreTypes =
getSupportedInteropExternalSemaphoreHandleTypes(
devices[device_no], vkDevice);
getSupportedInteropExternalSemaphoreHandleTypes(device,
*vkDevice);
}
else
{
@@ -1678,48 +1639,24 @@ int test_buffer_common(cl_device_id device_, cl_context context_,
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_NONE);
}
// If device does not support any semaphores, try the next one
if (!use_fence && supportedSemaphoreTypes.empty())
{
continue;
}
errNum =
memcmp(uuid, vkDevice.getPhysicalDevice().getUUID(), VK_UUID_SIZE);
if (errNum == 0)
{
break;
}
return TEST_FAIL;
}
if (!use_fence && supportedSemaphoreTypes.empty())
{
test_fail_and_cleanup(
errNum, CLEANUP,
"No devices found that support OpenCL semaphores\n");
test_error_fail(
errNum, "No devices found that support OpenCL semaphores\n");
}
if (device_no >= num_devices)
{
test_fail_and_cleanup(errNum, CLEANUP,
"OpenCL error: "
"No Vulkan-OpenCL Interop capable GPU found.\n");
}
deviceId = devices[device_no];
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &errNum);
test_error_and_cleanup(errNum, CLEANUP, "error creating context\n");
deviceId = device;
cmd_queue1 = clCreateCommandQueue(context, device, 0, &errNum);
test_error(errNum, "Error: Failed to create command queue!\n");
log_info("Successfully created context !!!\n");
cmd_queue1 = clCreateCommandQueue(context, devices[device_no], 0, &errNum);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to create command queue!\n");
cmd_queue2 = clCreateCommandQueue(context, devices[device_no], 0, &errNum);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to create command queue!\n");
cmd_queue2 = clCreateCommandQueue(context, device, 0, &errNum);
test_error(errNum, "Error: Failed to create command queue!\n");
log_info("clCreateCommandQueue successful\n");
for (int i = 0; i < 3; i++)
@@ -1729,12 +1666,11 @@ int test_buffer_common(cl_device_id device_, cl_context context_,
clCreateProgramWithSource(context, 1, &program_source_const[i],
&program_source_length, &errNum);
errNum = clBuildProgram(program[i], 0, NULL, NULL, NULL, NULL);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to build program \n");
test_error(errNum, "Error: Failed to build program \n");
// create the kernel
kernel[i] = clCreateKernel(program[i], "clUpdateBuffer", &errNum);
test_error_and_cleanup(errNum, CLEANUP, "clCreateKernel failed \n");
test_error(errNum, "clCreateKernel failed \n");
}
program_source_const_verify = kernel_text_verify;
@@ -1743,47 +1679,44 @@ int test_buffer_common(cl_device_id device_, cl_context context_,
clCreateProgramWithSource(context, 1, &program_source_const_verify,
&program_source_length, &errNum);
errNum = clBuildProgram(program_verify, 0, NULL, NULL, NULL, NULL);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to build program2\n");
test_error(errNum, "Error: Failed to build program2\n");
verify_kernel = clCreateKernel(program_verify, "checkKernel", &errNum);
test_error_and_cleanup(errNum, CLEANUP, "clCreateKernel failed \n");
test_error(errNum, "clCreateKernel failed \n");
if (multiCtx) // different context guard
{
context2 = clCreateContextFromType(
contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &errNum);
test_error_and_cleanup(errNum, CLEANUP, "error creating context\n");
context2 =
clCreateContext(0, 1, &device, nullptr, nullptr, &errNum);
test_error(errNum, "error creating context\n");
cmd_queue3 =
clCreateCommandQueue(context2, devices[device_no], 0, &errNum);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to create command queue!\n");
cmd_queue3 = clCreateCommandQueue(context2, device, 0, &errNum);
test_error(errNum, "Error: Failed to create command queue!\n");
for (int i = 0; i < 3; i++)
{
program_source_length = strlen(program_source_const[i]);
program[i] =
clCreateProgramWithSource(context2, 1, &program_source_const[i],
program[i] = clCreateProgramWithSource(
context2, 1, &program_source_const[i],
&program_source_length, &errNum);
errNum = clBuildProgram(program[i], 0, NULL, NULL, NULL, NULL);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to build program \n");
test_error(errNum, "Error: Failed to build program \n");
// create the kernel
kernel2[i] = clCreateKernel(program[i], "clUpdateBuffer", &errNum);
test_error_and_cleanup(errNum, CLEANUP, "clCreateKernel failed \n");
kernel2[i] =
clCreateKernel(program[i], "clUpdateBuffer", &errNum);
test_error(errNum, "clCreateKernel failed \n");
}
program_source_length = strlen(program_source_const_verify);
program_verify =
clCreateProgramWithSource(context2, 1, &program_source_const_verify,
program_verify = clCreateProgramWithSource(
context2, 1, &program_source_const_verify,
&program_source_length, &errNum);
errNum = clBuildProgram(program_verify, 0, NULL, NULL, NULL, NULL);
test_error_and_cleanup(errNum, CLEANUP,
"Error: Failed to build program2\n");
test_error(errNum, "Error: Failed to build program2\n");
verify_kernel2 = clCreateKernel(program_verify, "checkKernel", &errNum);
test_error_and_cleanup(errNum, CLEANUP, "clCreateKernel failed \n");
verify_kernel2 =
clCreateKernel(program_verify, "checkKernel", &errNum);
test_error(errNum, "clCreateKernel failed \n");
}
// TODO: Add support for empty list if use_fence enabled
@@ -1799,55 +1732,154 @@ int test_buffer_common(cl_device_id device_, cl_context context_,
sizeIdx++)
{
uint32_t bufferSize = bufferSizeList[sizeIdx];
log_info(
"&&&& RUNNING vulkan_opencl_buffer test for Buffer size: "
log_info("&&&& RUNNING vulkan_opencl_buffer test "
"for Buffer size: "
"%d\n",
bufferSize);
if (multiImport && !multiCtx)
{
errNum = run_test_with_multi_import_same_ctx(
context, cmd_queue1, kernel, verify_kernel, vkDevice,
numBuffers, bufferSize, use_fence, semaphoreType);
context, (cl_command_queue &)cmd_queue1,
(cl_kernel *)&kernel, (cl_kernel &)verify_kernel,
*vkDevice, numBuffers, bufferSize, use_fence,
semaphoreType);
}
else if (multiImport && multiCtx)
{
errNum = run_test_with_multi_import_diff_ctx(
context, context2, cmd_queue1, cmd_queue3, kernel,
kernel2, verify_kernel, verify_kernel2, vkDevice,
numBuffers, bufferSize, use_fence, semaphoreType);
context, (cl_context &)context2,
(cl_command_queue &)cmd_queue1,
(cl_command_queue &)cmd_queue3,
(cl_kernel *)&kernel, (cl_kernel *)&kernel2,
(cl_kernel &)verify_kernel, verify_kernel2,
*vkDevice, numBuffers, bufferSize, use_fence,
semaphoreType);
}
else if (numCQ == 2)
{
errNum = run_test_with_two_queue(
context, cmd_queue1, cmd_queue2, kernel, verify_kernel,
vkDevice, numBuffers + 1, bufferSize, use_fence,
context, (cl_command_queue &)cmd_queue1,
(cl_command_queue &)cmd_queue2,
(cl_kernel *)&kernel, (cl_kernel &)verify_kernel,
*vkDevice, numBuffers + 1, bufferSize, use_fence,
semaphoreType);
}
else
{
errNum = run_test_with_one_queue(
context, cmd_queue1, kernel, verify_kernel, vkDevice,
numBuffers, bufferSize, semaphoreType, use_fence);
context, (cl_command_queue &)cmd_queue1,
(cl_kernel *)&kernel, (cl_kernel &)verify_kernel,
*vkDevice, numBuffers, bufferSize, semaphoreType,
use_fence);
}
test_error_and_cleanup(errNum, CLEANUP, "func_name failed \n");
test_error(errNum, "func_name failed \n");
}
}
}
CLEANUP:
for (int i = 0; i < 3; i++)
{
if (program[i]) clReleaseProgram(program[i]);
if (kernel[i]) clReleaseKernel(kernel[i]);
}
if (cmd_queue1) clReleaseCommandQueue(cmd_queue1);
if (cmd_queue2) clReleaseCommandQueue(cmd_queue2);
if (cmd_queue3) clReleaseCommandQueue(cmd_queue3);
if (context) clReleaseContext(context);
if (context2) clReleaseContext(context2);
if (devices) free(devices);
if (extensions) free(extensions);
return errNum;
}
};
template <bool use_fence> struct BufferCommonBufferTest : public BufferTestBase
{
BufferCommonBufferTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: BufferTestBase(device, context, queue, nelems)
{}
cl_int Run() override { return test_buffer_common(use_fence); }
};
} // anonymous namespace
int test_buffer_single_queue(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<false>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiple_queue(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<false>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiImport_sameCtx(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
multiImport = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN SAME CONTEXT...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<false>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiImport_diffCtx(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
multiImport = true;
multiCtx = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN DIFFERENT CONTEXT...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<false>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_single_queue_fence(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<true>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiple_queue_fence(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<true>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiImport_sameCtx_fence(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
multiImport = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN SAME CONTEXT...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<true>>(
deviceID, context, defaultQueue, num_elements);
}
int test_buffer_multiImport_diffCtx_fence(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements)
{
params_reset();
multiImport = true;
multiCtx = true;
log_info("RUNNING TEST WITH MULTIPLE DEVICE MEMORY IMPORT "
"IN DIFFERENT CONTEXT...... \n\n");
return MakeAndRunTest<BufferCommonBufferTest<true>>(
deviceID, context, defaultQueue, num_elements);
}

View File

@@ -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.
@@ -19,7 +19,11 @@
#include "harness/errorHelpers.h"
#include "harness/os_helpers.h"
#include <algorithm>
#include "deviceInfo.h"
#include "vulkan_test_base.h"
#include "opencl_vulkan_wrapper.hpp"
namespace {
#define MAX_2D_IMAGES 5
#define MAX_2D_IMAGE_WIDTH 1024
@@ -46,14 +50,13 @@
ASSERT(0); \
}
namespace {
struct Params
{
uint32_t numImage2DDescriptors;
};
}
static cl_uchar uuid[CL_UUID_SIZE_KHR];
static cl_device_id deviceId = NULL;
cl_uchar uuid[CL_UUID_SIZE_KHR];
cl_device_id deviceId = NULL;
size_t max_width = MAX_2D_IMAGE_WIDTH;
size_t max_height = MAX_2D_IMAGE_HEIGHT;
@@ -245,7 +248,7 @@ int run_test_with_two_queue(
VulkanCommandPool vkCommandPool(vkDevice);
VulkanCommandBuffer vkCopyCommandBuffer(vkDevice, vkCommandPool);
VulkanCommandBuffer vkShaderCommandBuffer(vkDevice, vkCommandPool);
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue = vkDevice.getQueue(getVulkanQueueFamily());
VulkanSemaphore vkVk2CLSemaphore(vkDevice, vkExternalSemaphoreHandleType);
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
@@ -857,7 +860,7 @@ int run_test_with_one_queue(
VulkanCommandPool vkCommandPool(vkDevice);
VulkanCommandBuffer vkCopyCommandBuffer(vkDevice, vkCommandPool);
VulkanCommandBuffer vkShaderCommandBuffer(vkDevice, vkCommandPool);
VulkanQueue &vkQueue = vkDevice.getQueue();
VulkanQueue &vkQueue = vkDevice.getQueue(getVulkanQueueFamily());
VulkanSemaphore vkVk2CLSemaphore(vkDevice, vkExternalSemaphoreHandleType);
VulkanSemaphore vkCl2VkSemaphore(vkDevice, vkExternalSemaphoreHandleType);
@@ -1352,23 +1355,18 @@ CLEANUP:
return err;
}
int test_image_common(cl_device_id device_, cl_context context_,
cl_command_queue queue_, int numElements_)
struct ImageCommonTest : public VulkanTestBase
{
ImageCommonTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
int test_image_common()
{
int current_device = 0;
int device_count = 0;
int devices_prohibited = 0;
cl_int err = CL_SUCCESS;
cl_platform_id platform = NULL;
size_t extensionSize = 0;
cl_uint num_devices = 0;
cl_uint device_no = 0;
cl_device_id *devices;
char *extensions = NULL;
const char *program_source_const;
cl_command_queue cmd_queue1 = NULL;
cl_command_queue cmd_queue2 = NULL;
cl_context context = NULL;
clCommandQueueWrapper cmd_queue1;
clCommandQueueWrapper cmd_queue2;
const uint32_t num_kernels = ARRAY_SIZE(num2DImagesList) + 1;
// One kernel for Cross-CQ case
const uint32_t num_kernel_types = 3;
@@ -1379,119 +1377,41 @@ int test_image_common(cl_device_id device_, cl_context context_,
char source_2[4096];
char source_3[4096];
size_t program_source_length;
cl_program program[num_kernel_types] = { NULL };
cl_kernel kernel_float[num_kernels] = { NULL };
cl_kernel kernel_signed[num_kernels] = { NULL };
cl_kernel kernel_unsigned[num_kernels] = { NULL };
cl_mem external_mem_image1;
cl_mem external_mem_image2;
clProgramWrapper program[num_kernel_types] = { NULL };
clKernelWrapper kernel_float[num_kernels] = { NULL };
clKernelWrapper kernel_signed[num_kernels] = { NULL };
clKernelWrapper kernel_unsigned[num_kernels] = { NULL };
clMemWrapper external_mem_image1;
clMemWrapper external_mem_image2;
std::vector<VulkanExternalSemaphoreHandleType> supportedSemaphoreTypes;
VulkanDevice vkDevice;
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
// get the platform ID
err = clGetPlatformIDs(1, &platform, NULL);
test_error_and_cleanup(err, CLEANUP, "Error: Failed to get platform\n");
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
test_error_and_cleanup(
err, CLEANUP, "clGetDeviceIDs failed in returning no. of devices\n");
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
if (NULL == devices)
{
test_fail_and_cleanup(err, CLEANUP,
"Unable to allocate memory for devices\n");
}
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices, devices,
NULL);
test_error_and_cleanup(err, CLEANUP, "Failed to get deviceID.\n");
contextProperties[1] = (cl_context_properties)platform;
log_info("Assigned contextproperties for platform\n");
for (device_no = 0; device_no < num_devices; device_no++)
{
err = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS, 0, NULL,
&extensionSize);
if (CL_SUCCESS != err)
{
print_error(
err,
"Error in clGetDeviceInfo for getting device_extension size\n");
goto CLEANUP;
}
extensions = (char *)malloc(extensionSize);
if (NULL == extensions)
{
err = CL_OUT_OF_HOST_MEMORY;
print_error(err, "Unable to allocate memory for extensions\n");
goto CLEANUP;
}
err = clGetDeviceInfo(devices[device_no], CL_DEVICE_EXTENSIONS,
extensionSize, extensions, NULL);
if (CL_SUCCESS != err)
{
print_error(
err, "Error in clGetDeviceInfo for getting device_extension\n");
goto CLEANUP;
}
err = clGetDeviceInfo(devices[device_no], CL_DEVICE_UUID_KHR,
CL_UUID_SIZE_KHR, uuid, NULL);
test_error_and_cleanup(err, CLEANUP,
"clGetDeviceInfo failed with error");
supportedSemaphoreTypes =
getSupportedInteropExternalSemaphoreHandleTypes(devices[device_no],
vkDevice);
getSupportedInteropExternalSemaphoreHandleTypes(device, *vkDevice);
// If device does not support any semaphores, try the next one
if (supportedSemaphoreTypes.empty())
{
continue;
log_info("Device does not support any semaphores!\n");
return TEST_SKIPPED_ITSELF;
}
err =
memcmp(uuid, vkDevice.getPhysicalDevice().getUUID(), VK_UUID_SIZE);
if (err == 0)
{
break;
}
}
deviceId = device;
if (supportedSemaphoreTypes.empty())
{
test_fail_and_cleanup(
err, CLEANUP, "No devices found that support OpenCL semaphores\n");
}
if (device_no >= num_devices)
{
test_fail_and_cleanup(err, CLEANUP,
"OpenCL error:"
"No Vulkan-OpenCL Interop capable GPU found.\n");
}
deviceId = devices[device_no];
err = setMaxImageDimensions(deviceId, max_width, max_height);
test_error_and_cleanup(err, CLEANUP, "error setting max image dimensions");
test_error(err, "error setting max image dimensions");
log_info("Set max_width to %zu and max_height to %zu\n", max_width,
max_height);
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &err);
test_error_and_cleanup(err, CLEANUP, "error creating context");
log_info("Successfully created context !!!\n");
cmd_queue1 = clCreateCommandQueue(context, devices[device_no], 0, &err);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to create command queue!\n");
cmd_queue1 = clCreateCommandQueue(context, deviceId, 0, &err);
test_error(err, "Error: Failed to create command queue!\n");
log_info("clCreateCommandQueue successfull \n");
cmd_queue2 = clCreateCommandQueue(context, devices[device_no], 0, &err);
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to create command queue!\n");
cmd_queue2 = clCreateCommandQueue(context, deviceId, 0, &err);
test_error(err, "Error: Failed to create command queue!\n");
log_info("clCreateCommandQueue2 successful \n");
@@ -1502,44 +1422,46 @@ int test_image_common(cl_device_id device_, cl_context context_,
case 0:
sprintf(source_1, kernel_source[i], "float4", "f", "float4",
"f", "f", "f");
sprintf(source_2, kernel_source[i], "int4", "i", "int4", "i",
"i", "i");
sprintf(source_2, kernel_source[i], "int4", "i", "int4",
"i", "i", "i");
sprintf(source_3, kernel_source[i], "uint4", "ui", "uint4",
"ui", "ui", "ui");
break;
case 1:
sprintf(source_1, kernel_source[i], "float4", "f", "float4",
"f", "float4", "f", "float4", "f", "f", "f", "f", "f");
sprintf(source_2, kernel_source[i], "int4", "i", "int4", "i",
"int4", "i", "int4", "i", "i", "i", "i", "i");
"f", "float4", "f", "float4", "f", "f", "f", "f",
"f");
sprintf(source_2, kernel_source[i], "int4", "i", "int4",
"i", "int4", "i", "int4", "i", "i", "i", "i", "i");
sprintf(source_3, kernel_source[i], "uint4", "ui", "uint4",
"ui", "uint4", "ui", "uint4", "ui", "ui", "ui", "ui",
"ui");
"ui", "uint4", "ui", "uint4", "ui", "ui", "ui",
"ui", "ui");
break;
case 2:
sprintf(source_1, kernel_source[i], "float4", "f", "float4",
"f", "float4", "f", "float4", "f", "float4", "f",
"float4", "f", "float4", "f", "float4", "f", "f", "f",
"f", "f", "f", "f", "f", "f");
sprintf(source_2, kernel_source[i], "int4", "i", "int4", "i",
"int4", "i", "int4", "i", "int4", "i", "int4", "i",
"int4", "i", "int4", "i", "i", "i", "i", "i", "i", "i",
"i", "i");
"float4", "f", "float4", "f", "float4", "f", "f",
"f", "f", "f", "f", "f", "f", "f");
sprintf(source_2, kernel_source[i], "int4", "i", "int4",
"i", "int4", "i", "int4", "i", "int4", "i", "int4",
"i", "int4", "i", "int4", "i", "i", "i", "i", "i",
"i", "i", "i", "i");
sprintf(source_3, kernel_source[i], "uint4", "ui", "uint4",
"ui", "uint4", "ui", "uint4", "ui", "uint4", "ui",
"uint4", "ui", "uint4", "ui", "uint4", "ui", "ui", "ui",
"ui", "ui", "ui", "ui", "ui", "ui");
"uint4", "ui", "uint4", "ui", "uint4", "ui", "ui",
"ui", "ui", "ui", "ui", "ui", "ui", "ui");
break;
case 3:
// Addtional case for creating updateKernelCQ2 which takes two
// images
// Addtional case for creating updateKernelCQ2 which takes
// two images
sprintf(source_1, kernel_source[1], "float4", "f", "float4",
"f", "float4", "f", "float4", "f", "f", "f", "f", "f");
sprintf(source_2, kernel_source[1], "int4", "i", "int4", "i",
"int4", "i", "int4", "i", "i", "i", "i", "i");
"f", "float4", "f", "float4", "f", "f", "f", "f",
"f");
sprintf(source_2, kernel_source[1], "int4", "i", "int4",
"i", "int4", "i", "int4", "i", "i", "i", "i", "i");
sprintf(source_3, kernel_source[1], "uint4", "ui", "uint4",
"ui", "uint4", "ui", "uint4", "ui", "ui", "ui", "ui",
"ui");
"ui", "uint4", "ui", "uint4", "ui", "ui", "ui",
"ui", "ui");
break;
}
const char *sourceTexts[num_kernel_types] = { source_1, source_2,
@@ -1551,17 +1473,19 @@ int test_image_common(cl_device_id device_, cl_context context_,
context, 1, &sourceTexts[k], &program_source_length, &err);
err |= clBuildProgram(program[k], 0, NULL, NULL, NULL, NULL);
}
test_error_and_cleanup(err, CLEANUP, "Error: Failed to build program");
test_error(err, "Error: Failed to build program");
// create the kernel
kernel_float[i] = clCreateKernel(program[0], "image2DKernel", &err);
test_error_and_cleanup(err, CLEANUP, "clCreateKernel failed");
test_error(err, "clCreateKernel failed");
kernel_signed[i] = clCreateKernel(program[1], "image2DKernel", &err);
test_error_and_cleanup(err, CLEANUP, "clCreateKernel failed");
kernel_signed[i] =
clCreateKernel(program[1], "image2DKernel", &err);
test_error(err, "clCreateKernel failed");
kernel_unsigned[i] = clCreateKernel(program[2], "image2DKernel", &err);
test_error_and_cleanup(err, CLEANUP, "clCreateKernel failed ");
kernel_unsigned[i] =
clCreateKernel(program[2], "image2DKernel", &err);
test_error(err, "clCreateKernel failed ");
}
for (VulkanExternalSemaphoreHandleType externalSemaphoreType :
supportedSemaphoreTypes)
@@ -1569,45 +1493,47 @@ int test_image_common(cl_device_id device_, cl_context context_,
if (numCQ == 2)
{
err = run_test_with_two_queue(
context, cmd_queue1, cmd_queue2, kernel_unsigned, kernel_signed,
kernel_float, vkDevice, externalSemaphoreType);
context, (cl_command_queue &)cmd_queue1,
(cl_command_queue &)cmd_queue2,
(cl_kernel *)kernel_unsigned, (cl_kernel *)kernel_signed,
(cl_kernel *)kernel_float, *vkDevice,
externalSemaphoreType);
}
else
{
err = run_test_with_one_queue(context, cmd_queue1, kernel_unsigned,
kernel_signed, kernel_float, vkDevice,
err = run_test_with_one_queue(
context, (cl_command_queue &)cmd_queue1,
(cl_kernel *)kernel_unsigned, (cl_kernel *)kernel_signed,
(cl_kernel *)kernel_float, *vkDevice,
externalSemaphoreType);
}
test_error(err, "func_name failed \n");
}
CLEANUP:
for (int i = 0; i < num_kernels; i++)
{
if (kernel_float[i])
{
clReleaseKernel(kernel_float[i]);
}
if (kernel_unsigned[i])
{
clReleaseKernel(kernel_unsigned[i]);
}
if (kernel_signed[i])
{
clReleaseKernel(kernel_signed[i]);
}
}
for (int i = 0; i < num_kernel_types; i++)
{
if (program[i])
{
clReleaseProgram(program[i]);
}
}
if (cmd_queue1) clReleaseCommandQueue(cmd_queue1);
if (cmd_queue2) clReleaseCommandQueue(cmd_queue2);
if (context) clReleaseContext(context);
if (extensions) free(extensions);
if (devices) free(devices);
return err;
}
cl_int Run() override { return test_image_common(); }
};
} // anonymous namespace
int test_image_single_queue(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
params_reset();
log_info("RUNNING TEST WITH ONE QUEUE...... \n\n");
return MakeAndRunTest<ImageCommonTest>(deviceID, context, defaultQueue,
num_elements);
}
int test_image_multiple_queue(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
params_reset();
numCQ = 2;
log_info("RUNNING TEST WITH TWO QUEUE...... \n\n");
return MakeAndRunTest<ImageCommonTest>(deviceID, context, defaultQueue,
num_elements);
}

View File

@@ -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.
@@ -22,6 +22,10 @@
#include <string>
#include <vector>
#include "vulkan_test_base.h"
namespace {
typedef struct
{
cl_uint info;
@@ -29,38 +33,44 @@ typedef struct
} _info;
_info platform_info_table[] = {
#define STRING(x) \
#define PLATFORM_INFO_STRING(x) \
{ \
x, #x \
}
STRING(CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR),
STRING(CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
STRING(CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)
#undef STRING
PLATFORM_INFO_STRING(CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR),
PLATFORM_INFO_STRING(CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
PLATFORM_INFO_STRING(CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)
#undef PLATFORM_INFO_STRING
};
_info device_info_table[] = {
#define STRING(x) \
#define DEVICE_INFO_STRING(x) \
{ \
x, #x \
}
STRING(CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR),
STRING(CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
STRING(CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR)
#undef STRING
DEVICE_INFO_STRING(CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR),
DEVICE_INFO_STRING(CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
DEVICE_INFO_STRING(CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR)
#undef DEVICE_INFO_STRING
};
int test_platform_info(cl_device_id deviceID, cl_context _context,
cl_command_queue _queue, int num_elements)
struct PlatformInfoTest : public VulkanTestBase
{
PlatformInfoTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
cl_int Run() override
{
cl_uint i;
cl_platform_id platform = getPlatformFromDevice(deviceID);
cl_platform_id platform = getPlatformFromDevice(device);
cl_int errNum;
cl_uint *handle_type;
size_t handle_type_size = 0;
cl_uint num_handles = 0;
cl_bool external_mem_extn_available =
is_platform_extension_available(platform, "cl_khr_external_semaphore");
cl_bool external_mem_extn_available = is_platform_extension_available(
platform, "cl_khr_external_semaphore");
cl_bool external_sema_extn_available =
is_platform_extension_available(platform, "cl_khr_external_memory");
cl_bool supports_atleast_one_sema_query = false;
@@ -75,7 +85,8 @@ int test_platform_info(cl_device_id deviceID, cl_context _context,
log_info("Platform (id %lu) info:\n", (unsigned long)platform);
for (i = 0;
i < sizeof(platform_info_table) / sizeof(platform_info_table[0]); i++)
i < sizeof(platform_info_table) / sizeof(platform_info_table[0]);
i++)
{
errNum = clGetPlatformInfo(platform, platform_info_table[i].info, 0,
NULL, &handle_type_size);
@@ -87,8 +98,8 @@ int test_platform_info(cl_device_id deviceID, cl_context _context,
== CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR
&& external_mem_extn_available)
{
test_fail(
"External memory import handle types should be reported if "
test_fail("External memory import handle types should be "
"reported if "
"cl_khr_external_memory is available.\n");
}
log_info("%s not supported. Skipping the query.\n",
@@ -123,16 +134,24 @@ int test_platform_info(cl_device_id deviceID, cl_context _context,
if (external_sema_extn_available && !supports_atleast_one_sema_query)
{
log_info("External semaphore import/export or both should be supported "
log_info(
"External semaphore import/export or both should be supported "
"if cl_khr_external_semaphore is available.\n");
return TEST_FAIL;
}
return TEST_PASS;
}
};
int test_device_info(cl_device_id deviceID, cl_context _context,
cl_command_queue _queue, int num_elements)
struct DeviceInfoTest : public VulkanTestBase
{
DeviceInfoTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: VulkanTestBase(device, context, queue, nelems)
{}
cl_int Run() override
{
cl_uint j;
cl_uint *handle_type;
@@ -140,9 +159,9 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
cl_uint num_handles = 0;
cl_int errNum = CL_SUCCESS;
cl_bool external_mem_extn_available =
is_extension_available(deviceID, "cl_khr_external_memory");
is_extension_available(device, "cl_khr_external_memory");
cl_bool external_sema_extn_available =
is_extension_available(deviceID, "cl_khr_external_semaphore");
is_extension_available(device, "cl_khr_external_semaphore");
cl_bool supports_atleast_one_sema_query = false;
if (!external_mem_extn_available && !external_sema_extn_available)
@@ -152,10 +171,10 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
return TEST_SKIPPED_ITSELF;
}
for (j = 0; j < sizeof(device_info_table) / sizeof(device_info_table[0]);
j++)
for (j = 0;
j < sizeof(device_info_table) / sizeof(device_info_table[0]); j++)
{
errNum = clGetDeviceInfo(deviceID, device_info_table[j].info, 0, NULL,
errNum = clGetDeviceInfo(device, device_info_table[j].info, 0, NULL,
&handle_type_size);
test_error(errNum, "clGetDeviceInfo failed");
@@ -165,8 +184,8 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
== CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR
&& external_mem_extn_available)
{
test_fail(
"External memory import handle types should be reported if "
test_fail("External memory import handle types should be "
"reported if "
"cl_khr_external_memory is available.\n");
}
log_info("%s not supported. Skipping the query.\n",
@@ -185,7 +204,7 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
num_handles = handle_type_size / sizeof(cl_uint);
handle_type = (cl_uint *)malloc(handle_type_size);
errNum = clGetDeviceInfo(deviceID, device_info_table[j].info,
errNum = clGetDeviceInfo(device, device_info_table[j].info,
handle_type_size, handle_type, NULL);
test_error(errNum, "clGetDeviceInfo failed");
@@ -202,10 +221,28 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
if (external_sema_extn_available && !supports_atleast_one_sema_query)
{
log_info("External semaphore import/export or both should be supported "
log_info(
"External semaphore import/export or both should be supported "
"if cl_khr_external_semaphore is available.\n");
return TEST_FAIL;
}
return TEST_PASS;
}
};
} // anonymous namespace
int test_platform_info(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
return MakeAndRunTest<PlatformInfoTest>(deviceID, context, defaultQueue,
num_elements);
}
int test_device_info(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
return MakeAndRunTest<DeviceInfoTest>(deviceID, context, defaultQueue,
num_elements);
}

View File

@@ -0,0 +1,129 @@
//
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CL_VULKAN_TEST_BASE_H
#define CL_VULKAN_TEST_BASE_H
#include <CL/cl_ext.h>
#include <memory>
#include <vector>
#include "vulkan_interop_common.hpp"
#include "harness/deviceInfo.h"
#include "harness/testHarness.h"
#include "harness/typeWrappers.h"
inline void params_reset()
{
numCQ = 1;
multiImport = false;
multiCtx = false;
}
struct VulkanTestBase
{
VulkanTestBase(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
: device(device), context(context), num_elems(nelems)
{
vkDevice.reset(
new VulkanDevice(getAssociatedVulkanPhysicalDevice(device)));
if (!(is_extension_available(device, "cl_khr_external_memory")
&& is_extension_available(device, "cl_khr_external_semaphore")))
{
log_info("Device does not support cl_khr_external_memory "
"or cl_khr_external_semaphore\n");
log_info(" TEST SKIPPED\n");
throw std::runtime_error("VulkanTestBase not supported");
}
cl_platform_id platform;
cl_int error = clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
sizeof(cl_platform_id), &platform, NULL);
if (error != CL_SUCCESS)
throw std::runtime_error(
"clGetDeviceInfo for CL_DEVICE_PLATFORM failed");
// verify whether selected device is one of the type CL_DEVICE_TYPE_GPU
cl_uint num_devices = 0;
error =
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
if (CL_SUCCESS != error)
throw std::runtime_error(
"clGetDeviceIDs failed in returning of devices");
std::vector<cl_device_id> devices(num_devices);
error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, num_devices,
devices.data(), NULL);
bool found_gpu_match = false;
for (cl_uint i = 0; i < num_devices; i++)
if (devices[i] == device)
{
found_gpu_match = true;
break;
}
if (!found_gpu_match)
throw std::runtime_error(
"Vulkan tests can only run on a GPU device.");
init_cl_vk_ext(platform, 1, &device);
}
virtual cl_int Run() = 0;
protected:
cl_device_id device = nullptr;
cl_context context = nullptr;
clCommandQueueWrapper queue = nullptr;
cl_int num_elems = 0;
std::unique_ptr<VulkanDevice> vkDevice;
};
template <class T>
int MakeAndRunTest(cl_device_id device, cl_context context,
cl_command_queue queue, cl_int nelems)
{
if (!checkVkSupport())
{
log_info("Vulkan supported GPU not found \n");
log_info("TEST SKIPPED \n");
return TEST_SKIPPED_ITSELF;
}
cl_int status = TEST_PASS;
try
{
// moved from original test - do we want to stick to that ?
cl_int numElementsToUse = 1024;
auto test_fixture =
T(device, context, queue, /*nelems*/ numElementsToUse);
status = test_fixture.Run();
} catch (const std::runtime_error &e)
{
log_error("%s", e.what());
return TEST_FAIL;
}
return status;
}
#endif // CL_VULKAN_TEST_BASE_H