[llvm] [Offload] Introduce offload-tblgen and initial new API implementation (PR #108413)
Callum Fare via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 25 04:18:09 PDT 2024
https://github.com/callumfare updated https://github.com/llvm/llvm-project/pull/108413
>From 841d00229858f15476089d866c95ad3795d117a0 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 12 Sep 2024 15:32:27 +0100
Subject: [PATCH 01/14] [Offload] Introduce offload-tblgen and initial new API
implementation
---
offload/CMakeLists.txt | 3 +
offload/new-api/API/APIDefs.td | 212 ++++++++++++++++
offload/new-api/API/Common.td | 75 ++++++
offload/new-api/API/Device.td | 101 ++++++++
offload/new-api/API/OffloadAPI.td | 15 ++
offload/new-api/API/Platform.td | 94 ++++++++
offload/new-api/API/README.md | 150 ++++++++++++
offload/new-api/CMakeLists.txt | 36 +++
offload/new-api/README.md | 8 +
offload/new-api/src/helpers.hpp | 96 ++++++++
offload/new-api/src/offload_impl.cpp | 187 +++++++++++++++
offload/new-api/src/offload_lib.cpp | 23 ++
.../common/include/PluginInterface.h | 7 +
offload/tools/offload-tblgen/APIGen.cpp | 196 +++++++++++++++
offload/tools/offload-tblgen/CMakeLists.txt | 24 ++
.../tools/offload-tblgen/EntryPointGen.cpp | 86 +++++++
offload/tools/offload-tblgen/FuncsGen.cpp | 54 +++++
offload/tools/offload-tblgen/GenCommon.hpp | 58 +++++
offload/tools/offload-tblgen/Generators.hpp | 18 ++
offload/tools/offload-tblgen/PrintGen.cpp | 206 ++++++++++++++++
offload/tools/offload-tblgen/RecordTypes.hpp | 227 ++++++++++++++++++
.../tools/offload-tblgen/offload-tblgen.cpp | 95 ++++++++
22 files changed, 1971 insertions(+)
create mode 100644 offload/new-api/API/APIDefs.td
create mode 100644 offload/new-api/API/Common.td
create mode 100644 offload/new-api/API/Device.td
create mode 100644 offload/new-api/API/OffloadAPI.td
create mode 100644 offload/new-api/API/Platform.td
create mode 100644 offload/new-api/API/README.md
create mode 100644 offload/new-api/CMakeLists.txt
create mode 100644 offload/new-api/README.md
create mode 100644 offload/new-api/src/helpers.hpp
create mode 100644 offload/new-api/src/offload_impl.cpp
create mode 100644 offload/new-api/src/offload_lib.cpp
create mode 100644 offload/tools/offload-tblgen/APIGen.cpp
create mode 100644 offload/tools/offload-tblgen/CMakeLists.txt
create mode 100644 offload/tools/offload-tblgen/EntryPointGen.cpp
create mode 100644 offload/tools/offload-tblgen/FuncsGen.cpp
create mode 100644 offload/tools/offload-tblgen/GenCommon.hpp
create mode 100644 offload/tools/offload-tblgen/Generators.hpp
create mode 100644 offload/tools/offload-tblgen/PrintGen.cpp
create mode 100644 offload/tools/offload-tblgen/RecordTypes.hpp
create mode 100644 offload/tools/offload-tblgen/offload-tblgen.cpp
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 9ffe8f56b76e67..ba7be255cfe582 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -349,6 +349,9 @@ add_subdirectory(tools)
# Build target agnostic offloading library.
add_subdirectory(src)
+add_subdirectory(tools/offload-tblgen)
+add_subdirectory(new-api)
+
# Add tests.
add_subdirectory(test)
diff --git a/offload/new-api/API/APIDefs.td b/offload/new-api/API/APIDefs.td
new file mode 100644
index 00000000000000..410a28c4c90cfe
--- /dev/null
+++ b/offload/new-api/API/APIDefs.td
@@ -0,0 +1,212 @@
+//===-- APIDefs.td - Base definitions for Offload tablegen -*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the class definitions used to implement the Offload API,
+// as well as helper functions used to help populate relevant records.
+// See offload/API/README.md for more detailed documentation.
+//
+//===----------------------------------------------------------------------===//
+
+// Prefix for API naming. This could be hard-coded in the future when a value
+// is agreed upon.
+defvar PREFIX = "OFFLOAD";
+defvar prefix = !tolower(PREFIX);
+
+// Parameter flags
+defvar PARAM_IN = 0x1;
+defvar PARAM_OUT = 0x2;
+defvar PARAM_OPTIONAL = 0x4;
+defvar PARAM_IN_OPTIONAL = !or(PARAM_IN, PARAM_OPTIONAL);
+defvar PARAM_OUT_OPTIONAL = !or(PARAM_OUT, PARAM_OPTIONAL);
+
+// Does the type end with '_handle_t'?
+class IsHandleType<string Type> {
+ // size("_handle_t") == 9
+ bit ret = !if(!lt(!size(Type), 9), 0,
+ !ne(!find(Type, "_handle_t", !sub(!size(Type), 9)), -1));
+}
+
+// Does the type end with '*'?
+class IsPointerType<string Type> {
+ bit ret = !ne(!find(Type, "*", !sub(!size(Type), 1)), -1);
+}
+
+// Describes the valid range of a pointer parameter that reperesents an array
+class Range<string Begin, string End> {
+ string begin = Begin;
+ string end = End;
+}
+
+// Names the parameters that indicate the type and size of the data pointed to
+// by an opaque pointer parameter
+class TypeInfo<string TypeEnum, string TypeSize> {
+ string enum = TypeEnum;
+ string size = TypeSize;
+}
+
+class Param<string Type, string Name, string Desc, bits<3> Flags = 0> {
+ string type = Type;
+ string name = Name;
+ string desc = Desc;
+ bits<3> flags = Flags;
+ Range range = Range<"", "">;
+ TypeInfo type_info = TypeInfo<"", "">;
+ bit IsHandle = IsHandleType<type>.ret;
+ bit IsPointer = IsPointerType<type>.ret;
+}
+
+// A parameter whose range is described by other parameters in the function.
+class RangedParam<string Type, string Name, string Desc, bits<3> Flags, Range ParamRange> : Param<Type, Name, Desc, Flags> {
+ let range = ParamRange;
+}
+
+// A parameter (normally of type void*) which has its pointee type and size
+// described by other parameters in the function.
+class TypeTaggedParam<string Type, string Name, string Desc, bits<3> Flags, TypeInfo ParamTypeInfo> : Param<Type, Name, Desc, Flags> {
+ let type_info = ParamTypeInfo;
+}
+
+class Return<string Value, list<string> Conditions = []> {
+ string value = Value;
+ list<string> conditions = Conditions;
+}
+
+class ShouldCheckHandle<Param P> {
+ bit ret = !and(P.IsHandle, !eq(!and(PARAM_OPTIONAL, P.flags), 0));
+}
+
+class ShouldCheckPointer<Param P> {
+ bit ret = !and(P.IsPointer, !eq(!and(PARAM_OPTIONAL, P.flags), 0));
+}
+
+// For a list of returns that contains a specific return code, find and append
+// new conditions to that return
+class AppendConditionsToReturn<list<Return> Returns, string ReturnValue,
+ list<string> Conditions> {
+ list<Return> ret =
+ !foreach(Ret, Returns,
+ !if(!eq(Ret.value, ReturnValue),
+ Return<Ret.value, Ret.conditions#Conditions>, Ret));
+}
+
+// Add null handle checks to a function's return value descriptions
+class AddHandleChecksToReturns<list<Param> Params, list<Return> Returns> {
+ list<string> handle_params =
+ !foreach(P, Params, !if(ShouldCheckHandle<P>.ret, P.name, ""));
+ list<string> handle_params_filt =
+ !filter(param, handle_params, !ne(param, ""));
+ list<string> handle_param_conds =
+ !foreach(handle, handle_params_filt, "`NULL == "#handle#"`");
+
+ // Does the list of returns already contain ERROR_INVALID_NULL_HANDLE?
+ bit returns_has_inv_handle = !foldl(
+ 0, Returns, HasErr, Ret,
+ !or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_HANDLE")));
+
+ list<Return> returns_out = !if(returns_has_inv_handle,
+ AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>.ret,
+ !listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>])
+ );
+}
+
+// Add null pointer checks to a function's return value descriptions
+class AddPointerChecksToReturns<list<Param> Params, list<Return> Returns> {
+ list<string> ptr_params =
+ !foreach(P, Params, !if(ShouldCheckPointer<P>.ret, P.name, ""));
+ list<string> ptr_params_filt = !filter(param, ptr_params, !ne(param, ""));
+ list<string> ptr_param_conds =
+ !foreach(ptr, ptr_params_filt, "`NULL == "#ptr#"`");
+
+ // Does the list of returns already contain ERROR_INVALID_NULL_POINTER?
+ bit returns_has_inv_ptr = !foldl(
+ 0, Returns, HasErr, Ret,
+ !or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_POINTER")));
+ list<Return> returns_out = !if(returns_has_inv_ptr,
+ AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>.ret,
+ !listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>])
+ );
+}
+
+defvar DefaultReturns = [Return<PREFIX#"_RESULT_SUCCESS">,
+ Return<PREFIX#"_RESULT_ERROR_UNINITIALIZED">,
+ Return<PREFIX#"_RESULT_ERROR_DEVICE_LOST">];
+
+class APIObject {
+ string name;
+ string desc;
+}
+
+class Function : APIObject {
+ list<Param> params;
+ list<Return> returns;
+ list<string> details = [];
+ list<string> analogues = [];
+
+ list<Return> returns_with_def = !listconcat(DefaultReturns, returns);
+ list<Return> all_returns = AddPointerChecksToReturns<params,
+ AddHandleChecksToReturns<params, returns_with_def>.returns_out>.returns_out;
+}
+
+class Etor<string Name, string Desc> {
+ string name = Name;
+ string desc = Desc;
+ string tagged_type;
+}
+
+class TaggedEtor<string Name, string Type, string Desc> : Etor<Name, Desc> {
+ let tagged_type = Type;
+}
+
+class Enum : APIObject {
+ // This refers to whether the enumerator descriptions specify a return
+ // type for functions where this enum may be used as an output type. If set,
+ // all Etor values must be TaggedEtor records
+ bit is_typed = 0;
+
+ list<Etor> etors = [];
+}
+
+class StructMember<string Type, string Name, string Desc> {
+ string type = Type;
+ string name = Name;
+ string desc = Desc;
+}
+
+defvar DefaultPropStructMembers =
+ [StructMember<prefix#"_structure_type_t", "stype",
+ "type of this structure">,
+ StructMember<"void*", "pNext", "pointer to extension-specific structure">];
+
+class StructHasInheritedMembers<string BaseClass> {
+ bit ret = !or(!eq(BaseClass, prefix#"_base_properties_t"),
+ !eq(BaseClass, prefix#"_base_desc_t"));
+}
+
+class Struct : APIObject {
+ string base_class = "";
+ list<StructMember> members;
+ list<StructMember> all_members =
+ !if(StructHasInheritedMembers<base_class>.ret,
+ DefaultPropStructMembers, [])#members;
+}
+
+class Typedef : APIObject { string value; }
+
+class FptrTypedef : APIObject {
+ list<Param> params;
+ list<Return> returns;
+}
+
+class Macro : APIObject {
+ string value;
+
+ string condition;
+ string alt_value;
+}
+
+class Handle : APIObject;
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
new file mode 100644
index 00000000000000..d293e4addfef8b
--- /dev/null
+++ b/offload/new-api/API/Common.td
@@ -0,0 +1,75 @@
+def : Macro {
+ let name = "OFFLOAD_APICALL";
+ let desc = "Calling convention for all API functions";
+ let condition = "defined(_WIN32)";
+ let value = "__cdecl";
+ let alt_value = "";
+}
+
+def : Macro {
+ let name = "OFFLOAD_APIEXPORT";
+ let desc = "Microsoft-specific dllexport storage-class attribute";
+ let condition = "defined(_WIN32)";
+ let value = "__declspec(dllexport)";
+ let alt_value = "";
+}
+
+def : Macro {
+ let name = "OFFLOAD_DLLEXPORT";
+ let desc = "Microsoft-specific dllexport storage-class attribute";
+ let condition = "defined(_WIN32)";
+ let value = "__declspec(dllexport)";
+}
+
+def : Macro {
+ let name = "OFFLOAD_DLLEXPORT";
+ let desc = "GCC-specific dllexport storage-class attribute";
+ let condition = "__GNUC__ >= 4";
+ let value = "__attribute__ ((visibility (\"default\")))";
+ let alt_value = "";
+}
+
+def : Typedef {
+ let name = "offload_bool_t";
+ let value = "uint8_t";
+ let desc = "compiler-independent type";
+}
+
+def : Handle {
+ let name = "offload_platform_handle_t";
+ let desc = "Handle of a platform instance";
+}
+
+def : Handle {
+ let name = "offload_device_handle_t";
+ let desc = "Handle of platform's device object";
+}
+
+def : Handle {
+ let name = "offload_context_handle_t";
+ let desc = "Handle of context object";
+}
+
+def : Enum {
+ let name = "offload_result_t";
+ let desc = "Defines Return/Error codes";
+ let etors =[
+ Etor<"SUCCESS", "Success">,
+ Etor<"ERROR_INVALID_VALUE", "Invalid Value">,
+ Etor<"ERROR_INVALID_PLATFORM", "Invalid platform">,
+ Etor<"ERROR_DEVICE_NOT_FOUND", "Device not found">,
+ Etor<"ERROR_INVALID_DEVICE", "Invalid device">,
+ Etor<"ERROR_DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
+ Etor<"ERROR_UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
+ Etor<"ERROR_OUT_OF_RESOURCES", "Out of resources">,
+ Etor<"ERROR_UNSUPPORTED_VERSION", "[Validation] generic error code for unsupported versions">,
+ Etor<"ERROR_UNSUPPORTED_FEATURE", "[Validation] generic error code for unsupported features">,
+ Etor<"ERROR_INVALID_ARGUMENT", "[Validation] generic error code for invalid arguments">,
+ Etor<"ERROR_INVALID_NULL_HANDLE", "[Validation] handle argument is not valid">,
+ Etor<"ERROR_INVALID_NULL_POINTER", "[Validation] pointer argument may not be nullptr">,
+ Etor<"ERROR_INVALID_SIZE", "[Validation] invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
+ Etor<"ERROR_INVALID_ENUMERATION", "[Validation] enumerator argument is not valid">,
+ Etor<"ERROR_UNSUPPORTED_ENUMERATION", "[Validation] enumerator argument is not supported by the device">,
+ Etor<"ERROR_UNKNOWN", "Unknown or internal error">
+ ];
+}
\ No newline at end of file
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
new file mode 100644
index 00000000000000..2a330d7ef7c4cb
--- /dev/null
+++ b/offload/new-api/API/Device.td
@@ -0,0 +1,101 @@
+//===-- Device.td - Device definitions for Offload ---------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains Offload API definitions related to the Device handle
+//
+//===----------------------------------------------------------------------===//
+
+def : Enum {
+ let name = "offload_device_type_t";
+ let desc = "Supported device types";
+ let etors =[
+ Etor<"DEFAULT", "The default device type as preferred by the runtime">,
+ Etor<"ALL", "Devices of all types">,
+ Etor<"GPU", "GPU device type">,
+ Etor<"CPU", "CPU device type">,
+ ];
+}
+
+def : Enum {
+ let name = "offload_device_info_t";
+ let desc = "Supported device info";
+ let is_typed = 1;
+ let etors =[
+ TaggedEtor<"TYPE", "offload_device_type_t", "type of the device">,
+ TaggedEtor<"PLATFORM", "offload_platform_handle_t", "the platform associated with the device">,
+ TaggedEtor<"NAME", "char[]", "Device name">,
+ TaggedEtor<"VENDOR", "char[]", "Device vendor">,
+ TaggedEtor<"DRIVER_VERSION", "char[]", "Driver version">
+ ];
+}
+
+def : Function {
+ let name = "offloadDeviceGet";
+ let desc = "Retrieves devices within a platform";
+ let details = [
+ "Multiple calls to this function will return identical device handles, in the same order.",
+ "The number and order of handles returned from this function can be affected by environment variables that filter devices exposed through API.",
+ "The returned devices are taken a reference of and must be released with a subsequent call to olDeviceRelease.",
+ "The application may call this function from simultaneous threads, the implementation must be thread-safe"
+ ];
+ let params = [
+ Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
+ Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
+ Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices."
+ "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE"
+ "will be returned.", PARAM_IN>,
+ RangedParam<"offload_device_handle_t*", "phDevices", "array of handle of devices."
+ "If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
+ Range<"0", "NumEntries">>,
+ Param<"uint32_t*", "pNumDevices", "pointer to the number of devices."
+ "pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
+ ];
+ let returns = [
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ "`NumEntries == 0 && phDevices != NULL`"
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ "`NumEntries > 0 && phDevices == NULL`"
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_VALUE">
+ ];
+}
+
+def : Function {
+ let name = "offloadDeviceGetInfo";
+ let desc = "Retrieves various information about device";
+ let details = [
+ "The application may call this function from simultaneous threads.",
+ "The implementation of this function should be lock-free."
+ ];
+ let params = [
+ Param<"offload_device_handle_t", "hDevice", "handle of the device instance", PARAM_IN>,
+ Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
+ TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
+ "number of bytes needed to return the info then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and "
+ "pPropValue is not used.", PARAM_OUT_OPTIONAL, TypeInfo<"propName" , "propSize">>,
+ Param<"size_t*", "pPropSizeRet", "pointer to the actual size in bytes of the queried propName.", PARAM_OUT_OPTIONAL>
+ ];
+ let returns = [
+ Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
+ "If `propName` is not supported by the adapter."
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ "`propSize == 0 && pPropValue != NULL`",
+ "If `propSize` is less than the real number of bytes needed to return the info."
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ "`propSize != 0 && pPropValue == NULL`",
+ "`pPropValue == NULL && pPropSizeRet == NULL`"
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_DEVICE">,
+ Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
+ Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
+ ];
+}
diff --git a/offload/new-api/API/OffloadAPI.td b/offload/new-api/API/OffloadAPI.td
new file mode 100644
index 00000000000000..8a0c3c40581223
--- /dev/null
+++ b/offload/new-api/API/OffloadAPI.td
@@ -0,0 +1,15 @@
+//===-- OffloadAPI.td - Root tablegen file for Offload -----*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Always include this file first
+include "APIDefs.td"
+
+// Add API definition files here
+include "Common.td"
+include "Platform.td"
+include "Device.td"
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
new file mode 100644
index 00000000000000..71af04bb831998
--- /dev/null
+++ b/offload/new-api/API/Platform.td
@@ -0,0 +1,94 @@
+//===-- Platform.td - Platform definitions for Offload -----*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains Offload API definitions related to the Platform handle
+//
+//===----------------------------------------------------------------------===//
+def : Function {
+ let name = "offloadPlatformGet";
+ let desc = "Retrieves all available platforms";
+ let details = [
+ "Multiple calls to this function will return identical platforms handles, in the same order.",
+ ];
+ let params = [
+ Param<"uint32_t", "NumEntries",
+ "The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then"
+ "NumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE"
+ "will be returned.", PARAM_IN>,
+ RangedParam<"offload_platform_handle_t*", "phPlatforms",
+ "Array of handle of platforms. If NumEntries is"
+ "less than the number of platforms available, then offloadPlatformGet"
+ "shall only retrieve that number of platforms.",
+ PARAM_OUT_OPTIONAL, Range<"0", "NumEntries">>,
+ Param<"uint32_t*",
+ "pNumPlatforms", "returns the total number of platforms available.",
+ PARAM_OUT_OPTIONAL>
+ ];
+ let returns = [
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ "`NumEntries == 0 && phPlatforms != NULL`"
+ ]>
+ ];
+}
+
+def : Enum {
+ let name = "offload_platform_info_t";
+ let desc = "Supported platform info";
+ let is_typed = 1;
+ let etors = [
+ TaggedEtor<"NAME", "char[]", "The string denoting name of the platform. The size of the info needs to be dynamically queried.">,
+ TaggedEtor<"VENDOR_NAME", "char[]","The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.">,
+ TaggedEtor<"VERSION", "char[]", "The string denoting the version of the platform. The size of the info needs to be dynamically queried.">,
+ TaggedEtor<"BACKEND", "offload_platform_backend_t", "The backend of the platform. Identifies the native backend adapter implementing this platform.">
+ ];
+}
+
+def : Enum {
+ let name = "offload_platform_backend_t";
+ let desc = "Identifies the native backend of the platform";
+ let etors =[
+ Etor<"UNKNOWN", "The backend is not recognized">,
+ Etor<"CUDA", "The backend is CUDA">,
+ Etor<"AMDGPU", "The backend is AMDGPU">,
+ ];
+}
+
+def : Function {
+ let name = "offloadPlatformGetInfo";
+ let desc = "Retrieves various information about platform";
+ let details = [
+ "The application may call this function from simultaneous threads.",
+ "The implementation of this function should be lock-free."
+ ];
+ let params = [
+ Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
+ Param<"offload_platform_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
+ TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info."
+ "If Size is not equal to or greater to the real number of bytes needed to return the info"
+ "then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
+ TypeInfo<"propName" , "propSize">>,
+ Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
+ ];
+ let returns = [
+ Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
+ "If `propName` is not supported by the platform."
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ "`propSize == 0 && pPropValue != NULL`",
+ "If `propSize` is less than the real number of bytes needed to return the info."
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ "`propSize != 0 && pPropValue == NULL`",
+ "`pPropValue == NULL && pPropSizeRet == NULL`"
+ ]>,
+ Return<"OFFLOAD_RESULT_ERROR_INVALID_PLATFORM">,
+ Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
+ Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
+ ];
+}
diff --git a/offload/new-api/API/README.md b/offload/new-api/API/README.md
new file mode 100644
index 00000000000000..ab1db704404f35
--- /dev/null
+++ b/offload/new-api/API/README.md
@@ -0,0 +1,150 @@
+# Offload API definitions
+
+**Note**: This is a work-in-progress. It is loosely based on equivalent
+tooling in Unified Runtime.
+
+The Tablegen files in this directory are used to define the Offload API. They
+are used with the `offload-tblgen` tool to generate API headers, print headers,
+and other implementation details.
+
+The root file is `OffloadAPI.td` - additional `.td` files can be included in
+this file to add them to the API.
+
+## API Objects
+The API consists of a number of objects, which always have a *name* field and
+*description* field, and are one of the following types:
+
+### Function
+Represents an API entry point function. Has a list of returns and parameters.
+Also has fields for details (representing a bullet-point list of
+information about the function that would otherwise be too detailed for the
+description), and analogues (equivalent functions in other APIs).
+
+#### Parameter
+Represents a parameter to a function, has *type*, *name*, and *desc* fields.
+Also has a *flags* field containing flags representing whether the parameter is
+in, out, or optional.
+
+The *type* field is used to infer if the parameter is a pointer or handle type.
+A *handle* type is a pointer to an opaque struct, used to abstract over
+plugin-specific implementation details.
+
+There are two special variants of a *parameter*:
+* **RangedParameter** - Represents a parameter that has a range described by other parameters. Generally these are pointers to an arbitrary number of objects. The range is used for generating validation and printing code. E.g, a range might be between `(0, NumDevices)`
+* **TypeTaggedParameter** - Represents a parameter (usually of `void*` type) that has the type and size of its pointee data described by other function parameters. The type is usually described by a type-tagged enum. This allows functions (e.g. `offloadDeviceGetInfo`) to return data of an arbitrary type.
+
+#### Return
+A return represents a possible return code from the function, and optionally a
+list of conditions in which this value may be returned. The conditions list is
+not expected to be exhaustive. A condition is considered free-form text, but
+if it is wrapped in \`backticks\` then it is treated as literal code
+representing an error condition (e.g. `someParam < 1`). These conditions are
+used to automatically create validation checks by the `offload-tblgen`
+validation generator.
+
+Returns are automatically generated for functions with pointer or handle
+parameters, so API authors do not need to exhaustively add null checks for
+these types of parameters. All functions also get a number of default return
+values automatically.
+
+
+### Struct
+Represents a struct. Contains a list of members, which each have a *type*,
+*name*, and *desc*.
+
+Also optionally takes a *base_class* field. If this is either of the special
+`offload_base_properties_t` or `offload_base_desc_t` structs, then the struct
+will inherit members from those structs. The generated struct does **not** use
+actual C++ inheritance, but instead explicitly has those members copied in,
+which preserves ABI compatibility with C.
+
+### Enum
+Represents a C-style enum. Contains a list of `etor` values, which have a name
+and description.
+
+A `TaggedEtor` record type also exists which addtionally takes a type. This type
+is used when the enum is used as a parameter to a function with a type-tagged
+function parameter (e.g. `offloadDeviceGetInfo`).
+
+All enums automatically get a `<enum_name>_FORCE_UINT32 = 0x7fffffff` value,
+which forces the underlying type to be uint32.
+
+### Handle
+Represents a pointer to an opaque struct, as described in the Parameter section.
+It does not take any extra fields.
+
+### Typedef
+Represents a typedef, contains only a *value* field.
+
+### Macro
+Represents a C preprocessor `#define`. Contains a *value* field. Optionally
+takes a *condition* field, which allows the macro to be conditionally defined,
+and an *alt_value* field, which represents the value if the condition is false.
+
+Macro arguments are presented in the *name* field (e.g. name = `mymacro(arg)`).
+
+While there may seem little point generating a macro from tablegen, doing this
+allows the entire source of the header file to be generated from the tablegen
+files, rather than requiring a mix of C source and tablegen.
+
+## Generation
+
+### API header
+```
+./offload-tblgen -I <path-to-llvm>/offload/API <path-to-llvm>/offload/API/OffloadAPI.td --gen-api
+```
+The comments in the generated header are in Doxygen format, although
+generating documentation from them hasn't been implemented yet.
+
+The entirety of this header is generated by Tablegen, rather than having a predefined header file that includes one or more `.inc` files. This is because this header is expected to be part of the installation and distributed to end-users, so should be self-contained.
+
+### Entry Points
+```
+./offload-tblgen -I <path-to-llvm>/offload/API <path-to-llvm>/offload/API/OffloadAPI.td --gen-entry-points
+```
+These functions form the actual Offload interface, and are wrappers over the
+functions that contain the actual implementation (see
+'Adding a new entry point').
+
+They implement automatically generated validation checks, and tracing of
+function calls with arguments and results. The tracing can be enabled with the
+`OFFLOAD_TRACE` environment variable.
+
+### Implementation function declarations
+```
+./offload-tblgen -I <path-to-llvm>/offload/API <path-to-llvm>/offload/API/OffloadAPI.td --gen-impl-func-decls
+```
+Generates declarations of the implementation of functions of every entry point
+in the API, e.g. `offloadDeviceFoo_impl` for `offloadDeviceFoo`.
+
+### Print header
+```
+./offload-tblgen -I <path-to-llvm>/offload/API <path-to-llvm>/offload/API/OffloadAPI.td --gen-print-header
+```
+This header contains `std::ostream &operator<<(std::ostream&)` definitions for
+various API objects, including function parameters.
+
+As with the API header, it is expected that this header is part of the installed
+package, so it is entirely generated by Tablegen.
+
+For ease of implementation, and since it is not strictly part of the API, this
+is a C++ header file. If a C version is desirable it could be added.
+
+### Future Tablegen backends
+`RecordTypes.hpp` contains wrappers for all of the API object types, which will
+allow more backends to be easily added in future.
+
+## Adding to the API
+
+A new object can be added to the API by adding to one of the existing `.td`
+files. It is also possible to add a new tablegen file to the API by adding it
+to the includes in `OffloadAPI.td`. When the offload target is rebuilt, the
+new definition will be included in the generated files.
+
+### Adding a new entry point
+
+When a new entry point is added (e.g. `offloadDeviceFoo`), the actual entry
+point is automatically generated, which contains validation and tracing code.
+It expects an implementation function (`offloadDeviceFoo_impl`) to be defined,
+which it will call into. The definition of this implementation function should
+be added to `src/offload_impl.cpp`
\ No newline at end of file
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
new file mode 100644
index 00000000000000..c27591d2af3ab3
--- /dev/null
+++ b/offload/new-api/CMakeLists.txt
@@ -0,0 +1,36 @@
+
+set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/API/OffloadAPI.td)
+list(APPEND LLVM_TABLEGEN_FLAGS -I ${CMAKE_CURRENT_SOURCE_DIR}/API)
+
+tablegen(OFFLOAD offload_api.h -gen-api)
+tablegen(OFFLOAD offload_funcs.inc -gen-func-names)
+tablegen(OFFLOAD offload_impl_func_decls.inc -gen-impl-func-decls)
+tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
+tablegen(OFFLOAD offload_print.hpp -gen-print-header)
+
+
+add_public_tablegen_target(OffloadHeaderGen)
+
+add_llvm_library(offload_new SHARED
+ src/offload_lib.cpp
+ src/offload_impl.cpp
+ DEPENDS OffloadHeaderGen
+ LINK_LIBS omptarget omptarget.rtl.cuda omptarget.rtl.amdgpu)
+
+target_include_directories(offload_new PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
+
+# foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
+# target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
+# endforeach()
+
+set_target_properties(offload_new PROPERTIES
+ POSITION_INDEPENDENT_CODE ON
+ INSTALL_RPATH "$ORIGIN"
+ BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+install(TARGETS offload_new LIBRARY COMPONENT offload_new DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
diff --git a/offload/new-api/README.md b/offload/new-api/README.md
new file mode 100644
index 00000000000000..95c9bf54d7badd
--- /dev/null
+++ b/offload/new-api/README.md
@@ -0,0 +1,8 @@
+# Offload New API
+
+This directory contains the implementation of the experimental work-in-progress
+new API for Offload. It builds on top of the existing plugin implementations but
+provides a single level of abstraction suitable for runtimes for languages other
+than OpenMP to be built on top of.
+
+See the [API definition readme](API/README.md) for implementation details.
\ No newline at end of file
diff --git a/offload/new-api/src/helpers.hpp b/offload/new-api/src/helpers.hpp
new file mode 100644
index 00000000000000..66148d9f210083
--- /dev/null
+++ b/offload/new-api/src/helpers.hpp
@@ -0,0 +1,96 @@
+//===- helpers.hpp- GetInfo return helpers for the new LLVM/Offload API ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// The getInfo*/ReturnHelper facilities provide shortcut way of writing return
+// data + size for the various getInfo APIs. Based on the equivalent
+// implementations in Unified Runtime.
+//
+//===----------------------------------------------------------------------===//
+
+#include "offload_api.h"
+
+#include <cstring>
+
+
+template <typename T, typename Assign>
+offload_result_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, T Value,
+ size_t ValueSize, Assign &&AssignFunc) {
+ if (!ParamValue && !ParamValueSizeRet) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (ParamValue != nullptr) {
+ if (ParamValueSize < ValueSize) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+ AssignFunc(ParamValue, Value, ValueSize);
+ }
+
+ if (ParamValueSizeRet != nullptr) {
+ *ParamValueSizeRet = ValueSize;
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+template <typename T>
+offload_result_t getInfo(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, T Value) {
+ auto Assignment = [](void *ParamValue, T Value, size_t) {
+ *static_cast<T *>(ParamValue) = Value;
+ };
+
+ return getInfoImpl(ParamValueSize, ParamValue, ParamValueSizeRet, Value,
+ sizeof(T), Assignment);
+}
+
+template <typename T>
+offload_result_t getInfoArray(size_t array_length, size_t ParamValueSize,
+ void *ParamValue, size_t *ParamValueSizeRet,
+ const T *Value) {
+ return getInfoImpl(ParamValueSize, ParamValue, ParamValueSizeRet, Value,
+ array_length * sizeof(T), memcpy);
+}
+
+template <>
+inline offload_result_t
+getInfo<const char *>(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, const char *Value) {
+ return getInfoArray(strlen(Value) + 1, ParamValueSize, ParamValue,
+ ParamValueSizeRet, Value);
+}
+
+class ReturnHelper {
+public:
+ ReturnHelper(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet)
+ : ParamValueSize(ParamValueSize), ParamValue(ParamValue),
+ ParamValueSizeRet(ParamValueSizeRet) {}
+
+ // A version where in/out info size is represented by a single pointer
+ // to a value which is updated on return
+ ReturnHelper(size_t *ParamValueSize, void *ParamValue)
+ : ParamValueSize(*ParamValueSize), ParamValue(ParamValue),
+ ParamValueSizeRet(ParamValueSize) {}
+
+ // Scalar return Value
+ template <class T> offload_result_t operator()(const T &t) {
+ return getInfo(ParamValueSize, ParamValue, ParamValueSizeRet, t);
+ }
+
+ // Array return Value
+ template <class T> offload_result_t operator()(const T *t, size_t s) {
+ return getInfoArray(s, ParamValueSize, ParamValue, ParamValueSizeRet, t);
+ }
+
+protected:
+ size_t ParamValueSize;
+ void *ParamValue;
+ size_t *ParamValueSizeRet;
+};
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
new file mode 100644
index 00000000000000..165f2264ef7daa
--- /dev/null
+++ b/offload/new-api/src/offload_impl.cpp
@@ -0,0 +1,187 @@
+//===- offload_impl.cpp - Implementation of the new LLVM/Offload API ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains the definitions of the new LLVM/Offload API entry points. See
+// new-api/API/README.md for more information.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PluginManager.h"
+#include "helpers.hpp"
+#include "llvm/Support/FormatVariadic.h"
+#include <offload_api.h>
+
+#include <mutex>
+
+using namespace llvm;
+using namespace llvm::omp::target::plugin;
+
+// Handle type definitions. Ideally these would be 1:1 with the plugins
+struct offload_device_handle_t_ {
+ int DeviceNum;
+ GenericDeviceTy &Device;
+};
+
+struct offload_platform_handle_t_ {
+ std::unique_ptr<GenericPluginTy> Plugin;
+ std::vector<offload_device_handle_t_> Devices;
+};
+
+static std::vector<offload_platform_handle_t_> Platforms;
+
+// Every plugin exports this method to create an instance of the plugin type.
+#define PLUGIN_TARGET(Name) extern "C" GenericPluginTy *createPlugin_##Name();
+#include "Shared/Targets.def"
+
+void initPlugins() {
+ // Attempt to create an instance of each supported plugin.
+#define PLUGIN_TARGET(Name) \
+ do { \
+ Platforms.emplace_back(offload_platform_handle_t_{ \
+ std::unique_ptr<GenericPluginTy>(createPlugin_##Name()), {}}); \
+ } while (false);
+#include "Shared/Targets.def"
+
+ // Preemptively initialize all devices in the plugin so we can just return
+ // them from deviceGet
+ for (auto &Platform : Platforms) {
+ auto Err = Platform.Plugin->init();
+ [[maybe_unused]] std::string InfoMsg = toString(std::move(Err));
+ for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();
+ DevNum++) {
+ if (Platform.Plugin->init_device(DevNum) == OFFLOAD_SUCCESS) {
+ Platform.Devices.emplace_back(offload_device_handle_t_{
+ DevNum, Platform.Plugin->getDevice(DevNum)});
+ }
+ }
+ }
+}
+
+offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms) {
+ // It is expected that offloadPlatformGet is the first function to be called.
+ // In future it may make sense to have a specific entry point for Offload
+ // initialization, or expose explicit initialization of plugins.
+ static std::once_flag InitFlag;
+ std::call_once(InitFlag, initPlugins);
+
+ if (NumEntries > Platforms.size()) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+
+ if (phPlatforms) {
+ for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
+ PlatformIndex++) {
+ phPlatforms[PlatformIndex] = &Platforms[PlatformIndex];
+ }
+ }
+
+ if (pNumPlatforms) {
+ *pNumPlatforms = Platforms.size();
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_result_t
+offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet) {
+ ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
+
+ switch (propName) {
+ case OFFLOAD_PLATFORM_INFO_NAME:
+ return ReturnValue(hPlatform->Plugin->getName());
+ case OFFLOAD_PLATFORM_INFO_VENDOR_NAME:
+ // TODO: Implement this
+ return ReturnValue("Unknown platform vendor");
+ case OFFLOAD_PLATFORM_INFO_VERSION: {
+ // TODO: Implement this
+ return ReturnValue("v0.0.0");
+ }
+ case OFFLOAD_PLATFORM_INFO_BACKEND: {
+ auto PluginName = hPlatform->Plugin->getName();
+ if (PluginName == StringRef("CUDA")) {
+ return ReturnValue(OFFLOAD_PLATFORM_BACKEND_CUDA);
+ } else if (PluginName == StringRef("AMDGPU")) {
+ return ReturnValue(OFFLOAD_PLATFORM_BACKEND_AMDGPU);
+ } else {
+ return ReturnValue(OFFLOAD_PLATFORM_BACKEND_UNKNOWN);
+ }
+ }
+ default:
+ return OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION;
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
+ offload_device_type_t,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices) {
+
+ if (phDevices) {
+ for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
+ phDevices[DeviceIndex] = &(hPlatform->Devices[DeviceIndex]);
+ }
+ }
+
+ if (pNumDevices) {
+ *pNumDevices = static_cast<uint32_t>(hPlatform->Devices.size());
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize, void *pPropValue,
+ size_t *pPropSizeRet) {
+
+ ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
+
+ InfoQueueTy DevInfo;
+ if (auto Err = hDevice->Device.obtainInfoImpl(DevInfo))
+ return OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES;
+
+ // Find the info if it exists under any of the given names
+ auto GetInfo = [&DevInfo](std::vector<std::string> Names) {
+ for (auto Name : Names) {
+ auto InfoKeyMatches = [&](const InfoQueueTy::InfoQueueEntryTy &info) {
+ return info.Key == Name;
+ };
+ auto Item = std::find_if(DevInfo.getQueue().begin(),
+ DevInfo.getQueue().end(), InfoKeyMatches);
+
+ if (Item != std::end(DevInfo.getQueue())) {
+ return Item->Value;
+ }
+ }
+
+ return std::string("");
+ };
+
+ switch (propName) {
+ case OFFLOAD_DEVICE_INFO_TYPE:
+ return ReturnValue(OFFLOAD_DEVICE_TYPE_GPU);
+ case OFFLOAD_DEVICE_INFO_NAME:
+ return ReturnValue(GetInfo({"Device Name"}).c_str());
+ case OFFLOAD_DEVICE_INFO_VENDOR:
+ return ReturnValue(GetInfo({"Vendor Name"}).c_str());
+ case OFFLOAD_DEVICE_INFO_DRIVER_VERSION:
+ return ReturnValue(
+ GetInfo({"CUDA Driver Version", "HSA Runtime Version"}).c_str());
+ default:
+ return OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
new file mode 100644
index 00000000000000..b2452b2cdab950
--- /dev/null
+++ b/offload/new-api/src/offload_lib.cpp
@@ -0,0 +1,23 @@
+//===- offload_lib.cpp - Entry points for the new LLVM/Offload API --------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file pulls in the tablegen'd API entry point functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include <offload_api.h>
+#include <offload_print.hpp>
+
+#include <iostream>
+
+// Pull in the declarations for the implementation funtions. The actual entry
+// points in this file wrap these.
+#include "offload_impl_func_decls.inc"
+
+// Pull in the tablegen'd entry point definitions.
+#include "offload_entry_points.inc"
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 41cc0f286a581f..4cfe6cbf9ffe7f 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -124,6 +124,7 @@ enum InfoLevelKind { InfoLevel1 = 1, InfoLevel2, InfoLevel3 };
/// we use the level to determine the indentation of the key-value property at
/// printing time. See the enum InfoLevelKind for the list of accepted levels.
class InfoQueueTy {
+public:
struct InfoQueueEntryTy {
std::string Key;
std::string Value;
@@ -131,6 +132,8 @@ class InfoQueueTy {
uint64_t Level;
};
+
+private:
std::deque<InfoQueueEntryTy> Queue;
public:
@@ -153,6 +156,10 @@ class InfoQueueTy {
Queue.push_back({Key, Value, Units, L});
}
+ const std::deque<InfoQueueEntryTy> &getQueue() const {
+ return Queue;
+ }
+
/// Print all info entries added to the queue.
void print() const {
// We print four spances for each level.
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
new file mode 100644
index 00000000000000..6fdf3025f25bb5
--- /dev/null
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -0,0 +1,196 @@
+//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload header ----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a Tablegen backend that produces the contents of the Offload API
+// header. The generated comments are Doxygen compatible.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+#include "GenCommon.hpp"
+#include "RecordTypes.hpp"
+
+using namespace llvm;
+using namespace offload::tblgen;
+
+// Produce a possibly multi-line comment from the input string
+static std::string MakeComment(StringRef in) {
+ std::string out = "";
+ size_t LineStart = 0;
+ size_t LineBreak = 0;
+ while (LineBreak < in.size()) {
+ LineBreak = in.find_first_of("\n", LineStart);
+ if (LineBreak - LineStart <= 1) {
+ break;
+ }
+ out += std::string("\t///< ") +
+ in.substr(LineStart, LineBreak - LineStart).str() + "\n";
+ LineStart = LineBreak + 1;
+ }
+
+ return out;
+}
+
+static void ProcessHandle(const HandleRec &H, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("/// @brief {0}\n", H.getDesc());
+ OS << formatv("typedef struct {0}_ *{0};\n", H.getName());
+}
+
+static void ProcessTypedef(const TypedefRec &T, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("/// @brief {0}\n", T.getDesc());
+ OS << formatv("typedef {0} {1};\n", T.getValue(), T.getName());
+}
+
+static void ProcessMacro(const MacroRec &M, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("#ifndef {0}\n", M.getName());
+ if (auto Condition = M.getCondition()) {
+ OS << formatv("#if {0}\n", *Condition);
+ }
+ OS << "/// @brief " << M.getDesc() << "\n";
+ OS << formatv("#define {0} {1}\n", M.getNameWithArgs(), M.getValue());
+ if (auto AltValue = M.getAltValue()) {
+ OS << "#else\n";
+ OS << formatv("#define {0} {1}\n", M.getNameWithArgs(), *AltValue);
+ }
+ if (auto Condition = M.getCondition()) {
+ OS << formatv("#endif // {0}\n", *Condition);
+ }
+ OS << formatv("#endif // {0}\n", M.getName());
+}
+
+static void ProcessFunction(const FunctionRec &F, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("/// @brief {0}\n", F.getDesc());
+ OS << CommentsBreak;
+
+ OS << "/// @details\n";
+ for (auto &Detail : F.getDetails()) {
+ OS << formatv("/// - {0}\n", Detail);
+ }
+ OS << CommentsBreak;
+
+ // Emit analogue remarks
+ auto Analogues = F.getAnalogues();
+ if (!Analogues.empty()) {
+ OS << "/// @remarks\n/// _Analogues_\n";
+ for (auto &Analogue : Analogues) {
+ OS << formatv("/// - **{0}**\n", Analogue);
+ }
+ OS << CommentsBreak;
+ }
+
+ OS << "/// @returns\n";
+ auto Returns = F.getReturns();
+ for (auto &Ret : Returns) {
+ OS << formatv("/// - ::{0}\n", Ret.getValue());
+ auto RetConditions = Ret.getConditions();
+ for (auto &RetCondition : RetConditions) {
+ OS << formatv("/// + {0}\n", RetCondition);
+ }
+ }
+
+ OS << formatv("{0}_APIEXPORT {1}_result_t {0}_APICALL ", PrefixUpper,
+ PrefixLower);
+ OS << F.getName();
+ OS << "(\n";
+ auto Params = F.getParams();
+ for (auto &Param : Params) {
+ OS << " " << Param.getType() << " " << Param.getName();
+ if (Param != Params.back()) {
+ OS << ", ";
+ } else {
+ OS << " ";
+ }
+ OS << MakeParamComment(Param) << "\n";
+ }
+ OS << ");\n\n";
+}
+
+static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("/// @brief {0}\n", Enum.getDesc());
+ OS << formatv("typedef enum {0} {{\n", Enum.getName());
+
+ uint32_t EtorVal = 0;
+ for (const auto &EnumVal : Enum.getValues()) {
+ auto Desc = MakeComment(EnumVal.getDesc());
+ OS << formatv(TAB_1 "{0}_{1} = {2}, {3}", Enum.getEnumValNamePrefix(),
+ EnumVal.getName(), EtorVal++, Desc);
+ }
+
+ // Add force uint32 val
+ OS << formatv(TAB_1 "/// @cond\n" TAB_1
+ "{0}_FORCE_UINT32 = 0x7fffffff\n" TAB_1
+ "/// @endcond\n\n",
+ Enum.getEnumValNamePrefix());
+
+ OS << formatv("} {0};\n", Enum.getName());
+}
+
+static void ProcessStruct(const StructRec &Struct, raw_ostream &OS) {
+ OS << CommentsHeader;
+ OS << formatv("/// @brief {0}\n", Struct.getDesc());
+ OS << formatv("typedef struct {0} {{\n", Struct.getName());
+
+ for (const auto &Member : Struct.getMembers()) {
+ OS << formatv(TAB_1 "{0} {1}; {2}", Member.getType(), Member.getName(),
+ MakeComment(Member.getDesc()));
+ }
+
+ OS << formatv("} {0};\n\n", Struct.getName());
+}
+
+static void ProcessFuncParamStruct(const FunctionRec &Func, raw_ostream &OS) {
+ auto FuncParamStructBegin = R"(
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for {0}
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct {1} {{
+)";
+
+ OS << formatv(FuncParamStructBegin, Func.getName(),
+ Func.getParamStructName());
+ for (const auto &Param : Func.getParams()) {
+ OS << TAB_1 << Param.getType() << "* p" << Param.getName() << ";\n";
+ }
+ OS << formatv("} {0};\n", Func.getParamStructName());
+}
+
+void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
+ OS << FileHeader;
+ // Generate main API definitions
+ for (auto *R : Records.getAllDerivedDefinitions("APIObject")) {
+ if (R->isSubClassOf("Macro")) {
+ ProcessMacro(MacroRec{R}, OS);
+ } else if (R->isSubClassOf("Typedef")) {
+ ProcessTypedef(TypedefRec{R}, OS);
+ } else if (R->isSubClassOf("Handle")) {
+ ProcessHandle(HandleRec{R}, OS);
+ } else if (R->isSubClassOf("Function")) {
+ ProcessFunction(FunctionRec{R}, OS);
+ } else if (R->isSubClassOf("Enum")) {
+ ProcessEnum(EnumRec{R}, OS);
+ } else if (R->isSubClassOf("Struct")) {
+ ProcessStruct(StructRec{R}, OS);
+ }
+ }
+
+ // Generate auxiliary definitions (func param structs etc)
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ ProcessFuncParamStruct(FunctionRec{R}, OS);
+ }
+
+ OS << FileFooter;
+}
diff --git a/offload/tools/offload-tblgen/CMakeLists.txt b/offload/tools/offload-tblgen/CMakeLists.txt
new file mode 100644
index 00000000000000..52986cbbaa9187
--- /dev/null
+++ b/offload/tools/offload-tblgen/CMakeLists.txt
@@ -0,0 +1,24 @@
+##===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+##===----------------------------------------------------------------------===##
+include(TableGen)
+
+add_tablegen(offload-tblgen OFFLOAD
+ EXPORT OFFLOAD
+ APIGen.cpp
+ EntryPointGen.cpp
+ FuncsGen.cpp
+ GenCommon.hpp
+ Generators.hpp
+ offload-tblgen.cpp
+ PrintGen.cpp
+ RecordTypes.hpp
+ )
+
+set(OFFLOAD_TABLEGEN_EXE "${OFFLOAD_TABLEGEN_EXE}" CACHE INTERNAL "")
+set(OFFLOAD_TABLEGEN_TARGET "${OFFLOAD_TABLEGEN_TARGET}" CACHE INTERNAL "")
+
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
new file mode 100644
index 00000000000000..b89592187639e3
--- /dev/null
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -0,0 +1,86 @@
+//===- offload-tblgen/EntryPointGen.cpp - Tablegen backend for Offload ----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a Tablegen backend that produces the actual entry points for the
+// Offload API. It serves as a place to integrate functionality like tracing
+// and validation before dispatching to the actual implementations.
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/TableGen/Record.h"
+
+#include "GenCommon.hpp"
+#include "RecordTypes.hpp"
+
+using namespace llvm;
+using namespace offload::tblgen;
+
+static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
+ OS << CommentsHeader;
+ // Emit preamble
+ OS << formatv("{1}_APIEXPORT {0}_result_t {1}_APICALL {2}(\n ", PrefixLower,
+ PrefixUpper, F.getName());
+ // Emit arguments
+ std::string ParamNameList = "";
+ for (auto &Param : F.getParams()) {
+ OS << Param.getType() << " " << Param.getName();
+ if (Param != F.getParams().back()) {
+ OS << ", ";
+ }
+ ParamNameList += Param.getName().str() + ", ";
+ }
+ OS << ") {\n";
+
+ OS << TAB_1 "if (true /*enableParameterValidation*/) {\n";
+
+ // Emit validation checks
+ for (const auto &Return : F.getReturns()) {
+ for (auto &Condition : Return.getConditions()) {
+ if (Condition.starts_with("`") && Condition.ends_with("`")) {
+ auto ConditionString = Condition.substr(1, Condition.size() - 2);
+ OS << formatv(TAB_2 "if ({0}) {{\n", ConditionString);
+ OS << formatv(TAB_3 "return {0};\n", Return.getValue());
+ OS << TAB_2 "}\n\n";
+ }
+ }
+ }
+ OS << " }\n\n";
+
+ // Emit pre-call prints
+ OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
+ OS << formatv(TAB_2 "std::cout << \"---> {0}\";\n", F.getName());
+ OS << TAB_1 "}\n\n";
+
+ // Perform actual function call
+ ParamNameList = ParamNameList.substr(0, ParamNameList.size() - 2);
+ OS << formatv(TAB_1 "{0}_result_t result = {1}_impl({2});\n\n", PrefixLower,
+ F.getName(), ParamNameList);
+
+ // Emit post-call prints
+ OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
+ OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
+ for (const auto &Param : F.getParams()) {
+ OS << "&" << Param.getName();
+ if (Param != F.getParams().back()) {
+ OS << ", ";
+ }
+ }
+ OS << formatv("};\n");
+ OS << TAB_2 "std::cout << \"(\" << &Params << \")\";\n";
+ OS << TAB_2 "std::cout << \"-> \" << result << \"\\n\";\n";
+ OS << TAB_1 "}\n";
+
+ OS << TAB_1 "return result;\n";
+ OS << "}\n";
+}
+
+void EmitOffloadEntryPoints(RecordKeeper &Records, raw_ostream &OS) {
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ EmitEntryPointFunc(FunctionRec{R}, OS);
+ }
+}
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
new file mode 100644
index 00000000000000..4dc74047ac49d8
--- /dev/null
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -0,0 +1,54 @@
+//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload validation ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a Tablegen backend that produces validation functions for the Offload
+// API entry point functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/TableGen/Record.h"
+
+#include "GenCommon.hpp"
+#include "RecordTypes.hpp"
+
+using namespace llvm;
+using namespace offload::tblgen;
+
+// Emit a list of just the API function names
+void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
+ OS << R"(
+#ifndef OFFLOAD_FUNC
+#error Please define the macro OFFLOAD_FUNC(Function)
+#endif
+
+)";
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ FunctionRec FR{R};
+ OS << formatv("OFFLOAD_FUNC({0})", FR.getName()) << "\n";
+ }
+
+ OS << "\n#undef OFFLOAD_FUNC\n";
+}
+
+void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ FunctionRec F{R};
+ OS << formatv("{0}_result_t {1}_impl(", PrefixLower, F.getName());
+ auto Params = F.getParams();
+ for (auto &Param : Params) {
+ OS << Param.getType() << " " << Param.getName();
+ if (Param != Params.back()) {
+ OS << ", ";
+ } else {
+ OS << ");";
+ }
+ }
+ OS << "\n";
+ }
+}
diff --git a/offload/tools/offload-tblgen/GenCommon.hpp b/offload/tools/offload-tblgen/GenCommon.hpp
new file mode 100644
index 00000000000000..fb24ef06f9ec8f
--- /dev/null
+++ b/offload/tools/offload-tblgen/GenCommon.hpp
@@ -0,0 +1,58 @@
+//===- offload-tblgen/GenCommon.cpp - Common defs for Offload generators --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include "RecordTypes.hpp"
+#include "llvm/Support/FormatVariadic.h"
+
+// Having inline bits of tabbed code is hard to read, provide some definitions
+// so we can keep things tidier
+#define TAB_1 " "
+#define TAB_2 " "
+#define TAB_3 " "
+#define TAB_4 " "
+#define TAB_5 " "
+
+constexpr auto FileHeader = R"(
+// Auto-generated file, do not manually edit.
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+)";
+
+constexpr auto FileFooter = R"(
+#if defined(__cplusplus)
+} // extern "C"
+#endif
+
+)";
+
+constexpr auto CommentsHeader = R"(
+///////////////////////////////////////////////////////////////////////////////
+)";
+
+constexpr auto CommentsBreak = "///\n";
+
+constexpr auto PrefixLower = "offload";
+constexpr auto PrefixUpper = "OFFLOAD";
+
+inline std::string
+MakeParamComment(const llvm::offload::tblgen::ParamRec &Param) {
+ return llvm::formatv("///< {0}{1}{2} {3}", (Param.isIn() ? "[in]" : ""),
+ (Param.isOut() ? "[out]" : ""),
+ (Param.isOpt() ? "[optional]" : ""), Param.getDesc());
+}
+
diff --git a/offload/tools/offload-tblgen/Generators.hpp b/offload/tools/offload-tblgen/Generators.hpp
new file mode 100644
index 00000000000000..4b300f52ddf84d
--- /dev/null
+++ b/offload/tools/offload-tblgen/Generators.hpp
@@ -0,0 +1,18 @@
+//===- offload-tblgen/Generators.hpp - Offload generator declarations -----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include "llvm/TableGen/Record.h"
+
+void EmitOffloadAPI(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitOffloadFuncNames(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitOffloadImplFuncDecls(llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitOffloadEntryPoints(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitOffloadPrintHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
new file mode 100644
index 00000000000000..0c47695eca12b6
--- /dev/null
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -0,0 +1,206 @@
+//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload printing --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a Tablegen backend that produces print functions for the Offload API
+// entry point functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/TableGen/Record.h"
+
+#include "GenCommon.hpp"
+#include "RecordTypes.hpp"
+
+using namespace llvm;
+using namespace offload::tblgen;
+
+constexpr auto PrintEnumHeader =
+ R"(///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the {0} type
+/// @returns std::ostream &
+)";
+
+constexpr auto PrintTaggedEnumHeader =
+ R"(///////////////////////////////////////////////////////////////////////////////
+/// @brief Print type-tagged {0} enum value
+/// @returns std::ostream &
+)";
+
+static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) {
+ OS << formatv(PrintEnumHeader, Enum.getName());
+ OS << formatv(
+ "inline std::ostream &operator<<(std::ostream &os, enum {0} value) "
+ "{{\n" TAB_1 "switch (value) {{\n",
+ Enum.getName());
+
+ for (const auto &Val : Enum.getValues()) {
+ auto Name = Enum.getEnumValNamePrefix() + "_" + Val.getName();
+ OS << formatv(TAB_1 "case {0}:\n", Name);
+ OS << formatv(TAB_2 "os << \"{0}\";\n", Name);
+ OS << formatv(TAB_2 "break;\n");
+ }
+
+ OS << TAB_1 "default:\n" TAB_2 "os << \"unknown enumerator\";\n" TAB_2
+ "break;\n" TAB_1 "}\n" TAB_1 "return os;\n}\n\n";
+
+ if (!Enum.isTyped()) {
+ return;
+ }
+
+ OS << formatv(PrintTaggedEnumHeader, Enum.getName());
+
+ OS << formatv(R"""(template <>
+inline void printTagged(std::ostream &os, const void *ptr, {0} value, size_t size) {{
+ if (ptr == NULL) {{
+ printPtr(os, ptr);
+ return;
+ }
+
+ switch (value) {{
+)""",
+ Enum.getName());
+
+ for (const auto &Val : Enum.getValues()) {
+ auto Name = Enum.getEnumValNamePrefix() + "_" + Val.getName();
+ auto Type = Val.getTaggedType();
+ OS << formatv(TAB_1 "case {0}: {{\n", Name);
+ // Special case for strings
+ if (Type == "char[]") {
+ OS << formatv(TAB_2 "printPtr(os, (const char*) ptr);\n");
+ } else {
+ OS << formatv(TAB_2 "const {0} * const tptr = (const {0} * const)ptr;\n",
+ Type);
+ // TODO: Handle other cases here
+ OS << TAB_2 "os << (const void *)tptr << \" (\";\n";
+ if (Type.ends_with("*")) {
+ OS << TAB_2 "os << printPtr(os, tptr);\n";
+ } else {
+ OS << TAB_2 "os << *tptr;\n";
+ }
+ OS << TAB_2 "os << \")\";\n";
+ }
+ OS << formatv(TAB_2 "break;\n" TAB_1 "}\n");
+ }
+
+ OS << TAB_1 "default:\n" TAB_2 "os << \"unknown enumerator\";\n" TAB_2
+ "break;\n" TAB_1 "}\n";
+
+ OS << "}\n";
+}
+
+static void EmitFunctionParamStructPrint(const FunctionRec &Func,
+ raw_ostream &OS) {
+ OS << formatv(R"(
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct {0} *params) {{
+)",
+ Func.getParamStructName());
+
+ for (const auto &Param : Func.getParams()) {
+ OS << formatv(TAB_1 "os << \".{0} = \";\n", Param.getName());
+ if (auto Range = Param.getRange()) {
+ OS << formatv(TAB_1 "os << \"{{\";\n");
+ OS << formatv(TAB_1 "for (size_t i = {0}; i < *params->p{1}; i++){{\n",
+ Range->first, Range->second);
+ OS << TAB_2 "if (i > 0) {\n";
+ OS << TAB_3 " os << \", \";\n";
+ OS << TAB_2 "}\n";
+ OS << formatv(TAB_2 "printPtr(os, (*params->p{0})[i]);\n",
+ Param.getName());
+ OS << formatv(TAB_1 "}\n");
+ OS << formatv(TAB_1 "os << \"}\";\n");
+ } else if (auto TypeInfo = Param.getTypeInfo()) {
+ OS << formatv(
+ TAB_1
+ "printTagged(os, *params->p{0}, *params->p{1}, *params->p{2});\n",
+ Param.getName(), TypeInfo->first, TypeInfo->second);
+ } else if (Param.isPointerType() || Param.isHandleType()) {
+ OS << formatv(TAB_1 "printPtr(os, *params->p{0});\n", Param.getName());
+ } else {
+ OS << formatv(TAB_1 "os << *params->p{0};\n", Param.getName());
+ }
+ if (Param != Func.getParams().back()) {
+ OS << TAB_1 "os << \", \";\n";
+ }
+ }
+
+ OS << TAB_1 "return os;\n}\n";
+}
+
+void EmitOffloadPrintHeader(RecordKeeper &Records, raw_ostream &OS) {
+ OS << R"""(
+// Auto-generated file, do not manually edit.
+
+#pragma once
+
+#include <offload_api.h>
+#include <ostream>
+
+
+template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr);
+template <typename T> inline void printTagged(std::ostream &os, const void *ptr, T value, size_t size);
+)""";
+
+ // ==========
+ OS << "template <typename T> struct is_handle : std::false_type {};\n";
+ for (auto *R : Records.getAllDerivedDefinitions("Handle")) {
+ HandleRec H{R};
+ OS << formatv("template <> struct is_handle<{0}> : std::true_type {{};\n",
+ H.getName());
+ }
+ OS << "template <typename T> inline constexpr bool is_handle_v = "
+ "is_handle<T>::value;\n";
+ // =========
+
+ // Forward declare the operator<< overloads so their implementations can
+ // use each other.
+ OS << "\n";
+ for (auto *R : Records.getAllDerivedDefinitions("Enum")) {
+ OS << formatv(
+ "inline std::ostream &operator<<(std::ostream &os, enum {0} value);\n",
+ EnumRec{R}.getName());
+ }
+ OS << "\n";
+
+ // Create definitions
+ for (auto *R : Records.getAllDerivedDefinitions("Enum")) {
+ EnumRec E{R};
+ ProcessEnum(E, OS);
+ }
+
+ // Emit print functions for the function param structs
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ EmitFunctionParamStructPrint(FunctionRec{R}, OS);
+ }
+
+ OS << R"""(
+///////////////////////////////////////////////////////////////////////////////
+// @brief Print pointer value
+template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
+ if (ptr == nullptr) {
+ os << "nullptr";
+ } else if constexpr (std::is_pointer_v<T>) {
+ os << (const void *)(ptr) << " (";
+ printPtr(os, *ptr);
+ os << ")";
+ } else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
+ os << (const void *)ptr;
+ } else if constexpr (std::is_same_v<std::remove_cv_t< T >, char>) {
+ os << (const void *)(ptr) << " (";
+ os << ptr;
+ os << ")";
+ } else {
+ os << (const void *)(ptr) << " (";
+ os << *ptr;
+ os << ")";
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+ )""";
+}
diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp
new file mode 100644
index 00000000000000..ccd45d472cf770
--- /dev/null
+++ b/offload/tools/offload-tblgen/RecordTypes.hpp
@@ -0,0 +1,227 @@
+//===- offload-tblgen/RecordTypes.cpp - Offload record type wrappers -----===-//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include <string>
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+namespace offload {
+namespace tblgen {
+
+class HandleRec {
+public:
+ explicit HandleRec(Record *rec) : rec(rec) {}
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+
+private:
+ Record *rec;
+};
+
+class MacroRec {
+public:
+ explicit MacroRec(Record *rec) : rec(rec) {
+ auto Name = rec->getValueAsString("name");
+ auto OpenBrace = Name.find_first_of("(");
+ nameWithoutArgs = Name.substr(0, OpenBrace);
+ }
+ StringRef getName() const { return nameWithoutArgs; }
+ StringRef getNameWithArgs() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+
+ std::optional<StringRef> getCondition() const {
+ return rec->getValueAsOptionalString("condition");
+ }
+ StringRef getValue() const { return rec->getValueAsString("value"); }
+ std::optional<StringRef> getAltValue() const {
+ return rec->getValueAsOptionalString("alt_value");
+ }
+
+private:
+ Record *rec;
+ std::string nameWithoutArgs;
+};
+
+class TypedefRec {
+public:
+ explicit TypedefRec(Record *rec) : rec(rec) {}
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ StringRef getValue() const { return rec->getValueAsString("value"); }
+
+private:
+ Record *rec;
+};
+
+class EnumValueRec {
+public:
+ explicit EnumValueRec(Record *rec) : rec(rec) {}
+ std::string getName() const { return rec->getValueAsString("name").upper(); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ StringRef getTaggedType() const {
+ return rec->getValueAsString("tagged_type");
+ }
+
+private:
+ Record *rec;
+};
+
+class EnumRec {
+public:
+ explicit EnumRec(Record *rec) : rec(rec) {
+ for (auto *Val : rec->getValueAsListOfDefs("etors")) {
+ vals.emplace_back(EnumValueRec{Val});
+ }
+ }
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ const std::vector<EnumValueRec> &getValues() const { return vals; }
+
+ std::string getEnumValNamePrefix() const {
+ return StringRef(getName().str().substr(0, getName().str().length() - 2))
+ .upper();
+ }
+
+ bool isTyped() const { return rec->getValueAsBit("is_typed"); }
+
+private:
+ Record *rec;
+ std::vector<EnumValueRec> vals;
+};
+
+class StructMemberRec {
+public:
+ explicit StructMemberRec(Record *rec) : rec(rec) {}
+ StringRef getType() const { return rec->getValueAsString("type"); }
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+
+private:
+ Record *rec;
+};
+
+class StructRec {
+public:
+ explicit StructRec(Record *rec) : rec(rec) {
+ for (auto *Member : rec->getValueAsListOfDefs("all_members")) {
+ members.emplace_back(StructMemberRec(Member));
+ }
+ }
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ std::optional<StringRef> getBaseClass() const {
+ return rec->getValueAsOptionalString("base_class");
+ }
+ const std::vector<StructMemberRec> &getMembers() const { return members; }
+
+private:
+ Record *rec;
+ std::vector<StructMemberRec> members;
+};
+
+class ParamRec {
+public:
+ explicit ParamRec(Record *rec) : rec(rec) {
+ flags = rec->getValueAsBitsInit("flags");
+ auto *Range = rec->getValueAsDef("range");
+ auto RangeBegin = Range->getValueAsString("begin");
+ auto RangeEnd = Range->getValueAsString("end");
+ if (RangeBegin != "" && RangeEnd != "") {
+ range = {RangeBegin, RangeEnd};
+ } else {
+ range = std::nullopt;
+ }
+
+ auto *TypeInfo = rec->getValueAsDef("type_info");
+ auto TypeInfoEnum = TypeInfo->getValueAsString("enum");
+ auto TypeInfoSize = TypeInfo->getValueAsString("size");
+ if (TypeInfoEnum != "" && TypeInfoSize != "") {
+ typeinfo = {TypeInfoEnum, TypeInfoSize};
+ } else {
+ typeinfo = std::nullopt;
+ }
+ }
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getType() const { return rec->getValueAsString("type"); }
+ bool isPointerType() const { return getType().ends_with('*'); }
+ bool isHandleType() const { return getType().ends_with("_handle_t"); }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ bool isIn() const { return dyn_cast<BitInit>(flags->getBit(0))->getValue(); }
+ bool isOut() const { return dyn_cast<BitInit>(flags->getBit(1))->getValue(); }
+ bool isOpt() const { return dyn_cast<BitInit>(flags->getBit(2))->getValue(); }
+
+ Record *getRec() const { return rec; }
+ std::optional<std::pair<StringRef, StringRef>> getRange() const {
+ return range;
+ }
+
+ std::optional<std::pair<StringRef, StringRef>> getTypeInfo() const {
+ return typeinfo;
+ }
+
+ // Needed to check whether we're at the back of a vector of params
+ bool operator!=(const ParamRec &p) const { return rec != p.getRec(); }
+
+private:
+ Record *rec;
+ BitsInit *flags;
+ std::optional<std::pair<StringRef, StringRef>> range;
+ std::optional<std::pair<StringRef, StringRef>> typeinfo;
+};
+
+class ReturnRec {
+public:
+ ReturnRec(Record *rec) : rec(rec) {}
+ StringRef getValue() const { return rec->getValueAsString("value"); }
+ std::vector<StringRef> getConditions() const {
+ return rec->getValueAsListOfStrings("conditions");
+ }
+
+private:
+ Record *rec;
+};
+
+class FunctionRec {
+public:
+ FunctionRec(Record *rec) : rec(rec) {
+ for (auto &Ret : rec->getValueAsListOfDefs("all_returns"))
+ rets.emplace_back(Ret);
+ for (auto &Param : rec->getValueAsListOfDefs("params"))
+ params.emplace_back(Param);
+ }
+
+ std::string getParamStructName() const {
+ return llvm::formatv("{0}_params_t",
+ llvm::convertToSnakeFromCamelCase(getName()));
+ }
+
+ StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getClass() const { return rec->getValueAsString("api_class"); }
+ const std::vector<ReturnRec> &getReturns() const { return rets; }
+ const std::vector<ParamRec> &getParams() const { return params; }
+ StringRef getDesc() const { return rec->getValueAsString("desc"); }
+ std::vector<StringRef> getDetails() const {
+ return rec->getValueAsListOfStrings("details");
+ }
+ std::vector<StringRef> getAnalogues() const {
+ return rec->getValueAsListOfStrings("analogues");
+ }
+
+private:
+ std::vector<ReturnRec> rets;
+ std::vector<ParamRec> params;
+
+ Record *rec;
+};
+
+} // namespace tblgen
+} // namespace offload
+} // namespace llvm
diff --git a/offload/tools/offload-tblgen/offload-tblgen.cpp b/offload/tools/offload-tblgen/offload-tblgen.cpp
new file mode 100644
index 00000000000000..2e11ec08d0e93a
--- /dev/null
+++ b/offload/tools/offload-tblgen/offload-tblgen.cpp
@@ -0,0 +1,95 @@
+//===- offload-tblgen/offload-tblgen.cpp ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a Tablegen tool that produces source files for the Offload project.
+// See offload/API/README.md for more information.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/InitLLVM.h"
+#include "llvm/TableGen/Main.h"
+#include "llvm/TableGen/Record.h"
+
+#include "Generators.hpp"
+
+namespace llvm {
+namespace offload {
+namespace tblgen {
+
+enum ActionType {
+ PrintRecords,
+ DumpJSON,
+ GenAPI,
+ GenFuncNames,
+ GenImplFuncDecls,
+ GenEntryPoints,
+ GenPrintHeader
+};
+
+namespace {
+cl::opt<ActionType> Action(
+ cl::desc("Action to perform:"),
+ cl::values(
+ clEnumValN(PrintRecords, "print-records",
+ "Print all records to stdout (default)"),
+ clEnumValN(DumpJSON, "dump-json",
+ "Dump all records as machine-readable JSON"),
+ clEnumValN(GenAPI, "gen-api", "Generate Offload API header contents"),
+ clEnumValN(GenFuncNames, "gen-func-names",
+ "Generate a list of all Offload API function names"),
+ clEnumValN(
+ GenImplFuncDecls, "gen-impl-func-decls",
+ "Generate declarations for Offload API implementation functions"),
+ clEnumValN(GenEntryPoints, "gen-entry-points",
+ "Generate Offload API wrapper function definitions"),
+ clEnumValN(GenPrintHeader, "gen-print-header",
+ "Generate Offload API print header")));
+}
+
+static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
+ switch (Action) {
+ case PrintRecords:
+ OS << Records;
+ break;
+ case DumpJSON:
+ EmitJSON(Records, OS);
+ break;
+ case GenAPI:
+ EmitOffloadAPI(Records, OS);
+ break;
+ case GenFuncNames:
+ EmitOffloadFuncNames(Records, OS);
+ break;
+ case GenImplFuncDecls:
+ EmitOffloadImplFuncDecls(Records, OS);
+ break;
+ case GenEntryPoints:
+ EmitOffloadEntryPoints(Records, OS);
+ break;
+ case GenPrintHeader:
+ EmitOffloadPrintHeader(Records, OS);
+ break;
+ }
+
+ return false;
+}
+
+int OffloadTblgenMain(int argc, char **argv) {
+ InitLLVM y(argc, argv);
+ cl::ParseCommandLineOptions(argc, argv);
+ return TableGenMain(argv[0], &OffloadTableGenMain);
+}
+} // namespace tblgen
+} // namespace offload
+} // namespace llvm
+
+using namespace llvm;
+using namespace offload::tblgen;
+
+int main(int argc, char **argv) { return OffloadTblgenMain(argc, argv); }
>From 2b142440f0c4bdbf78a46394c51b18241f2046dc Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 13 Sep 2024 16:03:15 +0100
Subject: [PATCH 02/14] Fix liboffload_new linking and formatting
---
offload/new-api/CMakeLists.txt | 19 ++++++++++++-------
offload/new-api/src/helpers.hpp | 1 -
offload/new-api/src/offload_impl.cpp | 15 +++++++++------
.../common/include/PluginInterface.h | 5 +----
offload/tools/offload-tblgen/FuncsGen.cpp | 19 ++++++++++++++++---
offload/tools/offload-tblgen/GenCommon.hpp | 1 -
offload/tools/offload-tblgen/Generators.hpp | 1 +
.../tools/offload-tblgen/offload-tblgen.cpp | 10 ++++++++--
8 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
index c27591d2af3ab3..ac82e7db647601 100644
--- a/offload/new-api/CMakeLists.txt
+++ b/offload/new-api/CMakeLists.txt
@@ -1,4 +1,3 @@
-
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/API/OffloadAPI.td)
list(APPEND LLVM_TABLEGEN_FLAGS -I ${CMAKE_CURRENT_SOURCE_DIR}/API)
@@ -7,15 +6,22 @@ tablegen(OFFLOAD offload_funcs.inc -gen-func-names)
tablegen(OFFLOAD offload_impl_func_decls.inc -gen-impl-func-decls)
tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
tablegen(OFFLOAD offload_print.hpp -gen-print-header)
-
+tablegen(OFFLOAD offload_exports -gen-exports)
add_public_tablegen_target(OffloadHeaderGen)
add_llvm_library(offload_new SHARED
src/offload_lib.cpp
src/offload_impl.cpp
- DEPENDS OffloadHeaderGen
- LINK_LIBS omptarget omptarget.rtl.cuda omptarget.rtl.amdgpu)
+ DEPENDS OffloadHeaderGen)
+
+foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
+ target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
+endforeach()
+
+if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
+ target_link_libraries(offload_new PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/offload_exports")
+endif()
target_include_directories(offload_new PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
@@ -23,9 +29,8 @@ target_include_directories(offload_new PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
-# foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
-# target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
-# endforeach()
+target_compile_options(offload_new PRIVATE ${offload_compile_flags})
+target_link_options(offload_new PRIVATE ${offload_link_flags})
set_target_properties(offload_new PROPERTIES
POSITION_INDEPENDENT_CODE ON
diff --git a/offload/new-api/src/helpers.hpp b/offload/new-api/src/helpers.hpp
index 66148d9f210083..246de2b678015d 100644
--- a/offload/new-api/src/helpers.hpp
+++ b/offload/new-api/src/helpers.hpp
@@ -16,7 +16,6 @@
#include <cstring>
-
template <typename T, typename Assign>
offload_result_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
size_t *ParamValueSizeRet, T Value,
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index 165f2264ef7daa..b3bf602607ac47 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -32,7 +32,10 @@ struct offload_platform_handle_t_ {
std::vector<offload_device_handle_t_> Devices;
};
-static std::vector<offload_platform_handle_t_> Platforms;
+std::vector<offload_platform_handle_t_> &Platforms() {
+ static std::vector<offload_platform_handle_t_> Platforms;
+ return Platforms;
+}
// Every plugin exports this method to create an instance of the plugin type.
#define PLUGIN_TARGET(Name) extern "C" GenericPluginTy *createPlugin_##Name();
@@ -42,14 +45,14 @@ void initPlugins() {
// Attempt to create an instance of each supported plugin.
#define PLUGIN_TARGET(Name) \
do { \
- Platforms.emplace_back(offload_platform_handle_t_{ \
+ Platforms().emplace_back(offload_platform_handle_t_{ \
std::unique_ptr<GenericPluginTy>(createPlugin_##Name()), {}}); \
} while (false);
#include "Shared/Targets.def"
// Preemptively initialize all devices in the plugin so we can just return
// them from deviceGet
- for (auto &Platform : Platforms) {
+ for (auto &Platform : Platforms()) {
auto Err = Platform.Plugin->init();
[[maybe_unused]] std::string InfoMsg = toString(std::move(Err));
for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();
@@ -71,19 +74,19 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
static std::once_flag InitFlag;
std::call_once(InitFlag, initPlugins);
- if (NumEntries > Platforms.size()) {
+ if (NumEntries > Platforms().size()) {
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
}
if (phPlatforms) {
for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
PlatformIndex++) {
- phPlatforms[PlatformIndex] = &Platforms[PlatformIndex];
+ phPlatforms[PlatformIndex] = &(Platforms())[PlatformIndex];
}
}
if (pNumPlatforms) {
- *pNumPlatforms = Platforms.size();
+ *pNumPlatforms = Platforms().size();
}
return OFFLOAD_RESULT_SUCCESS;
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 4cfe6cbf9ffe7f..82efcdaf5ad3dc 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -132,7 +132,6 @@ class InfoQueueTy {
uint64_t Level;
};
-
private:
std::deque<InfoQueueEntryTy> Queue;
@@ -156,9 +155,7 @@ class InfoQueueTy {
Queue.push_back({Key, Value, Units, L});
}
- const std::deque<InfoQueueEntryTy> &getQueue() const {
- return Queue;
- }
+ const std::deque<InfoQueueEntryTy> &getQueue() const { return Queue; }
/// Print all info entries added to the queue.
void print() const {
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index 4dc74047ac49d8..567d784f320010 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -1,4 +1,4 @@
-//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload validation ===//
+//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload functions -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
//
-// This is a Tablegen backend that produces validation functions for the Offload
-// API entry point functions.
+// This is a Tablegen backend that handles generation of various small files
+// pertaining to the API functions.
//
//===----------------------------------------------------------------------===//
@@ -36,6 +36,19 @@ void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
OS << "\n#undef OFFLOAD_FUNC\n";
}
+void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
+ OS << "VERS1.0 {\n";
+ OS << TAB_1 "global:\n";
+
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ OS << formatv(TAB_2 "{0};\n", FunctionRec(R).getName());
+ }
+ OS << TAB_1 "local:\n";
+ OS << TAB_2 "*;\n";
+ OS << "};\n";
+}
+
+// Emit declarations for every implementation function
void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
FunctionRec F{R};
diff --git a/offload/tools/offload-tblgen/GenCommon.hpp b/offload/tools/offload-tblgen/GenCommon.hpp
index fb24ef06f9ec8f..16ffb3a4d667c8 100644
--- a/offload/tools/offload-tblgen/GenCommon.hpp
+++ b/offload/tools/offload-tblgen/GenCommon.hpp
@@ -55,4 +55,3 @@ MakeParamComment(const llvm::offload::tblgen::ParamRec &Param) {
(Param.isOut() ? "[out]" : ""),
(Param.isOpt() ? "[optional]" : ""), Param.getDesc());
}
-
diff --git a/offload/tools/offload-tblgen/Generators.hpp b/offload/tools/offload-tblgen/Generators.hpp
index 4b300f52ddf84d..4e347ba2fb2946 100644
--- a/offload/tools/offload-tblgen/Generators.hpp
+++ b/offload/tools/offload-tblgen/Generators.hpp
@@ -16,3 +16,4 @@ void EmitOffloadImplFuncDecls(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
void EmitOffloadEntryPoints(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitOffloadPrintHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitOffloadExports(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
diff --git a/offload/tools/offload-tblgen/offload-tblgen.cpp b/offload/tools/offload-tblgen/offload-tblgen.cpp
index 2e11ec08d0e93a..856ebebfc93249 100644
--- a/offload/tools/offload-tblgen/offload-tblgen.cpp
+++ b/offload/tools/offload-tblgen/offload-tblgen.cpp
@@ -29,7 +29,8 @@ enum ActionType {
GenFuncNames,
GenImplFuncDecls,
GenEntryPoints,
- GenPrintHeader
+ GenPrintHeader,
+ GenExports
};
namespace {
@@ -49,7 +50,9 @@ cl::opt<ActionType> Action(
clEnumValN(GenEntryPoints, "gen-entry-points",
"Generate Offload API wrapper function definitions"),
clEnumValN(GenPrintHeader, "gen-print-header",
- "Generate Offload API print header")));
+ "Generate Offload API print header"),
+ clEnumValN(GenExports, "gen-exports",
+ "Generate export file for the Offload library")));
}
static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
@@ -75,6 +78,9 @@ static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
case GenPrintHeader:
EmitOffloadPrintHeader(Records, OS);
break;
+ case GenExports:
+ EmitOffloadExports(Records, OS);
+ break;
}
return false;
>From bb17c4fae86b5f90dde584a9e5d8d4021a5b9812 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 18 Sep 2024 11:15:00 +0100
Subject: [PATCH 03/14] Refactor entry point validation so failures are visible
in tracing output
---
.../tools/offload-tblgen/EntryPointGen.cpp | 34 +++++++++++++++----
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index b89592187639e3..27f8a306e40ddf 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -20,11 +20,10 @@
using namespace llvm;
using namespace offload::tblgen;
-static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
+static void EmitValidationFunc(const FunctionRec &F, raw_ostream &OS) {
OS << CommentsHeader;
// Emit preamble
- OS << formatv("{1}_APIEXPORT {0}_result_t {1}_APICALL {2}(\n ", PrefixLower,
- PrefixUpper, F.getName());
+ OS << formatv("{0}_result_t {1}_val(\n ", PrefixLower, F.getName());
// Emit arguments
std::string ParamNameList = "";
for (auto &Param : F.getParams()) {
@@ -37,7 +36,6 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
OS << ") {\n";
OS << TAB_1 "if (true /*enableParameterValidation*/) {\n";
-
// Emit validation checks
for (const auto &Return : F.getReturns()) {
for (auto &Condition : Return.getConditions()) {
@@ -49,16 +47,37 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
}
}
}
- OS << " }\n\n";
+ OS << TAB_1 "}\n\n";
+
+ // Perform actual function call to the implementation
+ ParamNameList = ParamNameList.substr(0, ParamNameList.size() - 2);
+ OS << formatv(TAB_1 "return {0}_impl({1});\n\n", F.getName(), ParamNameList);
+ OS << "}\n";
+}
+
+static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
+ // Emit preamble
+ OS << formatv("{1}_APIEXPORT {0}_result_t {1}_APICALL {2}(\n ", PrefixLower,
+ PrefixUpper, F.getName());
+ // Emit arguments
+ std::string ParamNameList = "";
+ for (auto &Param : F.getParams()) {
+ OS << Param.getType() << " " << Param.getName();
+ if (Param != F.getParams().back()) {
+ OS << ", ";
+ }
+ ParamNameList += Param.getName().str() + ", ";
+ }
+ OS << ") {\n";
// Emit pre-call prints
OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
OS << formatv(TAB_2 "std::cout << \"---> {0}\";\n", F.getName());
OS << TAB_1 "}\n\n";
- // Perform actual function call
+ // Perform actual function call to the validation wrapper
ParamNameList = ParamNameList.substr(0, ParamNameList.size() - 2);
- OS << formatv(TAB_1 "{0}_result_t result = {1}_impl({2});\n\n", PrefixLower,
+ OS << formatv(TAB_1 "{0}_result_t result = {1}_val({2});\n\n", PrefixLower,
F.getName(), ParamNameList);
// Emit post-call prints
@@ -81,6 +100,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
void EmitOffloadEntryPoints(RecordKeeper &Records, raw_ostream &OS) {
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ EmitValidationFunc(FunctionRec{R}, OS);
EmitEntryPointFunc(FunctionRec{R}, OS);
}
}
>From 2c98c64bd34bd1903de7d071cf902dbb9d1b1dee Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 26 Sep 2024 16:58:33 +0100
Subject: [PATCH 04/14] Add Offload API unittests
---
offload/new-api/src/offload_impl.cpp | 7 +-
offload/unittests/CMakeLists.txt | 3 +-
offload/unittests/OffloadAPI/CMakeLists.txt | 12 +++
.../OffloadAPI/common/environment.cpp | 92 ++++++++++++++++
.../OffloadAPI/common/environment.hpp | 17 +++
.../unittests/OffloadAPI/common/fixtures.hpp | 54 ++++++++++
.../OffloadAPI/device/offloadDeviceGet.cpp | 41 +++++++
.../device/offloadDeviceGetInfo.cpp | 102 ++++++++++++++++++
.../platform/offloadPlatformGet.cpp | 28 +++++
.../platform/offloadPlatformGetInfo.cpp | 97 +++++++++++++++++
10 files changed, 450 insertions(+), 3 deletions(-)
create mode 100644 offload/unittests/OffloadAPI/CMakeLists.txt
create mode 100644 offload/unittests/OffloadAPI/common/environment.cpp
create mode 100644 offload/unittests/OffloadAPI/common/environment.hpp
create mode 100644 offload/unittests/OffloadAPI/common/fixtures.hpp
create mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
create mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index b3bf602607ac47..c6c68eeba0bf72 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -25,6 +25,7 @@ using namespace llvm::omp::target::plugin;
struct offload_device_handle_t_ {
int DeviceNum;
GenericDeviceTy &Device;
+ offload_platform_handle_t Platform;
};
struct offload_platform_handle_t_ {
@@ -59,7 +60,7 @@ void initPlugins() {
DevNum++) {
if (Platform.Plugin->init_device(DevNum) == OFFLOAD_SUCCESS) {
Platform.Devices.emplace_back(offload_device_handle_t_{
- DevNum, Platform.Plugin->getDevice(DevNum)});
+ DevNum, Platform.Plugin->getDevice(DevNum), &Platform});
}
}
}
@@ -173,6 +174,8 @@ offload_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
};
switch (propName) {
+ case OFFLOAD_DEVICE_INFO_PLATFORM:
+ return ReturnValue(hDevice->Platform);
case OFFLOAD_DEVICE_INFO_TYPE:
return ReturnValue(OFFLOAD_DEVICE_TYPE_GPU);
case OFFLOAD_DEVICE_INFO_NAME:
@@ -183,7 +186,7 @@ offload_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
return ReturnValue(
GetInfo({"CUDA Driver Version", "HSA Runtime Version"}).c_str());
default:
- return OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
+ return OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION;
}
return OFFLOAD_RESULT_SUCCESS;
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index 73c87b708d25fd..25ac4b2fa36752 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -5,4 +5,5 @@ function(add_libompt_unittest test_dirname)
add_unittest(LibomptUnitTests ${test_dirname} ${ARGN})
endfunction()
-add_subdirectory(Plugins)
+# add_subdirectory(Plugins)
+add_subdirectory(OffloadAPI)
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
new file mode 100644
index 00000000000000..0960fa5a135111
--- /dev/null
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -0,0 +1,12 @@
+set(PLUGINS_TEST_COMMON offload_new)
+set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common)
+
+add_libompt_unittest("offload.unittests"
+ ${CMAKE_CURRENT_SOURCE_DIR}/common/environment.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGet.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGetInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGet.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfo.cpp)
+add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON})
+target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
+target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})
diff --git a/offload/unittests/OffloadAPI/common/environment.cpp b/offload/unittests/OffloadAPI/common/environment.cpp
new file mode 100644
index 00000000000000..a19e09fc5767c0
--- /dev/null
+++ b/offload/unittests/OffloadAPI/common/environment.cpp
@@ -0,0 +1,92 @@
+//===------- Offload API tests - gtest environment ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "environment.hpp"
+#include "fixtures.hpp"
+#include "llvm/Support/CommandLine.h"
+#include <offload_api.h>
+
+using namespace llvm;
+
+static cl::opt<std::string>
+ SelectedPlatform("platform", cl::desc("Only test the specified platform"),
+ cl::value_desc("platform"));
+
+std::ostream &operator<<(std::ostream &Out,
+ const offload_platform_handle_t &Platform) {
+ size_t Size;
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_NAME, 0, nullptr,
+ &Size);
+ std::vector<char> Name(Size);
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_NAME, Size,
+ Name.data(), nullptr);
+ Out << Name.data();
+ return Out;
+}
+
+std::ostream &
+operator<<(std::ostream &Out,
+ const std::vector<offload_platform_handle_t> &Platforms) {
+ for (auto Platform : Platforms) {
+ Out << "\n * \"" << Platform << "\"";
+ }
+ return Out;
+}
+
+const std::vector<offload_platform_handle_t> &TestEnvironment::getPlatforms() {
+ static std::vector<offload_platform_handle_t> Platforms{};
+
+ if (Platforms.empty()) {
+ uint32_t PlatformCount = 0;
+ offloadPlatformGet(0, nullptr, &PlatformCount);
+ if (PlatformCount > 0) {
+ Platforms.resize(PlatformCount);
+ offloadPlatformGet(PlatformCount, Platforms.data(), nullptr);
+ }
+ }
+
+ return Platforms;
+}
+
+// Get a single platform, which may be selected by the user.
+offload_platform_handle_t TestEnvironment::getPlatform() {
+ static offload_platform_handle_t Platform = nullptr;
+ const auto &Platforms = getPlatforms();
+
+ if (!Platform) {
+ if (SelectedPlatform != "") {
+ for (const auto CandidatePlatform : Platforms) {
+ std::stringstream PlatformName;
+ PlatformName << CandidatePlatform;
+ if (SelectedPlatform == PlatformName.str()) {
+ Platform = CandidatePlatform;
+ return Platform;
+ }
+ }
+ std::cout << "No platform found with the name \"" << SelectedPlatform
+ << "\". Choose from:" << Platforms << "\n";
+ std::exit(1);
+ } else {
+ // Pick a single platform. We prefer one that has available devices, but
+ // just pick the first initially in case none have any devices.
+ Platform = Platforms[0];
+ for (auto CandidatePlatform : Platforms) {
+ uint32_t NumDevices = 0;
+ if (offloadDeviceGet(CandidatePlatform, OFFLOAD_DEVICE_TYPE_ALL, 0,
+ nullptr, &NumDevices) == OFFLOAD_RESULT_SUCCESS) {
+ if (NumDevices > 0) {
+ Platform = CandidatePlatform;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return Platform;
+}
diff --git a/offload/unittests/OffloadAPI/common/environment.hpp b/offload/unittests/OffloadAPI/common/environment.hpp
new file mode 100644
index 00000000000000..3e85c54c7413eb
--- /dev/null
+++ b/offload/unittests/OffloadAPI/common/environment.hpp
@@ -0,0 +1,17 @@
+//===------- Offload API tests - gtest environment ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+namespace TestEnvironment {
+const std::vector<offload_platform_handle_t> &getPlatforms();
+offload_platform_handle_t getPlatform();
+} // namespace TestEnvironment
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/fixtures.hpp
new file mode 100644
index 00000000000000..a7f5f84adb2568
--- /dev/null
+++ b/offload/unittests/OffloadAPI/common/fixtures.hpp
@@ -0,0 +1,54 @@
+//===------- Offload API tests - gtest fixtures --==-----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <gtest/gtest.h>
+#include <offload_api.h>
+#include <offload_print.hpp>
+
+#include "environment.hpp"
+
+#pragma once
+
+#ifndef ASSERT_SUCCESS
+#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_RESULT_SUCCESS, ACTUAL)
+#endif
+
+#define RETURN_ON_FATAL_FAILURE(...) \
+ __VA_ARGS__; \
+ if (this->HasFatalFailure() || this->IsSkipped()) { \
+ return; \
+ } \
+ (void)0
+
+struct offloadPlatformTest : ::testing::Test {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(::testing::Test::SetUp());
+
+ Platform = TestEnvironment::getPlatform();
+ ASSERT_NE(Platform, nullptr);
+ }
+
+ offload_platform_handle_t Platform;
+};
+
+struct offloadDeviceTest : offloadPlatformTest {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(offloadPlatformTest::SetUp());
+
+ uint32_t NumDevices;
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0,
+ nullptr, &NumDevices));
+ if (NumDevices == 0) {
+ GTEST_SKIP() << "No available devices on this platform.";
+ }
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 1,
+ &Device, nullptr));
+ }
+
+ offload_device_handle_t Device;
+};
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
new file mode 100644
index 00000000000000..1442ebc98c7f6e
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
@@ -0,0 +1,41 @@
+//===------- Offload API tests - offloadDeviceGet -------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/fixtures.hpp"
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+using offloadDeviceGetTest = offloadPlatformTest;
+
+TEST_F(offloadDeviceGetTest, Success) {
+ uint32_t Count = 0;
+ ASSERT_SUCCESS(
+ offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0, nullptr, &Count));
+ ASSERT_NE(Count, 0lu);
+ std::vector<offload_device_handle_t> Devices(Count);
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, Count,
+ Devices.data(), nullptr));
+ for (auto Device : Devices) {
+ ASSERT_NE(nullptr, Device);
+ }
+}
+
+TEST_F(offloadDeviceGetTest, SuccessSubsetOfDevices) {
+ uint32_t Count;
+ ASSERT_SUCCESS(
+ offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0, nullptr, &Count));
+ if (Count < 2) {
+ GTEST_SKIP() << "Only one device is available on this platform.";
+ }
+ std::vector<offload_device_handle_t> Devices(Count - 1);
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, Count - 1,
+ Devices.data(), nullptr));
+ for (auto Device : Devices) {
+ ASSERT_NE(nullptr, Device);
+ }
+}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
new file mode 100644
index 00000000000000..df8aecc1f0be2d
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
@@ -0,0 +1,102 @@
+//===------- Offload API tests - offloadDeviceGetInfo ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/fixtures.hpp"
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+struct offloadDeviceGetInfoTest
+ : offloadDeviceTest,
+ ::testing::WithParamInterface<offload_device_info_t> {
+
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
+};
+
+// TODO: We could autogenerate the list of enum values
+INSTANTIATE_TEST_SUITE_P(
+ , offloadDeviceGetInfoTest,
+ ::testing::Values(OFFLOAD_DEVICE_INFO_TYPE, OFFLOAD_DEVICE_INFO_PLATFORM,
+ OFFLOAD_DEVICE_INFO_NAME, OFFLOAD_DEVICE_INFO_VENDOR,
+ OFFLOAD_DEVICE_INFO_DRIVER_VERSION),
+ [](const ::testing::TestParamInfo<offload_device_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+// TODO: We could autogenerate this
+std::unordered_map<offload_device_info_t, size_t> DeviceInfoSizeMap = {
+ {OFFLOAD_DEVICE_INFO_TYPE, sizeof(offload_device_type_t)},
+ {OFFLOAD_DEVICE_INFO_PLATFORM, sizeof(offload_platform_handle_t)},
+};
+
+TEST_P(offloadDeviceGetInfoTest, Success) {
+ offload_device_info_t InfoType = GetParam();
+ size_t Size = 0;
+
+ ASSERT_SUCCESS(offloadDeviceGetInfo(Device, InfoType, 0, nullptr, &Size));
+ auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
+ if (ExpectedSize != DeviceInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+
+ std::vector<char> InfoData(Size);
+ ASSERT_SUCCESS(
+ offloadDeviceGetInfo(Device, InfoType, Size, InfoData.data(), nullptr));
+
+ if (InfoType == OFFLOAD_DEVICE_INFO_PLATFORM) {
+ auto *ReturnedPlatform =
+ reinterpret_cast<offload_platform_handle_t *>(InfoData.data());
+ ASSERT_EQ(Platform, *ReturnedPlatform);
+ }
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidNullHandleDevice) {
+ offload_device_type_t DeviceType;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE,
+ offloadDeviceGetInfo(nullptr, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(offload_device_type_t), &DeviceType,
+ nullptr));
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidEnumerationInfoType) {
+ offload_device_type_t DeviceType;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_FORCE_UINT32,
+ sizeof(offload_device_type_t), &DeviceType,
+ nullptr));
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSize) {
+ offload_device_type_t DeviceType;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
+ &DeviceType, nullptr));
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSizeSmall) {
+ offload_device_type_t DeviceType;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(DeviceType) - 1, &DeviceType, nullptr));
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropValue) {
+ offload_device_type_t DeviceType;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(DeviceType), nullptr, nullptr));
+}
+
+TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropSizeRet) {
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0, nullptr,
+ nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
new file mode 100644
index 00000000000000..6ede71ff1babe6
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
@@ -0,0 +1,28 @@
+//===------- Offload API tests - offloadPlatformGet -----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <gtest/gtest.h>
+#include <offload_api.h>
+#include "../common/fixtures.hpp"
+
+using offloadPlatformGetTest = ::testing::Test;
+
+TEST_F(offloadPlatformGetTest, Success) {
+ uint32_t PlatformCount;
+ ASSERT_SUCCESS(offloadPlatformGet(0, nullptr, &PlatformCount));
+ std::vector<offload_platform_handle_t> Platforms(PlatformCount);
+ ASSERT_SUCCESS(offloadPlatformGet(PlatformCount, Platforms.data(), nullptr));
+}
+
+TEST_F(offloadPlatformGetTest, InvalidNumEntries) {
+ uint32_t PlatformCount;
+ ASSERT_SUCCESS(offloadPlatformGet(0, nullptr, &PlatformCount));
+ std::vector<offload_platform_handle_t> Platforms(PlatformCount);
+ ASSERT_EQ(offloadPlatformGet(0, Platforms.data(), nullptr),
+ OFFLOAD_RESULT_ERROR_INVALID_SIZE);
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
new file mode 100644
index 00000000000000..7a967ee674b00c
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
@@ -0,0 +1,97 @@
+//===------- Offload API tests - offloadPlatformGetInfo -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <offload_api.h>
+
+#include "../common/fixtures.hpp"
+
+struct offloadPlatformGetInfoTest
+ : offloadPlatformTest,
+ ::testing::WithParamInterface<offload_platform_info_t> {};
+
+// TODO: We could autogenerate the list of enum values
+INSTANTIATE_TEST_SUITE_P(
+ offloadPlatformGetInfo, offloadPlatformGetInfoTest,
+ ::testing::Values(OFFLOAD_PLATFORM_INFO_NAME,
+ OFFLOAD_PLATFORM_INFO_VENDOR_NAME,
+ OFFLOAD_PLATFORM_INFO_VERSION,
+ OFFLOAD_PLATFORM_INFO_BACKEND),
+ [](const ::testing::TestParamInfo<offload_platform_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+// TODO: We could autogenerate this
+std::unordered_map<offload_platform_info_t, size_t> PlatformInfoSizeMap = {
+ {OFFLOAD_PLATFORM_INFO_BACKEND, sizeof(offload_platform_backend_t)},
+};
+
+TEST_P(offloadPlatformGetInfoTest, Success) {
+ size_t Size = 0;
+ offload_platform_info_t InfoType = GetParam();
+
+ ASSERT_SUCCESS(offloadPlatformGetInfo(Platform, InfoType, 0, nullptr, &Size));
+ auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
+ if (ExpectedSize != PlatformInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+
+ std::vector<char> InfoData(Size);
+ ASSERT_SUCCESS(offloadPlatformGetInfo(Platform, InfoType, Size,
+ InfoData.data(), nullptr));
+
+ // Info types with a dynamic size are all char[] so we can verify the returned
+ // string is the expected size.
+ if (ExpectedSize == PlatformInfoSizeMap.end()) {
+ ASSERT_EQ(Size, strlen(InfoData.data()) + 1);
+ }
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidNullHandle) {
+ size_t Size = 0;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE,
+ offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
+ nullptr, &Size));
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidPlatformInfoEnumeration) {
+ size_t Size = 0;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_FORCE_UINT32,
+ 0, nullptr, &Size));
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidSizeZero) {
+ offload_platform_backend_t Backend;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
+ &Backend, nullptr));
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidSizeSmall) {
+ offload_platform_backend_t Backend;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ sizeof(Backend) - 1, &Backend, nullptr));
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropValue) {
+ offload_platform_backend_t Backend;
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), nullptr, nullptr));
+}
+
+TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropSizeRet) {
+ ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
+ nullptr, nullptr));
+}
>From 5d926712b062c3e1827d58602daaeaf1835e9915 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Tue, 1 Oct 2024 09:46:03 +0100
Subject: [PATCH 05/14] Implement optional error details
---
offload/new-api/API/Common.td | 18 ++++++-
offload/new-api/CMakeLists.txt | 1 +
offload/new-api/include/offload_impl.hpp | 33 ++++++++++++
offload/new-api/src/offload_impl.cpp | 50 +++++++++++++------
offload/new-api/src/offload_lib.cpp | 9 ++++
.../tools/offload-tblgen/EntryPointGen.cpp | 4 ++
offload/tools/offload-tblgen/FuncsGen.cpp | 8 ++-
7 files changed, 107 insertions(+), 16 deletions(-)
create mode 100644 offload/new-api/include/offload_impl.hpp
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index d293e4addfef8b..55d03d4ff1e783 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -72,4 +72,20 @@ def : Enum {
Etor<"ERROR_UNSUPPORTED_ENUMERATION", "[Validation] enumerator argument is not supported by the device">,
Etor<"ERROR_UNKNOWN", "Unknown or internal error">
];
-}
\ No newline at end of file
+}
+
+def : Function {
+ let name = "offloadGetErrorDetails";
+ let desc = "Get a detailed error message for the last error that occurred on this thread, if it exists";
+ let details = [
+ "When an Offload API call returns a return value other than OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error message.",
+ "If a further Offload call (excluding this function) is made on the same thread without checking "
+ "its detailed error message with this function, that message should be considered lost.",
+ "The returned char* is only valid until the next Offload function call on the same thread (excluding further calls to this function.)"
+ ];
+ let params = [
+ Param<"size_t*", "SizeRet", "Pointer to return the size of the available error message. A size of 0 indicates no message.", PARAM_OUT_OPTIONAL>,
+ Param<"const char**", "DetailStringRet", "Pointer to return the error message string.", PARAM_OUT_OPTIONAL>
+ ];
+ let returns = []; // Only SUCCESS is expected
+}
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
index ac82e7db647601..be1e711564c244 100644
--- a/offload/new-api/CMakeLists.txt
+++ b/offload/new-api/CMakeLists.txt
@@ -26,6 +26,7 @@ endif()
target_include_directories(offload_new PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
new file mode 100644
index 00000000000000..1e96fdebfc765e
--- /dev/null
+++ b/offload/new-api/include/offload_impl.hpp
@@ -0,0 +1,33 @@
+//===- offload_impl.hpp- Implementation helpers for the Offload library ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <offload_api.h>
+#include <optional>
+#include <string>
+
+#include "llvm/ADT/StringRef.h"
+
+std::optional<std::string> &LastErrorDetails();
+
+struct offload_impl_result_t {
+ offload_impl_result_t() = delete;
+ offload_impl_result_t(offload_result_t Result) : Result(Result) {
+ LastErrorDetails() = std::nullopt;
+ }
+
+ offload_impl_result_t(offload_result_t Result, std::string Details)
+ : Result(Result) {
+ assert(Result != OFFLOAD_RESULT_SUCCESS);
+ LastErrorDetails() = Details;
+ }
+
+ operator offload_result_t() { return Result; }
+
+private:
+ offload_result_t Result;
+};
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index c6c68eeba0bf72..b544a847a8dbd2 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -13,6 +13,7 @@
#include "PluginManager.h"
#include "helpers.hpp"
+#include "offload_impl.hpp"
#include "llvm/Support/FormatVariadic.h"
#include <offload_api.h>
@@ -66,9 +67,27 @@ void initPlugins() {
}
}
-offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms) {
+offload_result_t offloadGetErrorDetails_impl(size_t *SizeRet,
+ const char **DetailStringRet) {
+ if (auto Details = LastErrorDetails()) {
+ if (SizeRet) {
+ *SizeRet = Details->size();
+ }
+ if (DetailStringRet) {
+ *DetailStringRet = Details->c_str();
+ }
+ } else {
+ if (SizeRet) {
+ *SizeRet = 0;
+ }
+ }
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_impl_result_t
+offloadPlatformGet_impl(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms) {
// It is expected that offloadPlatformGet is the first function to be called.
// In future it may make sense to have a specific entry point for Offload
// initialization, or expose explicit initialization of plugins.
@@ -76,7 +95,9 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
std::call_once(InitFlag, initPlugins);
if (NumEntries > Platforms().size()) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return {OFFLOAD_RESULT_ERROR_INVALID_SIZE,
+ formatv("{0} platform(s) available but {1} requested.",
+ Platforms().size(), NumEntries)};
}
if (phPlatforms) {
@@ -93,7 +114,7 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
return OFFLOAD_RESULT_SUCCESS;
}
-offload_result_t
+offload_impl_result_t
offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
offload_platform_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
@@ -126,11 +147,11 @@ offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
return OFFLOAD_RESULT_SUCCESS;
}
-offload_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
- offload_device_type_t,
- uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- uint32_t *pNumDevices) {
+offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
+ offload_device_type_t,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices) {
if (phDevices) {
for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
@@ -145,10 +166,11 @@ offload_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
return OFFLOAD_RESULT_SUCCESS;
}
-offload_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize, void *pPropValue,
- size_t *pPropSizeRet) {
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize,
+ void *pPropValue,
+ size_t *pPropSizeRet) {
ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index b2452b2cdab950..a8a23e94a2fd6c 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -10,11 +10,20 @@
//
//===----------------------------------------------------------------------===//
+#include "offload_impl.hpp"
#include <offload_api.h>
#include <offload_print.hpp>
#include <iostream>
+// Store details for the last error that occurred on this thread. It MAY be set
+// when an implementation function returns a result other than
+// OFFLOAD_RESULT_SUCCESS.
+std::optional<std::string> &LastErrorDetails() {
+ thread_local std::optional<std::string> Details;
+ return Details;
+}
+
// Pull in the declarations for the implementation funtions. The actual entry
// points in this file wrap these.
#include "offload_impl_func_decls.inc"
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 27f8a306e40ddf..5dbb0e8c22ae04 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -92,6 +92,10 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
OS << formatv("};\n");
OS << TAB_2 "std::cout << \"(\" << &Params << \")\";\n";
OS << TAB_2 "std::cout << \"-> \" << result << \"\\n\";\n";
+ OS << TAB_2 "if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {\n";
+ OS << TAB_3 "std::cout << \" *Error Details* \" << *LastErrorDetails() "
+ "<< \" \\n\";\n";
+ OS << TAB_2 "}\n";
OS << TAB_1 "}\n";
OS << TAB_1 "return result;\n";
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index 567d784f320010..ee651957abc703 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -52,7 +52,13 @@ void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
FunctionRec F{R};
- OS << formatv("{0}_result_t {1}_impl(", PrefixLower, F.getName());
+ // The error details function does not set error details itself, so don't
+ // use the impl result type
+ if (F.getName() == "offloadGetErrorDetails") {
+ OS << formatv("{0}_result_t {1}_impl(", PrefixLower, F.getName());
+ } else {
+ OS << formatv("{0}_impl_result_t {1}_impl(", PrefixLower, F.getName());
+ }
auto Params = F.getParams();
for (auto &Param : Params) {
OS << Param.getType() << " " << Param.getName();
>From 35e70fbece205cef8e8754a5b6acf141a41dd8aa Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Tue, 1 Oct 2024 17:31:28 +0100
Subject: [PATCH 06/14] Check in auto-generated Offload files
---
offload/new-api/CMakeLists.txt | 17 +-
offload/new-api/include/offload_api.h | 342 ++++++++++++++++
.../new-api/include/offload_entry_points.inc | 195 +++++++++
offload/new-api/include/offload_exports | 10 +
offload/new-api/include/offload_funcs.inc | 19 +
.../include/offload_impl_func_decls.inc | 12 +
offload/new-api/include/offload_print.hpp | 380 ++++++++++++++++++
offload/tools/offload-tblgen/APIGen.cpp | 1 +
.../tools/offload-tblgen/EntryPointGen.cpp | 1 +
offload/tools/offload-tblgen/FuncsGen.cpp | 2 +
offload/tools/offload-tblgen/GenCommon.hpp | 10 +
offload/tools/offload-tblgen/PrintGen.cpp | 1 +
12 files changed, 985 insertions(+), 5 deletions(-)
create mode 100644 offload/new-api/include/offload_api.h
create mode 100644 offload/new-api/include/offload_entry_points.inc
create mode 100644 offload/new-api/include/offload_exports
create mode 100644 offload/new-api/include/offload_funcs.inc
create mode 100644 offload/new-api/include/offload_impl_func_decls.inc
create mode 100644 offload/new-api/include/offload_print.hpp
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
index be1e711564c244..9c82eb841bb8b8 100644
--- a/offload/new-api/CMakeLists.txt
+++ b/offload/new-api/CMakeLists.txt
@@ -8,23 +8,30 @@ tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
tablegen(OFFLOAD offload_print.hpp -gen-print-header)
tablegen(OFFLOAD offload_exports -gen-exports)
-add_public_tablegen_target(OffloadHeaderGen)
+foreach(itm IN LISTS TABLEGEN_OUTPUT)
+ message(${itm})
+endforeach()
+
+set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT})
+add_public_tablegen_target(OffloadGenerate)
+
+add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
+ -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/include")
add_llvm_library(offload_new SHARED
src/offload_lib.cpp
src/offload_impl.cpp
- DEPENDS OffloadHeaderGen)
+ DEPENDS OffloadGenerate)
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
endforeach()
if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
- target_link_libraries(offload_new PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/offload_exports")
+ target_link_libraries(offload_new PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/include/offload_exports")
endif()
target_include_directories(offload_new PUBLIC
- ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../include
@@ -39,4 +46,4 @@ set_target_properties(offload_new PROPERTIES
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
install(TARGETS offload_new LIBRARY COMPONENT offload_new DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
new file mode 100644
index 00000000000000..c046496a2e0f9f
--- /dev/null
+++ b/offload/new-api/include/offload_api.h
@@ -0,0 +1,342 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Auto-generated file, do not manually edit.
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_APICALL
+#if defined(_WIN32)
+/// @brief Calling convention for all API functions
+#define OFFLOAD_APICALL __cdecl
+#else
+#define OFFLOAD_APICALL
+#endif // defined(_WIN32)
+#endif // OFFLOAD_APICALL
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_APIEXPORT
+#if defined(_WIN32)
+/// @brief Microsoft-specific dllexport storage-class attribute
+#define OFFLOAD_APIEXPORT __declspec(dllexport)
+#else
+#define OFFLOAD_APIEXPORT
+#endif // defined(_WIN32)
+#endif // OFFLOAD_APIEXPORT
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_DLLEXPORT
+#if defined(_WIN32)
+/// @brief Microsoft-specific dllexport storage-class attribute
+#define OFFLOAD_DLLEXPORT __declspec(dllexport)
+#endif // defined(_WIN32)
+#endif // OFFLOAD_DLLEXPORT
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_DLLEXPORT
+#if __GNUC__ >= 4
+/// @brief GCC-specific dllexport storage-class attribute
+#define OFFLOAD_DLLEXPORT __attribute__ ((visibility ("default")))
+#else
+#define OFFLOAD_DLLEXPORT
+#endif // __GNUC__ >= 4
+#endif // OFFLOAD_DLLEXPORT
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief compiler-independent type
+typedef uint8_t offload_bool_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Handle of a platform instance
+typedef struct offload_platform_handle_t_ *offload_platform_handle_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Handle of platform's device object
+typedef struct offload_device_handle_t_ *offload_device_handle_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Handle of context object
+typedef struct offload_context_handle_t_ *offload_context_handle_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Defines Return/Error codes
+typedef enum offload_result_t {
+ OFFLOAD_RESULT_SUCCESS = 0, ///< Success
+ OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1, ///< Invalid Value
+ OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2, ///< Invalid platform
+ OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3, ///< Device not found
+ OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4, ///< Invalid device
+ OFFLOAD_RESULT_ERROR_DEVICE_LOST = 5, ///< Device hung, reset, was removed, or driver update occurred
+ OFFLOAD_RESULT_ERROR_UNINITIALIZED = 6, ///< plugin is not initialized or specific entry-point is not implemented
+ OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7, ///< Out of resources
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION = 8, ///< [Validation] generic error code for unsupported versions
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE = 9, ///< [Validation] generic error code for unsupported features
+ OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT = 10, ///< [Validation] generic error code for invalid arguments
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE = 11, ///< [Validation] handle argument is not valid
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER = 12, ///< [Validation] pointer argument may not be nullptr
+ OFFLOAD_RESULT_ERROR_INVALID_SIZE = 13, ///< [Validation] invalid size or dimensions (e.g., must not be zero, or is out of bounds)
+ OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION = 14, ///< [Validation] enumerator argument is not valid
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION = 15, ///< [Validation] enumerator argument is not supported by the device
+ OFFLOAD_RESULT_ERROR_UNKNOWN = 16, ///< Unknown or internal error
+ /// @cond
+ OFFLOAD_RESULT_FORCE_UINT32 = 0x7fffffff
+ /// @endcond
+
+} offload_result_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Get a detailed error message for the last error that occurred on this thread, if it exists
+///
+/// @details
+/// - When an Offload API call returns a return value other than OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error message.
+/// - If a further Offload call (excluding this function) is made on the same thread without checking its detailed error message with this function, that message should be considered lost.
+/// - The returned char* is only valid until the next Offload function call on the same thread (excluding further calls to this function.)
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
+ size_t* SizeRet, ///< [out][optional] Pointer to return the size of the available error message. A size of 0 indicates no message.
+ const char** DetailStringRet ///< [out][optional] Pointer to return the error message string.
+);
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves all available platforms
+///
+/// @details
+/// - Multiple calls to this function will return identical platforms handles, in the same order.
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// + `NumEntries == 0 && phPlatforms != NULL`
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
+ uint32_t NumEntries, ///< [in] The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, thenNumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
+ offload_platform_handle_t* phPlatforms, ///< [out][optional] Array of handle of platforms. If NumEntries isless than the number of platforms available, then offloadPlatformGetshall only retrieve that number of platforms.
+ uint32_t* pNumPlatforms ///< [out][optional] returns the total number of platforms available.
+);
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Supported platform info
+typedef enum offload_platform_info_t {
+ OFFLOAD_PLATFORM_INFO_NAME = 0, ///< The string denoting name of the platform. The size of the info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VENDOR_NAME = 1, ///< The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VERSION = 2, ///< The string denoting the version of the platform. The size of the info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_BACKEND = 3, ///< The backend of the platform. Identifies the native backend adapter implementing this platform.
+ /// @cond
+ OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
+ /// @endcond
+
+} offload_platform_info_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Identifies the native backend of the platform
+typedef enum offload_platform_backend_t {
+ OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0, ///< The backend is not recognized
+ OFFLOAD_PLATFORM_BACKEND_CUDA = 1, ///< The backend is CUDA
+ OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2, ///< The backend is AMDGPU
+ /// @cond
+ OFFLOAD_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
+ /// @endcond
+
+} offload_platform_backend_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves various information about platform
+///
+/// @details
+/// - The application may call this function from simultaneous threads.
+/// - The implementation of this function should be lock-free.
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION
+/// + If `propName` is not supported by the platform.
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// + `propSize == 0 && pPropValue != NULL`
+/// + If `propSize` is less than the real number of bytes needed to return the info.
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// + `propSize != 0 && pPropValue == NULL`
+/// + `pPropValue == NULL && pPropSizeRet == NULL`
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_PLATFORM
+/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES
+/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// + `NULL == hPlatform`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
+ offload_platform_handle_t hPlatform, ///< [in] handle of the platform
+ offload_platform_info_t propName, ///< [in] type of the info to retrieve
+ size_t propSize, ///< [in] the number of bytes pointed to by pPlatformInfo.
+ void* pPropValue, ///< [out][optional] array of bytes holding the info.If Size is not equal to or greater to the real number of bytes needed to return the infothen the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.
+ size_t* pPropSizeRet ///< [out][optional] pointer to the actual number of bytes being queried by pPlatformInfo.
+);
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Supported device types
+typedef enum offload_device_type_t {
+ OFFLOAD_DEVICE_TYPE_DEFAULT = 0, ///< The default device type as preferred by the runtime
+ OFFLOAD_DEVICE_TYPE_ALL = 1, ///< Devices of all types
+ OFFLOAD_DEVICE_TYPE_GPU = 2, ///< GPU device type
+ OFFLOAD_DEVICE_TYPE_CPU = 3, ///< CPU device type
+ /// @cond
+ OFFLOAD_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
+ /// @endcond
+
+} offload_device_type_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Supported device info
+typedef enum offload_device_info_t {
+ OFFLOAD_DEVICE_INFO_TYPE = 0, ///< type of the device
+ OFFLOAD_DEVICE_INFO_PLATFORM = 1, ///< the platform associated with the device
+ OFFLOAD_DEVICE_INFO_NAME = 2, ///< Device name
+ OFFLOAD_DEVICE_INFO_VENDOR = 3, ///< Device vendor
+ OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4, ///< Driver version
+ /// @cond
+ OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
+ /// @endcond
+
+} offload_device_info_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves devices within a platform
+///
+/// @details
+/// - Multiple calls to this function will return identical device handles, in the same order.
+/// - The number and order of handles returned from this function can be affected by environment variables that filter devices exposed through API.
+/// - The returned devices are taken a reference of and must be released with a subsequent call to olDeviceRelease.
+/// - The application may call this function from simultaneous threads, the implementation must be thread-safe
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// + `NumEntries == 0 && phDevices != NULL`
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// + `NumEntries > 0 && phDevices == NULL`
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_VALUE
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// + `NULL == hPlatform`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
+ offload_platform_handle_t hPlatform, ///< [in] handle of the platform instance
+ offload_device_type_t DeviceType, ///< [in] the type of the devices.
+ uint32_t NumEntries, ///< [in] the number of devices to be added to phDevices.If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
+ offload_device_handle_t* phDevices, ///< [out][optional] array of handle of devices.If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.
+ uint32_t* pNumDevices ///< [out][optional] pointer to the number of devices.pNumDevices will be updated with the total number of devices available.
+);
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves various information about device
+///
+/// @details
+/// - The application may call this function from simultaneous threads.
+/// - The implementation of this function should be lock-free.
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION
+/// + If `propName` is not supported by the adapter.
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// + `propSize == 0 && pPropValue != NULL`
+/// + If `propSize` is less than the real number of bytes needed to return the info.
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// + `propSize != 0 && pPropValue == NULL`
+/// + `pPropValue == NULL && pPropSizeRet == NULL`
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_DEVICE
+/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES
+/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY
+/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// + `NULL == hDevice`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
+ offload_device_handle_t hDevice, ///< [in] handle of the device instance
+ offload_device_info_t propName, ///< [in] type of the info to retrieve
+ size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
+ void* pPropValue, ///< [out][optional] array of bytes holding the info. If propSize is not equal to or greater than the real number of bytes needed to return the info then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPropValue is not used.
+ size_t* pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName.
+);
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadGetErrorDetails
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_get_error_details_params_t {
+ size_t** pSizeRet;
+ const char*** pDetailStringRet;
+} offload_get_error_details_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadPlatformGet
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_platform_get_params_t {
+ uint32_t* pNumEntries;
+ offload_platform_handle_t** pphPlatforms;
+ uint32_t** ppNumPlatforms;
+} offload_platform_get_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadPlatformGetInfo
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_platform_get_info_params_t {
+ offload_platform_handle_t* phPlatform;
+ offload_platform_info_t* ppropName;
+ size_t* ppropSize;
+ void** ppPropValue;
+ size_t** ppPropSizeRet;
+} offload_platform_get_info_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadDeviceGet
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_device_get_params_t {
+ offload_platform_handle_t* phPlatform;
+ offload_device_type_t* pDeviceType;
+ uint32_t* pNumEntries;
+ offload_device_handle_t** pphDevices;
+ uint32_t** ppNumDevices;
+} offload_device_get_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadDeviceGetInfo
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_device_get_info_params_t {
+ offload_device_handle_t* phDevice;
+ offload_device_info_t* ppropName;
+ size_t* ppropSize;
+ void** ppPropValue;
+ size_t** ppPropSizeRet;
+} offload_device_get_info_params_t;
+
+#if defined(__cplusplus)
+} // extern "C"
+#endif
+
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
new file mode 100644
index 00000000000000..ce7b784f341a09
--- /dev/null
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -0,0 +1,195 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+///////////////////////////////////////////////////////////////////////////////
+offload_result_t offloadGetErrorDetails_val(
+ size_t* SizeRet, const char** DetailStringRet) {
+ if (true /*enableParameterValidation*/) {
+ }
+
+ return offloadGetErrorDetails_impl(SizeRet, DetailStringRet);
+
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
+ size_t* SizeRet, const char** DetailStringRet) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadGetErrorDetails";
+ }
+
+ offload_result_t result = offloadGetErrorDetails_val(SizeRet, DetailStringRet);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_get_error_details_params_t Params = { &SizeRet, &DetailStringRet};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
+ std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ }
+ }
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_result_t offloadPlatformGet_val(
+ uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms) {
+ if (true /*enableParameterValidation*/) {
+ if (NumEntries == 0 && phPlatforms != NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+
+ }
+
+ return offloadPlatformGet_impl(NumEntries, phPlatforms, pNumPlatforms);
+
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
+ uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadPlatformGet";
+ }
+
+ offload_result_t result = offloadPlatformGet_val(NumEntries, phPlatforms, pNumPlatforms);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_platform_get_params_t Params = { &NumEntries, &phPlatforms, &pNumPlatforms};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
+ std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ }
+ }
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_result_t offloadPlatformGetInfo_val(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ if (true /*enableParameterValidation*/) {
+ if (propSize == 0 && pPropValue != NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+
+ if (propSize != 0 && pPropValue == NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (pPropValue == NULL && pPropSizeRet == NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (NULL == hPlatform) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ }
+
+ }
+
+ return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadPlatformGetInfo";
+ }
+
+ offload_result_t result = offloadPlatformGetInfo_val(hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_platform_get_info_params_t Params = { &hPlatform, &propName, &propSize, &pPropValue, &pPropSizeRet};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
+ std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ }
+ }
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_result_t offloadDeviceGet_val(
+ offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices) {
+ if (true /*enableParameterValidation*/) {
+ if (NumEntries == 0 && phDevices != NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+
+ if (NumEntries > 0 && phDevices == NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (NULL == hPlatform) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ }
+
+ }
+
+ return offloadDeviceGet_impl(hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
+
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
+ offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadDeviceGet";
+ }
+
+ offload_result_t result = offloadDeviceGet_val(hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_device_get_params_t Params = { &hPlatform, &DeviceType, &NumEntries, &phDevices, &pNumDevices};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
+ std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ }
+ }
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_result_t offloadDeviceGetInfo_val(
+ offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ if (true /*enableParameterValidation*/) {
+ if (propSize == 0 && pPropValue != NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ }
+
+ if (propSize != 0 && pPropValue == NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (pPropValue == NULL && pPropSizeRet == NULL) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ }
+
+ if (NULL == hDevice) {
+ return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ }
+
+ }
+
+ return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue, pPropSizeRet);
+
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
+ offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadDeviceGetInfo";
+ }
+
+ offload_result_t result = offloadDeviceGetInfo_val(hDevice, propName, propSize, pPropValue, pPropSizeRet);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_device_get_info_params_t Params = { &hDevice, &propName, &propSize, &pPropValue, &pPropSizeRet};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
+ std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ }
+ }
+ return result;
+}
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
new file mode 100644
index 00000000000000..ec44d7cc0c2132
--- /dev/null
+++ b/offload/new-api/include/offload_exports
@@ -0,0 +1,10 @@
+VERS1.0 {
+ global:
+ offloadGetErrorDetails;
+ offloadPlatformGet;
+ offloadPlatformGetInfo;
+ offloadDeviceGet;
+ offloadDeviceGetInfo;
+ local:
+ *;
+};
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/new-api/include/offload_funcs.inc
new file mode 100644
index 00000000000000..7160b27a5332cf
--- /dev/null
+++ b/offload/new-api/include/offload_funcs.inc
@@ -0,0 +1,19 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OFFLOAD_FUNC
+#error Please define the macro OFFLOAD_FUNC(Function)
+#endif
+
+OFFLOAD_FUNC(offloadGetErrorDetails)
+OFFLOAD_FUNC(offloadPlatformGet)
+OFFLOAD_FUNC(offloadPlatformGetInfo)
+OFFLOAD_FUNC(offloadDeviceGet)
+OFFLOAD_FUNC(offloadDeviceGetInfo)
+
+#undef OFFLOAD_FUNC
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
new file mode 100644
index 00000000000000..1405a3e38c7c8c
--- /dev/null
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -0,0 +1,12 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+offload_result_t offloadGetErrorDetails_impl(size_t* SizeRet, const char** DetailStringRet);
+offload_impl_result_t offloadPlatformGet_impl(uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms);
+offload_impl_result_t offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet);
+offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices);
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet);
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
new file mode 100644
index 00000000000000..8b14d222a7245c
--- /dev/null
+++ b/offload/new-api/include/offload_print.hpp
@@ -0,0 +1,380 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Auto-generated file, do not manually edit.
+
+#pragma once
+
+#include <offload_api.h>
+#include <ostream>
+
+
+template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr);
+template <typename T> inline void printTagged(std::ostream &os, const void *ptr, T value, size_t size);
+template <typename T> struct is_handle : std::false_type {};
+template <> struct is_handle<offload_platform_handle_t> : std::true_type {};
+template <> struct is_handle<offload_device_handle_t> : std::true_type {};
+template <> struct is_handle<offload_context_handle_t> : std::true_type {};
+template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
+
+inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value);
+inline std::ostream &operator<<(std::ostream &os, enum offload_platform_info_t value);
+inline std::ostream &operator<<(std::ostream &os, enum offload_platform_backend_t value);
+inline std::ostream &operator<<(std::ostream &os, enum offload_device_type_t value);
+inline std::ostream &operator<<(std::ostream &os, enum offload_device_info_t value);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the offload_result_t type
+/// @returns std::ostream &
+inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value) {
+ switch (value) {
+ case OFFLOAD_RESULT_SUCCESS:
+ os << "OFFLOAD_RESULT_SUCCESS";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_VALUE:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_VALUE";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_PLATFORM:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_PLATFORM";
+ break;
+ case OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND:
+ os << "OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_DEVICE:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_DEVICE";
+ break;
+ case OFFLOAD_RESULT_ERROR_DEVICE_LOST:
+ os << "OFFLOAD_RESULT_ERROR_DEVICE_LOST";
+ break;
+ case OFFLOAD_RESULT_ERROR_UNINITIALIZED:
+ os << "OFFLOAD_RESULT_ERROR_UNINITIALIZED";
+ break;
+ case OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES:
+ os << "OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES";
+ break;
+ case OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION:
+ os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION";
+ break;
+ case OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE:
+ os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_SIZE:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_SIZE";
+ break;
+ case OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION:
+ os << "OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION";
+ break;
+ case OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
+ os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION";
+ break;
+ case OFFLOAD_RESULT_ERROR_UNKNOWN:
+ os << "OFFLOAD_RESULT_ERROR_UNKNOWN";
+ break;
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the offload_platform_info_t type
+/// @returns std::ostream &
+inline std::ostream &operator<<(std::ostream &os, enum offload_platform_info_t value) {
+ switch (value) {
+ case OFFLOAD_PLATFORM_INFO_NAME:
+ os << "OFFLOAD_PLATFORM_INFO_NAME";
+ break;
+ case OFFLOAD_PLATFORM_INFO_VENDOR_NAME:
+ os << "OFFLOAD_PLATFORM_INFO_VENDOR_NAME";
+ break;
+ case OFFLOAD_PLATFORM_INFO_VERSION:
+ os << "OFFLOAD_PLATFORM_INFO_VERSION";
+ break;
+ case OFFLOAD_PLATFORM_INFO_BACKEND:
+ os << "OFFLOAD_PLATFORM_INFO_BACKEND";
+ break;
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print type-tagged offload_platform_info_t enum value
+/// @returns std::ostream &
+template <>
+inline void printTagged(std::ostream &os, const void *ptr, offload_platform_info_t value, size_t size) {
+ if (ptr == NULL) {
+ printPtr(os, ptr);
+ return;
+ }
+
+ switch (value) {
+ case OFFLOAD_PLATFORM_INFO_NAME: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ case OFFLOAD_PLATFORM_INFO_VENDOR_NAME: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ case OFFLOAD_PLATFORM_INFO_VERSION: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ case OFFLOAD_PLATFORM_INFO_BACKEND: {
+ const offload_platform_backend_t * const tptr = (const offload_platform_backend_t * const)ptr;
+ os << (const void *)tptr << " (";
+ os << *tptr;
+ os << ")";
+ break;
+ }
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+}
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the offload_platform_backend_t type
+/// @returns std::ostream &
+inline std::ostream &operator<<(std::ostream &os, enum offload_platform_backend_t value) {
+ switch (value) {
+ case OFFLOAD_PLATFORM_BACKEND_UNKNOWN:
+ os << "OFFLOAD_PLATFORM_BACKEND_UNKNOWN";
+ break;
+ case OFFLOAD_PLATFORM_BACKEND_CUDA:
+ os << "OFFLOAD_PLATFORM_BACKEND_CUDA";
+ break;
+ case OFFLOAD_PLATFORM_BACKEND_AMDGPU:
+ os << "OFFLOAD_PLATFORM_BACKEND_AMDGPU";
+ break;
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the offload_device_type_t type
+/// @returns std::ostream &
+inline std::ostream &operator<<(std::ostream &os, enum offload_device_type_t value) {
+ switch (value) {
+ case OFFLOAD_DEVICE_TYPE_DEFAULT:
+ os << "OFFLOAD_DEVICE_TYPE_DEFAULT";
+ break;
+ case OFFLOAD_DEVICE_TYPE_ALL:
+ os << "OFFLOAD_DEVICE_TYPE_ALL";
+ break;
+ case OFFLOAD_DEVICE_TYPE_GPU:
+ os << "OFFLOAD_DEVICE_TYPE_GPU";
+ break;
+ case OFFLOAD_DEVICE_TYPE_CPU:
+ os << "OFFLOAD_DEVICE_TYPE_CPU";
+ break;
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print operator for the offload_device_info_t type
+/// @returns std::ostream &
+inline std::ostream &operator<<(std::ostream &os, enum offload_device_info_t value) {
+ switch (value) {
+ case OFFLOAD_DEVICE_INFO_TYPE:
+ os << "OFFLOAD_DEVICE_INFO_TYPE";
+ break;
+ case OFFLOAD_DEVICE_INFO_PLATFORM:
+ os << "OFFLOAD_DEVICE_INFO_PLATFORM";
+ break;
+ case OFFLOAD_DEVICE_INFO_NAME:
+ os << "OFFLOAD_DEVICE_INFO_NAME";
+ break;
+ case OFFLOAD_DEVICE_INFO_VENDOR:
+ os << "OFFLOAD_DEVICE_INFO_VENDOR";
+ break;
+ case OFFLOAD_DEVICE_INFO_DRIVER_VERSION:
+ os << "OFFLOAD_DEVICE_INFO_DRIVER_VERSION";
+ break;
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Print type-tagged offload_device_info_t enum value
+/// @returns std::ostream &
+template <>
+inline void printTagged(std::ostream &os, const void *ptr, offload_device_info_t value, size_t size) {
+ if (ptr == NULL) {
+ printPtr(os, ptr);
+ return;
+ }
+
+ switch (value) {
+ case OFFLOAD_DEVICE_INFO_TYPE: {
+ const offload_device_type_t * const tptr = (const offload_device_type_t * const)ptr;
+ os << (const void *)tptr << " (";
+ os << *tptr;
+ os << ")";
+ break;
+ }
+ case OFFLOAD_DEVICE_INFO_PLATFORM: {
+ const offload_platform_handle_t * const tptr = (const offload_platform_handle_t * const)ptr;
+ os << (const void *)tptr << " (";
+ os << *tptr;
+ os << ")";
+ break;
+ }
+ case OFFLOAD_DEVICE_INFO_NAME: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ case OFFLOAD_DEVICE_INFO_VENDOR: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ case OFFLOAD_DEVICE_INFO_DRIVER_VERSION: {
+ printPtr(os, (const char*) ptr);
+ break;
+ }
+ default:
+ os << "unknown enumerator";
+ break;
+ }
+}
+
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_get_error_details_params_t *params) {
+ os << ".SizeRet = ";
+ printPtr(os, *params->pSizeRet);
+ os << ", ";
+ os << ".DetailStringRet = ";
+ printPtr(os, *params->pDetailStringRet);
+ return os;
+}
+
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_platform_get_params_t *params) {
+ os << ".NumEntries = ";
+ os << *params->pNumEntries;
+ os << ", ";
+ os << ".phPlatforms = ";
+ os << "{";
+ for (size_t i = 0; i < *params->pNumEntries; i++){
+ if (i > 0) {
+ os << ", ";
+ }
+ printPtr(os, (*params->pphPlatforms)[i]);
+ }
+ os << "}";
+ os << ", ";
+ os << ".pNumPlatforms = ";
+ printPtr(os, *params->ppNumPlatforms);
+ return os;
+}
+
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_platform_get_info_params_t *params) {
+ os << ".hPlatform = ";
+ printPtr(os, *params->phPlatform);
+ os << ", ";
+ os << ".propName = ";
+ os << *params->ppropName;
+ os << ", ";
+ os << ".propSize = ";
+ os << *params->ppropSize;
+ os << ", ";
+ os << ".pPropValue = ";
+ printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ os << ", ";
+ os << ".pPropSizeRet = ";
+ printPtr(os, *params->ppPropSizeRet);
+ return os;
+}
+
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_device_get_params_t *params) {
+ os << ".hPlatform = ";
+ printPtr(os, *params->phPlatform);
+ os << ", ";
+ os << ".DeviceType = ";
+ os << *params->pDeviceType;
+ os << ", ";
+ os << ".NumEntries = ";
+ os << *params->pNumEntries;
+ os << ", ";
+ os << ".phDevices = ";
+ os << "{";
+ for (size_t i = 0; i < *params->pNumEntries; i++){
+ if (i > 0) {
+ os << ", ";
+ }
+ printPtr(os, (*params->pphDevices)[i]);
+ }
+ os << "}";
+ os << ", ";
+ os << ".pNumDevices = ";
+ printPtr(os, *params->ppNumDevices);
+ return os;
+}
+
+inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_device_get_info_params_t *params) {
+ os << ".hDevice = ";
+ printPtr(os, *params->phDevice);
+ os << ", ";
+ os << ".propName = ";
+ os << *params->ppropName;
+ os << ", ";
+ os << ".propSize = ";
+ os << *params->ppropSize;
+ os << ", ";
+ os << ".pPropValue = ";
+ printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ os << ", ";
+ os << ".pPropSizeRet = ";
+ printPtr(os, *params->ppPropSizeRet);
+ return os;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// @brief Print pointer value
+template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
+ if (ptr == nullptr) {
+ os << "nullptr";
+ } else if constexpr (std::is_pointer_v<T>) {
+ os << (const void *)(ptr) << " (";
+ printPtr(os, *ptr);
+ os << ")";
+ } else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
+ os << (const void *)ptr;
+ } else if constexpr (std::is_same_v<std::remove_cv_t< T >, char>) {
+ os << (const void *)(ptr) << " (";
+ os << ptr;
+ os << ")";
+ } else {
+ os << (const void *)(ptr) << " (";
+ os << *ptr;
+ os << ")";
+ }
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
\ No newline at end of file
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index 6fdf3025f25bb5..b905144abf19f2 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -169,6 +169,7 @@ typedef struct {1} {{
}
void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
+ OS << GenericHeader;
OS << FileHeader;
// Generate main API definitions
for (auto *R : Records.getAllDerivedDefinitions("APIObject")) {
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 5dbb0e8c22ae04..9f81d9d5582393 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -103,6 +103,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
}
void EmitOffloadEntryPoints(RecordKeeper &Records, raw_ostream &OS) {
+ OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
EmitValidationFunc(FunctionRec{R}, OS);
EmitEntryPointFunc(FunctionRec{R}, OS);
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index ee651957abc703..babb65c20c17c5 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -22,6 +22,7 @@ using namespace offload::tblgen;
// Emit a list of just the API function names
void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
+ OS << GenericHeader;
OS << R"(
#ifndef OFFLOAD_FUNC
#error Please define the macro OFFLOAD_FUNC(Function)
@@ -50,6 +51,7 @@ void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
// Emit declarations for every implementation function
void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
+ OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
FunctionRec F{R};
// The error details function does not set error details itself, so don't
diff --git a/offload/tools/offload-tblgen/GenCommon.hpp b/offload/tools/offload-tblgen/GenCommon.hpp
index 16ffb3a4d667c8..829f9b525fea92 100644
--- a/offload/tools/offload-tblgen/GenCommon.hpp
+++ b/offload/tools/offload-tblgen/GenCommon.hpp
@@ -19,6 +19,16 @@
#define TAB_4 " "
#define TAB_5 " "
+constexpr auto GenericHeader =
+ R"(//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+)";
+
constexpr auto FileHeader = R"(
// Auto-generated file, do not manually edit.
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index 0c47695eca12b6..b89d45388f0bf8 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -133,6 +133,7 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
}
void EmitOffloadPrintHeader(RecordKeeper &Records, raw_ostream &OS) {
+ OS << GenericHeader;
OS << R"""(
// Auto-generated file, do not manually edit.
>From 6d9c1bfda249c3495311e88b8108c02aafa6006d Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 2 Oct 2024 11:46:45 +0100
Subject: [PATCH 07/14] Fix OffloadGenerate target, clang-format generated
files
---
offload/new-api/API/CMakeLists.txt | 26 ++
offload/new-api/CMakeLists.txt | 23 +-
offload/new-api/include/offload_api.h | 249 +++++++++++-------
.../new-api/include/offload_entry_points.inc | 96 ++++---
offload/new-api/include/offload_exports | 16 +-
.../include/offload_impl_func_decls.inc | 29 +-
offload/new-api/include/offload_print.hpp | 127 +++++----
offload/new-api/src/offload_impl.cpp | 2 +-
offload/tools/offload-tblgen/FuncsGen.cpp | 2 +-
9 files changed, 348 insertions(+), 222 deletions(-)
create mode 100644 offload/new-api/API/CMakeLists.txt
diff --git a/offload/new-api/API/CMakeLists.txt b/offload/new-api/API/CMakeLists.txt
new file mode 100644
index 00000000000000..2f12b48133fbcc
--- /dev/null
+++ b/offload/new-api/API/CMakeLists.txt
@@ -0,0 +1,26 @@
+# The OffloadGenerate target is used to regenerate the generated files in the
+# include directory. These files are checked in with the rest of the source,
+# therefore it is only needed when making changes to the API.
+
+find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
+if (CLANG_FORMAT)
+ set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
+
+ tablegen(OFFLOAD offload_api.h -gen-api)
+ tablegen(OFFLOAD offload_funcs.inc -gen-func-names)
+ tablegen(OFFLOAD offload_impl_func_decls.inc -gen-impl-func-decls)
+ tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
+ tablegen(OFFLOAD offload_print.hpp -gen-print-header)
+ tablegen(OFFLOAD offload_exports -gen-exports)
+
+ set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT})
+ add_public_tablegen_target(OffloadGenerate)
+ add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT}
+ -i ${OFFLOAD_GENERATED_FILES})
+ add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
+ -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/../include")
+else()
+ message(WARNING "clang-format was not found, so the OffloadGenerate target\
+ will not be available. Offload will still build, but you will not be\
+ able to make changes to the API.")
+endif()
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
index 9c82eb841bb8b8..5a994dbc7e2cf7 100644
--- a/offload/new-api/CMakeLists.txt
+++ b/offload/new-api/CMakeLists.txt
@@ -1,27 +1,8 @@
-set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/API/OffloadAPI.td)
-list(APPEND LLVM_TABLEGEN_FLAGS -I ${CMAKE_CURRENT_SOURCE_DIR}/API)
-
-tablegen(OFFLOAD offload_api.h -gen-api)
-tablegen(OFFLOAD offload_funcs.inc -gen-func-names)
-tablegen(OFFLOAD offload_impl_func_decls.inc -gen-impl-func-decls)
-tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
-tablegen(OFFLOAD offload_print.hpp -gen-print-header)
-tablegen(OFFLOAD offload_exports -gen-exports)
-
-foreach(itm IN LISTS TABLEGEN_OUTPUT)
- message(${itm})
-endforeach()
-
-set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT})
-add_public_tablegen_target(OffloadGenerate)
-
-add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
- -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/include")
+add_subdirectory(API)
add_llvm_library(offload_new SHARED
src/offload_lib.cpp
- src/offload_impl.cpp
- DEPENDS OffloadGenerate)
+ src/offload_impl.cpp)
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index c046496a2e0f9f..99670c68902aba 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -17,14 +17,13 @@
extern "C" {
#endif
-
///////////////////////////////////////////////////////////////////////////////
#ifndef OFFLOAD_APICALL
#if defined(_WIN32)
/// @brief Calling convention for all API functions
#define OFFLOAD_APICALL __cdecl
#else
-#define OFFLOAD_APICALL
+#define OFFLOAD_APICALL
#endif // defined(_WIN32)
#endif // OFFLOAD_APICALL
@@ -34,7 +33,7 @@ extern "C" {
/// @brief Microsoft-specific dllexport storage-class attribute
#define OFFLOAD_APIEXPORT __declspec(dllexport)
#else
-#define OFFLOAD_APIEXPORT
+#define OFFLOAD_APIEXPORT
#endif // defined(_WIN32)
#endif // OFFLOAD_APIEXPORT
@@ -50,9 +49,9 @@ extern "C" {
#ifndef OFFLOAD_DLLEXPORT
#if __GNUC__ >= 4
/// @brief GCC-specific dllexport storage-class attribute
-#define OFFLOAD_DLLEXPORT __attribute__ ((visibility ("default")))
+#define OFFLOAD_DLLEXPORT __attribute__((visibility("default")))
#else
-#define OFFLOAD_DLLEXPORT
+#define OFFLOAD_DLLEXPORT
#endif // __GNUC__ >= 4
#endif // OFFLOAD_DLLEXPORT
@@ -75,23 +74,35 @@ typedef struct offload_context_handle_t_ *offload_context_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Defines Return/Error codes
typedef enum offload_result_t {
- OFFLOAD_RESULT_SUCCESS = 0, ///< Success
- OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1, ///< Invalid Value
- OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2, ///< Invalid platform
- OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3, ///< Device not found
- OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4, ///< Invalid device
- OFFLOAD_RESULT_ERROR_DEVICE_LOST = 5, ///< Device hung, reset, was removed, or driver update occurred
- OFFLOAD_RESULT_ERROR_UNINITIALIZED = 6, ///< plugin is not initialized or specific entry-point is not implemented
- OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7, ///< Out of resources
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION = 8, ///< [Validation] generic error code for unsupported versions
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE = 9, ///< [Validation] generic error code for unsupported features
- OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT = 10, ///< [Validation] generic error code for invalid arguments
- OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE = 11, ///< [Validation] handle argument is not valid
- OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER = 12, ///< [Validation] pointer argument may not be nullptr
- OFFLOAD_RESULT_ERROR_INVALID_SIZE = 13, ///< [Validation] invalid size or dimensions (e.g., must not be zero, or is out of bounds)
- OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION = 14, ///< [Validation] enumerator argument is not valid
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION = 15, ///< [Validation] enumerator argument is not supported by the device
- OFFLOAD_RESULT_ERROR_UNKNOWN = 16, ///< Unknown or internal error
+ OFFLOAD_RESULT_SUCCESS = 0, ///< Success
+ OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1, ///< Invalid Value
+ OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2, ///< Invalid platform
+ OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3, ///< Device not found
+ OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4, ///< Invalid device
+ OFFLOAD_RESULT_ERROR_DEVICE_LOST =
+ 5, ///< Device hung, reset, was removed, or driver update occurred
+ OFFLOAD_RESULT_ERROR_UNINITIALIZED =
+ 6, ///< plugin is not initialized or specific entry-point is not
+ ///< implemented
+ OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7, ///< Out of resources
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION =
+ 8, ///< [Validation] generic error code for unsupported versions
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE =
+ 9, ///< [Validation] generic error code for unsupported features
+ OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT =
+ 10, ///< [Validation] generic error code for invalid arguments
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE =
+ 11, ///< [Validation] handle argument is not valid
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER =
+ 12, ///< [Validation] pointer argument may not be nullptr
+ OFFLOAD_RESULT_ERROR_INVALID_SIZE =
+ 13, ///< [Validation] invalid size or dimensions (e.g., must not be zero,
+ ///< or is out of bounds)
+ OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION =
+ 14, ///< [Validation] enumerator argument is not valid
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION =
+ 15, ///< [Validation] enumerator argument is not supported by the device
+ OFFLOAD_RESULT_ERROR_UNKNOWN = 16, ///< Unknown or internal error
/// @cond
OFFLOAD_RESULT_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -99,12 +110,18 @@ typedef enum offload_result_t {
} offload_result_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Get a detailed error message for the last error that occurred on this thread, if it exists
+/// @brief Get a detailed error message for the last error that occurred on this
+/// thread, if it exists
///
/// @details
-/// - When an Offload API call returns a return value other than OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error message.
-/// - If a further Offload call (excluding this function) is made on the same thread without checking its detailed error message with this function, that message should be considered lost.
-/// - The returned char* is only valid until the next Offload function call on the same thread (excluding further calls to this function.)
+/// - When an Offload API call returns a return value other than
+/// OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error
+/// message.
+/// - If a further Offload call (excluding this function) is made on the same
+/// thread without checking its detailed error message with this function,
+/// that message should be considered lost.
+/// - The returned char* is only valid until the next Offload function call
+/// on the same thread (excluding further calls to this function.)
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
@@ -113,16 +130,19 @@ typedef enum offload_result_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
- size_t* SizeRet, ///< [out][optional] Pointer to return the size of the available error message. A size of 0 indicates no message.
- const char** DetailStringRet ///< [out][optional] Pointer to return the error message string.
+ size_t *
+ SizeRet, ///< [out][optional] Pointer to return the size of the
+ ///< available error message. A size of 0 indicates no message.
+ const char **DetailStringRet ///< [out][optional] Pointer to return the
+ ///< error message string.
);
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
///
/// @details
-/// - Multiple calls to this function will return identical platforms handles, in the same order.
+/// - Multiple calls to this function will return identical platforms
+/// handles, in the same order.
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
@@ -133,19 +153,35 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- uint32_t NumEntries, ///< [in] The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, thenNumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
- offload_platform_handle_t* phPlatforms, ///< [out][optional] Array of handle of platforms. If NumEntries isless than the number of platforms available, then offloadPlatformGetshall only retrieve that number of platforms.
- uint32_t* pNumPlatforms ///< [out][optional] returns the total number of platforms available.
+ uint32_t
+ NumEntries, ///< [in] The number of platforms to be added to
+ ///< phPlatforms. If phPlatforms is not NULL, thenNumEntries
+ ///< should be greater than zero, otherwise
+ ///< OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
+ offload_platform_handle_t
+ *phPlatforms, ///< [out][optional] Array of handle of platforms. If
+ ///< NumEntries isless than the number of platforms
+ ///< available, then offloadPlatformGetshall only retrieve
+ ///< that number of platforms.
+ uint32_t *pNumPlatforms ///< [out][optional] returns the total number of
+ ///< platforms available.
);
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported platform info
typedef enum offload_platform_info_t {
- OFFLOAD_PLATFORM_INFO_NAME = 0, ///< The string denoting name of the platform. The size of the info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_VENDOR_NAME = 1, ///< The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_VERSION = 2, ///< The string denoting the version of the platform. The size of the info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_BACKEND = 3, ///< The backend of the platform. Identifies the native backend adapter implementing this platform.
+ OFFLOAD_PLATFORM_INFO_NAME =
+ 0, ///< The string denoting name of the platform. The size of the info
+ ///< needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VENDOR_NAME =
+ 1, ///< The string denoting name of the vendor of the platform. The size
+ ///< of the info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VERSION =
+ 2, ///< The string denoting the version of the platform. The size of the
+ ///< info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_BACKEND =
+ 3, ///< The backend of the platform. Identifies the native backend adapter
+ ///< implementing this platform.
/// @cond
OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -155,9 +191,9 @@ typedef enum offload_platform_info_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Identifies the native backend of the platform
typedef enum offload_platform_backend_t {
- OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0, ///< The backend is not recognized
- OFFLOAD_PLATFORM_BACKEND_CUDA = 1, ///< The backend is CUDA
- OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2, ///< The backend is AMDGPU
+ OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0, ///< The backend is not recognized
+ OFFLOAD_PLATFORM_BACKEND_CUDA = 1, ///< The backend is CUDA
+ OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2, ///< The backend is AMDGPU
/// @cond
OFFLOAD_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -179,7 +215,8 @@ typedef enum offload_platform_backend_t {
/// + If `propName` is not supported by the platform.
/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
-/// + If `propSize` is less than the real number of bytes needed to return the info.
+/// + If `propSize` is less than the real number of bytes needed to
+/// return the info.
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
@@ -189,21 +226,26 @@ typedef enum offload_platform_backend_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
- offload_platform_handle_t hPlatform, ///< [in] handle of the platform
- offload_platform_info_t propName, ///< [in] type of the info to retrieve
- size_t propSize, ///< [in] the number of bytes pointed to by pPlatformInfo.
- void* pPropValue, ///< [out][optional] array of bytes holding the info.If Size is not equal to or greater to the real number of bytes needed to return the infothen the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.
- size_t* pPropSizeRet ///< [out][optional] pointer to the actual number of bytes being queried by pPlatformInfo.
+ offload_platform_handle_t hPlatform, ///< [in] handle of the platform
+ offload_platform_info_t propName, ///< [in] type of the info to retrieve
+ size_t propSize, ///< [in] the number of bytes pointed to by pPlatformInfo.
+ void *pPropValue, ///< [out][optional] array of bytes holding the info.If
+ ///< Size is not equal to or greater to the real number of
+ ///< bytes needed to return the infothen the
+ ///< OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned
+ ///< and pPlatformInfo is not used.
+ size_t *pPropSizeRet ///< [out][optional] pointer to the actual number of
+ ///< bytes being queried by pPlatformInfo.
);
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device types
typedef enum offload_device_type_t {
- OFFLOAD_DEVICE_TYPE_DEFAULT = 0, ///< The default device type as preferred by the runtime
- OFFLOAD_DEVICE_TYPE_ALL = 1, ///< Devices of all types
- OFFLOAD_DEVICE_TYPE_GPU = 2, ///< GPU device type
- OFFLOAD_DEVICE_TYPE_CPU = 3, ///< CPU device type
+ OFFLOAD_DEVICE_TYPE_DEFAULT =
+ 0, ///< The default device type as preferred by the runtime
+ OFFLOAD_DEVICE_TYPE_ALL = 1, ///< Devices of all types
+ OFFLOAD_DEVICE_TYPE_GPU = 2, ///< GPU device type
+ OFFLOAD_DEVICE_TYPE_CPU = 3, ///< CPU device type
/// @cond
OFFLOAD_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -213,11 +255,11 @@ typedef enum offload_device_type_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device info
typedef enum offload_device_info_t {
- OFFLOAD_DEVICE_INFO_TYPE = 0, ///< type of the device
- OFFLOAD_DEVICE_INFO_PLATFORM = 1, ///< the platform associated with the device
- OFFLOAD_DEVICE_INFO_NAME = 2, ///< Device name
- OFFLOAD_DEVICE_INFO_VENDOR = 3, ///< Device vendor
- OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4, ///< Driver version
+ OFFLOAD_DEVICE_INFO_TYPE = 0, ///< type of the device
+ OFFLOAD_DEVICE_INFO_PLATFORM = 1, ///< the platform associated with the device
+ OFFLOAD_DEVICE_INFO_NAME = 2, ///< Device name
+ OFFLOAD_DEVICE_INFO_VENDOR = 3, ///< Device vendor
+ OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4, ///< Driver version
/// @cond
OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -228,10 +270,15 @@ typedef enum offload_device_info_t {
/// @brief Retrieves devices within a platform
///
/// @details
-/// - Multiple calls to this function will return identical device handles, in the same order.
-/// - The number and order of handles returned from this function can be affected by environment variables that filter devices exposed through API.
-/// - The returned devices are taken a reference of and must be released with a subsequent call to olDeviceRelease.
-/// - The application may call this function from simultaneous threads, the implementation must be thread-safe
+/// - Multiple calls to this function will return identical device handles,
+/// in the same order.
+/// - The number and order of handles returned from this function can be
+/// affected by environment variables that filter devices exposed through
+/// API.
+/// - The returned devices are taken a reference of and must be released with
+/// a subsequent call to olDeviceRelease.
+/// - The application may call this function from simultaneous threads, the
+/// implementation must be thread-safe
///
/// @returns
/// - ::OFFLOAD_RESULT_SUCCESS
@@ -245,14 +292,22 @@ typedef enum offload_device_info_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
- offload_platform_handle_t hPlatform, ///< [in] handle of the platform instance
- offload_device_type_t DeviceType, ///< [in] the type of the devices.
- uint32_t NumEntries, ///< [in] the number of devices to be added to phDevices.If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
- offload_device_handle_t* phDevices, ///< [out][optional] array of handle of devices.If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.
- uint32_t* pNumDevices ///< [out][optional] pointer to the number of devices.pNumDevices will be updated with the total number of devices available.
+ offload_platform_handle_t
+ hPlatform, ///< [in] handle of the platform instance
+ offload_device_type_t DeviceType, ///< [in] the type of the devices.
+ uint32_t NumEntries, ///< [in] the number of devices to be added to
+ ///< phDevices.If phDevices is not NULL, then
+ ///< NumEntries should be greater than zero. Otherwise
+ ///< OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
+ offload_device_handle_t *
+ phDevices, ///< [out][optional] array of handle of devices.If NumEntries
+ ///< is less than the number of devices available, then
+ ///< platform shall only retrieve that number of devices.
+ uint32_t *pNumDevices ///< [out][optional] pointer to the number of
+ ///< devices.pNumDevices will be updated with the
+ ///< total number of devices available.
);
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves various information about device
///
@@ -268,7 +323,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// + If `propName` is not supported by the adapter.
/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
-/// + If `propSize` is less than the real number of bytes needed to return the info.
+/// + If `propSize` is less than the real number of bytes needed to
+/// return the info.
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
@@ -278,65 +334,68 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hDevice`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
- offload_device_handle_t hDevice, ///< [in] handle of the device instance
- offload_device_info_t propName, ///< [in] type of the info to retrieve
- size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
- void* pPropValue, ///< [out][optional] array of bytes holding the info. If propSize is not equal to or greater than the real number of bytes needed to return the info then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPropValue is not used.
- size_t* pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName.
+ offload_device_handle_t hDevice, ///< [in] handle of the device instance
+ offload_device_info_t propName, ///< [in] type of the info to retrieve
+ size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
+ void *pPropValue, ///< [out][optional] array of bytes holding the info. If
+ ///< propSize is not equal to or greater than the real
+ ///< number of bytes needed to return the info then the
+ ///< OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned
+ ///< and pPropValue is not used.
+ size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in
+ ///< bytes of the queried propName.
);
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadGetErrorDetails
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_get_error_details_params_t {
- size_t** pSizeRet;
- const char*** pDetailStringRet;
+ size_t **pSizeRet;
+ const char ***pDetailStringRet;
} offload_get_error_details_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGet
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_params_t {
- uint32_t* pNumEntries;
- offload_platform_handle_t** pphPlatforms;
- uint32_t** ppNumPlatforms;
+ uint32_t *pNumEntries;
+ offload_platform_handle_t **pphPlatforms;
+ uint32_t **ppNumPlatforms;
} offload_platform_get_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGetInfo
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_info_params_t {
- offload_platform_handle_t* phPlatform;
- offload_platform_info_t* ppropName;
- size_t* ppropSize;
- void** ppPropValue;
- size_t** ppPropSizeRet;
+ offload_platform_handle_t *phPlatform;
+ offload_platform_info_t *ppropName;
+ size_t *ppropSize;
+ void **ppPropValue;
+ size_t **ppPropSizeRet;
} offload_platform_get_info_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGet
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_params_t {
- offload_platform_handle_t* phPlatform;
- offload_device_type_t* pDeviceType;
- uint32_t* pNumEntries;
- offload_device_handle_t** pphDevices;
- uint32_t** ppNumDevices;
+ offload_platform_handle_t *phPlatform;
+ offload_device_type_t *pDeviceType;
+ uint32_t *pNumEntries;
+ offload_device_handle_t **pphDevices;
+ uint32_t **ppNumDevices;
} offload_device_get_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGetInfo
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_info_params_t {
- offload_device_handle_t* phDevice;
- offload_device_info_t* ppropName;
- size_t* ppropSize;
- void** ppPropValue;
- size_t** ppPropSizeRet;
+ offload_device_handle_t *phDevice;
+ offload_device_info_t *ppropName;
+ size_t *ppropSize;
+ void **ppPropValue;
+ size_t **ppPropSizeRet;
} offload_device_get_info_params_t;
#if defined(__cplusplus)
} // extern "C"
#endif
-
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index ce7b784f341a09..2910bc414071fc 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -7,24 +7,24 @@
//===----------------------------------------------------------------------===//
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadGetErrorDetails_val(
- size_t* SizeRet, const char** DetailStringRet) {
+offload_result_t offloadGetErrorDetails_val(size_t *SizeRet,
+ const char **DetailStringRet) {
if (true /*enableParameterValidation*/) {
}
return offloadGetErrorDetails_impl(SizeRet, DetailStringRet);
-
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
- size_t* SizeRet, const char** DetailStringRet) {
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadGetErrorDetails(size_t *SizeRet, const char **DetailStringRet) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadGetErrorDetails";
}
- offload_result_t result = offloadGetErrorDetails_val(SizeRet, DetailStringRet);
+ offload_result_t result =
+ offloadGetErrorDetails_val(SizeRet, DetailStringRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_get_error_details_params_t Params = { &SizeRet, &DetailStringRet};
+ offload_get_error_details_params_t Params = {&SizeRet, &DetailStringRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
@@ -35,28 +35,30 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadPlatformGet_val(
- uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms) {
+offload_result_t offloadPlatformGet_val(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0 && phPlatforms != NULL) {
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
}
-
}
return offloadPlatformGet_impl(NumEntries, phPlatforms, pNumPlatforms);
-
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms) {
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGet";
}
- offload_result_t result = offloadPlatformGet_val(NumEntries, phPlatforms, pNumPlatforms);
+ offload_result_t result =
+ offloadPlatformGet_val(NumEntries, phPlatforms, pNumPlatforms);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_params_t Params = { &NumEntries, &phPlatforms, &pNumPlatforms};
+ offload_platform_get_params_t Params = {&NumEntries, &phPlatforms,
+ &pNumPlatforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
@@ -67,8 +69,10 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadPlatformGetInfo_val(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+offload_result_t offloadPlatformGetInfo_val(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t propSize, void *pPropValue,
+ size_t *pPropSizeRet) {
if (true /*enableParameterValidation*/) {
if (propSize == 0 && pPropValue != NULL) {
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
@@ -85,22 +89,24 @@ offload_result_t offloadPlatformGetInfo_val(
if (NULL == hPlatform) {
return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
}
-
}
- return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue, pPropSizeRet);
-
+ return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue,
+ pPropSizeRet);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName,
+ size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGetInfo";
}
- offload_result_t result = offloadPlatformGetInfo_val(hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+ offload_result_t result = offloadPlatformGetInfo_val(
+ hPlatform, propName, propSize, pPropValue, pPropSizeRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_info_params_t Params = { &hPlatform, &propName, &propSize, &pPropValue, &pPropSizeRet};
+ offload_platform_get_info_params_t Params = {
+ &hPlatform, &propName, &propSize, &pPropValue, &pPropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
@@ -111,8 +117,11 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadDeviceGet_val(
- offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices) {
+offload_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
+ offload_device_type_t DeviceType,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0 && phDevices != NULL) {
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
@@ -125,22 +134,25 @@ offload_result_t offloadDeviceGet_val(
if (NULL == hPlatform) {
return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
}
-
}
- return offloadDeviceGet_impl(hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
-
+ return offloadDeviceGet_impl(hPlatform, DeviceType, NumEntries, phDevices,
+ pNumDevices);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
- offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices) {
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadDeviceGet(offload_platform_handle_t hPlatform,
+ offload_device_type_t DeviceType, uint32_t NumEntries,
+ offload_device_handle_t *phDevices, uint32_t *pNumDevices) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGet";
}
- offload_result_t result = offloadDeviceGet_val(hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
+ offload_result_t result = offloadDeviceGet_val(
+ hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_params_t Params = { &hPlatform, &DeviceType, &NumEntries, &phDevices, &pNumDevices};
+ offload_device_get_params_t Params = {&hPlatform, &DeviceType, &NumEntries,
+ &phDevices, &pNumDevices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
@@ -151,8 +163,10 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadDeviceGetInfo_val(
- offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+offload_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize, void *pPropValue,
+ size_t *pPropSizeRet) {
if (true /*enableParameterValidation*/) {
if (propSize == 0 && pPropValue != NULL) {
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
@@ -169,22 +183,24 @@ offload_result_t offloadDeviceGetInfo_val(
if (NULL == hDevice) {
return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
}
-
}
- return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue, pPropSizeRet);
-
+ return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue,
+ pPropSizeRet);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
- offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet) {
+ offload_device_handle_t hDevice, offload_device_info_t propName,
+ size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGetInfo";
}
- offload_result_t result = offloadDeviceGetInfo_val(hDevice, propName, propSize, pPropValue, pPropSizeRet);
+ offload_result_t result = offloadDeviceGetInfo_val(
+ hDevice, propName, propSize, pPropValue, pPropSizeRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_info_params_t Params = { &hDevice, &propName, &propSize, &pPropValue, &pPropSizeRet};
+ offload_device_get_info_params_t Params = {&hDevice, &propName, &propSize,
+ &pPropValue, &pPropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
index ec44d7cc0c2132..fb8103ae5e80ef 100644
--- a/offload/new-api/include/offload_exports
+++ b/offload/new-api/include/offload_exports
@@ -1,10 +1,10 @@
VERS1.0 {
- global:
- offloadGetErrorDetails;
- offloadPlatformGet;
- offloadPlatformGetInfo;
- offloadDeviceGet;
- offloadDeviceGetInfo;
- local:
- *;
+global:
+ offloadGetErrorDetails;
+ offloadPlatformGet;
+ offloadPlatformGetInfo;
+ offloadDeviceGet;
+ offloadDeviceGetInfo;
+local:
+ *;
};
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
index 1405a3e38c7c8c..df40c342049549 100644
--- a/offload/new-api/include/offload_impl_func_decls.inc
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -5,8 +5,27 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-offload_result_t offloadGetErrorDetails_impl(size_t* SizeRet, const char** DetailStringRet);
-offload_impl_result_t offloadPlatformGet_impl(uint32_t NumEntries, offload_platform_handle_t* phPlatforms, uint32_t* pNumPlatforms);
-offload_impl_result_t offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform, offload_platform_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet);
-offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform, offload_device_type_t DeviceType, uint32_t NumEntries, offload_device_handle_t* phDevices, uint32_t* pNumDevices);
-offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice, offload_device_info_t propName, size_t propSize, void* pPropValue, size_t* pPropSizeRet);
+offload_result_t offloadGetErrorDetails_impl(size_t *SizeRet,
+ const char **DetailStringRet);
+
+offload_impl_result_t
+offloadPlatformGet_impl(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms);
+
+offload_impl_result_t
+offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet);
+
+offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
+ offload_device_type_t DeviceType,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices);
+
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize,
+ void *pPropValue,
+ size_t *pPropSizeRet);
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
index 8b14d222a7245c..4a0f6d14f10b4e 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -13,9 +13,11 @@
#include <offload_api.h>
#include <ostream>
-
-template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr);
-template <typename T> inline void printTagged(std::ostream &os, const void *ptr, T value, size_t size);
+template <typename T>
+inline offload_result_t printPtr(std::ostream &os, const T *ptr);
+template <typename T>
+inline void printTagged(std::ostream &os, const void *ptr, T value,
+ size_t size);
template <typename T> struct is_handle : std::false_type {};
template <> struct is_handle<offload_platform_handle_t> : std::true_type {};
template <> struct is_handle<offload_device_handle_t> : std::true_type {};
@@ -23,10 +25,14 @@ template <> struct is_handle<offload_context_handle_t> : std::true_type {};
template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value);
-inline std::ostream &operator<<(std::ostream &os, enum offload_platform_info_t value);
-inline std::ostream &operator<<(std::ostream &os, enum offload_platform_backend_t value);
-inline std::ostream &operator<<(std::ostream &os, enum offload_device_type_t value);
-inline std::ostream &operator<<(std::ostream &os, enum offload_device_info_t value);
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_platform_info_t value);
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_platform_backend_t value);
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_device_type_t value);
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_device_info_t value);
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the offload_result_t type
@@ -94,7 +100,8 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value) {
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the offload_platform_info_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_platform_info_t value) {
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_platform_info_t value) {
switch (value) {
case OFFLOAD_PLATFORM_INFO_NAME:
os << "OFFLOAD_PLATFORM_INFO_NAME";
@@ -119,7 +126,8 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_platform_info_t v
/// @brief Print type-tagged offload_platform_info_t enum value
/// @returns std::ostream &
template <>
-inline void printTagged(std::ostream &os, const void *ptr, offload_platform_info_t value, size_t size) {
+inline void printTagged(std::ostream &os, const void *ptr,
+ offload_platform_info_t value, size_t size) {
if (ptr == NULL) {
printPtr(os, ptr);
return;
@@ -127,19 +135,20 @@ inline void printTagged(std::ostream &os, const void *ptr, offload_platform_info
switch (value) {
case OFFLOAD_PLATFORM_INFO_NAME: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
case OFFLOAD_PLATFORM_INFO_VENDOR_NAME: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
case OFFLOAD_PLATFORM_INFO_VERSION: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
case OFFLOAD_PLATFORM_INFO_BACKEND: {
- const offload_platform_backend_t * const tptr = (const offload_platform_backend_t * const)ptr;
+ const offload_platform_backend_t *const tptr =
+ (const offload_platform_backend_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
@@ -153,7 +162,8 @@ inline void printTagged(std::ostream &os, const void *ptr, offload_platform_info
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the offload_platform_backend_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_platform_backend_t value) {
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_platform_backend_t value) {
switch (value) {
case OFFLOAD_PLATFORM_BACKEND_UNKNOWN:
os << "OFFLOAD_PLATFORM_BACKEND_UNKNOWN";
@@ -174,7 +184,8 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_platform_backend_
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the offload_device_type_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_device_type_t value) {
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_device_type_t value) {
switch (value) {
case OFFLOAD_DEVICE_TYPE_DEFAULT:
os << "OFFLOAD_DEVICE_TYPE_DEFAULT";
@@ -198,7 +209,8 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_device_type_t val
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the offload_device_info_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_device_info_t value) {
+inline std::ostream &operator<<(std::ostream &os,
+ enum offload_device_info_t value) {
switch (value) {
case OFFLOAD_DEVICE_INFO_TYPE:
os << "OFFLOAD_DEVICE_INFO_TYPE";
@@ -226,7 +238,8 @@ inline std::ostream &operator<<(std::ostream &os, enum offload_device_info_t val
/// @brief Print type-tagged offload_device_info_t enum value
/// @returns std::ostream &
template <>
-inline void printTagged(std::ostream &os, const void *ptr, offload_device_info_t value, size_t size) {
+inline void printTagged(std::ostream &os, const void *ptr,
+ offload_device_info_t value, size_t size) {
if (ptr == NULL) {
printPtr(os, ptr);
return;
@@ -234,29 +247,31 @@ inline void printTagged(std::ostream &os, const void *ptr, offload_device_info_t
switch (value) {
case OFFLOAD_DEVICE_INFO_TYPE: {
- const offload_device_type_t * const tptr = (const offload_device_type_t * const)ptr;
+ const offload_device_type_t *const tptr =
+ (const offload_device_type_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
case OFFLOAD_DEVICE_INFO_PLATFORM: {
- const offload_platform_handle_t * const tptr = (const offload_platform_handle_t * const)ptr;
+ const offload_platform_handle_t *const tptr =
+ (const offload_platform_handle_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
case OFFLOAD_DEVICE_INFO_NAME: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
case OFFLOAD_DEVICE_INFO_VENDOR: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
case OFFLOAD_DEVICE_INFO_DRIVER_VERSION: {
- printPtr(os, (const char*) ptr);
+ printPtr(os, (const char *)ptr);
break;
}
default:
@@ -265,7 +280,9 @@ inline void printTagged(std::ostream &os, const void *ptr, offload_device_info_t
}
}
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_get_error_details_params_t *params) {
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_get_error_details_params_t *params) {
os << ".SizeRet = ";
printPtr(os, *params->pSizeRet);
os << ", ";
@@ -274,15 +291,17 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
return os;
}
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_platform_get_params_t *params) {
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_platform_get_params_t *params) {
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
os << ".phPlatforms = ";
os << "{";
- for (size_t i = 0; i < *params->pNumEntries; i++){
+ for (size_t i = 0; i < *params->pNumEntries; i++) {
if (i > 0) {
- os << ", ";
+ os << ", ";
}
printPtr(os, (*params->pphPlatforms)[i]);
}
@@ -293,7 +312,9 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
return os;
}
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_platform_get_info_params_t *params) {
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_platform_get_info_params_t *params) {
os << ".hPlatform = ";
printPtr(os, *params->phPlatform);
os << ", ";
@@ -311,7 +332,9 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
return os;
}
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_device_get_params_t *params) {
+inline std::ostream &
+operator<<(std::ostream &os,
+ [[maybe_unused]] const struct offload_device_get_params_t *params) {
os << ".hPlatform = ";
printPtr(os, *params->phPlatform);
os << ", ";
@@ -323,9 +346,9 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
os << ", ";
os << ".phDevices = ";
os << "{";
- for (size_t i = 0; i < *params->pNumEntries; i++){
+ for (size_t i = 0; i < *params->pNumEntries; i++) {
if (i > 0) {
- os << ", ";
+ os << ", ";
}
printPtr(os, (*params->pphDevices)[i]);
}
@@ -336,7 +359,9 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
return os;
}
-inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct offload_device_get_info_params_t *params) {
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_device_get_info_params_t *params) {
os << ".hDevice = ";
printPtr(os, *params->phDevice);
os << ", ";
@@ -356,25 +381,25 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
///////////////////////////////////////////////////////////////////////////////
// @brief Print pointer value
-template <typename T> inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
- if (ptr == nullptr) {
- os << "nullptr";
- } else if constexpr (std::is_pointer_v<T>) {
- os << (const void *)(ptr) << " (";
- printPtr(os, *ptr);
- os << ")";
- } else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
- os << (const void *)ptr;
- } else if constexpr (std::is_same_v<std::remove_cv_t< T >, char>) {
- os << (const void *)(ptr) << " (";
- os << ptr;
- os << ")";
- } else {
- os << (const void *)(ptr) << " (";
- os << *ptr;
- os << ")";
- }
+template <typename T>
+inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
+ if (ptr == nullptr) {
+ os << "nullptr";
+ } else if constexpr (std::is_pointer_v<T>) {
+ os << (const void *)(ptr) << " (";
+ printPtr(os, *ptr);
+ os << ")";
+ } else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
+ os << (const void *)ptr;
+ } else if constexpr (std::is_same_v<std::remove_cv_t<T>, char>) {
+ os << (const void *)(ptr) << " (";
+ os << ptr;
+ os << ")";
+ } else {
+ os << (const void *)(ptr) << " (";
+ os << *ptr;
+ os << ")";
+ }
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
-
\ No newline at end of file
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index b544a847a8dbd2..43112bba448045 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -11,9 +11,9 @@
//
//===----------------------------------------------------------------------===//
+#include "offload_impl.hpp"
#include "PluginManager.h"
#include "helpers.hpp"
-#include "offload_impl.hpp"
#include "llvm/Support/FormatVariadic.h"
#include <offload_api.h>
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index babb65c20c17c5..033ed8db3240ad 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -70,6 +70,6 @@ void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
OS << ");";
}
}
- OS << "\n";
+ OS << "\n\n";
}
}
>From dd266549e7ea66b553c51c12bd1ee21b91fe2e4f Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 2 Oct 2024 16:15:53 +0100
Subject: [PATCH 08/14] Fix offload header install location
---
offload/new-api/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/offload/new-api/CMakeLists.txt b/offload/new-api/CMakeLists.txt
index 5a994dbc7e2cf7..a79b88303bb4d7 100644
--- a/offload/new-api/CMakeLists.txt
+++ b/offload/new-api/CMakeLists.txt
@@ -27,4 +27,4 @@ set_target_properties(offload_new PROPERTIES
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
install(TARGETS offload_new LIBRARY COMPONENT offload_new DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/offload_api.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
>From 585a239a1222851a4d97c58733ed643d9edb3cbd Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 2 Oct 2024 17:19:52 +0100
Subject: [PATCH 09/14] Tidy generated comments etc
---
offload/new-api/API/Common.td | 22 +-
offload/new-api/API/Device.td | 8 +-
offload/new-api/API/Platform.td | 14 +-
offload/new-api/include/offload_api.h | 242 +++++++++++----------
offload/tools/offload-tblgen/APIGen.cpp | 14 +-
offload/tools/offload-tblgen/GenCommon.hpp | 2 +-
6 files changed, 155 insertions(+), 147 deletions(-)
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index 55d03d4ff1e783..8de5475af99371 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -29,12 +29,6 @@ def : Macro {
let alt_value = "";
}
-def : Typedef {
- let name = "offload_bool_t";
- let value = "uint8_t";
- let desc = "compiler-independent type";
-}
-
def : Handle {
let name = "offload_platform_handle_t";
let desc = "Handle of a platform instance";
@@ -62,14 +56,14 @@ def : Enum {
Etor<"ERROR_DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
Etor<"ERROR_UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
Etor<"ERROR_OUT_OF_RESOURCES", "Out of resources">,
- Etor<"ERROR_UNSUPPORTED_VERSION", "[Validation] generic error code for unsupported versions">,
- Etor<"ERROR_UNSUPPORTED_FEATURE", "[Validation] generic error code for unsupported features">,
- Etor<"ERROR_INVALID_ARGUMENT", "[Validation] generic error code for invalid arguments">,
- Etor<"ERROR_INVALID_NULL_HANDLE", "[Validation] handle argument is not valid">,
- Etor<"ERROR_INVALID_NULL_POINTER", "[Validation] pointer argument may not be nullptr">,
- Etor<"ERROR_INVALID_SIZE", "[Validation] invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
- Etor<"ERROR_INVALID_ENUMERATION", "[Validation] enumerator argument is not valid">,
- Etor<"ERROR_UNSUPPORTED_ENUMERATION", "[Validation] enumerator argument is not supported by the device">,
+ Etor<"ERROR_UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
+ Etor<"ERROR_UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
+ Etor<"ERROR_INVALID_ARGUMENT", "generic error code for invalid arguments">,
+ Etor<"ERROR_INVALID_NULL_HANDLE", "handle argument is not valid">,
+ Etor<"ERROR_INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
+ Etor<"ERROR_INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
+ Etor<"ERROR_INVALID_ENUMERATION", "enumerator argument is not valid">,
+ Etor<"ERROR_UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
Etor<"ERROR_UNKNOWN", "Unknown or internal error">
];
}
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index 2a330d7ef7c4cb..837d7071853f5c 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -46,13 +46,13 @@ def : Function {
let params = [
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
- Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices."
- "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE"
+ Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices. "
+ "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
"will be returned.", PARAM_IN>,
- RangedParam<"offload_device_handle_t*", "phDevices", "array of handle of devices."
+ RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
"If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
Range<"0", "NumEntries">>,
- Param<"uint32_t*", "pNumDevices", "pointer to the number of devices."
+ Param<"uint32_t*", "pNumDevices", "pointer to the number of devices. "
"pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
];
let returns = [
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index 71af04bb831998..d280da1156c798 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -17,13 +17,13 @@ def : Function {
];
let params = [
Param<"uint32_t", "NumEntries",
- "The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then"
- "NumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE"
+ "The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then "
+ "NumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
"will be returned.", PARAM_IN>,
RangedParam<"offload_platform_handle_t*", "phPlatforms",
- "Array of handle of platforms. If NumEntries is"
- "less than the number of platforms available, then offloadPlatformGet"
- "shall only retrieve that number of platforms.",
+ "Array of handle of platforms. If NumEntries is less than the number of "
+ "platforms available, then offloadPlatformGet shall only retrieve that "
+ "number of platforms.",
PARAM_OUT_OPTIONAL, Range<"0", "NumEntries">>,
Param<"uint32_t*",
"pNumPlatforms", "returns the total number of platforms available.",
@@ -69,8 +69,8 @@ def : Function {
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
Param<"offload_platform_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
- TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info."
- "If Size is not equal to or greater to the real number of bytes needed to return the info"
+ TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
+ "If Size is not equal to or greater to the real number of bytes needed to return the info "
"then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
TypeInfo<"propName" , "propSize">>,
Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 99670c68902aba..8e70efa27774d1 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -55,10 +55,6 @@ extern "C" {
#endif // __GNUC__ >= 4
#endif // OFFLOAD_DLLEXPORT
-///////////////////////////////////////////////////////////////////////////////
-/// @brief compiler-independent type
-typedef uint8_t offload_bool_t;
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Handle of a platform instance
typedef struct offload_platform_handle_t_ *offload_platform_handle_t;
@@ -74,35 +70,40 @@ typedef struct offload_context_handle_t_ *offload_context_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Defines Return/Error codes
typedef enum offload_result_t {
- OFFLOAD_RESULT_SUCCESS = 0, ///< Success
- OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1, ///< Invalid Value
- OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2, ///< Invalid platform
- OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3, ///< Device not found
- OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4, ///< Invalid device
- OFFLOAD_RESULT_ERROR_DEVICE_LOST =
- 5, ///< Device hung, reset, was removed, or driver update occurred
- OFFLOAD_RESULT_ERROR_UNINITIALIZED =
- 6, ///< plugin is not initialized or specific entry-point is not
- ///< implemented
- OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7, ///< Out of resources
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION =
- 8, ///< [Validation] generic error code for unsupported versions
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE =
- 9, ///< [Validation] generic error code for unsupported features
- OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT =
- 10, ///< [Validation] generic error code for invalid arguments
- OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE =
- 11, ///< [Validation] handle argument is not valid
- OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER =
- 12, ///< [Validation] pointer argument may not be nullptr
- OFFLOAD_RESULT_ERROR_INVALID_SIZE =
- 13, ///< [Validation] invalid size or dimensions (e.g., must not be zero,
- ///< or is out of bounds)
- OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION =
- 14, ///< [Validation] enumerator argument is not valid
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION =
- 15, ///< [Validation] enumerator argument is not supported by the device
- OFFLOAD_RESULT_ERROR_UNKNOWN = 16, ///< Unknown or internal error
+ /// Success
+ OFFLOAD_RESULT_SUCCESS = 0,
+ /// Invalid Value
+ OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1,
+ /// Invalid platform
+ OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2,
+ /// Device not found
+ OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3,
+ /// Invalid device
+ OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4,
+ /// Device hung, reset, was removed, or driver update occurred
+ OFFLOAD_RESULT_ERROR_DEVICE_LOST = 5,
+ /// plugin is not initialized or specific entry-point is not implemented
+ OFFLOAD_RESULT_ERROR_UNINITIALIZED = 6,
+ /// Out of resources
+ OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7,
+ /// generic error code for unsupported versions
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION = 8,
+ /// generic error code for unsupported features
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE = 9,
+ /// generic error code for invalid arguments
+ OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT = 10,
+ /// handle argument is not valid
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE = 11,
+ /// pointer argument may not be nullptr
+ OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER = 12,
+ /// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
+ OFFLOAD_RESULT_ERROR_INVALID_SIZE = 13,
+ /// enumerator argument is not valid
+ OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION = 14,
+ /// enumerator argument is not supported by the device
+ OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION = 15,
+ /// Unknown or internal error
+ OFFLOAD_RESULT_ERROR_UNKNOWN = 16,
/// @cond
OFFLOAD_RESULT_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -130,12 +131,11 @@ typedef enum offload_result_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
- size_t *
- SizeRet, ///< [out][optional] Pointer to return the size of the
- ///< available error message. A size of 0 indicates no message.
- const char **DetailStringRet ///< [out][optional] Pointer to return the
- ///< error message string.
-);
+ // [out][optional] Pointer to return the size of the available error
+ // message. A size of 0 indicates no message.
+ size_t *SizeRet,
+ // [out][optional] Pointer to return the error message string.
+ const char **DetailStringRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
@@ -153,35 +153,32 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- uint32_t
- NumEntries, ///< [in] The number of platforms to be added to
- ///< phPlatforms. If phPlatforms is not NULL, thenNumEntries
- ///< should be greater than zero, otherwise
- ///< OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
- offload_platform_handle_t
- *phPlatforms, ///< [out][optional] Array of handle of platforms. If
- ///< NumEntries isless than the number of platforms
- ///< available, then offloadPlatformGetshall only retrieve
- ///< that number of platforms.
- uint32_t *pNumPlatforms ///< [out][optional] returns the total number of
- ///< platforms available.
-);
+ // [in] The number of platforms to be added to phPlatforms. If phPlatforms
+ // is not NULL, then NumEntries should be greater than zero, otherwise
+ // OFFLOAD_RESULT_ERROR_INVALID_SIZE will be returned.
+ uint32_t NumEntries,
+ // [out][optional] Array of handle of platforms. If NumEntries is less than
+ // the number of platforms available, then offloadPlatformGet shall only
+ // retrieve that number of platforms.
+ offload_platform_handle_t *phPlatforms,
+ // [out][optional] returns the total number of platforms available.
+ uint32_t *pNumPlatforms);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported platform info
typedef enum offload_platform_info_t {
- OFFLOAD_PLATFORM_INFO_NAME =
- 0, ///< The string denoting name of the platform. The size of the info
- ///< needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_VENDOR_NAME =
- 1, ///< The string denoting name of the vendor of the platform. The size
- ///< of the info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_VERSION =
- 2, ///< The string denoting the version of the platform. The size of the
- ///< info needs to be dynamically queried.
- OFFLOAD_PLATFORM_INFO_BACKEND =
- 3, ///< The backend of the platform. Identifies the native backend adapter
- ///< implementing this platform.
+ /// The string denoting name of the platform. The size of the info needs to be
+ /// dynamically queried.
+ OFFLOAD_PLATFORM_INFO_NAME = 0,
+ /// The string denoting name of the vendor of the platform. The size of the
+ /// info needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VENDOR_NAME = 1,
+ /// The string denoting the version of the platform. The size of the info
+ /// needs to be dynamically queried.
+ OFFLOAD_PLATFORM_INFO_VERSION = 2,
+ /// The backend of the platform. Identifies the native backend adapter
+ /// implementing this platform.
+ OFFLOAD_PLATFORM_INFO_BACKEND = 3,
/// @cond
OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -191,9 +188,12 @@ typedef enum offload_platform_info_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Identifies the native backend of the platform
typedef enum offload_platform_backend_t {
- OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0, ///< The backend is not recognized
- OFFLOAD_PLATFORM_BACKEND_CUDA = 1, ///< The backend is CUDA
- OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2, ///< The backend is AMDGPU
+ /// The backend is not recognized
+ OFFLOAD_PLATFORM_BACKEND_UNKNOWN = 0,
+ /// The backend is CUDA
+ OFFLOAD_PLATFORM_BACKEND_CUDA = 1,
+ /// The backend is AMDGPU
+ OFFLOAD_PLATFORM_BACKEND_AMDGPU = 2,
/// @cond
OFFLOAD_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -226,26 +226,32 @@ typedef enum offload_platform_backend_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
- offload_platform_handle_t hPlatform, ///< [in] handle of the platform
- offload_platform_info_t propName, ///< [in] type of the info to retrieve
- size_t propSize, ///< [in] the number of bytes pointed to by pPlatformInfo.
- void *pPropValue, ///< [out][optional] array of bytes holding the info.If
- ///< Size is not equal to or greater to the real number of
- ///< bytes needed to return the infothen the
- ///< OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned
- ///< and pPlatformInfo is not used.
- size_t *pPropSizeRet ///< [out][optional] pointer to the actual number of
- ///< bytes being queried by pPlatformInfo.
-);
+ // [in] handle of the platform
+ offload_platform_handle_t hPlatform,
+ // [in] type of the info to retrieve
+ offload_platform_info_t propName,
+ // [in] the number of bytes pointed to by pPlatformInfo.
+ size_t propSize,
+ // [out][optional] array of bytes holding the info. If Size is not equal to
+ // or greater to the real number of bytes needed to return the info then the
+ // OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is
+ // not used.
+ void *pPropValue,
+ // [out][optional] pointer to the actual number of bytes being queried by
+ // pPlatformInfo.
+ size_t *pPropSizeRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device types
typedef enum offload_device_type_t {
- OFFLOAD_DEVICE_TYPE_DEFAULT =
- 0, ///< The default device type as preferred by the runtime
- OFFLOAD_DEVICE_TYPE_ALL = 1, ///< Devices of all types
- OFFLOAD_DEVICE_TYPE_GPU = 2, ///< GPU device type
- OFFLOAD_DEVICE_TYPE_CPU = 3, ///< CPU device type
+ /// The default device type as preferred by the runtime
+ OFFLOAD_DEVICE_TYPE_DEFAULT = 0,
+ /// Devices of all types
+ OFFLOAD_DEVICE_TYPE_ALL = 1,
+ /// GPU device type
+ OFFLOAD_DEVICE_TYPE_GPU = 2,
+ /// CPU device type
+ OFFLOAD_DEVICE_TYPE_CPU = 3,
/// @cond
OFFLOAD_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -255,11 +261,16 @@ typedef enum offload_device_type_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device info
typedef enum offload_device_info_t {
- OFFLOAD_DEVICE_INFO_TYPE = 0, ///< type of the device
- OFFLOAD_DEVICE_INFO_PLATFORM = 1, ///< the platform associated with the device
- OFFLOAD_DEVICE_INFO_NAME = 2, ///< Device name
- OFFLOAD_DEVICE_INFO_VENDOR = 3, ///< Device vendor
- OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4, ///< Driver version
+ /// type of the device
+ OFFLOAD_DEVICE_INFO_TYPE = 0,
+ /// the platform associated with the device
+ OFFLOAD_DEVICE_INFO_PLATFORM = 1,
+ /// Device name
+ OFFLOAD_DEVICE_INFO_NAME = 2,
+ /// Device vendor
+ OFFLOAD_DEVICE_INFO_VENDOR = 3,
+ /// Driver version
+ OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4,
/// @cond
OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
@@ -292,21 +303,21 @@ typedef enum offload_device_info_t {
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
- offload_platform_handle_t
- hPlatform, ///< [in] handle of the platform instance
- offload_device_type_t DeviceType, ///< [in] the type of the devices.
- uint32_t NumEntries, ///< [in] the number of devices to be added to
- ///< phDevices.If phDevices is not NULL, then
- ///< NumEntries should be greater than zero. Otherwise
- ///< OFFLOAD_RESULT_ERROR_INVALID_SIZEwill be returned.
- offload_device_handle_t *
- phDevices, ///< [out][optional] array of handle of devices.If NumEntries
- ///< is less than the number of devices available, then
- ///< platform shall only retrieve that number of devices.
- uint32_t *pNumDevices ///< [out][optional] pointer to the number of
- ///< devices.pNumDevices will be updated with the
- ///< total number of devices available.
-);
+ // [in] handle of the platform instance
+ offload_platform_handle_t hPlatform,
+ // [in] the type of the devices.
+ offload_device_type_t DeviceType,
+ // [in] the number of devices to be added to phDevices. If phDevices is not
+ // NULL, then NumEntries should be greater than zero. Otherwise
+ // OFFLOAD_RESULT_ERROR_INVALID_SIZE will be returned.
+ uint32_t NumEntries,
+ // [out][optional] Array of device handles. If NumEntries is less than the
+ // number of devices available, then platform shall only retrieve that
+ // number of devices.
+ offload_device_handle_t *phDevices,
+ // [out][optional] pointer to the number of devices. pNumDevices will be
+ // updated with the total number of devices available.
+ uint32_t *pNumDevices);
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves various information about device
@@ -334,17 +345,20 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hDevice`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
- offload_device_handle_t hDevice, ///< [in] handle of the device instance
- offload_device_info_t propName, ///< [in] type of the info to retrieve
- size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
- void *pPropValue, ///< [out][optional] array of bytes holding the info. If
- ///< propSize is not equal to or greater than the real
- ///< number of bytes needed to return the info then the
- ///< OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned
- ///< and pPropValue is not used.
- size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in
- ///< bytes of the queried propName.
-);
+ // [in] handle of the device instance
+ offload_device_handle_t hDevice,
+ // [in] type of the info to retrieve
+ offload_device_info_t propName,
+ // [in] the number of bytes pointed to by pPropValue.
+ size_t propSize,
+ // [out][optional] array of bytes holding the info. If propSize is not equal
+ // to or greater than the real number of bytes needed to return the info
+ // then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and
+ // pPropValue is not used.
+ void *pPropValue,
+ // [out][optional] pointer to the actual size in bytes of the queried
+ // propName.
+ size_t *pPropSizeRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadGetErrorDetails
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index b905144abf19f2..9395f589952594 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -32,7 +32,7 @@ static std::string MakeComment(StringRef in) {
if (LineBreak - LineStart <= 1) {
break;
}
- out += std::string("\t///< ") +
+ out += std::string("/// ") +
in.substr(LineStart, LineBreak - LineStart).str() + "\n";
LineStart = LineBreak + 1;
}
@@ -107,13 +107,13 @@ static void ProcessFunction(const FunctionRec &F, raw_ostream &OS) {
OS << "(\n";
auto Params = F.getParams();
for (auto &Param : Params) {
+ OS << MakeParamComment(Param) << "\n";
OS << " " << Param.getType() << " " << Param.getName();
if (Param != Params.back()) {
- OS << ", ";
+ OS << ",\n";
} else {
- OS << " ";
+ OS << "\n";
}
- OS << MakeParamComment(Param) << "\n";
}
OS << ");\n\n";
}
@@ -125,9 +125,9 @@ static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) {
uint32_t EtorVal = 0;
for (const auto &EnumVal : Enum.getValues()) {
- auto Desc = MakeComment(EnumVal.getDesc());
- OS << formatv(TAB_1 "{0}_{1} = {2}, {3}", Enum.getEnumValNamePrefix(),
- EnumVal.getName(), EtorVal++, Desc);
+ OS << TAB_1 << MakeComment(EnumVal.getDesc());
+ OS << formatv(TAB_1 "{0}_{1} = {2},\n", Enum.getEnumValNamePrefix(),
+ EnumVal.getName(), EtorVal++);
}
// Add force uint32 val
diff --git a/offload/tools/offload-tblgen/GenCommon.hpp b/offload/tools/offload-tblgen/GenCommon.hpp
index 829f9b525fea92..64df6be8442207 100644
--- a/offload/tools/offload-tblgen/GenCommon.hpp
+++ b/offload/tools/offload-tblgen/GenCommon.hpp
@@ -61,7 +61,7 @@ constexpr auto PrefixUpper = "OFFLOAD";
inline std::string
MakeParamComment(const llvm::offload::tblgen::ParamRec &Param) {
- return llvm::formatv("///< {0}{1}{2} {3}", (Param.isIn() ? "[in]" : ""),
+ return llvm::formatv("// {0}{1}{2} {3}", (Param.isIn() ? "[in]" : ""),
(Param.isOut() ? "[out]" : ""),
(Param.isOpt() ? "[optional]" : ""), Param.getDesc());
}
>From 147e39ee62b881f6abb999dd885f2dc8549ee782 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 4 Oct 2024 16:16:01 +0100
Subject: [PATCH 10/14] Rework Offload API errors
---
offload/new-api/API/APIDefs.td | 12 +-
offload/new-api/API/Common.td | 66 ++++----
offload/new-api/API/Device.td | 22 +--
offload/new-api/API/Platform.td | 18 +--
offload/new-api/include/offload_api.h | 147 ++++++++----------
.../new-api/include/offload_entry_points.inc | 102 +++++-------
offload/new-api/include/offload_exports | 1 -
offload/new-api/include/offload_funcs.inc | 1 -
offload/new-api/include/offload_impl.hpp | 71 ++++++++-
.../include/offload_impl_func_decls.inc | 3 -
offload/new-api/include/offload_print.hpp | 91 ++++++-----
offload/new-api/src/helpers.hpp | 28 ++--
offload/new-api/src/offload_impl.cpp | 37 ++---
offload/new-api/src/offload_lib.cpp | 14 +-
.../tools/offload-tblgen/EntryPointGen.cpp | 6 +-
offload/tools/offload-tblgen/PrintGen.cpp | 17 +-
.../OffloadAPI/common/environment.cpp | 2 +-
.../unittests/OffloadAPI/common/fixtures.hpp | 11 +-
.../device/offloadDeviceGetInfo.cpp | 41 ++---
.../platform/offloadPlatformGet.cpp | 5 +-
.../platform/offloadPlatformGetInfo.cpp | 37 ++---
21 files changed, 380 insertions(+), 352 deletions(-)
diff --git a/offload/new-api/API/APIDefs.td b/offload/new-api/API/APIDefs.td
index 410a28c4c90cfe..a74332363369ac 100644
--- a/offload/new-api/API/APIDefs.td
+++ b/offload/new-api/API/APIDefs.td
@@ -106,11 +106,11 @@ class AddHandleChecksToReturns<list<Param> Params, list<Return> Returns> {
// Does the list of returns already contain ERROR_INVALID_NULL_HANDLE?
bit returns_has_inv_handle = !foldl(
0, Returns, HasErr, Ret,
- !or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_HANDLE")));
+ !or(HasErr, !eq(Ret.value, PREFIX#"_ERRC_INVALID_NULL_HANDLE")));
list<Return> returns_out = !if(returns_has_inv_handle,
- AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>.ret,
- !listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>])
+ AppendConditionsToReturn<Returns, PREFIX # "_ERRC_INVALID_NULL_HANDLE", handle_param_conds>.ret,
+ !listconcat(Returns, [Return<PREFIX # "_ERRC_INVALID_NULL_HANDLE", handle_param_conds>])
);
}
@@ -125,10 +125,10 @@ class AddPointerChecksToReturns<list<Param> Params, list<Return> Returns> {
// Does the list of returns already contain ERROR_INVALID_NULL_POINTER?
bit returns_has_inv_ptr = !foldl(
0, Returns, HasErr, Ret,
- !or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_POINTER")));
+ !or(HasErr, !eq(Ret.value, PREFIX#"_ERROR_CODE_INVALID_NULL_POINTER")));
list<Return> returns_out = !if(returns_has_inv_ptr,
- AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>.ret,
- !listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>])
+ AppendConditionsToReturn<Returns, PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>.ret,
+ !listconcat(Returns, [Return<PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>])
);
}
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index 8de5475af99371..f2fe4b672fbfe5 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -45,41 +45,47 @@ def : Handle {
}
def : Enum {
- let name = "offload_result_t";
+ let name = "offload_errc_t";
let desc = "Defines Return/Error codes";
let etors =[
Etor<"SUCCESS", "Success">,
- Etor<"ERROR_INVALID_VALUE", "Invalid Value">,
- Etor<"ERROR_INVALID_PLATFORM", "Invalid platform">,
- Etor<"ERROR_DEVICE_NOT_FOUND", "Device not found">,
- Etor<"ERROR_INVALID_DEVICE", "Invalid device">,
- Etor<"ERROR_DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
- Etor<"ERROR_UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
- Etor<"ERROR_OUT_OF_RESOURCES", "Out of resources">,
- Etor<"ERROR_UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
- Etor<"ERROR_UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
- Etor<"ERROR_INVALID_ARGUMENT", "generic error code for invalid arguments">,
- Etor<"ERROR_INVALID_NULL_HANDLE", "handle argument is not valid">,
- Etor<"ERROR_INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
- Etor<"ERROR_INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
- Etor<"ERROR_INVALID_ENUMERATION", "enumerator argument is not valid">,
- Etor<"ERROR_UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
- Etor<"ERROR_UNKNOWN", "Unknown or internal error">
+ Etor<"INVALID_VALUE", "Invalid Value">,
+ Etor<"INVALID_PLATFORM", "Invalid platform">,
+ Etor<"DEVICE_NOT_FOUND", "Device not found">,
+ Etor<"INVALID_DEVICE", "Invalid device">,
+ Etor<"DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
+ Etor<"UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
+ Etor<"OUT_OF_RESOURCES", "Out of resources">,
+ Etor<"UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
+ Etor<"UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
+ Etor<"INVALID_ARGUMENT", "generic error code for invalid arguments">,
+ Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">,
+ Etor<"INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
+ Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
+ Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">,
+ Etor<"UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
+ Etor<"UNKNOWN", "Unknown or internal error">
];
}
-def : Function {
- let name = "offloadGetErrorDetails";
- let desc = "Get a detailed error message for the last error that occurred on this thread, if it exists";
- let details = [
- "When an Offload API call returns a return value other than OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error message.",
- "If a further Offload call (excluding this function) is made on the same thread without checking "
- "its detailed error message with this function, that message should be considered lost.",
- "The returned char* is only valid until the next Offload function call on the same thread (excluding further calls to this function.)"
- ];
- let params = [
- Param<"size_t*", "SizeRet", "Pointer to return the size of the available error message. A size of 0 indicates no message.", PARAM_OUT_OPTIONAL>,
- Param<"const char**", "DetailStringRet", "Pointer to return the error message string.", PARAM_OUT_OPTIONAL>
+def : Struct {
+ let name = "offload_error_struct_t";
+ let desc = "Details of the error condition returned by an API call";
+ let members = [
+ StructMember<"offload_errc_t", "code", "The error code">,
+ StructMember<"const char*", "details", "String containing error details">
];
- let returns = []; // Only SUCCESS is expected
+}
+
+def : Typedef {
+ let name = "offload_result_t";
+ let desc = "Result type returned by all entry points.";
+ let value = "const offload_error_struct_t*";
+}
+
+def : Macro {
+ let name = "OFFLOAD_SUCCESS";
+ let condition = "!defined(OFFLOAD_SUCCESS)";
+ let desc = "Success condition";
+ let value = "NULL";
}
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index 837d7071853f5c..da1141cf1986e0 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -47,7 +47,7 @@ def : Function {
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices. "
- "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
+ "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_ERRC_INVALID_SIZE "
"will be returned.", PARAM_IN>,
RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
"If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
@@ -56,13 +56,13 @@ def : Function {
"pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
];
let returns = [
- Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ Return<"OFFLOAD_ERRC_INVALID_SIZE", [
"`NumEntries == 0 && phDevices != NULL`"
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
"`NumEntries > 0 && phDevices == NULL`"
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_VALUE">
+ Return<"OFFLOAD_ERRC_INVALID_VALUE">
];
}
@@ -78,24 +78,24 @@ def : Function {
Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
- "number of bytes needed to return the info then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and "
+ "number of bytes needed to return the info then the OFFLOAD_ERRC_INVALID_SIZE error is returned and "
"pPropValue is not used.", PARAM_OUT_OPTIONAL, TypeInfo<"propName" , "propSize">>,
Param<"size_t*", "pPropSizeRet", "pointer to the actual size in bytes of the queried propName.", PARAM_OUT_OPTIONAL>
];
let returns = [
- Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
+ Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
"If `propName` is not supported by the adapter."
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ Return<"OFFLOAD_ERRC_INVALID_SIZE", [
"`propSize == 0 && pPropValue != NULL`",
"If `propSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
"`propSize != 0 && pPropValue == NULL`",
"`pPropValue == NULL && pPropSizeRet == NULL`"
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_DEVICE">,
- Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
- Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
+ Return<"OFFLOAD_ERRC_INVALID_DEVICE">,
+ Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
+ Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
];
}
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index d280da1156c798..0bfcbdce8d2d5c 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -18,7 +18,7 @@ def : Function {
let params = [
Param<"uint32_t", "NumEntries",
"The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then "
- "NumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
+ "NumEntries should be greater than zero, otherwise OFFLOAD_ERRC_INVALID_SIZE "
"will be returned.", PARAM_IN>,
RangedParam<"offload_platform_handle_t*", "phPlatforms",
"Array of handle of platforms. If NumEntries is less than the number of "
@@ -30,7 +30,7 @@ def : Function {
PARAM_OUT_OPTIONAL>
];
let returns = [
- Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ Return<"OFFLOAD_ERRC_INVALID_SIZE", [
"`NumEntries == 0 && phPlatforms != NULL`"
]>
];
@@ -71,24 +71,24 @@ def : Function {
Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
"If Size is not equal to or greater to the real number of bytes needed to return the info "
- "then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
+ "then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
TypeInfo<"propName" , "propSize">>,
Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
];
let returns = [
- Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
+ Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
"If `propName` is not supported by the platform."
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
+ Return<"OFFLOAD_ERRC_INVALID_SIZE", [
"`propSize == 0 && pPropValue != NULL`",
"If `propSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
+ Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
"`propSize != 0 && pPropValue == NULL`",
"`pPropValue == NULL && pPropSizeRet == NULL`"
]>,
- Return<"OFFLOAD_RESULT_ERROR_INVALID_PLATFORM">,
- Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
- Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
+ Return<"OFFLOAD_ERRC_INVALID_PLATFORM">,
+ Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
+ Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
];
}
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 8e70efa27774d1..a4d72b9a36a7c7 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -69,73 +69,65 @@ typedef struct offload_context_handle_t_ *offload_context_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Defines Return/Error codes
-typedef enum offload_result_t {
+typedef enum offload_errc_t {
/// Success
- OFFLOAD_RESULT_SUCCESS = 0,
+ OFFLOAD_ERRC_SUCCESS = 0,
/// Invalid Value
- OFFLOAD_RESULT_ERROR_INVALID_VALUE = 1,
+ OFFLOAD_ERRC_INVALID_VALUE = 1,
/// Invalid platform
- OFFLOAD_RESULT_ERROR_INVALID_PLATFORM = 2,
+ OFFLOAD_ERRC_INVALID_PLATFORM = 2,
/// Device not found
- OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND = 3,
+ OFFLOAD_ERRC_DEVICE_NOT_FOUND = 3,
/// Invalid device
- OFFLOAD_RESULT_ERROR_INVALID_DEVICE = 4,
+ OFFLOAD_ERRC_INVALID_DEVICE = 4,
/// Device hung, reset, was removed, or driver update occurred
- OFFLOAD_RESULT_ERROR_DEVICE_LOST = 5,
+ OFFLOAD_ERRC_DEVICE_LOST = 5,
/// plugin is not initialized or specific entry-point is not implemented
- OFFLOAD_RESULT_ERROR_UNINITIALIZED = 6,
+ OFFLOAD_ERRC_UNINITIALIZED = 6,
/// Out of resources
- OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES = 7,
+ OFFLOAD_ERRC_OUT_OF_RESOURCES = 7,
/// generic error code for unsupported versions
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION = 8,
+ OFFLOAD_ERRC_UNSUPPORTED_VERSION = 8,
/// generic error code for unsupported features
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE = 9,
+ OFFLOAD_ERRC_UNSUPPORTED_FEATURE = 9,
/// generic error code for invalid arguments
- OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT = 10,
+ OFFLOAD_ERRC_INVALID_ARGUMENT = 10,
/// handle argument is not valid
- OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE = 11,
+ OFFLOAD_ERRC_INVALID_NULL_HANDLE = 11,
/// pointer argument may not be nullptr
- OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER = 12,
+ OFFLOAD_ERRC_INVALID_NULL_POINTER = 12,
/// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
- OFFLOAD_RESULT_ERROR_INVALID_SIZE = 13,
+ OFFLOAD_ERRC_INVALID_SIZE = 13,
/// enumerator argument is not valid
- OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION = 14,
+ OFFLOAD_ERRC_INVALID_ENUMERATION = 14,
/// enumerator argument is not supported by the device
- OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION = 15,
+ OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION = 15,
/// Unknown or internal error
- OFFLOAD_RESULT_ERROR_UNKNOWN = 16,
+ OFFLOAD_ERRC_UNKNOWN = 16,
/// @cond
- OFFLOAD_RESULT_FORCE_UINT32 = 0x7fffffff
+ OFFLOAD_ERRC_FORCE_UINT32 = 0x7fffffff
/// @endcond
-} offload_result_t;
+} offload_errc_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Get a detailed error message for the last error that occurred on this
-/// thread, if it exists
-///
-/// @details
-/// - When an Offload API call returns a return value other than
-/// OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error
-/// message.
-/// - If a further Offload call (excluding this function) is made on the same
-/// thread without checking its detailed error message with this function,
-/// that message should be considered lost.
-/// - The returned char* is only valid until the next Offload function call
-/// on the same thread (excluding further calls to this function.)
-///
-/// @returns
-/// - ::OFFLOAD_RESULT_SUCCESS
-/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
-/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
- // [out][optional] Pointer to return the size of the available error
- // message. A size of 0 indicates no message.
- size_t *SizeRet,
- // [out][optional] Pointer to return the error message string.
- const char **DetailStringRet);
+/// @brief Details of the error condition returned by an API call
+typedef struct offload_error_struct_t {
+ offload_errc_t code; /// The error code
+ const char *details; /// String containing error details
+} offload_error_struct_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Result type returned by all entry points.
+typedef const offload_error_struct_t *offload_result_t;
+
+///////////////////////////////////////////////////////////////////////////////
+#ifndef OFFLOAD_SUCCESS
+#if !defined(OFFLOAD_SUCCESS)
+/// @brief Success condition
+#define OFFLOAD_SUCCESS NULL
+#endif // !defined(OFFLOAD_SUCCESS)
+#endif // OFFLOAD_SUCCESS
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
@@ -148,14 +140,14 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadGetErrorDetails(
/// - ::OFFLOAD_RESULT_SUCCESS
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `NumEntries == 0 && phPlatforms != NULL`
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
// [in] The number of platforms to be added to phPlatforms. If phPlatforms
// is not NULL, then NumEntries should be greater than zero, otherwise
- // OFFLOAD_RESULT_ERROR_INVALID_SIZE will be returned.
+ // OFFLOAD_ERRC_INVALID_SIZE will be returned.
uint32_t NumEntries,
// [out][optional] Array of handle of platforms. If NumEntries is less than
// the number of platforms available, then offloadPlatformGet shall only
@@ -211,20 +203,21 @@ typedef enum offload_platform_backend_t {
/// - ::OFFLOAD_RESULT_SUCCESS
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
-/// - ::OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION
+/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the platform.
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to
/// return the info.
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_PLATFORM
-/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES
-/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
+/// - ::OFFLOAD_ERRC_OUT_OF_RESOURCES
+/// - ::OFFLOAD_ERRC_OUT_OF_HOST_MEMORY
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
+/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
// [in] handle of the platform
offload_platform_handle_t hPlatform,
@@ -234,8 +227,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
size_t propSize,
// [out][optional] array of bytes holding the info. If Size is not equal to
// or greater to the real number of bytes needed to return the info then the
- // OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is
- // not used.
+ // OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not
+ // used.
void *pPropValue,
// [out][optional] pointer to the actual number of bytes being queried by
// pPlatformInfo.
@@ -295,13 +288,14 @@ typedef enum offload_device_info_t {
/// - ::OFFLOAD_RESULT_SUCCESS
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `NumEntries == 0 && phDevices != NULL`
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
/// + `NumEntries > 0 && phDevices == NULL`
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_VALUE
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_VALUE
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
+/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
// [in] handle of the platform instance
offload_platform_handle_t hPlatform,
@@ -309,7 +303,7 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
offload_device_type_t DeviceType,
// [in] the number of devices to be added to phDevices. If phDevices is not
// NULL, then NumEntries should be greater than zero. Otherwise
- // OFFLOAD_RESULT_ERROR_INVALID_SIZE will be returned.
+ // OFFLOAD_ERRC_INVALID_SIZE will be returned.
uint32_t NumEntries,
// [out][optional] Array of device handles. If NumEntries is less than the
// number of devices available, then platform shall only retrieve that
@@ -330,20 +324,21 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// - ::OFFLOAD_RESULT_SUCCESS
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
-/// - ::OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION
+/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_SIZE
+/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to
/// return the info.
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_DEVICE
-/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES
-/// - ::OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY
-/// - ::OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_DEVICE
+/// - ::OFFLOAD_ERRC_OUT_OF_RESOURCES
+/// - ::OFFLOAD_ERRC_OUT_OF_HOST_MEMORY
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hDevice`
+/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
// [in] handle of the device instance
offload_device_handle_t hDevice,
@@ -353,21 +348,13 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
size_t propSize,
// [out][optional] array of bytes holding the info. If propSize is not equal
// to or greater than the real number of bytes needed to return the info
- // then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and
- // pPropValue is not used.
+ // then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPropValue is
+ // not used.
void *pPropValue,
// [out][optional] pointer to the actual size in bytes of the queried
// propName.
size_t *pPropSizeRet);
-///////////////////////////////////////////////////////////////////////////////
-/// @brief Function parameters for offloadGetErrorDetails
-/// @details Each entry is a pointer to the parameter passed to the function;
-typedef struct offload_get_error_details_params_t {
- size_t **pSizeRet;
- const char ***pDetailStringRet;
-} offload_get_error_details_params_t;
-
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGet
/// @details Each entry is a pointer to the parameter passed to the function;
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index 2910bc414071fc..0bdfabe7fefa9c 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -7,40 +7,13 @@
//===----------------------------------------------------------------------===//
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadGetErrorDetails_val(size_t *SizeRet,
- const char **DetailStringRet) {
- if (true /*enableParameterValidation*/) {
- }
-
- return offloadGetErrorDetails_impl(SizeRet, DetailStringRet);
-}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadGetErrorDetails(size_t *SizeRet, const char **DetailStringRet) {
- if (std::getenv("OFFLOAD_TRACE")) {
- std::cout << "---> offloadGetErrorDetails";
- }
-
- offload_result_t result =
- offloadGetErrorDetails_val(SizeRet, DetailStringRet);
-
- if (std::getenv("OFFLOAD_TRACE")) {
- offload_get_error_details_params_t Params = {&SizeRet, &DetailStringRet};
- std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
- std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
- }
- }
- return result;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadPlatformGet_val(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms) {
+offload_impl_result_t
+offloadPlatformGet_val(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0 && phPlatforms != NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
}
@@ -61,33 +34,33 @@ offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
&pNumPlatforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
- if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
- std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadPlatformGetInfo_val(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t propSize, void *pPropValue,
- size_t *pPropSizeRet) {
+offload_impl_result_t
+offloadPlatformGetInfo_val(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet) {
if (true /*enableParameterValidation*/) {
if (propSize == 0 && pPropValue != NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
if (propSize != 0 && pPropValue == NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (pPropValue == NULL && pPropSizeRet == NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (NULL == hPlatform) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
}
@@ -109,30 +82,30 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
&hPlatform, &propName, &propSize, &pPropValue, &pPropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
- if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
- std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
- offload_device_type_t DeviceType,
- uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- uint32_t *pNumDevices) {
+offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
+ offload_device_type_t DeviceType,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0 && phDevices != NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
if (NumEntries > 0 && phDevices == NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (NULL == hPlatform) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
}
@@ -155,33 +128,34 @@ offloadDeviceGet(offload_platform_handle_t hPlatform,
&phDevices, &pNumDevices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
- if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
- std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
}
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize, void *pPropValue,
- size_t *pPropSizeRet) {
+offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize,
+ void *pPropValue,
+ size_t *pPropSizeRet) {
if (true /*enableParameterValidation*/) {
if (propSize == 0 && pPropValue != NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
if (propSize != 0 && pPropValue == NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (pPropValue == NULL && pPropSizeRet == NULL) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (NULL == hDevice) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE;
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
}
@@ -203,8 +177,8 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
&pPropValue, &pPropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
- if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {
- std::cout << " *Error Details* " << *LastErrorDetails() << " \n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
}
}
return result;
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
index fb8103ae5e80ef..cb256fd34770d5 100644
--- a/offload/new-api/include/offload_exports
+++ b/offload/new-api/include/offload_exports
@@ -1,6 +1,5 @@
VERS1.0 {
global:
- offloadGetErrorDetails;
offloadPlatformGet;
offloadPlatformGetInfo;
offloadDeviceGet;
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/new-api/include/offload_funcs.inc
index 7160b27a5332cf..14e878b9ed5a27 100644
--- a/offload/new-api/include/offload_funcs.inc
+++ b/offload/new-api/include/offload_funcs.inc
@@ -10,7 +10,6 @@
#error Please define the macro OFFLOAD_FUNC(Function)
#endif
-OFFLOAD_FUNC(offloadGetErrorDetails)
OFFLOAD_FUNC(offloadPlatformGet)
OFFLOAD_FUNC(offloadPlatformGetInfo)
OFFLOAD_FUNC(offloadDeviceGet)
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
index 1e96fdebfc765e..b0bdf6c2221ae4 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/new-api/include/offload_impl.hpp
@@ -5,25 +5,80 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+#pragma once
+#include <iostream>
+#include <memory>
#include <offload_api.h>
#include <optional>
+#include <set>
#include <string>
+#include <unordered_set>
+#include <vector>
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
-std::optional<std::string> &LastErrorDetails();
+// Use the StringSet container to efficiently deduplicate repeated error
+// strings (e.g. if the same error is hit constantly in a long running program)
+llvm::StringSet<> &ErrorStrs();
+
+// Use an unordered_set to avoid duplicates of error structs themselves.
+// We cannot store the structs directly as returned pointers to them must always
+// be valid, and a rehash of the set may invalidate them. This requires
+// custom hash and equal_to function objects.
+using ErrPtrT = std::unique_ptr<offload_error_struct_t>;
+struct ErrPtrEqual {
+ bool operator()(const ErrPtrT &lhs, const ErrPtrT &rhs) const {
+ if (!lhs && !rhs) {
+ return true;
+ }
+ if (!lhs || !rhs) {
+ return false;
+ }
+
+ bool StrsEqual = false;
+ if (lhs->details == NULL && rhs->details == NULL) {
+ StrsEqual = true;
+ } else if (lhs->details != NULL && rhs->details != NULL) {
+ StrsEqual = (std::strcmp(lhs->details, rhs->details) == 0);
+ }
+ return (lhs->code == rhs->code) && StrsEqual;
+ }
+};
+struct ErrPtrHash {
+ size_t operator()(const ErrPtrT &e) const {
+ if (!e) {
+ // We shouldn't store empty errors (i.e. success), but just in case
+ return 0lu;
+ } else {
+ return std::hash<int>{}(e->code);
+ }
+ }
+};
+using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
+ErrSetT &Errors();
struct offload_impl_result_t {
- offload_impl_result_t() = delete;
- offload_impl_result_t(offload_result_t Result) : Result(Result) {
- LastErrorDetails() = std::nullopt;
+ offload_impl_result_t(std::nullptr_t) : Result(OFFLOAD_SUCCESS) {}
+ offload_impl_result_t(offload_errc_t Code) {
+ if (Code == OFFLOAD_ERRC_SUCCESS) {
+ Result = nullptr;
+ } else {
+ auto Err = std::unique_ptr<offload_error_struct_t>(
+ new offload_error_struct_t{Code, nullptr});
+ Result = Errors().emplace(std::move(Err)).first->get();
+ }
}
- offload_impl_result_t(offload_result_t Result, std::string Details)
- : Result(Result) {
- assert(Result != OFFLOAD_RESULT_SUCCESS);
- LastErrorDetails() = Details;
+ offload_impl_result_t(offload_errc_t Code, llvm::StringRef Details) {
+ assert(Code != OFFLOAD_ERRC_SUCCESS);
+ Result = nullptr;
+ auto DetailsStr = ErrorStrs().insert(Details).first->getKeyData();
+ auto Err = std::unique_ptr<offload_error_struct_t>(
+ new offload_error_struct_t{Code, DetailsStr});
+ Result = Errors().emplace(std::move(Err)).first->get();
}
operator offload_result_t() { return Result; }
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
index df40c342049549..1160ee1c6e2549 100644
--- a/offload/new-api/include/offload_impl_func_decls.inc
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -5,9 +5,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-offload_result_t offloadGetErrorDetails_impl(size_t *SizeRet,
- const char **DetailStringRet);
-
offload_impl_result_t
offloadPlatformGet_impl(uint32_t NumEntries,
offload_platform_handle_t *phPlatforms,
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
index 4a0f6d14f10b4e..c3a6c0a702e5b7 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -24,7 +24,7 @@ template <> struct is_handle<offload_device_handle_t> : std::true_type {};
template <> struct is_handle<offload_context_handle_t> : std::true_type {};
template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
-inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value);
+inline std::ostream &operator<<(std::ostream &os, enum offload_errc_t value);
inline std::ostream &operator<<(std::ostream &os,
enum offload_platform_info_t value);
inline std::ostream &operator<<(std::ostream &os,
@@ -35,60 +35,60 @@ inline std::ostream &operator<<(std::ostream &os,
enum offload_device_info_t value);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Print operator for the offload_result_t type
+/// @brief Print operator for the offload_errc_t type
/// @returns std::ostream &
-inline std::ostream &operator<<(std::ostream &os, enum offload_result_t value) {
+inline std::ostream &operator<<(std::ostream &os, enum offload_errc_t value) {
switch (value) {
- case OFFLOAD_RESULT_SUCCESS:
- os << "OFFLOAD_RESULT_SUCCESS";
+ case OFFLOAD_ERRC_SUCCESS:
+ os << "OFFLOAD_ERRC_SUCCESS";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_VALUE:
- os << "OFFLOAD_RESULT_ERROR_INVALID_VALUE";
+ case OFFLOAD_ERRC_INVALID_VALUE:
+ os << "OFFLOAD_ERRC_INVALID_VALUE";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_PLATFORM:
- os << "OFFLOAD_RESULT_ERROR_INVALID_PLATFORM";
+ case OFFLOAD_ERRC_INVALID_PLATFORM:
+ os << "OFFLOAD_ERRC_INVALID_PLATFORM";
break;
- case OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND:
- os << "OFFLOAD_RESULT_ERROR_DEVICE_NOT_FOUND";
+ case OFFLOAD_ERRC_DEVICE_NOT_FOUND:
+ os << "OFFLOAD_ERRC_DEVICE_NOT_FOUND";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_DEVICE:
- os << "OFFLOAD_RESULT_ERROR_INVALID_DEVICE";
+ case OFFLOAD_ERRC_INVALID_DEVICE:
+ os << "OFFLOAD_ERRC_INVALID_DEVICE";
break;
- case OFFLOAD_RESULT_ERROR_DEVICE_LOST:
- os << "OFFLOAD_RESULT_ERROR_DEVICE_LOST";
+ case OFFLOAD_ERRC_DEVICE_LOST:
+ os << "OFFLOAD_ERRC_DEVICE_LOST";
break;
- case OFFLOAD_RESULT_ERROR_UNINITIALIZED:
- os << "OFFLOAD_RESULT_ERROR_UNINITIALIZED";
+ case OFFLOAD_ERRC_UNINITIALIZED:
+ os << "OFFLOAD_ERRC_UNINITIALIZED";
break;
- case OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES:
- os << "OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES";
+ case OFFLOAD_ERRC_OUT_OF_RESOURCES:
+ os << "OFFLOAD_ERRC_OUT_OF_RESOURCES";
break;
- case OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION:
- os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_VERSION";
+ case OFFLOAD_ERRC_UNSUPPORTED_VERSION:
+ os << "OFFLOAD_ERRC_UNSUPPORTED_VERSION";
break;
- case OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE:
- os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_FEATURE";
+ case OFFLOAD_ERRC_UNSUPPORTED_FEATURE:
+ os << "OFFLOAD_ERRC_UNSUPPORTED_FEATURE";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT:
- os << "OFFLOAD_RESULT_ERROR_INVALID_ARGUMENT";
+ case OFFLOAD_ERRC_INVALID_ARGUMENT:
+ os << "OFFLOAD_ERRC_INVALID_ARGUMENT";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE:
- os << "OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE";
+ case OFFLOAD_ERRC_INVALID_NULL_HANDLE:
+ os << "OFFLOAD_ERRC_INVALID_NULL_HANDLE";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER:
- os << "OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER";
+ case OFFLOAD_ERRC_INVALID_NULL_POINTER:
+ os << "OFFLOAD_ERRC_INVALID_NULL_POINTER";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_SIZE:
- os << "OFFLOAD_RESULT_ERROR_INVALID_SIZE";
+ case OFFLOAD_ERRC_INVALID_SIZE:
+ os << "OFFLOAD_ERRC_INVALID_SIZE";
break;
- case OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION:
- os << "OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION";
+ case OFFLOAD_ERRC_INVALID_ENUMERATION:
+ os << "OFFLOAD_ERRC_INVALID_ENUMERATION";
break;
- case OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
- os << "OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION";
+ case OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION:
+ os << "OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION";
break;
- case OFFLOAD_RESULT_ERROR_UNKNOWN:
- os << "OFFLOAD_RESULT_ERROR_UNKNOWN";
+ case OFFLOAD_ERRC_UNKNOWN:
+ os << "OFFLOAD_ERRC_UNKNOWN";
break;
default:
os << "unknown enumerator";
@@ -280,14 +280,13 @@ inline void printTagged(std::ostream &os, const void *ptr,
}
}
-inline std::ostream &operator<<(
- std::ostream &os,
- [[maybe_unused]] const struct offload_get_error_details_params_t *params) {
- os << ".SizeRet = ";
- printPtr(os, *params->pSizeRet);
- os << ", ";
- os << ".DetailStringRet = ";
- printPtr(os, *params->pDetailStringRet);
+inline std::ostream &operator<<(std::ostream &os,
+ const offload_error_struct_t *err) {
+ if (err == nullptr) {
+ os << "OFFLOAD_SUCCESS";
+ } else {
+ os << err->code;
+ }
return os;
}
@@ -401,5 +400,5 @@ inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
os << ")";
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
diff --git a/offload/new-api/src/helpers.hpp b/offload/new-api/src/helpers.hpp
index 246de2b678015d..e24bd58bc11111 100644
--- a/offload/new-api/src/helpers.hpp
+++ b/offload/new-api/src/helpers.hpp
@@ -17,16 +17,16 @@
#include <cstring>
template <typename T, typename Assign>
-offload_result_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
- size_t *ParamValueSizeRet, T Value,
- size_t ValueSize, Assign &&AssignFunc) {
+offload_errc_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, T Value, size_t ValueSize,
+ Assign &&AssignFunc) {
if (!ParamValue && !ParamValueSizeRet) {
- return OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER;
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
if (ParamValue != nullptr) {
if (ParamValueSize < ValueSize) {
- return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
AssignFunc(ParamValue, Value, ValueSize);
}
@@ -35,12 +35,12 @@ offload_result_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
*ParamValueSizeRet = ValueSize;
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_ERRC_SUCCESS;
}
template <typename T>
-offload_result_t getInfo(size_t ParamValueSize, void *ParamValue,
- size_t *ParamValueSizeRet, T Value) {
+offload_errc_t getInfo(size_t ParamValueSize, void *ParamValue,
+ size_t *ParamValueSizeRet, T Value) {
auto Assignment = [](void *ParamValue, T Value, size_t) {
*static_cast<T *>(ParamValue) = Value;
};
@@ -50,15 +50,15 @@ offload_result_t getInfo(size_t ParamValueSize, void *ParamValue,
}
template <typename T>
-offload_result_t getInfoArray(size_t array_length, size_t ParamValueSize,
- void *ParamValue, size_t *ParamValueSizeRet,
- const T *Value) {
+offload_errc_t getInfoArray(size_t array_length, size_t ParamValueSize,
+ void *ParamValue, size_t *ParamValueSizeRet,
+ const T *Value) {
return getInfoImpl(ParamValueSize, ParamValue, ParamValueSizeRet, Value,
array_length * sizeof(T), memcpy);
}
template <>
-inline offload_result_t
+inline offload_errc_t
getInfo<const char *>(size_t ParamValueSize, void *ParamValue,
size_t *ParamValueSizeRet, const char *Value) {
return getInfoArray(strlen(Value) + 1, ParamValueSize, ParamValue,
@@ -79,12 +79,12 @@ class ReturnHelper {
ParamValueSizeRet(ParamValueSize) {}
// Scalar return Value
- template <class T> offload_result_t operator()(const T &t) {
+ template <class T> offload_errc_t operator()(const T &t) {
return getInfo(ParamValueSize, ParamValue, ParamValueSizeRet, t);
}
// Array return Value
- template <class T> offload_result_t operator()(const T *t, size_t s) {
+ template <class T> offload_errc_t operator()(const T *t, size_t s) {
return getInfoArray(s, ParamValueSize, ParamValue, ParamValueSizeRet, t);
}
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index 43112bba448045..31329d2aea683d 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -67,23 +67,6 @@ void initPlugins() {
}
}
-offload_result_t offloadGetErrorDetails_impl(size_t *SizeRet,
- const char **DetailStringRet) {
- if (auto Details = LastErrorDetails()) {
- if (SizeRet) {
- *SizeRet = Details->size();
- }
- if (DetailStringRet) {
- *DetailStringRet = Details->c_str();
- }
- } else {
- if (SizeRet) {
- *SizeRet = 0;
- }
- }
- return OFFLOAD_RESULT_SUCCESS;
-}
-
offload_impl_result_t
offloadPlatformGet_impl(uint32_t NumEntries,
offload_platform_handle_t *phPlatforms,
@@ -95,9 +78,9 @@ offloadPlatformGet_impl(uint32_t NumEntries,
std::call_once(InitFlag, initPlugins);
if (NumEntries > Platforms().size()) {
- return {OFFLOAD_RESULT_ERROR_INVALID_SIZE,
- formatv("{0} platform(s) available but {1} requested.",
- Platforms().size(), NumEntries)};
+ return {OFFLOAD_ERRC_INVALID_SIZE,
+ std::string{formatv("{0} platform(s) available but {1} requested.",
+ Platforms().size(), NumEntries)}};
}
if (phPlatforms) {
@@ -111,7 +94,7 @@ offloadPlatformGet_impl(uint32_t NumEntries,
*pNumPlatforms = Platforms().size();
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
offload_impl_result_t
@@ -141,10 +124,10 @@ offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
}
}
default:
- return OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION;
+ return OFFLOAD_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
@@ -163,7 +146,7 @@ offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
*pNumDevices = static_cast<uint32_t>(hPlatform->Devices.size());
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
@@ -176,7 +159,7 @@ offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
InfoQueueTy DevInfo;
if (auto Err = hDevice->Device.obtainInfoImpl(DevInfo))
- return OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES;
+ return OFFLOAD_ERRC_OUT_OF_RESOURCES;
// Find the info if it exists under any of the given names
auto GetInfo = [&DevInfo](std::vector<std::string> Names) {
@@ -208,8 +191,8 @@ offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
return ReturnValue(
GetInfo({"CUDA Driver Version", "HSA Runtime Version"}).c_str());
default:
- return OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION;
+ return OFFLOAD_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index a8a23e94a2fd6c..7ad0ff1d6e35c3 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -16,12 +16,14 @@
#include <iostream>
-// Store details for the last error that occurred on this thread. It MAY be set
-// when an implementation function returns a result other than
-// OFFLOAD_RESULT_SUCCESS.
-std::optional<std::string> &LastErrorDetails() {
- thread_local std::optional<std::string> Details;
- return Details;
+llvm::StringSet<> &ErrorStrs() {
+ static llvm::StringSet<> ErrorStrs;
+ return ErrorStrs;
+}
+
+ErrSetT &Errors() {
+ static ErrSetT Errors{};
+ return Errors;
}
// Pull in the declarations for the implementation funtions. The actual entry
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 9f81d9d5582393..e36252e482c426 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -23,7 +23,7 @@ using namespace offload::tblgen;
static void EmitValidationFunc(const FunctionRec &F, raw_ostream &OS) {
OS << CommentsHeader;
// Emit preamble
- OS << formatv("{0}_result_t {1}_val(\n ", PrefixLower, F.getName());
+ OS << formatv("{0}_impl_result_t {1}_val(\n ", PrefixLower, F.getName());
// Emit arguments
std::string ParamNameList = "";
for (auto &Param : F.getParams()) {
@@ -92,8 +92,8 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
OS << formatv("};\n");
OS << TAB_2 "std::cout << \"(\" << &Params << \")\";\n";
OS << TAB_2 "std::cout << \"-> \" << result << \"\\n\";\n";
- OS << TAB_2 "if (result != OFFLOAD_RESULT_SUCCESS && LastErrorDetails()) {\n";
- OS << TAB_3 "std::cout << \" *Error Details* \" << *LastErrorDetails() "
+ OS << TAB_2 "if (result && result->details) {\n";
+ OS << TAB_3 "std::cout << \" *Error Details* \" << result->details "
"<< \" \\n\";\n";
OS << TAB_2 "}\n";
OS << TAB_1 "}\n";
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index b89d45388f0bf8..0e73c29c338a1b 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -94,6 +94,20 @@ inline void printTagged(std::ostream &os, const void *ptr, {0} value, size_t siz
OS << "}\n";
}
+static void EmitResultPrint(raw_ostream &OS) {
+ OS << R""(
+inline std::ostream &operator<<(std::ostream &os,
+ const offload_error_struct_t *err) {
+ if (err == nullptr) {
+ os << "OFFLOAD_SUCCESS";
+ } else {
+ os << err->code;
+ }
+ return os;
+}
+)"";
+}
+
static void EmitFunctionParamStructPrint(const FunctionRec &Func,
raw_ostream &OS) {
OS << formatv(R"(
@@ -173,6 +187,7 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
EnumRec E{R};
ProcessEnum(E, OS);
}
+ EmitResultPrint(OS);
// Emit print functions for the function param structs
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
@@ -201,7 +216,7 @@ template <typename T> inline offload_result_t printPtr(std::ostream &os, const T
os << ")";
}
- return OFFLOAD_RESULT_SUCCESS;
+ return OFFLOAD_SUCCESS;
}
)""";
}
diff --git a/offload/unittests/OffloadAPI/common/environment.cpp b/offload/unittests/OffloadAPI/common/environment.cpp
index a19e09fc5767c0..01973ec117e300 100644
--- a/offload/unittests/OffloadAPI/common/environment.cpp
+++ b/offload/unittests/OffloadAPI/common/environment.cpp
@@ -78,7 +78,7 @@ offload_platform_handle_t TestEnvironment::getPlatform() {
for (auto CandidatePlatform : Platforms) {
uint32_t NumDevices = 0;
if (offloadDeviceGet(CandidatePlatform, OFFLOAD_DEVICE_TYPE_ALL, 0,
- nullptr, &NumDevices) == OFFLOAD_RESULT_SUCCESS) {
+ nullptr, &NumDevices) == OFFLOAD_SUCCESS) {
if (NumDevices > 0) {
Platform = CandidatePlatform;
break;
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/fixtures.hpp
index a7f5f84adb2568..2366f8687a8e93 100644
--- a/offload/unittests/OffloadAPI/common/fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/fixtures.hpp
@@ -15,7 +15,16 @@
#pragma once
#ifndef ASSERT_SUCCESS
-#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_RESULT_SUCCESS, ACTUAL)
+#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_SUCCESS, ACTUAL)
+#endif
+
+// TODO: rework this so the EXPECTED/ACTUAL results are readable
+#ifndef ASSERT_ERROR
+#define ASSERT_ERROR(EXPECTED, ACTUAL) \
+ do { \
+ offload_result_t Res = ACTUAL; \
+ ASSERT_TRUE(Res && (Res->code == EXPECTED)); \
+ } while (0)
#endif
#define RETURN_ON_FATAL_FAILURE(...) \
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
index df8aecc1f0be2d..e9f5615b35d3ef 100644
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
@@ -60,43 +60,44 @@ TEST_P(offloadDeviceGetInfoTest, Success) {
TEST_F(offloadDeviceGetInfoTest, InvalidNullHandleDevice) {
offload_device_type_t DeviceType;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE,
- offloadDeviceGetInfo(nullptr, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(offload_device_type_t), &DeviceType,
- nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
+ offloadDeviceGetInfo(nullptr, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(offload_device_type_t), &DeviceType,
+ nullptr));
}
TEST_F(offloadDeviceGetInfoTest, InvalidEnumerationInfoType) {
offload_device_type_t DeviceType;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_FORCE_UINT32,
- sizeof(offload_device_type_t), &DeviceType,
- nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_FORCE_UINT32,
+ sizeof(offload_device_type_t), &DeviceType,
+ nullptr));
}
TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSize) {
offload_device_type_t DeviceType;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
- &DeviceType, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
+ &DeviceType, nullptr));
}
TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSizeSmall) {
offload_device_type_t DeviceType;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(DeviceType) - 1, &DeviceType, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(DeviceType) - 1, &DeviceType,
+ nullptr));
}
TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropValue) {
offload_device_type_t DeviceType;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(DeviceType), nullptr, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
+ sizeof(DeviceType), nullptr, nullptr));
}
TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropSizeRet) {
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0, nullptr,
- nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
+ nullptr, nullptr));
}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
index 6ede71ff1babe6..14b7b9bba6b4d4 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
@@ -23,6 +23,7 @@ TEST_F(offloadPlatformGetTest, InvalidNumEntries) {
uint32_t PlatformCount;
ASSERT_SUCCESS(offloadPlatformGet(0, nullptr, &PlatformCount));
std::vector<offload_platform_handle_t> Platforms(PlatformCount);
- ASSERT_EQ(offloadPlatformGet(0, Platforms.data(), nullptr),
- OFFLOAD_RESULT_ERROR_INVALID_SIZE);
+ ASSERT_ERROR(
+ OFFLOAD_ERRC_INVALID_SIZE,
+ offloadPlatformGet(PlatformCount + 1, Platforms.data(), nullptr));
}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
index 7a967ee674b00c..a5c86a7ba1933f 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
@@ -57,41 +57,42 @@ TEST_P(offloadPlatformGetInfoTest, Success) {
TEST_F(offloadPlatformGetInfoTest, InvalidNullHandle) {
size_t Size = 0;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_HANDLE,
- offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
- nullptr, &Size));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
+ offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
+ nullptr, &Size));
}
TEST_F(offloadPlatformGetInfoTest, InvalidPlatformInfoEnumeration) {
size_t Size = 0;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_ENUMERATION,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_FORCE_UINT32,
- 0, nullptr, &Size));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
+ offloadPlatformGetInfo(Platform,
+ OFFLOAD_PLATFORM_INFO_FORCE_UINT32, 0,
+ nullptr, &Size));
}
TEST_F(offloadPlatformGetInfoTest, InvalidSizeZero) {
offload_platform_backend_t Backend;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
- &Backend, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ 0, &Backend, nullptr));
}
TEST_F(offloadPlatformGetInfoTest, InvalidSizeSmall) {
offload_platform_backend_t Backend;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_SIZE,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- sizeof(Backend) - 1, &Backend, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ sizeof(Backend) - 1, &Backend, nullptr));
}
TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropValue) {
offload_platform_backend_t Backend;
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- sizeof(Backend), nullptr, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), nullptr, nullptr));
}
TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropSizeRet) {
- ASSERT_EQ(OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
- nullptr, nullptr));
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
+ 0, nullptr, nullptr));
}
>From fb6d7758eba23e496507c09e5fc40628266c9aae Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 23 Oct 2024 16:48:53 +0100
Subject: [PATCH 11/14] Add optional code location entry point variants
---
offload/new-api/API/Common.td | 11 ++++
offload/new-api/include/offload_api.h | 50 +++++++++++++++++++
.../new-api/include/offload_entry_points.inc | 44 ++++++++++++++++
offload/new-api/src/offload_lib.cpp | 5 ++
offload/tools/offload-tblgen/APIGen.cpp | 22 ++++++++
.../tools/offload-tblgen/EntryPointGen.cpp | 23 +++++++++
6 files changed, 155 insertions(+)
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index f2fe4b672fbfe5..c956ea9014596e 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -89,3 +89,14 @@ def : Macro {
let desc = "Success condition";
let value = "NULL";
}
+
+def : Struct {
+ let name = "offload_code_location_t";
+ let desc = "Code location information that can optionally be associated with an API call";
+ let members = [
+ StructMember<"const char*", "FunctionName", "Function name">,
+ StructMember<"const char*", "SourceFile", "Source code file">,
+ StructMember<"uint32_t", "LineNumber", "Source code line number">,
+ StructMember<"uint32_t", "ColumnNumber", "Source code column number">
+ ];
+}
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index a4d72b9a36a7c7..2e827655f16e7a 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -129,6 +129,16 @@ typedef const offload_error_struct_t *offload_result_t;
#endif // !defined(OFFLOAD_SUCCESS)
#endif // OFFLOAD_SUCCESS
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Code location information that can optionally be associated with an
+/// API call
+typedef struct offload_code_location_t {
+ const char *FunctionName; /// Function name
+ const char *SourceFile; /// Source code file
+ uint32_t LineNumber; /// Source code line number
+ uint32_t ColumnNumber; /// Source code column number
+} offload_code_location_t;
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
///
@@ -397,6 +407,46 @@ typedef struct offload_device_get_info_params_t {
size_t **ppPropSizeRet;
} offload_device_get_info_params_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadPlatformGet that also sets source code location
+/// information
+/// @details See also ::offloadPlatformGet
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms,
+ offload_code_location_t *pCodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadPlatformGetInfo that also sets source code location
+/// information
+/// @details See also ::offloadPlatformGetInfo
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGetInfoWithCodeLoc(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t propSize, void *pPropValue,
+ size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadDeviceGet that also sets source code location
+/// information
+/// @details See also ::offloadDeviceGet
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetWithCodeLoc(
+ offload_platform_handle_t hPlatform, offload_device_type_t DeviceType,
+ uint32_t NumEntries, offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices, offload_code_location_t *pCodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadDeviceGetInfo that also sets source code location
+/// information
+/// @details See also ::offloadDeviceGetInfo
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t hDevice,
+ offload_device_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation);
+
#if defined(__cplusplus)
} // extern "C"
#endif
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index 0bdfabe7fefa9c..5c29f7cbe1ce44 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -40,6 +40,16 @@ offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
}
return result;
}
+offload_result_t offloadPlatformGetWithCodeLoc(
+ uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
+ uint32_t *pNumPlatforms, offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result =
+ offloadPlatformGet(NumEntries, phPlatforms, pNumPlatforms);
+
+ CodeLocation() = nullptr;
+ return result;
+}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
@@ -88,6 +98,17 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
}
return result;
}
+offload_result_t offloadPlatformGetInfoWithCodeLoc(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName,
+ size_t propSize, void *pPropValue, size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadPlatformGetInfo(
+ hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+
+ CodeLocation() = nullptr;
+ return result;
+}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
@@ -134,6 +155,17 @@ offloadDeviceGet(offload_platform_handle_t hPlatform,
}
return result;
}
+offload_result_t offloadDeviceGetWithCodeLoc(
+ offload_platform_handle_t hPlatform, offload_device_type_t DeviceType,
+ uint32_t NumEntries, offload_device_handle_t *phDevices,
+ uint32_t *pNumDevices, offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadDeviceGet(hPlatform, DeviceType, NumEntries,
+ phDevices, pNumDevices);
+
+ CodeLocation() = nullptr;
+ return result;
+}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
@@ -183,3 +215,15 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
}
return result;
}
+offload_result_t
+offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t hDevice,
+ offload_device_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadDeviceGetInfo(hDevice, propName, propSize,
+ pPropValue, pPropSizeRet);
+
+ CodeLocation() = nullptr;
+ return result;
+}
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index 7ad0ff1d6e35c3..2635152c0910a8 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -26,6 +26,11 @@ ErrSetT &Errors() {
return Errors;
}
+offload_code_location_t *&CodeLocation() {
+ thread_local offload_code_location_t *CodeLoc = nullptr;
+ return CodeLoc;
+}
+
// Pull in the declarations for the implementation funtions. The actual entry
// points in this file wrap these.
#include "offload_impl_func_decls.inc"
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index 9395f589952594..cd9fe54085f1a8 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -168,6 +168,24 @@ typedef struct {1} {{
OS << formatv("} {0};\n", Func.getParamStructName());
}
+static void ProcessFuncWithCodeLocVariant(const FunctionRec &Func,
+ raw_ostream &OS) {
+
+ auto FuncWithCodeLocBegin = R"(
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of {0} that also sets source code location information
+/// @details See also ::{0}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL {0}WithCodeLoc(
+)";
+ OS << formatv(FuncWithCodeLocBegin, Func.getName());
+ auto Params = Func.getParams();
+ for (auto &Param : Params) {
+ OS << " " << Param.getType() << " " << Param.getName();
+ OS << ",\n";
+ }
+ OS << "offload_code_location_t *pCodeLocation);\n\n";
+}
+
void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
OS << FileHeader;
@@ -193,5 +211,9 @@ void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
ProcessFuncParamStruct(FunctionRec{R}, OS);
}
+ for (auto *R : Records.getAllDerivedDefinitions("Function")) {
+ ProcessFuncWithCodeLocVariant(FunctionRec{R}, OS);
+ }
+
OS << FileFooter;
}
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index e36252e482c426..c5c823f68cb56e 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -102,10 +102,33 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
OS << "}\n";
}
+static void EmitCodeLocWrapper(const FunctionRec &F, raw_ostream &OS) {
+ // Emit preamble
+ OS << formatv("{0}_result_t {1}WithCodeLoc(\n ", PrefixLower, F.getName());
+ // Emit arguments
+ std::string ParamNameList = "";
+ for (auto &Param : F.getParams()) {
+ OS << Param.getType() << " " << Param.getName() << ", ";
+ ParamNameList += Param.getName().str();
+ if (Param != F.getParams().back()) {
+ ParamNameList += ", ";
+ }
+ }
+ OS << "offload_code_location_t *pCodeLocation";
+ OS << ") {\n";
+ OS << TAB_1 "CodeLocation() = pCodeLocation;\n";
+ OS << formatv(TAB_1 "{0}_result_t result = {1}({2});\n\n", PrefixLower,
+ F.getName(), ParamNameList);
+ OS << TAB_1 "CodeLocation() = nullptr;\n";
+ OS << TAB_1 "return result;\n";
+ OS << "}\n";
+}
+
void EmitOffloadEntryPoints(RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
EmitValidationFunc(FunctionRec{R}, OS);
EmitEntryPointFunc(FunctionRec{R}, OS);
+ EmitCodeLocWrapper(FunctionRec{R}, OS);
}
}
>From 55740e022772e3b315d51bd1a6b08641efa8b7e3 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 25 Oct 2024 10:10:23 +0100
Subject: [PATCH 12/14] Rework API to avoid multiple returns, add
init/shutdown, general refactor
---
offload/new-api/API/APIDefs.td | 6 +-
offload/new-api/API/Common.td | 25 +-
offload/new-api/API/Device.td | 66 +--
offload/new-api/API/Platform.td | 61 ++-
offload/new-api/include/offload_api.h | 321 +++++++++++----
.../new-api/include/offload_entry_points.inc | 388 ++++++++++++++----
offload/new-api/include/offload_exports | 6 +
offload/new-api/include/offload_funcs.inc | 6 +
offload/new-api/include/offload_impl.hpp | 2 +-
.../include/offload_impl_func_decls.inc | 32 +-
offload/new-api/include/offload_print.hpp | 52 ++-
offload/new-api/src/offload_impl.cpp | 116 ++++--
offload/tools/offload-tblgen/APIGen.cpp | 4 +
.../tools/offload-tblgen/EntryPointGen.cpp | 18 +-
offload/tools/offload-tblgen/FuncsGen.cpp | 12 +-
offload/tools/offload-tblgen/PrintGen.cpp | 8 +-
offload/unittests/OffloadAPI/CMakeLists.txt | 6 +-
.../OffloadAPI/common/environment.cpp | 21 +-
.../unittests/OffloadAPI/common/fixtures.hpp | 16 +-
.../OffloadAPI/device/offloadDeviceGet.cpp | 12 +-
.../device/offloadDeviceGetCount.cpp | 30 ++
.../device/offloadDeviceGetInfo.cpp | 49 +--
.../device/offloadDeviceGetInfoSize.cpp | 61 +++
.../OffloadAPI/device/offloadDeviceInfo.hpp | 22 +
.../platform/offloadPlatformGet.cpp | 12 +-
.../platform/offloadPlatformGetCount.cpp | 23 ++
.../platform/offloadPlatformGetInfo.cpp | 50 +--
.../platform/offloadPlatformGetInfoSize.cpp | 58 +++
.../platform/offloadPlatformInfo.hpp | 21 +
29 files changed, 1118 insertions(+), 386 deletions(-)
create mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
create mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
create mode 100644 offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp
create mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
create mode 100644 offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp
diff --git a/offload/new-api/API/APIDefs.td b/offload/new-api/API/APIDefs.td
index a74332363369ac..64785217b48849 100644
--- a/offload/new-api/API/APIDefs.td
+++ b/offload/new-api/API/APIDefs.td
@@ -125,10 +125,10 @@ class AddPointerChecksToReturns<list<Param> Params, list<Return> Returns> {
// Does the list of returns already contain ERROR_INVALID_NULL_POINTER?
bit returns_has_inv_ptr = !foldl(
0, Returns, HasErr, Ret,
- !or(HasErr, !eq(Ret.value, PREFIX#"_ERROR_CODE_INVALID_NULL_POINTER")));
+ !or(HasErr, !eq(Ret.value, PREFIX#"_ERRC_INVALID_NULL_POINTER")));
list<Return> returns_out = !if(returns_has_inv_ptr,
- AppendConditionsToReturn<Returns, PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>.ret,
- !listconcat(Returns, [Return<PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>])
+ AppendConditionsToReturn<Returns, PREFIX # "_ERRC_INVALID_NULL_POINTER", ptr_param_conds>.ret,
+ !listconcat(Returns, [Return<PREFIX # "_ERRC_INVALID_NULL_POINTER", ptr_param_conds>])
);
}
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index c956ea9014596e..c2f03bbc0ae355 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -84,8 +84,7 @@ def : Typedef {
}
def : Macro {
- let name = "OFFLOAD_SUCCESS";
- let condition = "!defined(OFFLOAD_SUCCESS)";
+ let name = "OFFLOAD_RESULT_SUCCESS";
let desc = "Success condition";
let value = "NULL";
}
@@ -100,3 +99,25 @@ def : Struct {
StructMember<"uint32_t", "ColumnNumber", "Source code column number">
];
}
+
+def : Function {
+ let name = "offloadInit";
+ let desc = "Perform initialization of the Offload library and plugins";
+ let details = [
+ "This must be the first API call made by a user of the Offload library",
+ "Each call will increment an internal reference count that is decremented by `offloadShutDown`"
+ ];
+ let params = [];
+ let returns = [];
+}
+
+def : Function {
+ let name = "offloadShutDown";
+ let desc = "Release the resources in use by Offload";
+ let details = [
+ "This decrements an internal reference count. When this reaches 0, all resources will be released",
+ "Subsequent API calls made after this are not valid"
+ ];
+ let params = [];
+ let returns = [];
+}
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index da1141cf1986e0..2700f3c9f639f9 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -34,41 +34,40 @@ def : Enum {
];
}
+def : Function {
+ let name = "offloadDeviceGetCount";
+ let desc = "Retrieves the number of available devices within a platform";
+ let params = [
+ Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
+ Param<"uint32_t*", "pNumDevices", "pointer to the number of devices.", PARAM_OUT>
+ ];
+ let returns = [];
+}
+
def : Function {
let name = "offloadDeviceGet";
let desc = "Retrieves devices within a platform";
let details = [
"Multiple calls to this function will return identical device handles, in the same order.",
- "The number and order of handles returned from this function can be affected by environment variables that filter devices exposed through API.",
- "The returned devices are taken a reference of and must be released with a subsequent call to olDeviceRelease.",
"The application may call this function from simultaneous threads, the implementation must be thread-safe"
];
let params = [
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
- Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
- Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices. "
- "If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_ERRC_INVALID_SIZE "
- "will be returned.", PARAM_IN>,
+ Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices, which must be greater than zero", PARAM_IN>,
RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
- "If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
- Range<"0", "NumEntries">>,
- Param<"uint32_t*", "pNumDevices", "pointer to the number of devices. "
- "pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
+ "If NumEntries is less than the number of devices available, then this function shall only retrieve that number of devices.", PARAM_OUT,
+ Range<"0", "NumEntries">>
];
let returns = [
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`NumEntries == 0 && phDevices != NULL`"
- ]>,
- Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
- "`NumEntries > 0 && phDevices == NULL`"
- ]>,
- Return<"OFFLOAD_ERRC_INVALID_VALUE">
+ "`NumEntries == 0`"
+ ]>
];
}
def : Function {
let name = "offloadDeviceGetInfo";
- let desc = "Retrieves various information about device";
+ let desc = "Queries the given property of the device";
let details = [
"The application may call this function from simultaneous threads.",
"The implementation of this function should be lock-free."
@@ -79,23 +78,36 @@ def : Function {
Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
"number of bytes needed to return the info then the OFFLOAD_ERRC_INVALID_SIZE error is returned and "
- "pPropValue is not used.", PARAM_OUT_OPTIONAL, TypeInfo<"propName" , "propSize">>,
- Param<"size_t*", "pPropSizeRet", "pointer to the actual size in bytes of the queried propName.", PARAM_OUT_OPTIONAL>
+ "pPropValue is not used.", PARAM_OUT, TypeInfo<"propName" , "propSize">>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
- "If `propName` is not supported by the adapter."
+ "If `propName` is not supported by the device."
]>,
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`propSize == 0 && pPropValue != NULL`",
+ "`propSize == 0`",
"If `propSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
- "`propSize != 0 && pPropValue == NULL`",
- "`pPropValue == NULL && pPropSizeRet == NULL`"
+ Return<"OFFLOAD_ERRC_INVALID_DEVICE">
+ ];
+}
+
+def : Function {
+ let name = "offloadDeviceGetInfoSize";
+ let desc = "Returns the storage size of the given device query";
+ let details = [
+ "The application may call this function from simultaneous threads.",
+ "The implementation of this function should be lock-free."
+ ];
+ let params = [
+ Param<"offload_device_handle_t", "hDevice", "handle of the device instance", PARAM_IN>,
+ Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
+ ];
+ let returns = [
+ Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
+ "If `propName` is not supported by the device."
]>,
- Return<"OFFLOAD_ERRC_INVALID_DEVICE">,
- Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
- Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
+ Return<"OFFLOAD_ERRC_INVALID_DEVICE">
];
}
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index 0bfcbdce8d2d5c..564bea017cab9e 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -17,25 +17,33 @@ def : Function {
];
let params = [
Param<"uint32_t", "NumEntries",
- "The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then "
- "NumEntries should be greater than zero, otherwise OFFLOAD_ERRC_INVALID_SIZE "
- "will be returned.", PARAM_IN>,
+ "The number of platforms to be added to phPlatforms. NumEntries must be "
+ "greater than zero.",
+ PARAM_IN>,
RangedParam<"offload_platform_handle_t*", "phPlatforms",
"Array of handle of platforms. If NumEntries is less than the number of "
"platforms available, then offloadPlatformGet shall only retrieve that "
"number of platforms.",
- PARAM_OUT_OPTIONAL, Range<"0", "NumEntries">>,
- Param<"uint32_t*",
- "pNumPlatforms", "returns the total number of platforms available.",
- PARAM_OUT_OPTIONAL>
+ PARAM_OUT, Range<"0", "NumEntries">>
];
let returns = [
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`NumEntries == 0 && phPlatforms != NULL`"
+ "`NumEntries == 0`"
]>
];
}
+def : Function {
+ let name = "offloadPlatformGetCount";
+ let desc = "Retrieves the number of available platforms";
+ let params = [
+ Param<"uint32_t*",
+ "pNumPlatforms", "returns the total number of platforms available.",
+ PARAM_OUT>
+ ];
+ let returns = [];
+}
+
def : Enum {
let name = "offload_platform_info_t";
let desc = "Supported platform info";
@@ -60,8 +68,10 @@ def : Enum {
def : Function {
let name = "offloadPlatformGetInfo";
- let desc = "Retrieves various information about platform";
+ let desc = "Queries the given property of the platform";
let details = [
+ "`offloadPlatformGetInfoSize` can be used to query the storage size "
+ "required for the given query."
"The application may call this function from simultaneous threads.",
"The implementation of this function should be lock-free."
];
@@ -71,24 +81,37 @@ def : Function {
Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
"If Size is not equal to or greater to the real number of bytes needed to return the info "
- "then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
- TypeInfo<"propName" , "propSize">>,
- Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
+ "then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,
+ TypeInfo<"propName" , "propSize">>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
"If `propName` is not supported by the platform."
]>,
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`propSize == 0 && pPropValue != NULL`",
+ "`propSize == 0`",
"If `propSize` is less than the real number of bytes needed to return the info."
]>,
- Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
- "`propSize != 0 && pPropValue == NULL`",
- "`pPropValue == NULL && pPropSizeRet == NULL`"
+ Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
+ ];
+}
+
+def : Function {
+ let name = "offloadPlatformGetInfoSize";
+ let desc = "Returns the storage size of the given platform query";
+ let details = [
+ "The application may call this function from simultaneous threads.",
+ "The implementation of this function should be lock-free."
+ ];
+ let params = [
+ Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
+ Param<"offload_platform_info_t", "propName", "type of the info to query", PARAM_IN>,
+ Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
+ ];
+ let returns = [
+ Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
+ "If `propName` is not supported by the platform."
]>,
- Return<"OFFLOAD_ERRC_INVALID_PLATFORM">,
- Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
- Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
+ Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
];
}
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 2e827655f16e7a..4816abc22fd0b4 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -122,12 +122,10 @@ typedef struct offload_error_struct_t {
typedef const offload_error_struct_t *offload_result_t;
///////////////////////////////////////////////////////////////////////////////
-#ifndef OFFLOAD_SUCCESS
-#if !defined(OFFLOAD_SUCCESS)
+#ifndef OFFLOAD_RESULT_SUCCESS
/// @brief Success condition
-#define OFFLOAD_SUCCESS NULL
-#endif // !defined(OFFLOAD_SUCCESS)
-#endif // OFFLOAD_SUCCESS
+#define OFFLOAD_RESULT_SUCCESS NULL
+#endif // OFFLOAD_RESULT_SUCCESS
///////////////////////////////////////////////////////////////////////////////
/// @brief Code location information that can optionally be associated with an
@@ -139,6 +137,38 @@ typedef struct offload_code_location_t {
uint32_t ColumnNumber; /// Source code column number
} offload_code_location_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Perform initialization of the Offload library and plugins
+///
+/// @details
+/// - This must be the first API call made by a user of the Offload library
+/// - Each call will increment an internal reference count that is
+/// decremented by `offloadShutDown`
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit();
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Release the resources in use by Offload
+///
+/// @details
+/// - This decrements an internal reference count. When this reaches 0, all
+/// resources will be released
+/// - Subsequent API calls made after this are not valid
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves all available platforms
///
@@ -151,19 +181,33 @@ typedef struct offload_code_location_t {
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `NumEntries == 0 && phPlatforms != NULL`
+/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == phPlatforms`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- // [in] The number of platforms to be added to phPlatforms. If phPlatforms
- // is not NULL, then NumEntries should be greater than zero, otherwise
- // OFFLOAD_ERRC_INVALID_SIZE will be returned.
+ // [in] The number of platforms to be added to phPlatforms. NumEntries must
+ // be greater than zero.
uint32_t NumEntries,
- // [out][optional] Array of handle of platforms. If NumEntries is less than
- // the number of platforms available, then offloadPlatformGet shall only
- // retrieve that number of platforms.
- offload_platform_handle_t *phPlatforms,
- // [out][optional] returns the total number of platforms available.
+ // [out] Array of handle of platforms. If NumEntries is less than the number
+ // of platforms available, then offloadPlatformGet shall only retrieve that
+ // number of platforms.
+ offload_platform_handle_t *phPlatforms);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves the number of available platforms
+///
+/// @details
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pNumPlatforms`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetCount(
+ // [out] returns the total number of platforms available.
uint32_t *pNumPlatforms);
///////////////////////////////////////////////////////////////////////////////
@@ -203,10 +247,12 @@ typedef enum offload_platform_backend_t {
} offload_platform_backend_t;
///////////////////////////////////////////////////////////////////////////////
-/// @brief Retrieves various information about platform
+/// @brief Queries the given property of the platform
///
/// @details
-/// - The application may call this function from simultaneous threads.
+/// - `offloadPlatformGetInfoSize` can be used to query the storage size
+/// required for the given query.The application may call this function from
+/// simultaneous threads.
/// - The implementation of this function should be lock-free.
///
/// @returns
@@ -216,18 +262,14 @@ typedef enum offload_platform_backend_t {
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the platform.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `propSize == 0 && pPropValue != NULL`
+/// + `propSize == 0`
/// + If `propSize` is less than the real number of bytes needed to
/// return the info.
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `propSize != 0 && pPropValue == NULL`
-/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
-/// - ::OFFLOAD_ERRC_OUT_OF_RESOURCES
-/// - ::OFFLOAD_ERRC_OUT_OF_HOST_MEMORY
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
-/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pPropValue`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
// [in] handle of the platform
offload_platform_handle_t hPlatform,
@@ -235,13 +277,36 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
offload_platform_info_t propName,
// [in] the number of bytes pointed to by pPlatformInfo.
size_t propSize,
- // [out][optional] array of bytes holding the info. If Size is not equal to
- // or greater to the real number of bytes needed to return the info then the
+ // [out] array of bytes holding the info. If Size is not equal to or greater
+ // to the real number of bytes needed to return the info then the
// OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not
// used.
- void *pPropValue,
- // [out][optional] pointer to the actual number of bytes being queried by
- // pPlatformInfo.
+ void *pPropValue);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Returns the storage size of the given platform query
+///
+/// @details
+/// - The application may call this function from simultaneous threads.
+/// - The implementation of this function should be lock-free.
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// + If `propName` is not supported by the platform.
+/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// + `NULL == hPlatform`
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pPropSizeRet`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
+ // [in] handle of the platform
+ offload_platform_handle_t hPlatform,
+ // [in] type of the info to query
+ offload_platform_info_t propName,
+ // [out] pointer to the number of bytes required to store the query
size_t *pPropSizeRet);
///////////////////////////////////////////////////////////////////////////////
@@ -280,17 +345,31 @@ typedef enum offload_device_info_t {
} offload_device_info_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Retrieves the number of available devices within a platform
+///
+/// @details
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// + `NULL == hPlatform`
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pNumDevices`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
+ // [in] handle of the platform instance
+ offload_platform_handle_t hPlatform,
+ // [out] pointer to the number of devices.
+ uint32_t *pNumDevices);
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves devices within a platform
///
/// @details
/// - Multiple calls to this function will return identical device handles,
/// in the same order.
-/// - The number and order of handles returned from this function can be
-/// affected by environment variables that filter devices exposed through
-/// API.
-/// - The returned devices are taken a reference of and must be released with
-/// a subsequent call to olDeviceRelease.
/// - The application may call this function from simultaneous threads, the
/// implementation must be thread-safe
///
@@ -299,32 +378,24 @@ typedef enum offload_device_info_t {
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `NumEntries == 0 && phDevices != NULL`
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NumEntries > 0 && phDevices == NULL`
-/// - ::OFFLOAD_ERRC_INVALID_VALUE
+/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hPlatform`
-/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == phDevices`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
// [in] handle of the platform instance
offload_platform_handle_t hPlatform,
- // [in] the type of the devices.
- offload_device_type_t DeviceType,
- // [in] the number of devices to be added to phDevices. If phDevices is not
- // NULL, then NumEntries should be greater than zero. Otherwise
- // OFFLOAD_ERRC_INVALID_SIZE will be returned.
+ // [in] the number of devices to be added to phDevices, which must be
+ // greater than zero
uint32_t NumEntries,
- // [out][optional] Array of device handles. If NumEntries is less than the
- // number of devices available, then platform shall only retrieve that
- // number of devices.
- offload_device_handle_t *phDevices,
- // [out][optional] pointer to the number of devices. pNumDevices will be
- // updated with the total number of devices available.
- uint32_t *pNumDevices);
+ // [out] Array of device handles. If NumEntries is less than the number of
+ // devices available, then this function shall only retrieve that number of
+ // devices.
+ offload_device_handle_t *phDevices);
///////////////////////////////////////////////////////////////////////////////
-/// @brief Retrieves various information about device
+/// @brief Queries the given property of the device
///
/// @details
/// - The application may call this function from simultaneous threads.
@@ -335,20 +406,16 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
-/// + If `propName` is not supported by the adapter.
+/// + If `propName` is not supported by the device.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `propSize == 0 && pPropValue != NULL`
+/// + `propSize == 0`
/// + If `propSize` is less than the real number of bytes needed to
/// return the info.
-/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `propSize != 0 && pPropValue == NULL`
-/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::OFFLOAD_ERRC_INVALID_DEVICE
-/// - ::OFFLOAD_ERRC_OUT_OF_RESOURCES
-/// - ::OFFLOAD_ERRC_OUT_OF_HOST_MEMORY
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// + `NULL == hDevice`
-/// - ::OFFLOAD_ERROR_CODE_INVALID_NULL_POINTER
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pPropValue`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
// [in] handle of the device instance
offload_device_handle_t hDevice,
@@ -356,13 +423,35 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
offload_device_info_t propName,
// [in] the number of bytes pointed to by pPropValue.
size_t propSize,
- // [out][optional] array of bytes holding the info. If propSize is not equal
- // to or greater than the real number of bytes needed to return the info
- // then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPropValue is
- // not used.
- void *pPropValue,
- // [out][optional] pointer to the actual size in bytes of the queried
- // propName.
+ // [out] array of bytes holding the info. If propSize is not equal to or
+ // greater than the real number of bytes needed to return the info then the
+ // OFFLOAD_ERRC_INVALID_SIZE error is returned and pPropValue is not used.
+ void *pPropValue);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Returns the storage size of the given device query
+///
+/// @details
+/// - The application may call this function from simultaneous threads.
+/// - The implementation of this function should be lock-free.
+///
+/// @returns
+/// - ::OFFLOAD_RESULT_SUCCESS
+/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
+/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
+/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
+/// + If `propName` is not supported by the device.
+/// - ::OFFLOAD_ERRC_INVALID_DEVICE
+/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
+/// + `NULL == hDevice`
+/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
+/// + `NULL == pPropSizeRet`
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfoSize(
+ // [in] handle of the device instance
+ offload_device_handle_t hDevice,
+ // [in] type of the info to retrieve
+ offload_device_info_t propName,
+ // [out] pointer to the number of bytes required to store the query
size_t *pPropSizeRet);
///////////////////////////////////////////////////////////////////////////////
@@ -371,9 +460,15 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
typedef struct offload_platform_get_params_t {
uint32_t *pNumEntries;
offload_platform_handle_t **pphPlatforms;
- uint32_t **ppNumPlatforms;
} offload_platform_get_params_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadPlatformGetCount
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_platform_get_count_params_t {
+ uint32_t **ppNumPlatforms;
+} offload_platform_get_count_params_t;
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGetInfo
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -382,18 +477,32 @@ typedef struct offload_platform_get_info_params_t {
offload_platform_info_t *ppropName;
size_t *ppropSize;
void **ppPropValue;
- size_t **ppPropSizeRet;
} offload_platform_get_info_params_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadPlatformGetInfoSize
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_platform_get_info_size_params_t {
+ offload_platform_handle_t *phPlatform;
+ offload_platform_info_t *ppropName;
+ size_t **ppPropSizeRet;
+} offload_platform_get_info_size_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadDeviceGetCount
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_device_get_count_params_t {
+ offload_platform_handle_t *phPlatform;
+ uint32_t **ppNumDevices;
+} offload_device_get_count_params_t;
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGet
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_params_t {
offload_platform_handle_t *phPlatform;
- offload_device_type_t *pDeviceType;
uint32_t *pNumEntries;
offload_device_handle_t **pphDevices;
- uint32_t **ppNumDevices;
} offload_device_get_params_t;
///////////////////////////////////////////////////////////////////////////////
@@ -404,9 +513,31 @@ typedef struct offload_device_get_info_params_t {
offload_device_info_t *ppropName;
size_t *ppropSize;
void **ppPropValue;
- size_t **ppPropSizeRet;
} offload_device_get_info_params_t;
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Function parameters for offloadDeviceGetInfoSize
+/// @details Each entry is a pointer to the parameter passed to the function;
+typedef struct offload_device_get_info_size_params_t {
+ offload_device_handle_t *phDevice;
+ offload_device_info_t *ppropName;
+ size_t **ppPropSizeRet;
+} offload_device_get_info_size_params_t;
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadInit that also sets source code location
+/// information
+/// @details See also ::offloadInit
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadInitWithCodeLoc(offload_code_location_t *pCodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadShutDown that also sets source code location
+/// information
+/// @details See also ::offloadShutDown
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadShutDownWithCodeLoc(offload_code_location_t *pCodeLocation);
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGet that also sets source code location
/// information
@@ -414,9 +545,16 @@ typedef struct offload_device_get_info_params_t {
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms,
offload_code_location_t *pCodeLocation);
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadPlatformGetCount that also sets source code
+/// location information
+/// @details See also ::offloadPlatformGetCount
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGetCountWithCodeLoc(uint32_t *pNumPlatforms,
+ offload_code_location_t *pCodeLocation);
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGetInfo that also sets source code location
/// information
@@ -425,17 +563,34 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadPlatformGetInfoWithCodeLoc(offload_platform_handle_t hPlatform,
offload_platform_info_t propName,
size_t propSize, void *pPropValue,
- size_t *pPropSizeRet,
offload_code_location_t *pCodeLocation);
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadPlatformGetInfoSize that also sets source code
+/// location information
+/// @details See also ::offloadPlatformGetInfoSize
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGetInfoSizeWithCodeLoc(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation);
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadDeviceGetCount that also sets source code location
+/// information
+/// @details See also ::offloadDeviceGetCount
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t hPlatform,
+ uint32_t *pNumDevices,
+ offload_code_location_t *pCodeLocation);
+
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGet that also sets source code location
/// information
/// @details See also ::offloadDeviceGet
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetWithCodeLoc(
- offload_platform_handle_t hPlatform, offload_device_type_t DeviceType,
- uint32_t NumEntries, offload_device_handle_t *phDevices,
- uint32_t *pNumDevices, offload_code_location_t *pCodeLocation);
+ offload_platform_handle_t hPlatform, uint32_t NumEntries,
+ offload_device_handle_t *phDevices, offload_code_location_t *pCodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGetInfo that also sets source code location
@@ -444,9 +599,19 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetWithCodeLoc(
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t hDevice,
offload_device_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet,
+ void *pPropValue,
offload_code_location_t *pCodeLocation);
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Variant of offloadDeviceGetInfoSize that also sets source code
+/// location information
+/// @details See also ::offloadDeviceGetInfoSize
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadDeviceGetInfoSizeWithCodeLoc(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t *pPropSizeRet,
+ offload_code_location_t *pCodeLocation);
+
#if defined(__cplusplus)
} // extern "C"
#endif
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index 5c29f7cbe1ce44..cecc4699fb6646 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -6,32 +6,96 @@
//
//===----------------------------------------------------------------------===//
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t offloadInit_val() {
+ if (true /*enableParameterValidation*/) {
+ }
+
+ return offloadInit_impl();
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadInit";
+ }
+
+ offload_result_t result = offloadInit_val();
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "()";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t
+offloadInitWithCodeLoc(offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadInit();
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t offloadShutDown_val() {
+ if (true /*enableParameterValidation*/) {
+ }
+
+ return offloadShutDown_impl();
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadShutDown";
+ }
+
+ offload_result_t result = offloadShutDown_val();
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "()";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t
+offloadShutDownWithCodeLoc(offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadShutDown();
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
offloadPlatformGet_val(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms) {
+ offload_platform_handle_t *phPlatforms) {
if (true /*enableParameterValidation*/) {
- if (NumEntries == 0 && phPlatforms != NULL) {
+ if (NumEntries == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
+
+ if (NULL == phPlatforms) {
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ }
}
- return offloadPlatformGet_impl(NumEntries, phPlatforms, pNumPlatforms);
+ return offloadPlatformGet_impl(NumEntries, phPlatforms);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms) {
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
+ uint32_t NumEntries, offload_platform_handle_t *phPlatforms) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGet";
}
- offload_result_t result =
- offloadPlatformGet_val(NumEntries, phPlatforms, pNumPlatforms);
+ offload_result_t result = offloadPlatformGet_val(NumEntries, phPlatforms);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_params_t Params = {&NumEntries, &phPlatforms,
- &pNumPlatforms};
+ offload_platform_get_params_t Params = {&NumEntries, &phPlatforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result && result->details) {
@@ -40,12 +104,50 @@ offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
}
return result;
}
-offload_result_t offloadPlatformGetWithCodeLoc(
- uint32_t NumEntries, offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms, offload_code_location_t *pCodeLocation) {
+offload_result_t
+offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms,
+ offload_code_location_t *pCodeLocation) {
CodeLocation() = pCodeLocation;
- offload_result_t result =
- offloadPlatformGet(NumEntries, phPlatforms, pNumPlatforms);
+ offload_result_t result = offloadPlatformGet(NumEntries, phPlatforms);
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t offloadPlatformGetCount_val(uint32_t *pNumPlatforms) {
+ if (true /*enableParameterValidation*/) {
+ if (NULL == pNumPlatforms) {
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ }
+ }
+
+ return offloadPlatformGetCount_impl(pNumPlatforms);
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGetCount(uint32_t *pNumPlatforms) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadPlatformGetCount";
+ }
+
+ offload_result_t result = offloadPlatformGetCount_val(pNumPlatforms);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_platform_get_count_params_t Params = {&pNumPlatforms};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t
+offloadPlatformGetCountWithCodeLoc(uint32_t *pNumPlatforms,
+ offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadPlatformGetCount(pNumPlatforms);
CodeLocation() = nullptr;
return result;
@@ -55,41 +157,85 @@ offload_result_t offloadPlatformGetWithCodeLoc(
offload_impl_result_t
offloadPlatformGetInfo_val(offload_platform_handle_t hPlatform,
offload_platform_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet) {
+ void *pPropValue) {
if (true /*enableParameterValidation*/) {
- if (propSize == 0 && pPropValue != NULL) {
+ if (propSize == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (propSize != 0 && pPropValue == NULL) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ if (NULL == hPlatform) {
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (pPropValue == NULL && pPropSizeRet == NULL) {
+ if (NULL == pPropValue) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
+ }
+
+ return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue);
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName,
+ size_t propSize, void *pPropValue) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadPlatformGetInfo";
+ }
+
+ offload_result_t result =
+ offloadPlatformGetInfo_val(hPlatform, propName, propSize, pPropValue);
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_platform_get_info_params_t Params = {&hPlatform, &propName,
+ &propSize, &pPropValue};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t offloadPlatformGetInfoWithCodeLoc(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName,
+ size_t propSize, void *pPropValue, offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result =
+ offloadPlatformGetInfo(hPlatform, propName, propSize, pPropValue);
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t
+offloadPlatformGetInfoSize_val(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t *pPropSizeRet) {
+ if (true /*enableParameterValidation*/) {
if (NULL == hPlatform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
+
+ if (NULL == pPropSizeRet) {
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ }
}
- return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue,
- pPropSizeRet);
+ return offloadPlatformGetInfoSize_impl(hPlatform, propName, pPropSizeRet);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
+ size_t *pPropSizeRet) {
if (std::getenv("OFFLOAD_TRACE")) {
- std::cout << "---> offloadPlatformGetInfo";
+ std::cout << "---> offloadPlatformGetInfoSize";
}
- offload_result_t result = offloadPlatformGetInfo_val(
- hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+ offload_result_t result =
+ offloadPlatformGetInfoSize_val(hPlatform, propName, pPropSizeRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_info_params_t Params = {
- &hPlatform, &propName, &propSize, &pPropValue, &pPropSizeRet};
+ offload_platform_get_info_size_params_t Params = {&hPlatform, &propName,
+ &pPropSizeRet};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result && result->details) {
@@ -98,55 +244,94 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
}
return result;
}
-offload_result_t offloadPlatformGetInfoWithCodeLoc(
+offload_result_t offloadPlatformGetInfoSizeWithCodeLoc(
offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t propSize, void *pPropValue, size_t *pPropSizeRet,
- offload_code_location_t *pCodeLocation) {
+ size_t *pPropSizeRet, offload_code_location_t *pCodeLocation) {
CodeLocation() = pCodeLocation;
- offload_result_t result = offloadPlatformGetInfo(
- hPlatform, propName, propSize, pPropValue, pPropSizeRet);
+ offload_result_t result =
+ offloadPlatformGetInfoSize(hPlatform, propName, pPropSizeRet);
CodeLocation() = nullptr;
return result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
- offload_device_type_t DeviceType,
- uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- uint32_t *pNumDevices) {
+offload_impl_result_t
+offloadDeviceGetCount_val(offload_platform_handle_t hPlatform,
+ uint32_t *pNumDevices) {
if (true /*enableParameterValidation*/) {
- if (NumEntries == 0 && phDevices != NULL) {
- return OFFLOAD_ERRC_INVALID_SIZE;
+ if (NULL == hPlatform) {
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NumEntries > 0 && phDevices == NULL) {
+ if (NULL == pNumDevices) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
+ }
+
+ return offloadDeviceGetCount_impl(hPlatform, pNumDevices);
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
+ offload_platform_handle_t hPlatform, uint32_t *pNumDevices) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadDeviceGetCount";
+ }
+
+ offload_result_t result = offloadDeviceGetCount_val(hPlatform, pNumDevices);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_device_get_count_params_t Params = {&hPlatform, &pNumDevices};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t
+offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t hPlatform,
+ uint32_t *pNumDevices,
+ offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result = offloadDeviceGetCount(hPlatform, pNumDevices);
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices) {
+ if (true /*enableParameterValidation*/) {
+ if (NumEntries == 0) {
+ return OFFLOAD_ERRC_INVALID_SIZE;
+ }
if (NULL == hPlatform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
+
+ if (NULL == phDevices) {
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ }
}
- return offloadDeviceGet_impl(hPlatform, DeviceType, NumEntries, phDevices,
- pNumDevices);
+ return offloadDeviceGet_impl(hPlatform, NumEntries, phDevices);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGet(offload_platform_handle_t hPlatform,
- offload_device_type_t DeviceType, uint32_t NumEntries,
- offload_device_handle_t *phDevices, uint32_t *pNumDevices) {
+offloadDeviceGet(offload_platform_handle_t hPlatform, uint32_t NumEntries,
+ offload_device_handle_t *phDevices) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGet";
}
- offload_result_t result = offloadDeviceGet_val(
- hPlatform, DeviceType, NumEntries, phDevices, pNumDevices);
+ offload_result_t result =
+ offloadDeviceGet_val(hPlatform, NumEntries, phDevices);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_params_t Params = {&hPlatform, &DeviceType, &NumEntries,
- &phDevices, &pNumDevices};
+ offload_device_get_params_t Params = {&hPlatform, &NumEntries, &phDevices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result && result->details) {
@@ -155,13 +340,13 @@ offloadDeviceGet(offload_platform_handle_t hPlatform,
}
return result;
}
-offload_result_t offloadDeviceGetWithCodeLoc(
- offload_platform_handle_t hPlatform, offload_device_type_t DeviceType,
- uint32_t NumEntries, offload_device_handle_t *phDevices,
- uint32_t *pNumDevices, offload_code_location_t *pCodeLocation) {
+offload_result_t
+offloadDeviceGetWithCodeLoc(offload_platform_handle_t hPlatform,
+ uint32_t NumEntries,
+ offload_device_handle_t *phDevices,
+ offload_code_location_t *pCodeLocation) {
CodeLocation() = pCodeLocation;
- offload_result_t result = offloadDeviceGet(hPlatform, DeviceType, NumEntries,
- phDevices, pNumDevices);
+ offload_result_t result = offloadDeviceGet(hPlatform, NumEntries, phDevices);
CodeLocation() = nullptr;
return result;
@@ -171,42 +356,36 @@ offload_result_t offloadDeviceGetWithCodeLoc(
offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
offload_device_info_t propName,
size_t propSize,
- void *pPropValue,
- size_t *pPropSizeRet) {
+ void *pPropValue) {
if (true /*enableParameterValidation*/) {
- if (propSize == 0 && pPropValue != NULL) {
+ if (propSize == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (propSize != 0 && pPropValue == NULL) {
- return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ if (NULL == hDevice) {
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (pPropValue == NULL && pPropSizeRet == NULL) {
+ if (NULL == pPropValue) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
-
- if (NULL == hDevice) {
- return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
- }
}
- return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue,
- pPropSizeRet);
+ return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
offload_device_handle_t hDevice, offload_device_info_t propName,
- size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
+ size_t propSize, void *pPropValue) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGetInfo";
}
- offload_result_t result = offloadDeviceGetInfo_val(
- hDevice, propName, propSize, pPropValue, pPropSizeRet);
+ offload_result_t result =
+ offloadDeviceGetInfo_val(hDevice, propName, propSize, pPropValue);
if (std::getenv("OFFLOAD_TRACE")) {
offload_device_get_info_params_t Params = {&hDevice, &propName, &propSize,
- &pPropValue, &pPropSizeRet};
+ &pPropValue};
std::cout << "(" << &Params << ")";
std::cout << "-> " << result << "\n";
if (result && result->details) {
@@ -215,14 +394,61 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
}
return result;
}
-offload_result_t
-offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t hDevice,
- offload_device_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet,
- offload_code_location_t *pCodeLocation) {
+offload_result_t offloadDeviceGetInfoWithCodeLoc(
+ offload_device_handle_t hDevice, offload_device_info_t propName,
+ size_t propSize, void *pPropValue, offload_code_location_t *pCodeLocation) {
+ CodeLocation() = pCodeLocation;
+ offload_result_t result =
+ offloadDeviceGetInfo(hDevice, propName, propSize, pPropValue);
+
+ CodeLocation() = nullptr;
+ return result;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+offload_impl_result_t
+offloadDeviceGetInfoSize_val(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t *pPropSizeRet) {
+ if (true /*enableParameterValidation*/) {
+ if (NULL == hDevice) {
+ return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
+ }
+
+ if (NULL == pPropSizeRet) {
+ return OFFLOAD_ERRC_INVALID_NULL_POINTER;
+ }
+ }
+
+ return offloadDeviceGetInfoSize_impl(hDevice, propName, pPropSizeRet);
+}
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadDeviceGetInfoSize(offload_device_handle_t hDevice,
+ offload_device_info_t propName, size_t *pPropSizeRet) {
+ if (std::getenv("OFFLOAD_TRACE")) {
+ std::cout << "---> offloadDeviceGetInfoSize";
+ }
+
+ offload_result_t result =
+ offloadDeviceGetInfoSize_val(hDevice, propName, pPropSizeRet);
+
+ if (std::getenv("OFFLOAD_TRACE")) {
+ offload_device_get_info_size_params_t Params = {&hDevice, &propName,
+ &pPropSizeRet};
+ std::cout << "(" << &Params << ")";
+ std::cout << "-> " << result << "\n";
+ if (result && result->details) {
+ std::cout << " *Error Details* " << result->details << " \n";
+ }
+ }
+ return result;
+}
+offload_result_t offloadDeviceGetInfoSizeWithCodeLoc(
+ offload_device_handle_t hDevice, offload_device_info_t propName,
+ size_t *pPropSizeRet, offload_code_location_t *pCodeLocation) {
CodeLocation() = pCodeLocation;
- offload_result_t result = offloadDeviceGetInfo(hDevice, propName, propSize,
- pPropValue, pPropSizeRet);
+ offload_result_t result =
+ offloadDeviceGetInfoSize(hDevice, propName, pPropSizeRet);
CodeLocation() = nullptr;
return result;
diff --git a/offload/new-api/include/offload_exports b/offload/new-api/include/offload_exports
index cb256fd34770d5..3a2e9adf1340c6 100644
--- a/offload/new-api/include/offload_exports
+++ b/offload/new-api/include/offload_exports
@@ -1,9 +1,15 @@
VERS1.0 {
global:
+ offloadInit;
+ offloadShutDown;
offloadPlatformGet;
+ offloadPlatformGetCount;
offloadPlatformGetInfo;
+ offloadPlatformGetInfoSize;
+ offloadDeviceGetCount;
offloadDeviceGet;
offloadDeviceGetInfo;
+ offloadDeviceGetInfoSize;
local:
*;
};
diff --git a/offload/new-api/include/offload_funcs.inc b/offload/new-api/include/offload_funcs.inc
index 14e878b9ed5a27..2b062b9f69cb4e 100644
--- a/offload/new-api/include/offload_funcs.inc
+++ b/offload/new-api/include/offload_funcs.inc
@@ -10,9 +10,15 @@
#error Please define the macro OFFLOAD_FUNC(Function)
#endif
+OFFLOAD_FUNC(offloadInit)
+OFFLOAD_FUNC(offloadShutDown)
OFFLOAD_FUNC(offloadPlatformGet)
+OFFLOAD_FUNC(offloadPlatformGetCount)
OFFLOAD_FUNC(offloadPlatformGetInfo)
+OFFLOAD_FUNC(offloadPlatformGetInfoSize)
+OFFLOAD_FUNC(offloadDeviceGetCount)
OFFLOAD_FUNC(offloadDeviceGet)
OFFLOAD_FUNC(offloadDeviceGetInfo)
+OFFLOAD_FUNC(offloadDeviceGetInfoSize)
#undef OFFLOAD_FUNC
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
index b0bdf6c2221ae4..b7be0f0782e935 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/new-api/include/offload_impl.hpp
@@ -61,7 +61,7 @@ using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
ErrSetT &Errors();
struct offload_impl_result_t {
- offload_impl_result_t(std::nullptr_t) : Result(OFFLOAD_SUCCESS) {}
+ offload_impl_result_t(std::nullptr_t) : Result(OFFLOAD_RESULT_SUCCESS) {}
offload_impl_result_t(offload_errc_t Code) {
if (Code == OFFLOAD_ERRC_SUCCESS) {
Result = nullptr;
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
index 1160ee1c6e2549..4dfedd0cde26b2 100644
--- a/offload/new-api/include/offload_impl_func_decls.inc
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -5,24 +5,40 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+offload_impl_result_t offloadInit_impl();
+
+offload_impl_result_t offloadShutDown_impl();
+
offload_impl_result_t
offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms);
+ offload_platform_handle_t *phPlatforms);
+
+offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *pNumPlatforms);
offload_impl_result_t
offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
offload_platform_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet);
+ void *pPropValue);
+
+offload_impl_result_t
+offloadPlatformGetInfoSize_impl(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t *pPropSizeRet);
+
+offload_impl_result_t
+offloadDeviceGetCount_impl(offload_platform_handle_t hPlatform,
+ uint32_t *pNumDevices);
offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
- offload_device_type_t DeviceType,
uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- uint32_t *pNumDevices);
+ offload_device_handle_t *phDevices);
offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
offload_device_info_t propName,
size_t propSize,
- void *pPropValue,
- size_t *pPropSizeRet);
+ void *pPropValue);
+
+offload_impl_result_t
+offloadDeviceGetInfoSize_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t *pPropSizeRet);
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
index c3a6c0a702e5b7..35245fd9e736a4 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -283,7 +283,7 @@ inline void printTagged(std::ostream &os, const void *ptr,
inline std::ostream &operator<<(std::ostream &os,
const offload_error_struct_t *err) {
if (err == nullptr) {
- os << "OFFLOAD_SUCCESS";
+ os << "OFFLOAD_RESULT_SUCCESS";
} else {
os << err->code;
}
@@ -305,7 +305,12 @@ inline std::ostream &operator<<(
printPtr(os, (*params->pphPlatforms)[i]);
}
os << "}";
- os << ", ";
+ return os;
+}
+
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_platform_get_count_params_t *params) {
os << ".pNumPlatforms = ";
printPtr(os, *params->ppNumPlatforms);
return os;
@@ -325,21 +330,41 @@ inline std::ostream &operator<<(
os << ", ";
os << ".pPropValue = ";
printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ return os;
+}
+
+inline std::ostream &
+operator<<(std::ostream &os,
+ [[maybe_unused]] const struct offload_platform_get_info_size_params_t
+ *params) {
+ os << ".hPlatform = ";
+ printPtr(os, *params->phPlatform);
+ os << ", ";
+ os << ".propName = ";
+ os << *params->ppropName;
os << ", ";
os << ".pPropSizeRet = ";
printPtr(os, *params->ppPropSizeRet);
return os;
}
+inline std::ostream &operator<<(
+ std::ostream &os,
+ [[maybe_unused]] const struct offload_device_get_count_params_t *params) {
+ os << ".hPlatform = ";
+ printPtr(os, *params->phPlatform);
+ os << ", ";
+ os << ".pNumDevices = ";
+ printPtr(os, *params->ppNumDevices);
+ return os;
+}
+
inline std::ostream &
operator<<(std::ostream &os,
[[maybe_unused]] const struct offload_device_get_params_t *params) {
os << ".hPlatform = ";
printPtr(os, *params->phPlatform);
os << ", ";
- os << ".DeviceType = ";
- os << *params->pDeviceType;
- os << ", ";
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
@@ -352,9 +377,6 @@ operator<<(std::ostream &os,
printPtr(os, (*params->pphDevices)[i]);
}
os << "}";
- os << ", ";
- os << ".pNumDevices = ";
- printPtr(os, *params->ppNumDevices);
return os;
}
@@ -372,6 +394,18 @@ inline std::ostream &operator<<(
os << ", ";
os << ".pPropValue = ";
printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ return os;
+}
+
+inline std::ostream &
+operator<<(std::ostream &os,
+ [[maybe_unused]] const struct offload_device_get_info_size_params_t
+ *params) {
+ os << ".hDevice = ";
+ printPtr(os, *params->phDevice);
+ os << ", ";
+ os << ".propName = ";
+ os << *params->ppropName;
os << ", ";
os << ".pPropSizeRet = ";
printPtr(os, *params->ppPropSizeRet);
@@ -400,5 +434,5 @@ inline offload_result_t printPtr(std::ostream &os, const T *ptr) {
os << ")";
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index 31329d2aea683d..af26c28768b946 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -67,40 +67,44 @@ void initPlugins() {
}
}
-offload_impl_result_t
-offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- uint32_t *pNumPlatforms) {
+// TODO: We can properly reference count here and manage the resources in a more
+// clever way
+offload_impl_result_t offloadInit_impl() {
+ static std::once_flag InitFlag;
+ std::call_once(InitFlag, initPlugins);
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+offload_impl_result_t offloadShutDown_impl() { return OFFLOAD_RESULT_SUCCESS; }
+
+offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *pNumPlatforms) {
// It is expected that offloadPlatformGet is the first function to be called.
// In future it may make sense to have a specific entry point for Offload
// initialization, or expose explicit initialization of plugins.
- static std::once_flag InitFlag;
- std::call_once(InitFlag, initPlugins);
+ *pNumPlatforms = Platforms().size();
+ return OFFLOAD_RESULT_SUCCESS;
+}
+offload_impl_result_t
+offloadPlatformGet_impl(uint32_t NumEntries,
+ offload_platform_handle_t *phPlatforms) {
if (NumEntries > Platforms().size()) {
return {OFFLOAD_ERRC_INVALID_SIZE,
std::string{formatv("{0} platform(s) available but {1} requested.",
Platforms().size(), NumEntries)}};
}
- if (phPlatforms) {
- for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
- PlatformIndex++) {
- phPlatforms[PlatformIndex] = &(Platforms())[PlatformIndex];
- }
- }
-
- if (pNumPlatforms) {
- *pNumPlatforms = Platforms().size();
+ for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
+ PlatformIndex++) {
+ phPlatforms[PlatformIndex] = &(Platforms())[PlatformIndex];
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
-offload_impl_result_t
-offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet) {
+offload_impl_result_t offloadPlatformGetInfoImplDetail(
+ offload_platform_handle_t hPlatform, offload_platform_info_t propName,
+ size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
switch (propName) {
@@ -127,33 +131,51 @@ offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
return OFFLOAD_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
-offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
- offload_device_type_t,
- uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- uint32_t *pNumDevices) {
+offload_impl_result_t
+offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName, size_t propSize,
+ void *pPropValue) {
+ return offloadPlatformGetInfoImplDetail(hPlatform, propName, propSize,
+ pPropValue, nullptr);
+}
- if (phDevices) {
- for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
- phDevices[DeviceIndex] = &(hPlatform->Devices[DeviceIndex]);
- }
+offload_impl_result_t
+offloadPlatformGetInfoSize_impl(offload_platform_handle_t hPlatform,
+ offload_platform_info_t propName,
+ size_t *pPropSizeRet) {
+ return offloadPlatformGetInfoImplDetail(hPlatform, propName, 0, nullptr,
+ pPropSizeRet);
+}
+
+offload_impl_result_t
+offloadDeviceGetCount_impl(offload_platform_handle_t hPlatform,
+ uint32_t *pNumDevices) {
+ *pNumDevices = static_cast<uint32_t>(hPlatform->Devices.size());
+
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_impl_result_t
+offloadDeviceGet_impl(offload_platform_handle_t hPlatform, uint32_t NumEntries,
+ offload_device_handle_t *phDevices) {
+ if (NumEntries > hPlatform->Devices.size()) {
+ return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (pNumDevices) {
- *pNumDevices = static_cast<uint32_t>(hPlatform->Devices.size());
+ for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
+ phDevices[DeviceIndex] = &(hPlatform->Devices[DeviceIndex]);
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
-offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize,
- void *pPropValue,
- size_t *pPropSizeRet) {
+offload_impl_result_t
+offloadDeviceGetInfoImplDetail(offload_device_handle_t hDevice,
+ offload_device_info_t propName, size_t propSize,
+ void *pPropValue, size_t *pPropSizeRet) {
ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
@@ -194,5 +216,21 @@ offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
return OFFLOAD_ERRC_INVALID_ENUMERATION;
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
+}
+
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t propSize,
+ void *pPropValue) {
+ return offloadDeviceGetInfoImplDetail(hDevice, propName, propSize, pPropValue,
+ nullptr);
+}
+
+offload_impl_result_t
+offloadDeviceGetInfoSize_impl(offload_device_handle_t hDevice,
+ offload_device_info_t propName,
+ size_t *pPropSizeRet) {
+ return offloadDeviceGetInfoImplDetail(hDevice, propName, 0, nullptr,
+ pPropSizeRet);
}
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index cd9fe54085f1a8..c50146f351288e 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -153,6 +153,10 @@ static void ProcessStruct(const StructRec &Struct, raw_ostream &OS) {
}
static void ProcessFuncParamStruct(const FunctionRec &Func, raw_ostream &OS) {
+ if (Func.getParams().size() == 0) {
+ return;
+ }
+
auto FuncParamStructBegin = R"(
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for {0}
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index c5c823f68cb56e..16adcdce1e07e2 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -82,15 +82,19 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
// Emit post-call prints
OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
- OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
- for (const auto &Param : F.getParams()) {
- OS << "&" << Param.getName();
- if (Param != F.getParams().back()) {
- OS << ", ";
+ if (F.getParams().size() > 0) {
+ OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
+ for (const auto &Param : F.getParams()) {
+ OS << "&" << Param.getName();
+ if (Param != F.getParams().back()) {
+ OS << ", ";
+ }
}
+ OS << formatv("};\n");
+ OS << TAB_2 "std::cout << \"(\" << &Params << \")\";\n";
+ } else {
+ OS << TAB_2 "std::cout << \"()\";\n";
}
- OS << formatv("};\n");
- OS << TAB_2 "std::cout << \"(\" << &Params << \")\";\n";
OS << TAB_2 "std::cout << \"-> \" << result << \"\\n\";\n";
OS << TAB_2 "if (result && result->details) {\n";
OS << TAB_3 "std::cout << \" *Error Details* \" << result->details "
diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/FuncsGen.cpp
index 033ed8db3240ad..e0152053c9e19c 100644
--- a/offload/tools/offload-tblgen/FuncsGen.cpp
+++ b/offload/tools/offload-tblgen/FuncsGen.cpp
@@ -54,22 +54,14 @@ void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
OS << GenericHeader;
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
FunctionRec F{R};
- // The error details function does not set error details itself, so don't
- // use the impl result type
- if (F.getName() == "offloadGetErrorDetails") {
- OS << formatv("{0}_result_t {1}_impl(", PrefixLower, F.getName());
- } else {
- OS << formatv("{0}_impl_result_t {1}_impl(", PrefixLower, F.getName());
- }
+ OS << formatv("{0}_impl_result_t {1}_impl(", PrefixLower, F.getName());
auto Params = F.getParams();
for (auto &Param : Params) {
OS << Param.getType() << " " << Param.getName();
if (Param != Params.back()) {
OS << ", ";
- } else {
- OS << ");";
}
}
- OS << "\n\n";
+ OS << ");\n\n";
}
}
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index 0e73c29c338a1b..ef9ecf0f3ac235 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -99,7 +99,7 @@ static void EmitResultPrint(raw_ostream &OS) {
inline std::ostream &operator<<(std::ostream &os,
const offload_error_struct_t *err) {
if (err == nullptr) {
- os << "OFFLOAD_SUCCESS";
+ os << "OFFLOAD_RESULT_SUCCESS";
} else {
os << err->code;
}
@@ -110,6 +110,10 @@ inline std::ostream &operator<<(std::ostream &os,
static void EmitFunctionParamStructPrint(const FunctionRec &Func,
raw_ostream &OS) {
+ if (Func.getParams().size() == 0) {
+ return;
+ }
+
OS << formatv(R"(
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct {0} *params) {{
)",
@@ -216,7 +220,7 @@ template <typename T> inline offload_result_t printPtr(std::ostream &os, const T
os << ")";
}
- return OFFLOAD_SUCCESS;
+ return OFFLOAD_RESULT_SUCCESS;
}
)""";
}
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index 0960fa5a135111..276eb2be281922 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -4,9 +4,13 @@ set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
add_libompt_unittest("offload.unittests"
${CMAKE_CURRENT_SOURCE_DIR}/common/environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGet.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGetCount.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGetInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/platform/offloadPlatformGetInfoSize.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGet.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfo.cpp)
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetCount.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device/offloadDeviceGetInfoSize.cpp)
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON})
target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})
diff --git a/offload/unittests/OffloadAPI/common/environment.cpp b/offload/unittests/OffloadAPI/common/environment.cpp
index 01973ec117e300..ec71495d278552 100644
--- a/offload/unittests/OffloadAPI/common/environment.cpp
+++ b/offload/unittests/OffloadAPI/common/environment.cpp
@@ -13,6 +13,14 @@
using namespace llvm;
+// Wrapper so we don't have to constantly init and shutdown Offload in every
+// test, while having sensible lifetime for the platform environment
+struct OffloadInitWrapper {
+ OffloadInitWrapper() { offloadInit(); }
+ ~OffloadInitWrapper() { offloadShutDown(); }
+};
+static OffloadInitWrapper Wrapper{};
+
static cl::opt<std::string>
SelectedPlatform("platform", cl::desc("Only test the specified platform"),
cl::value_desc("platform"));
@@ -20,11 +28,10 @@ static cl::opt<std::string>
std::ostream &operator<<(std::ostream &Out,
const offload_platform_handle_t &Platform) {
size_t Size;
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_NAME, 0, nullptr,
- &Size);
+ offloadPlatformGetInfoSize(Platform, OFFLOAD_PLATFORM_INFO_NAME, &Size);
std::vector<char> Name(Size);
offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_NAME, Size,
- Name.data(), nullptr);
+ Name.data());
Out << Name.data();
return Out;
}
@@ -43,10 +50,10 @@ const std::vector<offload_platform_handle_t> &TestEnvironment::getPlatforms() {
if (Platforms.empty()) {
uint32_t PlatformCount = 0;
- offloadPlatformGet(0, nullptr, &PlatformCount);
+ offloadPlatformGetCount(&PlatformCount);
if (PlatformCount > 0) {
Platforms.resize(PlatformCount);
- offloadPlatformGet(PlatformCount, Platforms.data(), nullptr);
+ offloadPlatformGet(PlatformCount, Platforms.data());
}
}
@@ -77,8 +84,8 @@ offload_platform_handle_t TestEnvironment::getPlatform() {
Platform = Platforms[0];
for (auto CandidatePlatform : Platforms) {
uint32_t NumDevices = 0;
- if (offloadDeviceGet(CandidatePlatform, OFFLOAD_DEVICE_TYPE_ALL, 0,
- nullptr, &NumDevices) == OFFLOAD_SUCCESS) {
+ if (offloadDeviceGetCount(CandidatePlatform, &NumDevices) ==
+ OFFLOAD_RESULT_SUCCESS) {
if (NumDevices > 0) {
Platform = CandidatePlatform;
break;
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/fixtures.hpp
index 2366f8687a8e93..5dcf6232504bd9 100644
--- a/offload/unittests/OffloadAPI/common/fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/fixtures.hpp
@@ -15,7 +15,7 @@
#pragma once
#ifndef ASSERT_SUCCESS
-#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_SUCCESS, ACTUAL)
+#define ASSERT_SUCCESS(ACTUAL) ASSERT_EQ(OFFLOAD_RESULT_SUCCESS, ACTUAL)
#endif
// TODO: rework this so the EXPECTED/ACTUAL results are readable
@@ -34,9 +34,13 @@
} \
(void)0
-struct offloadPlatformTest : ::testing::Test {
+struct offloadTest : ::testing::Test {
+ // No special behavior now, but just in case we need to override it in future
+};
+
+struct offloadPlatformTest : offloadTest {
void SetUp() override {
- RETURN_ON_FATAL_FAILURE(::testing::Test::SetUp());
+ RETURN_ON_FATAL_FAILURE(offloadTest::SetUp());
Platform = TestEnvironment::getPlatform();
ASSERT_NE(Platform, nullptr);
@@ -50,13 +54,11 @@ struct offloadDeviceTest : offloadPlatformTest {
RETURN_ON_FATAL_FAILURE(offloadPlatformTest::SetUp());
uint32_t NumDevices;
- ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0,
- nullptr, &NumDevices));
+ ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &NumDevices));
if (NumDevices == 0) {
GTEST_SKIP() << "No available devices on this platform.";
}
- ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 1,
- &Device, nullptr));
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, 1, &Device));
}
offload_device_handle_t Device;
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
index 1442ebc98c7f6e..c14fd3997ee62d 100644
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGet.cpp
@@ -14,12 +14,10 @@ using offloadDeviceGetTest = offloadPlatformTest;
TEST_F(offloadDeviceGetTest, Success) {
uint32_t Count = 0;
- ASSERT_SUCCESS(
- offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0, nullptr, &Count));
+ ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
ASSERT_NE(Count, 0lu);
std::vector<offload_device_handle_t> Devices(Count);
- ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, Count,
- Devices.data(), nullptr));
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, Count, Devices.data()));
for (auto Device : Devices) {
ASSERT_NE(nullptr, Device);
}
@@ -27,14 +25,12 @@ TEST_F(offloadDeviceGetTest, Success) {
TEST_F(offloadDeviceGetTest, SuccessSubsetOfDevices) {
uint32_t Count;
- ASSERT_SUCCESS(
- offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, 0, nullptr, &Count));
+ ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
if (Count < 2) {
GTEST_SKIP() << "Only one device is available on this platform.";
}
std::vector<offload_device_handle_t> Devices(Count - 1);
- ASSERT_SUCCESS(offloadDeviceGet(Platform, OFFLOAD_DEVICE_TYPE_ALL, Count - 1,
- Devices.data(), nullptr));
+ ASSERT_SUCCESS(offloadDeviceGet(Platform, Count - 1, Devices.data()));
for (auto Device : Devices) {
ASSERT_NE(nullptr, Device);
}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
new file mode 100644
index 00000000000000..87ebbef1d8b7d8
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGetCount.cpp
@@ -0,0 +1,30 @@
+//===------- Offload API tests - offloadDeviceGetCount --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/fixtures.hpp"
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+using offloadDeviceGetCountTest = offloadPlatformTest;
+
+TEST_F(offloadDeviceGetCountTest, Success) {
+ uint32_t Count = 0;
+ ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
+ ASSERT_NE(Count, 0lu);
+}
+
+TEST_F(offloadDeviceGetCountTest, InvalidNullPlatform) {
+ uint32_t Count = 0;
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
+ offloadDeviceGetCount(nullptr, &Count));
+}
+
+TEST_F(offloadDeviceGetCountTest, InvalidNullPointer) {
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadDeviceGetCount(Platform, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
index e9f5615b35d3ef..099bc3abcf8c4b 100644
--- a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfo.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "../common/fixtures.hpp"
+#include "offloadDeviceInfo.hpp"
#include <gtest/gtest.h>
#include <offload_api.h>
@@ -17,39 +18,22 @@ struct offloadDeviceGetInfoTest
void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
};
-// TODO: We could autogenerate the list of enum values
INSTANTIATE_TEST_SUITE_P(
- , offloadDeviceGetInfoTest,
- ::testing::Values(OFFLOAD_DEVICE_INFO_TYPE, OFFLOAD_DEVICE_INFO_PLATFORM,
- OFFLOAD_DEVICE_INFO_NAME, OFFLOAD_DEVICE_INFO_VENDOR,
- OFFLOAD_DEVICE_INFO_DRIVER_VERSION),
+ , offloadDeviceGetInfoTest, ::testing::ValuesIn(DeviceQueries),
[](const ::testing::TestParamInfo<offload_device_info_t> &info) {
std::stringstream ss;
ss << info.param;
return ss.str();
});
-// TODO: We could autogenerate this
-std::unordered_map<offload_device_info_t, size_t> DeviceInfoSizeMap = {
- {OFFLOAD_DEVICE_INFO_TYPE, sizeof(offload_device_type_t)},
- {OFFLOAD_DEVICE_INFO_PLATFORM, sizeof(offload_platform_handle_t)},
-};
-
TEST_P(offloadDeviceGetInfoTest, Success) {
offload_device_info_t InfoType = GetParam();
size_t Size = 0;
- ASSERT_SUCCESS(offloadDeviceGetInfo(Device, InfoType, 0, nullptr, &Size));
- auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
- if (ExpectedSize != DeviceInfoSizeMap.end()) {
- ASSERT_EQ(Size, ExpectedSize->second);
- } else {
- ASSERT_NE(Size, 0lu);
- }
+ ASSERT_SUCCESS(offloadDeviceGetInfoSize(Device, InfoType, &Size));
std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(
- offloadDeviceGetInfo(Device, InfoType, Size, InfoData.data(), nullptr));
+ ASSERT_SUCCESS(offloadDeviceGetInfo(Device, InfoType, Size, InfoData.data()));
if (InfoType == OFFLOAD_DEVICE_INFO_PLATFORM) {
auto *ReturnedPlatform =
@@ -62,42 +46,35 @@ TEST_F(offloadDeviceGetInfoTest, InvalidNullHandleDevice) {
offload_device_type_t DeviceType;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
offloadDeviceGetInfo(nullptr, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(offload_device_type_t), &DeviceType,
- nullptr));
+ sizeof(offload_device_type_t),
+ &DeviceType));
}
TEST_F(offloadDeviceGetInfoTest, InvalidEnumerationInfoType) {
offload_device_type_t DeviceType;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_FORCE_UINT32,
- sizeof(offload_device_type_t), &DeviceType,
- nullptr));
+ sizeof(offload_device_type_t),
+ &DeviceType));
}
TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSize) {
offload_device_type_t DeviceType;
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
- &DeviceType, nullptr));
+ ASSERT_ERROR(
+ OFFLOAD_ERRC_INVALID_SIZE,
+ offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0, &DeviceType));
}
TEST_F(offloadDeviceGetInfoTest, InvalidSizePropSizeSmall) {
offload_device_type_t DeviceType;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(DeviceType) - 1, &DeviceType,
- nullptr));
+ sizeof(DeviceType) - 1, &DeviceType));
}
TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropValue) {
offload_device_type_t DeviceType;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE,
- sizeof(DeviceType), nullptr, nullptr));
-}
-
-TEST_F(offloadDeviceGetInfoTest, InvalidNullPointerPropSizeRet) {
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
- offloadDeviceGetInfo(Device, OFFLOAD_DEVICE_INFO_TYPE, 0,
- nullptr, nullptr));
+ sizeof(DeviceType), nullptr));
}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
new file mode 100644
index 00000000000000..8e08a59af902c2
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceGetInfoSize.cpp
@@ -0,0 +1,61 @@
+//===------- Offload API tests - offloadDeviceGetInfoSize -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <offload_api.h>
+
+#include "../common/fixtures.hpp"
+#include "offloadDeviceInfo.hpp"
+
+struct offloadDeviceGetInfoSizeTest
+ : offloadDeviceTest,
+ ::testing::WithParamInterface<offload_device_info_t> {
+
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
+};
+
+// TODO: We could autogenerate the list of enum values
+INSTANTIATE_TEST_SUITE_P(
+ , offloadDeviceGetInfoSizeTest, ::testing::ValuesIn(DeviceQueries),
+ [](const ::testing::TestParamInfo<offload_device_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(offloadDeviceGetInfoSizeTest, Success) {
+ offload_device_info_t InfoType = GetParam();
+ size_t Size = 0;
+
+ ASSERT_SUCCESS(offloadDeviceGetInfoSize(Device, InfoType, &Size));
+ auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
+ if (ExpectedSize != DeviceInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+}
+
+TEST_F(offloadDeviceGetInfoSizeTest, InvalidNullHandle) {
+ size_t Size = 0;
+ ASSERT_ERROR(
+ OFFLOAD_ERRC_INVALID_NULL_HANDLE,
+ offloadDeviceGetInfoSize(nullptr, OFFLOAD_DEVICE_INFO_TYPE, &Size));
+}
+
+TEST_F(offloadDeviceGetInfoSizeTest, InvalidDeviceInfoEnumeration) {
+ size_t Size = 0;
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
+ offloadDeviceGetInfoSize(
+ Device, OFFLOAD_DEVICE_INFO_FORCE_UINT32, &Size));
+}
+
+TEST_F(offloadDeviceGetInfoSizeTest, InvalidNullPointer) {
+ ASSERT_ERROR(
+ OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadDeviceGetInfoSize(Device, OFFLOAD_DEVICE_INFO_TYPE, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp b/offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp
new file mode 100644
index 00000000000000..064935ac10107f
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/offloadDeviceInfo.hpp
@@ -0,0 +1,22 @@
+//===------- Offload API tests - Helpers for device info query testing ----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#pragma once
+
+#include <unordered_map>
+#include <vector>
+
+// TODO: We could autogenerate these
+inline std::vector<offload_device_info_t> DeviceQueries = {
+ OFFLOAD_DEVICE_INFO_TYPE, OFFLOAD_DEVICE_INFO_PLATFORM,
+ OFFLOAD_DEVICE_INFO_NAME, OFFLOAD_DEVICE_INFO_VENDOR,
+ OFFLOAD_DEVICE_INFO_DRIVER_VERSION};
+
+inline std::unordered_map<offload_device_info_t, size_t> DeviceInfoSizeMap = {
+ {OFFLOAD_DEVICE_INFO_TYPE, sizeof(offload_device_type_t)},
+ {OFFLOAD_DEVICE_INFO_PLATFORM, sizeof(offload_platform_handle_t)},
+};
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
index 14b7b9bba6b4d4..37d4b8c62b5ee1 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGet.cpp
@@ -6,24 +6,24 @@
//
//===----------------------------------------------------------------------===//
+#include "../common/fixtures.hpp"
#include <gtest/gtest.h>
#include <offload_api.h>
-#include "../common/fixtures.hpp"
-using offloadPlatformGetTest = ::testing::Test;
+using offloadPlatformGetTest = offloadTest;
TEST_F(offloadPlatformGetTest, Success) {
uint32_t PlatformCount;
- ASSERT_SUCCESS(offloadPlatformGet(0, nullptr, &PlatformCount));
+ ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
std::vector<offload_platform_handle_t> Platforms(PlatformCount);
- ASSERT_SUCCESS(offloadPlatformGet(PlatformCount, Platforms.data(), nullptr));
+ ASSERT_SUCCESS(offloadPlatformGet(PlatformCount, Platforms.data()));
}
TEST_F(offloadPlatformGetTest, InvalidNumEntries) {
uint32_t PlatformCount;
- ASSERT_SUCCESS(offloadPlatformGet(0, nullptr, &PlatformCount));
+ ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
std::vector<offload_platform_handle_t> Platforms(PlatformCount);
ASSERT_ERROR(
OFFLOAD_ERRC_INVALID_SIZE,
- offloadPlatformGet(PlatformCount + 1, Platforms.data(), nullptr));
+ offloadPlatformGet(PlatformCount + 1, Platforms.data()));
}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp
new file mode 100644
index 00000000000000..94e2f4cad0e5dc
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGetCount.cpp
@@ -0,0 +1,23 @@
+//===------- Offload API tests - offloadPlatformGetCount ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/fixtures.hpp"
+#include <gtest/gtest.h>
+#include <offload_api.h>
+
+using offloadPlatformGetCountTest = offloadTest;
+
+TEST_F(offloadPlatformGetCountTest, Success) {
+ uint32_t PlatformCount;
+ ASSERT_SUCCESS(offloadPlatformGetCount(&PlatformCount));
+}
+
+TEST_F(offloadPlatformGetCountTest, InvalidNullPointer) {
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadPlatformGetCount(nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
index a5c86a7ba1933f..2522b3bf56f77c 100644
--- a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfo.cpp
@@ -9,90 +9,70 @@
#include <offload_api.h>
#include "../common/fixtures.hpp"
+#include "offloadPlatformInfo.hpp"
struct offloadPlatformGetInfoTest
: offloadPlatformTest,
::testing::WithParamInterface<offload_platform_info_t> {};
-// TODO: We could autogenerate the list of enum values
INSTANTIATE_TEST_SUITE_P(
offloadPlatformGetInfo, offloadPlatformGetInfoTest,
- ::testing::Values(OFFLOAD_PLATFORM_INFO_NAME,
- OFFLOAD_PLATFORM_INFO_VENDOR_NAME,
- OFFLOAD_PLATFORM_INFO_VERSION,
- OFFLOAD_PLATFORM_INFO_BACKEND),
+ ::testing::ValuesIn(PlatformQueries),
[](const ::testing::TestParamInfo<offload_platform_info_t> &info) {
std::stringstream ss;
ss << info.param;
return ss.str();
});
-// TODO: We could autogenerate this
-std::unordered_map<offload_platform_info_t, size_t> PlatformInfoSizeMap = {
- {OFFLOAD_PLATFORM_INFO_BACKEND, sizeof(offload_platform_backend_t)},
-};
-
TEST_P(offloadPlatformGetInfoTest, Success) {
size_t Size = 0;
offload_platform_info_t InfoType = GetParam();
- ASSERT_SUCCESS(offloadPlatformGetInfo(Platform, InfoType, 0, nullptr, &Size));
- auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
- if (ExpectedSize != PlatformInfoSizeMap.end()) {
- ASSERT_EQ(Size, ExpectedSize->second);
- } else {
- ASSERT_NE(Size, 0lu);
- }
-
+ ASSERT_SUCCESS(offloadPlatformGetInfoSize(Platform, InfoType, &Size));
std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(offloadPlatformGetInfo(Platform, InfoType, Size,
- InfoData.data(), nullptr));
+ ASSERT_SUCCESS(
+ offloadPlatformGetInfo(Platform, InfoType, Size, InfoData.data()));
// Info types with a dynamic size are all char[] so we can verify the returned
// string is the expected size.
+ auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
if (ExpectedSize == PlatformInfoSizeMap.end()) {
ASSERT_EQ(Size, strlen(InfoData.data()) + 1);
}
}
TEST_F(offloadPlatformGetInfoTest, InvalidNullHandle) {
- size_t Size = 0;
+ offload_platform_backend_t Backend;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
- offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND, 0,
- nullptr, &Size));
+ offloadPlatformGetInfo(nullptr, OFFLOAD_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), &Backend));
}
TEST_F(offloadPlatformGetInfoTest, InvalidPlatformInfoEnumeration) {
- size_t Size = 0;
+ offload_platform_backend_t Backend;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
offloadPlatformGetInfo(Platform,
- OFFLOAD_PLATFORM_INFO_FORCE_UINT32, 0,
- nullptr, &Size));
+ OFFLOAD_PLATFORM_INFO_FORCE_UINT32,
+ sizeof(Backend), &Backend));
}
TEST_F(offloadPlatformGetInfoTest, InvalidSizeZero) {
offload_platform_backend_t Backend;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- 0, &Backend, nullptr));
+ 0, &Backend));
}
TEST_F(offloadPlatformGetInfoTest, InvalidSizeSmall) {
offload_platform_backend_t Backend;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_SIZE,
offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- sizeof(Backend) - 1, &Backend, nullptr));
+ sizeof(Backend) - 1, &Backend));
}
TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropValue) {
offload_platform_backend_t Backend;
ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- sizeof(Backend), nullptr, nullptr));
-}
-
-TEST_F(offloadPlatformGetInfoTest, InvalidNullPointerPropSizeRet) {
- ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
- offloadPlatformGetInfo(Platform, OFFLOAD_PLATFORM_INFO_BACKEND,
- 0, nullptr, nullptr));
+ sizeof(Backend), nullptr));
}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
new file mode 100644
index 00000000000000..e90340666d1312
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformGetInfoSize.cpp
@@ -0,0 +1,58 @@
+//===------- Offload API tests - offloadPlatformGetInfoSize ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <offload_api.h>
+
+#include "../common/fixtures.hpp"
+#include "offloadPlatformInfo.hpp"
+
+struct offloadPlatformGetInfoSizeTest
+ : offloadPlatformTest,
+ ::testing::WithParamInterface<offload_platform_info_t> {};
+
+INSTANTIATE_TEST_SUITE_P(
+ offloadPlatformGetInfoSize, offloadPlatformGetInfoSizeTest,
+ ::testing::ValuesIn(PlatformQueries),
+ [](const ::testing::TestParamInfo<offload_platform_info_t> &info) {
+ std::stringstream ss;
+ ss << info.param;
+ return ss.str();
+ });
+
+TEST_P(offloadPlatformGetInfoSizeTest, Success) {
+ size_t Size = 0;
+ offload_platform_info_t InfoType = GetParam();
+
+ ASSERT_SUCCESS(offloadPlatformGetInfoSize(Platform, InfoType, &Size));
+ auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
+ if (ExpectedSize != PlatformInfoSizeMap.end()) {
+ ASSERT_EQ(Size, ExpectedSize->second);
+ } else {
+ ASSERT_NE(Size, 0lu);
+ }
+}
+
+TEST_F(offloadPlatformGetInfoSizeTest, InvalidNullHandle) {
+ size_t Size = 0;
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_HANDLE,
+ offloadPlatformGetInfoSize(
+ nullptr, OFFLOAD_PLATFORM_INFO_BACKEND, &Size));
+}
+
+TEST_F(offloadPlatformGetInfoSizeTest, InvalidPlatformInfoEnumeration) {
+ size_t Size = 0;
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_ENUMERATION,
+ offloadPlatformGetInfoSize(
+ Platform, OFFLOAD_PLATFORM_INFO_FORCE_UINT32, &Size));
+}
+
+TEST_F(offloadPlatformGetInfoSizeTest, InvalidNullPointer) {
+ ASSERT_ERROR(OFFLOAD_ERRC_INVALID_NULL_POINTER,
+ offloadPlatformGetInfoSize(
+ Platform, OFFLOAD_PLATFORM_INFO_BACKEND, nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp b/offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp
new file mode 100644
index 00000000000000..c4a0fc21b33d05
--- /dev/null
+++ b/offload/unittests/OffloadAPI/platform/offloadPlatformInfo.hpp
@@ -0,0 +1,21 @@
+//===------- Offload API tests - Helpers for platform info query testing --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#pragma once
+
+#include <vector>
+
+// TODO: We could autogenerate these
+
+inline std::vector<offload_platform_info_t> PlatformQueries = {
+ OFFLOAD_PLATFORM_INFO_NAME, OFFLOAD_PLATFORM_INFO_VENDOR_NAME,
+ OFFLOAD_PLATFORM_INFO_VERSION, OFFLOAD_PLATFORM_INFO_BACKEND};
+
+inline std::unordered_map<offload_platform_info_t, size_t> PlatformInfoSizeMap =
+ {
+ {OFFLOAD_PLATFORM_INFO_BACKEND, sizeof(offload_platform_backend_t)},
+};
>From 932d440f084dced9ccbc35df309d6e0d5e353401 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 25 Oct 2024 11:56:39 +0100
Subject: [PATCH 13/14] Fix style
---
offload/new-api/API/Common.td | 4 +-
offload/new-api/API/Device.td | 32 +-
offload/new-api/API/Platform.td | 32 +-
offload/new-api/include/offload_api.h | 195 +++++----
.../new-api/include/offload_entry_points.inc | 390 +++++++++---------
offload/new-api/include/offload_impl.hpp | 20 +-
.../include/offload_impl_func_decls.inc | 38 +-
offload/new-api/include/offload_print.hpp | 86 ++--
offload/new-api/src/offload_impl.cpp | 92 ++---
offload/new-api/src/offload_lib.cpp | 6 +-
offload/tools/offload-tblgen/APIGen.cpp | 2 +-
.../tools/offload-tblgen/EntryPointGen.cpp | 20 +-
offload/tools/offload-tblgen/PrintGen.cpp | 6 +-
.../unittests/OffloadAPI/common/fixtures.hpp | 2 +-
14 files changed, 460 insertions(+), 465 deletions(-)
diff --git a/offload/new-api/API/Common.td b/offload/new-api/API/Common.td
index c2f03bbc0ae355..d9c356c55bf5c0 100644
--- a/offload/new-api/API/Common.td
+++ b/offload/new-api/API/Common.td
@@ -72,8 +72,8 @@ def : Struct {
let name = "offload_error_struct_t";
let desc = "Details of the error condition returned by an API call";
let members = [
- StructMember<"offload_errc_t", "code", "The error code">,
- StructMember<"const char*", "details", "String containing error details">
+ StructMember<"offload_errc_t", "Code", "The error code">,
+ StructMember<"const char*", "Details", "String containing error details">
];
}
diff --git a/offload/new-api/API/Device.td b/offload/new-api/API/Device.td
index 2700f3c9f639f9..bc216708226c6f 100644
--- a/offload/new-api/API/Device.td
+++ b/offload/new-api/API/Device.td
@@ -38,8 +38,8 @@ def : Function {
let name = "offloadDeviceGetCount";
let desc = "Retrieves the number of available devices within a platform";
let params = [
- Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
- Param<"uint32_t*", "pNumDevices", "pointer to the number of devices.", PARAM_OUT>
+ Param<"offload_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
+ Param<"uint32_t*", "NumDevices", "pointer to the number of devices.", PARAM_OUT>
];
let returns = [];
}
@@ -52,9 +52,9 @@ def : Function {
"The application may call this function from simultaneous threads, the implementation must be thread-safe"
];
let params = [
- Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
+ Param<"offload_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices, which must be greater than zero", PARAM_IN>,
- RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
+ RangedParam<"offload_device_handle_t*", "Devices", "Array of device handles. "
"If NumEntries is less than the number of devices available, then this function shall only retrieve that number of devices.", PARAM_OUT,
Range<"0", "NumEntries">>
];
@@ -73,20 +73,20 @@ def : Function {
"The implementation of this function should be lock-free."
];
let params = [
- Param<"offload_device_handle_t", "hDevice", "handle of the device instance", PARAM_IN>,
- Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
- Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
- TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
+ Param<"offload_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
+ Param<"offload_device_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,
+ TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. If PropSize is not equal to or greater than the real "
"number of bytes needed to return the info then the OFFLOAD_ERRC_INVALID_SIZE error is returned and "
- "pPropValue is not used.", PARAM_OUT, TypeInfo<"propName" , "propSize">>
+ "PropValue is not used.", PARAM_OUT, TypeInfo<"PropName" , "PropSize">>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
- "If `propName` is not supported by the device."
+ "If `PropName` is not supported by the device."
]>,
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`propSize == 0`",
- "If `propSize` is less than the real number of bytes needed to return the info."
+ "`PropSize == 0`",
+ "If `PropSize` is less than the real number of bytes needed to return the info."
]>,
Return<"OFFLOAD_ERRC_INVALID_DEVICE">
];
@@ -100,13 +100,13 @@ def : Function {
"The implementation of this function should be lock-free."
];
let params = [
- Param<"offload_device_handle_t", "hDevice", "handle of the device instance", PARAM_IN>,
- Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
- Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
+ Param<"offload_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
+ Param<"offload_device_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
- "If `propName` is not supported by the device."
+ "If `PropName` is not supported by the device."
]>,
Return<"OFFLOAD_ERRC_INVALID_DEVICE">
];
diff --git a/offload/new-api/API/Platform.td b/offload/new-api/API/Platform.td
index 564bea017cab9e..c9b5d7d1fb99f9 100644
--- a/offload/new-api/API/Platform.td
+++ b/offload/new-api/API/Platform.td
@@ -17,10 +17,10 @@ def : Function {
];
let params = [
Param<"uint32_t", "NumEntries",
- "The number of platforms to be added to phPlatforms. NumEntries must be "
+ "The number of platforms to be added to Platforms. NumEntries must be "
"greater than zero.",
PARAM_IN>,
- RangedParam<"offload_platform_handle_t*", "phPlatforms",
+ RangedParam<"offload_platform_handle_t*", "Platforms",
"Array of handle of platforms. If NumEntries is less than the number of "
"platforms available, then offloadPlatformGet shall only retrieve that "
"number of platforms.",
@@ -38,7 +38,7 @@ def : Function {
let desc = "Retrieves the number of available platforms";
let params = [
Param<"uint32_t*",
- "pNumPlatforms", "returns the total number of platforms available.",
+ "NumPlatforms", "returns the total number of platforms available.",
PARAM_OUT>
];
let returns = [];
@@ -52,7 +52,7 @@ def : Enum {
TaggedEtor<"NAME", "char[]", "The string denoting name of the platform. The size of the info needs to be dynamically queried.">,
TaggedEtor<"VENDOR_NAME", "char[]","The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.">,
TaggedEtor<"VERSION", "char[]", "The string denoting the version of the platform. The size of the info needs to be dynamically queried.">,
- TaggedEtor<"BACKEND", "offload_platform_backend_t", "The backend of the platform. Identifies the native backend adapter implementing this platform.">
+ TaggedEtor<"BACKEND", "offload_platform_backend_t", "The native backend of the platform.">
];
}
@@ -76,21 +76,21 @@ def : Function {
"The implementation of this function should be lock-free."
];
let params = [
- Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
- Param<"offload_platform_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
- Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
- TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
+ Param<"offload_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,
+ Param<"offload_platform_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
+ Param<"size_t", "PropSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
+ TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "
"If Size is not equal to or greater to the real number of bytes needed to return the info "
"then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,
- TypeInfo<"propName" , "propSize">>
+ TypeInfo<"PropName" , "PropSize">>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
- "If `propName` is not supported by the platform."
+ "If `PropName` is not supported by the platform."
]>,
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
- "`propSize == 0`",
- "If `propSize` is less than the real number of bytes needed to return the info."
+ "`PropSize == 0`",
+ "If `PropSize` is less than the real number of bytes needed to return the info."
]>,
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
];
@@ -104,13 +104,13 @@ def : Function {
"The implementation of this function should be lock-free."
];
let params = [
- Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
- Param<"offload_platform_info_t", "propName", "type of the info to query", PARAM_IN>,
- Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
+ Param<"offload_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,
+ Param<"offload_platform_info_t", "PropName", "type of the info to query", PARAM_IN>,
+ Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
];
let returns = [
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
- "If `propName` is not supported by the platform."
+ "If `PropName` is not supported by the platform."
]>,
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
];
diff --git a/offload/new-api/include/offload_api.h b/offload/new-api/include/offload_api.h
index 4816abc22fd0b4..87325ad46eaade 100644
--- a/offload/new-api/include/offload_api.h
+++ b/offload/new-api/include/offload_api.h
@@ -113,8 +113,8 @@ typedef enum offload_errc_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Details of the error condition returned by an API call
typedef struct offload_error_struct_t {
- offload_errc_t code; /// The error code
- const char *details; /// String containing error details
+ offload_errc_t Code; /// The error code
+ const char *Details; /// String containing error details
} offload_error_struct_t;
///////////////////////////////////////////////////////////////////////////////
@@ -184,15 +184,15 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown();
/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == phPlatforms`
+/// + `NULL == Platforms`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- // [in] The number of platforms to be added to phPlatforms. NumEntries must
- // be greater than zero.
+ // [in] The number of platforms to be added to Platforms. NumEntries must be
+ // greater than zero.
uint32_t NumEntries,
// [out] Array of handle of platforms. If NumEntries is less than the number
// of platforms available, then offloadPlatformGet shall only retrieve that
// number of platforms.
- offload_platform_handle_t *phPlatforms);
+ offload_platform_handle_t *Platforms);
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves the number of available platforms
@@ -205,10 +205,10 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pNumPlatforms`
+/// + `NULL == NumPlatforms`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetCount(
// [out] returns the total number of platforms available.
- uint32_t *pNumPlatforms);
+ uint32_t *NumPlatforms);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported platform info
@@ -222,8 +222,7 @@ typedef enum offload_platform_info_t {
/// The string denoting the version of the platform. The size of the info
/// needs to be dynamically queried.
OFFLOAD_PLATFORM_INFO_VERSION = 2,
- /// The backend of the platform. Identifies the native backend adapter
- /// implementing this platform.
+ /// The native backend of the platform.
OFFLOAD_PLATFORM_INFO_BACKEND = 3,
/// @cond
OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
@@ -260,28 +259,28 @@ typedef enum offload_platform_backend_t {
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
-/// + If `propName` is not supported by the platform.
+/// + If `PropName` is not supported by the platform.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `propSize == 0`
-/// + If `propSize` is less than the real number of bytes needed to
+/// + `PropSize == 0`
+/// + If `PropSize` is less than the real number of bytes needed to
/// return the info.
/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hPlatform`
+/// + `NULL == Platform`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pPropValue`
+/// + `NULL == PropValue`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
// [in] handle of the platform
- offload_platform_handle_t hPlatform,
+ offload_platform_handle_t Platform,
// [in] type of the info to retrieve
- offload_platform_info_t propName,
+ offload_platform_info_t PropName,
// [in] the number of bytes pointed to by pPlatformInfo.
- size_t propSize,
+ size_t PropSize,
// [out] array of bytes holding the info. If Size is not equal to or greater
// to the real number of bytes needed to return the info then the
// OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not
// used.
- void *pPropValue);
+ void *PropValue);
///////////////////////////////////////////////////////////////////////////////
/// @brief Returns the storage size of the given platform query
@@ -295,19 +294,19 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
-/// + If `propName` is not supported by the platform.
+/// + If `PropName` is not supported by the platform.
/// - ::OFFLOAD_ERRC_INVALID_PLATFORM
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hPlatform`
+/// + `NULL == Platform`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pPropSizeRet`
+/// + `NULL == PropSizeRet`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
// [in] handle of the platform
- offload_platform_handle_t hPlatform,
+ offload_platform_handle_t Platform,
// [in] type of the info to query
- offload_platform_info_t propName,
+ offload_platform_info_t PropName,
// [out] pointer to the number of bytes required to store the query
- size_t *pPropSizeRet);
+ size_t *PropSizeRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported device types
@@ -355,14 +354,14 @@ typedef enum offload_device_info_t {
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hPlatform`
+/// + `NULL == Platform`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pNumDevices`
+/// + `NULL == NumDevices`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
// [in] handle of the platform instance
- offload_platform_handle_t hPlatform,
+ offload_platform_handle_t Platform,
// [out] pointer to the number of devices.
- uint32_t *pNumDevices);
+ uint32_t *NumDevices);
///////////////////////////////////////////////////////////////////////////////
/// @brief Retrieves devices within a platform
@@ -380,19 +379,19 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
/// - ::OFFLOAD_ERRC_INVALID_SIZE
/// + `NumEntries == 0`
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hPlatform`
+/// + `NULL == Platform`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == phDevices`
+/// + `NULL == Devices`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
// [in] handle of the platform instance
- offload_platform_handle_t hPlatform,
+ offload_platform_handle_t Platform,
// [in] the number of devices to be added to phDevices, which must be
// greater than zero
uint32_t NumEntries,
// [out] Array of device handles. If NumEntries is less than the number of
// devices available, then this function shall only retrieve that number of
// devices.
- offload_device_handle_t *phDevices);
+ offload_device_handle_t *Devices);
///////////////////////////////////////////////////////////////////////////////
/// @brief Queries the given property of the device
@@ -406,27 +405,27 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGet(
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
-/// + If `propName` is not supported by the device.
+/// + If `PropName` is not supported by the device.
/// - ::OFFLOAD_ERRC_INVALID_SIZE
-/// + `propSize == 0`
-/// + If `propSize` is less than the real number of bytes needed to
+/// + `PropSize == 0`
+/// + If `PropSize` is less than the real number of bytes needed to
/// return the info.
/// - ::OFFLOAD_ERRC_INVALID_DEVICE
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hDevice`
+/// + `NULL == Device`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pPropValue`
+/// + `NULL == PropValue`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
// [in] handle of the device instance
- offload_device_handle_t hDevice,
+ offload_device_handle_t Device,
// [in] type of the info to retrieve
- offload_device_info_t propName,
- // [in] the number of bytes pointed to by pPropValue.
- size_t propSize,
- // [out] array of bytes holding the info. If propSize is not equal to or
+ offload_device_info_t PropName,
+ // [in] the number of bytes pointed to by PropValue.
+ size_t PropSize,
+ // [out] array of bytes holding the info. If PropSize is not equal to or
// greater than the real number of bytes needed to return the info then the
- // OFFLOAD_ERRC_INVALID_SIZE error is returned and pPropValue is not used.
- void *pPropValue);
+ // OFFLOAD_ERRC_INVALID_SIZE error is returned and PropValue is not used.
+ void *PropValue);
///////////////////////////////////////////////////////////////////////////////
/// @brief Returns the storage size of the given device query
@@ -440,88 +439,88 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
/// - ::OFFLOAD_RESULT_ERROR_UNINITIALIZED
/// - ::OFFLOAD_RESULT_ERROR_DEVICE_LOST
/// - ::OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION
-/// + If `propName` is not supported by the device.
+/// + If `PropName` is not supported by the device.
/// - ::OFFLOAD_ERRC_INVALID_DEVICE
/// - ::OFFLOAD_ERRC_INVALID_NULL_HANDLE
-/// + `NULL == hDevice`
+/// + `NULL == Device`
/// - ::OFFLOAD_ERRC_INVALID_NULL_POINTER
-/// + `NULL == pPropSizeRet`
+/// + `NULL == PropSizeRet`
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfoSize(
// [in] handle of the device instance
- offload_device_handle_t hDevice,
+ offload_device_handle_t Device,
// [in] type of the info to retrieve
- offload_device_info_t propName,
+ offload_device_info_t PropName,
// [out] pointer to the number of bytes required to store the query
- size_t *pPropSizeRet);
+ size_t *PropSizeRet);
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGet
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_params_t {
uint32_t *pNumEntries;
- offload_platform_handle_t **pphPlatforms;
+ offload_platform_handle_t **pPlatforms;
} offload_platform_get_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGetCount
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_count_params_t {
- uint32_t **ppNumPlatforms;
+ uint32_t **pNumPlatforms;
} offload_platform_get_count_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGetInfo
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_info_params_t {
- offload_platform_handle_t *phPlatform;
- offload_platform_info_t *ppropName;
- size_t *ppropSize;
- void **ppPropValue;
+ offload_platform_handle_t *pPlatform;
+ offload_platform_info_t *pPropName;
+ size_t *pPropSize;
+ void **pPropValue;
} offload_platform_get_info_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadPlatformGetInfoSize
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_platform_get_info_size_params_t {
- offload_platform_handle_t *phPlatform;
- offload_platform_info_t *ppropName;
- size_t **ppPropSizeRet;
+ offload_platform_handle_t *pPlatform;
+ offload_platform_info_t *pPropName;
+ size_t **pPropSizeRet;
} offload_platform_get_info_size_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGetCount
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_count_params_t {
- offload_platform_handle_t *phPlatform;
- uint32_t **ppNumDevices;
+ offload_platform_handle_t *pPlatform;
+ uint32_t **pNumDevices;
} offload_device_get_count_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGet
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_params_t {
- offload_platform_handle_t *phPlatform;
+ offload_platform_handle_t *pPlatform;
uint32_t *pNumEntries;
- offload_device_handle_t **pphDevices;
+ offload_device_handle_t **pDevices;
} offload_device_get_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGetInfo
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_info_params_t {
- offload_device_handle_t *phDevice;
- offload_device_info_t *ppropName;
- size_t *ppropSize;
- void **ppPropValue;
+ offload_device_handle_t *pDevice;
+ offload_device_info_t *pPropName;
+ size_t *pPropSize;
+ void **pPropValue;
} offload_device_get_info_params_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for offloadDeviceGetInfoSize
/// @details Each entry is a pointer to the parameter passed to the function;
typedef struct offload_device_get_info_size_params_t {
- offload_device_handle_t *phDevice;
- offload_device_info_t *ppropName;
- size_t **ppPropSizeRet;
+ offload_device_handle_t *pDevice;
+ offload_device_info_t *pPropName;
+ size_t **pPropSizeRet;
} offload_device_get_info_size_params_t;
///////////////////////////////////////////////////////////////////////////////
@@ -529,14 +528,14 @@ typedef struct offload_device_get_info_size_params_t {
/// information
/// @details See also ::offloadInit
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadInitWithCodeLoc(offload_code_location_t *pCodeLocation);
+offloadInitWithCodeLoc(offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadShutDown that also sets source code location
/// information
/// @details See also ::offloadShutDown
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadShutDownWithCodeLoc(offload_code_location_t *pCodeLocation);
+offloadShutDownWithCodeLoc(offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGet that also sets source code location
@@ -544,73 +543,73 @@ offloadShutDownWithCodeLoc(offload_code_location_t *pCodeLocation);
/// @details See also ::offloadPlatformGet
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- offload_code_location_t *pCodeLocation);
+ offload_platform_handle_t *Platforms,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGetCount that also sets source code
/// location information
/// @details See also ::offloadPlatformGetCount
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetCountWithCodeLoc(uint32_t *pNumPlatforms,
- offload_code_location_t *pCodeLocation);
+offloadPlatformGetCountWithCodeLoc(uint32_t *NumPlatforms,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGetInfo that also sets source code location
/// information
/// @details See also ::offloadPlatformGetInfo
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetInfoWithCodeLoc(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t propSize, void *pPropValue,
- offload_code_location_t *pCodeLocation);
+offloadPlatformGetInfoWithCodeLoc(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName,
+ size_t PropSize, void *PropValue,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadPlatformGetInfoSize that also sets source code
/// location information
/// @details See also ::offloadPlatformGetInfoSize
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetInfoSizeWithCodeLoc(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t *pPropSizeRet,
- offload_code_location_t *pCodeLocation);
+offloadPlatformGetInfoSizeWithCodeLoc(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName,
+ size_t *PropSizeRet,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGetCount that also sets source code location
/// information
/// @details See also ::offloadDeviceGetCount
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t hPlatform,
- uint32_t *pNumDevices,
- offload_code_location_t *pCodeLocation);
+offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t Platform,
+ uint32_t *NumDevices,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGet that also sets source code location
/// information
/// @details See also ::offloadDeviceGet
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetWithCodeLoc(
- offload_platform_handle_t hPlatform, uint32_t NumEntries,
- offload_device_handle_t *phDevices, offload_code_location_t *pCodeLocation);
+ offload_platform_handle_t Platform, uint32_t NumEntries,
+ offload_device_handle_t *Devices, offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGetInfo that also sets source code location
/// information
/// @details See also ::offloadDeviceGetInfo
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t hDevice,
- offload_device_info_t propName, size_t propSize,
- void *pPropValue,
- offload_code_location_t *pCodeLocation);
+offloadDeviceGetInfoWithCodeLoc(offload_device_handle_t Device,
+ offload_device_info_t PropName, size_t PropSize,
+ void *PropValue,
+ offload_code_location_t *CodeLocation);
///////////////////////////////////////////////////////////////////////////////
/// @brief Variant of offloadDeviceGetInfoSize that also sets source code
/// location information
/// @details See also ::offloadDeviceGetInfoSize
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetInfoSizeWithCodeLoc(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t *pPropSizeRet,
- offload_code_location_t *pCodeLocation);
+offloadDeviceGetInfoSizeWithCodeLoc(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t *PropSizeRet,
+ offload_code_location_t *CodeLocation);
#if defined(__cplusplus)
} // extern "C"
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index cecc4699fb6646..f7971e6ba0d117 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -18,24 +18,23 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
std::cout << "---> offloadInit";
}
- offload_result_t result = offloadInit_val();
+ offload_result_t Result = offloadInit_val();
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "()";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
-offload_result_t
-offloadInitWithCodeLoc(offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadInit();
+offload_result_t offloadInitWithCodeLoc(offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadInit();
- CodeLocation() = nullptr;
- return result;
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
@@ -50,406 +49,403 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
std::cout << "---> offloadShutDown";
}
- offload_result_t result = offloadShutDown_val();
+ offload_result_t Result = offloadShutDown_val();
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "()";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t
-offloadShutDownWithCodeLoc(offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadShutDown();
+offloadShutDownWithCodeLoc(offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadShutDown();
- CodeLocation() = nullptr;
- return result;
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
offloadPlatformGet_val(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms) {
+ offload_platform_handle_t *Platforms) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (NULL == phPlatforms) {
+ if (NULL == Platforms) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGet_impl(NumEntries, phPlatforms);
+ return offloadPlatformGet_impl(NumEntries, Platforms);
}
-OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGet(
- uint32_t NumEntries, offload_platform_handle_t *phPlatforms) {
+OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
+offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *Platforms) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGet";
}
- offload_result_t result = offloadPlatformGet_val(NumEntries, phPlatforms);
+ offload_result_t Result = offloadPlatformGet_val(NumEntries, Platforms);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_params_t Params = {&NumEntries, &phPlatforms};
+ offload_platform_get_params_t Params = {&NumEntries, &Platforms};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t
offloadPlatformGetWithCodeLoc(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms,
- offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadPlatformGet(NumEntries, phPlatforms);
+ offload_platform_handle_t *Platforms,
+ offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadPlatformGet(NumEntries, Platforms);
- CodeLocation() = nullptr;
- return result;
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadPlatformGetCount_val(uint32_t *pNumPlatforms) {
+offload_impl_result_t offloadPlatformGetCount_val(uint32_t *NumPlatforms) {
if (true /*enableParameterValidation*/) {
- if (NULL == pNumPlatforms) {
+ if (NULL == NumPlatforms) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetCount_impl(pNumPlatforms);
+ return offloadPlatformGetCount_impl(NumPlatforms);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadPlatformGetCount(uint32_t *pNumPlatforms) {
+offloadPlatformGetCount(uint32_t *NumPlatforms) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGetCount";
}
- offload_result_t result = offloadPlatformGetCount_val(pNumPlatforms);
+ offload_result_t Result = offloadPlatformGetCount_val(NumPlatforms);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_count_params_t Params = {&pNumPlatforms};
+ offload_platform_get_count_params_t Params = {&NumPlatforms};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t
-offloadPlatformGetCountWithCodeLoc(uint32_t *pNumPlatforms,
- offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadPlatformGetCount(pNumPlatforms);
+offloadPlatformGetCountWithCodeLoc(uint32_t *NumPlatforms,
+ offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadPlatformGetCount(NumPlatforms);
- CodeLocation() = nullptr;
- return result;
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
-offloadPlatformGetInfo_val(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName, size_t propSize,
- void *pPropValue) {
+offloadPlatformGetInfo_val(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName, size_t PropSize,
+ void *PropValue) {
if (true /*enableParameterValidation*/) {
- if (propSize == 0) {
+ if (PropSize == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (NULL == hPlatform) {
+ if (NULL == Platform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == pPropValue) {
+ if (NULL == PropValue) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetInfo_impl(hPlatform, propName, propSize, pPropValue);
+ return offloadPlatformGetInfo_impl(Platform, PropName, PropSize, PropValue);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t propSize, void *pPropValue) {
+ offload_platform_handle_t Platform, offload_platform_info_t PropName,
+ size_t PropSize, void *PropValue) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGetInfo";
}
- offload_result_t result =
- offloadPlatformGetInfo_val(hPlatform, propName, propSize, pPropValue);
+ offload_result_t Result =
+ offloadPlatformGetInfo_val(Platform, PropName, PropSize, PropValue);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_info_params_t Params = {&hPlatform, &propName,
- &propSize, &pPropValue};
+ offload_platform_get_info_params_t Params = {&Platform, &PropName,
+ &PropSize, &PropValue};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t offloadPlatformGetInfoWithCodeLoc(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t propSize, void *pPropValue, offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result =
- offloadPlatformGetInfo(hPlatform, propName, propSize, pPropValue);
-
- CodeLocation() = nullptr;
- return result;
+ offload_platform_handle_t Platform, offload_platform_info_t PropName,
+ size_t PropSize, void *PropValue, offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result =
+ offloadPlatformGetInfo(Platform, PropName, PropSize, PropValue);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
-offloadPlatformGetInfoSize_val(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t *pPropSizeRet) {
+offloadPlatformGetInfoSize_val(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName,
+ size_t *PropSizeRet) {
if (true /*enableParameterValidation*/) {
- if (NULL == hPlatform) {
+ if (NULL == Platform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == pPropSizeRet) {
+ if (NULL == PropSizeRet) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadPlatformGetInfoSize_impl(hPlatform, propName, pPropSizeRet);
+ return offloadPlatformGetInfoSize_impl(Platform, PropName, PropSizeRet);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t *pPropSizeRet) {
+ offload_platform_handle_t Platform, offload_platform_info_t PropName,
+ size_t *PropSizeRet) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadPlatformGetInfoSize";
}
- offload_result_t result =
- offloadPlatformGetInfoSize_val(hPlatform, propName, pPropSizeRet);
+ offload_result_t Result =
+ offloadPlatformGetInfoSize_val(Platform, PropName, PropSizeRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_platform_get_info_size_params_t Params = {&hPlatform, &propName,
- &pPropSizeRet};
+ offload_platform_get_info_size_params_t Params = {&Platform, &PropName,
+ &PropSizeRet};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t offloadPlatformGetInfoSizeWithCodeLoc(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t *pPropSizeRet, offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result =
- offloadPlatformGetInfoSize(hPlatform, propName, pPropSizeRet);
-
- CodeLocation() = nullptr;
- return result;
+ offload_platform_handle_t Platform, offload_platform_info_t PropName,
+ size_t *PropSizeRet, offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result =
+ offloadPlatformGetInfoSize(Platform, PropName, PropSizeRet);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
-offloadDeviceGetCount_val(offload_platform_handle_t hPlatform,
- uint32_t *pNumDevices) {
+offloadDeviceGetCount_val(offload_platform_handle_t Platform,
+ uint32_t *NumDevices) {
if (true /*enableParameterValidation*/) {
- if (NULL == hPlatform) {
+ if (NULL == Platform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == pNumDevices) {
+ if (NULL == NumDevices) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetCount_impl(hPlatform, pNumDevices);
+ return offloadDeviceGetCount_impl(Platform, NumDevices);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
- offload_platform_handle_t hPlatform, uint32_t *pNumDevices) {
+ offload_platform_handle_t Platform, uint32_t *NumDevices) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGetCount";
}
- offload_result_t result = offloadDeviceGetCount_val(hPlatform, pNumDevices);
+ offload_result_t Result = offloadDeviceGetCount_val(Platform, NumDevices);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_count_params_t Params = {&hPlatform, &pNumDevices};
+ offload_device_get_count_params_t Params = {&Platform, &NumDevices};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t
-offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t hPlatform,
- uint32_t *pNumDevices,
- offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadDeviceGetCount(hPlatform, pNumDevices);
-
- CodeLocation() = nullptr;
- return result;
+offloadDeviceGetCountWithCodeLoc(offload_platform_handle_t Platform,
+ uint32_t *NumDevices,
+ offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadDeviceGetCount(Platform, NumDevices);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t hPlatform,
+offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t Platform,
uint32_t NumEntries,
- offload_device_handle_t *phDevices) {
+ offload_device_handle_t *Devices) {
if (true /*enableParameterValidation*/) {
if (NumEntries == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (NULL == hPlatform) {
+ if (NULL == Platform) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == phDevices) {
+ if (NULL == Devices) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGet_impl(hPlatform, NumEntries, phDevices);
+ return offloadDeviceGet_impl(Platform, NumEntries, Devices);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGet(offload_platform_handle_t hPlatform, uint32_t NumEntries,
- offload_device_handle_t *phDevices) {
+offloadDeviceGet(offload_platform_handle_t Platform, uint32_t NumEntries,
+ offload_device_handle_t *Devices) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGet";
}
- offload_result_t result =
- offloadDeviceGet_val(hPlatform, NumEntries, phDevices);
+ offload_result_t Result = offloadDeviceGet_val(Platform, NumEntries, Devices);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_params_t Params = {&hPlatform, &NumEntries, &phDevices};
+ offload_device_get_params_t Params = {&Platform, &NumEntries, &Devices};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
-offload_result_t
-offloadDeviceGetWithCodeLoc(offload_platform_handle_t hPlatform,
- uint32_t NumEntries,
- offload_device_handle_t *phDevices,
- offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result = offloadDeviceGet(hPlatform, NumEntries, phDevices);
-
- CodeLocation() = nullptr;
- return result;
+offload_result_t offloadDeviceGetWithCodeLoc(
+ offload_platform_handle_t Platform, uint32_t NumEntries,
+ offload_device_handle_t *Devices, offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result = offloadDeviceGet(Platform, NumEntries, Devices);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
-offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize,
- void *pPropValue) {
+offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t PropSize,
+ void *PropValue) {
if (true /*enableParameterValidation*/) {
- if (propSize == 0) {
+ if (PropSize == 0) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
- if (NULL == hDevice) {
+ if (NULL == Device) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == pPropValue) {
+ if (NULL == PropValue) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetInfo_impl(hDevice, propName, propSize, pPropValue);
+ return offloadDeviceGetInfo_impl(Device, PropName, PropSize, PropValue);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
- offload_device_handle_t hDevice, offload_device_info_t propName,
- size_t propSize, void *pPropValue) {
+ offload_device_handle_t Device, offload_device_info_t PropName,
+ size_t PropSize, void *PropValue) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGetInfo";
}
- offload_result_t result =
- offloadDeviceGetInfo_val(hDevice, propName, propSize, pPropValue);
+ offload_result_t Result =
+ offloadDeviceGetInfo_val(Device, PropName, PropSize, PropValue);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_info_params_t Params = {&hDevice, &propName, &propSize,
- &pPropValue};
+ offload_device_get_info_params_t Params = {&Device, &PropName, &PropSize,
+ &PropValue};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t offloadDeviceGetInfoWithCodeLoc(
- offload_device_handle_t hDevice, offload_device_info_t propName,
- size_t propSize, void *pPropValue, offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result =
- offloadDeviceGetInfo(hDevice, propName, propSize, pPropValue);
-
- CodeLocation() = nullptr;
- return result;
+ offload_device_handle_t Device, offload_device_info_t PropName,
+ size_t PropSize, void *PropValue, offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result =
+ offloadDeviceGetInfo(Device, PropName, PropSize, PropValue);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
///////////////////////////////////////////////////////////////////////////////
offload_impl_result_t
-offloadDeviceGetInfoSize_val(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t *pPropSizeRet) {
+offloadDeviceGetInfoSize_val(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t *PropSizeRet) {
if (true /*enableParameterValidation*/) {
- if (NULL == hDevice) {
+ if (NULL == Device) {
return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
}
- if (NULL == pPropSizeRet) {
+ if (NULL == PropSizeRet) {
return OFFLOAD_ERRC_INVALID_NULL_POINTER;
}
}
- return offloadDeviceGetInfoSize_impl(hDevice, propName, pPropSizeRet);
+ return offloadDeviceGetInfoSize_impl(Device, PropName, PropSizeRet);
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
-offloadDeviceGetInfoSize(offload_device_handle_t hDevice,
- offload_device_info_t propName, size_t *pPropSizeRet) {
+offloadDeviceGetInfoSize(offload_device_handle_t Device,
+ offload_device_info_t PropName, size_t *PropSizeRet) {
if (std::getenv("OFFLOAD_TRACE")) {
std::cout << "---> offloadDeviceGetInfoSize";
}
- offload_result_t result =
- offloadDeviceGetInfoSize_val(hDevice, propName, pPropSizeRet);
+ offload_result_t Result =
+ offloadDeviceGetInfoSize_val(Device, PropName, PropSizeRet);
if (std::getenv("OFFLOAD_TRACE")) {
- offload_device_get_info_size_params_t Params = {&hDevice, &propName,
- &pPropSizeRet};
+ offload_device_get_info_size_params_t Params = {&Device, &PropName,
+ &PropSizeRet};
std::cout << "(" << &Params << ")";
- std::cout << "-> " << result << "\n";
- if (result && result->details) {
- std::cout << " *Error Details* " << result->details << " \n";
+ std::cout << "-> " << Result << "\n";
+ if (Result && Result->Details) {
+ std::cout << " *Error Details* " << Result->Details << " \n";
}
}
- return result;
+ return Result;
}
offload_result_t offloadDeviceGetInfoSizeWithCodeLoc(
- offload_device_handle_t hDevice, offload_device_info_t propName,
- size_t *pPropSizeRet, offload_code_location_t *pCodeLocation) {
- CodeLocation() = pCodeLocation;
- offload_result_t result =
- offloadDeviceGetInfoSize(hDevice, propName, pPropSizeRet);
-
- CodeLocation() = nullptr;
- return result;
+ offload_device_handle_t Device, offload_device_info_t PropName,
+ size_t *PropSizeRet, offload_code_location_t *CodeLocation) {
+ currentCodeLocation() = CodeLocation;
+ offload_result_t Result =
+ offloadDeviceGetInfoSize(Device, PropName, PropSizeRet);
+
+ currentCodeLocation() = nullptr;
+ return Result;
}
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
index b7be0f0782e935..21e2f40a69d9f6 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/new-api/include/offload_impl.hpp
@@ -22,7 +22,7 @@
// Use the StringSet container to efficiently deduplicate repeated error
// strings (e.g. if the same error is hit constantly in a long running program)
-llvm::StringSet<> &ErrorStrs();
+llvm::StringSet<> &errorStrs();
// Use an unordered_set to avoid duplicates of error structs themselves.
// We cannot store the structs directly as returned pointers to them must always
@@ -39,12 +39,12 @@ struct ErrPtrEqual {
}
bool StrsEqual = false;
- if (lhs->details == NULL && rhs->details == NULL) {
+ if (lhs->Details == NULL && rhs->Details == NULL) {
StrsEqual = true;
- } else if (lhs->details != NULL && rhs->details != NULL) {
- StrsEqual = (std::strcmp(lhs->details, rhs->details) == 0);
+ } else if (lhs->Details != NULL && rhs->Details != NULL) {
+ StrsEqual = (std::strcmp(lhs->Details, rhs->Details) == 0);
}
- return (lhs->code == rhs->code) && StrsEqual;
+ return (lhs->Code == rhs->Code) && StrsEqual;
}
};
struct ErrPtrHash {
@@ -53,12 +53,12 @@ struct ErrPtrHash {
// We shouldn't store empty errors (i.e. success), but just in case
return 0lu;
} else {
- return std::hash<int>{}(e->code);
+ return std::hash<int>{}(e->Code);
}
}
};
using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
-ErrSetT &Errors();
+ErrSetT &errors();
struct offload_impl_result_t {
offload_impl_result_t(std::nullptr_t) : Result(OFFLOAD_RESULT_SUCCESS) {}
@@ -68,17 +68,17 @@ struct offload_impl_result_t {
} else {
auto Err = std::unique_ptr<offload_error_struct_t>(
new offload_error_struct_t{Code, nullptr});
- Result = Errors().emplace(std::move(Err)).first->get();
+ Result = errors().emplace(std::move(Err)).first->get();
}
}
offload_impl_result_t(offload_errc_t Code, llvm::StringRef Details) {
assert(Code != OFFLOAD_ERRC_SUCCESS);
Result = nullptr;
- auto DetailsStr = ErrorStrs().insert(Details).first->getKeyData();
+ auto DetailsStr = errorStrs().insert(Details).first->getKeyData();
auto Err = std::unique_ptr<offload_error_struct_t>(
new offload_error_struct_t{Code, DetailsStr});
- Result = Errors().emplace(std::move(Err)).first->get();
+ Result = errors().emplace(std::move(Err)).first->get();
}
operator offload_result_t() { return Result; }
diff --git a/offload/new-api/include/offload_impl_func_decls.inc b/offload/new-api/include/offload_impl_func_decls.inc
index 4dfedd0cde26b2..c56a393ae492a3 100644
--- a/offload/new-api/include/offload_impl_func_decls.inc
+++ b/offload/new-api/include/offload_impl_func_decls.inc
@@ -11,34 +11,34 @@ offload_impl_result_t offloadShutDown_impl();
offload_impl_result_t
offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms);
+ offload_platform_handle_t *Platforms);
-offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *pNumPlatforms);
+offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *NumPlatforms);
offload_impl_result_t
-offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName, size_t propSize,
- void *pPropValue);
+offloadPlatformGetInfo_impl(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName, size_t PropSize,
+ void *PropValue);
offload_impl_result_t
-offloadPlatformGetInfoSize_impl(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t *pPropSizeRet);
+offloadPlatformGetInfoSize_impl(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName,
+ size_t *PropSizeRet);
offload_impl_result_t
-offloadDeviceGetCount_impl(offload_platform_handle_t hPlatform,
- uint32_t *pNumDevices);
+offloadDeviceGetCount_impl(offload_platform_handle_t Platform,
+ uint32_t *NumDevices);
-offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t hPlatform,
+offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t Platform,
uint32_t NumEntries,
- offload_device_handle_t *phDevices);
+ offload_device_handle_t *Devices);
-offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize,
- void *pPropValue);
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t PropSize,
+ void *PropValue);
offload_impl_result_t
-offloadDeviceGetInfoSize_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t *pPropSizeRet);
+offloadDeviceGetInfoSize_impl(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t *PropSizeRet);
diff --git a/offload/new-api/include/offload_print.hpp b/offload/new-api/include/offload_print.hpp
index 35245fd9e736a4..36c4bed2b14669 100644
--- a/offload/new-api/include/offload_print.hpp
+++ b/offload/new-api/include/offload_print.hpp
@@ -281,11 +281,11 @@ inline void printTagged(std::ostream &os, const void *ptr,
}
inline std::ostream &operator<<(std::ostream &os,
- const offload_error_struct_t *err) {
- if (err == nullptr) {
+ const offload_error_struct_t *Err) {
+ if (Err == nullptr) {
os << "OFFLOAD_RESULT_SUCCESS";
} else {
- os << err->code;
+ os << Err->Code;
}
return os;
}
@@ -296,13 +296,13 @@ inline std::ostream &operator<<(
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
- os << ".phPlatforms = ";
+ os << ".Platforms = ";
os << "{";
for (size_t i = 0; i < *params->pNumEntries; i++) {
if (i > 0) {
os << ", ";
}
- printPtr(os, (*params->pphPlatforms)[i]);
+ printPtr(os, (*params->pPlatforms)[i]);
}
os << "}";
return os;
@@ -311,25 +311,25 @@ inline std::ostream &operator<<(
inline std::ostream &operator<<(
std::ostream &os,
[[maybe_unused]] const struct offload_platform_get_count_params_t *params) {
- os << ".pNumPlatforms = ";
- printPtr(os, *params->ppNumPlatforms);
+ os << ".NumPlatforms = ";
+ printPtr(os, *params->pNumPlatforms);
return os;
}
inline std::ostream &operator<<(
std::ostream &os,
[[maybe_unused]] const struct offload_platform_get_info_params_t *params) {
- os << ".hPlatform = ";
- printPtr(os, *params->phPlatform);
+ os << ".Platform = ";
+ printPtr(os, *params->pPlatform);
os << ", ";
- os << ".propName = ";
- os << *params->ppropName;
+ os << ".PropName = ";
+ os << *params->pPropName;
os << ", ";
- os << ".propSize = ";
- os << *params->ppropSize;
+ os << ".PropSize = ";
+ os << *params->pPropSize;
os << ", ";
- os << ".pPropValue = ";
- printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ os << ".PropValue = ";
+ printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
return os;
}
@@ -337,44 +337,44 @@ inline std::ostream &
operator<<(std::ostream &os,
[[maybe_unused]] const struct offload_platform_get_info_size_params_t
*params) {
- os << ".hPlatform = ";
- printPtr(os, *params->phPlatform);
+ os << ".Platform = ";
+ printPtr(os, *params->pPlatform);
os << ", ";
- os << ".propName = ";
- os << *params->ppropName;
+ os << ".PropName = ";
+ os << *params->pPropName;
os << ", ";
- os << ".pPropSizeRet = ";
- printPtr(os, *params->ppPropSizeRet);
+ os << ".PropSizeRet = ";
+ printPtr(os, *params->pPropSizeRet);
return os;
}
inline std::ostream &operator<<(
std::ostream &os,
[[maybe_unused]] const struct offload_device_get_count_params_t *params) {
- os << ".hPlatform = ";
- printPtr(os, *params->phPlatform);
+ os << ".Platform = ";
+ printPtr(os, *params->pPlatform);
os << ", ";
- os << ".pNumDevices = ";
- printPtr(os, *params->ppNumDevices);
+ os << ".NumDevices = ";
+ printPtr(os, *params->pNumDevices);
return os;
}
inline std::ostream &
operator<<(std::ostream &os,
[[maybe_unused]] const struct offload_device_get_params_t *params) {
- os << ".hPlatform = ";
- printPtr(os, *params->phPlatform);
+ os << ".Platform = ";
+ printPtr(os, *params->pPlatform);
os << ", ";
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
- os << ".phDevices = ";
+ os << ".Devices = ";
os << "{";
for (size_t i = 0; i < *params->pNumEntries; i++) {
if (i > 0) {
os << ", ";
}
- printPtr(os, (*params->pphDevices)[i]);
+ printPtr(os, (*params->pDevices)[i]);
}
os << "}";
return os;
@@ -383,17 +383,17 @@ operator<<(std::ostream &os,
inline std::ostream &operator<<(
std::ostream &os,
[[maybe_unused]] const struct offload_device_get_info_params_t *params) {
- os << ".hDevice = ";
- printPtr(os, *params->phDevice);
+ os << ".Device = ";
+ printPtr(os, *params->pDevice);
os << ", ";
- os << ".propName = ";
- os << *params->ppropName;
+ os << ".PropName = ";
+ os << *params->pPropName;
os << ", ";
- os << ".propSize = ";
- os << *params->ppropSize;
+ os << ".PropSize = ";
+ os << *params->pPropSize;
os << ", ";
- os << ".pPropValue = ";
- printTagged(os, *params->ppPropValue, *params->ppropName, *params->ppropSize);
+ os << ".PropValue = ";
+ printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
return os;
}
@@ -401,14 +401,14 @@ inline std::ostream &
operator<<(std::ostream &os,
[[maybe_unused]] const struct offload_device_get_info_size_params_t
*params) {
- os << ".hDevice = ";
- printPtr(os, *params->phDevice);
+ os << ".Device = ";
+ printPtr(os, *params->pDevice);
os << ", ";
- os << ".propName = ";
- os << *params->ppropName;
+ os << ".PropName = ";
+ os << *params->pPropName;
os << ", ";
- os << ".pPropSizeRet = ";
- printPtr(os, *params->ppPropSizeRet);
+ os << ".PropSizeRet = ";
+ printPtr(os, *params->pPropSizeRet);
return os;
}
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index af26c28768b946..3498510b6c27b3 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -77,17 +77,17 @@ offload_impl_result_t offloadInit_impl() {
}
offload_impl_result_t offloadShutDown_impl() { return OFFLOAD_RESULT_SUCCESS; }
-offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *pNumPlatforms) {
+offload_impl_result_t offloadPlatformGetCount_impl(uint32_t *NumPlatforms) {
// It is expected that offloadPlatformGet is the first function to be called.
// In future it may make sense to have a specific entry point for Offload
// initialization, or expose explicit initialization of plugins.
- *pNumPlatforms = Platforms().size();
+ *NumPlatforms = Platforms().size();
return OFFLOAD_RESULT_SUCCESS;
}
offload_impl_result_t
offloadPlatformGet_impl(uint32_t NumEntries,
- offload_platform_handle_t *phPlatforms) {
+ offload_platform_handle_t *PlatformsOut) {
if (NumEntries > Platforms().size()) {
return {OFFLOAD_ERRC_INVALID_SIZE,
std::string{formatv("{0} platform(s) available but {1} requested.",
@@ -96,20 +96,20 @@ offloadPlatformGet_impl(uint32_t NumEntries,
for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
PlatformIndex++) {
- phPlatforms[PlatformIndex] = &(Platforms())[PlatformIndex];
+ PlatformsOut[PlatformIndex] = &(Platforms())[PlatformIndex];
}
return OFFLOAD_RESULT_SUCCESS;
}
offload_impl_result_t offloadPlatformGetInfoImplDetail(
- offload_platform_handle_t hPlatform, offload_platform_info_t propName,
- size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
- ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
+ offload_platform_handle_t Platform, offload_platform_info_t PropName,
+ size_t PropSize, void *PropValue, size_t *PropSizeRet) {
+ ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
- switch (propName) {
+ switch (PropName) {
case OFFLOAD_PLATFORM_INFO_NAME:
- return ReturnValue(hPlatform->Plugin->getName());
+ return ReturnValue(Platform->Plugin->getName());
case OFFLOAD_PLATFORM_INFO_VENDOR_NAME:
// TODO: Implement this
return ReturnValue("Unknown platform vendor");
@@ -118,7 +118,7 @@ offload_impl_result_t offloadPlatformGetInfoImplDetail(
return ReturnValue("v0.0.0");
}
case OFFLOAD_PLATFORM_INFO_BACKEND: {
- auto PluginName = hPlatform->Plugin->getName();
+ auto PluginName = Platform->Plugin->getName();
if (PluginName == StringRef("CUDA")) {
return ReturnValue(OFFLOAD_PLATFORM_BACKEND_CUDA);
} else if (PluginName == StringRef("AMDGPU")) {
@@ -135,59 +135,59 @@ offload_impl_result_t offloadPlatformGetInfoImplDetail(
}
offload_impl_result_t
-offloadPlatformGetInfo_impl(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName, size_t propSize,
- void *pPropValue) {
- return offloadPlatformGetInfoImplDetail(hPlatform, propName, propSize,
- pPropValue, nullptr);
+offloadPlatformGetInfo_impl(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName, size_t PropSize,
+ void *PropValue) {
+ return offloadPlatformGetInfoImplDetail(Platform, PropName, PropSize,
+ PropValue, nullptr);
}
offload_impl_result_t
-offloadPlatformGetInfoSize_impl(offload_platform_handle_t hPlatform,
- offload_platform_info_t propName,
- size_t *pPropSizeRet) {
- return offloadPlatformGetInfoImplDetail(hPlatform, propName, 0, nullptr,
- pPropSizeRet);
+offloadPlatformGetInfoSize_impl(offload_platform_handle_t Platform,
+ offload_platform_info_t PropName,
+ size_t *PropSizeRet) {
+ return offloadPlatformGetInfoImplDetail(Platform, PropName, 0, nullptr,
+ PropSizeRet);
}
offload_impl_result_t
-offloadDeviceGetCount_impl(offload_platform_handle_t hPlatform,
+offloadDeviceGetCount_impl(offload_platform_handle_t Platform,
uint32_t *pNumDevices) {
- *pNumDevices = static_cast<uint32_t>(hPlatform->Devices.size());
+ *pNumDevices = static_cast<uint32_t>(Platform->Devices.size());
return OFFLOAD_RESULT_SUCCESS;
}
-offload_impl_result_t
-offloadDeviceGet_impl(offload_platform_handle_t hPlatform, uint32_t NumEntries,
- offload_device_handle_t *phDevices) {
- if (NumEntries > hPlatform->Devices.size()) {
+offload_impl_result_t offloadDeviceGet_impl(offload_platform_handle_t Platform,
+ uint32_t NumEntries,
+ offload_device_handle_t *Devices) {
+ if (NumEntries > Platform->Devices.size()) {
return OFFLOAD_ERRC_INVALID_SIZE;
}
for (uint32_t DeviceIndex = 0; DeviceIndex < NumEntries; DeviceIndex++) {
- phDevices[DeviceIndex] = &(hPlatform->Devices[DeviceIndex]);
+ Devices[DeviceIndex] = &(Platform->Devices[DeviceIndex]);
}
return OFFLOAD_RESULT_SUCCESS;
}
offload_impl_result_t
-offloadDeviceGetInfoImplDetail(offload_device_handle_t hDevice,
- offload_device_info_t propName, size_t propSize,
- void *pPropValue, size_t *pPropSizeRet) {
+offloadDeviceGetInfoImplDetail(offload_device_handle_t Device,
+ offload_device_info_t PropName, size_t PropSize,
+ void *PropValue, size_t *PropSizeRet) {
- ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
+ ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
InfoQueueTy DevInfo;
- if (auto Err = hDevice->Device.obtainInfoImpl(DevInfo))
+ if (auto Err = Device->Device.obtainInfoImpl(DevInfo))
return OFFLOAD_ERRC_OUT_OF_RESOURCES;
// Find the info if it exists under any of the given names
auto GetInfo = [&DevInfo](std::vector<std::string> Names) {
for (auto Name : Names) {
- auto InfoKeyMatches = [&](const InfoQueueTy::InfoQueueEntryTy &info) {
- return info.Key == Name;
+ auto InfoKeyMatches = [&](const InfoQueueTy::InfoQueueEntryTy &Info) {
+ return Info.Key == Name;
};
auto Item = std::find_if(DevInfo.getQueue().begin(),
DevInfo.getQueue().end(), InfoKeyMatches);
@@ -200,9 +200,9 @@ offloadDeviceGetInfoImplDetail(offload_device_handle_t hDevice,
return std::string("");
};
- switch (propName) {
+ switch (PropName) {
case OFFLOAD_DEVICE_INFO_PLATFORM:
- return ReturnValue(hDevice->Platform);
+ return ReturnValue(Device->Platform);
case OFFLOAD_DEVICE_INFO_TYPE:
return ReturnValue(OFFLOAD_DEVICE_TYPE_GPU);
case OFFLOAD_DEVICE_INFO_NAME:
@@ -219,18 +219,18 @@ offloadDeviceGetInfoImplDetail(offload_device_handle_t hDevice,
return OFFLOAD_RESULT_SUCCESS;
}
-offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t propSize,
- void *pPropValue) {
- return offloadDeviceGetInfoImplDetail(hDevice, propName, propSize, pPropValue,
+offload_impl_result_t offloadDeviceGetInfo_impl(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t PropSize,
+ void *PropValue) {
+ return offloadDeviceGetInfoImplDetail(Device, PropName, PropSize, PropValue,
nullptr);
}
offload_impl_result_t
-offloadDeviceGetInfoSize_impl(offload_device_handle_t hDevice,
- offload_device_info_t propName,
- size_t *pPropSizeRet) {
- return offloadDeviceGetInfoImplDetail(hDevice, propName, 0, nullptr,
- pPropSizeRet);
+offloadDeviceGetInfoSize_impl(offload_device_handle_t Device,
+ offload_device_info_t PropName,
+ size_t *PropSizeRet) {
+ return offloadDeviceGetInfoImplDetail(Device, PropName, 0, nullptr,
+ PropSizeRet);
}
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index 2635152c0910a8..1b5acdfeb6f7e1 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -16,17 +16,17 @@
#include <iostream>
-llvm::StringSet<> &ErrorStrs() {
+llvm::StringSet<> &errorStrs() {
static llvm::StringSet<> ErrorStrs;
return ErrorStrs;
}
-ErrSetT &Errors() {
+ErrSetT &errors() {
static ErrSetT Errors{};
return Errors;
}
-offload_code_location_t *&CodeLocation() {
+offload_code_location_t *¤tCodeLocation() {
thread_local offload_code_location_t *CodeLoc = nullptr;
return CodeLoc;
}
diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp
index c50146f351288e..29b5d2efb16f2d 100644
--- a/offload/tools/offload-tblgen/APIGen.cpp
+++ b/offload/tools/offload-tblgen/APIGen.cpp
@@ -187,7 +187,7 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL {0}WithCodeLoc(
OS << " " << Param.getType() << " " << Param.getName();
OS << ",\n";
}
- OS << "offload_code_location_t *pCodeLocation);\n\n";
+ OS << "offload_code_location_t *CodeLocation);\n\n";
}
void EmitOffloadAPI(RecordKeeper &Records, raw_ostream &OS) {
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index 16adcdce1e07e2..b9bbfedddba5cb 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -77,7 +77,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
// Perform actual function call to the validation wrapper
ParamNameList = ParamNameList.substr(0, ParamNameList.size() - 2);
- OS << formatv(TAB_1 "{0}_result_t result = {1}_val({2});\n\n", PrefixLower,
+ OS << formatv(TAB_1 "{0}_result_t Result = {1}_val({2});\n\n", PrefixLower,
F.getName(), ParamNameList);
// Emit post-call prints
@@ -95,14 +95,14 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
} else {
OS << TAB_2 "std::cout << \"()\";\n";
}
- OS << TAB_2 "std::cout << \"-> \" << result << \"\\n\";\n";
- OS << TAB_2 "if (result && result->details) {\n";
- OS << TAB_3 "std::cout << \" *Error Details* \" << result->details "
+ OS << TAB_2 "std::cout << \"-> \" << Result << \"\\n\";\n";
+ OS << TAB_2 "if (Result && Result->Details) {\n";
+ OS << TAB_3 "std::cout << \" *Error Details* \" << Result->Details "
"<< \" \\n\";\n";
OS << TAB_2 "}\n";
OS << TAB_1 "}\n";
- OS << TAB_1 "return result;\n";
+ OS << TAB_1 "return Result;\n";
OS << "}\n";
}
@@ -118,13 +118,13 @@ static void EmitCodeLocWrapper(const FunctionRec &F, raw_ostream &OS) {
ParamNameList += ", ";
}
}
- OS << "offload_code_location_t *pCodeLocation";
+ OS << "offload_code_location_t *CodeLocation";
OS << ") {\n";
- OS << TAB_1 "CodeLocation() = pCodeLocation;\n";
- OS << formatv(TAB_1 "{0}_result_t result = {1}({2});\n\n", PrefixLower,
+ OS << TAB_1 "currentCodeLocation() = CodeLocation;\n";
+ OS << formatv(TAB_1 "{0}_result_t Result = {1}({2});\n\n", PrefixLower,
F.getName(), ParamNameList);
- OS << TAB_1 "CodeLocation() = nullptr;\n";
- OS << TAB_1 "return result;\n";
+ OS << TAB_1 "currentCodeLocation() = nullptr;\n";
+ OS << TAB_1 "return Result;\n";
OS << "}\n";
}
diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp
index ef9ecf0f3ac235..e8dc84f9170fdf 100644
--- a/offload/tools/offload-tblgen/PrintGen.cpp
+++ b/offload/tools/offload-tblgen/PrintGen.cpp
@@ -97,11 +97,11 @@ inline void printTagged(std::ostream &os, const void *ptr, {0} value, size_t siz
static void EmitResultPrint(raw_ostream &OS) {
OS << R""(
inline std::ostream &operator<<(std::ostream &os,
- const offload_error_struct_t *err) {
- if (err == nullptr) {
+ const offload_error_struct_t *Err) {
+ if (Err == nullptr) {
os << "OFFLOAD_RESULT_SUCCESS";
} else {
- os << err->code;
+ os << Err->Code;
}
return os;
}
diff --git a/offload/unittests/OffloadAPI/common/fixtures.hpp b/offload/unittests/OffloadAPI/common/fixtures.hpp
index 5dcf6232504bd9..7c5e85acb8d94e 100644
--- a/offload/unittests/OffloadAPI/common/fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/fixtures.hpp
@@ -23,7 +23,7 @@
#define ASSERT_ERROR(EXPECTED, ACTUAL) \
do { \
offload_result_t Res = ACTUAL; \
- ASSERT_TRUE(Res && (Res->code == EXPECTED)); \
+ ASSERT_TRUE(Res && (Res->Code == EXPECTED)); \
} while (0)
#endif
>From 87ddac34ecfe64d6f0736b2d5e622a199860004a Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Fri, 25 Oct 2024 12:17:49 +0100
Subject: [PATCH 14/14] Only check OFFLOAD_TRACE once
---
.../new-api/include/offload_entry_points.inc | 40 +++++++++----------
offload/new-api/include/offload_impl.hpp | 6 +++
offload/new-api/src/offload_impl.cpp | 2 +
offload/new-api/src/offload_lib.cpp | 5 +++
.../tools/offload-tblgen/EntryPointGen.cpp | 4 +-
5 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/offload/new-api/include/offload_entry_points.inc b/offload/new-api/include/offload_entry_points.inc
index f7971e6ba0d117..a21a0ca56cfe6a 100644
--- a/offload/new-api/include/offload_entry_points.inc
+++ b/offload/new-api/include/offload_entry_points.inc
@@ -14,13 +14,13 @@ offload_impl_result_t offloadInit_val() {
return offloadInit_impl();
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadInit() {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadInit";
}
offload_result_t Result = offloadInit_val();
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "()";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -45,13 +45,13 @@ offload_impl_result_t offloadShutDown_val() {
return offloadShutDown_impl();
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadShutDown() {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadShutDown";
}
offload_result_t Result = offloadShutDown_val();
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "()";
std::cout << "-> " << Result << "\n";
if (Result && Result->Details) {
@@ -87,13 +87,13 @@ offloadPlatformGet_val(uint32_t NumEntries,
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadPlatformGet(uint32_t NumEntries, offload_platform_handle_t *Platforms) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadPlatformGet";
}
offload_result_t Result = offloadPlatformGet_val(NumEntries, Platforms);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_platform_get_params_t Params = {&NumEntries, &Platforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
@@ -126,13 +126,13 @@ offload_impl_result_t offloadPlatformGetCount_val(uint32_t *NumPlatforms) {
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadPlatformGetCount(uint32_t *NumPlatforms) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadPlatformGetCount";
}
offload_result_t Result = offloadPlatformGetCount_val(NumPlatforms);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_platform_get_count_params_t Params = {&NumPlatforms};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
@@ -176,14 +176,14 @@ offloadPlatformGetInfo_val(offload_platform_handle_t Platform,
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfo(
offload_platform_handle_t Platform, offload_platform_info_t PropName,
size_t PropSize, void *PropValue) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadPlatformGetInfo";
}
offload_result_t Result =
offloadPlatformGetInfo_val(Platform, PropName, PropSize, PropValue);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_platform_get_info_params_t Params = {&Platform, &PropName,
&PropSize, &PropValue};
std::cout << "(" << &Params << ")";
@@ -225,14 +225,14 @@ offloadPlatformGetInfoSize_val(offload_platform_handle_t Platform,
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetInfoSize(
offload_platform_handle_t Platform, offload_platform_info_t PropName,
size_t *PropSizeRet) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadPlatformGetInfoSize";
}
offload_result_t Result =
offloadPlatformGetInfoSize_val(Platform, PropName, PropSizeRet);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_platform_get_info_size_params_t Params = {&Platform, &PropName,
&PropSizeRet};
std::cout << "(" << &Params << ")";
@@ -272,13 +272,13 @@ offloadDeviceGetCount_val(offload_platform_handle_t Platform,
}
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetCount(
offload_platform_handle_t Platform, uint32_t *NumDevices) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadDeviceGetCount";
}
offload_result_t Result = offloadDeviceGetCount_val(Platform, NumDevices);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_device_get_count_params_t Params = {&Platform, &NumDevices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
@@ -322,13 +322,13 @@ offload_impl_result_t offloadDeviceGet_val(offload_platform_handle_t Platform,
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadDeviceGet(offload_platform_handle_t Platform, uint32_t NumEntries,
offload_device_handle_t *Devices) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadDeviceGet";
}
offload_result_t Result = offloadDeviceGet_val(Platform, NumEntries, Devices);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_device_get_params_t Params = {&Platform, &NumEntries, &Devices};
std::cout << "(" << &Params << ")";
std::cout << "-> " << Result << "\n";
@@ -372,14 +372,14 @@ offload_impl_result_t offloadDeviceGetInfo_val(offload_device_handle_t Device,
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadDeviceGetInfo(
offload_device_handle_t Device, offload_device_info_t PropName,
size_t PropSize, void *PropValue) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadDeviceGetInfo";
}
offload_result_t Result =
offloadDeviceGetInfo_val(Device, PropName, PropSize, PropValue);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_device_get_info_params_t Params = {&Device, &PropName, &PropSize,
&PropValue};
std::cout << "(" << &Params << ")";
@@ -421,14 +421,14 @@ offloadDeviceGetInfoSize_val(offload_device_handle_t Device,
OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL
offloadDeviceGetInfoSize(offload_device_handle_t Device,
offload_device_info_t PropName, size_t *PropSizeRet) {
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
std::cout << "---> offloadDeviceGetInfoSize";
}
offload_result_t Result =
offloadDeviceGetInfoSize_val(Device, PropName, PropSizeRet);
- if (std::getenv("OFFLOAD_TRACE")) {
+ if (offloadConfig().TracingEnabled) {
offload_device_get_info_size_params_t Params = {&Device, &PropName,
&PropSizeRet};
std::cout << "(" << &Params << ")";
diff --git a/offload/new-api/include/offload_impl.hpp b/offload/new-api/include/offload_impl.hpp
index 21e2f40a69d9f6..0774f8ea5e8ef2 100644
--- a/offload/new-api/include/offload_impl.hpp
+++ b/offload/new-api/include/offload_impl.hpp
@@ -20,6 +20,12 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
+struct OffloadConfig {
+ bool TracingEnabled = false;
+};
+
+OffloadConfig &offloadConfig();
+
// Use the StringSet container to efficiently deduplicate repeated error
// strings (e.g. if the same error is hit constantly in a long running program)
llvm::StringSet<> &errorStrs();
diff --git a/offload/new-api/src/offload_impl.cpp b/offload/new-api/src/offload_impl.cpp
index 3498510b6c27b3..32672d572f8fb4 100644
--- a/offload/new-api/src/offload_impl.cpp
+++ b/offload/new-api/src/offload_impl.cpp
@@ -65,6 +65,8 @@ void initPlugins() {
}
}
}
+
+ offloadConfig().TracingEnabled = std::getenv("OFFLOAD_TRACE");
}
// TODO: We can properly reference count here and manage the resources in a more
diff --git a/offload/new-api/src/offload_lib.cpp b/offload/new-api/src/offload_lib.cpp
index 1b5acdfeb6f7e1..20beb72575c3eb 100644
--- a/offload/new-api/src/offload_lib.cpp
+++ b/offload/new-api/src/offload_lib.cpp
@@ -31,6 +31,11 @@ offload_code_location_t *¤tCodeLocation() {
return CodeLoc;
}
+OffloadConfig &offloadConfig() {
+ static OffloadConfig Config{};
+ return Config;
+}
+
// Pull in the declarations for the implementation funtions. The actual entry
// points in this file wrap these.
#include "offload_impl_func_decls.inc"
diff --git a/offload/tools/offload-tblgen/EntryPointGen.cpp b/offload/tools/offload-tblgen/EntryPointGen.cpp
index b9bbfedddba5cb..67e6af671e4f36 100644
--- a/offload/tools/offload-tblgen/EntryPointGen.cpp
+++ b/offload/tools/offload-tblgen/EntryPointGen.cpp
@@ -71,7 +71,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
OS << ") {\n";
// Emit pre-call prints
- OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
+ OS << TAB_1 "if (offloadConfig().TracingEnabled) {\n";
OS << formatv(TAB_2 "std::cout << \"---> {0}\";\n", F.getName());
OS << TAB_1 "}\n\n";
@@ -81,7 +81,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
F.getName(), ParamNameList);
// Emit post-call prints
- OS << TAB_1 "if (std::getenv(\"OFFLOAD_TRACE\")) {\n";
+ OS << TAB_1 "if (offloadConfig().TracingEnabled) {\n";
if (F.getParams().size() > 0) {
OS << formatv(TAB_2 "{0} Params = {{ ", F.getParamStructName());
for (const auto &Param : F.getParams()) {
More information about the llvm-commits
mailing list