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

add a unified SVM consistency check test #2174

Open
wants to merge 4 commits into
base: cl_khr_unified_svm
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions test_conformance/SVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(${MODULE_NAME}_SOURCES
test_shared_address_space_fine_grain_buffers.cpp
test_shared_sub_buffers.cpp
test_migrate.cpp
test_unified_svm_consistency.cpp
)

set_gnulike_module_compile_flags("-Wno-sometimes-uninitialized -Wno-sign-compare")
Expand Down
159 changes: 159 additions & 0 deletions test_conformance/SVM/test_unified_svm_consistency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// 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 "common.h"
#include <cinttypes>

REGISTER_TEST(unified_svm_consistency)
{
if (!is_extension_available(deviceID, "cl_khr_unified_svm"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not been following the unified svm test plan closely, but is the idea that the extension tests will live in test_conformance/SVM rather than test_conformance/extensions/cl_khr_unified_svm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I don't think we've discussed this. I'll create a new test executable if that's what the group prefers, but I think we've generally tried to minimize test executables, so I'm inclined to put the unified SVM tests here unless we have a good reason to do otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I may have found a few good reasons to create a new test executable:

  1. The "SVM" tests run an InitCL function to decide whether to run the tests, which currently requires OpenCL 2.0 or newer, and requires that the query for CL_DEVICE_SVM_CAPABILITIES returns a non-zero value. The first part is debatably OK, though the extension is currently written to support OpenCL 1.2 devices also. The second part is not OK though, because a device can support unified SVM without supporting SVM.

  2. The "SVM" tests run with forceNoContextCreation set to true, which means no context or queue are created. Not the end of the world, but I think the harness context and queue will be sufficient for most of the unified SVM tests, so it'd be nice to keep things simple and use them.

{
log_info("cl_khr_unified_svm is not supported, skipping test.\n");
return TEST_SKIPPED_ITSELF;
}

cl_int err;

cl_platform_id platformID;
err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id),
(void *)(&platformID), nullptr);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM");

cl_uint numDevices = 0;
err =
clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 0, nullptr, &numDevices);
test_error(err, "clGetDeviceIDs failed to get number of devices");

std::vector<cl_device_id> devices(numDevices);
err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, numDevices,
devices.data(), nullptr);
test_error(err, "clGetDeviceIDs failed to get device IDs");

// For each device in the platform, check that the platform and device
// report the same number of SVM capability combinations.

size_t platformSize{};
err = clGetPlatformInfo(platformID, CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR,
0, nullptr, &platformSize);
test_error(err,
"clGetPlatformInfo failed for "
"CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR");

if (platformSize % sizeof(cl_svm_capabilities_khr) != 0)
{
test_fail(
"Unexpected platform SVM type capabilities size: %zu bytes.\n",
platformSize);
}

for (auto device : devices)
{
size_t deviceSize{};
err = clGetDeviceInfo(device, CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR, 0,
nullptr, &deviceSize);
test_error(
err,
"clGetDeviceInfo failed for CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR");

if (deviceSize % sizeof(cl_svm_capabilities_khr) != 0)
{
test_fail("Unexpected device SVM type capabilities size: "
"%zu bytes.\n",
deviceSize);
}
if (platformSize != deviceSize)
{
test_fail("Platform and device report different number of "
"SVM type capability combinations.\n");
}
}

// For each SVM capability combination reported by the platform, check that
// the reported platform capabilities at an index are the intersection of
// all non-zero device capabilities at the same index.

size_t capabilityCount = platformSize / sizeof(cl_svm_capabilities_khr);

std::vector<cl_svm_capabilities_khr> platformCapabilities(capabilityCount);
err = clGetPlatformInfo(platformID, CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR,
platformSize, platformCapabilities.data(), nullptr);
test_error(err,
"clGetPlatformInfo failed for "
"CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR");

for (int i = 0; i < capabilityCount; i++)
{
cl_svm_capabilities_khr check = 0;
for (auto device : devices)
{
std::vector<cl_svm_capabilities_khr> deviceCapabilities(
capabilityCount);
err = clGetDeviceInfo(device, CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR,
platformSize, deviceCapabilities.data(),
nullptr);
test_error(
err,
"clGetDeviceInfo failed for CL_DEVICE_SVM_CAPABILITIES_KHR");

if (deviceCapabilities[i] != 0)
{
if (check == 0)
{
check = deviceCapabilities[i];
}
else
{
check &= deviceCapabilities[i];
}
}
}
if (platformCapabilities[i] != check)
{
test_fail("Platform SVM type capabilities at index %zu: 0x%" PRIx64
" do not match the intersection of device capabilities "
"0x%" PRIx64 ".\n",
i, platformCapabilities[i], check);
}
}

// For each SVM capability combination reported by the test device, check
// that the device SVM capabilities are either a super-set of the platform
// SVM capabilities or are zero, indicating that this SVM type is not
// supported.

std::vector<cl_svm_capabilities_khr> deviceCapabilities(capabilityCount);
err = clGetDeviceInfo(deviceID, CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR,
platformSize, deviceCapabilities.data(), nullptr);
test_error(err,
"clGetDeviceInfo failed for CL_DEVICE_SVM_CAPABILITIES_KHR");

for (int i = 0; i < capabilityCount; i++)
{
bool consistent = (deviceCapabilities[i] & platformCapabilities[i])
== platformCapabilities[i]
|| deviceCapabilities[i] == 0;
if (!consistent)
{
test_fail(
"Device SVM type capabilities at index %zu: 0x%" PRIx64
" are not consistent with platform SVM type capabilities: "
"0x%" PRIx64 ".\n",
i, deviceCapabilities[i], platformCapabilities[i]);
}
}

return TEST_PASS;
}
Loading