Format subgroups tests according to clang-format (#745)

* Format subgroups tests to clang-format

* Format issue - fix do/while issue
This commit is contained in:
Grzegorz Wawiorko
2020-05-19 11:16:06 +02:00
committed by GitHub
parent a6c3d921ae
commit ec32bd9b5e
7 changed files with 1260 additions and 821 deletions

View File

@@ -1,6 +1,6 @@
//
// Copyright (c) 2017 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
@@ -15,117 +15,160 @@
//
#include "procs.h"
typedef struct {
typedef struct
{
cl_uint maxSubGroupSize;
cl_uint numSubGroups;
} result_data;
static const char * query_kernel_source =
"#pragma OPENCL EXTENSION cl_khr_subgroups : enable\n"
"\n"
"typedef struct {\n"
" uint maxSubGroupSize;\n"
" uint numSubGroups;\n"
"} result_data;\n"
"\n"
"__kernel void query_kernel( __global result_data *outData )\n"
"{\n"
" int gid = get_global_id( 0 );\n"
" outData[gid].maxSubGroupSize = get_max_sub_group_size();\n"
" outData[gid].numSubGroups = get_num_sub_groups();\n"
"}";
static const char *query_kernel_source =
"#pragma OPENCL EXTENSION cl_khr_subgroups : enable\n"
"\n"
"typedef struct {\n"
" uint maxSubGroupSize;\n"
" uint numSubGroups;\n"
"} result_data;\n"
"\n"
"__kernel void query_kernel( __global result_data *outData )\n"
"{\n"
" int gid = get_global_id( 0 );\n"
" outData[gid].maxSubGroupSize = get_max_sub_group_size();\n"
" outData[gid].numSubGroups = get_num_sub_groups();\n"
"}";
int
test_sub_group_info(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
int test_sub_group_info(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
static const size_t gsize0 = 80;
int i, error;
size_t realSize;
size_t kernel_max_subgroup_size, kernel_subgroup_count;
size_t global[] = {gsize0,14,10};
size_t local[] = {0,0,0};
size_t global[] = { gsize0, 14, 10 };
size_t local[] = { 0, 0, 0 };
result_data result[gsize0];
cl_uint max_dimensions;
error = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(max_dimensions), &max_dimensions, NULL);
test_error(error, "clGetDeviceInfo failed for CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS");
error = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
sizeof(max_dimensions), &max_dimensions, NULL);
test_error(error,
"clGetDeviceInfo failed for CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS");
cl_platform_id platform;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper out;
error = create_single_kernel_helper_with_build_options(context, &program, &kernel, 1, &query_kernel_source, "query_kernel", "-cl-std=CL2.0");
if (error != 0)
return error;
error = create_single_kernel_helper_with_build_options(
context, &program, &kernel, 1, &query_kernel_source, "query_kernel",
"-cl-std=CL2.0");
if (error != 0) return error;
// Determine some local dimensions to use for the test.
if (max_dimensions == 1) {
error = get_max_common_work_group_size(context, kernel, global[0], &local[0]);
if (max_dimensions == 1)
{
error = get_max_common_work_group_size(context, kernel, global[0],
&local[0]);
test_error(error, "get_max_common_work_group_size failed");
} else if (max_dimensions == 2) {
error = get_max_common_2D_work_group_size(context, kernel, global, local);
}
else if (max_dimensions == 2)
{
error =
get_max_common_2D_work_group_size(context, kernel, global, local);
test_error(error, "get_max_common_2D_work_group_size failed");
} else {
error = get_max_common_3D_work_group_size(context, kernel, global, local);
}
else
{
error =
get_max_common_3D_work_group_size(context, kernel, global, local);
test_error(error, "get_max_common_3D_work_group_size failed");
}
error = clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), (void *)&platform, NULL);
error = clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform),
(void *)&platform, NULL);
test_error(error, "clDeviceInfo failed for CL_DEVICE_PLATFORM");
clGetKernelSubGroupInfoKHR_fn clGetKernelSubGroupInfoKHR_ptr;
clGetKernelSubGroupInfoKHR_ptr = (clGetKernelSubGroupInfoKHR_fn)clGetExtensionFunctionAddressForPlatform(platform, "clGetKernelSubGroupInfoKHR");
if (clGetKernelSubGroupInfoKHR_ptr == NULL) {
clGetKernelSubGroupInfoKHR_ptr =
(clGetKernelSubGroupInfoKHR_fn)clGetExtensionFunctionAddressForPlatform(
platform, "clGetKernelSubGroupInfoKHR");
if (clGetKernelSubGroupInfoKHR_ptr == NULL)
{
log_error("ERROR: clGetKernelSubGroupInfoKHR function not available");
return -1;
}
error = clGetKernelSubGroupInfoKHR_ptr(kernel, device, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR,
sizeof(local), (void *)&local, sizeof(kernel_max_subgroup_size), (void *)&kernel_max_subgroup_size, &realSize);
test_error(error, "clGetKernelSubGroupInfoKHR failed for CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR");
log_info("The CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR for the kernel is %d.\n", (int)kernel_max_subgroup_size);
error = clGetKernelSubGroupInfoKHR_ptr(
kernel, device, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR,
sizeof(local), (void *)&local, sizeof(kernel_max_subgroup_size),
(void *)&kernel_max_subgroup_size, &realSize);
test_error(error,
"clGetKernelSubGroupInfoKHR failed for "
"CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR");
log_info("The CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR for the kernel "
"is %d.\n",
(int)kernel_max_subgroup_size);
if (realSize != sizeof(kernel_max_subgroup_size)) {
log_error( "ERROR: Returned size of max sub group size not valid! (Expected %d, got %d)\n", (int)sizeof(kernel_max_subgroup_size), (int)realSize );
if (realSize != sizeof(kernel_max_subgroup_size))
{
log_error("ERROR: Returned size of max sub group size not valid! "
"(Expected %d, got %d)\n",
(int)sizeof(kernel_max_subgroup_size), (int)realSize);
return -1;
}
error = clGetKernelSubGroupInfoKHR_ptr(kernel, device, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR,
sizeof(local), (void *)&local, sizeof(kernel_subgroup_count), (void *)&kernel_subgroup_count, &realSize);
test_error(error, "clGetKernelSubGroupInfoKHR failed for CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR");
log_info("The CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR for the kernel is %d.\n", (int)kernel_subgroup_count);
error = clGetKernelSubGroupInfoKHR_ptr(
kernel, device, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR,
sizeof(local), (void *)&local, sizeof(kernel_subgroup_count),
(void *)&kernel_subgroup_count, &realSize);
test_error(error,
"clGetKernelSubGroupInfoKHR failed for "
"CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR");
log_info(
"The CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR for the kernel is %d.\n",
(int)kernel_subgroup_count);
if (realSize != sizeof(kernel_subgroup_count)) {
log_error( "ERROR: Returned size of sub group count not valid! (Expected %d, got %d)\n", (int)sizeof(kernel_subgroup_count), (int)realSize );
if (realSize != sizeof(kernel_subgroup_count))
{
log_error("ERROR: Returned size of sub group count not valid! "
"(Expected %d, got %d)\n",
(int)sizeof(kernel_subgroup_count), (int)realSize);
return -1;
}
// Verify that the kernel gets the same max_subgroup_size and subgroup_count
out = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(result), NULL, &error);
out = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(result), NULL,
&error);
test_error(error, "clCreateBuffer failed");
error = clSetKernelArg(kernel, 0, sizeof(out), &out);
test_error(error, "clSetKernelArg failed");
error = clEnqueueNDRangeKernel(queue, kernel, max_dimensions, NULL, global, local, 0, NULL, NULL);
error = clEnqueueNDRangeKernel(queue, kernel, max_dimensions, NULL, global,
local, 0, NULL, NULL);
test_error(error, "clEnqueueNDRangeKernel failed");
error = clEnqueueReadBuffer(queue, out, CL_FALSE, 0, sizeof(result), &result, 0, NULL, NULL);
error = clEnqueueReadBuffer(queue, out, CL_FALSE, 0, sizeof(result),
&result, 0, NULL, NULL);
test_error(error, "clEnqueueReadBuffer failed");
error = clFinish(queue);
test_error(error, "clFinish failed");
for (i=0; i<(int)gsize0; ++i) {
if (result[i].maxSubGroupSize != (cl_uint)kernel_max_subgroup_size) {
log_error("ERROR: get_max_subgroup_size() doesn't match result from clGetKernelSubGroupInfoKHR, %u vs %u\n",
result[i].maxSubGroupSize, (cl_uint)kernel_max_subgroup_size);
for (i = 0; i < (int)gsize0; ++i)
{
if (result[i].maxSubGroupSize != (cl_uint)kernel_max_subgroup_size)
{
log_error("ERROR: get_max_subgroup_size() doesn't match result "
"from clGetKernelSubGroupInfoKHR, %u vs %u\n",
result[i].maxSubGroupSize,
(cl_uint)kernel_max_subgroup_size);
return -1;
}
if (result[i].numSubGroups != (cl_uint)kernel_subgroup_count) {
log_error("ERROR: get_num_sub_groups() doesn't match result from clGetKernelSubGroupInfoKHR, %u vs %u\n",
if (result[i].numSubGroups != (cl_uint)kernel_subgroup_count)
{
log_error("ERROR: get_num_sub_groups() doesn't match result from "
"clGetKernelSubGroupInfoKHR, %u vs %u\n",
result[i].numSubGroups, (cl_uint)kernel_subgroup_count);
return -1;
}
@@ -133,4 +176,3 @@ test_sub_group_info(cl_device_id device, cl_context context, cl_command_queue qu
return 0;
}