From c4bc17835470c23148ef1f2c84b802e8884d605e Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Thu, 19 Sep 2024 16:11:10 +0100 Subject: [PATCH] Add optional-query tag and auto-generate cts logic. --- include/ur_api.h | 55 ++++++------ scripts/core/device.yml | 28 +++--- scripts/core/kernel.yml | 4 +- scripts/core/program.yml | 4 +- scripts/core/queue.yml | 2 +- scripts/generate_code.py | 16 ++++ scripts/json2src.py | 4 + scripts/templates/helper.py | 36 +++++++- scripts/templates/optional_queries.h.mako | 46 ++++++++++ scripts/templates/tools-info.hpp.mako | 20 +++-- test/conformance/adapter/urAdapterGetInfo.cpp | 3 +- test/conformance/context/urContextGetInfo.cpp | 3 +- test/conformance/device/urDeviceGetInfo.cpp | 50 ++--------- .../enqueue_adapter_level_zero_v2.match | 10 --- test/conformance/event/urEventGetInfo.cpp | 3 +- .../event/urEventGetProfilingInfo.cpp | 5 +- .../kernel/urKernelGetGroupInfo.cpp | 13 +-- test/conformance/kernel/urKernelGetInfo.cpp | 13 +-- .../kernel/urKernelGetSubGroupInfo.cpp | 5 +- test/conformance/memory/urMemGetInfo.cpp | 2 +- test/conformance/memory/urMemImageGetInfo.cpp | 3 +- .../platform/urPlatformGetInfo.cpp | 3 +- .../program/urProgramGetBuildInfo.cpp | 5 +- test/conformance/program/urProgramGetInfo.cpp | 13 +-- test/conformance/queue/urQueueGetInfo.cpp | 70 +++++++-------- test/conformance/sampler/urSamplerGetInfo.cpp | 3 +- test/conformance/testing/include/uur/checks.h | 14 +++ .../testing/include/uur/optional_queries.h | 90 +++++++++++++++++++ test/conformance/usm/urUSMGetMemAllocInfo.cpp | 5 +- test/conformance/usm/urUSMPoolGetInfo.cpp | 3 +- .../virtual_memory/urVirtualMemGetInfo.cpp | 5 +- .../urVirtualMemGranularityGetInfo.cpp | 5 +- 32 files changed, 349 insertions(+), 192 deletions(-) create mode 100644 scripts/templates/optional_queries.h.mako create mode 100644 test/conformance/testing/include/uur/optional_queries.h diff --git a/include/ur_api.h b/include/ur_api.h index f765e75137..0bb0272bd2 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -1507,7 +1507,7 @@ typedef enum ur_device_info_t { UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE = 23, ///< [uint32_t] native vector width for double UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF = 24, ///< [uint32_t] native vector width for half float UR_DEVICE_INFO_MAX_CLOCK_FREQUENCY = 25, ///< [uint32_t] max clock frequency in MHz - UR_DEVICE_INFO_MEMORY_CLOCK_RATE = 26, ///< [uint32_t] memory clock frequency in MHz (optional) + UR_DEVICE_INFO_MEMORY_CLOCK_RATE = 26, ///< [uint32_t][optional-query] memory clock frequency in MHz UR_DEVICE_INFO_ADDRESS_BITS = 27, ///< [uint32_t] address bits UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE = 28, ///< [uint64_t] max memory allocation size UR_DEVICE_INFO_IMAGE_SUPPORTED = 29, ///< [::ur_bool_t] images are supported @@ -1531,7 +1531,8 @@ typedef enum ur_device_info_t { UR_DEVICE_INFO_GLOBAL_MEM_CACHELINE_SIZE = 44, ///< [uint32_t] global memory cache line size in bytes UR_DEVICE_INFO_GLOBAL_MEM_CACHE_SIZE = 45, ///< [uint64_t] size of global memory cache in bytes UR_DEVICE_INFO_GLOBAL_MEM_SIZE = 46, ///< [uint64_t] size of global memory in bytes - UR_DEVICE_INFO_GLOBAL_MEM_FREE = 47, ///< [uint64_t] size of global memory which is free in bytes (optional) + UR_DEVICE_INFO_GLOBAL_MEM_FREE = 47, ///< [uint64_t][optional-query] size of global memory which is free in + ///< bytes UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE = 48, ///< [uint64_t] max constant buffer size in bytes UR_DEVICE_INFO_MAX_CONSTANT_ARGS = 49, ///< [uint32_t] max number of __const declared arguments in a kernel UR_DEVICE_INFO_LOCAL_MEM_TYPE = 50, ///< [::ur_device_local_mem_type_t] local memory type @@ -1588,15 +1589,16 @@ typedef enum ur_device_info_t { ///< shared memory access UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT = 87, ///< [::ur_device_usm_access_capability_flags_t] support USM system wide ///< shared memory access - UR_DEVICE_INFO_UUID = 88, ///< [uint8_t[]] return device UUID (optional) - UR_DEVICE_INFO_PCI_ADDRESS = 89, ///< [char[]] return device PCI address (optional) - UR_DEVICE_INFO_GPU_EU_COUNT = 90, ///< [uint32_t] return Intel GPU EU count (optional) - UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 91, ///< [uint32_t] return Intel GPU EU SIMD width (optional) - UR_DEVICE_INFO_GPU_EU_SLICES = 92, ///< [uint32_t] return Intel GPU number of slices (optional) - UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE = 93, ///< [uint32_t] return Intel GPU EU count per subslice (optional) - UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE = 94, ///< [uint32_t] return Intel GPU number of subslices per slice (optional) - UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU = 95, ///< [uint32_t] return Intel GPU number of threads per EU (optional) - UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH = 96, ///< [uint32_t] return max memory bandwidth in Mb/s (optional) + UR_DEVICE_INFO_UUID = 88, ///< [uint8_t[]][optional-query] return device UUID + UR_DEVICE_INFO_PCI_ADDRESS = 89, ///< [char[]][optional-query] return device PCI address + UR_DEVICE_INFO_GPU_EU_COUNT = 90, ///< [uint32_t][optional-query] return Intel GPU EU count + UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 91, ///< [uint32_t][optional-query] return Intel GPU EU SIMD width + UR_DEVICE_INFO_GPU_EU_SLICES = 92, ///< [uint32_t][optional-query] return Intel GPU number of slices + UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE = 93, ///< [uint32_t][optional-query] return Intel GPU EU count per subslice + UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE = 94, ///< [uint32_t][optional-query] return Intel GPU number of subslices per + ///< slice + UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU = 95, ///< [uint32_t][optional-query] return Intel GPU number of threads per EU + UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH = 96, ///< [uint32_t][optional-query] return max memory bandwidth in Mb/s UR_DEVICE_INFO_IMAGE_SRGB = 97, ///< [::ur_bool_t] device supports sRGB images UR_DEVICE_INFO_BUILD_ON_SUBDEVICE = 98, ///< [::ur_bool_t] Return true if sub-device should do its own program ///< build @@ -1615,18 +1617,18 @@ typedef enum ur_device_info_t { ///< available for this device. UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS = 106, ///< [::ur_bool_t] support the ::urKernelSetSpecializationConstants entry ///< point - UR_DEVICE_INFO_MEMORY_BUS_WIDTH = 107, ///< [uint32_t] return the width in bits of the memory bus interface of the - ///< device (optional). + UR_DEVICE_INFO_MEMORY_BUS_WIDTH = 107, ///< [uint32_t][optional-query] return the width in bits of the memory bus + ///< interface of the device. UR_DEVICE_INFO_MAX_WORK_GROUPS_3D = 108, ///< [size_t[3]] return max 3D work groups UR_DEVICE_INFO_ASYNC_BARRIER = 109, ///< [::ur_bool_t] return true if Async Barrier is supported UR_DEVICE_INFO_MEM_CHANNEL_SUPPORT = 110, ///< [::ur_bool_t] return true if specifying memory channels is supported UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED = 111, ///< [::ur_bool_t] Return true if the device supports enqueueing commands ///< to read and write pipes from the host. - UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP = 112, ///< [uint32_t] The maximum number of registers available per block. - ///< (optional) - UR_DEVICE_INFO_IP_VERSION = 113, ///< [uint32_t] The device IP version. The meaning of the device IP version - ///< is implementation-defined, but newer devices should have a higher - ///< version than older devices. (optional) + UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP = 112, ///< [uint32_t][optional-query] The maximum number of registers available + ///< per block. + UR_DEVICE_INFO_IP_VERSION = 113, ///< [uint32_t][optional-query] The device IP version. The meaning of the + ///< device IP version is implementation-defined, but newer devices should + ///< have a higher version than older devices. UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT = 114, ///< [::ur_bool_t] return true if the device supports virtual memory. UR_DEVICE_INFO_ESIMD_SUPPORT = 115, ///< [::ur_bool_t] return true if the device supports ESIMD. UR_DEVICE_INFO_COMPONENT_DEVICES = 116, ///< [::ur_device_handle_t[]] The set of component devices contained by @@ -4495,9 +4497,10 @@ typedef enum ur_program_info_t { UR_PROGRAM_INFO_BINARY_SIZES = 5, ///< [size_t[]] Return program binary sizes for each device. UR_PROGRAM_INFO_BINARIES = 6, ///< [unsigned char[]] Return program binaries for all devices for this ///< Program. - UR_PROGRAM_INFO_NUM_KERNELS = 7, ///< [size_t] Number of kernels in Program, return type size_t (optional). - UR_PROGRAM_INFO_KERNEL_NAMES = 8, ///< [char[]] Return a null-terminated, semi-colon separated list of kernel - ///< names in Program (optional). + UR_PROGRAM_INFO_NUM_KERNELS = 7, ///< [size_t][optional-query] Number of kernels in Program, return type + ///< size_t. + UR_PROGRAM_INFO_KERNEL_NAMES = 8, ///< [char[]][optional-query] Return a null-terminated, semi-colon + ///< separated list of kernel names in Program. /// @cond UR_PROGRAM_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -4843,8 +4846,8 @@ typedef enum ur_kernel_info_t { UR_KERNEL_INFO_CONTEXT = 3, ///< [::ur_context_handle_t] Return Context object associated with Kernel. UR_KERNEL_INFO_PROGRAM = 4, ///< [::ur_program_handle_t] Return Program object associated with Kernel. UR_KERNEL_INFO_ATTRIBUTES = 5, ///< [char[]] Return null-terminated kernel attributes string. - UR_KERNEL_INFO_NUM_REGS = 6, ///< [uint32_t] Return the number of registers used by the compiled kernel - ///< (optional). + UR_KERNEL_INFO_NUM_REGS = 6, ///< [uint32_t][optional-query] Return the number of registers used by the + ///< compiled kernel. /// @cond UR_KERNEL_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -4854,7 +4857,7 @@ typedef enum ur_kernel_info_t { /////////////////////////////////////////////////////////////////////////////// /// @brief Get Kernel Work Group information typedef enum ur_kernel_group_info_t { - UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE = 0, ///< [size_t[3]] Return Work Group maximum global size (optional) + UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE = 0, ///< [size_t[3]][optional-query] Return Work Group maximum global size UR_KERNEL_GROUP_INFO_WORK_GROUP_SIZE = 1, ///< [size_t] Return maximum Work Group size UR_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE = 2, ///< [size_t[3]] Return Work Group size required by the source code, such ///< as __attribute__((required_work_group_size(X,Y,Z)), or (0, 0, 0) if @@ -5376,8 +5379,8 @@ typedef enum ur_queue_info_t { UR_QUEUE_INFO_SIZE = 5, ///< [uint32_t] The size of the queue on the device. Only a valid query ///< if the queue was created with the `ON_DEVICE` queue flag, otherwise ///< `::urQueueGetInfo` will return `::UR_RESULT_ERROR_INVALID_QUEUE`. - UR_QUEUE_INFO_EMPTY = 6, ///< [::ur_bool_t] return true if the queue was empty at the time of the - ///< query + UR_QUEUE_INFO_EMPTY = 6, ///< [::ur_bool_t][optional-query] return true if the queue was empty at + ///< the time of the query. /// @cond UR_QUEUE_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond diff --git a/scripts/core/device.yml b/scripts/core/device.yml index a37448ca78..6ef43ed0ee 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -248,7 +248,7 @@ etors: - name: MAX_CLOCK_FREQUENCY desc: "[uint32_t] max clock frequency in MHz" - name: MEMORY_CLOCK_RATE - desc: "[uint32_t] memory clock frequency in MHz (optional)" + desc: "[uint32_t][optional-query] memory clock frequency in MHz" - name: ADDRESS_BITS desc: "[uint32_t] address bits" - name: MAX_MEM_ALLOC_SIZE @@ -290,7 +290,7 @@ etors: - name: GLOBAL_MEM_SIZE desc: "[uint64_t] size of global memory in bytes" - name: GLOBAL_MEM_FREE - desc: "[uint64_t] size of global memory which is free in bytes (optional)" + desc: "[uint64_t][optional-query] size of global memory which is free in bytes" - name: MAX_CONSTANT_BUFFER_SIZE desc: "[uint64_t] max constant buffer size in bytes" - name: MAX_CONSTANT_ARGS @@ -377,23 +377,23 @@ etors: - name: USM_SYSTEM_SHARED_SUPPORT desc: "[$x_device_usm_access_capability_flags_t] support USM system wide shared memory access" - name: UUID - desc: "[uint8_t[]] return device UUID (optional)" + desc: "[uint8_t[]][optional-query] return device UUID" - name: PCI_ADDRESS - desc: "[char[]] return device PCI address (optional)" + desc: "[char[]][optional-query] return device PCI address" - name: GPU_EU_COUNT - desc: "[uint32_t] return Intel GPU EU count (optional)" + desc: "[uint32_t][optional-query] return Intel GPU EU count" - name: GPU_EU_SIMD_WIDTH - desc: "[uint32_t] return Intel GPU EU SIMD width (optional)" + desc: "[uint32_t][optional-query] return Intel GPU EU SIMD width" - name: GPU_EU_SLICES - desc: "[uint32_t] return Intel GPU number of slices (optional)" + desc: "[uint32_t][optional-query] return Intel GPU number of slices" - name: GPU_EU_COUNT_PER_SUBSLICE - desc: "[uint32_t] return Intel GPU EU count per subslice (optional)" + desc: "[uint32_t][optional-query] return Intel GPU EU count per subslice" - name: GPU_SUBSLICES_PER_SLICE - desc: "[uint32_t] return Intel GPU number of subslices per slice (optional)" + desc: "[uint32_t][optional-query] return Intel GPU number of subslices per slice" - name: GPU_HW_THREADS_PER_EU - desc: "[uint32_t] return Intel GPU number of threads per EU (optional)" + desc: "[uint32_t][optional-query] return Intel GPU number of threads per EU" - name: MAX_MEMORY_BANDWIDTH - desc: "[uint32_t] return max memory bandwidth in Mb/s (optional)" + desc: "[uint32_t][optional-query] return max memory bandwidth in Mb/s" - name: IMAGE_SRGB desc: "[$x_bool_t] device supports sRGB images" - name: BUILD_ON_SUBDEVICE @@ -418,7 +418,7 @@ etors: - name: KERNEL_SET_SPECIALIZATION_CONSTANTS desc: "[$x_bool_t] support the $xKernelSetSpecializationConstants entry point" - name: MEMORY_BUS_WIDTH - desc: "[uint32_t] return the width in bits of the memory bus interface of the device (optional)." + desc: "[uint32_t][optional-query] return the width in bits of the memory bus interface of the device." - name: MAX_WORK_GROUPS_3D desc: "[size_t[3]] return max 3D work groups" - name: ASYNC_BARRIER @@ -428,9 +428,9 @@ etors: - name: HOST_PIPE_READ_WRITE_SUPPORTED desc: "[$x_bool_t] Return true if the device supports enqueueing commands to read and write pipes from the host." - name: MAX_REGISTERS_PER_WORK_GROUP - desc: "[uint32_t] The maximum number of registers available per block. (optional)" + desc: "[uint32_t][optional-query] The maximum number of registers available per block." - name: IP_VERSION - desc: "[uint32_t] The device IP version. The meaning of the device IP version is implementation-defined, but newer devices should have a higher version than older devices. (optional)" + desc: "[uint32_t][optional-query] The device IP version. The meaning of the device IP version is implementation-defined, but newer devices should have a higher version than older devices." - name: VIRTUAL_MEMORY_SUPPORT desc: "[$x_bool_t] return true if the device supports virtual memory." - name: ESIMD_SUPPORT diff --git a/scripts/core/kernel.yml b/scripts/core/kernel.yml index aeee3e1cb5..204360ca57 100644 --- a/scripts/core/kernel.yml +++ b/scripts/core/kernel.yml @@ -124,7 +124,7 @@ etors: - name: ATTRIBUTES desc: "[char[]] Return null-terminated kernel attributes string." - name: NUM_REGS - desc: "[uint32_t] Return the number of registers used by the compiled kernel (optional)." + desc: "[uint32_t][optional-query] Return the number of registers used by the compiled kernel." --- #-------------------------------------------------------------------------- type: enum desc: "Get Kernel Work Group information" @@ -133,7 +133,7 @@ name: $x_kernel_group_info_t typed_etors: True etors: - name: GLOBAL_WORK_SIZE - desc: "[size_t[3]] Return Work Group maximum global size (optional)" + desc: "[size_t[3]][optional-query] Return Work Group maximum global size" - name: WORK_GROUP_SIZE desc: "[size_t] Return maximum Work Group size" - name: COMPILE_WORK_GROUP_SIZE diff --git a/scripts/core/program.yml b/scripts/core/program.yml index b144092b91..90d5e2f229 100644 --- a/scripts/core/program.yml +++ b/scripts/core/program.yml @@ -383,9 +383,9 @@ etors: - name: BINARIES desc: "[unsigned char[]] Return program binaries for all devices for this Program." - name: NUM_KERNELS - desc: "[size_t] Number of kernels in Program, return type size_t (optional)." + desc: "[size_t][optional-query] Number of kernels in Program, return type size_t." - name: KERNEL_NAMES - desc: "[char[]] Return a null-terminated, semi-colon separated list of kernel names in Program (optional)." + desc: "[char[]][optional-query] Return a null-terminated, semi-colon separated list of kernel names in Program." --- #-------------------------------------------------------------------------- type: function desc: "Query information about a Program object" diff --git a/scripts/core/queue.yml b/scripts/core/queue.yml index 263685d1aa..4668bcbb9a 100644 --- a/scripts/core/queue.yml +++ b/scripts/core/queue.yml @@ -37,7 +37,7 @@ etors: if the queue was created with the `ON_DEVICE` queue flag, otherwise `$xQueueGetInfo` will return `$X_RESULT_ERROR_INVALID_QUEUE`. - name: EMPTY - desc: "[$x_bool_t] return true if the queue was empty at the time of the query" + desc: "[$x_bool_t][optional-query] return true if the queue was empty at the time of the query." --- #-------------------------------------------------------------------------- type: enum desc: "Queue property flags" diff --git a/scripts/generate_code.py b/scripts/generate_code.py index 0c7476ab42..ecb150d447 100644 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -548,3 +548,19 @@ def generate_level_zero_queue_api(path, section, namespace, tags, version, specs specs=specs, meta=meta) print("QUEUE Generated %s lines of code.\n" % loc) + +def generate_cts_headers(path, section, namespace, tags, version, specs, meta): + template = "optional_queries.h.mako" + fin = os.path.join("templates", template) + name = "optional_queries" + filename = "optional_queries.h" + dstpath = os.path.join(path, "conformance", "testing", "include", "uur") + fout = os.path.join(dstpath, filename) + + print("Generating %s..." % fout) + + loc = util.makoWrite(fin, fout, + filename = name, namespace = namespace, + tags = tags, specs = specs, meta = meta) + + print("CTS Generated %s lines of code.\n" % loc) diff --git a/scripts/json2src.py b/scripts/json2src.py index df11f879ac..baff735d89 100755 --- a/scripts/json2src.py +++ b/scripts/json2src.py @@ -32,6 +32,7 @@ def add_argument(parser, name, help, default=False): add_argument(parser, "common", "generation of common files.", True) add_argument(parser, "tools", "generation of common files.", True) add_argument(parser, "l0_queue", "generation of l0 queue abstractions.", True) + add_argument(parser, "cts", "generation of cts headers", True) parser.add_argument("--debug", action='store_true', help="dump intermediate data to disk.") parser.add_argument("--sections", type=list, default=None, help="Optional list of sections for which to generate source, default is all") parser.add_argument("--ver", type=str, default="1.0", help="specification version to generate.") @@ -45,6 +46,7 @@ def add_argument(parser, name, help, default=False): srcpath = os.path.join(args.out_dir, "source") toolspath = os.path.join(args.out_dir, "tools") + testpath = os.path.join(args.out_dir, "test") for idx, specs in enumerate(input['specs']): config = input['configs'][idx] @@ -63,6 +65,8 @@ def add_argument(parser, name, help, default=False): generate_code.generate_tools(toolspath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta']) if args.l0_queue: generate_code.generate_level_zero_queue_api(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta']) + if args.cts: + generate_code.generate_cts_headers(testpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta']) if args.debug: util.makoFileListWrite("generated.json") diff --git a/scripts/templates/helper.py b/scripts/templates/helper.py index 9c08f8be11..415f5dd0c1 100644 --- a/scripts/templates/helper.py +++ b/scripts/templates/helper.py @@ -541,6 +541,18 @@ def is_global(item, tags): except: return False +""" + Extracts traits from an enum +""" +class enum_traits: + RE_OPTIONAL_QUERY = r".*\[optional-query\].*" + + @classmethod + def is_optional_query(cls, item): + try: + return True if re.match(cls.RE_OPTIONAL_QUERY, item['desc']) else False + except: + return False """ Public: @@ -780,11 +792,12 @@ def make_etor_name(namespace, tags, enum, etor, meta=None): returns the associated type of an etor from a typed enum """ def etor_get_associated_type(namespace, tags, item): - match = re.match(r'^\[(.+)\]\s', item['desc']) + match = re.match(r'^\[([$A-Za-z0-9_*[\] ]+)\]', item['desc']) if match: associated_type = match.group(1) return subt(namespace, tags, associated_type) else: + print("couldn't figure type from %s" % item['desc']) return None """ @@ -1692,3 +1705,24 @@ def transform_queue_related_function_name(namespace, tags, obj, format = ["name" params = params[1:] return "{}({})".format(function_name, ", ".join(params)) + +""" +Public: + Returns a dictionary mapping info enum types to the list of optional queries + within that enum. If an enum type doesn't have any optional queries it will + not appear in the dictionary as a key. +""" +def get_optional_queries(specs, namespace, tags): + optional_queries = {} + for s in specs: + for obj in s['objects']: + if obj['type'] == 'enum': + optional_etors = [] + for e in obj['etors']: + if enum_traits.is_optional_query(e): + name = make_enum_name(namespace, tags, e) + optional_etors.append(name) + if optional_etors: + type_name = make_type_name(namespace, tags, obj) + optional_queries[type_name] = optional_etors + return optional_queries diff --git a/scripts/templates/optional_queries.h.mako b/scripts/templates/optional_queries.h.mako new file mode 100644 index 0000000000..78b9b20610 --- /dev/null +++ b/scripts/templates/optional_queries.h.mako @@ -0,0 +1,46 @@ +<%! +import re +from templates import helper as th +%><% +optional_queries = th.get_optional_queries(specs, namespace, tags) +%> +/* + * + * Copyright (C) 2024 Intel Corporation + * + * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.TXT + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + * @file ${filename}.h + * + */ + + // Auto-generated file, do not edit. + +#pragma once + +#include +#include +#include + +namespace uur { + +template bool isQueryOptional(T) { return false; } + +%for type, names in optional_queries.items(): +constexpr std::array optional_${type} = { +%for name in names: + ${name}, +%endfor +}; + +template <> inline bool isQueryOptional(${type} query) { + return std::find(optional_${type}.begin(), + optional_${type}.end(), + query) != optional_${type}.end(); +} + +%endfor + +} diff --git a/scripts/templates/tools-info.hpp.mako b/scripts/templates/tools-info.hpp.mako index ed9d67bb34..cff5cb837f 100644 --- a/scripts/templates/tools-info.hpp.mako +++ b/scripts/templates/tools-info.hpp.mako @@ -32,8 +32,9 @@ namespace urinfo { inline void printLoaderConfigInfos(${x}_loader_config_handle_t hLoaderConfig, std::string_view prefix = " ") { %for etor in obj['etors']: %if 'REFERENCE_COUNT' not in etor['name']: - std::cout << prefix; - printLoaderConfigInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hLoaderConfig, ${etor['name'].replace('$X', X)}); + <%etype = th.etor_get_associated_type(n, tags, etor) + %>std::cout << prefix; + printLoaderConfigInfo<${etype}>(hLoaderConfig, ${etor['name'].replace('$X', X)}); %endif %endfor } @@ -42,8 +43,9 @@ inline void printLoaderConfigInfos(${x}_loader_config_handle_t hLoaderConfig, st inline void printAdapterInfos(${x}_adapter_handle_t hAdapter, std::string_view prefix = " ") { %for etor in obj['etors']: %if 'REFERENCE_COUNT' not in etor['name']: - std::cout << prefix; - printAdapterInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hAdapter, ${etor['name'].replace('$X', X)}); + <%etype = th.etor_get_associated_type(n, tags, etor) + %>std::cout << prefix; + printAdapterInfo<${etype}>(hAdapter, ${etor['name'].replace('$X', X)}); %endif %endfor } @@ -52,8 +54,9 @@ inline void printAdapterInfos(${x}_adapter_handle_t hAdapter, std::string_view p %if obj["name"] == '$x_platform_info_t': inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_view prefix = " ") { %for etor in obj['etors']: - std::cout << prefix; - printPlatformInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hPlatform, ${etor['name'].replace('$X', X)}); + <%etype = th.etor_get_associated_type(n, tags, etor) + %>std::cout << prefix; + printPlatformInfo<${etype}>(hPlatform, ${etor['name'].replace('$X', X)}); %endfor } @@ -61,11 +64,12 @@ inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_vie %if obj['name'] == '$x_device_info_t': inline void printDeviceInfos(${x}_device_handle_t hDevice, std::string_view prefix = " ") { %for etor in obj['etors']: - std::cout << prefix; + <%etype = th.etor_get_associated_type(n, tags, etor) + %>std::cout << prefix; %if etor['name'] == '$X_DEVICE_INFO_UUID': printDeviceUUID(hDevice, ${etor['name'].replace('$X', X)}); %else: - printDeviceInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hDevice, ${etor['name'].replace('$X', X)}); + printDeviceInfo<${etype}>(hDevice, ${etor['name'].replace('$X', X)}); %endif %endfor } diff --git a/test/conformance/adapter/urAdapterGetInfo.cpp b/test/conformance/adapter/urAdapterGetInfo.cpp index 6eea5182d8..9d7bd160c4 100644 --- a/test/conformance/adapter/urAdapterGetInfo.cpp +++ b/test/conformance/adapter/urAdapterGetInfo.cpp @@ -35,7 +35,8 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(urAdapterGetInfoTest, Success) { size_t size = 0; ur_adapter_info_t info_type = GetParam(); - ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS( + urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), info_type); ASSERT_NE(size, 0); if (const auto expected_size = adapter_info_size_map.find(info_type); diff --git a/test/conformance/context/urContextGetInfo.cpp b/test/conformance/context/urContextGetInfo.cpp index f9f699d511..0a318be779 100644 --- a/test/conformance/context/urContextGetInfo.cpp +++ b/test/conformance/context/urContextGetInfo.cpp @@ -43,7 +43,8 @@ UUR_TEST_SUITE_P(urContextGetInfoTestWithInfoParam, TEST_P(urContextGetInfoTestWithInfoParam, Success) { ur_context_info_t info = getParam(); size_t info_size = 0; - ASSERT_SUCCESS(urContextGetInfo(context, info, 0, nullptr, &info_size)); + ASSERT_QUERY_SUCCESS( + urContextGetInfo(context, info, 0, nullptr, &info_size), info); ASSERT_NE(info_size, 0); if (const auto expected_size = ctx_info_size_map.find(info); diff --git a/test/conformance/device/urDeviceGetInfo.cpp b/test/conformance/device/urDeviceGetInfo.cpp index a20e6eeb91..6f2ca4e2c0 100644 --- a/test/conformance/device/urDeviceGetInfo.cpp +++ b/test/conformance/device/urDeviceGetInfo.cpp @@ -270,52 +270,12 @@ bool doesReturnArray(ur_device_info_t info_type) { return false; } -const std::set optionalQueries{UR_DEVICE_INFO_MEMORY_CLOCK_RATE, - UR_DEVICE_INFO_GLOBAL_MEM_FREE, - UR_DEVICE_INFO_PCI_ADDRESS, - UR_DEVICE_INFO_UUID, - UR_DEVICE_INFO_GPU_EU_COUNT, - UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH, - UR_DEVICE_INFO_GPU_EU_SLICES, - UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE, - UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE, - UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU, - UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH, - UR_DEVICE_INFO_MEMORY_BUS_WIDTH, - UR_DEVICE_INFO_IP_VERSION, - UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP}; - TEST_P(urDeviceGetInfoTest, Success) { ur_device_info_t info_type = GetParam(); for (auto device : devices) { size_t size = 0; - auto result = urDeviceGetInfo(device, info_type, 0, nullptr, &size); - - if (result == UR_RESULT_SUCCESS) { - if (doesReturnArray(info_type) && size == 0) { - return; - } - ASSERT_NE(size, 0); - - if (const auto expected_size = device_info_size_map.find(info_type); - expected_size != device_info_size_map.end()) { - ASSERT_EQ(expected_size->second, size); - } - - std::vector info_data(size); - ASSERT_SUCCESS(urDeviceGetInfo(device, info_type, size, - info_data.data(), nullptr)); - - if (info_type == UR_DEVICE_INFO_PLATFORM) { - auto returned_platform = - reinterpret_cast(info_data.data()); - ASSERT_EQ(*returned_platform, platform); - } - } else { - ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION); - ASSERT_TRUE(optionalQueries.count(info_type)); - return; - } + ASSERT_QUERY_SUCCESS( + urDeviceGetInfo(device, info_type, 0, nullptr, &size), info_type); if (doesReturnArray(info_type) && size == 0) { return; @@ -330,6 +290,12 @@ TEST_P(urDeviceGetInfoTest, Success) { std::vector info_data(size); ASSERT_SUCCESS(urDeviceGetInfo(device, info_type, size, info_data.data(), nullptr)); + + if (info_type == UR_DEVICE_INFO_PLATFORM) { + auto returned_platform = + reinterpret_cast(info_data.data()); + ASSERT_EQ(*returned_platform, platform); + } } } diff --git a/test/conformance/enqueue/enqueue_adapter_level_zero_v2.match b/test/conformance/enqueue/enqueue_adapter_level_zero_v2.match index df2be32782..d20ebef18d 100644 --- a/test/conformance/enqueue/enqueue_adapter_level_zero_v2.match +++ b/test/conformance/enqueue/enqueue_adapter_level_zero_v2.match @@ -292,15 +292,5 @@ urEnqueueUSMAdviseTest.MultipleParamsSuccess/Intel_R__oneAPI_Unified_Runtime_ove urEnqueueUSMAdviseTest.NonCoherentDeviceMemorySuccessOrWarning/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urEnqueueUSMPrefetchWithParamTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_USM_MIGRATION_FLAG_DEFAULT urEnqueueUSMPrefetchWithParamTest.CheckWaitEvent/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_USM_MIGRATION_FLAG_DEFAULT -urEnqueueReadHostPipeTest.InvalidNullHandleQueue/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueReadHostPipeTest.InvalidNullHandleProgram/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueReadHostPipeTest.InvalidNullPointerPipeSymbol/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueReadHostPipeTest.InvalidNullPointerBuffer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueReadHostPipeTest.InvalidEventWaitList/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueWriteHostPipeTest.InvalidNullHandleQueue/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueWriteHostPipeTest.InvalidNullHandleProgram/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueWriteHostPipeTest.InvalidNullPointerPipeSymbol/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueWriteHostPipeTest.InvalidNullPointerBuffer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urEnqueueWriteHostPipeTest.InvalidEventWaitList/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urEnqueueTimestampRecordingExpTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urEnqueueTimestampRecordingExpTest.SuccessBlocking/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ diff --git a/test/conformance/event/urEventGetInfo.cpp b/test/conformance/event/urEventGetInfo.cpp index 4cca805cd0..2542ea7d27 100644 --- a/test/conformance/event/urEventGetInfo.cpp +++ b/test/conformance/event/urEventGetInfo.cpp @@ -11,7 +11,8 @@ TEST_P(urEventGetInfoTest, Success) { ur_event_info_t info_type = getParam(); size_t size; - ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size), + info_type); ASSERT_NE(size, 0); std::vector data(size); ASSERT_SUCCESS( diff --git a/test/conformance/event/urEventGetProfilingInfo.cpp b/test/conformance/event/urEventGetProfilingInfo.cpp index 7b91679dad..531cd82b6c 100644 --- a/test/conformance/event/urEventGetProfilingInfo.cpp +++ b/test/conformance/event/urEventGetProfilingInfo.cpp @@ -12,8 +12,9 @@ TEST_P(urEventGetProfilingInfoTest, Success) { ur_profiling_info_t info_type = getParam(); size_t size; - ASSERT_SUCCESS( - urEventGetProfilingInfo(event, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS( + urEventGetProfilingInfo(event, info_type, 0, nullptr, &size), + info_type); ASSERT_EQ(size, 8); std::vector data(size); diff --git a/test/conformance/kernel/urKernelGetGroupInfo.cpp b/test/conformance/kernel/urKernelGetGroupInfo.cpp index f6702ea27c..43f5dee56e 100644 --- a/test/conformance/kernel/urKernelGetGroupInfo.cpp +++ b/test/conformance/kernel/urKernelGetGroupInfo.cpp @@ -19,8 +19,6 @@ UUR_TEST_SUITE_P( UR_KERNEL_GROUP_INFO_PRIVATE_MEM_SIZE), uur::deviceTestWithParamPrinter); -const std::set optionalQueries{UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE}; - struct urKernelGetGroupInfoSingleTest : uur::urKernelTest { void SetUp() override { UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::SetUp()); @@ -43,14 +41,9 @@ TEST_P(urKernelGetGroupInfoTest, Success) { auto property_name = getParam(); size_t property_size = 0; std::vector property_value; - auto result = urKernelGetGroupInfo(kernel, device, property_name, 0, - nullptr, &property_size); - if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) { - ASSERT_TRUE(optionalQueries.count(property_name)); - return; - } else { - ASSERT_SUCCESS(result); - } + ASSERT_QUERY_SUCCESS(urKernelGetGroupInfo(kernel, device, property_name, 0, + nullptr, &property_size), + property_name); property_value.resize(property_size); ASSERT_SUCCESS(urKernelGetGroupInfo(kernel, device, property_name, property_size, property_value.data(), diff --git a/test/conformance/kernel/urKernelGetInfo.cpp b/test/conformance/kernel/urKernelGetInfo.cpp index b7a8da2c2c..51b20aca4d 100644 --- a/test/conformance/kernel/urKernelGetInfo.cpp +++ b/test/conformance/kernel/urKernelGetInfo.cpp @@ -15,8 +15,6 @@ UUR_TEST_SUITE_P( UR_KERNEL_INFO_NUM_REGS), uur::deviceTestWithParamPrinter); -const std::set optionalQueries{UR_KERNEL_INFO_NUM_REGS}; - using urKernelGetInfoSingleTest = uur::urKernelExecutionTest; UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelGetInfoSingleTest); @@ -24,14 +22,9 @@ TEST_P(urKernelGetInfoTest, Success) { auto property_name = getParam(); size_t property_size = 0; std::vector property_value; - auto result = - urKernelGetInfo(kernel, property_name, 0, nullptr, &property_size); - if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) { - ASSERT_TRUE(optionalQueries.count(property_name)); - return; - } else { - ASSERT_SUCCESS(result); - } + ASSERT_QUERY_SUCCESS( + urKernelGetInfo(kernel, property_name, 0, nullptr, &property_size), + property_name); property_value.resize(property_size); ASSERT_SUCCESS(urKernelGetInfo(kernel, property_name, property_size, property_value.data(), nullptr)); diff --git a/test/conformance/kernel/urKernelGetSubGroupInfo.cpp b/test/conformance/kernel/urKernelGetSubGroupInfo.cpp index fa4e045483..d20c6cfda8 100644 --- a/test/conformance/kernel/urKernelGetSubGroupInfo.cpp +++ b/test/conformance/kernel/urKernelGetSubGroupInfo.cpp @@ -27,8 +27,9 @@ TEST_P(urKernelGetSubGroupInfoTest, Success) { auto property_name = getParam(); size_t property_size = 0; std::vector property_value; - ASSERT_SUCCESS(urKernelGetSubGroupInfo(kernel, device, property_name, 0, - nullptr, &property_size)); + ASSERT_QUERY_SUCCESS(urKernelGetSubGroupInfo(kernel, device, property_name, + 0, nullptr, &property_size), + property_name); property_value.resize(property_size); ASSERT_SUCCESS(urKernelGetSubGroupInfo(kernel, device, property_name, property_size, property_value.data(), diff --git a/test/conformance/memory/urMemGetInfo.cpp b/test/conformance/memory/urMemGetInfo.cpp index a28b581a26..2a2a636a7c 100644 --- a/test/conformance/memory/urMemGetInfo.cpp +++ b/test/conformance/memory/urMemGetInfo.cpp @@ -21,7 +21,7 @@ UUR_TEST_SUITE_P(urMemGetInfoTest, ::testing::ValuesIn(mem_info_values), TEST_P(urMemGetInfoTest, Success) { ur_mem_info_t info = getParam(); size_t size; - ASSERT_SUCCESS(urMemGetInfo(buffer, info, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urMemGetInfo(buffer, info, 0, nullptr, &size), info); ASSERT_NE(size, 0); if (const auto expected_size = mem_info_size_map.find(info); diff --git a/test/conformance/memory/urMemImageGetInfo.cpp b/test/conformance/memory/urMemImageGetInfo.cpp index ae85720220..5ea4403b48 100644 --- a/test/conformance/memory/urMemImageGetInfo.cpp +++ b/test/conformance/memory/urMemImageGetInfo.cpp @@ -28,7 +28,8 @@ UUR_TEST_SUITE_P(urMemImageGetInfoTest, TEST_P(urMemImageGetInfoTest, Success) { ur_image_info_t info = getParam(); size_t size = 0; - ASSERT_SUCCESS(urMemImageGetInfo(image, info, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urMemImageGetInfo(image, info, 0, nullptr, &size), + info); ASSERT_NE(size, 0); if (const auto expected_size = image_info_size_map.find(info); diff --git a/test/conformance/platform/urPlatformGetInfo.cpp b/test/conformance/platform/urPlatformGetInfo.cpp index 1dc92b26d7..e29001fb87 100644 --- a/test/conformance/platform/urPlatformGetInfo.cpp +++ b/test/conformance/platform/urPlatformGetInfo.cpp @@ -29,7 +29,8 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(urPlatformGetInfoTest, Success) { size_t size = 0; ur_platform_info_t info_type = GetParam(); - ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS( + urPlatformGetInfo(platform, info_type, 0, nullptr, &size), info_type); if (info_type == UR_PLATFORM_INFO_BACKEND) { ASSERT_EQ(size, sizeof(ur_platform_backend_t)); } else { diff --git a/test/conformance/program/urProgramGetBuildInfo.cpp b/test/conformance/program/urProgramGetBuildInfo.cpp index 02faebcfb0..4bac844901 100644 --- a/test/conformance/program/urProgramGetBuildInfo.cpp +++ b/test/conformance/program/urProgramGetBuildInfo.cpp @@ -33,8 +33,9 @@ TEST_P(urProgramGetBuildInfoTest, Success) { auto property_name = getParam(); size_t property_size = 0; std::vector property_value; - ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, property_name, 0, - nullptr, &property_size)); + ASSERT_QUERY_SUCCESS(urProgramGetBuildInfo(program, device, property_name, + 0, nullptr, &property_size), + property_name); property_value.resize(property_size); ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, property_name, property_size, property_value.data(), diff --git a/test/conformance/program/urProgramGetInfo.cpp b/test/conformance/program/urProgramGetInfo.cpp index 81fd784f2f..4b799c3a6c 100644 --- a/test/conformance/program/urProgramGetInfo.cpp +++ b/test/conformance/program/urProgramGetInfo.cpp @@ -23,9 +23,6 @@ UUR_TEST_SUITE_P( UR_PROGRAM_INFO_KERNEL_NAMES), uur::deviceTestWithParamPrinter); -const std::set optionalQueries{UR_PROGRAM_INFO_NUM_KERNELS, - UR_PROGRAM_INFO_KERNEL_NAMES}; - struct urProgramGetInfoSingleTest : uur::urProgramTest { void SetUp() override { UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp()); @@ -55,13 +52,9 @@ TEST_P(urProgramGetInfoTest, Success) { sizeof(binaries[0]), binaries, nullptr)); } else { - auto result = urProgramGetInfo(program, property_name, 0, nullptr, - &property_size); - if (result != UR_RESULT_SUCCESS) { - ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION); - ASSERT_TRUE(optionalQueries.count(property_name)); - return; - } + ASSERT_QUERY_SUCCESS(urProgramGetInfo(program, property_name, 0, + nullptr, &property_size), + property_name); property_value.resize(property_size); ASSERT_SUCCESS(urProgramGetInfo(program, property_name, property_size, property_value.data(), nullptr)); diff --git a/test/conformance/queue/urQueueGetInfo.cpp b/test/conformance/queue/urQueueGetInfo.cpp index 03eb4b9df2..378da946b9 100644 --- a/test/conformance/queue/urQueueGetInfo.cpp +++ b/test/conformance/queue/urQueueGetInfo.cpp @@ -27,44 +27,41 @@ UUR_TEST_SUITE_P(urQueueGetInfoTestWithInfoParam, TEST_P(urQueueGetInfoTestWithInfoParam, Success) { ur_queue_info_t info_type = getParam(); size_t size = 0; - auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size); + ASSERT_QUERY_SUCCESS(urQueueGetInfo(queue, info_type, 0, nullptr, &size), + info_type); - if (result == UR_RESULT_SUCCESS) { - ASSERT_NE(size, 0); + ASSERT_NE(size, 0); - if (const auto expected_size = queue_info_size_map.find(info_type); - expected_size != queue_info_size_map.end()) { - ASSERT_EQ(expected_size->second, size); - } + if (const auto expected_size = queue_info_size_map.find(info_type); + expected_size != queue_info_size_map.end()) { + ASSERT_EQ(expected_size->second, size); + } - std::vector data(size); - ASSERT_SUCCESS( - urQueueGetInfo(queue, info_type, size, data.data(), nullptr)); - - switch (info_type) { - case UR_QUEUE_INFO_CONTEXT: { - auto returned_context = - reinterpret_cast(data.data()); - ASSERT_EQ(context, *returned_context); - break; - } - case UR_QUEUE_INFO_DEVICE: { - auto returned_device = - reinterpret_cast(data.data()); - ASSERT_EQ(*returned_device, device); - break; - } - case UR_QUEUE_INFO_REFERENCE_COUNT: { - auto returned_reference_count = - reinterpret_cast(data.data()); - ASSERT_GT(*returned_reference_count, 0U); - break; - } - default: - break; - } - } else { - ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION); + std::vector data(size); + ASSERT_SUCCESS( + urQueueGetInfo(queue, info_type, size, data.data(), nullptr)); + + switch (info_type) { + case UR_QUEUE_INFO_CONTEXT: { + auto returned_context = + reinterpret_cast(data.data()); + ASSERT_EQ(context, *returned_context); + break; + } + case UR_QUEUE_INFO_DEVICE: { + auto returned_device = + reinterpret_cast(data.data()); + ASSERT_EQ(*returned_device, device); + break; + } + case UR_QUEUE_INFO_REFERENCE_COUNT: { + auto returned_reference_count = + reinterpret_cast(data.data()); + ASSERT_GT(*returned_reference_count, 0U); + break; + } + default: + break; } } @@ -109,7 +106,8 @@ UUR_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam, TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Success) { ur_queue_info_t info_type = getParam(); size_t size = 0; - ASSERT_SUCCESS(urQueueGetInfo(queue, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urQueueGetInfo(queue, info_type, 0, nullptr, &size), + info_type); ASSERT_NE(size, 0); diff --git a/test/conformance/sampler/urSamplerGetInfo.cpp b/test/conformance/sampler/urSamplerGetInfo.cpp index e1f9326df7..bcba79eb35 100644 --- a/test/conformance/sampler/urSamplerGetInfo.cpp +++ b/test/conformance/sampler/urSamplerGetInfo.cpp @@ -18,7 +18,8 @@ UUR_TEST_SUITE_P(urSamplerGetInfoTestWithParam, TEST_P(urSamplerGetInfoTestWithParam, Success) { size_t size = 0; ur_sampler_info_t info = getParam(); - ASSERT_SUCCESS(urSamplerGetInfo(sampler, info, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urSamplerGetInfo(sampler, info, 0, nullptr, &size), + info); ASSERT_NE(size, 0); std::vector infoData(size); ASSERT_SUCCESS( diff --git a/test/conformance/testing/include/uur/checks.h b/test/conformance/testing/include/uur/checks.h index 2ad3925842..a6564fbced 100644 --- a/test/conformance/testing/include/uur/checks.h +++ b/test/conformance/testing/include/uur/checks.h @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace uur { @@ -46,6 +47,19 @@ inline std::ostream &operator<<(std::ostream &out, const Result &result) { #define EXPECT_SUCCESS(ACTUAL) EXPECT_EQ_RESULT(UR_RESULT_SUCCESS, ACTUAL) #endif +// This macro is intended to be used for the first call to a GetInfo query, it +// gracefully handles cases where the adapter doesn't support a query marked +// [optional-query] in the spec by returning early. +#ifndef ASSERT_QUERY_SUCCESS +#define ASSERT_QUERY_SUCCESS(CALL, QUERY) \ + auto result = CALL; \ + if (result != UR_RESULT_SUCCESS) { \ + ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION); \ + ASSERT_TRUE(uur::isQueryOptional(QUERY)); \ + return; \ + } +#endif + inline std::ostream &operator<<(std::ostream &out, const ur_device_handle_t &device) { out << uur::GetDeviceName(device); diff --git a/test/conformance/testing/include/uur/optional_queries.h b/test/conformance/testing/include/uur/optional_queries.h new file mode 100644 index 0000000000..8fb938c572 --- /dev/null +++ b/test/conformance/testing/include/uur/optional_queries.h @@ -0,0 +1,90 @@ + +/* + * + * Copyright (C) 2024 Intel Corporation + * + * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.TXT + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + * @file optional_queries.h + * + */ + +// Auto-generated file, do not edit. + +#pragma once + +#include +#include +#include + +namespace uur { + +template bool isQueryOptional(T) { return false; } + +constexpr std::array optional_ur_device_info_t = { + UR_DEVICE_INFO_MEMORY_CLOCK_RATE, + UR_DEVICE_INFO_GLOBAL_MEM_FREE, + UR_DEVICE_INFO_UUID, + UR_DEVICE_INFO_PCI_ADDRESS, + UR_DEVICE_INFO_GPU_EU_COUNT, + UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH, + UR_DEVICE_INFO_GPU_EU_SLICES, + UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE, + UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE, + UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU, + UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH, + UR_DEVICE_INFO_MEMORY_BUS_WIDTH, + UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, + UR_DEVICE_INFO_IP_VERSION, +}; + +template <> inline bool isQueryOptional(ur_device_info_t query) { + return std::find(optional_ur_device_info_t.begin(), + optional_ur_device_info_t.end(), + query) != optional_ur_device_info_t.end(); +} + +constexpr std::array optional_ur_program_info_t = { + UR_PROGRAM_INFO_NUM_KERNELS, + UR_PROGRAM_INFO_KERNEL_NAMES, +}; + +template <> inline bool isQueryOptional(ur_program_info_t query) { + return std::find(optional_ur_program_info_t.begin(), + optional_ur_program_info_t.end(), + query) != optional_ur_program_info_t.end(); +} + +constexpr std::array optional_ur_kernel_info_t = { + UR_KERNEL_INFO_NUM_REGS, +}; + +template <> inline bool isQueryOptional(ur_kernel_info_t query) { + return std::find(optional_ur_kernel_info_t.begin(), + optional_ur_kernel_info_t.end(), + query) != optional_ur_kernel_info_t.end(); +} + +constexpr std::array optional_ur_kernel_group_info_t = { + UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE, +}; + +template <> inline bool isQueryOptional(ur_kernel_group_info_t query) { + return std::find(optional_ur_kernel_group_info_t.begin(), + optional_ur_kernel_group_info_t.end(), + query) != optional_ur_kernel_group_info_t.end(); +} + +constexpr std::array optional_ur_queue_info_t = { + UR_QUEUE_INFO_EMPTY, +}; + +template <> inline bool isQueryOptional(ur_queue_info_t query) { + return std::find(optional_ur_queue_info_t.begin(), + optional_ur_queue_info_t.end(), + query) != optional_ur_queue_info_t.end(); +} + +} // namespace uur diff --git a/test/conformance/usm/urUSMGetMemAllocInfo.cpp b/test/conformance/usm/urUSMGetMemAllocInfo.cpp index 3a26236219..328a0a524b 100644 --- a/test/conformance/usm/urUSMGetMemAllocInfo.cpp +++ b/test/conformance/usm/urUSMGetMemAllocInfo.cpp @@ -34,8 +34,9 @@ static std::unordered_map usm_info_size_map = { TEST_P(urUSMAllocInfoTest, Success) { size_t size = 0; auto alloc_info = getParam(); - ASSERT_SUCCESS( - urUSMGetMemAllocInfo(context, ptr, alloc_info, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS( + urUSMGetMemAllocInfo(context, ptr, alloc_info, 0, nullptr, &size), + alloc_info); ASSERT_NE(size, 0); if (const auto expected_size = usm_info_size_map.find(alloc_info); diff --git a/test/conformance/usm/urUSMPoolGetInfo.cpp b/test/conformance/usm/urUSMPoolGetInfo.cpp index 945ce1b0b2..1b0a47c78b 100644 --- a/test/conformance/usm/urUSMPoolGetInfo.cpp +++ b/test/conformance/usm/urUSMPoolGetInfo.cpp @@ -22,7 +22,8 @@ UUR_TEST_SUITE_P(urUSMPoolGetInfoTestWithInfoParam, TEST_P(urUSMPoolGetInfoTestWithInfoParam, Success) { ur_usm_pool_info_t info_type = getParam(); size_t size = 0; - ASSERT_SUCCESS(urUSMPoolGetInfo(pool, info_type, 0, nullptr, &size)); + ASSERT_QUERY_SUCCESS(urUSMPoolGetInfo(pool, info_type, 0, nullptr, &size), + info_type); ASSERT_NE(size, 0); if (const auto expected_size = pool_info_size_map.find(info_type); diff --git a/test/conformance/virtual_memory/urVirtualMemGetInfo.cpp b/test/conformance/virtual_memory/urVirtualMemGetInfo.cpp index 79579e9297..de044775d1 100644 --- a/test/conformance/virtual_memory/urVirtualMemGetInfo.cpp +++ b/test/conformance/virtual_memory/urVirtualMemGetInfo.cpp @@ -13,8 +13,9 @@ UUR_TEST_SUITE_P(urVirtualMemGetInfoTestWithParam, TEST_P(urVirtualMemGetInfoTestWithParam, Success) { size_t info_size = 0; ur_virtual_mem_info_t info = getParam(); - ASSERT_SUCCESS(urVirtualMemGetInfo(context, virtual_ptr, size, info, 0, - nullptr, &info_size)); + ASSERT_QUERY_SUCCESS(urVirtualMemGetInfo(context, virtual_ptr, size, info, + 0, nullptr, &info_size), + info); ASSERT_NE(info_size, 0); std::vector data(info_size); diff --git a/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp b/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp index ddd1143a21..a850440224 100644 --- a/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp +++ b/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp @@ -28,8 +28,9 @@ UUR_TEST_SUITE_P( TEST_P(urVirtualMemGranularityGetInfoTest, Success) { size_t size = 0; ur_virtual_mem_granularity_info_t info = getParam(); - ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(context, device, info, 0, - nullptr, &size)); + ASSERT_QUERY_SUCCESS(urVirtualMemGranularityGetInfo(context, device, info, + 0, nullptr, &size), + info); ASSERT_NE(size, 0); std::vector infoData(size);