Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a few new tests in test_api #736

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,16 @@ cl_int CLVK_API_CALL clGetDeviceIDs(cl_platform_id platform,
cl_uint num = 0;

for (auto dev : icd_downcast(platform)->devices()) {
if (dev->type() & device_type) {
if ((dev->type() & device_type) ||
(device_type == CL_DEVICE_TYPE_DEFAULT && num == 0) ||
(device_type == CL_DEVICE_TYPE_ALL)) {
if ((devices != nullptr) && (num < num_entries)) {
devices[num] = dev;
}
num++;
if (device_type == CL_DEVICE_TYPE_DEFAULT) {
break;
}
}
}

Expand Down Expand Up @@ -620,19 +625,23 @@ cl_int CLVK_API_CALL clGetDeviceInfo(cl_device_id dev,
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT:
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG:
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT:
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF:
val_uint = 1; // FIXME can we do better?
copy_ptr = &val_uint;
size_ret = sizeof(val_uint);
break;
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE:
val_uint = 0;
copy_ptr = &val_uint;
size_ret = sizeof(val_uint);
break;
case CL_DEVICE_PROFILING_TIMER_RESOLUTION:
val_sizet = 1;
copy_ptr = &val_sizet;
Expand Down
4 changes: 2 additions & 2 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ constexpr VkMemoryPropertyFlags cvk_device::buffer_supported_memory_types[];
constexpr VkMemoryPropertyFlags cvk_device::image_supported_memory_types[];

cvk_device* cvk_device::create(cvk_platform* platform, VkInstance instance,
VkPhysicalDevice pdev, bool is_default) {
cvk_device* device = new cvk_device(platform, pdev, is_default);
VkPhysicalDevice pdev) {
cvk_device* device = new cvk_device(platform, pdev);

if (!device->init(instance)) {
delete device;
Expand Down
15 changes: 6 additions & 9 deletions src/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,23 @@ struct cvk_platform;
struct cvk_device : public _cl_device_id,
object_magic_header<object_magic::device> {

cvk_device(cvk_platform* platform, VkPhysicalDevice pd, bool is_default)
cvk_device(cvk_platform* platform, VkPhysicalDevice pd)
: m_platform(platform), m_pdev(pd) {
vkGetPhysicalDeviceProperties(m_pdev, &m_properties);
vkGetPhysicalDeviceMemoryProperties(m_pdev, &m_mem_properties);
if (is_default) {
m_type = CL_DEVICE_TYPE_DEFAULT;
}

switch (m_properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
m_type |= CL_DEVICE_TYPE_GPU;
m_type = CL_DEVICE_TYPE_GPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_CPU:
m_type |= CL_DEVICE_TYPE_CPU;
m_type = CL_DEVICE_TYPE_CPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
default:
m_type |= CL_DEVICE_TYPE_ACCELERATOR;
m_type = CL_DEVICE_TYPE_ACCELERATOR;
break;
}

Expand All @@ -77,7 +74,7 @@ struct cvk_device : public _cl_device_id,
}

static cvk_device* create(cvk_platform* platform, VkInstance instance,
VkPhysicalDevice pdev, bool is_default);
VkPhysicalDevice pdev);

virtual ~cvk_device() {
for (auto entry : m_pipeline_caches) {
Expand Down Expand Up @@ -844,7 +841,7 @@ struct cvk_platform : public _cl_platform_id,

CHECK_RETURN bool create_device(VkInstance instance,
VkPhysicalDevice pdev) {
auto dev = cvk_device::create(this, instance, pdev, m_devices.empty());
auto dev = cvk_device::create(this, instance, pdev);
if (dev != nullptr) {
m_devices.push_back(dev);
return true;
Expand Down
30 changes: 0 additions & 30 deletions tests/api/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,6 @@

#include <unordered_set>

TEST(Platform, HasOneDefaultDevice) {
cl_int err;
cl_uint num_devices;
err =
clGetDeviceIDs(gPlatform, CL_DEVICE_TYPE_ALL, 0, nullptr, &num_devices);
ASSERT_EQ(err, CL_SUCCESS);

std::vector<cl_device_id> devices(num_devices);

err = clGetDeviceIDs(gPlatform, CL_DEVICE_TYPE_ALL, num_devices,
devices.data(), nullptr);
ASSERT_EQ(err, CL_SUCCESS);

unsigned num_default = 0;

for (auto dev : devices) {
cl_device_type dtype;
err = clGetDeviceInfo(dev, CL_DEVICE_TYPE, sizeof(dtype), &dtype,
nullptr);
ASSERT_EQ(err, CL_SUCCESS);

if (dtype & CL_DEVICE_TYPE_DEFAULT) {
num_default++;
}
}

ASSERT_EQ(num_default, 1);
}

TEST(Platform, DeviceQueryWithMultipleTypes) {
cl_int err;

Expand All @@ -55,7 +26,6 @@ TEST(Platform, DeviceQueryWithMultipleTypes) {
ASSERT_EQ(err, CL_SUCCESS);

// Check its type is one of the expected values
dtype &= ~CL_DEVICE_TYPE_DEFAULT;
ASSERT_TRUE(dtype == CL_DEVICE_TYPE_GPU || dtype == CL_DEVICE_TYPE_CPU ||
dtype == CL_DEVICE_TYPE_ACCELERATOR);

Expand Down